opencode-websearch 0.2.0 → 0.2.1
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/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -61
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ interface ProviderData {
|
|
|
16
16
|
*/
|
|
17
17
|
declare const resolveFromProviders: (providers: ProviderData[]) => AnthropicConfig | null;
|
|
18
18
|
declare const formatConfigError: () => string;
|
|
19
|
-
export { formatConfigError, resolveFromProviders };
|
|
19
|
+
export { formatConfigError, ProviderData, resolveFromProviders };
|
|
20
20
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -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,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,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAqBD;;;GAGG;AACH,QAAA,MAAM,oBAAoB,GAAI,WAAW,YAAY,EAAE,KAAG,eAAe,GAAG,IAgB3E,CAAC;AAIF,QAAA,MAAM,iBAAiB,QAAO,MA6B0B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC"}
|
|
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,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,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAqBD;;;GAGG;AACH,QAAA,MAAM,oBAAoB,GAAI,WAAW,YAAY,EAAE,KAAG,eAAe,GAAG,IAgB3E,CAAC;AAIF,QAAA,MAAM,iBAAiB,QAAO,MA6B0B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,wBAsEoB"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,63 @@ var MIN_SEARCH_USES = 1;
|
|
|
10
10
|
// src/index.ts
|
|
11
11
|
import { tool } from "@opencode-ai/plugin";
|
|
12
12
|
|
|
13
|
+
// src/config.ts
|
|
14
|
+
var isAnthropicModel = (model) => model.api.npm === ANTHROPIC_NPM_PACKAGE;
|
|
15
|
+
var hasWebSearch = (model) => model.options.websearch === true;
|
|
16
|
+
var normalizeBaseURL = (url) => url.replace(/\/v1\/?$/, "");
|
|
17
|
+
var extractBaseURL = (options) => {
|
|
18
|
+
if (typeof options.baseURL !== "string") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return normalizeBaseURL(options.baseURL);
|
|
22
|
+
};
|
|
23
|
+
var resolveFromProviders = (providers) => {
|
|
24
|
+
for (const provider of providers) {
|
|
25
|
+
for (const model of Object.values(provider.models)) {
|
|
26
|
+
if (isAnthropicModel(model) && hasWebSearch(model)) {
|
|
27
|
+
if (!provider.key) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
apiKey: provider.key,
|
|
32
|
+
baseURL: extractBaseURL(provider.options),
|
|
33
|
+
model: model.id
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
var formatConfigError = () => `Error: web-search requires an Anthropic provider with \`websearch: true\` set on at least one model.
|
|
41
|
+
|
|
42
|
+
No model with \`"websearch": true\` was found in your opencode.json configuration.
|
|
43
|
+
|
|
44
|
+
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:
|
|
45
|
+
|
|
46
|
+
{
|
|
47
|
+
"provider": {
|
|
48
|
+
"anthropic": {
|
|
49
|
+
"npm": "@ai-sdk/anthropic",
|
|
50
|
+
"options": {
|
|
51
|
+
"apiKey": "{env:ANTHROPIC_API_KEY}"
|
|
52
|
+
},
|
|
53
|
+
"models": {
|
|
54
|
+
"claude-sonnet-4-5": {
|
|
55
|
+
"options": {
|
|
56
|
+
"websearch": true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Steps:
|
|
65
|
+
1. Open your opencode.json (project root, .opencode/opencode.json, or ~/.config/opencode/opencode.json)
|
|
66
|
+
2. Ensure you have an Anthropic provider configured with a valid API key
|
|
67
|
+
3. Add \`"websearch": true\` to the \`options\` of the Claude model you want to use for web search
|
|
68
|
+
4. Restart OpenCode to pick up the configuration change`;
|
|
69
|
+
|
|
13
70
|
// src/providers/anthropic.ts
|
|
14
71
|
import Anthropic, { APIError } from "@anthropic-ai/sdk";
|
|
15
72
|
var formatSearchResult = (result) => {
|
|
@@ -112,73 +169,19 @@ var executeSearch = async (config, args) => {
|
|
|
112
169
|
`) || "No results returned from web search.";
|
|
113
170
|
};
|
|
114
171
|
|
|
115
|
-
// src/config.ts
|
|
116
|
-
var isAnthropicModel = (model) => model.api.npm === ANTHROPIC_NPM_PACKAGE;
|
|
117
|
-
var hasWebSearch = (model) => model.options.websearch === true;
|
|
118
|
-
var normalizeBaseURL = (url) => url.replace(/\/v1\/?$/, "");
|
|
119
|
-
var extractBaseURL = (options) => {
|
|
120
|
-
if (typeof options.baseURL !== "string") {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
return normalizeBaseURL(options.baseURL);
|
|
124
|
-
};
|
|
125
|
-
var resolveFromProviders = (providers) => {
|
|
126
|
-
for (const provider of providers) {
|
|
127
|
-
for (const model of Object.values(provider.models)) {
|
|
128
|
-
if (isAnthropicModel(model) && hasWebSearch(model)) {
|
|
129
|
-
if (!provider.key) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
apiKey: provider.key,
|
|
134
|
-
baseURL: extractBaseURL(provider.options),
|
|
135
|
-
model: model.id
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
};
|
|
142
|
-
var formatConfigError = () => `Error: web-search requires an Anthropic provider with \`websearch: true\` set on at least one model.
|
|
143
|
-
|
|
144
|
-
No model with \`"websearch": true\` was found in your opencode.json configuration.
|
|
145
|
-
|
|
146
|
-
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:
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
"provider": {
|
|
150
|
-
"anthropic": {
|
|
151
|
-
"npm": "@ai-sdk/anthropic",
|
|
152
|
-
"options": {
|
|
153
|
-
"apiKey": "{env:ANTHROPIC_API_KEY}"
|
|
154
|
-
},
|
|
155
|
-
"models": {
|
|
156
|
-
"claude-sonnet-4-5": {
|
|
157
|
-
"options": {
|
|
158
|
-
"websearch": true
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
Steps:
|
|
167
|
-
1. Open your opencode.json (project root, .opencode/opencode.json, or ~/.config/opencode/opencode.json)
|
|
168
|
-
2. Ensure you have an Anthropic provider configured with a valid API key
|
|
169
|
-
3. Add \`"websearch": true\` to the \`options\` of the Claude model you want to use for web search
|
|
170
|
-
4. Restart OpenCode to pick up the configuration change`;
|
|
171
|
-
|
|
172
172
|
// src/helpers.ts
|
|
173
173
|
var getCurrentMonthYear = () => new Date().toLocaleDateString("en-US", { month: "long", year: "numeric" });
|
|
174
174
|
|
|
175
175
|
// src/index.ts
|
|
176
|
-
var
|
|
177
|
-
const { data } = await
|
|
178
|
-
let config = null;
|
|
176
|
+
var resolveConfig = async (client) => {
|
|
177
|
+
const { data } = await client.config.providers();
|
|
179
178
|
if (data) {
|
|
180
|
-
|
|
179
|
+
return resolveFromProviders(data.providers);
|
|
181
180
|
}
|
|
181
|
+
return null;
|
|
182
|
+
};
|
|
183
|
+
var src_default = async (input) => {
|
|
184
|
+
let config = null;
|
|
182
185
|
return {
|
|
183
186
|
tool: {
|
|
184
187
|
"web-search": tool({
|
|
@@ -213,6 +216,9 @@ IMPORTANT - Use the correct year in search queries:
|
|
|
213
216
|
- It is currently ${getCurrentMonthYear()}. You MUST use this when searching for recent information, documentation, or current events.
|
|
214
217
|
- Example: If the user asks for "latest React docs", search for "React documentation" with the current year, NOT last year`,
|
|
215
218
|
async execute(args) {
|
|
219
|
+
if (!config) {
|
|
220
|
+
config = await resolveConfig(input.client);
|
|
221
|
+
}
|
|
216
222
|
if (!config) {
|
|
217
223
|
return formatConfigError();
|
|
218
224
|
}
|