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