@fffangchenghao/dsh-web-search 0.10.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 +82 -0
- package/README.md +247 -41
- package/README.zh-CN.md +247 -41
- package/client.js +66 -9
- package/lib/cache-persist.d.ts +96 -0
- package/lib/cache-persist.js +249 -0
- package/lib/cache.d.ts +56 -8
- package/lib/cache.js +141 -13
- package/lib/config.d.ts +33 -1
- package/lib/config.js +54 -2
- package/lib/domain-tool.d.ts +119 -0
- package/lib/domain-tool.js +196 -0
- package/lib/engines.js +68 -10
- package/lib/fetch.d.ts +7 -0
- package/lib/fetch.js +36 -3
- package/lib/freshness.d.ts +102 -0
- package/lib/freshness.js +359 -0
- package/lib/index.d.ts +44 -2
- package/lib/index.js +144 -23
- package/lib/markdown.d.ts +84 -0
- package/lib/markdown.js +847 -0
- package/lib/parsers.js +59 -5
- package/lib/rank.d.ts +14 -1
- package/lib/rank.js +18 -0
- package/lib/search-many.d.ts +117 -0
- package/lib/search-many.js +286 -0
- package/lib/transport.d.ts +4 -2
- package/lib/transport.js +4 -2
- package/lib/types.d.ts +22 -6
- package/lib/verticals.d.ts +164 -0
- package/lib/verticals.js +539 -0
- package/package.json +4 -4
package/lib/freshness.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/** Milliseconds in one day, shared with the ranking module. */
|
|
2
|
+
export const MS_PER_DAY = 86_400_000;
|
|
3
|
+
/** Rolling window length per range. `off` is handled separately. */
|
|
4
|
+
export const TIME_RANGE_MS = {
|
|
5
|
+
day: MS_PER_DAY,
|
|
6
|
+
week: 7 * MS_PER_DAY,
|
|
7
|
+
month: 30 * MS_PER_DAY,
|
|
8
|
+
year: 365 * MS_PER_DAY,
|
|
9
|
+
};
|
|
10
|
+
/** Every accepted `timeRange` value, in settings order. */
|
|
11
|
+
export const TIME_RANGES = ['off', 'day', 'week', 'month', 'year'];
|
|
12
|
+
/** Longest relative age accepted, so a stray huge number cannot overflow. */
|
|
13
|
+
const MAX_RELATIVE = 10_000;
|
|
14
|
+
/** Plausible absolute years; anything outside is a number, not a date. */
|
|
15
|
+
const MIN_YEAR = 1900;
|
|
16
|
+
const MAX_YEAR = 2200;
|
|
17
|
+
/** Month names as the scraped engines spell them. */
|
|
18
|
+
const MONTHS = {
|
|
19
|
+
jan: 1,
|
|
20
|
+
feb: 2,
|
|
21
|
+
mar: 3,
|
|
22
|
+
apr: 4,
|
|
23
|
+
may: 5,
|
|
24
|
+
jun: 6,
|
|
25
|
+
jul: 7,
|
|
26
|
+
aug: 8,
|
|
27
|
+
sep: 9,
|
|
28
|
+
sept: 9,
|
|
29
|
+
oct: 10,
|
|
30
|
+
nov: 11,
|
|
31
|
+
dec: 12,
|
|
32
|
+
};
|
|
33
|
+
/** Boundaries that make a relative phrase a whole token, not prose. */
|
|
34
|
+
const BEFORE = '(?:^|[\\s,,。;;::|((【\\[])';
|
|
35
|
+
const AFTER = '(?=$|[\\s,,。;;::|))】\\]])';
|
|
36
|
+
/** Chinese relative stamps: `3 天前`, `10 小时之前`, `昨天`, `刚刚`. */
|
|
37
|
+
const CN_RELATIVE = new RegExp(`${BEFORE}(\\d{1,5})\\s*(分钟|小时|天|周|个月|年)\\s*(?:前|之前)${AFTER}`, 'u');
|
|
38
|
+
/** Chinese named days, which carry no number. */
|
|
39
|
+
const CN_NAMED = new RegExp(`${BEFORE}(今天|昨天|前天|刚刚)${AFTER}`, 'u');
|
|
40
|
+
/** English relative stamps: `3 days ago`, `22 hours ago`, `yesterday`. */
|
|
41
|
+
const EN_RELATIVE = new RegExp(`${BEFORE}(\\d{1,5})\\s+(minute|hour|day|week|month|year)s?\\s+ago${AFTER}`, 'i');
|
|
42
|
+
/** English named days. */
|
|
43
|
+
const EN_NAMED = new RegExp(`${BEFORE}(today|yesterday)${AFTER}`, 'i');
|
|
44
|
+
/** `2024年5月1日` and `2024年5月1号`. */
|
|
45
|
+
const CN_ABSOLUTE = /(\d{4})\s*年\s*(\d{1,2})\s*月\s*(\d{1,2})\s*[日号]/u;
|
|
46
|
+
/** `2024-05-01`, `2024/5/1`, and the date part of a full ISO instant. */
|
|
47
|
+
const ISO_ABSOLUTE = /(\d{4})[-/](\d{1,2})[-/](\d{1,2})(?!\d)/u;
|
|
48
|
+
/** `May 1, 2024`, `Sept 25 2025`, `Oct 3rd, 2025`. */
|
|
49
|
+
const EN_MONTH_FIRST = /\b(jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+(\d{4})\b/i;
|
|
50
|
+
/** `1 May 2024`, `3rd Oct 2025`. */
|
|
51
|
+
const EN_DAY_FIRST = /\b(\d{1,2})(?:st|nd|rd|th)?\s+(jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?,?\s+(\d{4})\b/i;
|
|
52
|
+
/** The marker AnySearch appends to `content`, e.g. `date: 22 hours ago`. */
|
|
53
|
+
const DATE_MARKER = /(?:^|[\s|])date\s*[::]\s*([^|\n]+?)\s*$/i;
|
|
54
|
+
/**
|
|
55
|
+
* Build a UTC instant for a calendar date.
|
|
56
|
+
*
|
|
57
|
+
* The time of day is fixed at noon UTC on purpose: a date without a time
|
|
58
|
+
* belongs to no particular hour, and noon keeps it inside its own calendar day
|
|
59
|
+
* for every timezone from UTC-11 to UTC+12. `Date.UTC` also means the machine's
|
|
60
|
+
* `TZ` is never consulted.
|
|
61
|
+
*
|
|
62
|
+
* @param year - four-digit year.
|
|
63
|
+
* @param month - 1-based month.
|
|
64
|
+
* @param day - day of month.
|
|
65
|
+
* @returns epoch milliseconds, or `undefined` when the components are not a
|
|
66
|
+
* real calendar date (for example 31 February).
|
|
67
|
+
*/
|
|
68
|
+
function utcDate(year, month, day) {
|
|
69
|
+
if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day))
|
|
70
|
+
return undefined;
|
|
71
|
+
if (year < MIN_YEAR || year > MAX_YEAR)
|
|
72
|
+
return undefined;
|
|
73
|
+
if (month < 1 || month > 12 || day < 1 || day > 31)
|
|
74
|
+
return undefined;
|
|
75
|
+
const at = Date.UTC(year, month - 1, day, 12, 0, 0, 0);
|
|
76
|
+
const check = new Date(at);
|
|
77
|
+
if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
return at;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert epoch milliseconds to the canonical ISO string.
|
|
84
|
+
* @param at - epoch milliseconds.
|
|
85
|
+
* @returns ISO 8601 in UTC, the only shape `Source.publishedAt` carries.
|
|
86
|
+
*/
|
|
87
|
+
function iso(at) {
|
|
88
|
+
return new Date(at).toISOString();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Read the unit multiplier for a Chinese relative unit.
|
|
92
|
+
* @param unit - `分钟`, `小时`, `天`, `周`, `个月` or `年`.
|
|
93
|
+
* @returns milliseconds per unit, or `undefined` for an unknown unit.
|
|
94
|
+
*/
|
|
95
|
+
function cnUnitMs(unit) {
|
|
96
|
+
switch (unit) {
|
|
97
|
+
case '分钟':
|
|
98
|
+
return 60_000;
|
|
99
|
+
case '小时':
|
|
100
|
+
return 3_600_000;
|
|
101
|
+
case '天':
|
|
102
|
+
return MS_PER_DAY;
|
|
103
|
+
case '周':
|
|
104
|
+
return 7 * MS_PER_DAY;
|
|
105
|
+
case '个月':
|
|
106
|
+
return 30 * MS_PER_DAY;
|
|
107
|
+
case '年':
|
|
108
|
+
return 365 * MS_PER_DAY;
|
|
109
|
+
default:
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Read the unit multiplier for an English relative unit.
|
|
115
|
+
* @param unit - `minute`, `hour`, `day`, `week`, `month` or `year`.
|
|
116
|
+
* @returns milliseconds per unit, or `undefined` for an unknown unit.
|
|
117
|
+
*/
|
|
118
|
+
function enUnitMs(unit) {
|
|
119
|
+
switch (unit.toLowerCase()) {
|
|
120
|
+
case 'minute':
|
|
121
|
+
return 60_000;
|
|
122
|
+
case 'hour':
|
|
123
|
+
return 3_600_000;
|
|
124
|
+
case 'day':
|
|
125
|
+
return MS_PER_DAY;
|
|
126
|
+
case 'week':
|
|
127
|
+
return 7 * MS_PER_DAY;
|
|
128
|
+
case 'month':
|
|
129
|
+
return 30 * MS_PER_DAY;
|
|
130
|
+
case 'year':
|
|
131
|
+
return 365 * MS_PER_DAY;
|
|
132
|
+
default:
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parse the first relative phrase in a fragment.
|
|
138
|
+
*
|
|
139
|
+
* Relative stamps are rolling: `3 days ago` means `now - 3 * 24h`, not three
|
|
140
|
+
* calendar days. That avoids the timezone and daylight-saving questions a
|
|
141
|
+
* calendar subtraction would raise, and matches how the engines mean them.
|
|
142
|
+
*
|
|
143
|
+
* @param value - normalised text.
|
|
144
|
+
* @param now - evaluation instant in epoch milliseconds.
|
|
145
|
+
* @returns epoch milliseconds, or `undefined` when there is no relative phrase.
|
|
146
|
+
*/
|
|
147
|
+
function parseRelative(value, now) {
|
|
148
|
+
const cnNumbered = CN_RELATIVE.exec(value);
|
|
149
|
+
if (cnNumbered !== null) {
|
|
150
|
+
const amount = Number(cnNumbered[1]);
|
|
151
|
+
const unit = cnUnitMs(cnNumbered[2] ?? '');
|
|
152
|
+
if (Number.isFinite(amount) && amount >= 0 && amount <= MAX_RELATIVE && unit !== undefined) {
|
|
153
|
+
return now - amount * unit;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const enNumbered = EN_RELATIVE.exec(value);
|
|
157
|
+
if (enNumbered !== null) {
|
|
158
|
+
const amount = Number(enNumbered[1]);
|
|
159
|
+
const unit = enUnitMs(enNumbered[2] ?? '');
|
|
160
|
+
if (Number.isFinite(amount) && amount >= 0 && amount <= MAX_RELATIVE && unit !== undefined) {
|
|
161
|
+
return now - amount * unit;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const cnNamed = CN_NAMED.exec(value);
|
|
165
|
+
if (cnNamed !== null) {
|
|
166
|
+
switch (cnNamed[1]) {
|
|
167
|
+
case '昨天':
|
|
168
|
+
return now - MS_PER_DAY;
|
|
169
|
+
case '前天':
|
|
170
|
+
return now - 2 * MS_PER_DAY;
|
|
171
|
+
case '今天':
|
|
172
|
+
case '刚刚':
|
|
173
|
+
default:
|
|
174
|
+
return now;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const enNamed = EN_NAMED.exec(value);
|
|
178
|
+
if (enNamed !== null)
|
|
179
|
+
return enNamed[1]?.toLowerCase() === 'yesterday' ? now - MS_PER_DAY : now;
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Parse the first absolute date in a fragment.
|
|
184
|
+
*
|
|
185
|
+
* Checked before relative stamps only when declared explicitly; the caller
|
|
186
|
+
* decides the order. All arithmetic is UTC.
|
|
187
|
+
*
|
|
188
|
+
* @param value - normalised text.
|
|
189
|
+
* @returns epoch milliseconds, or `undefined` when no valid date is present.
|
|
190
|
+
*/
|
|
191
|
+
function parseAbsolute(value) {
|
|
192
|
+
const cn = CN_ABSOLUTE.exec(value);
|
|
193
|
+
if (cn !== null) {
|
|
194
|
+
const at = utcDate(Number(cn[1]), Number(cn[2]), Number(cn[3]));
|
|
195
|
+
if (at !== undefined)
|
|
196
|
+
return at;
|
|
197
|
+
}
|
|
198
|
+
const isoDate = ISO_ABSOLUTE.exec(value);
|
|
199
|
+
if (isoDate !== null) {
|
|
200
|
+
const at = utcDate(Number(isoDate[1]), Number(isoDate[2]), Number(isoDate[3]));
|
|
201
|
+
if (at !== undefined)
|
|
202
|
+
return at;
|
|
203
|
+
}
|
|
204
|
+
const monthFirst = EN_MONTH_FIRST.exec(value);
|
|
205
|
+
if (monthFirst !== null) {
|
|
206
|
+
const month = MONTHS[(monthFirst[1] ?? '').toLowerCase()];
|
|
207
|
+
if (month !== undefined) {
|
|
208
|
+
const at = utcDate(Number(monthFirst[3]), month, Number(monthFirst[2]));
|
|
209
|
+
if (at !== undefined)
|
|
210
|
+
return at;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const dayFirst = EN_DAY_FIRST.exec(value);
|
|
214
|
+
if (dayFirst !== null) {
|
|
215
|
+
const month = MONTHS[(dayFirst[2] ?? '').toLowerCase()];
|
|
216
|
+
if (month !== undefined) {
|
|
217
|
+
const at = utcDate(Number(dayFirst[3]), month, Number(dayFirst[1]));
|
|
218
|
+
if (at !== undefined)
|
|
219
|
+
return at;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Normalise whitespace so the boundary patterns see one predictable shape.
|
|
226
|
+
* @param value - raw fragment.
|
|
227
|
+
* @returns single-spaced trimmed text.
|
|
228
|
+
*/
|
|
229
|
+
function normalise(value) {
|
|
230
|
+
return value.replace(/[\u00a0\u2000-\u200a\u202f\u205f\u3000]/gu, ' ').replace(/\s+/gu, ' ').trim();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Extract a publication date from one fragment of result text.
|
|
234
|
+
*
|
|
235
|
+
* The search order is deliberate: an explicit `date:` marker wins (AnySearch
|
|
236
|
+
* puts the engine's stamp there), then a relative phrase, then an absolute
|
|
237
|
+
* date. `今天` inside a sentence such as `但是我们今天讲的逻辑复制` is not a
|
|
238
|
+
* publication stamp, so relative words only match as whole tokens; a bare date
|
|
239
|
+
* such as `2024-05-01` is unambiguous enough to match anywhere.
|
|
240
|
+
*
|
|
241
|
+
* @param fragment - summary, stamp or result text.
|
|
242
|
+
* @param now - evaluation instant, injected so tests are deterministic.
|
|
243
|
+
* @returns ISO 8601 UTC, or `undefined` when the fragment carries no date.
|
|
244
|
+
*/
|
|
245
|
+
export function parsePublishedAt(fragment, now = Date.now()) {
|
|
246
|
+
if (typeof fragment !== 'string' || fragment.trim().length === 0)
|
|
247
|
+
return undefined;
|
|
248
|
+
const value = normalise(fragment);
|
|
249
|
+
const marker = DATE_MARKER.exec(value);
|
|
250
|
+
if (marker !== null) {
|
|
251
|
+
const marked = normalise(marker[1] ?? '');
|
|
252
|
+
const at = parseRelative(marked, now) ?? parseAbsolute(marked);
|
|
253
|
+
if (at !== undefined)
|
|
254
|
+
return iso(at);
|
|
255
|
+
}
|
|
256
|
+
const relative = parseRelative(value, now);
|
|
257
|
+
if (relative !== undefined)
|
|
258
|
+
return iso(relative);
|
|
259
|
+
const absolute = parseAbsolute(value);
|
|
260
|
+
if (absolute !== undefined)
|
|
261
|
+
return iso(absolute);
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Parse the first fragment that carries a usable date.
|
|
266
|
+
*
|
|
267
|
+
* Parsers pass the most authoritative fragment first (a dedicated timestamp
|
|
268
|
+
* element, then the snippet), so a date mentioned in prose cannot override the
|
|
269
|
+
* stamp the engine printed.
|
|
270
|
+
*
|
|
271
|
+
* @param fragments - candidate texts, most authoritative first.
|
|
272
|
+
* @param now - evaluation instant, injected for tests.
|
|
273
|
+
* @returns the first parsed ISO 8601 UTC value, or `undefined`.
|
|
274
|
+
*/
|
|
275
|
+
export function extractPublishedAt(fragments, now = Date.now()) {
|
|
276
|
+
for (const fragment of fragments) {
|
|
277
|
+
if (typeof fragment !== 'string')
|
|
278
|
+
continue;
|
|
279
|
+
const parsed = parsePublishedAt(fragment, now);
|
|
280
|
+
if (parsed !== undefined)
|
|
281
|
+
return parsed;
|
|
282
|
+
}
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Read a publication date as epoch milliseconds.
|
|
287
|
+
* @param publishedAt - canonical ISO string, or `undefined`.
|
|
288
|
+
* @returns epoch milliseconds, or `undefined` when absent or unparsable.
|
|
289
|
+
*/
|
|
290
|
+
export function publishedTimestamp(publishedAt) {
|
|
291
|
+
if (typeof publishedAt !== 'string' || publishedAt.length === 0)
|
|
292
|
+
return undefined;
|
|
293
|
+
const at = Date.parse(publishedAt);
|
|
294
|
+
return Number.isNaN(at) ? undefined : at;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Whether a result belongs to the rolling window.
|
|
298
|
+
*
|
|
299
|
+
* `off` accepts everything. A missing or unparsable date is accepted on
|
|
300
|
+
* purpose: filtering exists to remove results known to be stale, not to punish
|
|
301
|
+
* pages that publish no metadata. A date in the future is accepted too — it is
|
|
302
|
+
* still inside the window, and ranking clamps its age to zero.
|
|
303
|
+
*
|
|
304
|
+
* @param publishedAt - canonical ISO string, or `undefined`.
|
|
305
|
+
* @param range - active window.
|
|
306
|
+
* @param now - evaluation instant.
|
|
307
|
+
* @returns `true` when the result may stay.
|
|
308
|
+
*/
|
|
309
|
+
export function isWithinTimeRange(publishedAt, range, now = Date.now()) {
|
|
310
|
+
if (range === 'off')
|
|
311
|
+
return true;
|
|
312
|
+
const at = publishedTimestamp(publishedAt);
|
|
313
|
+
if (at === undefined)
|
|
314
|
+
return true;
|
|
315
|
+
return at >= now - TIME_RANGE_MS[range];
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Keep only results inside the window.
|
|
319
|
+
*
|
|
320
|
+
* A result whose date could not be parsed is not evidence of an old page, so it
|
|
321
|
+
* is held back rather than dropped: when at least one dated result falls inside
|
|
322
|
+
* the window, only those are returned; when none does, the undated results are
|
|
323
|
+
* returned as a fallback so the caller is not left empty-handed. That trades a
|
|
324
|
+
* little precision for never answering "last 24 hours" with nothing at all.
|
|
325
|
+
* @param sources - parsed sources, in engine order.
|
|
326
|
+
* @param range - active window.
|
|
327
|
+
* @param now - evaluation instant.
|
|
328
|
+
* @returns a new list; the input array and its objects are untouched.
|
|
329
|
+
*/
|
|
330
|
+
export function filterByTimeRange(sources, range, now = Date.now()) {
|
|
331
|
+
if (range === 'off')
|
|
332
|
+
return [...sources];
|
|
333
|
+
// "Undated" means the timestamp could not be parsed, not merely absent: a
|
|
334
|
+
// junk value is no more evidence of age than a missing one.
|
|
335
|
+
const dated = sources.filter((source) => publishedTimestamp(source.publishedAt) !== undefined);
|
|
336
|
+
const inside = dated.filter((source) => isWithinTimeRange(source.publishedAt, range, now));
|
|
337
|
+
if (inside.length > 0)
|
|
338
|
+
return inside;
|
|
339
|
+
const undated = sources.filter((source) => publishedTimestamp(source.publishedAt) === undefined);
|
|
340
|
+
return undated.length > 0 ? undated : [];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Apply a window to an already merged list.
|
|
344
|
+
*
|
|
345
|
+
* Per-engine filtering can only see one engine's dates, so an engine that dates
|
|
346
|
+
* nothing keeps all of its rows; this pass runs after the merge, where a dated
|
|
347
|
+
* row from any engine can speak for the whole list. When nothing is dated inside
|
|
348
|
+
* the window the merged list is returned unchanged rather than emptied.
|
|
349
|
+
* @param sources - merged sources.
|
|
350
|
+
* @param range - active window.
|
|
351
|
+
* @param now - evaluation instant.
|
|
352
|
+
* @returns the rows to keep.
|
|
353
|
+
*/
|
|
354
|
+
export function preferWindow(sources, range, now = Date.now()) {
|
|
355
|
+
if (range === 'off')
|
|
356
|
+
return [...sources];
|
|
357
|
+
const inside = sources.filter((source) => publishedTimestamp(source.publishedAt) !== undefined && isWithinTimeRange(source.publishedAt, range, now));
|
|
358
|
+
return inside.length > 0 ? inside : [...sources];
|
|
359
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PluginConfig } from './config.ts';
|
|
2
2
|
import type { FetchProvider } from './fetch.ts';
|
|
3
3
|
import type { Source } from './types.ts';
|
|
4
|
-
export declare const name = "dsh-web-search
|
|
4
|
+
export declare const name = "dsh-web-search";
|
|
5
5
|
/** The `ctx.web` service this plugin registers a search provider with. */
|
|
6
6
|
export declare const inject: string[];
|
|
7
7
|
/** Provider id referenced by `web.searchProvider`. */
|
|
@@ -30,6 +30,22 @@ export interface PluginContext {
|
|
|
30
30
|
registerSearchProvider: (provider: SearchProvider) => void;
|
|
31
31
|
registerFetchProvider: (provider: FetchProvider) => void;
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Cordis's inject-free service lookup. `tools` is read through this rather
|
|
35
|
+
* than added to {@link inject} on purpose: a hard `tools` dependency would
|
|
36
|
+
* stop the whole plugin (including `web_search`) from mounting in a
|
|
37
|
+
* deployment that has no tool registry.
|
|
38
|
+
*/
|
|
39
|
+
get?: (name: string) => unknown;
|
|
40
|
+
/** Fallback for tests and hosts that expose the registry as a property. */
|
|
41
|
+
tools?: unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Cordis lifecycle hook. `effect` is the canonical registration; `on` is the
|
|
44
|
+
* older/test fallback. Both let the tool registration and the cache release
|
|
45
|
+
* their resources when the plugin is disposed.
|
|
46
|
+
*/
|
|
47
|
+
effect?: (execute: () => (() => void) | void) => unknown;
|
|
48
|
+
on?: (event: string, listener: () => void) => unknown;
|
|
33
49
|
}
|
|
34
50
|
/** Configuration as the loader hands it over, already schema-validated. */
|
|
35
51
|
export type ApplyConfig = PluginConfig;
|
|
@@ -56,6 +72,8 @@ declare const _default: typeof apply & {
|
|
|
56
72
|
Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
57
73
|
hosts: import("@deepseek-ai/schemastery").default<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
|
|
58
74
|
timeoutMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
75
|
+
fetchFormat: import("@deepseek-ai/schemastery").default<"markdown" | "text", "markdown" | "text", "volatile-defined">;
|
|
76
|
+
fetchMaxLength: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
59
77
|
wait: import("@deepseek-ai/schemastery").default<"auto" | "all" | "fast", "auto" | "all" | "fast", "volatile-defined">;
|
|
60
78
|
proxy: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
61
79
|
limit: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
@@ -64,15 +82,23 @@ declare const _default: typeof apply & {
|
|
|
64
82
|
authorityBoost: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
65
83
|
freshnessBoost: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
66
84
|
freshnessDays: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
85
|
+
timeRange: import("@deepseek-ai/schemastery").default<"off" | "day" | "week" | "month" | "year", "off" | "day" | "week" | "month" | "year", "volatile-defined">;
|
|
67
86
|
cacheTtlMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
68
87
|
cacheEntries: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
88
|
+
cachePersist: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
89
|
+
cacheFile: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
69
90
|
anysearchApiKey: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
70
91
|
anysearchDomain: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
71
92
|
baseCooldownMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
72
93
|
maxCooldownMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
94
|
+
domainSources: import("@deepseek-ai/schemastery").default<NoInfer<string | string[]>, NoInfer<string | string[]>, "volatile-defined">;
|
|
95
|
+
domainLimit: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
96
|
+
domainTimeoutMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
73
97
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
74
98
|
hosts: import("@deepseek-ai/schemastery").default<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
|
|
75
99
|
timeoutMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
100
|
+
fetchFormat: import("@deepseek-ai/schemastery").default<"markdown" | "text", "markdown" | "text", "volatile-defined">;
|
|
101
|
+
fetchMaxLength: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
76
102
|
wait: import("@deepseek-ai/schemastery").default<"auto" | "all" | "fast", "auto" | "all" | "fast", "volatile-defined">;
|
|
77
103
|
proxy: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
78
104
|
limit: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
@@ -81,21 +107,37 @@ declare const _default: typeof apply & {
|
|
|
81
107
|
authorityBoost: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
82
108
|
freshnessBoost: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
83
109
|
freshnessDays: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
110
|
+
timeRange: import("@deepseek-ai/schemastery").default<"off" | "day" | "week" | "month" | "year", "off" | "day" | "week" | "month" | "year", "volatile-defined">;
|
|
84
111
|
cacheTtlMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
85
112
|
cacheEntries: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
113
|
+
cachePersist: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
114
|
+
cacheFile: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
86
115
|
anysearchApiKey: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
87
116
|
anysearchDomain: import("@deepseek-ai/schemastery").default<string, string, "volatile-defined">;
|
|
88
117
|
baseCooldownMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
89
118
|
maxCooldownMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
119
|
+
domainSources: import("@deepseek-ai/schemastery").default<NoInfer<string | string[]>, NoInfer<string | string[]>, "volatile-defined">;
|
|
120
|
+
domainLimit: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
121
|
+
domainTimeoutMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
90
122
|
}>>, "plain">;
|
|
91
123
|
inject: string[];
|
|
92
124
|
};
|
|
93
125
|
export default _default;
|
|
94
126
|
export { HOSTS, search } from './engines.ts';
|
|
95
127
|
export { SearchCache, cacheKey } from './cache.ts';
|
|
128
|
+
export type { CachePersistOptions, SearchCacheOptions } from './cache.ts';
|
|
129
|
+
export { CACHE_FILE_VERSION, DEFAULT_CACHE_FILE_MAX_BYTES, defaultCacheFile, resolveCacheFile, readCacheFile, serializeCache, writeCacheFile, } from './cache-persist.ts';
|
|
130
|
+
export type { CacheFileIo, CacheWriteOptions, PersistedEntry, SerializedCache } from './cache-persist.ts';
|
|
96
131
|
export { EngineHealth } from './health.ts';
|
|
97
132
|
export { SearchError, parseRetryAfter } from './errors.ts';
|
|
98
133
|
export { resolveHref, parseDdgHtml, parseDdgLite, parseBing, parseSo, parseAnySearch, echoesQuery, } from './parsers.ts';
|
|
99
134
|
export { fuse, interleave, dedupe, mergeRegions } from './rank.ts';
|
|
135
|
+
export { MS_PER_DAY, TIME_RANGE_MS, TIME_RANGES, parsePublishedAt, extractPublishedAt, publishedTimestamp, isWithinTimeRange, filterByTimeRange, } from './freshness.ts';
|
|
100
136
|
export { parseProxy, proxyFromEnv, resolveProxy, proxyGet } from './proxy.ts';
|
|
101
|
-
export
|
|
137
|
+
export { VERTICAL_IDS, VERTICALS, searchVerticals, verticalById, isVerticalId, parseGithub, parseNpm, parsePypi, parseArxiv, parseWikipedia, parseHn, parseStackExchange, parseCrates, } from './verticals.ts';
|
|
138
|
+
export { DOMAIN_TOOL_NAME, DOMAIN_TOOL_FALLBACK_NAME, createDomainToolDefinition, registerDomainTool, formatDomainValue, } from './domain-tool.ts';
|
|
139
|
+
export type { VerticalId, VerticalSpec, VerticalOutcome, VerticalSearchOptions } from './verticals.ts';
|
|
140
|
+
export type { DomainToolSettings, DomainToolValue, DomainToolDefinition, ToolRegistryLike } from './domain-tool.ts';
|
|
141
|
+
export { SEARCH_MANY_TOOL_NAME, SEARCH_MANY_FALLBACK_NAME, SEARCH_MANY_CONCURRENCY, SEARCH_MANY_DEFAULT_LIMIT, createSearchManyDefinition, registerSearchManyTool, pickSearchManyToolName, formatSearchManyValue, } from './search-many.ts';
|
|
142
|
+
export type { SearchManyDefinition, SearchManyOutcome, SearchManyRegistration, SearchManyRegistryLike, SearchManyResult, SearchManyRunner, SearchManySource, SearchManyValue, } from './search-many.ts';
|
|
143
|
+
export type { Source, SearchOutcome, RankOptions, SearchOptions, HostSpec, Region, TimeRange, WaitPolicy } from './types.ts';
|