@opencode-ai/sdk 0.5.13 → 0.5.15

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.
@@ -0,0 +1,5 @@
1
+ export * from "./gen/types.gen.js";
2
+ export { type Config as OpencodeClientConfig, OpencodeClient };
3
+ import { type Config } from "./gen/client/types.js";
4
+ import { OpencodeClient } from "./gen/sdk.gen.js";
5
+ export declare function createOpencodeClient(config?: Config): OpencodeClient;
package/dist/client.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./gen/types.gen.js";
2
+ export { OpencodeClient };
3
+ import { createClient } from "./gen/client/client.js";
4
+ import { OpencodeClient } from "./gen/sdk.gen.js";
5
+ export function createOpencodeClient(config) {
6
+ const client = createClient(config);
7
+ return new OpencodeClient({ client });
8
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Options as ClientOptions, TDataShape, Client } from "./client/index.js";
2
- import type { EventSubscribeData, EventSubscribeResponses, AppGetData, AppGetResponses, AppInitData, AppInitResponses, ConfigGetData, ConfigGetResponses, SessionListData, SessionListResponses, SessionCreateData, SessionCreateResponses, SessionCreateErrors, SessionDeleteData, SessionDeleteResponses, SessionGetData, SessionGetResponses, SessionUpdateData, SessionUpdateResponses, SessionChildrenData, SessionChildrenResponses, SessionInitData, SessionInitResponses, SessionAbortData, SessionAbortResponses, SessionUnshareData, SessionUnshareResponses, SessionShareData, SessionShareResponses, SessionSummarizeData, SessionSummarizeResponses, SessionMessagesData, SessionMessagesResponses, SessionChatData, SessionChatResponses, SessionMessageData, SessionMessageResponses, SessionShellData, SessionShellResponses, SessionRevertData, SessionRevertResponses, SessionUnrevertData, SessionUnrevertResponses, PostSessionByIdPermissionsByPermissionIdData, PostSessionByIdPermissionsByPermissionIdResponses, ConfigProvidersData, ConfigProvidersResponses, FindTextData, FindTextResponses, FindFilesData, FindFilesResponses, FindSymbolsData, FindSymbolsResponses, FileReadData, FileReadResponses, FileStatusData, FileStatusResponses, AppLogData, AppLogResponses, AppAgentsData, AppAgentsResponses, TuiAppendPromptData, TuiAppendPromptResponses, TuiOpenHelpData, TuiOpenHelpResponses, TuiOpenSessionsData, TuiOpenSessionsResponses, TuiOpenThemesData, TuiOpenThemesResponses, TuiOpenModelsData, TuiOpenModelsResponses, TuiSubmitPromptData, TuiSubmitPromptResponses, TuiClearPromptData, TuiClearPromptResponses, TuiExecuteCommandData, TuiExecuteCommandResponses, TuiShowToastData, TuiShowToastResponses, AuthSetData, AuthSetResponses, AuthSetErrors } from "./types.gen.js";
2
+ import type { EventSubscribeData, EventSubscribeResponses, AppGetData, AppGetResponses, AppInitData, AppInitResponses, ConfigGetData, ConfigGetResponses, SessionListData, SessionListResponses, SessionCreateData, SessionCreateResponses, SessionCreateErrors, SessionDeleteData, SessionDeleteResponses, SessionGetData, SessionGetResponses, SessionUpdateData, SessionUpdateResponses, SessionChildrenData, SessionChildrenResponses, SessionInitData, SessionInitResponses, SessionAbortData, SessionAbortResponses, SessionUnshareData, SessionUnshareResponses, SessionShareData, SessionShareResponses, SessionSummarizeData, SessionSummarizeResponses, SessionMessagesData, SessionMessagesResponses, SessionChatData, SessionChatResponses, SessionMessageData, SessionMessageResponses, SessionCommandData, SessionCommandResponses, SessionShellData, SessionShellResponses, SessionRevertData, SessionRevertResponses, SessionUnrevertData, SessionUnrevertResponses, PostSessionByIdPermissionsByPermissionIdData, PostSessionByIdPermissionsByPermissionIdResponses, CommandListData, CommandListResponses, ConfigProvidersData, ConfigProvidersResponses, FindTextData, FindTextResponses, FindFilesData, FindFilesResponses, FindSymbolsData, FindSymbolsResponses, FileReadData, FileReadResponses, FileStatusData, FileStatusResponses, AppLogData, AppLogResponses, AppAgentsData, AppAgentsResponses, TuiAppendPromptData, TuiAppendPromptResponses, TuiOpenHelpData, TuiOpenHelpResponses, TuiOpenSessionsData, TuiOpenSessionsResponses, TuiOpenThemesData, TuiOpenThemesResponses, TuiOpenModelsData, TuiOpenModelsResponses, TuiSubmitPromptData, TuiSubmitPromptResponses, TuiClearPromptData, TuiClearPromptResponses, TuiExecuteCommandData, TuiExecuteCommandResponses, TuiShowToastData, TuiShowToastResponses, AuthSetData, AuthSetResponses, AuthSetErrors } from "./types.gen.js";
3
3
  export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
4
4
  /**
5
5
  * You can provide a client instance returned by `createClient()` instead of
@@ -110,6 +110,10 @@ declare class Session extends _HeyApiClient {
110
110
  * Get a message from a session
111
111
  */
112
112
  message<ThrowOnError extends boolean = false>(options: Options<SessionMessageData, ThrowOnError>): import("./client/types.js").RequestResult<SessionMessageResponses, unknown, ThrowOnError, "fields">;
113
+ /**
114
+ * Send a new command to a session
115
+ */
116
+ command<ThrowOnError extends boolean = false>(options: Options<SessionCommandData, ThrowOnError>): import("./client/types.js").RequestResult<SessionCommandResponses, unknown, ThrowOnError, "fields">;
113
117
  /**
114
118
  * Run a shell command
115
119
  */
@@ -123,6 +127,12 @@ declare class Session extends _HeyApiClient {
123
127
  */
124
128
  unrevert<ThrowOnError extends boolean = false>(options: Options<SessionUnrevertData, ThrowOnError>): import("./client/types.js").RequestResult<SessionUnrevertResponses, unknown, ThrowOnError, "fields">;
125
129
  }
130
+ declare class Command extends _HeyApiClient {
131
+ /**
132
+ * List all commands
133
+ */
134
+ list<ThrowOnError extends boolean = false>(options?: Options<CommandListData, ThrowOnError>): import("./client/types.js").RequestResult<CommandListResponses, unknown, ThrowOnError, "fields">;
135
+ }
126
136
  declare class Find extends _HeyApiClient {
127
137
  /**
128
138
  * Find text in files
@@ -200,6 +210,7 @@ export declare class OpencodeClient extends _HeyApiClient {
200
210
  app: App;
201
211
  config: Config;
202
212
  session: Session;
213
+ command: Command;
203
214
  find: Find;
204
215
  file: File;
205
216
  tui: Tui;
@@ -228,6 +228,19 @@ class Session extends _HeyApiClient {
228
228
  ...options,
229
229
  });
230
230
  }
231
+ /**
232
+ * Send a new command to a session
233
+ */
234
+ command(options) {
235
+ return (options.client ?? this._client).post({
236
+ url: "/session/{id}/command",
237
+ ...options,
238
+ headers: {
239
+ "Content-Type": "application/json",
240
+ ...options.headers,
241
+ },
242
+ });
243
+ }
231
244
  /**
232
245
  * Run a shell command
233
246
  */
@@ -264,6 +277,17 @@ class Session extends _HeyApiClient {
264
277
  });
265
278
  }
266
279
  }
280
+ class Command extends _HeyApiClient {
281
+ /**
282
+ * List all commands
283
+ */
284
+ list(options) {
285
+ return (options?.client ?? this._client).get({
286
+ url: "/command",
287
+ ...options,
288
+ });
289
+ }
290
+ }
267
291
  class Find extends _HeyApiClient {
268
292
  /**
269
293
  * Find text in files
@@ -441,6 +465,7 @@ export class OpencodeClient extends _HeyApiClient {
441
465
  app = new App({ client: this._client });
442
466
  config = new Config({ client: this._client });
443
467
  session = new Session({ client: this._client });
468
+ command = new Command({ client: this._client });
444
469
  find = new Find({ client: this._client });
445
470
  file = new File({ client: this._client });
446
471
  tui = new Tui({ client: this._client });
@@ -493,6 +493,14 @@ export type Config = {
493
493
  */
494
494
  scroll_speed: number;
495
495
  };
496
+ command?: {
497
+ [key: string]: {
498
+ template: string;
499
+ description?: string;
500
+ agent?: string;
501
+ model?: string;
502
+ };
503
+ };
496
504
  plugin?: Array<string>;
497
505
  snapshot?: boolean;
498
506
  /**
@@ -988,6 +996,13 @@ export type AgentPartInput = {
988
996
  end: number;
989
997
  };
990
998
  };
999
+ export type Command = {
1000
+ name: string;
1001
+ description?: string;
1002
+ agent?: string;
1003
+ model?: string;
1004
+ template: string;
1005
+ };
991
1006
  export type Symbol = {
992
1007
  name: string;
993
1008
  kind: number;
@@ -1340,7 +1355,10 @@ export type SessionChatResponses = {
1340
1355
  /**
1341
1356
  * Created message
1342
1357
  */
1343
- 200: AssistantMessage;
1358
+ 200: {
1359
+ info: AssistantMessage;
1360
+ parts: Array<Part>;
1361
+ };
1344
1362
  };
1345
1363
  export type SessionChatResponse = SessionChatResponses[keyof SessionChatResponses];
1346
1364
  export type SessionMessageData = {
@@ -1368,6 +1386,33 @@ export type SessionMessageResponses = {
1368
1386
  };
1369
1387
  };
1370
1388
  export type SessionMessageResponse = SessionMessageResponses[keyof SessionMessageResponses];
1389
+ export type SessionCommandData = {
1390
+ body?: {
1391
+ messageID?: string;
1392
+ agent?: string;
1393
+ model?: string;
1394
+ arguments: string;
1395
+ command: string;
1396
+ };
1397
+ path: {
1398
+ /**
1399
+ * Session ID
1400
+ */
1401
+ id: string;
1402
+ };
1403
+ query?: never;
1404
+ url: "/session/{id}/command";
1405
+ };
1406
+ export type SessionCommandResponses = {
1407
+ /**
1408
+ * Created message
1409
+ */
1410
+ 200: {
1411
+ info: AssistantMessage;
1412
+ parts: Array<Part>;
1413
+ };
1414
+ };
1415
+ export type SessionCommandResponse = SessionCommandResponses[keyof SessionCommandResponses];
1371
1416
  export type SessionShellData = {
1372
1417
  body?: {
1373
1418
  agent: string;
@@ -1440,6 +1485,19 @@ export type PostSessionByIdPermissionsByPermissionIdResponses = {
1440
1485
  200: boolean;
1441
1486
  };
1442
1487
  export type PostSessionByIdPermissionsByPermissionIdResponse = PostSessionByIdPermissionsByPermissionIdResponses[keyof PostSessionByIdPermissionsByPermissionIdResponses];
1488
+ export type CommandListData = {
1489
+ body?: never;
1490
+ path?: never;
1491
+ query?: never;
1492
+ url: "/command";
1493
+ };
1494
+ export type CommandListResponses = {
1495
+ /**
1496
+ * List of commands
1497
+ */
1498
+ 200: Array<Command>;
1499
+ };
1500
+ export type CommandListResponse = CommandListResponses[keyof CommandListResponses];
1443
1501
  export type ConfigProvidersData = {
1444
1502
  body?: never;
1445
1503
  path?: never;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,2 @@
1
- import { type Config } from "./gen/client/types.js";
2
- import { OpencodeClient } from "./gen/sdk.gen.js";
3
- export * from "./gen/types.gen.js";
4
- export declare function createOpencodeClient(config?: Config): OpencodeClient;
5
- export type ServerConfig = {
6
- host?: string;
7
- port?: number;
8
- };
9
- export declare function createOpencodeServer(config?: ServerConfig): Promise<{
10
- url: string;
11
- close(): void;
12
- }>;
1
+ export * from "./client.js";
2
+ export * from "./server.js";
package/dist/index.js CHANGED
@@ -1,22 +1,2 @@
1
- import { createClient } from "./gen/client/client.js";
2
- import { OpencodeClient } from "./gen/sdk.gen.js";
3
- export * from "./gen/types.gen.js";
4
- import { spawn } from "child_process";
5
- export function createOpencodeClient(config) {
6
- const client = createClient(config);
7
- return new OpencodeClient({ client });
8
- }
9
- export async function createOpencodeServer(config) {
10
- config = Object.assign({
11
- host: "127.0.0.1",
12
- port: 4096,
13
- }, config ?? {});
14
- const proc = spawn(`opencode`, [`serve`, `--host=${config.host}`, `--port=${config.port}`]);
15
- const url = `http://${config.host}:${config.port}`;
16
- return {
17
- url,
18
- close() {
19
- proc.kill();
20
- },
21
- };
22
- }
1
+ export * from "./client.js";
2
+ export * from "./server.js";
@@ -0,0 +1,10 @@
1
+ export type ServerConfig = {
2
+ hostname?: string;
3
+ port?: number;
4
+ signal?: AbortSignal;
5
+ timeout?: number;
6
+ };
7
+ export declare function createOpencodeServer(config?: ServerConfig): Promise<{
8
+ url: string;
9
+ close(): void;
10
+ }>;
package/dist/server.js ADDED
@@ -0,0 +1,59 @@
1
+ import { spawn } from "node:child_process";
2
+ export async function createOpencodeServer(config) {
3
+ config = Object.assign({
4
+ hostname: "127.0.0.1",
5
+ port: 4096,
6
+ timeout: 5000,
7
+ }, config ?? {});
8
+ const proc = spawn(`opencode`, [`servel`, `--hostname=${config.hostname}`, `--port=${config.port}`], {
9
+ signal: config.signal,
10
+ });
11
+ const url = await new Promise((resolve, reject) => {
12
+ const id = setTimeout(() => {
13
+ reject(new Error(`Timeout waiting for server to start after ${config.timeout}ms`));
14
+ }, config.timeout);
15
+ let output = "";
16
+ proc.stdout?.on("data", (chunk) => {
17
+ output += chunk.toString();
18
+ const lines = output.split("\n");
19
+ for (const line of lines) {
20
+ if (line.startsWith("opencode server listening")) {
21
+ const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
22
+ if (!match) {
23
+ throw new Error(`Failed to parse server url from output: ${line}`);
24
+ }
25
+ clearTimeout(id);
26
+ resolve(match[1]);
27
+ return;
28
+ }
29
+ }
30
+ });
31
+ proc.stderr?.on("data", (chunk) => {
32
+ output += chunk.toString();
33
+ });
34
+ proc.on("exit", (code) => {
35
+ clearTimeout(id);
36
+ let msg = `Server exited with code ${code}`;
37
+ if (output.trim()) {
38
+ msg += `\nServer output: ${output}`;
39
+ }
40
+ reject(new Error(msg));
41
+ });
42
+ proc.on("error", (error) => {
43
+ clearTimeout(id);
44
+ reject(error);
45
+ });
46
+ if (config.signal) {
47
+ config.signal.addEventListener("abort", () => {
48
+ clearTimeout(id);
49
+ reject(new Error("Aborted"));
50
+ });
51
+ }
52
+ });
53
+ return {
54
+ url,
55
+ close() {
56
+ proc.kill();
57
+ },
58
+ };
59
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode-ai/sdk",
4
- "version": "0.5.13",
4
+ "version": "0.5.15",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "typecheck": "tsc --noEmit"
@@ -10,6 +10,14 @@
10
10
  ".": {
11
11
  "development": "./src/index.ts",
12
12
  "import": "./dist/index.js"
13
+ },
14
+ "./client": {
15
+ "development": "./src/client.ts",
16
+ "import": "./dist/client.js"
17
+ },
18
+ "./server": {
19
+ "development": "./src/server.ts",
20
+ "import": "./dist/server.js"
13
21
  }
14
22
  },
15
23
  "files": [