opencode-search 1.0.0-next.4 → 1.0.0-next.7
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/package.json +4 -2
- 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/search.d.ts.map +1 -1
- package/dist/src/search.js +28 -18
- package/dist/src/search.js.map +1 -1
- package/package.json +4 -2
- 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/standard-search.test.ts +29 -0
- package/src/providers/standard-search.ts +94 -0
- package/src/providers/wiki-search.test.ts +16 -0
- package/src/providers/wiki-search.ts +72 -0
- package/src/renderers.test.ts +327 -0
- package/src/renderers.ts +51 -0
- package/src/safe.test.ts +87 -0
- package/src/safe.ts +27 -0
- package/src/search.ts +310 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-search",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.7",
|
|
4
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",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"types": "./dist/search.d.ts",
|
|
39
39
|
"files": [
|
|
40
40
|
"dist/",
|
|
41
|
+
"src/",
|
|
42
|
+
"search.ts",
|
|
41
43
|
"README.md",
|
|
42
44
|
"REMOVED.md",
|
|
43
45
|
"LICENSE"
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
"scripts": {
|
|
46
48
|
"build": "npm run clean && tsc",
|
|
47
49
|
"clean": "rm -rf dist",
|
|
48
|
-
"
|
|
50
|
+
"prepare": "npm run build",
|
|
49
51
|
"test": "bun test",
|
|
50
52
|
"typecheck": "tsc --noEmit"
|
|
51
53
|
},
|
|
@@ -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,E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AAChC,CAAC,CAAA"}
|
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;AA0D1D,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,wBAAwB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG,IAAI,CAAC,IAyCtE,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,EAQpE,CAAA"}
|
package/dist/src/search.js
CHANGED
|
@@ -12,8 +12,9 @@ import { safeAsync } from "./safe.js";
|
|
|
12
12
|
const postResult = async (context, ctx, text) => {
|
|
13
13
|
await safeAsync(() => sendResult({ context, sessionID: ctx.sessionID, text }));
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// No `output` field: declaring one without a matching output schema in the tool definition makes
|
|
16
|
+
// OpenCode reject the result.
|
|
17
|
+
const textOutput = (text) => ({
|
|
17
18
|
content: [{ type: 'text', text }],
|
|
18
19
|
});
|
|
19
20
|
const isRecord = (value) => (typeof value === 'object' && value !== null && !Array.isArray(value));
|
|
@@ -45,7 +46,7 @@ export const createDdgSearchTool = (context) => ({
|
|
|
45
46
|
const query = stringField(input, 'query');
|
|
46
47
|
const { data, error } = await safeAsync(() => ddgSearch(query));
|
|
47
48
|
if (error)
|
|
48
|
-
return textOutput(
|
|
49
|
+
return textOutput('DuckDuckGo search failed: ' + error.message);
|
|
49
50
|
const formatted = formatResults({
|
|
50
51
|
label: 'DuckDuckGo results',
|
|
51
52
|
items: data,
|
|
@@ -53,7 +54,7 @@ export const createDdgSearchTool = (context) => ({
|
|
|
53
54
|
renderItem: renderDdgResult,
|
|
54
55
|
});
|
|
55
56
|
await postResult(context, ctx, formatted);
|
|
56
|
-
return textOutput(
|
|
57
|
+
return textOutput(formatted);
|
|
57
58
|
},
|
|
58
59
|
});
|
|
59
60
|
export const createBraveSearchTool = (context) => ({
|
|
@@ -64,7 +65,7 @@ export const createBraveSearchTool = (context) => ({
|
|
|
64
65
|
const query = stringField(input, 'query');
|
|
65
66
|
const { data, error } = await safeAsync(() => braveSearch(query));
|
|
66
67
|
if (error)
|
|
67
|
-
return textOutput(
|
|
68
|
+
return textOutput('Brave search failed: ' + error.message);
|
|
68
69
|
const formatted = formatResults({
|
|
69
70
|
label: 'Brave results',
|
|
70
71
|
items: data,
|
|
@@ -72,7 +73,7 @@ export const createBraveSearchTool = (context) => ({
|
|
|
72
73
|
renderItem: renderWebResult,
|
|
73
74
|
});
|
|
74
75
|
await postResult(context, ctx, formatted);
|
|
75
|
-
return textOutput(
|
|
76
|
+
return textOutput(formatted);
|
|
76
77
|
},
|
|
77
78
|
});
|
|
78
79
|
export const createBskySearchTool = (context) => ({
|
|
@@ -97,7 +98,7 @@ export const createBskySearchTool = (context) => ({
|
|
|
97
98
|
const sort = stringField(input, 'sort') || undefined;
|
|
98
99
|
const { data, error } = await safeAsync(() => (bskySearch({ query, limit, sort })));
|
|
99
100
|
if (error)
|
|
100
|
-
return textOutput(
|
|
101
|
+
return textOutput('Bluesky search failed: ' + error.message);
|
|
101
102
|
const formatted = formatResults({
|
|
102
103
|
label: 'Bluesky results',
|
|
103
104
|
items: data.posts,
|
|
@@ -107,7 +108,7 @@ export const createBskySearchTool = (context) => ({
|
|
|
107
108
|
renderItem: renderBskyPost,
|
|
108
109
|
});
|
|
109
110
|
await postResult(context, ctx, formatted);
|
|
110
|
-
return textOutput(
|
|
111
|
+
return textOutput(formatted);
|
|
111
112
|
},
|
|
112
113
|
});
|
|
113
114
|
export const createStandardSearchTool = (context) => ({
|
|
@@ -132,7 +133,7 @@ export const createStandardSearchTool = (context) => ({
|
|
|
132
133
|
const offset = numberField(input, 'offset');
|
|
133
134
|
const { data, error } = await safeAsync(() => (standardSearch({ query, limit, offset })));
|
|
134
135
|
if (error)
|
|
135
|
-
return textOutput(
|
|
136
|
+
return textOutput('Standard.site search failed: ' + error.message);
|
|
136
137
|
const total = Number(data.totalResults) || data.documents.length;
|
|
137
138
|
const formatted = formatResults({
|
|
138
139
|
label: 'Standard.site results',
|
|
@@ -143,7 +144,7 @@ export const createStandardSearchTool = (context) => ({
|
|
|
143
144
|
renderItem: renderStandardDoc,
|
|
144
145
|
});
|
|
145
146
|
await postResult(context, ctx, formatted);
|
|
146
|
-
return textOutput(
|
|
147
|
+
return textOutput(formatted);
|
|
147
148
|
},
|
|
148
149
|
});
|
|
149
150
|
export const createWikiSearchTool = (context) => ({
|
|
@@ -163,7 +164,7 @@ export const createWikiSearchTool = (context) => ({
|
|
|
163
164
|
const limit = numberField(input, 'limit');
|
|
164
165
|
const { data, error } = await safeAsync(() => (wikiSearch({ query, limit })));
|
|
165
166
|
if (error)
|
|
166
|
-
return textOutput(
|
|
167
|
+
return textOutput('Wikipedia search failed: ' + error.message);
|
|
167
168
|
const formatted = formatResults({
|
|
168
169
|
label: 'Wikipedia results',
|
|
169
170
|
items: data.pages,
|
|
@@ -173,7 +174,7 @@ export const createWikiSearchTool = (context) => ({
|
|
|
173
174
|
renderItem: renderWikiPage,
|
|
174
175
|
});
|
|
175
176
|
await postResult(context, ctx, formatted);
|
|
176
|
-
return textOutput(
|
|
177
|
+
return textOutput(formatted);
|
|
177
178
|
},
|
|
178
179
|
});
|
|
179
180
|
export const createGnewsSearchTool = (context) => ({
|
|
@@ -183,12 +184,21 @@ export const createGnewsSearchTool = (context) => ({
|
|
|
183
184
|
'News and tech media only — not general web search, and not documentation.',
|
|
184
185
|
'Links are news.google.com redirect URLs, not publisher URLs.',
|
|
185
186
|
].join(' '),
|
|
186
|
-
input:
|
|
187
|
+
input: {
|
|
188
|
+
type: 'object',
|
|
189
|
+
properties: {
|
|
190
|
+
query: { type: 'string', description: 'The search query' },
|
|
191
|
+
limit: { type: 'number', description: 'Maximum number of results to return (default 20)' },
|
|
192
|
+
},
|
|
193
|
+
required: ['query'],
|
|
194
|
+
additionalProperties: false,
|
|
195
|
+
},
|
|
187
196
|
async execute(input, ctx) {
|
|
188
197
|
const query = stringField(input, 'query');
|
|
189
|
-
const
|
|
198
|
+
const limit = numberField(input, 'limit');
|
|
199
|
+
const { data, error } = await safeAsync(() => gnewsSearch(query, limit));
|
|
190
200
|
if (error)
|
|
191
|
-
return textOutput(
|
|
201
|
+
return textOutput('Google News search failed: ' + error.message);
|
|
192
202
|
const formatted = formatResults({
|
|
193
203
|
label: 'Google News results',
|
|
194
204
|
items: data,
|
|
@@ -196,7 +206,7 @@ export const createGnewsSearchTool = (context) => ({
|
|
|
196
206
|
renderItem: renderGnewsItem,
|
|
197
207
|
});
|
|
198
208
|
await postResult(context, ctx, formatted);
|
|
199
|
-
return textOutput(
|
|
209
|
+
return textOutput(formatted);
|
|
200
210
|
},
|
|
201
211
|
});
|
|
202
212
|
export const createMdnSearchTool = (context) => ({
|
|
@@ -218,7 +228,7 @@ export const createMdnSearchTool = (context) => ({
|
|
|
218
228
|
const page = numberField(input, 'page');
|
|
219
229
|
const { data, error } = await safeAsync(() => (mdnSearch({ query, limit, page })));
|
|
220
230
|
if (error)
|
|
221
|
-
return textOutput(
|
|
231
|
+
return textOutput('MDN search failed: ' + error.message);
|
|
222
232
|
const formatted = formatResults({
|
|
223
233
|
label: 'MDN Web Docs results',
|
|
224
234
|
items: data.documents,
|
|
@@ -227,7 +237,7 @@ export const createMdnSearchTool = (context) => ({
|
|
|
227
237
|
renderItem: renderMdnDoc,
|
|
228
238
|
});
|
|
229
239
|
await postResult(context, ctx, formatted);
|
|
230
|
-
return textOutput(
|
|
240
|
+
return textOutput(formatted);
|
|
231
241
|
},
|
|
232
242
|
});
|
|
233
243
|
export const createSearchTools = (context) => [
|
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,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,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
|
3
|
+
"version": "1.0.0-next.7",
|
|
4
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",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"types": "./dist/search.d.ts",
|
|
39
39
|
"files": [
|
|
40
40
|
"dist/",
|
|
41
|
+
"src/",
|
|
42
|
+
"search.ts",
|
|
41
43
|
"README.md",
|
|
42
44
|
"REMOVED.md",
|
|
43
45
|
"LICENSE"
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
"scripts": {
|
|
46
48
|
"build": "npm run clean && tsc",
|
|
47
49
|
"clean": "rm -rf dist",
|
|
48
|
-
"
|
|
50
|
+
"prepare": "npm run build",
|
|
49
51
|
"test": "bun test",
|
|
50
52
|
"typecheck": "tsc --noEmit"
|
|
51
53
|
},
|
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
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { formatDate, formatDateTime, formatHeader, formatResults } from './format.ts'
|
|
3
|
+
|
|
4
|
+
describe('formatHeader', () => {
|
|
5
|
+
it('formats basic header with defaults', () => {
|
|
6
|
+
const result = formatHeader('Test results', {
|
|
7
|
+
total: 10,
|
|
8
|
+
count: 5,
|
|
9
|
+
})
|
|
10
|
+
expect(result).toBe('Test results (showing 1-5 of 10, page 1)')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('includes offset in range', () => {
|
|
14
|
+
const result = formatHeader('Test results', {
|
|
15
|
+
total: 50,
|
|
16
|
+
count: 10,
|
|
17
|
+
limit: 10,
|
|
18
|
+
offset: 20,
|
|
19
|
+
})
|
|
20
|
+
expect(result).toBe('Test results (showing 21-30 of 50, page 3)')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('calculates page 1 when limit matches count', () => {
|
|
24
|
+
const result = formatHeader('Test results', {
|
|
25
|
+
total: 25,
|
|
26
|
+
count: 25,
|
|
27
|
+
limit: 25,
|
|
28
|
+
offset: 0,
|
|
29
|
+
})
|
|
30
|
+
expect(result).toBe('Test results (showing 1-25 of 25, page 1)')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('handles zero count', () => {
|
|
34
|
+
const result = formatHeader('Empty', {
|
|
35
|
+
total: 0,
|
|
36
|
+
count: 0,
|
|
37
|
+
})
|
|
38
|
+
expect(result).toBe('Empty (0 results)')
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('formatDate', () => {
|
|
43
|
+
it('formats a valid ISO date string without time', () => {
|
|
44
|
+
const result = formatDate('2025-06-15T14:30:00.000Z')
|
|
45
|
+
expect(result).toContain('Jun')
|
|
46
|
+
expect(result).toContain('2025')
|
|
47
|
+
expect(result).not.toContain(':')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('returns raw string for invalid date', () => {
|
|
51
|
+
expect(formatDate('not-a-date')).toBe('not-a-date')
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('formatDateTime', () => {
|
|
56
|
+
it('includes time', () => {
|
|
57
|
+
const result = formatDateTime('2025-01-01T03:05:00.000Z')
|
|
58
|
+
expect(result).toMatch(/AM|PM/)
|
|
59
|
+
expect(result).toMatch(/:05/)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('returns raw string for invalid date', () => {
|
|
63
|
+
expect(formatDateTime('not-a-date')).toBe('not-a-date')
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('formatResults', () => {
|
|
68
|
+
it('renders header and items using renderItem callback', () => {
|
|
69
|
+
const result = formatResults({
|
|
70
|
+
label: 'Test',
|
|
71
|
+
items: ['a', 'b'],
|
|
72
|
+
total: 2,
|
|
73
|
+
renderItem: (item, i) => `${i + 1}. ${item}`,
|
|
74
|
+
})
|
|
75
|
+
expect(result).toBe([
|
|
76
|
+
'Test (showing 1-2 of 2, page 1)',
|
|
77
|
+
'',
|
|
78
|
+
'1. a',
|
|
79
|
+
'',
|
|
80
|
+
'2. b',
|
|
81
|
+
].join('\n'))
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('supports multi-line renderItem output', () => {
|
|
85
|
+
const result = formatResults({
|
|
86
|
+
label: 'Multi',
|
|
87
|
+
items: [{ title: 'Foo', url: 'https://foo.com' }],
|
|
88
|
+
total: 1,
|
|
89
|
+
renderItem: (item) => `${item.title}\n ${item.url}`,
|
|
90
|
+
})
|
|
91
|
+
expect(result).toBe([
|
|
92
|
+
'Multi (showing 1-1 of 1, page 1)',
|
|
93
|
+
'',
|
|
94
|
+
'Foo',
|
|
95
|
+
' https://foo.com',
|
|
96
|
+
].join('\n'))
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('passes limit and offset to header', () => {
|
|
100
|
+
const result = formatResults({
|
|
101
|
+
label: 'Paged',
|
|
102
|
+
items: ['x'],
|
|
103
|
+
total: 30,
|
|
104
|
+
limit: 10,
|
|
105
|
+
offset: 10,
|
|
106
|
+
renderItem: (item) => item,
|
|
107
|
+
})
|
|
108
|
+
expect(result).toContain('showing 11-11 of 30, page 2')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('handles empty items array', () => {
|
|
112
|
+
const result = formatResults({
|
|
113
|
+
label: 'Empty',
|
|
114
|
+
items: [],
|
|
115
|
+
total: 0,
|
|
116
|
+
renderItem: () => 'should not appear',
|
|
117
|
+
})
|
|
118
|
+
expect(result).toBe('Empty (0 results)')
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('formatResults', () => {
|
|
123
|
+
it('renders header and items using renderItem callback', () => {
|
|
124
|
+
const result = formatResults({
|
|
125
|
+
label: 'Test',
|
|
126
|
+
items: ['a', 'b'],
|
|
127
|
+
total: 2,
|
|
128
|
+
renderItem: (item, i) => `${i + 1}. ${item}`,
|
|
129
|
+
})
|
|
130
|
+
expect(result).toBe([
|
|
131
|
+
'Test (showing 1-2 of 2, page 1)',
|
|
132
|
+
'',
|
|
133
|
+
'1. a',
|
|
134
|
+
'',
|
|
135
|
+
'2. b',
|
|
136
|
+
].join('\n'))
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('supports multi-line renderItem output', () => {
|
|
140
|
+
const result = formatResults({
|
|
141
|
+
label: 'Multi',
|
|
142
|
+
items: [{ title: 'Foo', url: 'https://foo.com' }],
|
|
143
|
+
total: 1,
|
|
144
|
+
renderItem: (item) => `${item.title}\n ${item.url}`,
|
|
145
|
+
})
|
|
146
|
+
expect(result).toBe([
|
|
147
|
+
'Multi (showing 1-1 of 1, page 1)',
|
|
148
|
+
'',
|
|
149
|
+
'Foo',
|
|
150
|
+
' https://foo.com',
|
|
151
|
+
].join('\n'))
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('passes limit and offset to header', () => {
|
|
155
|
+
const result = formatResults({
|
|
156
|
+
label: 'Paged',
|
|
157
|
+
items: ['x'],
|
|
158
|
+
total: 30,
|
|
159
|
+
limit: 10,
|
|
160
|
+
offset: 10,
|
|
161
|
+
renderItem: (item) => item,
|
|
162
|
+
})
|
|
163
|
+
expect(result).toContain('showing 11-11 of 30, page 2')
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('handles empty items array', () => {
|
|
167
|
+
const result = formatResults({
|
|
168
|
+
label: 'Empty',
|
|
169
|
+
items: [],
|
|
170
|
+
total: 0,
|
|
171
|
+
renderItem: () => 'should not appear',
|
|
172
|
+
})
|
|
173
|
+
expect(result).toBe('Empty (0 results)')
|
|
174
|
+
})
|
|
175
|
+
})
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
type PaginationOptions = {
|
|
2
|
+
total: number
|
|
3
|
+
count: number
|
|
4
|
+
limit?: number
|
|
5
|
+
offset?: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const formatHeader = (label: string, options: PaginationOptions): string => {
|
|
9
|
+
const { total, count, limit } = options
|
|
10
|
+
const offset = options.offset ?? 0
|
|
11
|
+
|
|
12
|
+
if (count === 0) return label + ' (0 results)'
|
|
13
|
+
|
|
14
|
+
const start = offset + 1
|
|
15
|
+
const end = offset + count
|
|
16
|
+
const pageSize = limit ?? count
|
|
17
|
+
const page = pageSize > 0 ? Math.floor(offset / pageSize) + 1 : 1
|
|
18
|
+
|
|
19
|
+
return label + ' (showing ' + start + '-' + end + ' of ' + total + ', page ' + page + ')'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DATE_FMT: Intl.DateTimeFormatOptions = {
|
|
23
|
+
month: 'short',
|
|
24
|
+
day: 'numeric',
|
|
25
|
+
year: 'numeric',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const DATETIME_FMT: Intl.DateTimeFormatOptions = {
|
|
29
|
+
month: 'short',
|
|
30
|
+
day: 'numeric',
|
|
31
|
+
year: 'numeric',
|
|
32
|
+
hour: 'numeric',
|
|
33
|
+
minute: '2-digit',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const parseDate = (raw: string): Date | null => {
|
|
37
|
+
const d = new Date(raw)
|
|
38
|
+
return isNaN(d.getTime()) ? null : d
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const formatDate = (raw: string): string => {
|
|
42
|
+
const d = parseDate(raw)
|
|
43
|
+
return d ? d.toLocaleString('en-US', DATE_FMT) : raw
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const formatDateTime = (raw: string): string => {
|
|
47
|
+
const d = parseDate(raw)
|
|
48
|
+
return d ? d.toLocaleString('en-US', DATETIME_FMT) : raw
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type FormatResultsOptions<T> = {
|
|
52
|
+
label: string
|
|
53
|
+
items: Array<T>
|
|
54
|
+
total: number
|
|
55
|
+
limit?: number
|
|
56
|
+
offset?: number
|
|
57
|
+
renderItem: (item: T, index: number) => string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const formatResults = <T>(options: FormatResultsOptions<T>): string => {
|
|
61
|
+
const { label, items, total, limit, offset, renderItem } = options
|
|
62
|
+
|
|
63
|
+
const header = formatHeader(label, { total, count: items.length, limit, offset })
|
|
64
|
+
|
|
65
|
+
if (items.length === 0) return header
|
|
66
|
+
|
|
67
|
+
const body = items
|
|
68
|
+
.map((item, i) => renderItem(item, i))
|
|
69
|
+
.join('\n\n')
|
|
70
|
+
|
|
71
|
+
return header + '\n\n' + body
|
|
72
|
+
}
|