@liontree/opencode-agent-sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,7 +58,7 @@ This package declares `@opencode-ai/sdk` and `opencode-ai` as dependencies, so y
58
58
  npm install @liontree/opencode-agent-sdk
59
59
  ```
60
60
 
61
- See `examples/subagents.ts` for a complete subagent lineage and `resumeAgent()` example.
61
+ See `examples/subagents.ts` for a complete subagent lineage and `resumeAgent()` example, and `examples/attach.ts` for attaching to an existing OpenCode server.
62
62
 
63
63
  ```ts
64
64
  import { createAgentRuntime } from "@liontree/opencode-agent-sdk"
@@ -138,6 +138,18 @@ const runtime = await createAgentRuntime({
138
138
  })
139
139
  ```
140
140
 
141
+ If you already have an OpenCode server running, attach to it with `serverUrl`:
142
+
143
+ ```ts
144
+ const runtime = await createAgentRuntime({
145
+ directory: "/app",
146
+ serverUrl: "http://127.0.0.1:40937",
147
+ model: "openai/gpt-5.4",
148
+ })
149
+ ```
150
+
151
+ In attach mode, `model` still works as a local default and is sent with each prompt. Other runtime config such as `config`, `mcp`, `permission`, and `rawConfigContent` is not pushed into the existing server.
152
+
141
153
  If you only need the final answer instead of a streamed event loop, use `runAgent()`:
142
154
 
143
155
  ```ts
@@ -199,13 +211,12 @@ Use `config.agent.<name>.permission.task` when you want to override a built-in a
199
211
 
200
212
  ### `createAgentRuntime(options)`
201
213
 
202
- Creates a managed OpenCode runtime and injects:
214
+ Creates an OpenCode runtime in one of two modes:
215
+
216
+ - managed mode: starts and manages an OpenCode server, then injects agent prompts, optional default model, optional MCP config, optional permission config, and optional extra config merged with inherited inline config
217
+ - attach mode: connects to an existing OpenCode server with `serverUrl`
203
218
 
204
- - agent prompts
205
- - optional default model
206
- - optional MCP config
207
- - optional permission config
208
- - optional extra config merged with inherited inline config
219
+ Attach mode does not push `config`, `mcp`, `permission`, or `rawConfigContent` into the existing server. `model` still works as a local default and is sent with each prompt. `serverUrl` cannot be combined with `hostname`, `port`, or `timeoutMs`.
209
220
 
210
221
  ### `runtime.createSession({ agent, model })`
211
222
 
package/dist/runtime.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createOpencode, } from "@opencode-ai/sdk/v2";
1
+ import { createOpencode, createOpencodeClient, } from "@opencode-ai/sdk/v2";
2
2
  import { buildRuntimeConfig, normalizeModelReference, parseModelSpec } from "./config.js";
3
3
  import { delay, extractTextFromParts, formatErrorInfo, requireData, toErrorInfo } from "./utils.js";
4
4
  const POST_IDLE_EVENT_DRAIN_MS = 300;
@@ -928,6 +928,16 @@ export class OpencodeAgentRuntime {
928
928
  }
929
929
  export async function createAgentRuntime(options) {
930
930
  const agents = options.agents ?? {};
931
+ if (options.serverUrl) {
932
+ if (typeof options.hostname === "string" || typeof options.port === "number" || typeof options.timeoutMs === "number") {
933
+ throw new Error("serverUrl cannot be combined with hostname, port, or timeoutMs");
934
+ }
935
+ const client = createOpencodeClient({
936
+ baseUrl: options.serverUrl,
937
+ directory: options.directory,
938
+ });
939
+ return new OpencodeAgentRuntime(client, options.directory, agents, undefined, options.model);
940
+ }
931
941
  const runtimeConfig = buildRuntimeConfig({
932
942
  agents,
933
943
  ...(options.config ? { config: options.config } : {}),
package/dist/types.d.ts CHANGED
@@ -28,6 +28,7 @@ export type AgentRuntimeOptions = {
28
28
  permission?: JsonObject;
29
29
  port?: number;
30
30
  rawConfigContent?: string;
31
+ serverUrl?: string;
31
32
  timeoutMs?: number;
32
33
  };
33
34
  export type AgentSessionOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liontree/opencode-agent-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "High-level agent runtime built on top of @opencode-ai/sdk",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",