@fffangchenghao/dsh-web-search 0.19.3 → 0.20.1
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 +173 -1
- package/README.md +214 -34
- package/README.zh-CN.md +187 -35
- package/SECURITY.md +42 -7
- package/client.js +248 -10
- package/docs/store-evidence.md +10 -5
- package/lib/advanced-search.d.ts +107 -0
- package/lib/advanced-search.js +255 -0
- package/lib/bridge.d.ts +34 -0
- package/lib/bridge.js +305 -0
- package/lib/cache.d.ts +11 -4
- package/lib/cache.js +9 -5
- package/lib/config.d.ts +19 -3
- package/lib/config.js +24 -0
- package/lib/domain-tool.d.ts +5 -0
- package/lib/domain-tool.js +45 -6
- package/lib/engine-test.d.ts +116 -0
- package/lib/engine-test.js +256 -0
- package/lib/engines.d.ts +11 -1
- package/lib/engines.js +118 -19
- package/lib/errors.d.ts +16 -2
- package/lib/errors.js +40 -1
- package/lib/index.d.ts +24 -2
- package/lib/index.js +309 -21
- package/lib/inject.d.ts +68 -0
- package/lib/inject.js +1 -0
- package/lib/markdown.js +18 -1
- package/lib/mirrors.d.ts +23 -0
- package/lib/mirrors.js +69 -0
- package/lib/official-feed.d.ts +114 -0
- package/lib/official-feed.js +288 -0
- package/lib/official-support.d.ts +74 -0
- package/lib/official-support.js +134 -0
- package/lib/platform-tool.d.ts +77 -0
- package/lib/platform-tool.js +173 -0
- package/lib/platforms.d.ts +178 -0
- package/lib/platforms.js +1035 -0
- package/lib/query-router.d.ts +29 -0
- package/lib/query-router.js +58 -0
- package/lib/read-page.js +2 -1
- package/lib/research-cache.d.ts +115 -0
- package/lib/research-cache.js +275 -0
- package/lib/research.d.ts +45 -4
- package/lib/research.js +505 -22
- package/lib/search-many.d.ts +7 -1
- package/lib/search-many.js +7 -2
- package/lib/system-prompt.d.ts +27 -0
- package/lib/system-prompt.js +50 -0
- package/lib/tool-suite.d.ts +97 -0
- package/lib/tool-suite.js +224 -0
- package/lib/transport.d.ts +33 -2
- package/lib/transport.js +42 -9
- package/lib/types.d.ts +20 -0
- package/lib/types.js +9 -1
- package/lib/untrusted.d.ts +33 -0
- package/lib/untrusted.js +42 -0
- package/lib/verticals.d.ts +3 -1
- package/lib/verticals.js +26 -7
- package/package.json +5 -3
- package/skills/dsh-web-search/SKILL.md +21 -6
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small, key-free official feeds used to answer questions that ordinary
|
|
3
|
+
* search-result snippets cannot date.
|
|
4
|
+
*
|
|
5
|
+
* Chrome Releases is the first entry: its Atom/JSON feed exposes the real
|
|
6
|
+
* publication timestamp for every post, while the HTML search result often
|
|
7
|
+
* loses it. The feed is deliberately bounded and only consulted for an
|
|
8
|
+
* explicitly windowed Chrome security/release query; a generic web search still
|
|
9
|
+
* uses the normal engine path.
|
|
10
|
+
*
|
|
11
|
+
* @module @fangchenghao/dsh-web-search/official-feed
|
|
12
|
+
*/
|
|
13
|
+
import type { Source, TimeRange } from './types.ts';
|
|
14
|
+
/** Chrome Releases' public Blogger feed, newest first. */
|
|
15
|
+
export declare const CHROME_RELEASES_FEED_URL = "https://chromereleases.googleblog.com/feeds/posts/default?alt=json&max-results=30";
|
|
16
|
+
/** Inputs accepted by {@link fetchChromeReleases}. */
|
|
17
|
+
export interface ChromeFeedOptions {
|
|
18
|
+
/** Tunnel URL from the plugin's `proxy` setting, when configured. */
|
|
19
|
+
proxy?: string;
|
|
20
|
+
/** Per-request deadline in milliseconds. */
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
/** Caller cancellation. */
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
/** Test seam; defaults to the platform `fetch`. */
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
/** True for a query that is specifically about a Chrome release/security post. */
|
|
28
|
+
export declare function isChromeSecurityQuery(query: string): boolean;
|
|
29
|
+
/** One severity distribution exposed by a Chrome release post. */
|
|
30
|
+
export interface ChromeSecuritySummary {
|
|
31
|
+
/** Version string found in the post, when one is stated. */
|
|
32
|
+
version?: string;
|
|
33
|
+
/** Number of fixes the post says the update contains. */
|
|
34
|
+
total?: number;
|
|
35
|
+
/** Distinct CVE rows by severity, when the post lists them. */
|
|
36
|
+
critical?: number;
|
|
37
|
+
high?: number;
|
|
38
|
+
medium?: number;
|
|
39
|
+
low?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read the version, fix count and CVE severity distribution from a post body.
|
|
43
|
+
*
|
|
44
|
+
* Chrome release posts put the useful facts below the opening paragraph, past
|
|
45
|
+
* the point where a short search snippet usually cuts off. Extracting them here
|
|
46
|
+
* keeps the snippet useful without pretending the feed is a CVE database.
|
|
47
|
+
*
|
|
48
|
+
* @param plain - the post content converted to plain text.
|
|
49
|
+
* @returns only the fields the post actually states.
|
|
50
|
+
*/
|
|
51
|
+
export declare function chromeSecuritySummary(plain: string): ChromeSecuritySummary;
|
|
52
|
+
/**
|
|
53
|
+
* Parse the Chrome Releases JSON feed.
|
|
54
|
+
*
|
|
55
|
+
* The parser is intentionally tolerant: a feed shape change (or a non-JSON
|
|
56
|
+
* maintenance page) yields an empty list instead of making the caller fail.
|
|
57
|
+
*
|
|
58
|
+
* @param payload - the feed body.
|
|
59
|
+
* @param limit - maximum posts to keep.
|
|
60
|
+
* @returns posts with their real publication timestamps, newest first.
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseChromeReleases(payload: string, limit?: number): Source[];
|
|
63
|
+
/** Release channel inferred from a Chrome Releases post title. */
|
|
64
|
+
export type ChromeChannel = 'stable' | 'beta' | 'dev' | 'other';
|
|
65
|
+
/**
|
|
66
|
+
* Classify one feed post by its title.
|
|
67
|
+
*
|
|
68
|
+
* Chrome's feed mixes Desktop, Android, iOS and ChromeOS posts in one stream.
|
|
69
|
+
* The title is the only channel marker the feed exposes consistently, so the
|
|
70
|
+
* query path uses it before handing posts to the model.
|
|
71
|
+
*
|
|
72
|
+
* @param source - one parsed feed post.
|
|
73
|
+
* @returns the channel name, or `other` for an unrecognised title.
|
|
74
|
+
*/
|
|
75
|
+
export declare function chromeChannel(source: Source): ChromeChannel;
|
|
76
|
+
/**
|
|
77
|
+
* Keep the posts that belong to the channel the query asked about.
|
|
78
|
+
*
|
|
79
|
+
* This is intentionally narrow: only an explicit Stable request changes the
|
|
80
|
+
* feed, so a general Chrome security query still sees every channel. The
|
|
81
|
+
* function is lexical and never invents a channel the title does not state.
|
|
82
|
+
*
|
|
83
|
+
* @param sources - posts inside the requested time window.
|
|
84
|
+
* @param query - the caller's query.
|
|
85
|
+
* @returns stable-only posts when the query says Stable; otherwise a copy.
|
|
86
|
+
*/
|
|
87
|
+
export declare function filterChromeChannel(sources: readonly Source[], query: string): Source[];
|
|
88
|
+
/** True when a stable-only query dropped any post, for an honest note. */
|
|
89
|
+
export declare function hasNonStableChromePosts(sources: readonly Source[], query: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Fetch and parse the latest Chrome Releases posts.
|
|
92
|
+
*
|
|
93
|
+
* @param options - proxy/deadline/cancellation seams.
|
|
94
|
+
* @returns dated posts, newest first; an empty list when the feed is malformed.
|
|
95
|
+
*/
|
|
96
|
+
export declare function fetchChromeReleases(options?: ChromeFeedOptions): Promise<Source[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Keep only posts inside the requested window.
|
|
99
|
+
* @param sources - parsed feed posts.
|
|
100
|
+
* @param range - the requested publication window.
|
|
101
|
+
* @param now - test seam for the current time.
|
|
102
|
+
* @returns posts inside the window, preserving feed order.
|
|
103
|
+
*/
|
|
104
|
+
export declare function chromeWindow(sources: readonly Source[], range: TimeRange, now?: number): Source[];
|
|
105
|
+
/**
|
|
106
|
+
* Explain what the official feed showed, including the absence of a zero-day
|
|
107
|
+
* mention. This is evidence about the feed, not an assertion that no such
|
|
108
|
+
* vulnerability exists anywhere.
|
|
109
|
+
* @param sources - feed posts inside the window.
|
|
110
|
+
* @param range - the requested window.
|
|
111
|
+
* @param query - the caller's query, used to decide whether zero-day matters.
|
|
112
|
+
* @returns one short note.
|
|
113
|
+
*/
|
|
114
|
+
export declare function chromeFeedNote(sources: readonly Source[], range: TimeRange, query: string): string;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { filterByTimeRange } from "./freshness.js";
|
|
2
|
+
import { proxyGet } from "./proxy.js";
|
|
3
|
+
import { text } from "./parsers.js";
|
|
4
|
+
/** Chrome Releases' public Blogger feed, newest first. */
|
|
5
|
+
export const CHROME_RELEASES_FEED_URL = 'https://chromereleases.googleblog.com/feeds/posts/default?alt=json&max-results=30';
|
|
6
|
+
/** Default deadline for one feed read. */
|
|
7
|
+
const DEFAULT_TIMEOUT_MS = 8_000;
|
|
8
|
+
/** Largest number of feed entries requested. */
|
|
9
|
+
const FEED_LIMIT = 30;
|
|
10
|
+
/** True for a query that is specifically about a Chrome release/security post. */
|
|
11
|
+
export function isChromeSecurityQuery(query) {
|
|
12
|
+
if (typeof query !== 'string')
|
|
13
|
+
return false;
|
|
14
|
+
const value = query.trim();
|
|
15
|
+
if (!/\b(?:chrome|chromium)\b/i.test(value))
|
|
16
|
+
return false;
|
|
17
|
+
return /(?:zero[- ]?day|0[- ]?day|security|vulnerab|漏洞|安全|安全博客|releases?|发布|公告)/i.test(value);
|
|
18
|
+
}
|
|
19
|
+
/** Read one nested string field from the Blogger JSON envelope. */
|
|
20
|
+
function nested(value, key) {
|
|
21
|
+
if (typeof value !== 'object' || value === null)
|
|
22
|
+
return '';
|
|
23
|
+
const candidate = value[key];
|
|
24
|
+
if (typeof candidate === 'string')
|
|
25
|
+
return candidate;
|
|
26
|
+
if (typeof candidate === 'object' && candidate !== null) {
|
|
27
|
+
const textValue = candidate['$t'];
|
|
28
|
+
return typeof textValue === 'string' ? textValue : '';
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
/** Find the canonical post URL, not the comment-feed URL. */
|
|
33
|
+
function postUrl(entry) {
|
|
34
|
+
const links = Array.isArray(entry['link']) ? entry['link'] : [];
|
|
35
|
+
for (const candidate of links) {
|
|
36
|
+
if (typeof candidate !== 'object' || candidate === null)
|
|
37
|
+
continue;
|
|
38
|
+
const link = candidate;
|
|
39
|
+
const href = typeof link['href'] === 'string' ? link['href'] : '';
|
|
40
|
+
if (!href.startsWith('https://'))
|
|
41
|
+
continue;
|
|
42
|
+
if (link['rel'] === 'alternate')
|
|
43
|
+
return href;
|
|
44
|
+
}
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
/** Normalize Blogger's timestamp; malformed entries are dropped. */
|
|
48
|
+
function postDate(raw) {
|
|
49
|
+
if (raw.length === 0)
|
|
50
|
+
return undefined;
|
|
51
|
+
const date = new Date(raw);
|
|
52
|
+
return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read the version, fix count and CVE severity distribution from a post body.
|
|
56
|
+
*
|
|
57
|
+
* Chrome release posts put the useful facts below the opening paragraph, past
|
|
58
|
+
* the point where a short search snippet usually cuts off. Extracting them here
|
|
59
|
+
* keeps the snippet useful without pretending the feed is a CVE database.
|
|
60
|
+
*
|
|
61
|
+
* @param plain - the post content converted to plain text.
|
|
62
|
+
* @returns only the fields the post actually states.
|
|
63
|
+
*/
|
|
64
|
+
export function chromeSecuritySummary(plain) {
|
|
65
|
+
const summary = {};
|
|
66
|
+
const version = /\b(\d{2,3}\.\d+\.\d+\.\d+(?:\/\.?\d+)?)\b/.exec(plain);
|
|
67
|
+
if (version?.[1] !== undefined)
|
|
68
|
+
summary.version = version[1];
|
|
69
|
+
const total = /(?:includes?|contains?)\s+(\d[\d,]*)\s+security\s+fix(?:es)?/i.exec(plain);
|
|
70
|
+
if (total?.[1] !== undefined) {
|
|
71
|
+
const parsed = Number.parseInt(total[1].replaceAll(',', ''), 10);
|
|
72
|
+
if (Number.isFinite(parsed))
|
|
73
|
+
summary.total = parsed;
|
|
74
|
+
}
|
|
75
|
+
const severity = new Map();
|
|
76
|
+
for (const match of plain.matchAll(/\b(Critical|High|Medium|Low)\s+CVE-\d{4}-\d+/gi)) {
|
|
77
|
+
const key = (match[1] ?? '').toLowerCase();
|
|
78
|
+
severity.set(key, (severity.get(key) ?? 0) + 1);
|
|
79
|
+
}
|
|
80
|
+
const critical = severity.get('critical');
|
|
81
|
+
const high = severity.get('high');
|
|
82
|
+
const medium = severity.get('medium');
|
|
83
|
+
const low = severity.get('low');
|
|
84
|
+
if (critical !== undefined)
|
|
85
|
+
summary.critical = critical;
|
|
86
|
+
if (high !== undefined)
|
|
87
|
+
summary.high = high;
|
|
88
|
+
if (medium !== undefined)
|
|
89
|
+
summary.medium = medium;
|
|
90
|
+
if (low !== undefined)
|
|
91
|
+
summary.low = low;
|
|
92
|
+
return summary;
|
|
93
|
+
}
|
|
94
|
+
/** Build a compact snippet that puts the release facts before the prose. */
|
|
95
|
+
function chromeSnippet(plain) {
|
|
96
|
+
const summary = chromeSecuritySummary(plain);
|
|
97
|
+
const facts = [];
|
|
98
|
+
if (summary.version !== undefined)
|
|
99
|
+
facts.push(`version ${summary.version}`);
|
|
100
|
+
if (summary.total !== undefined)
|
|
101
|
+
facts.push(`${summary.total} security fix(es)`);
|
|
102
|
+
const severity = [
|
|
103
|
+
summary.critical === undefined ? undefined : `Critical ${summary.critical}`,
|
|
104
|
+
summary.high === undefined ? undefined : `High ${summary.high}`,
|
|
105
|
+
summary.medium === undefined ? undefined : `Medium ${summary.medium}`,
|
|
106
|
+
summary.low === undefined ? undefined : `Low ${summary.low}`,
|
|
107
|
+
].filter((part) => part !== undefined);
|
|
108
|
+
if (severity.length > 0)
|
|
109
|
+
facts.push(`listed severity: ${severity.join(' / ')}`);
|
|
110
|
+
const prefix = facts.length === 0 ? '' : `${facts.join('; ')}. `;
|
|
111
|
+
const body = plain.length > Math.max(200, 400 - prefix.length)
|
|
112
|
+
? `${plain.slice(0, Math.max(200, 400 - prefix.length)).trimEnd()}…`
|
|
113
|
+
: plain;
|
|
114
|
+
return `${prefix}${body}`.trim();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse the Chrome Releases JSON feed.
|
|
118
|
+
*
|
|
119
|
+
* The parser is intentionally tolerant: a feed shape change (or a non-JSON
|
|
120
|
+
* maintenance page) yields an empty list instead of making the caller fail.
|
|
121
|
+
*
|
|
122
|
+
* @param payload - the feed body.
|
|
123
|
+
* @param limit - maximum posts to keep.
|
|
124
|
+
* @returns posts with their real publication timestamps, newest first.
|
|
125
|
+
*/
|
|
126
|
+
export function parseChromeReleases(payload, limit = FEED_LIMIT) {
|
|
127
|
+
if (typeof payload !== 'string' || payload.trim().length === 0)
|
|
128
|
+
return [];
|
|
129
|
+
let body;
|
|
130
|
+
try {
|
|
131
|
+
body = JSON.parse(payload);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
const feed = typeof body === 'object' && body !== null
|
|
137
|
+
? body['feed']
|
|
138
|
+
: undefined;
|
|
139
|
+
const entries = typeof feed === 'object' && feed !== null
|
|
140
|
+
? feed['entry']
|
|
141
|
+
: undefined;
|
|
142
|
+
if (!Array.isArray(entries))
|
|
143
|
+
return [];
|
|
144
|
+
const sources = [];
|
|
145
|
+
for (const raw of entries) {
|
|
146
|
+
if (typeof raw !== 'object' || raw === null)
|
|
147
|
+
continue;
|
|
148
|
+
const entry = raw;
|
|
149
|
+
const url = postUrl(entry);
|
|
150
|
+
if (url.length === 0)
|
|
151
|
+
continue;
|
|
152
|
+
const title = text(nested(entry['title'], '$t')).trim();
|
|
153
|
+
const content = nested(entry['content'], '$t') || nested(entry['summary'], '$t');
|
|
154
|
+
const plain = text(content).replace(/\s+/gu, ' ').trim();
|
|
155
|
+
const snippet = chromeSnippet(plain);
|
|
156
|
+
const publishedAt = postDate(nested(entry['published'], '$t'));
|
|
157
|
+
if (title.length === 0 && snippet.length === 0)
|
|
158
|
+
continue;
|
|
159
|
+
sources.push({
|
|
160
|
+
url,
|
|
161
|
+
...(title.length > 0 ? { title } : {}),
|
|
162
|
+
...(snippet.length > 0 ? { snippet: snippet.length > 400 ? `${snippet.slice(0, 400).trimEnd()}…` : snippet } : {}),
|
|
163
|
+
...(publishedAt === undefined ? {} : { publishedAt }),
|
|
164
|
+
});
|
|
165
|
+
if (sources.length >= Math.max(1, Math.min(FEED_LIMIT, limit)))
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
return sources;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Classify one feed post by its title.
|
|
172
|
+
*
|
|
173
|
+
* Chrome's feed mixes Desktop, Android, iOS and ChromeOS posts in one stream.
|
|
174
|
+
* The title is the only channel marker the feed exposes consistently, so the
|
|
175
|
+
* query path uses it before handing posts to the model.
|
|
176
|
+
*
|
|
177
|
+
* @param source - one parsed feed post.
|
|
178
|
+
* @returns the channel name, or `other` for an unrecognised title.
|
|
179
|
+
*/
|
|
180
|
+
export function chromeChannel(source) {
|
|
181
|
+
const title = (source.title ?? '').toLowerCase();
|
|
182
|
+
if (title.length === 0)
|
|
183
|
+
return 'other';
|
|
184
|
+
if (/\b(?:dev|canary)\b|developer channel/.test(title))
|
|
185
|
+
return 'dev';
|
|
186
|
+
if (/\bbeta\b/.test(title))
|
|
187
|
+
return 'beta';
|
|
188
|
+
// "Early" and "Extended" Stable are separate rollout/maintenance channels,
|
|
189
|
+
// not the Stable channel the user asked about.
|
|
190
|
+
if (/early stable|extended stable/.test(title))
|
|
191
|
+
return 'other';
|
|
192
|
+
if (/\bstable\b|chrome for (?:android|ios) update|chromeos/.test(title))
|
|
193
|
+
return 'stable';
|
|
194
|
+
return 'other';
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Keep the posts that belong to the channel the query asked about.
|
|
198
|
+
*
|
|
199
|
+
* This is intentionally narrow: only an explicit Stable request changes the
|
|
200
|
+
* feed, so a general Chrome security query still sees every channel. The
|
|
201
|
+
* function is lexical and never invents a channel the title does not state.
|
|
202
|
+
*
|
|
203
|
+
* @param sources - posts inside the requested time window.
|
|
204
|
+
* @param query - the caller's query.
|
|
205
|
+
* @returns stable-only posts when the query says Stable; otherwise a copy.
|
|
206
|
+
*/
|
|
207
|
+
export function filterChromeChannel(sources, query) {
|
|
208
|
+
if (!/\bstable\b|稳定版|稳定渠道/i.test(query))
|
|
209
|
+
return [...sources];
|
|
210
|
+
return sources.filter((source) => chromeChannel(source) === 'stable');
|
|
211
|
+
}
|
|
212
|
+
/** True when a stable-only query dropped any post, for an honest note. */
|
|
213
|
+
export function hasNonStableChromePosts(sources, query) {
|
|
214
|
+
return /\bstable\b|稳定版|稳定渠道/i.test(query)
|
|
215
|
+
&& sources.some((source) => chromeChannel(source) !== 'stable');
|
|
216
|
+
}
|
|
217
|
+
/** Read the feed directly or through the configured HTTP tunnel. */
|
|
218
|
+
async function readFeed(options) {
|
|
219
|
+
const timeoutMs = typeof options.timeoutMs === 'number' && Number.isFinite(options.timeoutMs) && options.timeoutMs > 0
|
|
220
|
+
? Math.min(15_000, Math.max(1_000, Math.floor(options.timeoutMs)))
|
|
221
|
+
: DEFAULT_TIMEOUT_MS;
|
|
222
|
+
const headers = {
|
|
223
|
+
accept: 'application/json',
|
|
224
|
+
'user-agent': 'dsh-web-search/0.20 (+https://github.com/fangchenghao/dsh-web-search)',
|
|
225
|
+
};
|
|
226
|
+
if (options.proxy !== undefined && options.proxy.trim().length > 0) {
|
|
227
|
+
const response = await proxyGet(CHROME_RELEASES_FEED_URL, {
|
|
228
|
+
proxy: options.proxy,
|
|
229
|
+
headers,
|
|
230
|
+
timeoutMs,
|
|
231
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
232
|
+
});
|
|
233
|
+
if (response.status < 200 || response.status >= 300) {
|
|
234
|
+
throw new Error(`Chrome Releases feed returned HTTP ${response.status}`);
|
|
235
|
+
}
|
|
236
|
+
return response.text;
|
|
237
|
+
}
|
|
238
|
+
const timer = AbortSignal.timeout(timeoutMs);
|
|
239
|
+
const signal = options.signal === undefined ? timer : AbortSignal.any([options.signal, timer]);
|
|
240
|
+
const doFetch = options.fetch ?? fetch;
|
|
241
|
+
const response = await doFetch(CHROME_RELEASES_FEED_URL, { signal, headers });
|
|
242
|
+
if (!response.ok)
|
|
243
|
+
throw new Error(`Chrome Releases feed returned HTTP ${response.status}`);
|
|
244
|
+
return response.text();
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Fetch and parse the latest Chrome Releases posts.
|
|
248
|
+
*
|
|
249
|
+
* @param options - proxy/deadline/cancellation seams.
|
|
250
|
+
* @returns dated posts, newest first; an empty list when the feed is malformed.
|
|
251
|
+
*/
|
|
252
|
+
export async function fetchChromeReleases(options = {}) {
|
|
253
|
+
return parseChromeReleases(await readFeed(options));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Keep only posts inside the requested window.
|
|
257
|
+
* @param sources - parsed feed posts.
|
|
258
|
+
* @param range - the requested publication window.
|
|
259
|
+
* @param now - test seam for the current time.
|
|
260
|
+
* @returns posts inside the window, preserving feed order.
|
|
261
|
+
*/
|
|
262
|
+
export function chromeWindow(sources, range, now = Date.now()) {
|
|
263
|
+
if (range === 'off')
|
|
264
|
+
return [...sources];
|
|
265
|
+
return filterByTimeRange(sources, range, now);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Explain what the official feed showed, including the absence of a zero-day
|
|
269
|
+
* mention. This is evidence about the feed, not an assertion that no such
|
|
270
|
+
* vulnerability exists anywhere.
|
|
271
|
+
* @param sources - feed posts inside the window.
|
|
272
|
+
* @param range - the requested window.
|
|
273
|
+
* @param query - the caller's query, used to decide whether zero-day matters.
|
|
274
|
+
* @returns one short note.
|
|
275
|
+
*/
|
|
276
|
+
export function chromeFeedNote(sources, range, query) {
|
|
277
|
+
const window = range === 'off' ? 'latest' : range;
|
|
278
|
+
if (!/zero[- ]?day|0[- ]?day|零日/iu.test(query)) {
|
|
279
|
+
return `Official Chrome Releases feed: ${sources.length} post(s) in the ${window} result set, each with a publication date.`;
|
|
280
|
+
}
|
|
281
|
+
const zeroDay = sources.filter((source) => /zero[- ]?day|0[- ]?day|零日/iu.test(`${source.title ?? ''} ${source.snippet ?? ''}`)).length;
|
|
282
|
+
if (sources.length === 0) {
|
|
283
|
+
return `Official Chrome Releases feed checked: no post fell inside the ${window} window.`;
|
|
284
|
+
}
|
|
285
|
+
return zeroDay === 0
|
|
286
|
+
? `Official Chrome Releases feed checked: ${sources.length} post(s) inside the ${window} window; no title or summary mentions zero-day.`
|
|
287
|
+
: `Official Chrome Releases feed checked: ${sources.length} post(s) inside the ${window} window; ${zeroDay} mention zero-day.`;
|
|
288
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official, key-free release facts that ordinary search results often miss.
|
|
3
|
+
*
|
|
4
|
+
* PostgreSQL's versioning page is the first entry: it is the authoritative
|
|
5
|
+
* source for the current major, current minor and final-support date, while a
|
|
6
|
+
* generic web query frequently returns cloud-provider EOL pages or an old
|
|
7
|
+
* press kit. The lookup is deliberately narrow: only a PostgreSQL query that
|
|
8
|
+
* asks about versions, support or EOL is enriched, so an ordinary PostgreSQL
|
|
9
|
+
* how-to search keeps the normal engine ranking.
|
|
10
|
+
*
|
|
11
|
+
* @module @fangchenghao/dsh-web-search/official-support
|
|
12
|
+
*/
|
|
13
|
+
import type { Source } from './types.ts';
|
|
14
|
+
/** PostgreSQL's official versioning and support table. */
|
|
15
|
+
export declare const POSTGRES_SUPPORT_URL = "https://www.postgresql.org/support/versioning/";
|
|
16
|
+
/** One major release row from the official table. */
|
|
17
|
+
export interface PostgresRelease {
|
|
18
|
+
/** Major version, e.g. `18` or `9.6`. */
|
|
19
|
+
major: string;
|
|
20
|
+
/** Current minor release, e.g. `18.6`. */
|
|
21
|
+
minor: string;
|
|
22
|
+
/** Whether the PostgreSQL project still supports this major. */
|
|
23
|
+
supported: boolean;
|
|
24
|
+
/** First release date as printed by the page. */
|
|
25
|
+
firstRelease: string;
|
|
26
|
+
/** Final release date as printed by the page. */
|
|
27
|
+
finalRelease: string;
|
|
28
|
+
}
|
|
29
|
+
/** Inputs accepted by {@link fetchPostgresSupport}. */
|
|
30
|
+
export interface PostgresSupportOptions {
|
|
31
|
+
/** Tunnel URL from the plugin's `proxy` setting, when configured. */
|
|
32
|
+
proxy?: string;
|
|
33
|
+
/** Per-request deadline in milliseconds. */
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
/** Caller cancellation. */
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
/** Test seam; defaults to the platform `fetch`. */
|
|
38
|
+
fetch?: typeof fetch;
|
|
39
|
+
}
|
|
40
|
+
/** True for a PostgreSQL query that is asking about versions/support/EOL. */
|
|
41
|
+
export declare function isPostgresVersionQuery(query: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Parse the official versioning table.
|
|
44
|
+
*
|
|
45
|
+
* The parser intentionally ignores the surrounding navigation and prose, and
|
|
46
|
+
* returns only rows with five cells. A markup change yields an empty list so
|
|
47
|
+
* the caller can fall back to ordinary search instead of returning a made-up
|
|
48
|
+
* version.
|
|
49
|
+
*
|
|
50
|
+
* @param payload - the support page HTML.
|
|
51
|
+
* @returns release rows, highest major first.
|
|
52
|
+
*/
|
|
53
|
+
export declare function parsePostgresSupport(payload: string): PostgresRelease[];
|
|
54
|
+
/**
|
|
55
|
+
* Build one model-facing source from the parsed table.
|
|
56
|
+
*
|
|
57
|
+
* The EOL field is the page's "Final Release" column. It is labeled as the
|
|
58
|
+
* official final release/EOL date rather than as a promise about the exact
|
|
59
|
+
* day a deployment stops receiving fixes.
|
|
60
|
+
*
|
|
61
|
+
* @param releases - parsed rows.
|
|
62
|
+
* @returns a source, or `undefined` when no usable row exists.
|
|
63
|
+
*/
|
|
64
|
+
export declare function postgresSupportSource(releases: readonly PostgresRelease[]): Source | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Fetch and parse the official PostgreSQL support source.
|
|
67
|
+
*
|
|
68
|
+
* Failure is contained: a blocked page, a timeout or markup drift returns
|
|
69
|
+
* `undefined` and the caller keeps its ordinary search rows.
|
|
70
|
+
*
|
|
71
|
+
* @param options - proxy, deadline, cancellation and fetch seam.
|
|
72
|
+
* @returns the official source, or `undefined`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function fetchPostgresSupport(options?: PostgresSupportOptions): Promise<Source | undefined>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { proxyGet } from "./proxy.js";
|
|
2
|
+
import { text } from "./parsers.js";
|
|
3
|
+
/** PostgreSQL's official versioning and support table. */
|
|
4
|
+
export const POSTGRES_SUPPORT_URL = 'https://www.postgresql.org/support/versioning/';
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 8_000;
|
|
6
|
+
/** True for a PostgreSQL query that is asking about versions/support/EOL. */
|
|
7
|
+
export function isPostgresVersionQuery(query) {
|
|
8
|
+
if (typeof query !== 'string')
|
|
9
|
+
return false;
|
|
10
|
+
const value = query.trim();
|
|
11
|
+
if (!/\bpostgres(?:ql)?\b/iu.test(value))
|
|
12
|
+
return false;
|
|
13
|
+
return /(?:eol|end[- ]of[- ]life|support(?:ed)?|version|latest|current|release|大版本|最新|版本|支持|结束|生命周期|过期|停止维护)/iu.test(value);
|
|
14
|
+
}
|
|
15
|
+
/** Read one table cell as plain text. */
|
|
16
|
+
function cellText(html) {
|
|
17
|
+
return text(html).replace(/\s+/gu, ' ').trim();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse the official versioning table.
|
|
21
|
+
*
|
|
22
|
+
* The parser intentionally ignores the surrounding navigation and prose, and
|
|
23
|
+
* returns only rows with five cells. A markup change yields an empty list so
|
|
24
|
+
* the caller can fall back to ordinary search instead of returning a made-up
|
|
25
|
+
* version.
|
|
26
|
+
*
|
|
27
|
+
* @param payload - the support page HTML.
|
|
28
|
+
* @returns release rows, highest major first.
|
|
29
|
+
*/
|
|
30
|
+
export function parsePostgresSupport(payload) {
|
|
31
|
+
if (typeof payload !== 'string' || payload.trim().length === 0)
|
|
32
|
+
return [];
|
|
33
|
+
const rows = [];
|
|
34
|
+
for (const match of payload.matchAll(/<tr\b[^>]*>([\s\S]*?)<\/tr>/giu)) {
|
|
35
|
+
const body = match[1] ?? '';
|
|
36
|
+
const cells = [...body.matchAll(/<td\b[^>]*>([\s\S]*?)<\/td>/giu)].map((cell) => cellText(cell[1] ?? ''));
|
|
37
|
+
if (cells.length < 5)
|
|
38
|
+
continue;
|
|
39
|
+
const [major = '', minor = '', supported = '', firstRelease = '', finalRelease = ''] = cells;
|
|
40
|
+
if (!/^\d+(?:\.\d+)?$/u.test(major))
|
|
41
|
+
continue;
|
|
42
|
+
rows.push({
|
|
43
|
+
major,
|
|
44
|
+
minor,
|
|
45
|
+
supported: /^yes\b/iu.test(supported),
|
|
46
|
+
firstRelease,
|
|
47
|
+
finalRelease,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
rows.sort((left, right) => Number.parseFloat(right.major) - Number.parseFloat(left.major));
|
|
51
|
+
return rows;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build one model-facing source from the parsed table.
|
|
55
|
+
*
|
|
56
|
+
* The EOL field is the page's "Final Release" column. It is labeled as the
|
|
57
|
+
* official final release/EOL date rather than as a promise about the exact
|
|
58
|
+
* day a deployment stops receiving fixes.
|
|
59
|
+
*
|
|
60
|
+
* @param releases - parsed rows.
|
|
61
|
+
* @returns a source, or `undefined` when no usable row exists.
|
|
62
|
+
*/
|
|
63
|
+
export function postgresSupportSource(releases) {
|
|
64
|
+
const latest = releases.find((release) => release.supported) ?? releases[0];
|
|
65
|
+
if (latest === undefined)
|
|
66
|
+
return undefined;
|
|
67
|
+
const status = latest.supported ? 'supported' : 'not supported';
|
|
68
|
+
return {
|
|
69
|
+
url: POSTGRES_SUPPORT_URL,
|
|
70
|
+
title: `PostgreSQL versioning policy: major ${latest.major} (${latest.minor}), ${status}`,
|
|
71
|
+
snippet: `Official PostgreSQL versioning policy: latest major ${latest.major}; current minor ${latest.minor}; ` +
|
|
72
|
+
`status ${status}; first release ${latest.firstRelease || 'not stated'}; ` +
|
|
73
|
+
`final release (EOL) ${latest.finalRelease || 'not stated'}.`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Read the page over the configured tunnel, or directly when none is set. */
|
|
77
|
+
async function fetchText(url, options, timeoutMs) {
|
|
78
|
+
if (options.proxy !== undefined && options.proxy.length > 0) {
|
|
79
|
+
const response = await proxyGet(url, {
|
|
80
|
+
proxy: options.proxy,
|
|
81
|
+
timeoutMs,
|
|
82
|
+
headers: {
|
|
83
|
+
'user-agent': 'Mozilla/5.0 (compatible; dsh-web-search/0.20; +https://github.com/fangchenghao/dsh-web-search)',
|
|
84
|
+
accept: 'text/html,application/xhtml+xml',
|
|
85
|
+
},
|
|
86
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
87
|
+
});
|
|
88
|
+
if (response.status < 200 || response.status >= 300)
|
|
89
|
+
throw new Error(`HTTP ${response.status}`);
|
|
90
|
+
return response.text;
|
|
91
|
+
}
|
|
92
|
+
const controller = new AbortController();
|
|
93
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
94
|
+
const abort = () => controller.abort();
|
|
95
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
96
|
+
try {
|
|
97
|
+
const send = options.fetch ?? fetch;
|
|
98
|
+
const response = await send(url, {
|
|
99
|
+
headers: {
|
|
100
|
+
'user-agent': 'Mozilla/5.0 (compatible; dsh-web-search/0.20; +https://github.com/fangchenghao/dsh-web-search)',
|
|
101
|
+
accept: 'text/html,application/xhtml+xml',
|
|
102
|
+
},
|
|
103
|
+
signal: controller.signal,
|
|
104
|
+
});
|
|
105
|
+
if (!response.ok)
|
|
106
|
+
throw new Error(`HTTP ${response.status}`);
|
|
107
|
+
return await response.text();
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
clearTimeout(timer);
|
|
111
|
+
options.signal?.removeEventListener('abort', abort);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Fetch and parse the official PostgreSQL support source.
|
|
116
|
+
*
|
|
117
|
+
* Failure is contained: a blocked page, a timeout or markup drift returns
|
|
118
|
+
* `undefined` and the caller keeps its ordinary search rows.
|
|
119
|
+
*
|
|
120
|
+
* @param options - proxy, deadline, cancellation and fetch seam.
|
|
121
|
+
* @returns the official source, or `undefined`.
|
|
122
|
+
*/
|
|
123
|
+
export async function fetchPostgresSupport(options = {}) {
|
|
124
|
+
const timeoutMs = typeof options.timeoutMs === 'number' && Number.isFinite(options.timeoutMs) && options.timeoutMs > 0
|
|
125
|
+
? options.timeoutMs
|
|
126
|
+
: DEFAULT_TIMEOUT_MS;
|
|
127
|
+
try {
|
|
128
|
+
const payload = await fetchText(POSTGRES_SUPPORT_URL, options, Math.min(timeoutMs, DEFAULT_TIMEOUT_MS));
|
|
129
|
+
return postgresSupportSource(parsePostgresSupport(payload));
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|