mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-03 11:16:46 +00:00
app: refactor server management backend (#13813)
This commit is contained in:
22
packages/app/src/utils/server.ts
Normal file
22
packages/app/src/utils/server.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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, ...auth },
|
||||
baseUrl: server.url,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user