@fffangchenghao/dsh-web-search 0.11.0 → 0.12.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/CHANGELOG.md +28 -0
- package/README.md +132 -34
- package/README.zh-CN.md +132 -34
- package/client.js +28 -3
- package/lib/cache-persist.d.ts +96 -0
- package/lib/cache-persist.js +249 -0
- package/lib/cache.d.ts +48 -4
- package/lib/cache.js +134 -9
- package/lib/config.d.ts +16 -0
- package/lib/config.js +28 -0
- package/lib/fetch.d.ts +7 -0
- package/lib/fetch.js +36 -3
- package/lib/index.d.ts +20 -0
- package/lib/index.js +91 -27
- package/lib/markdown.d.ts +84 -0
- package/lib/markdown.js +847 -0
- package/lib/search-many.d.ts +117 -0
- package/lib/search-many.js +286 -0
- package/lib/types.d.ts +7 -4
- package/package.json +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing `search_many` tool: several independent searches in one
|
|
3
|
+
* call, each reusing the same engine layer, cache and cooldown tracker as
|
|
4
|
+
* `web_search`.
|
|
5
|
+
*
|
|
6
|
+
* The batch is deliberately boring: every query is a normal search, failures
|
|
7
|
+
* are recorded per query instead of aborting the batch, and at most three
|
|
8
|
+
* searches run at once so one call cannot spend the whole engine budget. The
|
|
9
|
+
* registration path mirrors `domain-tool.ts` — raw JSON Schema, `output`
|
|
10
|
+
* carrying `{ schema, render }`, the optional `ctx.get('tools')` lookup, a
|
|
11
|
+
* fallback name on collision, and a contained failure path.
|
|
12
|
+
*
|
|
13
|
+
* @module @fangchenghao/dsh-web-search/search-many
|
|
14
|
+
*/
|
|
15
|
+
import type { Source } from './types.ts';
|
|
16
|
+
import type { ToolContent, ToolJsonSchema } from './domain-tool.ts';
|
|
17
|
+
/** The name this tool prefers. */
|
|
18
|
+
export declare const SEARCH_MANY_TOOL_NAME = "search_many";
|
|
19
|
+
/** The name used when another plugin already registered `search_many`. */
|
|
20
|
+
export declare const SEARCH_MANY_FALLBACK_NAME = "web_search_many";
|
|
21
|
+
/** How many queries run at the same time; deliberately below the engine count. */
|
|
22
|
+
export declare const SEARCH_MANY_CONCURRENCY = 3;
|
|
23
|
+
/** Queries accepted in one call. */
|
|
24
|
+
export declare const SEARCH_MANY_MIN_QUERIES = 1;
|
|
25
|
+
/** Queries accepted in one call. */
|
|
26
|
+
export declare const SEARCH_MANY_MAX_QUERIES = 5;
|
|
27
|
+
/** Default result budget for a query that names none. */
|
|
28
|
+
export declare const SEARCH_MANY_DEFAULT_LIMIT = 5;
|
|
29
|
+
/** Largest per-query budget the tool accepts. */
|
|
30
|
+
export declare const SEARCH_MANY_MAX_LIMIT = 20;
|
|
31
|
+
/** One source as `search_many` reports it; `site` appears only when asked. */
|
|
32
|
+
export interface SearchManySource extends Source {
|
|
33
|
+
/** Lower-cased hostname of {@link Source.url}, when `withSites` is true. */
|
|
34
|
+
site?: string;
|
|
35
|
+
}
|
|
36
|
+
/** What one query in the batch produced. */
|
|
37
|
+
export interface SearchManyResult {
|
|
38
|
+
/** The query exactly as it was accepted (trimmed). */
|
|
39
|
+
query: string;
|
|
40
|
+
sources: SearchManySource[];
|
|
41
|
+
/** Failures for this query alone; a thrown search becomes one entry here. */
|
|
42
|
+
failures: string[];
|
|
43
|
+
}
|
|
44
|
+
/** What the tool returns to the model. */
|
|
45
|
+
export interface SearchManyValue {
|
|
46
|
+
results: SearchManyResult[];
|
|
47
|
+
/** True when any per-query budget was cut by the deployment's limit. */
|
|
48
|
+
truncated: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** What a single query's runner reports back. */
|
|
51
|
+
export interface SearchManyOutcome {
|
|
52
|
+
sources: Source[];
|
|
53
|
+
failures: string[];
|
|
54
|
+
/** True when the deployment's configured limit cut the requested budget. */
|
|
55
|
+
truncated: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Run one search; the plugin binds this to the same path as `web_search`. */
|
|
58
|
+
export type SearchManyRunner = (query: string, limit: number, signal?: AbortSignal) => Promise<SearchManyOutcome>;
|
|
59
|
+
/** A tool definition in the host registry's native shape. */
|
|
60
|
+
export interface SearchManyDefinition {
|
|
61
|
+
name: string;
|
|
62
|
+
description: string;
|
|
63
|
+
parameters: ToolJsonSchema;
|
|
64
|
+
output: {
|
|
65
|
+
schema: ToolJsonSchema;
|
|
66
|
+
render: (args: unknown, value: SearchManyValue) => ToolContent[];
|
|
67
|
+
};
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
isConcurrencySafe?: (args: unknown) => boolean;
|
|
70
|
+
execute: (args: unknown, exec: {
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
}) => Promise<SearchManyValue>;
|
|
73
|
+
}
|
|
74
|
+
/** The slice of the tool registry this module needs. */
|
|
75
|
+
export interface SearchManyRegistryLike {
|
|
76
|
+
register(definition: SearchManyDefinition): unknown;
|
|
77
|
+
get?(name: string, scope?: unknown): unknown;
|
|
78
|
+
}
|
|
79
|
+
/** Construction seams. */
|
|
80
|
+
export interface SearchManyOptions {
|
|
81
|
+
/** Registration diagnostics. */
|
|
82
|
+
warn?: (message: string) => void;
|
|
83
|
+
}
|
|
84
|
+
/** A successful registration plus the exact way to undo it. */
|
|
85
|
+
export interface SearchManyRegistration {
|
|
86
|
+
name: string;
|
|
87
|
+
dispose: () => void;
|
|
88
|
+
}
|
|
89
|
+
/** Format the model-facing result text. */
|
|
90
|
+
export declare function formatSearchManyValue(value: SearchManyValue): string;
|
|
91
|
+
/**
|
|
92
|
+
* Build the tool definition the host registry accepts.
|
|
93
|
+
* @param name - `search_many`, or the fallback when that name is taken.
|
|
94
|
+
* @param runQuery - executes one search through the plugin's normal path.
|
|
95
|
+
* @returns a registry-ready definition.
|
|
96
|
+
*/
|
|
97
|
+
export declare function createSearchManyDefinition(name: string, runQuery: SearchManyRunner): SearchManyDefinition;
|
|
98
|
+
/**
|
|
99
|
+
* Pick the tool name this deployment can accept.
|
|
100
|
+
* @param tools - the live registry.
|
|
101
|
+
* @returns the preferred or fallback name.
|
|
102
|
+
*/
|
|
103
|
+
export declare function pickSearchManyToolName(tools: SearchManyRegistryLike): string;
|
|
104
|
+
/**
|
|
105
|
+
* Register the tool when a registry is available.
|
|
106
|
+
*
|
|
107
|
+
* Every failure path is contained: a duplicate name falls back, and any
|
|
108
|
+
* registry rejection is reported and swallowed so `web_search` keeps working.
|
|
109
|
+
* The returned registration owns the host disposer, so plugin disposal removes
|
|
110
|
+
* exactly the definition this call added.
|
|
111
|
+
*
|
|
112
|
+
* @param tools - the live registry.
|
|
113
|
+
* @param runQuery - executes one search through the plugin's normal path.
|
|
114
|
+
* @param options - diagnostics.
|
|
115
|
+
* @returns the registered name and its disposer, or `undefined` when skipped.
|
|
116
|
+
*/
|
|
117
|
+
export declare function registerSearchManyTool(tools: SearchManyRegistryLike, runQuery: SearchManyRunner, options?: SearchManyOptions): SearchManyRegistration | undefined;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/** The name this tool prefers. */
|
|
2
|
+
export const SEARCH_MANY_TOOL_NAME = 'search_many';
|
|
3
|
+
/** The name used when another plugin already registered `search_many`. */
|
|
4
|
+
export const SEARCH_MANY_FALLBACK_NAME = 'web_search_many';
|
|
5
|
+
/** How many queries run at the same time; deliberately below the engine count. */
|
|
6
|
+
export const SEARCH_MANY_CONCURRENCY = 3;
|
|
7
|
+
/** Queries accepted in one call. */
|
|
8
|
+
export const SEARCH_MANY_MIN_QUERIES = 1;
|
|
9
|
+
/** Queries accepted in one call. */
|
|
10
|
+
export const SEARCH_MANY_MAX_QUERIES = 5;
|
|
11
|
+
/** Default result budget for a query that names none. */
|
|
12
|
+
export const SEARCH_MANY_DEFAULT_LIMIT = 5;
|
|
13
|
+
/** Largest per-query budget the tool accepts. */
|
|
14
|
+
export const SEARCH_MANY_MAX_LIMIT = 20;
|
|
15
|
+
/** True for a value usable as a record. */
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
/** The parameter schema, in the registry's raw JSON-Schema dialect. */
|
|
20
|
+
function parameterSchema() {
|
|
21
|
+
return {
|
|
22
|
+
type: 'object',
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
properties: {
|
|
25
|
+
queries: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
items: { type: 'string' },
|
|
28
|
+
description: `The searches to run, ${SEARCH_MANY_MIN_QUERIES}–${SEARCH_MANY_MAX_QUERIES} independent queries. Each runs as its own \`web_search\`.`,
|
|
29
|
+
},
|
|
30
|
+
limit: {
|
|
31
|
+
type: 'integer',
|
|
32
|
+
description: `Results wanted per query, 1–${SEARCH_MANY_MAX_LIMIT}; defaults to ${SEARCH_MANY_DEFAULT_LIMIT}.`,
|
|
33
|
+
},
|
|
34
|
+
withSites: {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
description: 'Attach the result hostname to every source. Defaults to false.',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ['queries'],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** The output schema, in the same dialect. */
|
|
43
|
+
function outputSchema() {
|
|
44
|
+
const sourceSchema = {
|
|
45
|
+
type: 'object',
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
properties: {
|
|
48
|
+
url: { type: 'string' },
|
|
49
|
+
title: { type: 'string' },
|
|
50
|
+
snippet: { type: 'string' },
|
|
51
|
+
publishedAt: { type: 'string' },
|
|
52
|
+
site: { type: 'string' },
|
|
53
|
+
},
|
|
54
|
+
required: ['url'],
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
type: 'object',
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
properties: {
|
|
60
|
+
results: {
|
|
61
|
+
type: 'array',
|
|
62
|
+
items: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
properties: {
|
|
66
|
+
query: { type: 'string' },
|
|
67
|
+
sources: { type: 'array', items: sourceSchema },
|
|
68
|
+
failures: { type: 'array', items: { type: 'string' } },
|
|
69
|
+
},
|
|
70
|
+
required: ['query', 'sources', 'failures'],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
truncated: { type: 'boolean' },
|
|
74
|
+
},
|
|
75
|
+
required: ['results', 'truncated'],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Parse model arguments into a validated shape, throwing on nonsense. */
|
|
79
|
+
function parseArgs(args) {
|
|
80
|
+
if (!isRecord(args))
|
|
81
|
+
throw new Error('search_many requires arguments');
|
|
82
|
+
const rawQueries = args['queries'];
|
|
83
|
+
if (!Array.isArray(rawQueries)) {
|
|
84
|
+
throw new Error(`search_many requires a queries array with ${SEARCH_MANY_MIN_QUERIES}–${SEARCH_MANY_MAX_QUERIES} entries`);
|
|
85
|
+
}
|
|
86
|
+
if (rawQueries.length < SEARCH_MANY_MIN_QUERIES || rawQueries.length > SEARCH_MANY_MAX_QUERIES) {
|
|
87
|
+
throw new Error(`search_many accepts ${SEARCH_MANY_MIN_QUERIES}–${SEARCH_MANY_MAX_QUERIES} queries, got ${rawQueries.length}`);
|
|
88
|
+
}
|
|
89
|
+
const queries = [];
|
|
90
|
+
for (const raw of rawQueries) {
|
|
91
|
+
if (typeof raw !== 'string' || raw.trim().length === 0) {
|
|
92
|
+
throw new Error('search_many requires every query to be a non-empty string');
|
|
93
|
+
}
|
|
94
|
+
queries.push(raw.trim());
|
|
95
|
+
}
|
|
96
|
+
const rawLimit = args['limit'];
|
|
97
|
+
let limit = SEARCH_MANY_DEFAULT_LIMIT;
|
|
98
|
+
if (rawLimit !== undefined) {
|
|
99
|
+
if (typeof rawLimit !== 'number' || !Number.isInteger(rawLimit)
|
|
100
|
+
|| rawLimit < 1 || rawLimit > SEARCH_MANY_MAX_LIMIT) {
|
|
101
|
+
throw new Error(`search_many limit must be an integer between 1 and ${SEARCH_MANY_MAX_LIMIT}`);
|
|
102
|
+
}
|
|
103
|
+
limit = rawLimit;
|
|
104
|
+
}
|
|
105
|
+
const rawSites = args['withSites'];
|
|
106
|
+
if (rawSites !== undefined && typeof rawSites !== 'boolean') {
|
|
107
|
+
throw new Error('search_many withSites must be a boolean');
|
|
108
|
+
}
|
|
109
|
+
return { queries, limit, withSites: rawSites === true };
|
|
110
|
+
}
|
|
111
|
+
/** Return the hostname a source is served from, or `undefined` for a bad URL. */
|
|
112
|
+
function siteOf(url) {
|
|
113
|
+
try {
|
|
114
|
+
const host = new URL(url).hostname.trim().toLowerCase();
|
|
115
|
+
return host.length === 0 ? undefined : host;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Attach the hostname without mutating the cached source object. */
|
|
122
|
+
function withSite(source) {
|
|
123
|
+
const site = siteOf(source.url);
|
|
124
|
+
return site === undefined ? { ...source } : { ...source, site };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Run `worker` over items with at most `limit` in flight, preserving order.
|
|
128
|
+
* A dedicated helper keeps the concurrency contract visible instead of relying
|
|
129
|
+
* on an unstated promise-pool behaviour.
|
|
130
|
+
*/
|
|
131
|
+
async function mapLimit(items, limit, worker) {
|
|
132
|
+
const results = new Array(items.length);
|
|
133
|
+
let next = 0;
|
|
134
|
+
const runners = Array.from({ length: Math.min(Math.max(1, limit), items.length) }, async () => {
|
|
135
|
+
for (;;) {
|
|
136
|
+
const index = next;
|
|
137
|
+
next += 1;
|
|
138
|
+
if (index >= items.length)
|
|
139
|
+
return;
|
|
140
|
+
results[index] = await worker(items[index], index);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
await Promise.all(runners);
|
|
144
|
+
return results;
|
|
145
|
+
}
|
|
146
|
+
/** Format the model-facing result text. */
|
|
147
|
+
export function formatSearchManyValue(value) {
|
|
148
|
+
const total = value.results.reduce((sum, result) => sum + result.sources.length, 0);
|
|
149
|
+
const failed = value.results.reduce((sum, result) => sum + result.failures.length, 0);
|
|
150
|
+
const head = `Batch search: ${value.results.length} quer${value.results.length === 1 ? 'y' : 'ies'}, `
|
|
151
|
+
+ `${total} result(s)${failed === 0 ? '' : `, ${failed} failure(s)`}${value.truncated ? ' (truncated)' : ''}.`;
|
|
152
|
+
const sections = value.results.map((result, index) => {
|
|
153
|
+
const lines = [`${index + 1}. ${JSON.stringify(result.query)} — ${result.sources.length} result(s)`];
|
|
154
|
+
for (const [position, source] of result.sources.entries()) {
|
|
155
|
+
const title = source.title !== undefined && source.title.length > 0 ? source.title : source.url;
|
|
156
|
+
lines.push(` ${position + 1}. ${title}`);
|
|
157
|
+
lines.push(` ${source.url}${source.site === undefined ? '' : ` [${source.site}]`}`);
|
|
158
|
+
if (source.snippet !== undefined && source.snippet.length > 0)
|
|
159
|
+
lines.push(` ${source.snippet}`);
|
|
160
|
+
if (source.publishedAt !== undefined && source.publishedAt.length > 0) {
|
|
161
|
+
lines.push(` ${source.publishedAt}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (result.failures.length > 0)
|
|
165
|
+
lines.push(` failures: ${result.failures.join('; ')}`);
|
|
166
|
+
return lines.join('\n');
|
|
167
|
+
});
|
|
168
|
+
return [head, '', ...sections].join('\n').trimEnd();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Build the tool definition the host registry accepts.
|
|
172
|
+
* @param name - `search_many`, or the fallback when that name is taken.
|
|
173
|
+
* @param runQuery - executes one search through the plugin's normal path.
|
|
174
|
+
* @returns a registry-ready definition.
|
|
175
|
+
*/
|
|
176
|
+
export function createSearchManyDefinition(name, runQuery) {
|
|
177
|
+
return {
|
|
178
|
+
name,
|
|
179
|
+
description: 'Run 1–5 independent web searches in one call and return each query\'s results separately. Use it when one question needs several distinct queries; a failed query does not stop the others. For a single query use web_search.',
|
|
180
|
+
parameters: parameterSchema(),
|
|
181
|
+
output: {
|
|
182
|
+
schema: outputSchema(),
|
|
183
|
+
render: (_args, value) => [{ type: 'text', text: formatSearchManyValue(value) }],
|
|
184
|
+
},
|
|
185
|
+
timeoutMs: 30_000,
|
|
186
|
+
isConcurrencySafe: () => true,
|
|
187
|
+
async execute(args, exec) {
|
|
188
|
+
const parsed = parseArgs(args);
|
|
189
|
+
const outcomes = await mapLimit(parsed.queries, SEARCH_MANY_CONCURRENCY, async (query) => {
|
|
190
|
+
try {
|
|
191
|
+
const outcome = await runQuery(query, parsed.limit, exec.signal);
|
|
192
|
+
const mapped = parsed.withSites
|
|
193
|
+
? outcome.sources.map(withSite)
|
|
194
|
+
: outcome.sources.map((source) => ({ ...source }));
|
|
195
|
+
const truncated = outcome.truncated || mapped.length > parsed.limit;
|
|
196
|
+
return {
|
|
197
|
+
result: {
|
|
198
|
+
query,
|
|
199
|
+
sources: mapped.slice(0, parsed.limit),
|
|
200
|
+
failures: [...outcome.failures],
|
|
201
|
+
},
|
|
202
|
+
truncated,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
return {
|
|
207
|
+
result: {
|
|
208
|
+
query,
|
|
209
|
+
sources: [],
|
|
210
|
+
failures: [error instanceof Error ? error.message : String(error)],
|
|
211
|
+
},
|
|
212
|
+
truncated: false,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return {
|
|
217
|
+
results: outcomes.map((entry) => entry.result),
|
|
218
|
+
truncated: outcomes.some((entry) => entry.truncated),
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Pick the tool name this deployment can accept.
|
|
225
|
+
* @param tools - the live registry.
|
|
226
|
+
* @returns the preferred or fallback name.
|
|
227
|
+
*/
|
|
228
|
+
export function pickSearchManyToolName(tools) {
|
|
229
|
+
if (typeof tools.get !== 'function')
|
|
230
|
+
return SEARCH_MANY_TOOL_NAME;
|
|
231
|
+
try {
|
|
232
|
+
return tools.get(SEARCH_MANY_TOOL_NAME) === undefined ? SEARCH_MANY_TOOL_NAME : SEARCH_MANY_FALLBACK_NAME;
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return SEARCH_MANY_TOOL_NAME;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** Report a registration failure without throwing out of the plugin. */
|
|
239
|
+
function report(options, error) {
|
|
240
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
241
|
+
try {
|
|
242
|
+
options.warn?.(`search_many registration skipped: ${message}`);
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// A diagnostic callback must never break plugin loading.
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Register the tool when a registry is available.
|
|
250
|
+
*
|
|
251
|
+
* Every failure path is contained: a duplicate name falls back, and any
|
|
252
|
+
* registry rejection is reported and swallowed so `web_search` keeps working.
|
|
253
|
+
* The returned registration owns the host disposer, so plugin disposal removes
|
|
254
|
+
* exactly the definition this call added.
|
|
255
|
+
*
|
|
256
|
+
* @param tools - the live registry.
|
|
257
|
+
* @param runQuery - executes one search through the plugin's normal path.
|
|
258
|
+
* @param options - diagnostics.
|
|
259
|
+
* @returns the registered name and its disposer, or `undefined` when skipped.
|
|
260
|
+
*/
|
|
261
|
+
export function registerSearchManyTool(tools, runQuery, options = {}) {
|
|
262
|
+
const name = pickSearchManyToolName(tools);
|
|
263
|
+
try {
|
|
264
|
+
const registered = tools.register(createSearchManyDefinition(name, runQuery));
|
|
265
|
+
const disposeHost = typeof registered === 'function' ? registered : undefined;
|
|
266
|
+
let disposed = false;
|
|
267
|
+
return {
|
|
268
|
+
name,
|
|
269
|
+
dispose: () => {
|
|
270
|
+
if (disposed)
|
|
271
|
+
return;
|
|
272
|
+
disposed = true;
|
|
273
|
+
try {
|
|
274
|
+
disposeHost?.();
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
// Disposal must stay contained; the plugin is already going away.
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
report(options, error);
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -120,10 +120,13 @@ export interface RankOptions {
|
|
|
120
120
|
}
|
|
121
121
|
/** Cache knobs. */
|
|
122
122
|
export interface CacheOptions {
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Entry lifetime in milliseconds. `0` disables the cache. A reader keeps
|
|
125
|
+
* Settings edits live without a remount.
|
|
126
|
+
*/
|
|
127
|
+
ttlMs?: number | (() => number);
|
|
128
|
+
/** Maximum retained entries, or a reader for it; the least recently used goes. */
|
|
129
|
+
maxEntries?: number | (() => number);
|
|
127
130
|
}
|
|
128
131
|
/** Health knobs for the per-engine cooldown. */
|
|
129
132
|
export interface HealthOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fffangchenghao/dsh-web-search",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "DSH bundle: a key-free web search provider. Leads with the anonymous AnySearch API and falls back to public result pages (DuckDuckGo, Bing, 360), merged by reciprocal-rank fusion with a bilingual region policy, an engine cooldown and a TTL cache.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|