@opencode-ai/sdk 1.14.44 → 1.14.45

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
  }
@@ -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";
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.45",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {