Skip to content

Commit 2b7c3f7

Browse files
Fix Basic Auth handling in v2 client and CLI status command
1 parent e14f4c5 commit 2b7c3f7

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/memory/src/cli/commands/status.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ export async function run(argv: StatusArgs): Promise<void> {
3131

3232
async function tryFetchSessionOutput(serverUrl: string, sessionId: string, directory: string) {
3333
try {
34-
const client = createOpencodeClient({ baseUrl: serverUrl, directory })
34+
const url = new URL(serverUrl)
35+
const password = url.password || process.env['OPENCODE_SERVER_PASSWORD']
36+
const cleanUrl = new URL(url.toString())
37+
cleanUrl.username = ''
38+
cleanUrl.password = ''
39+
const clientConfig: Parameters<typeof createOpencodeClient>[0] = { baseUrl: cleanUrl.toString(), directory }
40+
if (password) {
41+
clientConfig.headers = {
42+
Authorization: `Basic ${Buffer.from(`opencode:${password}`).toString('base64')}`,
43+
}
44+
}
45+
const client = createOpencodeClient(clientConfig)
3546
return await fetchSessionOutput(client, sessionId, directory)
3647
} catch {
3748
return null

packages/memory/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,18 @@ export function createMemoryPlugin(config: PluginConfig): Plugin {
264264
const { directory, project, client } = input
265265
const projectId = project.id
266266

267-
const v2 = createV2Client({ baseUrl: input.serverUrl.toString(), directory })
267+
const serverUrl = input.serverUrl
268+
const serverPassword = serverUrl.password || process.env['OPENCODE_SERVER_PASSWORD']
269+
const cleanUrl = new URL(serverUrl.toString())
270+
cleanUrl.username = ''
271+
cleanUrl.password = ''
272+
const v2ClientConfig: Parameters<typeof createV2Client>[0] = { baseUrl: cleanUrl.toString(), directory }
273+
if (serverPassword) {
274+
v2ClientConfig.headers = {
275+
Authorization: `Basic ${Buffer.from(`opencode:${serverPassword}`).toString('base64')}`,
276+
}
277+
}
278+
const v2 = createV2Client(v2ClientConfig)
268279

269280
const loggingConfig = config.logging
270281
const logger = createLogger({

0 commit comments

Comments
 (0)