dsh-web-search-pro 0.1.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/LICENSE +21 -0
- package/LOGIN.md +67 -0
- package/README.md +123 -0
- package/cordis.patch.yml +21 -0
- package/lib/browser-service.d.ts +68 -0
- package/lib/browser-service.js +8 -0
- package/lib/browser-service.js.map +1 -0
- package/lib/config.d.ts +91 -0
- package/lib/config.js +72 -0
- package/lib/config.js.map +1 -0
- package/lib/deps.d.ts +34 -0
- package/lib/deps.js +90 -0
- package/lib/deps.js.map +1 -0
- package/lib/engines.d.ts +71 -0
- package/lib/engines.js +562 -0
- package/lib/engines.js.map +1 -0
- package/lib/extract.d.ts +40 -0
- package/lib/extract.js +243 -0
- package/lib/extract.js.map +1 -0
- package/lib/fetch.d.ts +42 -0
- package/lib/fetch.js +175 -0
- package/lib/fetch.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +117 -0
- package/lib/index.js.map +1 -0
- package/lib/memory-cache.d.ts +18 -0
- package/lib/memory-cache.js +42 -0
- package/lib/memory-cache.js.map +1 -0
- package/lib/platform-search.d.ts +34 -0
- package/lib/platform-search.js +61 -0
- package/lib/platform-search.js.map +1 -0
- package/lib/playwright.d.ts +71 -0
- package/lib/playwright.js +165 -0
- package/lib/playwright.js.map +1 -0
- package/lib/router.d.ts +66 -0
- package/lib/router.js +332 -0
- package/lib/router.js.map +1 -0
- package/lib/store.d.ts +117 -0
- package/lib/store.js +223 -0
- package/lib/store.js.map +1 -0
- package/lib/tools.d.ts +28 -0
- package/lib/tools.js +542 -0
- package/lib/tools.js.map +1 -0
- package/lib/util.d.ts +73 -0
- package/lib/util.js +220 -0
- package/lib/util.js.map +1 -0
- package/package.json +59 -0
- package/scripts/save-login.mjs +77 -0
package/lib/router.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search orchestration: engine ordering/fallback (agent-reach style routing),
|
|
3
|
+
* optional parallel multi-engine merging, SQLite caching, and persistence.
|
|
4
|
+
* @module web-search-pro/router
|
|
5
|
+
*/
|
|
6
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials';
|
|
7
|
+
import { seamEngine, exaEngine, ddgEngine, bingEngine, jinaSearchEngine, githubEngine, bilibiliEngine, v2exEngine, youtubeEngine, arxivEngine, pubmedEngine, platformEngines, rssEngine, customPlatformEngine, EngineError, } from "./engines.js";
|
|
8
|
+
import { normQuery, capText } from "./util.js";
|
|
9
|
+
import { LruCache } from "./memory-cache.js";
|
|
10
|
+
const ENGINE_FACTORIES = {
|
|
11
|
+
seam: (_deps) => seamEngine(_deps),
|
|
12
|
+
exa: (deps) => exaEngine(deps),
|
|
13
|
+
ddg: () => ddgEngine(),
|
|
14
|
+
bing: () => bingEngine(),
|
|
15
|
+
jina: (deps) => jinaSearchEngine(deps),
|
|
16
|
+
github: (deps) => githubEngine(deps),
|
|
17
|
+
bilibili: (deps) => bilibiliEngine(deps),
|
|
18
|
+
v2ex: () => v2exEngine(),
|
|
19
|
+
youtube: (deps) => youtubeEngine(deps),
|
|
20
|
+
arxiv: () => arxivEngine(),
|
|
21
|
+
pubmed: () => pubmedEngine(),
|
|
22
|
+
};
|
|
23
|
+
export class SearchRouter {
|
|
24
|
+
ctx;
|
|
25
|
+
config;
|
|
26
|
+
store;
|
|
27
|
+
dynamic;
|
|
28
|
+
browser;
|
|
29
|
+
memory;
|
|
30
|
+
constructor(ctx, config, store, dynamic = () => config, browser, memory = new LruCache(config.memoryCacheEntries)) {
|
|
31
|
+
this.ctx = ctx;
|
|
32
|
+
this.config = config;
|
|
33
|
+
this.store = store;
|
|
34
|
+
this.dynamic = dynamic;
|
|
35
|
+
this.browser = browser;
|
|
36
|
+
this.memory = memory;
|
|
37
|
+
}
|
|
38
|
+
/** Resolve a key through credentials first, then process env. */
|
|
39
|
+
async resolveKey(ref, literal) {
|
|
40
|
+
if (literal && literal.length > 0)
|
|
41
|
+
return literal;
|
|
42
|
+
const credentials = this.ctx.get('credentials');
|
|
43
|
+
if (credentials) {
|
|
44
|
+
try {
|
|
45
|
+
const resolved = await credentials.resolve(credentialRef(ref));
|
|
46
|
+
if (resolved?.value)
|
|
47
|
+
return resolved.value;
|
|
48
|
+
}
|
|
49
|
+
catch { /* fall through to env */ }
|
|
50
|
+
}
|
|
51
|
+
return process.env[ref];
|
|
52
|
+
}
|
|
53
|
+
async deps(skipSeam) {
|
|
54
|
+
const cfg = this.dynamic();
|
|
55
|
+
const web = this.ctx.get('web');
|
|
56
|
+
const exaApiKey = await this.resolveKey(cfg.exaApiKeyEnv, cfg.exaApiKey);
|
|
57
|
+
const jinaApiKey = await this.resolveKey(cfg.jinaApiKeyEnv, cfg.jinaApiKey);
|
|
58
|
+
return {
|
|
59
|
+
...web !== undefined ? { web } : {},
|
|
60
|
+
...exaApiKey ? { exaApiKey } : {},
|
|
61
|
+
...jinaApiKey ? { jinaApiKey } : {},
|
|
62
|
+
enableCli: cfg.enableCliBackends,
|
|
63
|
+
opencliEnabled: cfg.opencliEnabled,
|
|
64
|
+
agentReachEnabled: cfg.agentReachEnabled,
|
|
65
|
+
...this.browser !== undefined ? { browser: this.browser } : {},
|
|
66
|
+
...cfg.platformRules !== undefined ? { platformRules: cfg.platformRules } : {},
|
|
67
|
+
...cfg.customPlatforms !== undefined ? { customPlatforms: cfg.customPlatforms } : {},
|
|
68
|
+
skipSeam,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Sync key check for available() (no credential resolution — env/literal only). */
|
|
72
|
+
depsSync(skipSeam) {
|
|
73
|
+
const cfg = this.dynamic();
|
|
74
|
+
const web = this.ctx.get('web');
|
|
75
|
+
const exaApiKey = cfg.exaApiKey || process.env[cfg.exaApiKeyEnv];
|
|
76
|
+
const jinaApiKey = cfg.jinaApiKey || process.env[cfg.jinaApiKeyEnv];
|
|
77
|
+
return {
|
|
78
|
+
...web !== undefined ? { web } : {},
|
|
79
|
+
...exaApiKey ? { exaApiKey } : {},
|
|
80
|
+
...jinaApiKey ? { jinaApiKey } : {},
|
|
81
|
+
enableCli: cfg.enableCliBackends,
|
|
82
|
+
opencliEnabled: cfg.opencliEnabled,
|
|
83
|
+
agentReachEnabled: cfg.agentReachEnabled,
|
|
84
|
+
...this.browser !== undefined ? { browser: this.browser } : {},
|
|
85
|
+
...cfg.platformRules !== undefined ? { platformRules: cfg.platformRules } : {},
|
|
86
|
+
...cfg.customPlatforms !== undefined ? { customPlatforms: cfg.customPlatforms } : {},
|
|
87
|
+
skipSeam,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Whether any configured engine is currently usable. */
|
|
91
|
+
anyEngineAvailable() {
|
|
92
|
+
const ids = this.dynamic().engines;
|
|
93
|
+
return ids.some(id => this.buildSync(id, false).available());
|
|
94
|
+
}
|
|
95
|
+
async build(id, skipSeam) {
|
|
96
|
+
const factory = ENGINE_FACTORIES[id];
|
|
97
|
+
if (!factory)
|
|
98
|
+
throw new EngineError('unknown engine: ' + id, 'ENGINE_UNAVAILABLE', false);
|
|
99
|
+
return factory(await this.deps(skipSeam), this.dynamic());
|
|
100
|
+
}
|
|
101
|
+
buildSync(id, skipSeam) {
|
|
102
|
+
const factory = ENGINE_FACTORIES[id];
|
|
103
|
+
if (!factory)
|
|
104
|
+
throw new EngineError('unknown engine: ' + id, 'ENGINE_UNAVAILABLE', false);
|
|
105
|
+
return factory(this.depsSync(skipSeam), this.dynamic());
|
|
106
|
+
}
|
|
107
|
+
/** Run a full search with caching + persistence. */
|
|
108
|
+
async search(opts) {
|
|
109
|
+
const query = opts.query.trim();
|
|
110
|
+
if (!query)
|
|
111
|
+
throw new Error('query must be a non-empty string');
|
|
112
|
+
const cfg = this.dynamic();
|
|
113
|
+
const ids = (opts.engines && opts.engines.length ? opts.engines : cfg.engines)
|
|
114
|
+
.filter((id, i, arr) => arr.indexOf(id) === i);
|
|
115
|
+
const nq = normQuery(query);
|
|
116
|
+
const count = Math.min(Math.max(opts.count, 1), 20);
|
|
117
|
+
// 1. In-process LRU cache, then SQLite.
|
|
118
|
+
if (!opts.fresh) {
|
|
119
|
+
for (const id of ids) {
|
|
120
|
+
const hot = this.memory.get(id + '|' + nq, cfg.ttlSeconds * 1000);
|
|
121
|
+
if (hot)
|
|
122
|
+
return { ...hot, fromCache: true, enginesTried: [id] };
|
|
123
|
+
}
|
|
124
|
+
for (const id of ids) {
|
|
125
|
+
const cached = this.store.getCachedSearch(id, nq, cfg.ttlSeconds);
|
|
126
|
+
if (cached) {
|
|
127
|
+
const rows = this.store.resultsForQuery(cached.id);
|
|
128
|
+
if (rows.length) {
|
|
129
|
+
let detail;
|
|
130
|
+
if (cached.detail) {
|
|
131
|
+
try {
|
|
132
|
+
detail = JSON.parse(cached.detail);
|
|
133
|
+
}
|
|
134
|
+
catch { /* ignore */ }
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
...detail?.content ? { content: detail.content } : {},
|
|
138
|
+
sources: rows.map(r => ({
|
|
139
|
+
url: r.url,
|
|
140
|
+
...r.title ? { title: r.title } : {},
|
|
141
|
+
...r.snippet ? { snippet: r.snippet } : {},
|
|
142
|
+
...r.published ? { publishedAt: r.published } : {},
|
|
143
|
+
})),
|
|
144
|
+
engine: id,
|
|
145
|
+
enginesTried: [id],
|
|
146
|
+
fromCache: true,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// 2. Run engines.
|
|
153
|
+
const enginesTried = [];
|
|
154
|
+
let outcome;
|
|
155
|
+
let usedId;
|
|
156
|
+
const signal = opts.signal;
|
|
157
|
+
if (opts.multi) {
|
|
158
|
+
const results = await Promise.allSettled(ids.map(async (id) => {
|
|
159
|
+
const engine = await this.build(id, opts.skipSeam ?? false);
|
|
160
|
+
if (!engine.available())
|
|
161
|
+
throw new EngineError(engine.label + ' unavailable', 'ENGINE_UNAVAILABLE', false);
|
|
162
|
+
return { id, outcome: await engine.search(query, count, signal) };
|
|
163
|
+
}));
|
|
164
|
+
enginesTried.push(...ids);
|
|
165
|
+
// Reciprocal Rank Fusion + freshness/authority signals (Argo-style
|
|
166
|
+
// evidence credibility): each engine's rank order contributes 1/(k+rank);
|
|
167
|
+
// recency and authoritative domains add a bounded bonus so a recent,
|
|
168
|
+
// trustworthy source can edge out an older, lower-authority one.
|
|
169
|
+
const k = Math.max(cfg.rrfConstant, 1);
|
|
170
|
+
const scores = new Map();
|
|
171
|
+
const entries = new Map();
|
|
172
|
+
const freshnessBoost = Math.min(Math.max(cfg.freshnessBoost, 0), 1);
|
|
173
|
+
const authorityBoost = Math.min(Math.max(cfg.authorityBoost, 0), 1);
|
|
174
|
+
const freshnessDays = Math.max(cfg.freshnessDays, 1);
|
|
175
|
+
const authorityDomains = [...cfg.authorityDomains, 'github.com', 'wikipedia.org', 'arxiv.org', 'pubmed.ncbi.nlm.nih.gov', 'stackoverflow.com', 'developer.mozilla.org'];
|
|
176
|
+
for (const r of results) {
|
|
177
|
+
if (r.status !== 'fulfilled')
|
|
178
|
+
continue;
|
|
179
|
+
r.value.outcome.sources.forEach((s, rank) => {
|
|
180
|
+
if (!s.url)
|
|
181
|
+
return;
|
|
182
|
+
let score = scores.get(s.url) ?? 0;
|
|
183
|
+
score += 1 / (k + rank + 1);
|
|
184
|
+
if (freshnessBoost > 0 && s.publishedAt) {
|
|
185
|
+
const published = Date.parse(s.publishedAt);
|
|
186
|
+
if (!Number.isNaN(published)) {
|
|
187
|
+
const ageDays = (Date.now() - published) / 86400_000;
|
|
188
|
+
if (ageDays >= 0)
|
|
189
|
+
score += freshnessBoost * Math.max(0, 1 - ageDays / freshnessDays);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (authorityBoost > 0) {
|
|
193
|
+
let host = '';
|
|
194
|
+
try {
|
|
195
|
+
host = new URL(s.url).hostname.toLowerCase();
|
|
196
|
+
}
|
|
197
|
+
catch { /* ignore */ }
|
|
198
|
+
const isAuthority = authorityDomains.some(d => host === d || host.endsWith('.' + d))
|
|
199
|
+
|| /(^|\.)(edu|gov|org)$/.test(host);
|
|
200
|
+
if (isAuthority)
|
|
201
|
+
score += authorityBoost;
|
|
202
|
+
}
|
|
203
|
+
scores.set(s.url, score);
|
|
204
|
+
if (!entries.has(s.url)) {
|
|
205
|
+
entries.set(s.url, { url: s.url, ...s.title ? { title: s.title } : {}, ...s.snippet ? { snippet: s.snippet } : {}, ...s.publishedAt ? { publishedAt: s.publishedAt } : {} });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (!scores.size)
|
|
210
|
+
throw new Error('all engines failed: ' + enginesTried.join(', '));
|
|
211
|
+
const ranked = [...scores.entries()].sort((a, b) => b[1] - a[1]).slice(0, count);
|
|
212
|
+
outcome = { sources: ranked.map(([url]) => entries.get(url)) };
|
|
213
|
+
usedId = 'multi(' + ids.join('+') + ')';
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
for (const id of ids) {
|
|
217
|
+
enginesTried.push(id);
|
|
218
|
+
const engine = await this.build(id, opts.skipSeam ?? false);
|
|
219
|
+
if (!engine.available())
|
|
220
|
+
continue;
|
|
221
|
+
try {
|
|
222
|
+
outcome = await engine.search(query, count, signal);
|
|
223
|
+
usedId = id;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (signal?.aborted)
|
|
228
|
+
throw error;
|
|
229
|
+
// keep trying the next engine on failure
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (!outcome || !usedId) {
|
|
233
|
+
throw new Error('no engine produced results (tried: ' + enginesTried.join(', ') + ')');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// 3. Persist.
|
|
237
|
+
const queryId = this.store.recordQuery({
|
|
238
|
+
kind: 'search',
|
|
239
|
+
query: nq,
|
|
240
|
+
engine: usedId,
|
|
241
|
+
status: 'ok',
|
|
242
|
+
...outcome.content ? { detail: JSON.stringify({ content: outcome.content }) } : {},
|
|
243
|
+
});
|
|
244
|
+
this.store.recordResults(queryId, outcome.sources, usedId);
|
|
245
|
+
const result = {
|
|
246
|
+
...outcome.content ? { content: outcome.content } : {},
|
|
247
|
+
sources: outcome.sources.slice(0, count).map(s => ({
|
|
248
|
+
url: s.url,
|
|
249
|
+
...s.title ? { title: s.title } : {},
|
|
250
|
+
...s.snippet ? { snippet: capText(s.snippet, 500) } : {},
|
|
251
|
+
...s.publishedAt ? { publishedAt: s.publishedAt } : {},
|
|
252
|
+
})),
|
|
253
|
+
engine: usedId,
|
|
254
|
+
enginesTried,
|
|
255
|
+
fromCache: false,
|
|
256
|
+
};
|
|
257
|
+
// 4. Warm the in-process LRU (memory-only; survives across SQLite hits).
|
|
258
|
+
this.memory.set(usedId + '|' + nq, result);
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
/** Platform search (web_platform_search tool) with the same cache+persist flow. */
|
|
262
|
+
async platformSearch(platform, query, url, count, opts) {
|
|
263
|
+
const nq = normQuery(query || url || platform);
|
|
264
|
+
const custom = this.dynamic().customPlatforms?.[platform];
|
|
265
|
+
const engines = custom
|
|
266
|
+
? [customPlatformEngine(platform, custom, this.depsSync(true))]
|
|
267
|
+
: (platform === 'rss' && url ? [rssEngine(url)] : platformEngines(platform, this.depsSync(true)));
|
|
268
|
+
if (!engines.length)
|
|
269
|
+
throw new Error('unsupported platform: ' + platform);
|
|
270
|
+
if (!opts.fresh) {
|
|
271
|
+
const cached = this.store.getCachedSearch('platform-' + platform, nq, this.dynamic().ttlSeconds);
|
|
272
|
+
if (cached) {
|
|
273
|
+
const rows = this.store.resultsForQuery(cached.id);
|
|
274
|
+
if (rows.length) {
|
|
275
|
+
return {
|
|
276
|
+
sources: rows.map(r => ({ url: r.url, ...r.title ? { title: r.title } : {}, ...r.snippet ? { snippet: r.snippet } : {} })),
|
|
277
|
+
engine: platform,
|
|
278
|
+
enginesTried: [platform],
|
|
279
|
+
fromCache: true,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const enginesTried = [];
|
|
285
|
+
let outcome;
|
|
286
|
+
for (const engine of engines) {
|
|
287
|
+
enginesTried.push(engine.id);
|
|
288
|
+
if (!engine.available())
|
|
289
|
+
continue;
|
|
290
|
+
try {
|
|
291
|
+
outcome = await engine.search(query || 'latest', Math.min(Math.max(count, 1), 20), opts.signal);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
if (opts.signal?.aborted)
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (!outcome)
|
|
300
|
+
throw new Error('platform ' + platform + ' unavailable (tried: ' + enginesTried.join(', ') + ')');
|
|
301
|
+
const queryId = this.store.recordQuery({
|
|
302
|
+
kind: 'platform',
|
|
303
|
+
query: nq,
|
|
304
|
+
platform,
|
|
305
|
+
engine: enginesTried.at(-1) ?? 'unknown',
|
|
306
|
+
status: 'ok',
|
|
307
|
+
});
|
|
308
|
+
this.store.recordResults(queryId, outcome.sources, 'platform-' + platform);
|
|
309
|
+
return { sources: outcome.sources, engine: platform, enginesTried, fromCache: false };
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* ctx.web provider adapter: route the seam request through this router.
|
|
313
|
+
* Returns a WebSearchResult-shaped value for the built-in web_search tool.
|
|
314
|
+
*/
|
|
315
|
+
async searchAsProvider(request, signal) {
|
|
316
|
+
const cfg = this.dynamic();
|
|
317
|
+
const result = await this.search({
|
|
318
|
+
query: request.query,
|
|
319
|
+
count: request.maxResults ?? cfg.searchMaxResults,
|
|
320
|
+
fresh: false,
|
|
321
|
+
multi: cfg.parallelEngines,
|
|
322
|
+
signal,
|
|
323
|
+
skipSeam: true,
|
|
324
|
+
});
|
|
325
|
+
return {
|
|
326
|
+
...result.content ? { content: result.content } : {},
|
|
327
|
+
sources: result.sources.map(s => ({ url: s.url, ...s.title ? { title: s.title } : {}, ...s.snippet ? { snippet: s.snippet } : {}, ...s.publishedAt ? { publishedAt: s.publishedAt } : {} })),
|
|
328
|
+
truncated: result.sources.length > (request.maxResults ?? cfg.searchMaxResults),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAG5D,OAAO,EACL,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAC5E,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EACrF,SAAS,EAAE,oBAAoB,EAAE,WAAW,GAC7C,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAyB5C,MAAM,gBAAgB,GAAkE;IACtF,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;IAClC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;IAC9B,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE;IACtB,IAAI,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE;IACxB,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC;IACpC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC;IACxC,IAAI,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE;IACxB,OAAO,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results, fetched page snapshots, and user-extended
|
|
4
|
+
* extraction rules (userscript-style). All methods are synchronous; writes are
|
|
5
|
+
* small and batched per call.
|
|
6
|
+
* @module web-search-pro/store
|
|
7
|
+
*/
|
|
8
|
+
export type QueryKind = 'search' | 'fetch' | 'platform' | 'snapshot';
|
|
9
|
+
export interface QueryRecord {
|
|
10
|
+
id: string;
|
|
11
|
+
kind: QueryKind;
|
|
12
|
+
query?: string;
|
|
13
|
+
engine?: string;
|
|
14
|
+
platform?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
status: string;
|
|
17
|
+
ts: string;
|
|
18
|
+
detail?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SourceRow {
|
|
21
|
+
id: string;
|
|
22
|
+
queryId: string;
|
|
23
|
+
rank: number;
|
|
24
|
+
url: string;
|
|
25
|
+
title?: string;
|
|
26
|
+
snippet?: string;
|
|
27
|
+
published?: string;
|
|
28
|
+
engine?: string;
|
|
29
|
+
extra?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface PageRecord {
|
|
32
|
+
id: string;
|
|
33
|
+
url: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
text?: string;
|
|
36
|
+
htmlPath?: string;
|
|
37
|
+
screenshotPath?: string;
|
|
38
|
+
status?: number;
|
|
39
|
+
fetchedAt: string;
|
|
40
|
+
source?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface RuleRecord {
|
|
43
|
+
hostname: string;
|
|
44
|
+
content: string;
|
|
45
|
+
remove?: string;
|
|
46
|
+
createdAt: string;
|
|
47
|
+
updatedAt: string;
|
|
48
|
+
}
|
|
49
|
+
export declare class Store {
|
|
50
|
+
readonly dbPath: string;
|
|
51
|
+
private db;
|
|
52
|
+
constructor(dbPath: string);
|
|
53
|
+
close(): void;
|
|
54
|
+
/** Record one operation (search / fetch / platform / snapshot). Returns its id. */
|
|
55
|
+
recordQuery(input: Omit<QueryRecord, 'id' | 'ts'> & {
|
|
56
|
+
id?: string;
|
|
57
|
+
}): string;
|
|
58
|
+
/** Look up a fresh cached search by (engine, normalized query). */
|
|
59
|
+
getCachedSearch(engine: string, normQuery: string, ttlSeconds: number): {
|
|
60
|
+
id: string;
|
|
61
|
+
detail?: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
recordResults(queryId: string, sources: {
|
|
64
|
+
url: string;
|
|
65
|
+
title?: string;
|
|
66
|
+
snippet?: string;
|
|
67
|
+
publishedAt?: string;
|
|
68
|
+
extra?: string;
|
|
69
|
+
}[], engine: string): void;
|
|
70
|
+
resultsForQuery(queryId: string): SourceRow[];
|
|
71
|
+
/** Fresh page snapshot by URL, or undefined. */
|
|
72
|
+
getPage(url: string, ttlSeconds: number): PageRecord | undefined;
|
|
73
|
+
savePage(input: Omit<PageRecord, 'id' | 'fetchedAt'>): void;
|
|
74
|
+
listQueries(opts: {
|
|
75
|
+
kind?: QueryKind;
|
|
76
|
+
query?: string;
|
|
77
|
+
engine?: string;
|
|
78
|
+
platform?: string;
|
|
79
|
+
limit?: number;
|
|
80
|
+
}): QueryRecord[];
|
|
81
|
+
clearCache(opts: {
|
|
82
|
+
olderThanDays?: number;
|
|
83
|
+
engine?: string;
|
|
84
|
+
}): {
|
|
85
|
+
queries: number;
|
|
86
|
+
results: number;
|
|
87
|
+
pages: number;
|
|
88
|
+
};
|
|
89
|
+
private removeQuery;
|
|
90
|
+
/** Delete one query and its results; returns whether it existed. */
|
|
91
|
+
deleteQuery(id: string): boolean;
|
|
92
|
+
/** Most-used engines, desc. */
|
|
93
|
+
topEngines(limit?: number): {
|
|
94
|
+
engine: string;
|
|
95
|
+
count: number;
|
|
96
|
+
}[];
|
|
97
|
+
/** Most-frequent queries, desc. */
|
|
98
|
+
topQueries(limit?: number): {
|
|
99
|
+
query: string;
|
|
100
|
+
count: number;
|
|
101
|
+
}[];
|
|
102
|
+
/** Per-kind record counts. */
|
|
103
|
+
kindCounts(): {
|
|
104
|
+
kind: string;
|
|
105
|
+
count: number;
|
|
106
|
+
}[];
|
|
107
|
+
stats(): {
|
|
108
|
+
dbSizeBytes: number;
|
|
109
|
+
queries: number;
|
|
110
|
+
results: number;
|
|
111
|
+
pages: number;
|
|
112
|
+
rules: number;
|
|
113
|
+
};
|
|
114
|
+
listRules(): RuleRecord[];
|
|
115
|
+
upsertRule(hostname: string, content: string, remove?: string): void;
|
|
116
|
+
removeRule(hostname: string): boolean;
|
|
117
|
+
}
|