fix(cli): inject server auth for attach clients

This commit is contained in:
William Obino
2026-04-18 17:49:05 +03:00
parent 2892ca4adf
commit ef5c74e972
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -1,6 +1,7 @@
import { createOpencode, createOpencodeClient } from "@opencode-ai/sdk"
import pc from "picocolors"
import type { ServerConnection } from "./types"
import { injectServerAuthIntoClient } from "../../shared/opencode-server-auth"
import { getAvailableServerPort, isPortAvailable, DEFAULT_SERVER_PORT } from "../../shared/port-utils"
import { withWorkingOpencodePath } from "./opencode-binary-resolver"
@@ -40,6 +41,7 @@ export async function createServerConnection(options: {
if (attach !== undefined) {
console.log(pc.dim("Attaching to existing server at"), pc.cyan(attach))
const client = createOpencodeClient({ baseUrl: attach })
injectServerAuthIntoClient(client)
return { client, cleanup: () => {} }
}
@@ -66,12 +68,14 @@ export async function createServerConnection(options: {
console.log(pc.dim("Port"), pc.cyan(port.toString()), pc.dim("became occupied, attaching to existing server"))
const client = createOpencodeClient({ baseUrl: `http://127.0.0.1:${port}` })
injectServerAuthIntoClient(client)
return { client, cleanup: () => {} }
}
}
console.log(pc.dim("Port"), pc.cyan(port.toString()), pc.dim("is occupied, attaching to existing server"))
const client = createOpencodeClient({ baseUrl: `http://127.0.0.1:${port}` })
injectServerAuthIntoClient(client)
return { client, cleanup: () => {} }
}
@@ -93,6 +97,7 @@ export async function createServerConnection(options: {
console.log(pc.dim("Port range exhausted, attaching to existing server on"), pc.cyan(DEFAULT_SERVER_PORT.toString()))
const client = createOpencodeClient({ baseUrl: `http://127.0.0.1:${DEFAULT_SERVER_PORT}` })
injectServerAuthIntoClient(client)
return { client, cleanup: () => {} }
}
+1 -1
View File
@@ -78,7 +78,7 @@ function tryInjectViaInterceptors(internal: UnknownRecord, auth: string): boolea
return false
}
use((request: Request): Request => {
use.call(requestInterceptors, (request: Request): Request => {
if (!request.headers.get("Authorization")) {
request.headers.set("Authorization", auth)
}