Support basic auth in opencode sdk

This commit is contained in:
Andrew Joslin 2025-11-24 11:14:14 -08:00
parent 8167e90801
commit 126f2b0600

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 })
}