opencode-websearch-deepseek 0.1.2 → 0.2.0

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
@@ -63,8 +63,8 @@ in:
63
63
 
64
64
  | Variable | Required | Default | Description |
65
65
  | ------------------- | -------- | ------------------ | ------------------------------------------------------------------ |
66
- | `DEEPSEEK_API_KEY` | yes | — | DeepSeek API key. |
67
- | `WEBSEARCH_API_KEY` | no | — | Fallback key used when `DEEPSEEK_API_KEY` is not set. |
66
+ | `DEEPSEEK_API_KEY` | no\* | — | DeepSeek API key (takes precedence over the stored credential). |
67
+ | `WEBSEARCH_API_KEY` | no | — | Fallback env key used when `DEEPSEEK_API_KEY` is not set. |
68
68
  | `WEBSEARCH_MODEL` | no | `deepseek-v4-flash`| Model used for search and synthesis. |
69
69
  | `WEBSEARCH_MAX_USES`| no | `5` | Max server-side searches per query (positive integer). |
70
70
  | `WEBSEARCH_THINKING`| no | `enabled` | `enabled` or `disabled`; disables extended thinking when set to `disabled`. |
@@ -72,6 +72,11 @@ in:
72
72
  > `WEBSEARCH_MODEL` is passed through as-is. DeepSeek maps unknown model names
73
73
  > to its default, so any server-side-search-capable DeepSeek model works.
74
74
 
75
+ > \* If no environment key is set, the plugin reuses the API key OpenCode
76
+ > stores for the `deepseek` provider (for example after `opencode auth login`),
77
+ > so no environment variable is required when that provider is already
78
+ > authenticated.
79
+
75
80
  > The plugin always selects the DeepSeek provider. Without an API key, a
76
81
  > `websearch` call fails with a clear error rather than silently falling back
77
82
  > to a different provider.
package/dist/index.d.ts CHANGED
@@ -83,12 +83,32 @@ interface WebsearchEditor {
83
83
  set(providerID: string | false): void;
84
84
  };
85
85
  }
86
+ /** A credential returned by OpenCode for a configured provider. */
87
+ export interface StoredCredential {
88
+ type?: string;
89
+ key?: string;
90
+ }
91
+ /** Minimal slice of OpenCode's integration API used to read a stored provider key. */
92
+ export interface IntegrationContext {
93
+ connection: {
94
+ active(integrationID: string): Promise<unknown>;
95
+ resolve(connection: unknown): Promise<StoredCredential | undefined>;
96
+ };
97
+ }
86
98
  /** Context passed to the plugin's `setup`. */
87
99
  export interface WebsearchContext {
88
100
  websearch: {
89
101
  transform(callback: (editor: WebsearchEditor) => void): Promise<unknown> | unknown;
90
102
  };
103
+ /** Present in OpenCode 2.x; used to reuse the DeepSeek provider credential. */
104
+ integration?: IntegrationContext;
91
105
  }
106
+ /**
107
+ * Resolve the DeepSeek API key. An explicit environment variable takes
108
+ * precedence; otherwise the key OpenCode stores for the `deepseek` provider
109
+ * (configured via `opencode auth login`) is used.
110
+ */
111
+ export declare function resolveApiKey(ctx: WebsearchContext): Promise<string | undefined>;
92
112
  /**
93
113
  * Resolve the `max_uses` value for the search tool declaration.
94
114
  * Falls back to {@link DEFAULT_MAX_USES} for missing or invalid input.
package/dist/index.js CHANGED
@@ -46,6 +46,30 @@ export const SYSTEM_PROMPT = [
46
46
  "",
47
47
  "Your response must be the final answer, not another search request.",
48
48
  ].join("\n");
49
+ /**
50
+ * Resolve the DeepSeek API key. An explicit environment variable takes
51
+ * precedence; otherwise the key OpenCode stores for the `deepseek` provider
52
+ * (configured via `opencode auth login`) is used.
53
+ */
54
+ export async function resolveApiKey(ctx) {
55
+ const fromEnv = readEnv("DEEPSEEK_API_KEY") ?? readEnv("WEBSEARCH_API_KEY");
56
+ if (fromEnv)
57
+ return fromEnv;
58
+ const integration = ctx.integration;
59
+ if (!integration)
60
+ return undefined;
61
+ try {
62
+ const connection = await integration.connection.active("deepseek");
63
+ if (!connection)
64
+ return undefined;
65
+ const credential = await integration.connection.resolve(connection);
66
+ const key = credential?.key;
67
+ return typeof key === "string" && key.trim() ? key.trim() : undefined;
68
+ }
69
+ catch {
70
+ return undefined;
71
+ }
72
+ }
49
73
  /** Read an environment variable, treating blank strings as unset. */
50
74
  function readEnv(name, env = process.env) {
51
75
  const value = env[name];
@@ -211,9 +235,9 @@ export const plugin = {
211
235
  id: "deepseek",
212
236
  name: "DeepSeek Web Search",
213
237
  execute: async ({ query }, { signal } = {}) => {
214
- const apiKey = readEnv("DEEPSEEK_API_KEY") ?? readEnv("WEBSEARCH_API_KEY");
238
+ const apiKey = await resolveApiKey(ctx);
215
239
  if (!apiKey) {
216
- throw new Error("DEEPSEEK_API_KEY is not set in the OpenCode environment");
240
+ throw new Error("DEEPSEEK_API_KEY is not set and no stored DeepSeek credential was found; set the env var or sign in to the deepseek provider in OpenCode");
217
241
  }
218
242
  if (!/^[\x21-\x7e]+$/.test(apiKey)) {
219
243
  throw new Error("The API key contains invalid characters");
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.2",
4
+ "version": "0.2.0",
5
5
  "description": "DeepSeek-powered web search provider for OpenCode's built-in websearch tool.",
6
6
  "type": "module",
7
7
  "license": "MIT",