mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-13 15:44:56 +00:00
26 lines
707 B
TypeScript
26 lines
707 B
TypeScript
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"
|
|
import type { ServerConnection } from "@/context/server"
|
|
|
|
export function createSdkForServer({
|
|
server,
|
|
...config
|
|
}: Omit<NonNullable<Parameters<typeof createOpencodeClient>[0]>, "baseUrl"> & {
|
|
server: ServerConnection.HttpBase
|
|
}) {
|
|
const auth = (() => {
|
|
if (!server.password) return
|
|
return {
|
|
Authorization: `Basic ${btoa(`${server.username ?? "opencode"}:${server.password}`)}`,
|
|
}
|
|
})()
|
|
|
|
return createOpencodeClient({
|
|
...config,
|
|
headers: {
|
|
...(config.headers instanceof Headers ? Object.fromEntries(config.headers.entries()) : config.headers),
|
|
...auth,
|
|
},
|
|
baseUrl: server.url,
|
|
})
|
|
}
|