opencode-websearch 0.2.4 → 0.3.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
@@ -1,6 +1,6 @@
1
1
  # opencode-websearch
2
2
 
3
- Web search plugin for [OpenCode](https://opencode.ai), powered by Anthropic's server-side `web_search` API. A port of the Claude Code WebSearch tool to OpenCode.
3
+ Web search plugin for [OpenCode](https://opencode.ai), powered by Anthropic's server-side [`web_search` tool](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/web-search-tool). Gives any OpenCode model access to real-time web results with source citations -- the same web search capability available in Claude Code, brought to OpenCode.
4
4
 
5
5
  ## Install
6
6
 
@@ -16,9 +16,24 @@ OpenCode will install it automatically at startup.
16
16
 
17
17
  ## Configuration
18
18
 
19
- The plugin looks for an Anthropic provider (`@ai-sdk/anthropic`) with `"websearch": true` set on at least one model. It picks up credentials however you've configured them in OpenCode -- via `/connect`, environment variables, or `options.apiKey` in your config.
19
+ The plugin scans your OpenCode providers for any that use `@ai-sdk/anthropic` and picks up credentials however you've configured them -- via `/connect`, environment variables, or `options.apiKey` in your config.
20
20
 
21
- Add `"websearch": true` to the model you want the plugin to use for searches:
21
+ Tag a model with `"websearch": "auto"` or `"websearch": "always"` to control how web search selects its model.
22
+
23
+ ### Model selection
24
+
25
+ The plugin dynamically chooses which Anthropic model to use for each search, following this priority chain:
26
+
27
+ | Priority | Condition | Behavior |
28
+ | -------- | ----------------------------------- | --------------------------------------------------------------------------- |
29
+ | 1 | A model is tagged `"always"` | That model is **always** used, regardless of what you're chatting with |
30
+ | 2 | Your active chat model is Anthropic | The active model is used directly -- no extra configuration needed |
31
+ | 3 | A model is tagged `"auto"` | That model is used as a **fallback** when the active model is non-Anthropic |
32
+ | 4 | None of the above | An error is returned |
33
+
34
+ ### `"auto"` mode (recommended)
35
+
36
+ Use `"auto"` when you want web search to work seamlessly whether you're chatting with an Anthropic model or not. When your active model is Anthropic, it's used directly; otherwise the tagged model kicks in as a fallback.
22
37
 
23
38
  ```json
24
39
  {
@@ -27,7 +42,7 @@ Add `"websearch": true` to the model you want the plugin to use for searches:
27
42
  "models": {
28
43
  "claude-sonnet-4-5": {
29
44
  "options": {
30
- "websearch": true
45
+ "websearch": "auto"
31
46
  }
32
47
  }
33
48
  }
@@ -36,6 +51,28 @@ Add `"websearch": true` to the model you want the plugin to use for searches:
36
51
  }
37
52
  ```
38
53
 
54
+ ### `"always"` mode
55
+
56
+ Use `"always"` to hard-lock web search to a specific model. This is useful when you want a cheaper or faster model to always handle searches, no matter what you're chatting with.
57
+
58
+ ```json
59
+ {
60
+ "provider": {
61
+ "anthropic": {
62
+ "models": {
63
+ "claude-haiku-3-5": {
64
+ "options": {
65
+ "websearch": "always"
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### Custom providers
75
+
39
76
  This also works with custom providers that use `@ai-sdk/anthropic`, such as a LiteLLM proxy:
40
77
 
41
78
  ```json
@@ -50,7 +87,7 @@ This also works with custom providers that use `@ai-sdk/anthropic`, such as a Li
50
87
  "models": {
51
88
  "claude-sonnet-4-5": {
52
89
  "options": {
53
- "websearch": true
90
+ "websearch": "auto"
54
91
  }
55
92
  }
56
93
  }
@@ -59,21 +96,6 @@ This also works with custom providers that use `@ai-sdk/anthropic`, such as a Li
59
96
  }
60
97
  ```
61
98
 
62
- ## Usage
63
-
64
- Once configured, the `web-search` tool is available to the AI agent. It accepts:
65
-
66
- | Argument | Type | Required | Description |
67
- |---|---|---|---|
68
- | `query` | `string` | Yes | The search query |
69
- | `allowed_domains` | `string[]` | No | Restrict results to these domains |
70
- | `blocked_domains` | `string[]` | No | Exclude results from these domains |
71
- | `max_uses` | `number` (1-10) | No | Max searches per invocation (default: 5) |
72
-
73
- You cannot specify both `allowed_domains` and `blocked_domains` at the same time.
74
-
75
- Results are returned as formatted markdown with source links.
76
-
77
99
  ## Development
78
100
 
79
101
  ### Local Development
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnthropicConfig } from "./types.js";
1
+ import { ProviderResolution } from "./types.js";
2
2
  interface ProviderData {
3
3
  id: string;
4
4
  key?: string;
@@ -12,10 +12,17 @@ interface ProviderData {
12
12
  options: Record<string, unknown>;
13
13
  }
14
14
  /**
15
- * Scan providers returned by the SDK for the first Anthropic model
16
- * with `websearch: true` set in its options.
15
+ * Scan providers for Anthropic credentials and any websearch-tagged models.
16
+ *
17
+ * Resolution priority:
18
+ * - `lockedModel`: first model with `"websearch": "always"` (hard lock)
19
+ * - `fallbackModel`: first model with `"websearch": "auto"` (soft fallback)
20
+ * - `credentials`: API key + optional baseURL from the first Anthropic provider
21
+ *
22
+ * Returns `null` if no Anthropic provider with a valid API key is found.
17
23
  */
18
- declare const resolveFromProviders: (providers: ProviderData[]) => AnthropicConfig | null;
19
- declare const formatConfigError: () => string;
20
- export { formatConfigError, ProviderData, resolveFromProviders };
24
+ declare const resolveFromProviders: (providers: ProviderData[]) => ProviderResolution | null;
25
+ declare const formatNoProviderError: () => string;
26
+ declare const formatNonAnthropicError: (activeModelID: string) => string;
27
+ export { formatNoProviderError, formatNonAnthropicError, ProviderData, resolveFromProviders };
21
28
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7C,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IAC/F,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AA4BD;;;GAGG;AACH,QAAA,MAAM,oBAAoB,GAAI,WAAW,YAAY,EAAE,KAAG,eAAe,GAAG,IAiB3E,CAAC;AAIF,QAAA,MAAM,iBAAiB,QAAO,MA6B0B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAItE,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IAC/F,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AA0ED;;;;;;;;;GASG;AACH,QAAA,MAAM,oBAAoB,GAAI,WAAW,YAAY,EAAE,KAAG,kBAAkB,GAAG,IAgB9E,CAAC;AAIF,QAAA,MAAM,qBAAqB,QAAO,MAoBsB,CAAC;AAEzD,QAAA,MAAM,uBAAuB,GAAI,eAAe,MAAM,KAAG,MAuBiD,CAAC;AAE3G,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC"}
@@ -6,5 +6,7 @@ declare const MIN_QUERY_LENGTH = 2;
6
6
  declare const MONTH_OFFSET = 1;
7
7
  declare const PAD_LENGTH = 2;
8
8
  declare const SEARCH_SYSTEM_PROMPT = "You are an assistant for performing a web search tool use";
9
- export { ANTHROPIC_NPM_PACKAGE, DEFAULT_SEARCH_USES, EMPTY_LENGTH, MAX_RESPONSE_TOKENS, MIN_QUERY_LENGTH, MONTH_OFFSET, PAD_LENGTH, SEARCH_SYSTEM_PROMPT, };
9
+ declare const WEBSEARCH_ALWAYS = "always";
10
+ declare const WEBSEARCH_AUTO = "auto";
11
+ export { ANTHROPIC_NPM_PACKAGE, DEFAULT_SEARCH_USES, EMPTY_LENGTH, MAX_RESPONSE_TOKENS, MIN_QUERY_LENGTH, MONTH_OFFSET, PAD_LENGTH, SEARCH_SYSTEM_PROMPT, WEBSEARCH_ALWAYS, WEBSEARCH_AUTO, };
10
12
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,qBAAqB,sBAAsB,CAAC;AAClD,QAAA,MAAM,mBAAmB,IAAI,CAAC;AAC9B,QAAA,MAAM,YAAY,IAAI,CAAC;AACvB,QAAA,MAAM,mBAAmB,QAAS,CAAC;AACnC,QAAA,MAAM,gBAAgB,IAAI,CAAC;AAC3B,QAAA,MAAM,YAAY,IAAI,CAAC;AACvB,QAAA,MAAM,UAAU,IAAI,CAAC;AACrB,QAAA,MAAM,oBAAoB,8DAA8D,CAAC;AAEzF,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,oBAAoB,GACrB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,qBAAqB,sBAAsB,CAAC;AAClD,QAAA,MAAM,mBAAmB,IAAI,CAAC;AAC9B,QAAA,MAAM,YAAY,IAAI,CAAC;AACvB,QAAA,MAAM,mBAAmB,QAAS,CAAC;AACnC,QAAA,MAAM,gBAAgB,IAAI,CAAC;AAC3B,QAAA,MAAM,YAAY,IAAI,CAAC;AACvB,QAAA,MAAM,UAAU,IAAI,CAAC;AACrB,QAAA,MAAM,oBAAoB,8DAA8D,CAAC;AACzF,QAAA,MAAM,gBAAgB,WAAW,CAAC;AAClC,QAAA,MAAM,cAAc,SAAS,CAAC;AAE9B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,GACf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  declare const _default: (input: import("@opencode-ai/plugin").PluginInput) => Promise<{
2
+ "chat.message": (hookInput: {
3
+ sessionID: string;
4
+ agent?: string;
5
+ model?: {
6
+ providerID: string;
7
+ modelID: string;
8
+ };
9
+ messageID?: string;
10
+ variant?: string;
11
+ }) => Promise<void>;
2
12
  tool: {
3
13
  "web-search": {
4
14
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA2BA,wBAgEoB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwFA,wBAoFoB"}
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // src/index.ts
2
- import { tool } from "@opencode-ai/plugin";
3
-
4
1
  // src/constants.ts
5
2
  var ANTHROPIC_NPM_PACKAGE = "@ai-sdk/anthropic";
6
3
  var DEFAULT_SEARCH_USES = 8;
@@ -8,10 +5,21 @@ var EMPTY_LENGTH = 0;
8
5
  var MAX_RESPONSE_TOKENS = 16000;
9
6
  var MIN_QUERY_LENGTH = 2;
10
7
  var SEARCH_SYSTEM_PROMPT = "You are an assistant for performing a web search tool use";
8
+ var WEBSEARCH_ALWAYS = "always";
9
+ var WEBSEARCH_AUTO = "auto";
10
+
11
+ // src/index.ts
12
+ import { tool } from "@opencode-ai/plugin";
11
13
 
12
14
  // src/config.ts
13
- var isAnthropicModel = (model) => model.api.npm === ANTHROPIC_NPM_PACKAGE;
14
- var hasWebSearch = (model) => model.options.websearch === true;
15
+ var isAnthropicProvider = (model) => model.api.npm === ANTHROPIC_NPM_PACKAGE;
16
+ var getWebsearchOption = (model) => {
17
+ const value = model.options.websearch;
18
+ if (value === WEBSEARCH_ALWAYS || value === WEBSEARCH_AUTO) {
19
+ return value;
20
+ }
21
+ return null;
22
+ };
15
23
  var normalizeBaseURL = (url) => url.replace(/\/v1\/?$/, "");
16
24
  var extractApiKey = (options) => {
17
25
  if (typeof options.apiKey !== "string") {
@@ -25,41 +33,82 @@ var extractBaseURL = (options) => {
25
33
  }
26
34
  return normalizeBaseURL(options.baseURL);
27
35
  };
36
+ var extractCredentials = (provider) => {
37
+ const apiKey = provider.key ?? extractApiKey(provider.options);
38
+ if (!apiKey) {
39
+ return null;
40
+ }
41
+ return { apiKey, baseURL: extractBaseURL(provider.options) };
42
+ };
43
+ var processProviderModel = (provider, model, accumulated) => {
44
+ if (!isAnthropicProvider(model)) {
45
+ return;
46
+ }
47
+ if (!accumulated.credentials) {
48
+ accumulated.credentials = extractCredentials(provider);
49
+ }
50
+ const option = getWebsearchOption(model);
51
+ if (option === WEBSEARCH_ALWAYS && !accumulated.lockedModel) {
52
+ accumulated.lockedModel = model.id;
53
+ }
54
+ if (option === WEBSEARCH_AUTO && !accumulated.fallbackModel) {
55
+ accumulated.fallbackModel = model.id;
56
+ }
57
+ };
58
+ var scanProviderModels = (provider, accumulated) => {
59
+ for (const model of Object.values(provider.models)) {
60
+ processProviderModel(provider, model, accumulated);
61
+ }
62
+ };
28
63
  var resolveFromProviders = (providers) => {
64
+ const result = { credentials: null };
29
65
  for (const provider of providers) {
30
- for (const model of Object.values(provider.models)) {
31
- if (isAnthropicModel(model) && hasWebSearch(model)) {
32
- const apiKey = provider.key ?? extractApiKey(provider.options);
33
- if (!apiKey) {
34
- return null;
35
- }
36
- return {
37
- apiKey,
38
- baseURL: extractBaseURL(provider.options),
39
- model: model.id
40
- };
41
- }
42
- }
66
+ scanProviderModels(provider, result);
43
67
  }
44
- return null;
68
+ if (!result.credentials) {
69
+ return null;
70
+ }
71
+ return {
72
+ credentials: result.credentials,
73
+ fallbackModel: result.fallbackModel,
74
+ lockedModel: result.lockedModel
75
+ };
45
76
  };
46
- var formatConfigError = () => `Error: web-search requires an Anthropic provider with \`websearch: true\` set on at least one model.
77
+ var formatNoProviderError = () => `Error: web-search requires an Anthropic provider.
47
78
 
48
- No model with \`"websearch": true\` was found in your opencode.json configuration.
79
+ No Anthropic provider with a valid API key was found in your opencode.json configuration.
49
80
 
50
- To fix this, add an Anthropic provider to your opencode.json and set \`"websearch": true\` in the options of the model you want to use for web searches:
81
+ To fix this, add an Anthropic provider to your opencode.json:
51
82
 
52
83
  {
53
84
  "provider": {
54
85
  "anthropic": {
55
- "npm": "@ai-sdk/anthropic",
56
86
  "options": {
57
87
  "apiKey": "{env:ANTHROPIC_API_KEY}"
58
- },
88
+ }
89
+ }
90
+ }
91
+ }
92
+
93
+ Steps:
94
+ 1. Open your opencode.json (project root, .opencode/, or ~/.config/opencode/)
95
+ 2. Ensure you have an Anthropic provider configured with a valid API key
96
+ 3. Restart OpenCode to pick up the configuration change`;
97
+ var formatNonAnthropicError = (activeModelID) => `Error: your current model (${activeModelID}) does not support web search.
98
+
99
+ Web search uses Anthropic's server-side web_search tool, which only works with Anthropic models.
100
+
101
+ You can either:
102
+ 1. Switch to an Anthropic model (e.g. claude-sonnet-4-5)
103
+ 2. Set \`"websearch": "auto"\` on an Anthropic model to use it as a fallback:
104
+
105
+ {
106
+ "provider": {
107
+ "anthropic": {
59
108
  "models": {
60
109
  "claude-sonnet-4-5": {
61
110
  "options": {
62
- "websearch": true
111
+ "websearch": "auto"
63
112
  }
64
113
  }
65
114
  }
@@ -67,11 +116,7 @@ To fix this, add an Anthropic provider to your opencode.json and set \`"websearc
67
116
  }
68
117
  }
69
118
 
70
- Steps:
71
- 1. Open your opencode.json (project root, .opencode/opencode.json, or ~/.config/opencode/opencode.json)
72
- 2. Ensure you have an Anthropic provider configured with a valid API key
73
- 3. Add \`"websearch": true\` to the \`options\` of the Claude model you want to use for web search
74
- 4. Restart OpenCode to pick up the configuration change`;
119
+ Or set \`"websearch": "always"\` to always use that model for web search regardless of your active model.`;
75
120
 
76
121
  // src/providers/anthropic.ts
77
122
  import Anthropic, { APIError } from "@anthropic-ai/sdk";
@@ -156,16 +201,56 @@ var executeSearch = async (config, args) => {
156
201
  var getCurrentMonthYear = () => new Date().toLocaleDateString("en-US", { month: "long", year: "numeric" });
157
202
 
158
203
  // src/index.ts
159
- var resolveConfig = async (client) => {
160
- const { data } = await client.config.providers();
161
- if (data) {
162
- return resolveFromProviders(data.providers);
204
+ var resolveSearchModel = (resolution, active) => {
205
+ if (resolution.lockedModel) {
206
+ return resolution.lockedModel;
207
+ }
208
+ if (active) {
209
+ return active.modelID;
210
+ }
211
+ if (resolution.fallbackModel) {
212
+ return resolution.fallbackModel;
163
213
  }
164
214
  return null;
165
215
  };
216
+ var isAnthropicActive = (active, providers) => {
217
+ if (!active) {
218
+ return false;
219
+ }
220
+ for (const provider of providers) {
221
+ for (const model of Object.values(provider.models)) {
222
+ if (model.id === active.modelID && model.api.npm === ANTHROPIC_NPM_PACKAGE) {
223
+ return true;
224
+ }
225
+ }
226
+ }
227
+ return false;
228
+ };
229
+ var resolveProviderState = async (client) => {
230
+ const { data } = await client.config.providers();
231
+ if (!data) {
232
+ return { list: [], resolution: null };
233
+ }
234
+ const list = data.providers;
235
+ return { list, resolution: resolveFromProviders(list) };
236
+ };
237
+ var buildSearchConfig = (resolution, modelID) => ({
238
+ apiKey: resolution.credentials.apiKey,
239
+ baseURL: resolution.credentials.baseURL,
240
+ model: modelID
241
+ });
166
242
  var src_default = async (input) => {
167
- let config = null;
243
+ let state = null;
244
+ const activeModels = new Map;
168
245
  return {
246
+ "chat.message": async (hookInput) => {
247
+ if (hookInput.model) {
248
+ activeModels.set(hookInput.sessionID, {
249
+ modelID: hookInput.model.modelID,
250
+ providerID: hookInput.model.providerID
251
+ });
252
+ }
253
+ },
169
254
  tool: {
170
255
  "web-search": tool({
171
256
  args: {
@@ -197,18 +282,23 @@ Usage notes:
197
282
  IMPORTANT - Use the correct year in search queries:
198
283
  - It is currently ${getCurrentMonthYear()}. You MUST use this when searching for recent information, documentation, or current events.
199
284
  - Example: If the user asks for "latest React docs", search for "React documentation" with the current year, NOT last year`,
200
- async execute(args) {
201
- if (!config) {
202
- config = await resolveConfig(input.client);
285
+ async execute(args, context) {
286
+ if (!state) {
287
+ state = await resolveProviderState(input.client);
203
288
  }
204
- if (!config) {
205
- return formatConfigError();
289
+ if (!state.resolution) {
290
+ return formatNoProviderError();
206
291
  }
207
292
  if (args.allowed_domains && args.blocked_domains) {
208
293
  return "Error: Cannot specify both allowed_domains and blocked_domains.";
209
294
  }
295
+ const active = activeModels.get(context.sessionID);
296
+ const modelID = resolveSearchModel(state.resolution, isAnthropicActive(active, state.list) ? active : undefined);
297
+ if (!modelID) {
298
+ return formatNonAnthropicError(active?.modelID ?? "unknown");
299
+ }
210
300
  try {
211
- return await executeSearch(config, args);
301
+ return await executeSearch(buildSearchConfig(state.resolution, modelID), args);
212
302
  } catch (error) {
213
303
  return formatErrorMessage(error);
214
304
  }
@@ -1,6 +1,6 @@
1
- import { AnthropicConfig } from "../types.js";
1
+ import { SearchConfig } from "../types.js";
2
2
  declare const formatErrorMessage: (error: unknown) => string;
3
- declare const executeSearch: (config: AnthropicConfig, args: {
3
+ declare const executeSearch: (config: SearchConfig, args: {
4
4
  allowed_domains?: string[];
5
5
  blocked_domains?: string[];
6
6
  query: string;
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAiC,MAAM,aAAa,CAAC;AAgF7E,QAAA,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,MAQ5C,CAAC;AAcF,QAAA,MAAM,aAAa,GACjB,QAAQ,eAAe,EACvB,MAAM;IACJ,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf,KACA,OAAO,CAAC,MAAM,CAqBhB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,YAAY,EAAmB,MAAM,aAAa,CAAC;AAgF1E,QAAA,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,MAQ5C,CAAC;AAcF,QAAA,MAAM,aAAa,GACjB,QAAQ,YAAY,EACpB,MAAM;IACJ,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf,KACA,OAAO,CAAC,MAAM,CAqBhB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,39 @@
1
- interface AnthropicConfig {
1
+ /**
2
+ * Credentials needed to call the Anthropic API.
3
+ * Resolved from any Anthropic provider in the OpenCode config.
4
+ */
5
+ interface AnthropicCredentials {
6
+ apiKey: string;
7
+ baseURL?: string;
8
+ }
9
+ /**
10
+ * Fully resolved config for a single web search call:
11
+ * credentials + the specific model to use.
12
+ */
13
+ interface SearchConfig {
2
14
  apiKey: string;
3
15
  baseURL?: string;
4
16
  model: string;
5
17
  }
18
+ /**
19
+ * The result of scanning all providers at startup:
20
+ * - `credentials`: API key + optional base URL from the first Anthropic provider
21
+ * - `lockedModel`: model ID if a model has `websearch: "always"` (hard lock)
22
+ * - `fallbackModel`: model ID if a model has `"websearch": "auto"` (soft fallback)
23
+ */
24
+ interface ProviderResolution {
25
+ credentials: AnthropicCredentials;
26
+ fallbackModel?: string;
27
+ lockedModel?: string;
28
+ }
29
+ /**
30
+ * Tracks the model the user is currently chatting with,
31
+ * as reported by the `chat.message` hook.
32
+ */
33
+ interface ActiveModel {
34
+ modelID: string;
35
+ providerID: string;
36
+ }
6
37
  interface WebSearchResult {
7
38
  title: string;
8
39
  type: "web_search_result";
@@ -28,5 +59,5 @@ type ContentBlock = {
28
59
  text: string;
29
60
  type: "text";
30
61
  } | ServerToolUse | WebSearchToolResult;
31
- export { AnthropicConfig, ContentBlock, ServerToolUse, WebSearchResult, WebSearchToolResult };
62
+ export { ActiveModel, AnthropicCredentials, ContentBlock, ProviderResolution, SearchConfig, ServerToolUse, WebSearchResult, WebSearchToolResult, };
32
63
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAID,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,mBAAmB,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,mBAAmB;IAC3B,OAAO,EAAE,eAAe,EAAE,GAAG;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,8BAA8B,CAAA;KAAE,CAAC;IAC1F,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,wBAAwB,CAAC;CAChC;AAED,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,UAAU,oBAAoB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,UAAU,kBAAkB;IAC1B,WAAW,EAAE,oBAAoB,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAID;;;GAGG;AACH,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,mBAAmB,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,mBAAmB;IAC3B,OAAO,EAAE,eAAe,EAAE,GAAG;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,8BAA8B,CAAA;KAAE,CAAC;IAC1F,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,wBAAwB,CAAC;CAChC;AAED,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAEzF,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,mBAAmB,GACpB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-websearch",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Web search plugin for OpenCode, inspired by Claude Code's WebSearch tool",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",