mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 01:34:22 +01:00
feat: add createOpencodeTui() function to SDK for programmatic TUI launching (#2410)
This commit is contained in:
@@ -9,6 +9,15 @@ export type ServerOptions = {
|
|||||||
config?: Config
|
config?: Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TuiOptions = {
|
||||||
|
project?: string
|
||||||
|
model?: string
|
||||||
|
session?: string
|
||||||
|
agent?: string
|
||||||
|
signal?: AbortSignal
|
||||||
|
config?: Config
|
||||||
|
}
|
||||||
|
|
||||||
export async function createOpencodeServer(options?: ServerOptions) {
|
export async function createOpencodeServer(options?: ServerOptions) {
|
||||||
options = Object.assign(
|
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()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user