@opencode-ai/sdk 1.14.44 → 1.14.46

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/dist/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./gen/types.gen.js";
2
2
  import { createClient } from "./gen/client/client.gen.js";
3
3
  import { OpencodeClient } from "./gen/sdk.gen.js";
4
+ import { wrapClientError } from "./error-interceptor.js";
4
5
  export { OpencodeClient };
5
6
  function pick(value, fallback) {
6
7
  if (!value)
@@ -47,5 +48,6 @@ export function createOpencodeClient(config) {
47
48
  }
48
49
  const client = createClient(config);
49
50
  client.interceptors.request.use((request) => rewrite(request, config?.directory));
51
+ client.interceptors.error.use(wrapClientError);
50
52
  return new OpencodeClient({ client });
51
53
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Wrap whatever the generated client decoded from a non-2xx error body
3
+ * into a real `Error` so downstream formatters (TUI, plugins) get a
4
+ * useful `.message` instead of `[object Object]` or blank. The original
5
+ * parsed body and status live under `.cause` for callers that need
6
+ * structured fields.
7
+ *
8
+ * Only fires when the caller used `{ throwOnError: true }`. Callers that
9
+ * read `result.error` directly (the result-tuple path) get the parsed
10
+ * body unchanged so existing field-level reads (`.error.name`,
11
+ * `JSON.stringify(error)`, etc.) are byte-for-byte identical to before.
12
+ */
13
+ export declare function wrapClientError(error: unknown, response: Response | undefined, request: Request | undefined, opts: {
14
+ throwOnError?: boolean;
15
+ } | undefined): unknown;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Wrap whatever the generated client decoded from a non-2xx error body
3
+ * into a real `Error` so downstream formatters (TUI, plugins) get a
4
+ * useful `.message` instead of `[object Object]` or blank. The original
5
+ * parsed body and status live under `.cause` for callers that need
6
+ * structured fields.
7
+ *
8
+ * Only fires when the caller used `{ throwOnError: true }`. Callers that
9
+ * read `result.error` directly (the result-tuple path) get the parsed
10
+ * body unchanged so existing field-level reads (`.error.name`,
11
+ * `JSON.stringify(error)`, etc.) are byte-for-byte identical to before.
12
+ */
13
+ export function wrapClientError(error, response, request, opts) {
14
+ if (!opts?.throwOnError)
15
+ return error;
16
+ if (error instanceof Error)
17
+ return error;
18
+ // NamedError-shaped responses (the common case for opencode 4xx) come
19
+ // through as POJOs — extract a useful message first, then wrap.
20
+ if (typeof error === "object" && error !== null && Object.keys(error).length > 0) {
21
+ const obj = error;
22
+ const message = (typeof obj.data?.message === "string" && obj.data.message) ||
23
+ (typeof obj.message === "string" && obj.message) ||
24
+ (typeof obj.name === "string" && obj.name) ||
25
+ describe(request, response);
26
+ return new Error(message, { cause: { body: error, status: response?.status } });
27
+ }
28
+ if (typeof error === "string" && error.length > 0) {
29
+ return new Error(error, { cause: { body: error, status: response?.status } });
30
+ }
31
+ // Empty body / network failure / undefined / null / empty object.
32
+ const reason = response ? "(empty response body)" : "network error (no response)";
33
+ return new Error(`opencode server ${describe(request, response)}: ${reason}`, {
34
+ cause: { body: error, status: response?.status },
35
+ });
36
+ }
37
+ function describe(request, response) {
38
+ const method = request?.method ?? "?";
39
+ const url = request?.url ?? "?";
40
+ const status = response?.status;
41
+ const statusText = response?.statusText;
42
+ return `${method} ${url}${status ? " → " + status : ""}${statusText ? " " + statusText : ""}`;
43
+ }
@@ -911,7 +911,7 @@ export type ProviderConfig = {
911
911
  output: Array<"text" | "audio" | "image" | "video" | "pdf">;
912
912
  };
913
913
  experimental?: boolean;
914
- status?: "alpha" | "beta" | "deprecated";
914
+ status?: "alpha" | "beta" | "deprecated" | "active";
915
915
  options?: {
916
916
  [key: string]: unknown;
917
917
  };
@@ -2619,7 +2619,7 @@ export type ProviderListResponses = {
2619
2619
  output: Array<"text" | "audio" | "image" | "video" | "pdf">;
2620
2620
  };
2621
2621
  experimental?: boolean;
2622
- status?: "alpha" | "beta" | "deprecated";
2622
+ status?: "alpha" | "beta" | "deprecated" | "active";
2623
2623
  options: {
2624
2624
  [key: string]: unknown;
2625
2625
  };
package/dist/v2/client.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./gen/types.gen.js";
2
2
  import { createClient } from "./gen/client/client.gen.js";
3
3
  import { OpencodeClient } from "./gen/sdk.gen.js";
4
+ import { wrapClientError } from "../error-interceptor.js";
4
5
  export { OpencodeClient };
5
6
  function pick(value, fallback, encode) {
6
7
  if (!value)
@@ -72,25 +73,6 @@ export function createOpencodeClient(config) {
72
73
  throw new Error("Request is not supported by this version of OpenCode Server (Server responded with text/html)");
73
74
  return response;
74
75
  });
75
- // The generated client falls back to throwing a literal `{}` when the server
76
- // responds with an empty / unparseable error body, which surfaces as a bare
77
- // `{}` in TUI / CLI error output. Wrap ONLY that case in a real Error so
78
- // downstream formatters get a useful message — but pass through any parsed
79
- // JSON error body unchanged so existing consumers can still inspect fields.
80
- client.interceptors.error.use((error, response, request) => {
81
- const isEmpty = error === undefined ||
82
- error === null ||
83
- error === "" ||
84
- (typeof error === "object" && !(error instanceof Error) && Object.keys(error).length === 0);
85
- if (!isEmpty)
86
- return error;
87
- const method = request?.method ?? "?";
88
- const url = request?.url ?? "?";
89
- if (!response)
90
- return new Error(`opencode server ${method} ${url}: network error (no response)`);
91
- const status = response.status;
92
- const statusText = response.statusText ? " " + response.statusText : "";
93
- return new Error(`opencode server ${method} ${url} → ${status}${statusText}: (empty response body)`);
94
- });
76
+ client.interceptors.error.use(wrapClientError);
95
77
  return new OpencodeClient({ client });
96
78
  }
@@ -1304,6 +1304,13 @@ export declare class Session3 extends HeyApiClient {
1304
1304
  list<ThrowOnError extends boolean = false>(parameters?: {
1305
1305
  directory?: string;
1306
1306
  workspace?: string;
1307
+ limit?: number;
1308
+ order?: "asc" | "desc";
1309
+ path?: string;
1310
+ roots?: boolean | "true" | "false";
1311
+ start?: number;
1312
+ search?: string;
1313
+ cursor?: string;
1307
1314
  }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<V2SessionListResponses, V2SessionListErrors, ThrowOnError, "fields">;
1308
1315
  /**
1309
1316
  * Send v2 message
@@ -1356,6 +1363,9 @@ export declare class Session3 extends HeyApiClient {
1356
1363
  sessionID: string;
1357
1364
  directory?: string;
1358
1365
  workspace?: string;
1366
+ limit?: number;
1367
+ order?: "asc" | "desc";
1368
+ cursor?: string;
1359
1369
  }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<V2SessionMessagesResponses, V2SessionMessagesErrors, ThrowOnError, "fields">;
1360
1370
  }
1361
1371
  export declare class V2 extends HeyApiClient {
@@ -2614,6 +2614,13 @@ export class Session3 extends HeyApiClient {
2614
2614
  args: [
2615
2615
  { in: "query", key: "directory" },
2616
2616
  { in: "query", key: "workspace" },
2617
+ { in: "query", key: "limit" },
2618
+ { in: "query", key: "order" },
2619
+ { in: "query", key: "path" },
2620
+ { in: "query", key: "roots" },
2621
+ { in: "query", key: "start" },
2622
+ { in: "query", key: "search" },
2623
+ { in: "query", key: "cursor" },
2617
2624
  ],
2618
2625
  },
2619
2626
  ]);
@@ -2726,6 +2733,9 @@ export class Session3 extends HeyApiClient {
2726
2733
  { in: "path", key: "sessionID" },
2727
2734
  { in: "query", key: "directory" },
2728
2735
  { in: "query", key: "workspace" },
2736
+ { in: "query", key: "limit" },
2737
+ { in: "query", key: "order" },
2738
+ { in: "query", key: "cursor" },
2729
2739
  ],
2730
2740
  },
2731
2741
  ]);
@@ -38,8 +38,8 @@ export type PermissionRequest = {
38
38
  };
39
39
  };
40
40
  export type SnapshotFileDiff = {
41
- file: string;
42
- patch: string;
41
+ file?: string;
42
+ patch?: string;
43
43
  additions: number;
44
44
  deletions: number;
45
45
  status?: "added" | "deleted" | "modified";
@@ -739,7 +739,7 @@ export type ProviderConfig = {
739
739
  output: Array<"text" | "audio" | "image" | "video" | "pdf">;
740
740
  };
741
741
  experimental?: boolean;
742
- status?: "alpha" | "beta" | "deprecated";
742
+ status?: "alpha" | "beta" | "deprecated" | "active";
743
743
  provider?: {
744
744
  npm?: string;
745
745
  api?: string;
@@ -1158,7 +1158,7 @@ export type VcsFileStatus = {
1158
1158
  };
1159
1159
  export type VcsFileDiff = {
1160
1160
  file: string;
1161
- patch: string;
1161
+ patch?: string;
1162
1162
  additions: number;
1163
1163
  deletions: number;
1164
1164
  status?: "added" | "deleted" | "modified";
@@ -5249,6 +5249,16 @@ export type V2SessionListData = {
5249
5249
  query?: {
5250
5250
  directory?: string;
5251
5251
  workspace?: string;
5252
+ limit?: number;
5253
+ order?: "asc" | "desc";
5254
+ path?: string;
5255
+ roots?: boolean | "true" | "false";
5256
+ start?: number;
5257
+ search?: string;
5258
+ /**
5259
+ * Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response. Do not combine with order or filters.
5260
+ */
5261
+ cursor?: string;
5252
5262
  };
5253
5263
  url: "/api/session";
5254
5264
  };
@@ -5349,6 +5359,12 @@ export type V2SessionMessagesData = {
5349
5359
  query?: {
5350
5360
  directory?: string;
5351
5361
  workspace?: string;
5362
+ limit?: number;
5363
+ order?: "asc" | "desc";
5364
+ /**
5365
+ * Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response. Do not combine with order.
5366
+ */
5367
+ cursor?: string;
5352
5368
  };
5353
5369
  url: "/api/session/{sessionID}/message";
5354
5370
  };
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": "1.14.44",
4
+ "version": "1.14.46",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {