opencode-search 0.0.9 → 1.0.0-next.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 +39 -6
- package/REMOVED.md +29 -0
- package/dist/package.json +18 -11
- package/dist/search.d.ts +2 -3
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +19 -14
- package/dist/search.js.map +1 -1
- package/dist/src/cache.d.ts.map +1 -1
- package/dist/src/cache.js +2 -4
- package/dist/src/cache.js.map +1 -1
- package/dist/src/format.d.ts.map +1 -1
- package/dist/src/format.js +2 -4
- package/dist/src/format.js.map +1 -1
- package/dist/src/html.d.ts +8 -0
- package/dist/src/html.d.ts.map +1 -0
- package/dist/src/html.js +28 -0
- package/dist/src/html.js.map +1 -0
- package/dist/src/opencode/notify.d.ts +4 -4
- package/dist/src/opencode/notify.d.ts.map +1 -1
- package/dist/src/opencode/notify.js +4 -9
- package/dist/src/opencode/notify.js.map +1 -1
- package/dist/src/parse-results.d.ts.map +1 -1
- package/dist/src/parse-results.js +1 -2
- package/dist/src/parse-results.js.map +1 -1
- package/dist/src/providers/brave-search.d.ts +4 -0
- package/dist/src/providers/brave-search.d.ts.map +1 -0
- package/dist/src/providers/brave-search.js +29 -0
- package/dist/src/providers/brave-search.js.map +1 -0
- package/dist/src/providers/bsky-search.d.ts.map +1 -1
- package/dist/src/providers/bsky-search.js +4 -8
- package/dist/src/providers/bsky-search.js.map +1 -1
- package/dist/src/providers/ddg-search.d.ts.map +1 -1
- package/dist/src/providers/ddg-search.js +64 -37
- package/dist/src/providers/ddg-search.js.map +1 -1
- package/dist/src/providers/gnews-search.d.ts +9 -0
- package/dist/src/providers/gnews-search.d.ts.map +1 -0
- package/dist/src/providers/gnews-search.js +48 -0
- package/dist/src/providers/gnews-search.js.map +1 -0
- package/dist/src/providers/mdn-search.d.ts.map +1 -1
- package/dist/src/providers/mdn-search.js +4 -8
- package/dist/src/providers/mdn-search.js.map +1 -1
- package/dist/src/providers/standard-search.d.ts.map +1 -1
- package/dist/src/providers/standard-search.js +6 -12
- package/dist/src/providers/standard-search.js.map +1 -1
- package/dist/src/providers/wiki-search.d.ts.map +1 -1
- package/dist/src/providers/wiki-search.js +3 -6
- package/dist/src/providers/wiki-search.js.map +1 -1
- package/dist/src/renderers.d.ts +3 -2
- package/dist/src/renderers.d.ts.map +1 -1
- package/dist/src/renderers.js +5 -3
- package/dist/src/renderers.js.map +1 -1
- package/dist/src/safe.d.ts +5 -4
- package/dist/src/safe.d.ts.map +1 -1
- package/dist/src/safe.js +4 -18
- package/dist/src/safe.js.map +1 -1
- package/dist/src/search.d.ts +10 -71
- package/dist/src/search.d.ts.map +1 -1
- package/dist/src/search.js +225 -151
- package/dist/src/search.js.map +1 -1
- package/dist/src/strategies.d.ts +13 -0
- package/dist/src/strategies.d.ts.map +1 -0
- package/dist/src/strategies.js +48 -0
- package/dist/src/strategies.js.map +1 -0
- package/dist/src/v1-message.d.ts +2 -0
- package/dist/src/v1-message.d.ts.map +1 -0
- package/dist/src/v1-message.js +11 -0
- package/dist/src/v1-message.js.map +1 -0
- package/package.json +18 -11
- package/dist/src/providers/ggl-search.d.ts +0 -7
- package/dist/src/providers/ggl-search.d.ts.map +0 -1
- package/dist/src/providers/ggl-search.js +0 -92
- package/dist/src/providers/ggl-search.js.map +0 -1
package/dist/src/search.js
CHANGED
|
@@ -1,168 +1,242 @@
|
|
|
1
|
-
import { tool } from '@opencode-ai/plugin';
|
|
2
1
|
import { formatResults } from "./format.js";
|
|
3
2
|
import { sendResult } from "./opencode/notify.js";
|
|
3
|
+
import { braveSearch } from "./providers/brave-search.js";
|
|
4
4
|
import { bskySearch } from "./providers/bsky-search.js";
|
|
5
5
|
import { ddgSearch } from "./providers/ddg-search.js";
|
|
6
|
-
import {
|
|
6
|
+
import { gnewsSearch } from "./providers/gnews-search.js";
|
|
7
7
|
import { mdnSearch } from "./providers/mdn-search.js";
|
|
8
8
|
import { standardSearch } from "./providers/standard-search.js";
|
|
9
9
|
import { wikiSearch } from "./providers/wiki-search.js";
|
|
10
|
-
import { renderBskyPost, renderDdgResult,
|
|
10
|
+
import { renderBskyPost, renderDdgResult, renderGnewsItem, renderMdnDoc, renderStandardDoc, renderWebResult, renderWikiPage, } from "./renderers.js";
|
|
11
11
|
import { safeAsync } from "./safe.js";
|
|
12
|
-
const postResult = async (
|
|
13
|
-
await safeAsync(() => sendResult({
|
|
12
|
+
const postResult = async (context, ctx, text) => {
|
|
13
|
+
await safeAsync(() => sendResult({ context, sessionID: ctx.sessionID, text }));
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
const formatted = formatResults({
|
|
27
|
-
label: 'DuckDuckGo results',
|
|
28
|
-
items: data,
|
|
29
|
-
total: data.length,
|
|
30
|
-
renderItem: renderDdgResult,
|
|
31
|
-
});
|
|
32
|
-
await postResult(client, ctx, formatted);
|
|
33
|
-
return 'Search results displayed in chat.';
|
|
34
|
-
},
|
|
35
|
-
});
|
|
15
|
+
const textOutput = (output, text) => ({
|
|
16
|
+
output,
|
|
17
|
+
content: [{ type: 'text', text }],
|
|
18
|
+
});
|
|
19
|
+
const isRecord = (value) => (typeof value === 'object' && value !== null && !Array.isArray(value));
|
|
20
|
+
const stringField = (input, key) => {
|
|
21
|
+
if (!isRecord(input))
|
|
22
|
+
return '';
|
|
23
|
+
const value = input[key];
|
|
24
|
+
return typeof value === 'string' ? value : '';
|
|
36
25
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
async execute(args, ctx) {
|
|
44
|
-
const { data, error } = await safeAsync(() => googleSearch(args.query));
|
|
45
|
-
if (error) {
|
|
46
|
-
return 'Google search failed: ' + error.message;
|
|
47
|
-
}
|
|
48
|
-
const formatted = formatResults({
|
|
49
|
-
label: 'Google results',
|
|
50
|
-
items: data,
|
|
51
|
-
total: data.length,
|
|
52
|
-
renderItem: renderGoogleResult,
|
|
53
|
-
});
|
|
54
|
-
await postResult(client, ctx, formatted);
|
|
55
|
-
return 'Search results displayed in chat.';
|
|
56
|
-
},
|
|
57
|
-
});
|
|
26
|
+
const numberField = (input, key) => {
|
|
27
|
+
if (!isRecord(input))
|
|
28
|
+
return undefined;
|
|
29
|
+
const value = input[key];
|
|
30
|
+
return typeof value === 'number' ? value : undefined;
|
|
58
31
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
query: tool.schema.string().describe('The search query'),
|
|
67
|
-
limit: tool.schema.number().optional().describe('Maximum number of results to return'),
|
|
68
|
-
sort: tool.schema.string().optional().describe('Sort order: top or latest'),
|
|
69
|
-
},
|
|
70
|
-
async execute(args, ctx) {
|
|
71
|
-
const { data, error } = await safeAsync(() => (bskySearch({ query: args.query, limit: args.limit, sort: args.sort })));
|
|
72
|
-
if (error) {
|
|
73
|
-
return 'Bluesky search failed: ' + error.message;
|
|
74
|
-
}
|
|
75
|
-
const formatted = formatResults({
|
|
76
|
-
label: 'Bluesky results',
|
|
77
|
-
items: data.posts,
|
|
78
|
-
total: data.hitsTotal,
|
|
79
|
-
limit: args.limit,
|
|
80
|
-
offset: 0,
|
|
81
|
-
renderItem: renderBskyPost,
|
|
82
|
-
});
|
|
83
|
-
await postResult(client, ctx, formatted);
|
|
84
|
-
return 'Search results displayed in chat.';
|
|
85
|
-
},
|
|
86
|
-
});
|
|
32
|
+
const queryArg = {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
query: { type: 'string', description: 'The search query' },
|
|
36
|
+
},
|
|
37
|
+
required: ['query'],
|
|
38
|
+
additionalProperties: false,
|
|
87
39
|
};
|
|
88
|
-
export const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
40
|
+
export const createDdgSearchTool = (context) => ({
|
|
41
|
+
name: 'ddg-search',
|
|
42
|
+
description: 'Search DuckDuckGo and return results as extracted text content',
|
|
43
|
+
input: queryArg,
|
|
44
|
+
async execute(input, ctx) {
|
|
45
|
+
const query = stringField(input, 'query');
|
|
46
|
+
const { data, error } = await safeAsync(() => ddgSearch(query));
|
|
47
|
+
if (error)
|
|
48
|
+
return textOutput({ error: error.message }, 'DuckDuckGo search failed: ' + error.message);
|
|
49
|
+
const formatted = formatResults({
|
|
50
|
+
label: 'DuckDuckGo results',
|
|
51
|
+
items: data,
|
|
52
|
+
total: data.length,
|
|
53
|
+
renderItem: renderDdgResult,
|
|
54
|
+
});
|
|
55
|
+
await postResult(context, ctx, formatted);
|
|
56
|
+
return textOutput({ results: data, total: data.length }, 'Search results displayed in chat.');
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
export const createBraveSearchTool = (context) => ({
|
|
60
|
+
name: 'brave-search',
|
|
61
|
+
description: 'Search the web via Brave Search, returning titles, URLs, and snippets.',
|
|
62
|
+
input: queryArg,
|
|
63
|
+
async execute(input, ctx) {
|
|
64
|
+
const query = stringField(input, 'query');
|
|
65
|
+
const { data, error } = await safeAsync(() => braveSearch(query));
|
|
66
|
+
if (error)
|
|
67
|
+
return textOutput({ error: error.message }, 'Brave search failed: ' + error.message);
|
|
68
|
+
const formatted = formatResults({
|
|
69
|
+
label: 'Brave results',
|
|
70
|
+
items: data,
|
|
71
|
+
total: data.length,
|
|
72
|
+
renderItem: renderWebResult,
|
|
73
|
+
});
|
|
74
|
+
await postResult(context, ctx, formatted);
|
|
75
|
+
return textOutput({ results: data, total: data.length }, 'Search results displayed in chat.');
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
export const createBskySearchTool = (context) => ({
|
|
79
|
+
name: 'bsky-search',
|
|
80
|
+
description: [
|
|
81
|
+
'Search Bluesky posts via the AT Protocol.',
|
|
82
|
+
'Returns posts with author, text, and engagement counts.',
|
|
83
|
+
].join(' '),
|
|
84
|
+
input: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
properties: {
|
|
87
|
+
query: { type: 'string', description: 'The search query' },
|
|
88
|
+
limit: { type: 'number', description: 'Maximum number of results to return' },
|
|
89
|
+
sort: { type: 'string', description: 'Sort order: top or latest' },
|
|
98
90
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
91
|
+
required: ['query'],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
},
|
|
94
|
+
async execute(input, ctx) {
|
|
95
|
+
const query = stringField(input, 'query');
|
|
96
|
+
const limit = numberField(input, 'limit');
|
|
97
|
+
const sort = stringField(input, 'sort') || undefined;
|
|
98
|
+
const { data, error } = await safeAsync(() => (bskySearch({ query, limit, sort })));
|
|
99
|
+
if (error)
|
|
100
|
+
return textOutput({ error: error.message }, 'Bluesky search failed: ' + error.message);
|
|
101
|
+
const formatted = formatResults({
|
|
102
|
+
label: 'Bluesky results',
|
|
103
|
+
items: data.posts,
|
|
104
|
+
total: data.hitsTotal,
|
|
105
|
+
limit,
|
|
106
|
+
offset: 0,
|
|
107
|
+
renderItem: renderBskyPost,
|
|
108
|
+
});
|
|
109
|
+
await postResult(context, ctx, formatted);
|
|
110
|
+
return textOutput({ results: data.posts, total: data.hitsTotal }, 'Search results displayed in chat.');
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
export const createStandardSearchTool = (context) => ({
|
|
114
|
+
name: 'standard-search',
|
|
115
|
+
description: [
|
|
116
|
+
'Search site.standard.document records on the AT Protocol.',
|
|
117
|
+
'Returns blog posts and articles from the ATmosphere.',
|
|
118
|
+
].join(' '),
|
|
119
|
+
input: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
query: { type: 'string', description: 'The search query' },
|
|
123
|
+
limit: { type: 'number', description: 'Maximum number of results to return' },
|
|
124
|
+
offset: { type: 'number', description: 'Number of results to skip' },
|
|
115
125
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
required: ['query'],
|
|
127
|
+
additionalProperties: false,
|
|
128
|
+
},
|
|
129
|
+
async execute(input, ctx) {
|
|
130
|
+
const query = stringField(input, 'query');
|
|
131
|
+
const limit = numberField(input, 'limit');
|
|
132
|
+
const offset = numberField(input, 'offset');
|
|
133
|
+
const { data, error } = await safeAsync(() => (standardSearch({ query, limit, offset })));
|
|
134
|
+
if (error)
|
|
135
|
+
return textOutput({ error: error.message }, 'Standard.site search failed: ' + error.message);
|
|
136
|
+
const total = Number(data.totalResults) || data.documents.length;
|
|
137
|
+
const formatted = formatResults({
|
|
138
|
+
label: 'Standard.site results',
|
|
139
|
+
items: data.documents,
|
|
140
|
+
total,
|
|
141
|
+
limit,
|
|
142
|
+
offset,
|
|
143
|
+
renderItem: renderStandardDoc,
|
|
144
|
+
});
|
|
145
|
+
await postResult(context, ctx, formatted);
|
|
146
|
+
return textOutput({ results: data.documents, total }, 'Search results displayed in chat.');
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
export const createWikiSearchTool = (context) => ({
|
|
150
|
+
name: 'wiki-search',
|
|
151
|
+
description: 'Search Wikipedia articles. Returns page titles, descriptions, and excerpts.',
|
|
152
|
+
input: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
query: { type: 'string', description: 'The search query' },
|
|
156
|
+
limit: { type: 'number', description: 'Maximum number of results to return (1-100)' },
|
|
140
157
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
158
|
+
required: ['query'],
|
|
159
|
+
additionalProperties: false,
|
|
160
|
+
},
|
|
161
|
+
async execute(input, ctx) {
|
|
162
|
+
const query = stringField(input, 'query');
|
|
163
|
+
const limit = numberField(input, 'limit');
|
|
164
|
+
const { data, error } = await safeAsync(() => (wikiSearch({ query, limit })));
|
|
165
|
+
if (error)
|
|
166
|
+
return textOutput({ error: error.message }, 'Wikipedia search failed: ' + error.message);
|
|
167
|
+
const formatted = formatResults({
|
|
168
|
+
label: 'Wikipedia results',
|
|
169
|
+
items: data.pages,
|
|
170
|
+
total: data.pages.length,
|
|
171
|
+
limit,
|
|
172
|
+
offset: 0,
|
|
173
|
+
renderItem: renderWikiPage,
|
|
174
|
+
});
|
|
175
|
+
await postResult(context, ctx, formatted);
|
|
176
|
+
return textOutput({ results: data.pages, total: data.pages.length }, 'Search results displayed in chat.');
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
export const createGnewsSearchTool = (context) => ({
|
|
180
|
+
name: 'gnews-search',
|
|
181
|
+
description: [
|
|
182
|
+
'Search Google News for recent articles, returning headlines, publishers, and dates.',
|
|
183
|
+
'News and tech media only — not general web search, and not documentation.',
|
|
184
|
+
'Links are news.google.com redirect URLs, not publisher URLs.',
|
|
185
|
+
].join(' '),
|
|
186
|
+
input: queryArg,
|
|
187
|
+
async execute(input, ctx) {
|
|
188
|
+
const query = stringField(input, 'query');
|
|
189
|
+
const { data, error } = await safeAsync(() => gnewsSearch(query));
|
|
190
|
+
if (error)
|
|
191
|
+
return textOutput({ error: error.message }, 'Google News search failed: ' + error.message);
|
|
192
|
+
const formatted = formatResults({
|
|
193
|
+
label: 'Google News results',
|
|
194
|
+
items: data,
|
|
195
|
+
total: data.length,
|
|
196
|
+
renderItem: renderGnewsItem,
|
|
197
|
+
});
|
|
198
|
+
await postResult(context, ctx, formatted);
|
|
199
|
+
return textOutput({ results: data, total: data.length }, 'Search results displayed in chat.');
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
export const createMdnSearchTool = (context) => ({
|
|
203
|
+
name: 'mdn-search',
|
|
204
|
+
description: 'Search MDN Web Docs. Returns documentation pages for web technologies.',
|
|
205
|
+
input: {
|
|
206
|
+
type: 'object',
|
|
207
|
+
properties: {
|
|
208
|
+
query: { type: 'string', description: 'The search query' },
|
|
209
|
+
limit: { type: 'number', description: 'Maximum number of results to return' },
|
|
210
|
+
page: { type: 'number', description: 'Page number for pagination' },
|
|
150
211
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
};
|
|
212
|
+
required: ['query'],
|
|
213
|
+
additionalProperties: false,
|
|
214
|
+
},
|
|
215
|
+
async execute(input, ctx) {
|
|
216
|
+
const query = stringField(input, 'query');
|
|
217
|
+
const limit = numberField(input, 'limit');
|
|
218
|
+
const page = numberField(input, 'page');
|
|
219
|
+
const { data, error } = await safeAsync(() => (mdnSearch({ query, limit, page })));
|
|
220
|
+
if (error)
|
|
221
|
+
return textOutput({ error: error.message }, 'MDN search failed: ' + error.message);
|
|
222
|
+
const formatted = formatResults({
|
|
223
|
+
label: 'MDN Web Docs results',
|
|
224
|
+
items: data.documents,
|
|
225
|
+
total: data.total,
|
|
226
|
+
limit,
|
|
227
|
+
renderItem: renderMdnDoc,
|
|
228
|
+
});
|
|
229
|
+
await postResult(context, ctx, formatted);
|
|
230
|
+
return textOutput({ results: data.documents, total: data.total }, 'Search results displayed in chat.');
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
export const createSearchTools = (context) => [
|
|
234
|
+
createBraveSearchTool(context),
|
|
235
|
+
createBskySearchTool(context),
|
|
236
|
+
createDdgSearchTool(context),
|
|
237
|
+
createGnewsSearchTool(context),
|
|
238
|
+
createMdnSearchTool(context),
|
|
239
|
+
createStandardSearchTool(context),
|
|
240
|
+
createWikiSearchTool(context),
|
|
241
|
+
];
|
|
168
242
|
//# sourceMappingURL=search.js.map
|
package/dist/src/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/search.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,cAAc,GACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,UAAU,GAAG,KAAK,EAAE,OAAuB,EAAE,GAAqB,EAA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AC,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,CAAA;QAEzC,OAAO,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,mCAAmC,CAAC,CAAA;IACxG,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAuB,EAAe,EAAE,CAAC;IACzE,qBAAqB,CAAC,OAAO,CAAC;IAC9B,oBAAoB,CAAC,OAAO,CAAC;IAC7B,mBAAmB,CAAC,OAAO,CAAC;IAC5B,qBAAqB,CAAC,OAAO,CAAC;IAC9B,mBAAmB,CAAC,OAAO,CAAC;IAC5B,wBAAwB,CAAC,OAAO,CAAC;IACjC,oBAAoB,CAAC,OAAO,CAAC;CAC9B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const USER_AGENTS: string[];
|
|
2
|
+
export declare const nextUserAgent: () => string;
|
|
3
|
+
export declare const baseHeaders: (userAgent: string) => Record<string, string>;
|
|
4
|
+
export declare class BlockedError extends Error {
|
|
5
|
+
constructor(source: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const detectBlock: (source: string, html: string, markers: string[]) => void;
|
|
8
|
+
export type Strategy<T> = {
|
|
9
|
+
name: string;
|
|
10
|
+
run: (userAgent: string) => Promise<T[]>;
|
|
11
|
+
};
|
|
12
|
+
export declare const runStrategies: <T>(strategies: Strategy<T>[]) => Promise<T[]>;
|
|
13
|
+
//# sourceMappingURL=strategies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../src/strategies.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,UAKvB,CAAA;AAKD,eAAO,MAAM,aAAa,QAAO,MAKhC,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAKnE,CAAA;AAEF,qBAAa,YAAa,SAAQ,KAAK;gBACzB,MAAM,EAAE,MAAM;CAI3B;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM,EAAE,KAAG,IAI7E,CAAA;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAA;CACzC,CAAA;AAGD,eAAO,MAAM,aAAa,GAAU,CAAC,EAAE,YAAY,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAG,OAAO,CAAC,CAAC,EAAE,CAgB7E,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { safeAsync } from "./safe.js";
|
|
2
|
+
export const USER_AGENTS = [
|
|
3
|
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
4
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
|
5
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15',
|
|
6
|
+
'Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0',
|
|
7
|
+
];
|
|
8
|
+
let uaIndex = 0;
|
|
9
|
+
// Rotation gives each fallback attempt a fresh identity after a block
|
|
10
|
+
export const nextUserAgent = () => {
|
|
11
|
+
const agent = USER_AGENTS[uaIndex % USER_AGENTS.length];
|
|
12
|
+
uaIndex += 1;
|
|
13
|
+
return agent ?? '';
|
|
14
|
+
};
|
|
15
|
+
export const baseHeaders = (userAgent) => ({
|
|
16
|
+
'User-Agent': userAgent,
|
|
17
|
+
'Accept': 'text/html',
|
|
18
|
+
'Accept-Encoding': 'gzip',
|
|
19
|
+
'DNT': '1',
|
|
20
|
+
});
|
|
21
|
+
export class BlockedError extends Error {
|
|
22
|
+
constructor(source) {
|
|
23
|
+
super(source + ' blocked the request (CAPTCHA or rate limit)');
|
|
24
|
+
this.name = 'BlockedError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export const detectBlock = (source, html, markers) => {
|
|
28
|
+
for (const marker of markers) {
|
|
29
|
+
if (html.includes(marker))
|
|
30
|
+
throw new BlockedError(source);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
// A strategy fails by throwing or by returning zero results; the next one gets a chance
|
|
34
|
+
export const runStrategies = async (strategies) => {
|
|
35
|
+
let lastError = new Error('no strategies provided');
|
|
36
|
+
for (const strategy of strategies) {
|
|
37
|
+
const { data, error } = await safeAsync(() => strategy.run(nextUserAgent()));
|
|
38
|
+
if (error) {
|
|
39
|
+
lastError = error;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (data.length > 0)
|
|
43
|
+
return data;
|
|
44
|
+
lastError = new Error(strategy.name + ' returned no results');
|
|
45
|
+
}
|
|
46
|
+
throw lastError;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=strategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.js","sourceRoot":"","sources":["../../src/strategies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,uGAAuG;IACvG,iHAAiH;IACjH,uHAAuH;IACvH,wEAAwE;CACzE,CAAA;AAED,IAAI,OAAO,GAAG,CAAC,CAAA;AAEf,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,GAAW,EAAE;IACxC,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IACvD,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C,IAAI,GAAG,sBAAsB,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,SAAS,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-message.d.ts","sourceRoot":"","sources":["../../src/v1-message.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,QAQX,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Shown when OpenCode 1 loads this build, where the alternative is a module resolution error.
|
|
2
|
+
export const V1_MESSAGE = [
|
|
3
|
+
'opencode-search 1.x requires OpenCode 2 and cannot load under OpenCode 1.',
|
|
4
|
+
'',
|
|
5
|
+
'Either pin the last OpenCode 1 release, which will not be updated:',
|
|
6
|
+
'',
|
|
7
|
+
' { "plugin": ["opencode-search@0.0.9"] }',
|
|
8
|
+
'',
|
|
9
|
+
'or upgrade to OpenCode 2 (https://opencode.ai/v2/docs) and use the "plugins" key.',
|
|
10
|
+
].join('\n');
|
|
11
|
+
//# sourceMappingURL=v1-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-message.js","sourceRoot":"","sources":["../../src/v1-message.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,2EAA2E;IAC3E,EAAE;IACF,oEAAoE;IACpE,EAAE;IACF,2CAA2C;IAC3C,EAAE;IACF,mFAAmF;CACpF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-search",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "OpenCode plugin that provides web search tools using DuckDuckGo, Google, Wikipedia, Bluesky, Standard.site, and MDN Web Docs.",
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
|
+
"description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky, Standard.site, and MDN Web Docs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
7
7
|
"opencode-plugin",
|
|
8
8
|
"plugin",
|
|
9
9
|
"search",
|
|
10
10
|
"web-search",
|
|
11
|
-
"wikipedia",
|
|
12
11
|
"duckduckgo",
|
|
13
|
-
"
|
|
12
|
+
"brave",
|
|
13
|
+
"google-news",
|
|
14
|
+
"wikipedia",
|
|
15
|
+
"mdn",
|
|
14
16
|
"bluesky",
|
|
15
17
|
"atproto",
|
|
16
18
|
"standard-site"
|
|
@@ -28,8 +30,8 @@
|
|
|
28
30
|
"type": "module",
|
|
29
31
|
"exports": {
|
|
30
32
|
".": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
+
"types": "./dist/search.d.ts",
|
|
34
|
+
"import": "./dist/search.js"
|
|
33
35
|
}
|
|
34
36
|
},
|
|
35
37
|
"main": "./dist/search.js",
|
|
@@ -37,27 +39,32 @@
|
|
|
37
39
|
"files": [
|
|
38
40
|
"dist/",
|
|
39
41
|
"README.md",
|
|
42
|
+
"REMOVED.md",
|
|
40
43
|
"LICENSE"
|
|
41
44
|
],
|
|
42
45
|
"scripts": {
|
|
43
46
|
"build": "npm run clean && tsc",
|
|
44
47
|
"clean": "rm -rf dist",
|
|
45
|
-
"fmt": "bun run dprint fmt",
|
|
46
48
|
"prepublishOnly": "npm run build",
|
|
47
|
-
"test": "bun test"
|
|
49
|
+
"test": "bun test",
|
|
50
|
+
"typecheck": "tsc --noEmit"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
53
|
"@mozilla/readability": "0.5.0",
|
|
51
54
|
"jsdom": "26.1.0"
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
54
|
-
"@opencode
|
|
57
|
+
"@opencode/plugin": "2.0.10",
|
|
55
58
|
"@types/bun": "1.3.9",
|
|
56
59
|
"@types/jsdom": "27.0.0",
|
|
57
|
-
"dprint": "latest",
|
|
58
60
|
"typescript": "5.9.3"
|
|
59
61
|
},
|
|
60
62
|
"peerDependencies": {
|
|
61
|
-
"@opencode
|
|
63
|
+
"@opencode/plugin": ">=2.0.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"@opencode/plugin": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ggl-search.d.ts","sourceRoot":"","sources":["../../../src/providers/ggl-search.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAkBD,eAAO,MAAM,YAAY,GAAU,OAAO,MAAM,KAAG,OAAO,CAAC,YAAY,EAAE,CA2FxE,CAAA"}
|