opencode-search 1.0.0-next.4 → 1.0.0-next.8
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 +4 -18
- package/REMOVED.md +10 -0
- package/dist/package.json +6 -5
- package/dist/src/providers/gnews-search.d.ts +1 -1
- package/dist/src/providers/gnews-search.d.ts.map +1 -1
- package/dist/src/providers/gnews-search.js +5 -3
- package/dist/src/providers/gnews-search.js.map +1 -1
- package/dist/src/renderers.d.ts +0 -2
- package/dist/src/renderers.d.ts.map +1 -1
- package/dist/src/renderers.js +0 -8
- package/dist/src/renderers.js.map +1 -1
- package/dist/src/search.d.ts +0 -1
- package/dist/src/search.d.ts.map +1 -1
- package/dist/src/search.js +27 -55
- package/dist/src/search.js.map +1 -1
- package/package.json +6 -5
- package/search.ts +22 -0
- package/src/cache.test.ts +14 -0
- package/src/cache.ts +61 -0
- package/src/format.test.ts +175 -0
- package/src/format.ts +72 -0
- package/src/html.ts +39 -0
- package/src/normalize-blurb.test.ts +67 -0
- package/src/normalize-blurb.ts +22 -0
- package/src/opencode/notify.ts +16 -0
- package/src/parse-results.test.ts +75 -0
- package/src/parse-results.ts +22 -0
- package/src/providers/brave-search.ts +39 -0
- package/src/providers/bsky-search.test.ts +16 -0
- package/src/providers/bsky-search.ts +88 -0
- package/src/providers/ddg-search.test.ts +15 -0
- package/src/providers/ddg-search.ts +117 -0
- package/src/providers/gnews-search.ts +72 -0
- package/src/providers/mdn-search.test.ts +17 -0
- package/src/providers/mdn-search.ts +83 -0
- package/src/providers/wiki-search.test.ts +16 -0
- package/src/providers/wiki-search.ts +72 -0
- package/src/renderers.test.ts +263 -0
- package/src/renderers.ts +42 -0
- package/src/safe.test.ts +87 -0
- package/src/safe.ts +27 -0
- package/src/search.ts +264 -0
- package/src/strategies.test.ts +92 -0
- package/src/strategies.ts +62 -0
- package/src/user-agent.ts +3 -0
- package/src/v1-message.test.ts +17 -0
- package/src/v1-message.ts +10 -0
- package/dist/src/providers/standard-search.d.ts +0 -18
- package/dist/src/providers/standard-search.d.ts.map +0 -1
- package/dist/src/providers/standard-search.js +0 -61
- package/dist/src/providers/standard-search.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# opencode-search
|
|
2
2
|
|
|
3
|
-
An [OpenCode](https://opencode.ai) plugin that gives your agent access to DuckDuckGo, Brave, Google News, Wikipedia, Bluesky,
|
|
3
|
+
An [OpenCode](https://opencode.ai) plugin that gives your agent access to DuckDuckGo, Brave, Google News, Wikipedia, Bluesky, and MDN Web Docs.
|
|
4
4
|
|
|
5
5
|
<img width="786" height="377" alt="image" src="https://github.com/user-attachments/assets/9ad19ade-402a-4cc1-9882-a33d2a8e4d42" />
|
|
6
6
|
|
|
7
7
|
## What this adds over OpenCode's built-in tools
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Six search tools that work without an API key. OpenCode 1 has no web search at all unless you use its own provider, and OpenCode 2's requires a key for Exa, Firecrawl, Parallel or Tavily.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Four of the tools search sources a general web search does not reach: Bluesky posts through the AT Protocol, Wikipedia and MDN through their own APIs, and Google News for what is being published now.
|
|
12
12
|
|
|
13
13
|
**Use at your own risk:** the DuckDuckGo and Brave providers scrape HTML nobody promised would stay parseable, so they can break without warning and may run against a service's terms. Results are unverified input.
|
|
14
14
|
|
|
15
|
-
Google web search and
|
|
15
|
+
Google web search, Mojeek and standard.site were removed — see [REMOVED.md](REMOVED.md) for what was tested and why.
|
|
16
16
|
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
@@ -81,20 +81,6 @@ Search Bluesky posts via the AT Protocol. Returns posts with author handle, text
|
|
|
81
81
|
| `limit` | number | no | Number of results to return |
|
|
82
82
|
| `sort` | string | no | Sort order: `top` or `latest` |
|
|
83
83
|
|
|
84
|
-
### standard_search
|
|
85
|
-
|
|
86
|
-
Search [standard.site](https://standard.site) document records on the AT Protocol. Returns blog posts and articles published to the ATmosphere with title, URL, date, and snippet.
|
|
87
|
-
|
|
88
|
-
| Parameter | Type | Required | Description |
|
|
89
|
-
| --------- | ------ | -------- | ---------------------------------- |
|
|
90
|
-
| `query` | string | yes | |
|
|
91
|
-
| `limit` | number | no | Number of results to return |
|
|
92
|
-
| `offset` | number | no | Number of results to skip |
|
|
93
|
-
|
|
94
|
-
standard.site is a publishing platform built on the AT Protocol where content is stored in a user's personal data repository. Unlike traditional websites that require crawlers and indexing pipelines to be discoverable, content published on standard.site is structured, portable, and directly queryable through the AT Protocol.
|
|
95
|
-
|
|
96
|
-
**Currently unavailable.** The appview this tool queries, `standard-search.octet-stream.net`, refuses connections, and no replacement endpoint is published on standard.site or in its docs. The provider is left in place unchanged; its live test soft-skips while the host is unreachable, so the suite stays green without masking parser regressions.
|
|
97
|
-
|
|
98
84
|
### wiki_search
|
|
99
85
|
|
|
100
86
|
Search Wikipedia articles using the MediaWiki REST API. Returns structured results with title, description, excerpt, and a direct link to the article. No API key required.
|
package/REMOVED.md
CHANGED
|
@@ -18,6 +18,16 @@ The gate is applied before the page is built, so TLS fingerprinting is not the v
|
|
|
18
18
|
|
|
19
19
|
Use `brave_search` or `ddg_search` instead, or `gnews_search` for news — Google News RSS is a separate service and still answers plain HTTP.
|
|
20
20
|
|
|
21
|
+
## standard_search — standard.site
|
|
22
|
+
|
|
23
|
+
The appview this tool queried, `standard-search.octet-stream.net`, no longer resolves. Checked 2026-09-19: no DNS record at all, so the host is gone rather than temporarily down.
|
|
24
|
+
|
|
25
|
+
standard.site itself is alive and answers on `/`, but publishes no replacement search endpoint. `/docs` returns 200 and mentions none; `/api`, `/about` and `/developers` are 404.
|
|
26
|
+
|
|
27
|
+
The provider had been kept in place with its live test soft-skipping while the host was unreachable. With the DNS record gone and nothing documented to point at, there is no endpoint to restore it to.
|
|
28
|
+
|
|
29
|
+
Worth revisiting if standard.site publishes an appview again — the AT Protocol records it searched are structured and directly queryable, which no general web search substitutes for.
|
|
30
|
+
|
|
21
31
|
## mojeek_search — Mojeek
|
|
22
32
|
|
|
23
33
|
Mojeek's [robots.txt](https://www.mojeek.com/robots.txt) is `Disallow: /search` for all user agents, and their [terms](https://www.mojeek.com/about/terms.html) prohibit automated access except by "an authorised Mojeek API user", stating that "scraping the Services without Our prior consent is expressly prohibited".
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-search",
|
|
3
|
-
"version": "1.0.0-next.
|
|
4
|
-
"description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky,
|
|
3
|
+
"version": "1.0.0-next.8",
|
|
4
|
+
"description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky, and MDN Web Docs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
7
7
|
"opencode-plugin",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"wikipedia",
|
|
15
15
|
"mdn",
|
|
16
16
|
"bluesky",
|
|
17
|
-
"atproto"
|
|
18
|
-
"standard-site"
|
|
17
|
+
"atproto"
|
|
19
18
|
],
|
|
20
19
|
"homepage": "https://github.com/whaaaley/opencode-search#readme",
|
|
21
20
|
"bugs": {
|
|
@@ -38,6 +37,8 @@
|
|
|
38
37
|
"types": "./dist/search.d.ts",
|
|
39
38
|
"files": [
|
|
40
39
|
"dist/",
|
|
40
|
+
"src/",
|
|
41
|
+
"search.ts",
|
|
41
42
|
"README.md",
|
|
42
43
|
"REMOVED.md",
|
|
43
44
|
"LICENSE"
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "npm run clean && tsc",
|
|
47
48
|
"clean": "rm -rf dist",
|
|
48
|
-
"
|
|
49
|
+
"prepare": "npm run build",
|
|
49
50
|
"test": "bun test",
|
|
50
51
|
"typecheck": "tsc --noEmit"
|
|
51
52
|
},
|
|
@@ -5,5 +5,5 @@ export type GnewsResult = {
|
|
|
5
5
|
source: string;
|
|
6
6
|
date: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const gnewsSearch: (query: string) => Promise<GnewsResult[]>;
|
|
8
|
+
export declare const gnewsSearch: (query: string, limit?: number) => Promise<GnewsResult[]>;
|
|
9
9
|
//# sourceMappingURL=gnews-search.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gnews-search.d.ts","sourceRoot":"","sources":["../../../src/providers/gnews-search.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;
|
|
1
|
+
{"version":3,"file":"gnews-search.d.ts","sourceRoot":"","sources":["../../../src/providers/gnews-search.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAwBD,eAAO,MAAM,WAAW,GAAU,OAAO,MAAM,EAAE,cAAqB,KAAG,OAAO,CAAC,WAAW,EAAE,CAmC7F,CAAA"}
|
|
@@ -16,11 +16,13 @@ const stripSource = (title, source) => {
|
|
|
16
16
|
const suffix = ' - ' + source;
|
|
17
17
|
return title.endsWith(suffix) ? title.slice(0, -suffix.length) : title;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
// The feed always returns about 100 items, which is ~10k tokens of context for one call.
|
|
20
|
+
const DEFAULT_LIMIT = 20;
|
|
21
|
+
export const gnewsSearch = async (query, limit = DEFAULT_LIMIT) => {
|
|
20
22
|
const cacheKey = 'gnews:' + query;
|
|
21
23
|
const cached = await cache.get(cacheKey);
|
|
22
24
|
if (cached)
|
|
23
|
-
return cached;
|
|
25
|
+
return cached.slice(0, limit);
|
|
24
26
|
const params = new URLSearchParams({ q: query, hl: 'en-US', gl: 'US', ceid: 'US:en' });
|
|
25
27
|
const res = await fetch(GNEWS_URL + '?' + params, { headers: baseHeaders('') });
|
|
26
28
|
if (!res.ok)
|
|
@@ -43,6 +45,6 @@ export const gnewsSearch = async (query) => {
|
|
|
43
45
|
results.push({ title, url, abstract: '', source, date: tag('pubDate') });
|
|
44
46
|
}
|
|
45
47
|
await cache.set(cacheKey, results);
|
|
46
|
-
return results;
|
|
48
|
+
return results.slice(0, limit);
|
|
47
49
|
};
|
|
48
50
|
//# sourceMappingURL=gnews-search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gnews-search.js","sourceRoot":"","sources":["../../../src/providers/gnews-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,+FAA+F;AAC/F,MAAM,SAAS,GAAG,oCAAoC,CAAA;AAUtD,MAAM,QAAQ,GAA2B;IACvC,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;CACb,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,CAChD,KAAK,CAAC,OAAO,CAAC,gCAAgC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CACrF,CAAA;AAED,mGAAmG;AACnG,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,MAAc,EAAU,EAAE;IAC5D,MAAM,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;IAC7B,OAAO,KAAK,CAAC,QAAQ,CAAC,MA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AAO,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC9E,CAAC,CAAA;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC5B,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAA;QAC/C,gFAAgF;QAChF,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;QAEvB,IAAI,KAAK,IAAI,GAAG;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAElC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA"}
|
package/dist/src/renderers.d.ts
CHANGED
|
@@ -2,13 +2,11 @@ import type { BskyPost } from './providers/bsky-search.ts';
|
|
|
2
2
|
import type { DdgResult } from './providers/ddg-search.ts';
|
|
3
3
|
import type { GnewsResult } from './providers/gnews-search.ts';
|
|
4
4
|
import type { MdnDocument } from './providers/mdn-search.ts';
|
|
5
|
-
import type { StandardDocument } from './providers/standard-search.ts';
|
|
6
5
|
import type { WikiPage } from './providers/wiki-search.ts';
|
|
7
6
|
export declare const renderDdgResult: (result: DdgResult, index: number) => string;
|
|
8
7
|
export declare const renderWebResult: (result: DdgResult, index: number) => string;
|
|
9
8
|
export declare const renderGnewsItem: (result: GnewsResult, index: number) => string;
|
|
10
9
|
export declare const renderBskyPost: (post: BskyPost, index: number) => string;
|
|
11
|
-
export declare const renderStandardDoc: (doc: StandardDocument, index: number) => string;
|
|
12
10
|
export declare const renderWikiPage: (page: WikiPage, index: number) => string;
|
|
13
11
|
export declare const renderMdnDoc: (doc: MdnDocument, index: number) => string;
|
|
14
12
|
//# sourceMappingURL=renderers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../src/renderers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAC5D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../src/renderers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAE1D,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,EAAE,OAAO,MAAM,KAAG,MAIlE,CAAA;AAGD,eAAO,MAAM,eAAe,WAPY,SAAS,SAAS,MAAM,KAAG,MAOrB,CAAA;AAE9C,eAAO,MAAM,eAAe,GAAI,QAAQ,WAAW,EAAE,OAAO,MAAM,KAAG,MAIpE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,KAAG,MAI9D,CAAA;AAGD,eAAO,MAAM,cAAc,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,KAAG,MAK9D,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,WAAW,EAAE,OAAO,MAAM,KAAG,MAI9D,CAAA"}
|
package/dist/src/renderers.js
CHANGED
|
@@ -15,14 +15,6 @@ export const renderGnewsItem = (result, index) => {
|
|
|
15
15
|
export const renderBskyPost = (post, index) => (`${index + 1}. @${post.author.handle} (${formatDateTime(post.record.createdAt)})
|
|
16
16
|
${normalizeBlurb(post.record.text)}
|
|
17
17
|
Likes: ${post.likeCount} Reposts: ${post.repostCount} Replies: ${post.replyCount}`);
|
|
18
|
-
export const renderStandardDoc = (doc, index) => {
|
|
19
|
-
const title = doc.date
|
|
20
|
-
? `${index + 1}. ${doc.title} (${formatDate(doc.date)})`
|
|
21
|
-
: `${index + 1}. ${doc.title}`;
|
|
22
|
-
return `${title}
|
|
23
|
-
${doc.url}
|
|
24
|
-
${normalizeBlurb(doc.snippet)}`;
|
|
25
|
-
};
|
|
26
18
|
export const renderWikiPage = (page, index) => {
|
|
27
19
|
const desc = page.description ? `\n ${normalizeBlurb(page.description)}` : '';
|
|
28
20
|
return `${index + 1}. ${page.title}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../src/renderers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../src/renderers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAOrD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAiB,EAAE,KAAa,EAAU,EAAE;IAC1E,OAAO,GAAG,KAAK,GAAG,CAAC,KAAK,MAAM,CAAC,KAAK;KACjC,MAAM,CAAC,GAAG;KACV,cAAc,CAAC,MAAM,CAAC,QAAQ,CAA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GAAG,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK;kCACD,GAAG,CAAC,OAAO;KACxC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAA;AAClC,CAAC,CAAA"}
|
package/dist/src/search.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type * as Tool from '@opencode/plugin/promise/tool';
|
|
|
3
3
|
export declare const createDdgSearchTool: (context: Plugin.Context) => Tool.Info;
|
|
4
4
|
export declare const createBraveSearchTool: (context: Plugin.Context) => Tool.Info;
|
|
5
5
|
export declare const createBskySearchTool: (context: Plugin.Context) => Tool.Info;
|
|
6
|
-
export declare const createStandardSearchTool: (context: Plugin.Context) => Tool.Info;
|
|
7
6
|
export declare const createWikiSearchTool: (context: Plugin.Context) => Tool.Info;
|
|
8
7
|
export declare const createGnewsSearchTool: (context: Plugin.Context) => Tool.Info;
|
|
9
8
|
export declare const createMdnSearchTool: (context: Plugin.Context) => Tool.Info;
|
package/dist/src/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,KAAK,IAAI,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,KAAK,IAAI,MAAM,+BAA+B,CAAA;AAwD1D,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAqBjE,CAAA;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAqBnE,CAAA;AAEF,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAwClE,CAAA;AAEF,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAmClE,CAAA;AAEF,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAkCnE,CAAA;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAoCjE,CAAA;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAAI,EAOpE,CAAA"}
|
package/dist/src/search.js
CHANGED
|
@@ -5,15 +5,15 @@ import { bskySearch } from "./providers/bsky-search.js";
|
|
|
5
5
|
import { ddgSearch } from "./providers/ddg-search.js";
|
|
6
6
|
import { gnewsSearch } from "./providers/gnews-search.js";
|
|
7
7
|
import { mdnSearch } from "./providers/mdn-search.js";
|
|
8
|
-
import { standardSearch } from "./providers/standard-search.js";
|
|
9
8
|
import { wikiSearch } from "./providers/wiki-search.js";
|
|
10
|
-
import { renderBskyPost, renderDdgResult, renderGnewsItem, renderMdnDoc,
|
|
9
|
+
import { renderBskyPost, renderDdgResult, renderGnewsItem, renderMdnDoc, renderWebResult, renderWikiPage, } from "./renderers.js";
|
|
11
10
|
import { safeAsync } from "./safe.js";
|
|
12
11
|
const postResult = async (context, ctx, text) => {
|
|
13
12
|
await safeAsync(() => sendResult({ context, sessionID: ctx.sessionID, text }));
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// No `output` field: declaring one without a matching output schema in the tool definition makes
|
|
15
|
+
// OpenCode reject the result.
|
|
16
|
+
const textOutput = (text) => ({
|
|
17
17
|
content: [{ type: 'text', text }],
|
|
18
18
|
});
|
|
19
19
|
const isRecord = (value) => (typeof value === 'object' && value !== null && !Array.isArray(value));
|
|
@@ -45,7 +45,7 @@ export const createDdgSearchTool = (context) => ({
|
|
|
45
45
|
const query = stringField(input, 'query');
|
|
46
46
|
const { data, error } = await safeAsync(() => ddgSearch(query));
|
|
47
47
|
if (error)
|
|
48
|
-
return textOutput(
|
|
48
|
+
return textOutput('DuckDuckGo search failed: ' + error.message);
|
|
49
49
|
const formatted = formatResults({
|
|
50
50
|
label: 'DuckDuckGo results',
|
|
51
51
|
items: data,
|
|
@@ -53,7 +53,7 @@ export const createDdgSearchTool = (context) => ({
|
|
|
53
53
|
renderItem: renderDdgResult,
|
|
54
54
|
});
|
|
55
55
|
await postResult(context, ctx, formatted);
|
|
56
|
-
return textOutput(
|
|
56
|
+
return textOutput(formatted);
|
|
57
57
|
},
|
|
58
58
|
});
|
|
59
59
|
export const createBraveSearchTool = (context) => ({
|
|
@@ -64,7 +64,7 @@ export const createBraveSearchTool = (context) => ({
|
|
|
64
64
|
const query = stringField(input, 'query');
|
|
65
65
|
const { data, error } = await safeAsync(() => braveSearch(query));
|
|
66
66
|
if (error)
|
|
67
|
-
return textOutput(
|
|
67
|
+
return textOutput('Brave search failed: ' + error.message);
|
|
68
68
|
const formatted = formatResults({
|
|
69
69
|
label: 'Brave results',
|
|
70
70
|
items: data,
|
|
@@ -72,7 +72,7 @@ export const createBraveSearchTool = (context) => ({
|
|
|
72
72
|
renderItem: renderWebResult,
|
|
73
73
|
});
|
|
74
74
|
await postResult(context, ctx, formatted);
|
|
75
|
-
return textOutput(
|
|
75
|
+
return textOutput(formatted);
|
|
76
76
|
},
|
|
77
77
|
});
|
|
78
78
|
export const createBskySearchTool = (context) => ({
|
|
@@ -97,7 +97,7 @@ export const createBskySearchTool = (context) => ({
|
|
|
97
97
|
const sort = stringField(input, 'sort') || undefined;
|
|
98
98
|
const { data, error } = await safeAsync(() => (bskySearch({ query, limit, sort })));
|
|
99
99
|
if (error)
|
|
100
|
-
return textOutput(
|
|
100
|
+
return textOutput('Bluesky search failed: ' + error.message);
|
|
101
101
|
const formatted = formatResults({
|
|
102
102
|
label: 'Bluesky results',
|
|
103
103
|
items: data.posts,
|
|
@@ -107,43 +107,7 @@ export const createBskySearchTool = (context) => ({
|
|
|
107
107
|
renderItem: renderBskyPost,
|
|
108
108
|
});
|
|
109
109
|
await postResult(context, ctx, formatted);
|
|
110
|
-
return textOutput(
|
|
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' },
|
|
125
|
-
},
|
|
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.');
|
|
110
|
+
return textOutput(formatted);
|
|
147
111
|
},
|
|
148
112
|
});
|
|
149
113
|
export const createWikiSearchTool = (context) => ({
|
|
@@ -163,7 +127,7 @@ export const createWikiSearchTool = (context) => ({
|
|
|
163
127
|
const limit = numberField(input, 'limit');
|
|
164
128
|
const { data, error } = await safeAsync(() => (wikiSearch({ query, limit })));
|
|
165
129
|
if (error)
|
|
166
|
-
return textOutput(
|
|
130
|
+
return textOutput('Wikipedia search failed: ' + error.message);
|
|
167
131
|
const formatted = formatResults({
|
|
168
132
|
label: 'Wikipedia results',
|
|
169
133
|
items: data.pages,
|
|
@@ -173,7 +137,7 @@ export const createWikiSearchTool = (context) => ({
|
|
|
173
137
|
renderItem: renderWikiPage,
|
|
174
138
|
});
|
|
175
139
|
await postResult(context, ctx, formatted);
|
|
176
|
-
return textOutput(
|
|
140
|
+
return textOutput(formatted);
|
|
177
141
|
},
|
|
178
142
|
});
|
|
179
143
|
export const createGnewsSearchTool = (context) => ({
|
|
@@ -183,12 +147,21 @@ export const createGnewsSearchTool = (context) => ({
|
|
|
183
147
|
'News and tech media only — not general web search, and not documentation.',
|
|
184
148
|
'Links are news.google.com redirect URLs, not publisher URLs.',
|
|
185
149
|
].join(' '),
|
|
186
|
-
input:
|
|
150
|
+
input: {
|
|
151
|
+
type: 'object',
|
|
152
|
+
properties: {
|
|
153
|
+
query: { type: 'string', description: 'The search query' },
|
|
154
|
+
limit: { type: 'number', description: 'Maximum number of results to return (default 20)' },
|
|
155
|
+
},
|
|
156
|
+
required: ['query'],
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
},
|
|
187
159
|
async execute(input, ctx) {
|
|
188
160
|
const query = stringField(input, 'query');
|
|
189
|
-
const
|
|
161
|
+
const limit = numberField(input, 'limit');
|
|
162
|
+
const { data, error } = await safeAsync(() => gnewsSearch(query, limit));
|
|
190
163
|
if (error)
|
|
191
|
-
return textOutput(
|
|
164
|
+
return textOutput('Google News search failed: ' + error.message);
|
|
192
165
|
const formatted = formatResults({
|
|
193
166
|
label: 'Google News results',
|
|
194
167
|
items: data,
|
|
@@ -196,7 +169,7 @@ export const createGnewsSearchTool = (context) => ({
|
|
|
196
169
|
renderItem: renderGnewsItem,
|
|
197
170
|
});
|
|
198
171
|
await postResult(context, ctx, formatted);
|
|
199
|
-
return textOutput(
|
|
172
|
+
return textOutput(formatted);
|
|
200
173
|
},
|
|
201
174
|
});
|
|
202
175
|
export const createMdnSearchTool = (context) => ({
|
|
@@ -218,7 +191,7 @@ export const createMdnSearchTool = (context) => ({
|
|
|
218
191
|
const page = numberField(input, 'page');
|
|
219
192
|
const { data, error } = await safeAsync(() => (mdnSearch({ query, limit, page })));
|
|
220
193
|
if (error)
|
|
221
|
-
return textOutput(
|
|
194
|
+
return textOutput('MDN search failed: ' + error.message);
|
|
222
195
|
const formatted = formatResults({
|
|
223
196
|
label: 'MDN Web Docs results',
|
|
224
197
|
items: data.documents,
|
|
@@ -227,7 +200,7 @@ export const createMdnSearchTool = (context) => ({
|
|
|
227
200
|
renderItem: renderMdnDoc,
|
|
228
201
|
});
|
|
229
202
|
await postResult(context, ctx, formatted);
|
|
230
|
-
return textOutput(
|
|
203
|
+
return textOutput(formatted);
|
|
231
204
|
},
|
|
232
205
|
});
|
|
233
206
|
export const createSearchTools = (context) => [
|
|
@@ -236,7 +209,6 @@ export const createSearchTools = (context) => [
|
|
|
236
209
|
createDdgSearchTool(context),
|
|
237
210
|
createGnewsSearchTool(context),
|
|
238
211
|
createMdnSearchTool(context),
|
|
239
|
-
createStandardSearchTool(context),
|
|
240
212
|
createWikiSearchTool(context),
|
|
241
213
|
];
|
|
242
214
|
//# 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":"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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AC9B,KAAK,EAAE,sBAAsB;YAC7B,KAAK,EAAE,IAAI,CAAC,SAAS;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK;YACL,UAAU,EAAE,YAAY;SACzB,CAAC,CAAA;QAEF,MAAM,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,CAAA;QAEzC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,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,oBAAoB,CAAC,OAAO,CAAC;CAC9B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-search",
|
|
3
|
-
"version": "1.0.0-next.
|
|
4
|
-
"description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky,
|
|
3
|
+
"version": "1.0.0-next.8",
|
|
4
|
+
"description": "OpenCode plugin that provides web search tools using DuckDuckGo, Brave, Google News, Wikipedia, Bluesky, and MDN Web Docs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
7
7
|
"opencode-plugin",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"wikipedia",
|
|
15
15
|
"mdn",
|
|
16
16
|
"bluesky",
|
|
17
|
-
"atproto"
|
|
18
|
-
"standard-site"
|
|
17
|
+
"atproto"
|
|
19
18
|
],
|
|
20
19
|
"homepage": "https://github.com/whaaaley/opencode-search#readme",
|
|
21
20
|
"bugs": {
|
|
@@ -38,6 +37,8 @@
|
|
|
38
37
|
"types": "./dist/search.d.ts",
|
|
39
38
|
"files": [
|
|
40
39
|
"dist/",
|
|
40
|
+
"src/",
|
|
41
|
+
"search.ts",
|
|
41
42
|
"README.md",
|
|
42
43
|
"REMOVED.md",
|
|
43
44
|
"LICENSE"
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "npm run clean && tsc",
|
|
47
48
|
"clean": "rm -rf dist",
|
|
48
|
-
"
|
|
49
|
+
"prepare": "npm run build",
|
|
49
50
|
"test": "bun test",
|
|
50
51
|
"typecheck": "tsc --noEmit"
|
|
51
52
|
},
|
package/search.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createSearchTools } from './src/search.ts'
|
|
2
|
+
import { safeAsync } from './src/safe.ts'
|
|
3
|
+
import { V1_MESSAGE } from './src/v1-message.ts'
|
|
4
|
+
|
|
5
|
+
// Under OpenCode 1 this package is absent or exports no Plugin.define.
|
|
6
|
+
// A dynamic import makes that catchable, so the failure can be a message instead of a stack trace.
|
|
7
|
+
const { data: plugin, error } = await safeAsync(() => import('@opencode/plugin'))
|
|
8
|
+
|
|
9
|
+
if (error || typeof plugin.Plugin?.define !== 'function') {
|
|
10
|
+
throw new Error(V1_MESSAGE, { cause: error ?? new Error('Plugin.define is not exported') })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default plugin.Plugin.define({
|
|
14
|
+
id: 'opencode-search',
|
|
15
|
+
setup: async (ctx) => {
|
|
16
|
+
await ctx.tool.transform((tools) => {
|
|
17
|
+
for (const definition of createSearchTools(ctx)) {
|
|
18
|
+
tools.add(definition)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
},
|
|
22
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { get, set } from './cache.ts'
|
|
3
|
+
|
|
4
|
+
describe('cache', () => {
|
|
5
|
+
it('stores and retrieves data', async () => {
|
|
6
|
+
const testKey = 'test:cache-key'
|
|
7
|
+
const testData = { foo: 'bar', nested: { value: 123 } }
|
|
8
|
+
|
|
9
|
+
await set(testKey, testData)
|
|
10
|
+
const result = await get(testKey)
|
|
11
|
+
|
|
12
|
+
expect(result).toEqual(testData)
|
|
13
|
+
})
|
|
14
|
+
})
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { safe, safeAsync } from './safe.ts'
|
|
5
|
+
|
|
6
|
+
const CACHE_FILE = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '.cache')
|
|
7
|
+
const CACHE_DURATION = 7 * 24 * 60 * 60 * 1000 // 7 days
|
|
8
|
+
|
|
9
|
+
type CacheEntry = {
|
|
10
|
+
data: unknown
|
|
11
|
+
timestamp: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type CacheStore = Record<string, CacheEntry>
|
|
15
|
+
|
|
16
|
+
let store: CacheStore = {}
|
|
17
|
+
let loaded = false
|
|
18
|
+
|
|
19
|
+
const loadCache = async () => {
|
|
20
|
+
if (loaded) return
|
|
21
|
+
|
|
22
|
+
const { data } = await safeAsync(() => readFile(CACHE_FILE, 'utf-8'))
|
|
23
|
+
|
|
24
|
+
if (data) {
|
|
25
|
+
const { data: parsed } = safe(() => JSON.parse(data) as CacheStore)
|
|
26
|
+
store = parsed ?? {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
loaded = true
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const saveCache = async () => {
|
|
33
|
+
await writeFile(CACHE_FILE, JSON.stringify(store, null, 2))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const get = async <T = unknown>(key: string): Promise<T | null> => {
|
|
37
|
+
await loadCache()
|
|
38
|
+
|
|
39
|
+
const entry = store[key]
|
|
40
|
+
if (!entry) return null
|
|
41
|
+
|
|
42
|
+
const age = Date.now() - entry.timestamp
|
|
43
|
+
if (age > CACHE_DURATION) {
|
|
44
|
+
delete store[key]
|
|
45
|
+
await saveCache()
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return entry.data as T
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const set = async (key: string, data: unknown): Promise<void> => {
|
|
53
|
+
await loadCache()
|
|
54
|
+
|
|
55
|
+
store[key] = {
|
|
56
|
+
data,
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await saveCache()
|
|
61
|
+
}
|