opencode-websearch 0.1.0 → 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.
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +142 -123
- package/dist/providers/anthropic.d.ts +10 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +13 -2
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConfigResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve Anthropic configuration from multiple sources:
|
|
4
|
+
* 1. opencode.json config files (project-level, then global)
|
|
5
|
+
* 2. ANTHROPIC_API_KEY environment variable (fallback)
|
|
6
|
+
*/
|
|
7
|
+
declare const getAnthropicConfig: () => ConfigResult;
|
|
8
|
+
declare const formatConfigError: (error?: string) => string;
|
|
9
|
+
export { formatConfigError, getAnthropicConfig };
|
|
10
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAIb,MAAM,YAAY,CAAC;AAiJpB;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,QAAO,YAiB9B,CAAC;AAEF,QAAA,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAuB3C,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const DEFAULT_MODEL = "claude-sonnet-4-5";
|
|
2
|
+
declare const DEFAULT_SEARCH_USES = 5;
|
|
3
|
+
declare const EMPTY_LENGTH = 0;
|
|
4
|
+
declare const ENV_VAR_CAPTURE_GROUP = 1;
|
|
5
|
+
declare const FIRST_MODEL_INDEX = 0;
|
|
6
|
+
declare const MAX_RESPONSE_TOKENS = 16000;
|
|
7
|
+
declare const MAX_SEARCH_USES = 10;
|
|
8
|
+
declare const MIN_QUERY_LENGTH = 2;
|
|
9
|
+
declare const MIN_SEARCH_USES = 1;
|
|
10
|
+
declare const MONTH_OFFSET = 1;
|
|
11
|
+
declare const PAD_LENGTH = 2;
|
|
12
|
+
export { DEFAULT_MODEL, DEFAULT_SEARCH_USES, EMPTY_LENGTH, ENV_VAR_CAPTURE_GROUP, FIRST_MODEL_INDEX, MAX_RESPONSE_TOKENS, MAX_SEARCH_USES, MIN_QUERY_LENGTH, MIN_SEARCH_USES, MONTH_OFFSET, PAD_LENGTH, };
|
|
13
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa,sBAAsB,CAAC;AAC1C,QAAA,MAAM,mBAAmB,IAAI,CAAC;AAC9B,QAAA,MAAM,YAAY,IAAI,CAAC;AACvB,QAAA,MAAM,qBAAqB,IAAI,CAAC;AAChC,QAAA,MAAM,iBAAiB,IAAI,CAAC;AAC5B,QAAA,MAAM,mBAAmB,QAAS,CAAC;AACnC,QAAA,MAAM,eAAe,KAAK,CAAC;AAC3B,QAAA,MAAM,gBAAgB,IAAI,CAAC;AAC3B,QAAA,MAAM,eAAe,IAAI,CAAC;AAC1B,QAAA,MAAM,YAAY,IAAI,CAAC;AACvB,QAAA,MAAM,UAAU,IAAI,CAAC;AAErB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,UAAU,GACX,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const getTodayDate: () => string;
|
|
2
|
+
declare const resolveEnvVar: (value: string) => string;
|
|
3
|
+
declare const getCurrentMonthYear: () => string;
|
|
4
|
+
declare const normalizeBaseURL: (url: string) => string;
|
|
5
|
+
export { getCurrentMonthYear, getTodayDate, normalizeBaseURL, resolveEnvVar };
|
|
6
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,YAAY,QAAO,MAMxB,CAAC;AAEF,QAAA,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAMtC,CAAC;AAEF,QAAA,MAAM,mBAAmB,QAAO,MAC4C,CAAC;AAE7E,QAAA,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,MAAqC,CAAC;AAE9E,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,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":";;;;;;;;;;;;;;;;;;;AASA,wBAgEqB"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,123 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { tool } from "@opencode-ai/plugin";
|
|
6
|
-
import Anthropic, { APIError } from "@anthropic-ai/sdk";
|
|
1
|
+
// src/constants.ts
|
|
7
2
|
var DEFAULT_MODEL = "claude-sonnet-4-5";
|
|
8
|
-
var
|
|
9
|
-
var
|
|
3
|
+
var DEFAULT_SEARCH_USES = 5;
|
|
4
|
+
var EMPTY_LENGTH = 0;
|
|
10
5
|
var ENV_VAR_CAPTURE_GROUP = 1;
|
|
11
6
|
var FIRST_MODEL_INDEX = 0;
|
|
12
|
-
var
|
|
7
|
+
var MAX_RESPONSE_TOKENS = 16000;
|
|
8
|
+
var MAX_SEARCH_USES = 10;
|
|
13
9
|
var MIN_QUERY_LENGTH = 2;
|
|
14
10
|
var MIN_SEARCH_USES = 1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
|
|
12
|
+
// src/index.ts
|
|
13
|
+
import { tool } from "@opencode-ai/plugin";
|
|
14
|
+
|
|
15
|
+
// src/providers/anthropic.ts
|
|
16
|
+
import Anthropic, { APIError } from "@anthropic-ai/sdk";
|
|
17
|
+
var formatSearchResult = (result) => {
|
|
18
|
+
if (result.page_age) {
|
|
19
|
+
return `- [${result.title}](${result.url}) (Updated: ${result.page_age})`;
|
|
20
|
+
}
|
|
21
|
+
return `- [${result.title}](${result.url})`;
|
|
22
|
+
};
|
|
23
|
+
var processSearchToolResult = (block, results) => {
|
|
24
|
+
if (Array.isArray(block.content)) {
|
|
25
|
+
const searchResults = block.content;
|
|
26
|
+
if (searchResults.length === EMPTY_LENGTH) {
|
|
27
|
+
results.push("No results found.");
|
|
28
|
+
} else {
|
|
29
|
+
results.push(`
|
|
30
|
+
Found ${searchResults.length} results:
|
|
31
|
+
`);
|
|
32
|
+
for (const result of searchResults) {
|
|
33
|
+
results.push(formatSearchResult(result));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else if (block.content?.type === "web_search_tool_result_error") {
|
|
37
|
+
results.push(`Search error: ${block.content.error_code}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var processBlock = (block, results) => {
|
|
41
|
+
if (block.type === "server_tool_use" && block.name === "web_search") {
|
|
42
|
+
results.push(`Search query: "${block.input.query}"`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (block.type === "web_search_tool_result") {
|
|
46
|
+
processSearchToolResult(block, results);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (block.type === "text" && block.text) {
|
|
50
|
+
results.push(`
|
|
51
|
+
${block.text}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var buildWebSearchTool = (args) => {
|
|
55
|
+
const searchTool = {
|
|
56
|
+
max_uses: args.max_uses ?? DEFAULT_SEARCH_USES,
|
|
57
|
+
name: "web_search",
|
|
58
|
+
type: "web_search_20250305"
|
|
59
|
+
};
|
|
60
|
+
if (args.allowed_domains?.length) {
|
|
61
|
+
searchTool.allowed_domains = args.allowed_domains;
|
|
62
|
+
}
|
|
63
|
+
if (args.blocked_domains?.length) {
|
|
64
|
+
searchTool.blocked_domains = args.blocked_domains;
|
|
65
|
+
}
|
|
66
|
+
return searchTool;
|
|
67
|
+
};
|
|
68
|
+
var formatErrorMessage = (error) => {
|
|
69
|
+
if (error instanceof APIError) {
|
|
70
|
+
return `Anthropic API error: ${error.message} (status: ${error.status})`;
|
|
71
|
+
}
|
|
72
|
+
if (error instanceof Error) {
|
|
73
|
+
return `Error performing web search: ${error.message}`;
|
|
74
|
+
}
|
|
75
|
+
return `Error performing web search: ${String(error)}`;
|
|
76
|
+
};
|
|
77
|
+
var createAnthropicClient = (config) => {
|
|
78
|
+
const options = {
|
|
79
|
+
apiKey: config.apiKey
|
|
80
|
+
};
|
|
81
|
+
if (config.baseURL) {
|
|
82
|
+
options.baseURL = config.baseURL;
|
|
83
|
+
}
|
|
84
|
+
return new Anthropic(options);
|
|
85
|
+
};
|
|
86
|
+
var appendUsageInfo = (usage, results) => {
|
|
87
|
+
if (usage.server_tool_use?.web_search_requests) {
|
|
88
|
+
results.push(`
|
|
89
|
+
---
|
|
90
|
+
Searches performed: ${usage.server_tool_use.web_search_requests}`);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var executeSearch = async (config, args) => {
|
|
94
|
+
const client = createAnthropicClient(config);
|
|
95
|
+
const webSearchTool = buildWebSearchTool(args);
|
|
96
|
+
const response = await client.messages.create({
|
|
97
|
+
max_tokens: MAX_RESPONSE_TOKENS,
|
|
98
|
+
messages: [
|
|
99
|
+
{
|
|
100
|
+
content: `Perform a web search for: ${args.query}`,
|
|
101
|
+
role: "user"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
model: config.model,
|
|
105
|
+
tools: [webSearchTool]
|
|
106
|
+
});
|
|
107
|
+
const results = [];
|
|
108
|
+
const content = response.content;
|
|
109
|
+
for (const block of content) {
|
|
110
|
+
processBlock(block, results);
|
|
111
|
+
}
|
|
112
|
+
appendUsageInfo(response.usage, results);
|
|
113
|
+
return results.join(`
|
|
114
|
+
`) || "No results returned from web search.";
|
|
24
115
|
};
|
|
116
|
+
|
|
117
|
+
// src/config.ts
|
|
118
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
119
|
+
|
|
120
|
+
// src/helpers.ts
|
|
25
121
|
var resolveEnvVar = (value) => {
|
|
26
122
|
const match = value.match(/^\{env:(\w+)\}$/);
|
|
27
123
|
if (match?.[ENV_VAR_CAPTURE_GROUP]) {
|
|
@@ -29,7 +125,12 @@ var resolveEnvVar = (value) => {
|
|
|
29
125
|
}
|
|
30
126
|
return value;
|
|
31
127
|
};
|
|
128
|
+
var getCurrentMonthYear = () => new Date().toLocaleDateString("en-US", { month: "long", year: "numeric" });
|
|
32
129
|
var normalizeBaseURL = (url) => url.replace(/\/v1\/?$/, "");
|
|
130
|
+
|
|
131
|
+
// src/config.ts
|
|
132
|
+
import { homedir } from "node:os";
|
|
133
|
+
import { join } from "node:path";
|
|
33
134
|
var CONFIG_PATHS = [
|
|
34
135
|
join(process.cwd(), "opencode.json"),
|
|
35
136
|
join(process.cwd(), ".opencode", "opencode.json"),
|
|
@@ -151,57 +252,6 @@ var getAnthropicConfig = () => {
|
|
|
151
252
|
}
|
|
152
253
|
return { config: null };
|
|
153
254
|
};
|
|
154
|
-
var formatSearchResult = (result) => {
|
|
155
|
-
if (result.page_age) {
|
|
156
|
-
return `- [${result.title}](${result.url}) (Updated: ${result.page_age})`;
|
|
157
|
-
}
|
|
158
|
-
return `- [${result.title}](${result.url})`;
|
|
159
|
-
};
|
|
160
|
-
var processSearchToolResult = (block, results) => {
|
|
161
|
-
if (Array.isArray(block.content)) {
|
|
162
|
-
const searchResults = block.content;
|
|
163
|
-
if (searchResults.length === EMPTY_LENGTH) {
|
|
164
|
-
results.push("No results found.");
|
|
165
|
-
} else {
|
|
166
|
-
results.push(`
|
|
167
|
-
Found ${searchResults.length} results:
|
|
168
|
-
`);
|
|
169
|
-
for (const result of searchResults) {
|
|
170
|
-
results.push(formatSearchResult(result));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
} else if (block.content?.type === "web_search_tool_result_error") {
|
|
174
|
-
results.push(`Search error: ${block.content.error_code}`);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
var processBlock = (block, results) => {
|
|
178
|
-
if (block.type === "server_tool_use" && block.name === "web_search") {
|
|
179
|
-
results.push(`Search query: "${block.input.query}"`);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (block.type === "web_search_tool_result") {
|
|
183
|
-
processSearchToolResult(block, results);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
if (block.type === "text" && block.text) {
|
|
187
|
-
results.push(`
|
|
188
|
-
${block.text}`);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
var buildWebSearchTool = (args) => {
|
|
192
|
-
const searchTool = {
|
|
193
|
-
max_uses: args.max_uses ?? DEFAULT_SEARCH_USES,
|
|
194
|
-
name: "web_search",
|
|
195
|
-
type: "web_search_20250305"
|
|
196
|
-
};
|
|
197
|
-
if (args.allowed_domains?.length) {
|
|
198
|
-
searchTool.allowed_domains = args.allowed_domains;
|
|
199
|
-
}
|
|
200
|
-
if (args.blocked_domains?.length) {
|
|
201
|
-
searchTool.blocked_domains = args.blocked_domains;
|
|
202
|
-
}
|
|
203
|
-
return searchTool;
|
|
204
|
-
};
|
|
205
255
|
var formatConfigError = (error) => {
|
|
206
256
|
let hint = "";
|
|
207
257
|
if (error) {
|
|
@@ -227,54 +277,8 @@ Set the ANTHROPIC_API_KEY environment variable, or add an Anthropic provider to
|
|
|
227
277
|
}
|
|
228
278
|
}${hint}`;
|
|
229
279
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return `Anthropic API error: ${error.message} (status: ${error.status})`;
|
|
233
|
-
}
|
|
234
|
-
if (error instanceof Error) {
|
|
235
|
-
return `Error performing web search: ${error.message}`;
|
|
236
|
-
}
|
|
237
|
-
return `Error performing web search: ${String(error)}`;
|
|
238
|
-
};
|
|
239
|
-
var createAnthropicClient = (config) => {
|
|
240
|
-
const options = {
|
|
241
|
-
apiKey: config.apiKey
|
|
242
|
-
};
|
|
243
|
-
if (config.baseURL) {
|
|
244
|
-
options.baseURL = config.baseURL;
|
|
245
|
-
}
|
|
246
|
-
return new Anthropic(options);
|
|
247
|
-
};
|
|
248
|
-
var appendUsageInfo = (usage, results) => {
|
|
249
|
-
if (usage.server_tool_use?.web_search_requests) {
|
|
250
|
-
results.push(`
|
|
251
|
-
---
|
|
252
|
-
Searches performed: ${usage.server_tool_use.web_search_requests}`);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var executeSearch = async (config, args) => {
|
|
256
|
-
const client = createAnthropicClient(config);
|
|
257
|
-
const webSearchTool = buildWebSearchTool(args);
|
|
258
|
-
const response = await client.messages.create({
|
|
259
|
-
max_tokens: MAX_RESPONSE_TOKENS,
|
|
260
|
-
messages: [
|
|
261
|
-
{
|
|
262
|
-
content: `Perform a web search for: ${args.query}`,
|
|
263
|
-
role: "user"
|
|
264
|
-
}
|
|
265
|
-
],
|
|
266
|
-
model: config.model,
|
|
267
|
-
tools: [webSearchTool]
|
|
268
|
-
});
|
|
269
|
-
const results = [];
|
|
270
|
-
const content = response.content;
|
|
271
|
-
for (const block of content) {
|
|
272
|
-
processBlock(block, results);
|
|
273
|
-
}
|
|
274
|
-
appendUsageInfo(response.usage, results);
|
|
275
|
-
return results.join(`
|
|
276
|
-
`) || "No results returned from web search.";
|
|
277
|
-
};
|
|
280
|
+
|
|
281
|
+
// src/index.ts
|
|
278
282
|
var src_default = async () => ({
|
|
279
283
|
tool: {
|
|
280
284
|
"web-search": tool({
|
|
@@ -284,15 +288,30 @@ var src_default = async () => ({
|
|
|
284
288
|
max_uses: tool.schema.number().min(MIN_SEARCH_USES).max(MAX_SEARCH_USES).optional().describe("Maximum number of searches to perform (default: 5)"),
|
|
285
289
|
query: tool.schema.string().min(MIN_QUERY_LENGTH).describe("The search query to execute")
|
|
286
290
|
},
|
|
287
|
-
description:
|
|
288
|
-
|
|
291
|
+
description: `- Allows OpenCode to search the web and use the results to inform responses
|
|
289
292
|
- Provides up-to-date information for current events and recent data
|
|
290
|
-
- Returns search
|
|
291
|
-
- Use this for accessing information beyond the knowledge cutoff
|
|
293
|
+
- Returns search result information formatted as search result blocks, including links as markdown hyperlinks
|
|
294
|
+
- Use this tool for accessing information beyond the model's knowledge cutoff
|
|
295
|
+
- Searches are performed automatically within a single API call
|
|
296
|
+
|
|
297
|
+
CRITICAL REQUIREMENT - You MUST follow this:
|
|
298
|
+
- After answering the user's question, you MUST include a "Sources:" section at the end of your response
|
|
299
|
+
- In the Sources section, list all relevant URLs from the search results as markdown hyperlinks: [Title](URL)
|
|
300
|
+
- This is MANDATORY - never skip including sources in your response
|
|
301
|
+
- Example format:
|
|
302
|
+
|
|
303
|
+
[Your answer here]
|
|
304
|
+
|
|
305
|
+
Sources:
|
|
306
|
+
- [Source Title 1](https://example.com/1)
|
|
307
|
+
- [Source Title 2](https://example.com/2)
|
|
292
308
|
|
|
293
|
-
|
|
309
|
+
Usage notes:
|
|
310
|
+
- Domain filtering is supported to include or block specific websites
|
|
294
311
|
|
|
295
|
-
|
|
312
|
+
IMPORTANT - Use the correct year in search queries:
|
|
313
|
+
- It is currently ${getCurrentMonthYear()}. You MUST use this when searching for recent information, documentation, or current events.
|
|
314
|
+
- Example: If the user asks for "latest React docs", search for "React documentation" with the current year, NOT last year`,
|
|
296
315
|
async execute(args) {
|
|
297
316
|
const { config, error } = getAnthropicConfig();
|
|
298
317
|
if (!config) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnthropicConfig } from "../types.js";
|
|
2
|
+
declare const formatErrorMessage: (error: unknown) => string;
|
|
3
|
+
declare const executeSearch: (config: AnthropicConfig, args: {
|
|
4
|
+
allowed_domains?: string[];
|
|
5
|
+
blocked_domains?: string[];
|
|
6
|
+
max_uses?: number;
|
|
7
|
+
query: string;
|
|
8
|
+
}) => Promise<string>;
|
|
9
|
+
export { executeSearch, formatErrorMessage };
|
|
10
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EAKhB,MAAM,aAAa,CAAC;AAqErB,QAAA,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,MAQ5C,CAAC;AAoBF,QAAA,MAAM,aAAa,GACjB,QAAQ,eAAe,EACvB,MAAM;IACJ,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,KACA,OAAO,CAAC,MAAM,CA0BhB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
interface AnthropicConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
model: string;
|
|
5
|
+
}
|
|
6
|
+
interface OpenCodeProvider {
|
|
7
|
+
models?: Record<string, {
|
|
8
|
+
name?: string;
|
|
9
|
+
}>;
|
|
10
|
+
npm?: string;
|
|
11
|
+
options?: {
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface OpenCodeConfig {
|
|
17
|
+
provider?: Record<string, OpenCodeProvider>;
|
|
18
|
+
}
|
|
19
|
+
interface ConfigResult {
|
|
20
|
+
config: AnthropicConfig | null;
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ProviderContext {
|
|
24
|
+
configPath: string;
|
|
25
|
+
errors: string[];
|
|
26
|
+
providerName: string;
|
|
27
|
+
}
|
|
28
|
+
interface WebSearchResult {
|
|
29
|
+
page_age?: string;
|
|
30
|
+
title: string;
|
|
31
|
+
type: "web_search_result";
|
|
32
|
+
url: string;
|
|
33
|
+
}
|
|
34
|
+
interface WebSearchToolResult {
|
|
35
|
+
content: WebSearchResult[] | {
|
|
36
|
+
error_code: string;
|
|
37
|
+
type: "web_search_tool_result_error";
|
|
38
|
+
};
|
|
39
|
+
tool_use_id: string;
|
|
40
|
+
type: "web_search_tool_result";
|
|
41
|
+
}
|
|
42
|
+
interface ServerToolUse {
|
|
43
|
+
id: string;
|
|
44
|
+
input: {
|
|
45
|
+
query: string;
|
|
46
|
+
};
|
|
47
|
+
name: string;
|
|
48
|
+
type: "server_tool_use";
|
|
49
|
+
}
|
|
50
|
+
interface SearchUsage {
|
|
51
|
+
input_tokens: number;
|
|
52
|
+
output_tokens: number;
|
|
53
|
+
server_tool_use?: {
|
|
54
|
+
web_search_requests?: number;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
type ContentBlock = {
|
|
58
|
+
text: string;
|
|
59
|
+
type: "text";
|
|
60
|
+
} | ServerToolUse | WebSearchToolResult;
|
|
61
|
+
export { AnthropicConfig, ConfigResult, ContentBlock, OpenCodeConfig, OpenCodeProvider, ProviderContext, SearchUsage, ServerToolUse, WebSearchResult, WebSearchToolResult, };
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;AAED,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC7C;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAID,UAAU,eAAe;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,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,UAAU,WAAW;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAEzF,OAAO,EACL,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,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.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Claude Code's WebSearch tool ported to OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,9 +18,12 @@
|
|
|
18
18
|
"build": "bun build src/index.ts --outdir dist --target node --format esm --packages external && bun run build:types",
|
|
19
19
|
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
20
20
|
"dev": "bun run --watch src/index.ts",
|
|
21
|
+
"format": "oxfmt src/",
|
|
22
|
+
"format:check": "oxfmt --check src/",
|
|
21
23
|
"lint": "oxlint --tsconfig tsconfig.json src/",
|
|
24
|
+
"lint:fix": "oxlint --tsconfig tsconfig.json --fix src/",
|
|
22
25
|
"typecheck": "tsc --noEmit",
|
|
23
|
-
"check": "bun run lint && bun run typecheck",
|
|
26
|
+
"check": "bun run format:check && bun run lint && bun run typecheck",
|
|
24
27
|
"prepublishOnly": "bun run check && bun run build"
|
|
25
28
|
},
|
|
26
29
|
"keywords": [
|
|
@@ -30,6 +33,13 @@
|
|
|
30
33
|
"anthropic",
|
|
31
34
|
"ai"
|
|
32
35
|
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/emilsvennesson/opencode-websearch.git"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=24"
|
|
42
|
+
},
|
|
33
43
|
"license": "MIT",
|
|
34
44
|
"dependencies": {
|
|
35
45
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
@@ -37,6 +47,7 @@
|
|
|
37
47
|
"devDependencies": {
|
|
38
48
|
"@opencode-ai/plugin": "^1.1.65",
|
|
39
49
|
"@types/bun": "latest",
|
|
50
|
+
"oxfmt": "^0.32.0",
|
|
40
51
|
"oxlint": "^1.47.0",
|
|
41
52
|
"typescript": "^5.8.0"
|
|
42
53
|
},
|