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

@@ -10,6 +10,14 @@
".": { ".": {
"development": "./src/index.ts", "development": "./src/index.ts",
"import": "./dist/index.js" "import": "./dist/index.js"
},
"./client": {
"development": "./src/client.ts",
"import": "./dist/client.js"
},
"./server": {
"development": "./src/server.ts",
"import": "./dist/server.js"
} }
}, },
"files": [ "files": [

View File

@@ -0,0 +1,10 @@
import { createClient } from "./gen/client/client.js"
import { type Config } from "./gen/client/types.js"
import { OpencodeClient } from "./gen/sdk.gen.js"
export * from "./gen/types.gen.js"
export { type Config, OpencodeClient }
export function createOpencodeClient(config?: Config) {
const client = createClient(config)
return new OpencodeClient({ client })
}

View File

@@ -1,39 +1,2 @@
import { createClient } from "./gen/client/client.js" export * from "./client.js"
import { type Config } from "./gen/client/types.js" export * from "./server.js"
import { OpencodeClient } from "./gen/sdk.gen.js"
export * from "./gen/types.gen.js"
export {
type Config,
OpencodeClient
}
import { spawn } from "child_process"
export function createOpencodeClient(config?: Config) {
const client = createClient(config)
return new OpencodeClient({ client })
}
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()
},
}
}

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