allow importing sdk from @opencode-ai/sdk/server and @opencode-ai/sdk/client

This commit is contained in:
Dax Raad
2025-08-21 12:58:37 -04:00
parent b1e584ca1d
commit 9a3186317b
4 changed files with 46 additions and 39 deletions

View File

@@ -0,0 +1,26 @@
import { spawn } from "node:child_process"
export type ServerConfig = {
host?: string
port?: number
}
export async function createOpencodeServer(config?: ServerConfig) {
config = Object.assign(
{
host: "127.0.0.1",
port: 4096,
},
config ?? {},
)
const proc = spawn(`opencode`, [`serve`, `--host=${config.host}`, `--port=${config.port}`])
const url = `http://${config.host}:${config.port}`
return {
url,
close() {
proc.kill()
},
}
}