The open source coding agent.
TypeScript
wip: sdk
Dax Raadee62dc07456a
diff --git a/packages/sdk/js/src/gen/types.gen.ts b/packages/sdk/js/src/gen/types.gen.tsindex 06b87ff2188..3652ea584f8 100644--- a/packages/sdk/js/src/gen/types.gen.ts+++ b/packages/sdk/js/src/gen/types.gen.ts@@ -54,14 +54,14 @@ export type Event =} & EventIdeInstalled)export type EventInstallationUpdated = {- type: string+ type: "installation.updated"properties: {version: string}}export type EventLspClientDiagnostics = {- type: string+ type: "lsp.client.diagnostics"properties: {serverID: stringpath: string@@ -69,7 +69,7 @@ export type EventLspClientDiagnostics = {}export type EventMessageUpdated = {- type: string+ type: "message.updated"properties: {info: Message}@@ -86,7 +86,7 @@ export type Message =export type UserMessage = {id: stringsessionID: string- role: string+ role: "user"time: {created: number}@@ -95,7 +95,7 @@ export type UserMessage = {export type AssistantMessage = {id: stringsessionID: string- role: string+ role: "assistant"time: {created: numbercompleted?: number@@ -135,7 +135,7 @@ export type AssistantMessage = {}export type ProviderAuthError = {- name: string+ name: "ProviderAuthError"data: {providerID: stringmessage: string@@ -143,28 +143,28 @@ export type ProviderAuthError = {}export type UnknownError = {- name: string+ name: "UnknownError"data: {message: string}}export type MessageOutputLengthError = {- name: string+ name: "MessageOutputLengthError"data: {[key: string]: unknown}}export type MessageAbortedError = {- name: string+ name: "MessageAbortedError"data: {[key: string]: unknown}}export type EventMessageRemoved = {- type: string+ type: "message.removed"properties: {sessionID: stringmessageID: string@@ -172,7 +172,7 @@ export type EventMessageRemoved = {}export type EventMessagePartUpdated = {- type: string+ type: "message.part.updated"properties: {part: Part}@@ -211,7 +211,7 @@ export type TextPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "text"text: stringsynthetic?: booleantime?: {@@ -224,7 +224,7 @@ export type ReasoningPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "reasoning"text: stringmetadata?: {[key: string]: unknown@@ -239,7 +239,7 @@ export type FilePart = {id: stringsessionID: stringmessageID: string- type: string+ type: "file"mime: stringfilename?: stringurl: string@@ -256,7 +256,7 @@ export type FilePartSource =export type FileSource = {text: FilePartSourceText- type: string+ type: "file"path: string}@@ -268,7 +268,7 @@ export type FilePartSourceText = {export type SymbolSource = {text: FilePartSourceText- type: string+ type: "symbol"path: stringrange: Rangename: string@@ -290,7 +290,7 @@ export type ToolPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "tool"callID: stringtool: stringstate: ToolState@@ -311,11 +311,11 @@ export type ToolState =} & ToolStateError)export type ToolStatePending = {- status: string+ status: "pending"}export type ToolStateRunning = {- status: string+ status: "running"input?: unknowntitle?: stringmetadata?: {@@ -327,7 +327,7 @@ export type ToolStateRunning = {}export type ToolStateCompleted = {- status: string+ status: "completed"input: {[key: string]: unknown}@@ -343,7 +343,7 @@ export type ToolStateCompleted = {}export type ToolStateError = {- status: string+ status: "error"input: {[key: string]: unknown}@@ -358,14 +358,14 @@ export type StepStartPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "step-start"}export type StepFinishPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "step-finish"cost: numbertokens: {input: number@@ -382,7 +382,7 @@ export type SnapshotPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "snapshot"snapshot: string}@@ -390,7 +390,7 @@ export type PatchPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "patch"hash: stringfiles: Array<string>}@@ -399,7 +399,7 @@ export type AgentPart = {id: stringsessionID: stringmessageID: string- type: string+ type: "agent"name: stringsource?: {value: string@@ -409,7 +409,7 @@ export type AgentPart = {}export type EventMessagePartRemoved = {- type: string+ type: "message.part.removed"properties: {sessionID: stringmessageID: string@@ -418,7 +418,7 @@ export type EventMessagePartRemoved = {}export type EventStorageWrite = {- type: string+ type: "storage.write"properties: {key: stringcontent?: unknown@@ -426,21 +426,21 @@ export type EventStorageWrite = {}export type EventFileEdited = {- type: string+ type: "file.edited"properties: {file: string}}export type EventServerConnected = {- type: string+ type: "server.connected"properties: {[key: string]: unknown}}export type EventPermissionUpdated = {- type: string+ type: "permission.updated"properties: Permission}@@ -461,7 +461,7 @@ export type Permission = {}export type EventPermissionReplied = {- type: string+ type: "permission.replied"properties: {sessionID: stringpermissionID: string@@ -470,7 +470,7 @@ export type EventPermissionReplied = {}export type EventSessionUpdated = {- type: string+ type: "session.updated"properties: {info: Session}@@ -497,21 +497,21 @@ export type Session = {}export type EventSessionDeleted = {- type: string+ type: "session.deleted"properties: {info: Session}}export type EventSessionIdle = {- type: string+ type: "session.idle"properties: {sessionID: string}}export type EventSessionError = {- type: string+ type: "session.error"properties: {sessionID?: stringerror?:@@ -531,15 +531,15 @@ export type EventSessionError = {}export type EventFileWatcherUpdated = {- type: string+ type: "file.watcher.updated"properties: {file: string- event: string+ event: "rename" | "change"}}export type EventIdeInstalled = {- type: string+ type: "ide.installed"properties: {ide: string}@@ -569,6 +569,9 @@ export type Config = {* Theme name to use for the interface*/theme?: string+ /**+ * Custom keybind configurations+ */keybinds?: KeybindsConfigplugin?: Array<string>snapshot?: boolean@@ -683,7 +686,7 @@ export type Config = {lsp?: {[key: string]:| {- disabled: boolean+ disabled: true}| {command: Array<string>@@ -701,15 +704,18 @@ export type Config = {* Additional instruction files or patterns to include*/instructions?: Array<string>+ /**+ * @deprecated Always uses stretch layout.+ */layout?: LayoutConfigpermission?: {- edit?: string+ edit?: "ask" | "allow" | "deny"bash?:- | string+ | ("ask" | "allow" | "deny")| {- [key: string]: string+ [key: string]: "ask" | "allow" | "deny"}- webfetch?: string+ webfetch?: "ask" | "allow" | "deny"}experimental?: {hook?: {@@ -911,15 +917,15 @@ export type AgentConfig = {* Description of when to use the agent*/description?: string- mode?: string+ mode?: "subagent" | "primary" | "all"permission?: {- edit?: string+ edit?: "ask" | "allow" | "deny"bash?:- | string+ | ("ask" | "allow" | "deny")| {- [key: string]: string+ [key: string]: "ask" | "allow" | "deny"}- webfetch?: string+ webfetch?: "ask" | "allow" | "deny"}[key: string]:| unknown@@ -929,15 +935,15 @@ export type AgentConfig = {[key: string]: boolean}| boolean- | string+ | ("subagent" | "primary" | "all")| {- edit?: string+ edit?: "ask" | "allow" | "deny"bash?:- | string+ | ("ask" | "allow" | "deny")| {- [key: string]: string+ [key: string]: "ask" | "allow" | "deny"}- webfetch?: string+ webfetch?: "ask" | "allow" | "deny"}| undefined}@@ -980,7 +986,7 @@ export type McpLocalConfig = {/*** Type of MCP server connection*/- type: string+ type: "local"/*** Command and arguments to run the MCP server*/@@ -1001,7 +1007,7 @@ export type McpRemoteConfig = {/*** Type of MCP server connection*/- type: string+ type: "remote"/*** URL of the remote MCP server*/@@ -1028,7 +1034,7 @@ export type _Error = {export type TextPartInput = {id?: string- type: string+ type: "text"text: stringsynthetic?: booleantime?: {@@ -1039,7 +1045,7 @@ export type TextPartInput = {export type FilePartInput = {id?: string- type: string+ type: "file"mime: stringfilename?: stringurl: string@@ -1048,7 +1054,7 @@ export type FilePartInput = {export type AgentPartInput = {id?: string- type: string+ type: "agent"name: stringsource?: {value: string@@ -1076,15 +1082,15 @@ export type File = {export type Agent = {name: stringdescription?: string- mode: string+ mode: "subagent" | "primary" | "all"topP?: numbertemperature?: numberpermission: {- edit: string+ edit: "ask" | "allow" | "deny"bash: {- [key: string]: string+ [key: string]: "ask" | "allow" | "deny"}- webfetch?: string+ webfetch?: "ask" | "allow" | "deny"}model?: {modelID: stringdiff --git a/packages/sdk/js/src/index.ts b/packages/sdk/js/src/index.tsindex eeb837903a8..a8f0a105dc1 100644--- a/packages/sdk/js/src/index.ts+++ b/packages/sdk/js/src/index.ts@@ -2,8 +2,34 @@ 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"+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()+ },+ }+}