Support basic auth in opencode sdk (#4697)

pull/4715/head
Andrew Joslin 2025-11-24 15:05:35 -08:00 committed by GitHub
parent 2458e7597b
commit b9253d0b3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -24,6 +24,19 @@ export function createOpencodeClient(config?: Config & { directory?: string }) {
}
}
if (config?.baseUrl) {
const baseUrl = new URL(config.baseUrl)
if (baseUrl.username || baseUrl.password) {
config.headers = {
...config.headers,
Authorization: `Basic ${btoa(`${baseUrl.username}:${baseUrl.password}`)}`,
}
baseUrl.username = ""
baseUrl.password = ""
config.baseUrl = baseUrl.toString()
}
}
const client = createClient(config)
return new OpencodeClient({ client })
}