diff options
| author | Zack Jackson <[email protected]> | 2025-09-04 14:49:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-04 02:49:44 -0400 |
| commit | e001af27098635f8b0d92af341b1b2eb980936ca (patch) | |
| tree | 1ee5dcad69f70e3529c48d1e2e282500d06d0772 | |
| parent | a97612287f483c09259c60d5459a315ef2e08818 (diff) | |
| download | opencode-e001af27098635f8b0d92af341b1b2eb980936ca.tar.gz opencode-e001af27098635f8b0d92af341b1b2eb980936ca.zip | |
feat: add createOpencodeTui() function to SDK for programmatic TUI launching (#2410)
| -rw-r--r-- | packages/sdk/js/src/server.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/sdk/js/src/server.ts b/packages/sdk/js/src/server.ts index 3cee64752..24f716a2c 100644 --- a/packages/sdk/js/src/server.ts +++ b/packages/sdk/js/src/server.ts @@ -9,6 +9,15 @@ export type ServerOptions = { config?: Config } +export type TuiOptions = { + project?: string + model?: string + session?: string + agent?: string + signal?: AbortSignal + config?: Config +} + export async function createOpencodeServer(options?: ServerOptions) { options = Object.assign( { @@ -77,3 +86,35 @@ export async function createOpencodeServer(options?: ServerOptions) { }, } } + +export function createOpencodeTui(options?: TuiOptions) { + const args = [] + + if (options?.project) { + args.push(`--project=${options.project}`) + } + if (options?.model) { + args.push(`--model=${options.model}`) + } + if (options?.session) { + args.push(`--session=${options.session}`) + } + if (options?.agent) { + args.push(`--agent=${options.agent}`) + } + + const proc = spawn(`opencode`, args, { + signal: options?.signal, + stdio: 'inherit', + env: { + ...process.env, + OPENCODE_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}), + }, + }) + + return { + close() { + proc.kill() + }, + } +} |
