opencode-websearch-deepseek 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.
Files changed (2) hide show
  1. package/dist/index.js +19 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -51,6 +51,23 @@ function readEnv(name, env = process.env) {
51
51
  const value = env[name];
52
52
  return value && value.trim() ? value.trim() : undefined;
53
53
  }
54
+ /**
55
+ * Rethrow the cancellation reason from `signal`. `Error` and `DOMException`
56
+ * (e.g. `AbortError`) are preserved as-is; other values (primitives) are
57
+ * normalised to an `Error` so callers always receive one.
58
+ */
59
+ function throwCancellation(signal, fallback) {
60
+ const reason = signal.reason;
61
+ if (reason instanceof Error)
62
+ throw reason;
63
+ if (typeof reason === "object" && reason !== null)
64
+ throw reason;
65
+ if (reason !== undefined && reason !== null)
66
+ throw new Error(String(reason));
67
+ if (fallback instanceof Error)
68
+ throw fallback;
69
+ throw new Error("The web search was aborted");
70
+ }
54
71
  /**
55
72
  * Resolve the `max_uses` value for the search tool declaration.
56
73
  * Falls back to {@link DEFAULT_MAX_USES} for missing or invalid input.
@@ -220,7 +237,7 @@ export const plugin = {
220
237
  const text = await response.text().catch((error) => {
221
238
  // Preserve cancellation: never turn an abort into an API error.
222
239
  if (signal?.aborted)
223
- throw signal.reason ?? error;
240
+ return throwCancellation(signal, error);
224
241
  if (error?.name === "AbortError")
225
242
  throw error;
226
243
  return "";
@@ -228,7 +245,7 @@ export const plugin = {
228
245
  // An abort can also arrive after the body resolves; re-check so it
229
246
  // is not masked as an API error.
230
247
  if (signal?.aborted)
231
- throw signal.reason ?? new Error("The web search was aborted");
248
+ throwCancellation(signal, undefined);
232
249
  throw new Error(`DeepSeek API error ${response.status}: ${text.slice(0, 300)}`);
233
250
  }
234
251
  const data = (await response.json());
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "opencode-websearch-deepseek",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "DeepSeek-powered web search provider for OpenCode's built-in websearch tool.",
6
6
  "type": "module",
7
7
  "license": "MIT",