mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 01:34:22 +01:00
allow importing sdk from @opencode-ai/sdk/server and @opencode-ai/sdk/client
This commit is contained in:
26
packages/sdk/js/src/server.ts
Normal file
26
packages/sdk/js/src/server.ts
Normal 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()
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user