opencode-search 1.0.0-next.7 → 1.0.0-next.9

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.
Files changed (39) hide show
  1. package/README.md +35 -20
  2. package/REMOVED.md +10 -0
  3. package/dist/package.json +14 -10
  4. package/dist/src/providers/rfc-search.d.ts +9 -0
  5. package/dist/src/providers/rfc-search.d.ts.map +1 -0
  6. package/dist/src/providers/rfc-search.js +35 -0
  7. package/dist/src/providers/rfc-search.js.map +1 -0
  8. package/dist/src/providers/w3c-search.d.ts +6 -0
  9. package/dist/src/providers/w3c-search.d.ts.map +1 -0
  10. package/dist/src/providers/w3c-search.js +42 -0
  11. package/dist/src/providers/w3c-search.js.map +1 -0
  12. package/dist/src/providers/whatwg-search.d.ts +8 -0
  13. package/dist/src/providers/whatwg-search.d.ts.map +1 -0
  14. package/dist/src/providers/whatwg-search.js +31 -0
  15. package/dist/src/providers/whatwg-search.js.map +1 -0
  16. package/dist/src/renderers.d.ts +6 -2
  17. package/dist/src/renderers.d.ts.map +1 -1
  18. package/dist/src/renderers.js +14 -8
  19. package/dist/src/renderers.js.map +1 -1
  20. package/dist/src/search.d.ts +3 -1
  21. package/dist/src/search.d.ts.map +1 -1
  22. package/dist/src/search.js +91 -39
  23. package/dist/src/search.js.map +1 -1
  24. package/package.json +14 -10
  25. package/src/providers/rfc-search.test.ts +22 -0
  26. package/src/providers/rfc-search.ts +57 -0
  27. package/src/providers/w3c-search.test.ts +22 -0
  28. package/src/providers/w3c-search.ts +67 -0
  29. package/src/providers/whatwg-search.test.ts +21 -0
  30. package/src/providers/whatwg-search.ts +55 -0
  31. package/src/renderers.test.ts +0 -64
  32. package/src/renderers.ts +20 -9
  33. package/src/search.ts +105 -46
  34. package/dist/src/providers/standard-search.d.ts +0 -18
  35. package/dist/src/providers/standard-search.d.ts.map +0 -1
  36. package/dist/src/providers/standard-search.js +0 -61
  37. package/dist/src/providers/standard-search.js.map +0 -1
  38. package/src/providers/standard-search.test.ts +0 -29
  39. package/src/providers/standard-search.ts +0 -94
package/package.json CHANGED
@@ -1,21 +1,25 @@
1
1
  {
2
2
  "name": "opencode-search",
3
- "version": "1.0.0-next.7",
4
- "description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky, Standard.site, and MDN Web Docs.",
3
+ "version": "1.0.0-next.9",
4
+ "description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky, MDN Web Docs, and the IETF, W3C and WHATWG specifications.",
5
5
  "keywords": [
6
+ "atproto",
7
+ "bluesky",
8
+ "brave",
9
+ "duckduckgo",
10
+ "google-news",
11
+ "ietf",
12
+ "mdn",
6
13
  "opencode",
7
14
  "opencode-plugin",
8
15
  "plugin",
16
+ "rfc",
9
17
  "search",
18
+ "specifications",
19
+ "w3c",
10
20
  "web-search",
11
- "duckduckgo",
12
- "brave",
13
- "google-news",
14
- "wikipedia",
15
- "mdn",
16
- "bluesky",
17
- "atproto",
18
- "standard-site"
21
+ "whatwg",
22
+ "wikipedia"
19
23
  ],
20
24
  "homepage": "https://github.com/whaaaley/opencode-search#readme",
21
25
  "bugs": {
@@ -0,0 +1,22 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { rfcSearch } from './rfc-search.ts'
3
+
4
+ describe('rfcSearch', () => {
5
+ it('returns RFCs matching a title query', async () => {
6
+ const results = await rfcSearch('HTTP Semantics')
7
+
8
+ expect(results.length).toBeGreaterThan(0)
9
+
10
+ const first = results[0]
11
+ if (!first) throw new Error('Expected at least one RFC')
12
+
13
+ expect(first.id).toMatch(/^RFC\d+$/)
14
+ expect(first.url).toStartWith('https://www.rfc-editor.org/rfc/')
15
+ })
16
+
17
+ it('respects the limit', async () => {
18
+ const results = await rfcSearch('HTTP', 3)
19
+
20
+ expect(results.length).toBeLessThanOrEqual(3)
21
+ })
22
+ })
@@ -0,0 +1,57 @@
1
+ import * as cache from '../cache.ts'
2
+
3
+ const DATATRACKER_URL = 'https://datatracker.ietf.org/api/v1/doc/document/'
4
+ const DEFAULT_LIMIT = 20
5
+
6
+ export type RfcResult = {
7
+ id: string
8
+ title: string
9
+ url: string
10
+ date: string
11
+ abstract: string
12
+ }
13
+
14
+ type DatatrackerDoc = {
15
+ name?: string
16
+ title?: string
17
+ time?: string
18
+ abstract?: string
19
+ }
20
+
21
+ export const rfcSearch = async (query: string, limit = DEFAULT_LIMIT): Promise<RfcResult[]> => {
22
+ const cacheKey = 'rfc:' + query
23
+
24
+ const cached = await cache.get<RfcResult[]>(cacheKey)
25
+ if (cached) return cached.slice(0, limit)
26
+
27
+ const params = new URLSearchParams({
28
+ title__icontains: query,
29
+ type: 'rfc',
30
+ limit: String(Math.min(limit, 100)),
31
+ format: 'json',
32
+ })
33
+
34
+ const res = await fetch(DATATRACKER_URL + '?' + params)
35
+
36
+ if (!res.ok) throw new Error('IETF Datatracker returned ' + res.status + ' ' + res.statusText)
37
+
38
+ const body = await res.json() as { objects?: DatatrackerDoc[] }
39
+ const results: RfcResult[] = []
40
+
41
+ for (const doc of body.objects ?? []) {
42
+ const id = doc.name ?? ''
43
+ if (!id) continue
44
+
45
+ results.push({
46
+ id: id.toUpperCase(),
47
+ title: doc.title ?? '',
48
+ url: 'https://www.rfc-editor.org/rfc/' + id + '.html',
49
+ date: doc.time ?? '',
50
+ abstract: doc.abstract ?? '',
51
+ })
52
+ }
53
+
54
+ await cache.set(cacheKey, results)
55
+
56
+ return results.slice(0, limit)
57
+ }
@@ -0,0 +1,22 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { w3cSearch } from './w3c-search.ts'
3
+
4
+ describe('w3cSearch', () => {
5
+ it('filters specifications by title', async () => {
6
+ const results = await w3cSearch('CSS')
7
+
8
+ expect(results.length).toBeGreaterThan(0)
9
+
10
+ const first = results[0]
11
+ if (!first) throw new Error('Expected at least one specification')
12
+
13
+ expect(first.title.toLowerCase()).toContain('css')
14
+ expect(first.url).toStartWith('http')
15
+ })
16
+
17
+ it('respects the limit', async () => {
18
+ const results = await w3cSearch('CSS', 5)
19
+
20
+ expect(results.length).toBeLessThanOrEqual(5)
21
+ })
22
+ })
@@ -0,0 +1,67 @@
1
+ import * as cache from '../cache.ts'
2
+
3
+ // The W3C API accepts a `q` parameter and ignores it: 'css' and a nonsense string both return all
4
+ // 1713 specifications.
5
+ // So the whole list is fetched and filtered here, 1000 per page.
6
+ const API_URL = 'https://api.w3.org/specifications'
7
+ const PAGE_SIZE = 1000
8
+ const DEFAULT_LIMIT = 20
9
+
10
+ export type W3cResult = {
11
+ title: string
12
+ url: string
13
+ }
14
+
15
+ type Spec = {
16
+ title?: string
17
+ href?: string
18
+ 'shortlink'?: string
19
+ }
20
+
21
+ type Page = {
22
+ pages?: number
23
+ _links?: { specifications?: Spec[] }
24
+ }
25
+
26
+ const fetchPage = async (page: number): Promise<Page> => {
27
+ const params = new URLSearchParams({ items: String(PAGE_SIZE), page: String(page) })
28
+ const res = await fetch(API_URL + '?' + params)
29
+
30
+ if (!res.ok) throw new Error('W3C API returned ' + res.status + ' ' + res.statusText)
31
+
32
+ return await res.json() as Page
33
+ }
34
+
35
+ export const w3cSearch = async (query: string, limit = DEFAULT_LIMIT): Promise<W3cResult[]> => {
36
+ const cacheKey = 'w3c:' + query
37
+
38
+ const cached = await cache.get<W3cResult[]>(cacheKey)
39
+ if (cached) return cached.slice(0, limit)
40
+
41
+ const first = await fetchPage(1)
42
+ const specs = [...first._links?.specifications ?? []]
43
+
44
+ // `pages` counts pages at the requested size, so a second fetch covers the rest at 1000 each.
45
+ const total = first.pages ?? 1
46
+ for (let page = 2; page <= total; page++) {
47
+ const next = await fetchPage(page)
48
+ specs.push(...next._links?.specifications ?? [])
49
+ }
50
+
51
+ const needle = query.toLowerCase()
52
+ const results: W3cResult[] = []
53
+
54
+ for (const spec of specs) {
55
+ const title = spec.title ?? ''
56
+ const url = spec.shortlink ?? spec.href ?? ''
57
+
58
+ if (!title || !url) continue
59
+ if (!title.toLowerCase().includes(needle)) continue
60
+
61
+ results.push({ title, url })
62
+ }
63
+
64
+ await cache.set(cacheKey, results)
65
+
66
+ return results.slice(0, limit)
67
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { whatwgSearch } from './whatwg-search.ts'
3
+
4
+ describe('whatwgSearch', () => {
5
+ it('finds a living standard by name', async () => {
6
+ const results = await whatwgSearch('HTML')
7
+
8
+ expect(results.length).toBeGreaterThan(0)
9
+
10
+ const first = results[0]
11
+ if (!first) throw new Error('Expected at least one standard')
12
+
13
+ expect(first.url).toContain('spec.whatwg.org')
14
+ })
15
+
16
+ it('returns nothing for a query that matches no standard', async () => {
17
+ const results = await whatwgSearch('zzzznotastandard')
18
+
19
+ expect(results.length).toEqual(0)
20
+ })
21
+ })
@@ -0,0 +1,55 @@
1
+ import * as cache from '../cache.ts'
2
+
3
+ // WHATWG publishes its whole standards index as one small JSON file, and offers no search endpoint.
4
+ const DB_URL = 'https://raw.githubusercontent.com/whatwg/sg/main/db.json'
5
+ const DEFAULT_LIMIT = 20
6
+
7
+ export type WhatwgResult = {
8
+ title: string
9
+ url: string
10
+ abstract: string
11
+ workstream: string
12
+ }
13
+
14
+ type Standard = {
15
+ name?: string
16
+ href?: string
17
+ description?: string
18
+ }
19
+
20
+ type Workstream = {
21
+ name?: string
22
+ standards?: Standard[]
23
+ }
24
+
25
+ export const whatwgSearch = async (query: string, limit = DEFAULT_LIMIT): Promise<WhatwgResult[]> => {
26
+ const cacheKey = 'whatwg:' + query
27
+
28
+ const cached = await cache.get<WhatwgResult[]>(cacheKey)
29
+ if (cached) return cached.slice(0, limit)
30
+
31
+ const res = await fetch(DB_URL)
32
+
33
+ if (!res.ok) throw new Error('WHATWG index returned ' + res.status + ' ' + res.statusText)
34
+
35
+ const body = await res.json() as { workstreams?: Workstream[] }
36
+ const needle = query.toLowerCase()
37
+ const results: WhatwgResult[] = []
38
+
39
+ for (const workstream of body.workstreams ?? []) {
40
+ for (const standard of workstream.standards ?? []) {
41
+ const title = standard.name ?? ''
42
+ const url = standard.href ?? ''
43
+ const abstract = standard.description ?? ''
44
+
45
+ if (!title || !url) continue
46
+ if (!(title + ' ' + abstract).toLowerCase().includes(needle)) continue
47
+
48
+ results.push({ title, url, abstract, workstream: workstream.name ?? '' })
49
+ }
50
+ }
51
+
52
+ await cache.set(cacheKey, results)
53
+
54
+ return results.slice(0, limit)
55
+ }
@@ -4,7 +4,6 @@ import {
4
4
  renderDdgResult,
5
5
  renderGnewsItem,
6
6
  renderMdnDoc,
7
- renderStandardDoc,
8
7
  renderWebResult,
9
8
  renderWikiPage,
10
9
  } from './renderers.ts'
@@ -134,69 +133,6 @@ describe('renderBskyPost', () => {
134
133
  })
135
134
  })
136
135
 
137
- describe('renderStandardDoc', () => {
138
- it('includes date in title line when date is present', () => {
139
- const doc = {
140
- title: 'My Article',
141
- url: 'https://example.com/article',
142
- date: '2025-03-10',
143
- snippet: 'Article snippet text',
144
- }
145
- const lines = renderStandardDoc(doc, 0).split('\n')
146
- expect(lines[0]).toContain('1. My Article')
147
- expect(lines[0]).toContain('Mar')
148
- expect(lines[0]).toContain('2025')
149
- })
150
-
151
- it('omits date from title line when date is empty', () => {
152
- const doc = {
153
- title: 'No Date Article',
154
- url: 'https://example.com/nodate',
155
- date: '',
156
- snippet: 'Snippet',
157
- }
158
- const lines = renderStandardDoc(doc, 0).split('\n')
159
- expect(lines[0]).toBe('1. No Date Article')
160
- expect(lines[0]).not.toContain('(')
161
- })
162
-
163
- it('returns three lines: title, url, snippet', () => {
164
- const doc = {
165
- title: 'Title',
166
- url: 'https://example.com',
167
- date: '',
168
- snippet: 'Snippet text',
169
- }
170
- const lines = renderStandardDoc(doc, 0).split('\n')
171
- expect(lines).toHaveLength(3)
172
- expect(lines[1]).toContain('https://example.com')
173
- expect(lines[2]).toContain('Snippet text')
174
- })
175
-
176
- it('uses 1-based index', () => {
177
- const doc = {
178
- title: 'Title',
179
- url: 'https://example.com',
180
- date: '',
181
- snippet: 'Snippet',
182
- }
183
- const lines = renderStandardDoc(doc, 9).split('\n')
184
- expect(lines[0]).toStartWith('10. ')
185
- })
186
-
187
- it('indents url and snippet lines', () => {
188
- const doc = {
189
- title: 'Title',
190
- url: 'https://example.com',
191
- date: '',
192
- snippet: 'Snippet',
193
- }
194
- const lines = renderStandardDoc(doc, 0).split('\n')
195
- expect(lines[1]).toStartWith(' ')
196
- expect(lines[2]).toStartWith(' ')
197
- })
198
- })
199
-
200
136
  describe('renderWikiPage', () => {
201
137
  it('includes title and wikipedia url', () => {
202
138
  const result = renderWikiPage({
package/src/renderers.ts CHANGED
@@ -4,7 +4,9 @@ import type { BskyPost } from './providers/bsky-search.ts'
4
4
  import type { DdgResult } from './providers/ddg-search.ts'
5
5
  import type { GnewsResult } from './providers/gnews-search.ts'
6
6
  import type { MdnDocument } from './providers/mdn-search.ts'
7
- import type { StandardDocument } from './providers/standard-search.ts'
7
+ import type { RfcResult } from './providers/rfc-search.ts'
8
+ import type { W3cResult } from './providers/w3c-search.ts'
9
+ import type { WhatwgResult } from './providers/whatwg-search.ts'
8
10
  import type { WikiPage } from './providers/wiki-search.ts'
9
11
 
10
12
  export const renderDdgResult = (result: DdgResult, index: number): string => {
@@ -28,14 +30,6 @@ export const renderBskyPost = (post: BskyPost, index: number): string => (
28
30
  Likes: ${post.likeCount} Reposts: ${post.repostCount} Replies: ${post.replyCount}`
29
31
  )
30
32
 
31
- export const renderStandardDoc = (doc: StandardDocument, index: number): string => {
32
- const title = doc.date
33
- ? `${index + 1}. ${doc.title} (${formatDate(doc.date)})`
34
- : `${index + 1}. ${doc.title}`
35
- return `${title}
36
- ${doc.url}
37
- ${normalizeBlurb(doc.snippet)}`
38
- }
39
33
 
40
34
  export const renderWikiPage = (page: WikiPage, index: number): string => {
41
35
  const desc = page.description ? `\n ${normalizeBlurb(page.description)}` : ''
@@ -49,3 +43,20 @@ export const renderMdnDoc = (doc: MdnDocument, index: number): string => {
49
43
  https://developer.mozilla.org${doc.mdn_url}
50
44
  ${normalizeBlurb(doc.summary)}`
51
45
  }
46
+
47
+ export const renderRfc = (result: RfcResult, index: number): string => {
48
+ return `${index + 1}. ${result.id} — ${result.title}
49
+ ${result.url}
50
+ ${normalizeBlurb(result.abstract)}`
51
+ }
52
+
53
+ export const renderW3c = (result: W3cResult, index: number): string => {
54
+ return `${index + 1}. ${result.title}
55
+ ${result.url}`
56
+ }
57
+
58
+ export const renderWhatwg = (result: WhatwgResult, index: number): string => {
59
+ return `${index + 1}. ${result.title}
60
+ ${result.url}
61
+ ${normalizeBlurb(result.abstract)}`
62
+ }
package/src/search.ts CHANGED
@@ -7,14 +7,18 @@ import { bskySearch } from './providers/bsky-search.ts'
7
7
  import { ddgSearch } from './providers/ddg-search.ts'
8
8
  import { gnewsSearch } from './providers/gnews-search.ts'
9
9
  import { mdnSearch } from './providers/mdn-search.ts'
10
- import { standardSearch } from './providers/standard-search.ts'
10
+ import { rfcSearch } from './providers/rfc-search.ts'
11
+ import { w3cSearch } from './providers/w3c-search.ts'
12
+ import { whatwgSearch } from './providers/whatwg-search.ts'
11
13
  import { wikiSearch } from './providers/wiki-search.ts'
12
14
  import {
13
15
  renderBskyPost,
14
16
  renderDdgResult,
15
17
  renderGnewsItem,
16
18
  renderMdnDoc,
17
- renderStandardDoc,
19
+ renderRfc,
20
+ renderW3c,
21
+ renderWhatwg,
18
22
  renderWebResult,
19
23
  renderWikiPage,
20
24
  } from './renderers.ts'
@@ -145,49 +149,6 @@ export const createBskySearchTool = (context: Plugin.Context): Tool.Info => ({
145
149
  },
146
150
  })
147
151
 
148
- export const createStandardSearchTool = (context: Plugin.Context): Tool.Info => ({
149
- name: 'standard_search',
150
- description: [
151
- 'Search site.standard.document records on the AT Protocol.',
152
- 'Returns blog posts and articles from the ATmosphere.',
153
- ].join(' '),
154
- input: {
155
- type: 'object',
156
- properties: {
157
- query: { type: 'string', description: 'The search query' },
158
- limit: { type: 'number', description: 'Maximum number of results to return' },
159
- offset: { type: 'number', description: 'Number of results to skip' },
160
- },
161
- required: ['query'],
162
- additionalProperties: false,
163
- },
164
- async execute(input, ctx) {
165
- const query = stringField(input, 'query')
166
- const limit = numberField(input, 'limit')
167
- const offset = numberField(input, 'offset')
168
-
169
- const { data, error } = await safeAsync(() => (
170
- standardSearch({ query, limit, offset })
171
- ))
172
-
173
- if (error) return textOutput('Standard.site search failed: ' + error.message)
174
-
175
- const total = Number(data.totalResults) || data.documents.length
176
- const formatted = formatResults({
177
- label: 'Standard.site results',
178
- items: data.documents,
179
- total,
180
- limit,
181
- offset,
182
- renderItem: renderStandardDoc,
183
- })
184
-
185
- await postResult(context, ctx, formatted)
186
-
187
- return textOutput(formatted)
188
- },
189
- })
190
-
191
152
  export const createWikiSearchTool = (context: Plugin.Context): Tool.Info => ({
192
153
  name: 'wiki_search',
193
154
  description: 'Search Wikipedia articles. Returns page titles, descriptions, and excerpts.',
@@ -299,12 +260,110 @@ export const createMdnSearchTool = (context: Plugin.Context): Tool.Info => ({
299
260
  },
300
261
  })
301
262
 
263
+ export const createRfcSearchTool = (context: Plugin.Context): Tool.Info => ({
264
+ name: 'rfc_search',
265
+ description: 'Search IETF RFCs by title. Returns RFC number, title, date, and abstract.',
266
+ input: {
267
+ type: 'object',
268
+ properties: {
269
+ query: { type: 'string', description: 'The search query' },
270
+ limit: { type: 'number', description: 'Maximum number of results to return (default 20)' },
271
+ },
272
+ required: ['query'],
273
+ additionalProperties: false,
274
+ },
275
+ async execute(input, ctx) {
276
+ const query = stringField(input, 'query')
277
+ const limit = numberField(input, 'limit')
278
+
279
+ const { data, error } = await safeAsync(() => rfcSearch(query, limit))
280
+ if (error) return textOutput('RFC search failed: ' + error.message)
281
+
282
+ const formatted = formatResults({
283
+ label: 'RFC results',
284
+ items: data,
285
+ total: data.length,
286
+ renderItem: renderRfc,
287
+ })
288
+
289
+ await postResult(context, ctx, formatted)
290
+
291
+ return textOutput(formatted)
292
+ },
293
+ })
294
+
295
+ export const createW3cSearchTool = (context: Plugin.Context): Tool.Info => ({
296
+ name: 'w3c_search',
297
+ description: 'Search W3C specifications by title. Returns the spec title and its URL.',
298
+ input: {
299
+ type: 'object',
300
+ properties: {
301
+ query: { type: 'string', description: 'The search query' },
302
+ limit: { type: 'number', description: 'Maximum number of results to return (default 20)' },
303
+ },
304
+ required: ['query'],
305
+ additionalProperties: false,
306
+ },
307
+ async execute(input, ctx) {
308
+ const query = stringField(input, 'query')
309
+ const limit = numberField(input, 'limit')
310
+
311
+ const { data, error } = await safeAsync(() => w3cSearch(query, limit))
312
+ if (error) return textOutput('W3C search failed: ' + error.message)
313
+
314
+ const formatted = formatResults({
315
+ label: 'W3C results',
316
+ items: data,
317
+ total: data.length,
318
+ renderItem: renderW3c,
319
+ })
320
+
321
+ await postResult(context, ctx, formatted)
322
+
323
+ return textOutput(formatted)
324
+ },
325
+ })
326
+
327
+ export const createWhatwgSearchTool = (context: Plugin.Context): Tool.Info => ({
328
+ name: 'whatwg_search',
329
+ description: 'Search WHATWG living standards. Returns the standard name, URL, and description.',
330
+ input: {
331
+ type: 'object',
332
+ properties: {
333
+ query: { type: 'string', description: 'The search query' },
334
+ limit: { type: 'number', description: 'Maximum number of results to return (default 20)' },
335
+ },
336
+ required: ['query'],
337
+ additionalProperties: false,
338
+ },
339
+ async execute(input, ctx) {
340
+ const query = stringField(input, 'query')
341
+ const limit = numberField(input, 'limit')
342
+
343
+ const { data, error } = await safeAsync(() => whatwgSearch(query, limit))
344
+ if (error) return textOutput('WHATWG search failed: ' + error.message)
345
+
346
+ const formatted = formatResults({
347
+ label: 'WHATWG results',
348
+ items: data,
349
+ total: data.length,
350
+ renderItem: renderWhatwg,
351
+ })
352
+
353
+ await postResult(context, ctx, formatted)
354
+
355
+ return textOutput(formatted)
356
+ },
357
+ })
358
+
302
359
  export const createSearchTools = (context: Plugin.Context): Tool.Info[] => [
303
360
  createBraveSearchTool(context),
304
361
  createBskySearchTool(context),
305
362
  createDdgSearchTool(context),
306
363
  createGnewsSearchTool(context),
307
364
  createMdnSearchTool(context),
308
- createStandardSearchTool(context),
365
+ createRfcSearchTool(context),
366
+ createW3cSearchTool(context),
367
+ createWhatwgSearchTool(context),
309
368
  createWikiSearchTool(context),
310
369
  ]
@@ -1,18 +0,0 @@
1
- export type StandardDocument = {
2
- title: string;
3
- url: string;
4
- date: string;
5
- snippet: string;
6
- };
7
- export type StandardSearchResult = {
8
- documents: Array<StandardDocument>;
9
- totalResults: string;
10
- };
11
- type StandardSearchOptions = {
12
- query: string;
13
- limit?: number;
14
- offset?: number;
15
- };
16
- export declare const standardSearch: (options: StandardSearchOptions) => Promise<StandardSearchResult>;
17
- export {};
18
- //# sourceMappingURL=standard-search.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"standard-search.d.ts","sourceRoot":"","sources":["../../../src/providers/standard-search.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AA0BD,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,SAAS,qBAAqB,KAAG,OAAO,CAAC,oBAAoB,CA8CjG,CAAA"}
@@ -1,61 +0,0 @@
1
- import { JSDOM, VirtualConsole } from 'jsdom';
2
- import * as cache from "../cache.js";
3
- const SEARCH_URL = 'https://standard-search.octet-stream.net/search';
4
- const parseDocument = (el) => {
5
- const titleEl = el.querySelector('.result-title a');
6
- if (!titleEl || !titleEl.textContent)
7
- return null;
8
- const title = titleEl.textContent.trim();
9
- const href = titleEl.getAttribute('href');
10
- const urlEl = el.querySelector('.result-url');
11
- const urlText = urlEl && urlEl.textContent ? urlEl.textContent : '';
12
- const snippetEl = el.querySelector('.result-snippet');
13
- const snippet = snippetEl && snippetEl.textContent ? snippetEl.textContent : '';
14
- const parts = urlText.split(' \u00B7 ');
15
- const datePart = parts.length > 1 ? parts[1] : '';
16
- return {
17
- title,
18
- url: href ? href.trim() : '',
19
- date: datePart ? datePart.trim() : '',
20
- snippet: snippet.trim(),
21
- };
22
- };
23
- export const standardSearch = async (options) => {
24
- const cacheKey = ['standard', options.query, options.limit ?? 0, options.offset ?? 0].join(':');
25
- const cached = await cache.get(cacheKey);
26
- if (cached && cached.documents && cached.documents.length > 0)
27
- return cached;
28
- const url = SEARCH_URL + '?q=' + encodeURIComponent(options.query);
29
- const res = await fetch(url);
30
- if (!res.ok)
31
- throw new Error('Standard Search error (' + res.status + '): ' + res.statusText);
32
- const html = await res.text();
33
- const virtualConsole = new VirtualConsole();
34
- virtualConsole.on('jsdomError', () => { });
35
- const dom = new JSDOM(html, { url, virtualConsole });
36
- const doc = dom.window.document;
37
- const countEl = doc.querySelector('.result-count');
38
- const countText = countEl ? countEl.textContent : '';
39
- const totalResults = countText ? countText.trim() : '0';
40
- const elements = doc.querySelectorAll('.result');
41
- const documents = [];
42
- for (let i = 0; i < elements.length; i++) {
43
- const el = elements[i];
44
- if (!el)
45
- continue;
46
- const parsed = parseDocument(el);
47
- if (parsed)
48
- documents.push(parsed);
49
- }
50
- const start = options.offset ?? 0;
51
- const end = options.limit ? start + options.limit : documents.length;
52
- const sliced = documents.slice(start, end);
53
- const result = {
54
- documents: sliced,
55
- totalResults,
56
- };
57
- if (sliced.length > 0)
58
- await cache.set(cacheKey, result);
59
- return result;
60
- };
61
- //# sourceMappingURL=standard-search.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"standard-search.js","sourceRoot":"","sources":["../../../src/providers/standard-search.ts"],"names":[],"mappings":"AAAA,OA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