@fffangchenghao/dsh-web-search 0.24.4 → 0.24.6
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 +37 -0
- package/README.md +5 -5
- package/README.zh-CN.md +4 -4
- package/client.js +1 -1
- package/docs/comparison.md +1 -1
- package/docs/images/web-tools-demo.svg +1 -1
- package/docs/latency-and-sources.md +1 -1
- package/docs/store-evidence.md +1 -1
- package/lib/domain-tool.d.ts +2 -0
- package/lib/domain-tool.js +7 -1
- package/lib/engine-test.js +16 -2
- package/lib/engines.js +11 -1
- package/lib/index.js +9 -4
- package/lib/platform-tool.d.ts +1 -0
- package/lib/platform-tool.js +7 -1
- package/lib/render.js +117 -22
- package/lib/search-many.js +16 -2
- package/lib/tool-suite.d.ts +2 -0
- package/lib/tool-suite.js +14 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.24.6
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **A pre-aborted search no longer resolves a proxy or starts an engine.** The
|
|
7
|
+
public `search()` entry checks the caller signal before `resolveProxy()`, and
|
|
8
|
+
`runTier()` repeats the guard so a cancellation arriving at the tier boundary
|
|
9
|
+
cannot dispatch a request. The regression test stubs `fetch` and asserts it is
|
|
10
|
+
never called.
|
|
11
|
+
|
|
12
|
+
**Test suite: 718 tests across 56 files** (717 pass, 1 skipped).
|
|
13
|
+
|
|
14
|
+
## 0.24.5
|
|
15
|
+
|
|
16
|
+
Completed the delayed GPT-6-astra `xhigh` audit batch: tool registration,
|
|
17
|
+
rendering, advanced/search_many/engine_test, domain and platform tools.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- **`web_tools` ignored `limit` for `advanced_search`.** The unified dispatcher
|
|
21
|
+
now maps `limit` to `maxResults` when `maxResults` is absent; an explicit
|
|
22
|
+
`maxResults` still wins. Its own parser still validates the range.
|
|
23
|
+
- **Tool disposers were dropped by three registrars.** `registerUnifiedTool`,
|
|
24
|
+
`registerDomainTool` and `registerPlatformTool` now forward the host's
|
|
25
|
+
`tools.register()` disposer through an optional `onRegister` callback, and
|
|
26
|
+
legacy fallback registrations are wired into `onDispose` too.
|
|
27
|
+
- **`readableTextLength` was quadratic on repeated unclosed raw-text tags.**
|
|
28
|
+
The regex chain is replaced with a single forward scanner; repeated unclosed
|
|
29
|
+
`<head>`/`<script>` now stops at the end instead of rescanning the suffix.
|
|
30
|
+
- **Render cancellation covered only browser launch.** `renderWithPlaywright`
|
|
31
|
+
now has one total deadline covering launch, `newPage`, navigation, idle wait
|
|
32
|
+
and `content`; every phase races an abort signal, late handles are closed,
|
|
33
|
+
and page/browser cleanup runs concurrently with a short cap.
|
|
34
|
+
- **Batch tools swallowed cancellation.** `search_many` and `engine_test` now
|
|
35
|
+
reject on a caller abort, stop pulling queued work, and never start a
|
|
36
|
+
pre-aborted batch.
|
|
37
|
+
|
|
38
|
+
**Test suite: 717 tests across 56 files** (716 pass, 1 skipped).
|
|
39
|
+
|
|
3
40
|
## 0.24.4
|
|
4
41
|
|
|
5
42
|
Second independent audit, this time with `Vendor2/GPT-6-astra` at reasoning
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
12
|
<a href="https://www.npmjs.com/package/@fffangchenghao/dsh-web-search"><img src="https://img.shields.io/npm/v/@fffangchenghao/dsh-web-search.svg" alt="npm version"></a>
|
|
13
|
-
<img src="https://img.shields.io/badge/tests-
|
|
13
|
+
<img src="https://img.shields.io/badge/tests-718%20tests-brightgreen" alt="tests">
|
|
14
14
|
<img src="https://img.shields.io/badge/engines-8%2C%20zero%20API%20key-brightgreen" alt="engines">
|
|
15
15
|
<img src="https://img.shields.io/badge/node-%3E%3D22.18-blue" alt="node">
|
|
16
16
|
<img src="https://img.shields.io/badge/dsh-%3E%3D0.2.1--rc.2%20%3C0.3.0-blueviolet" alt="dsh">
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
- **Measured in public, including the losses.** A 30-query bilingual comparison records availability, latency, unique domains, official-domain presence and every failure against keyless Firecrawl and anonymous Exa. The follow-up documents the Exa architecture difference, the 3 s CJK budget and the Rust official-source lookup. Exa is faster here; this plugin returns more distinct domains. Both test arms were keyless. The method and raw results are in [docs/comparison.md](docs/comparison.md) and a [public gist](https://gist.github.com/fangchenghao/3db9838fa98928435c1c2df38202c373).
|
|
29
29
|
- **Fetching admits failure.** Binary documents and empty 200 responses are rejected by name (`SEARCH_UNSUPPORTED`, `SEARCH_EMPTY`) instead of being returned as noise; arXiv PDF links are the deliberate exception and are read through the HTML full-text view; the direct → tunnel → render → extract ladder shares one 25 s budget and stops when there is no time left. The budget is per request — there is a regression test for exactly that.
|
|
30
30
|
- **Windows is a first-class host.** Pure ESM, no native addon or install script; the system proxy is discovered from Windows Internet Settings, and the full suite runs on a `windows-latest` CI runner. See [Install on Windows](#windows).
|
|
31
|
-
- **
|
|
31
|
+
- **718 tests across 56 files**, a committed `lib/`, declared `engines.dsh` / `engines.node`, and a [SECURITY.md](SECURITY.md) that lists every process, host and file the plugin touches.
|
|
32
32
|
- **Bilingual documentation.** This README and [中文说明](README.zh-CN.md) are maintained side by side.
|
|
33
33
|
|
|
34
34
|

|
|
@@ -45,7 +45,7 @@ The web-search corner of the DSH plugin ecosystem is crowded. A dated snapshot
|
|
|
45
45
|
| Key-free path | 8 engines, all key-free | ~30-engine free/paid chain | 5 defaults (seam, Exa, DDG, Bing, Jina) | Firecrawl + Keenable keyless defaults | 1 anonymous AnySearch API |
|
|
46
46
|
| Dedicated vertical sources | 34 (8 on by default) | 41 | platform registry, not a vertical catalog | web + X, no vertical catalog | vertical API behind AnySearch |
|
|
47
47
|
| Model-facing tools | 1 (`web_tools`, 8 actions) + 4 MCP tools | ~10 | 2 (`web_index` / `web_call`, 20 actions) | native search/fetch + skill | 5 |
|
|
48
|
-
| Tests | 56 files /
|
|
48
|
+
| Tests | 56 files / 718 cases, locally verified | no test script in `package.json` | 774 unit + 94 bench, self-reported | Vitest configured; count not published | Vitest configured; count not published |
|
|
49
49
|
| GitHub stars | 0 | 620 | 77 | 836 | 663 |
|
|
50
50
|
| npm downloads, last month | 1,087 | 52,436 | 6,420 | 43,151 | 9,251 |
|
|
51
51
|
| npm unpacked size | 1.2 MB | 0.70 MB | 3.05 MB | 0.51 MB | 0.27 MB |
|
|
@@ -56,7 +56,7 @@ read is:
|
|
|
56
56
|
- **Feature depth:** upper-middle. `dsh-free-search` has more engines and
|
|
57
57
|
verticals; `dsh-web-search-pro` has a deeper evidence/ranking pipeline and far
|
|
58
58
|
more platform backends; `modsearch` is the stronger cross-host bridge.
|
|
59
|
-
- **Engineering and verification:** near the top.
|
|
59
|
+
- **Engineering and verification:** near the top. 718 local tests, a replayable
|
|
60
60
|
ranking benchmark, declared security boundaries and one runtime dependency
|
|
61
61
|
put it alongside the best-maintained entries, while remaining much smaller
|
|
62
62
|
than the Playwright-heavy option.
|
|
@@ -65,7 +65,7 @@ read is:
|
|
|
65
65
|
common in the other plugins.
|
|
66
66
|
- **Adoption and maturity:** bottom third of this sample. At the 2026-10-25
|
|
67
67
|
snapshot the repository was four days old, had no stars and little
|
|
68
|
-
independent adoption; the current npm release is 0.24.
|
|
68
|
+
independent adoption; the current npm release is 0.24.6.
|
|
69
69
|
- **Tool-surface economy:** now competitive. 0.20.x exposes one `web_tools`
|
|
70
70
|
entry with eight actions, close to `dsh-web-search-pro`'s two tools with 20
|
|
71
71
|
actions; the legacy eight-name surface remains opt-in for old prompts.
|
package/README.zh-CN.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
11
|
<a href="https://www.npmjs.com/package/@fffangchenghao/dsh-web-search"><img src="https://img.shields.io/npm/v/@fffangchenghao/dsh-web-search.svg" alt="npm 版本"></a>
|
|
12
|
-
<img src="https://img.shields.io/badge/tests-
|
|
12
|
+
<img src="https://img.shields.io/badge/tests-718%20tests-brightgreen" alt="测试">
|
|
13
13
|
<img src="https://img.shields.io/badge/engines-8%2C%20zero%20API%20key-brightgreen" alt="引擎">
|
|
14
14
|
<img src="https://img.shields.io/badge/node-%3E%3D22.18-blue" alt="node">
|
|
15
15
|
<img src="https://img.shields.io/badge/dsh-%3E%3D0.2.1--rc.2%20%3C0.3.0-blueviolet" alt="dsh">
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
- **公开测量,也公开输的地方。** 30 条中英查询对比记录可用性、延迟、独立域名、官方域名命中与每一条失败;对比对象是免 key Firecrawl 和匿名 Exa。这里 Exa 更快,本插件返回的独立域名更多;两条对比路径都未使用 key。方法和原始结果在 [docs/comparison.md](docs/comparison.md);Exa 架构差异、中文 3 秒预算和 Rust 官方源见 [延迟与官方源](docs/latency-and-sources.md)。
|
|
28
28
|
- **抓取会承认失败。** 二进制文档和「200 但正文为空」会被明确拒绝(`SEARCH_UNSUPPORTED`、`SEARCH_EMPTY`),而不是当噪音返回;arXiv 的 PDF 链接是有意保留的例外,会改读 HTML 全文;direct → tunnel → render → extract 四级阶梯共享 25 秒预算,预算不足就不再起新的一级。预算是「每次请求」而不是「插件启动时」,这点有回归测试守着。
|
|
29
29
|
- **Windows 是一等宿主。** 纯 ESM,没有原生扩展或安装脚本;会自动读取 Windows 的 Internet 设置代理,完整测试套件也在 `windows-latest` CI 上跑通。安装见[Windows 小节](#windows)。
|
|
30
|
-
- **56 个测试文件、
|
|
30
|
+
- **56 个测试文件、718 个用例**,`lib/` 产物入库,声明了 `engines.dsh` / `engines.node`,[SECURITY.md](SECURITY.md) 逐项列出插件会碰的进程、主机和文件。
|
|
31
31
|
- **双语文档。** 本文件和 [English README](README.md) 同步维护。
|
|
32
32
|
|
|
33
33
|

|
|
@@ -54,11 +54,11 @@ DSH 插件生态里的「联网搜索」已经很挤。下面是一张 2026-10-2
|
|
|
54
54
|
- **功能深度:中上。** `dsh-free-search` 引擎和垂直源更多;
|
|
55
55
|
`dsh-web-search-pro` 的证据/排序管线和平台后端更深;`modsearch` 的跨宿主
|
|
56
56
|
能力更强。
|
|
57
|
-
- **工程质量与可验证性:接近第一梯队。**
|
|
57
|
+
- **工程质量与可验证性:接近第一梯队。** 718 个本地测试、可重放的排序基准、
|
|
58
58
|
明确的安全边界、只有 1 个运行时依赖,同时体积远小于 Playwright 重型方案。
|
|
59
59
|
- **免 key + 官方源纠错:最强卖点。** Chrome、PostgreSQL、AI Act 的官方路径
|
|
60
60
|
和 34 个垂直源,不是其他插件普遍具备的。
|
|
61
|
-
- **采用度与成熟度:这个样本里的后段。** 2026-10-25 快照时 GitHub 仓库刚创建 4 天、0 stars,还缺少独立采用;当前 npm 版本是 0.24.
|
|
61
|
+
- **采用度与成熟度:这个样本里的后段。** 2026-10-25 快照时 GitHub 仓库刚创建 4 天、0 stars,还缺少独立采用;当前 npm 版本是 0.24.6。
|
|
62
62
|
- **工具面的经济性:现在有竞争力。** 0.20.x 只暴露一个 `web_tools` + 8 个
|
|
63
63
|
action,接近 `dsh-web-search-pro` 的 2 工具 + 20 动作;旧的八个工具名保留为
|
|
64
64
|
可选兼容模式。
|
package/client.js
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
var ENTRY = 'web-search-bing';
|
|
75
75
|
var PACKAGE_NAME = 'dsh-web-search-bing';
|
|
76
76
|
/** Keep in step with package.json; compared with the npm registry. */
|
|
77
|
-
var VERSION = '0.24.
|
|
77
|
+
var VERSION = '0.24.6';
|
|
78
78
|
/** Snapshot used while no configuration service is reachable. */
|
|
79
79
|
var EMPTY_STATE = { status: 'unavailable', value: undefined, base: undefined, user: undefined, revision: undefined, writable: false };
|
|
80
80
|
|
package/docs/comparison.md
CHANGED
|
@@ -6,7 +6,7 @@ whether a provider answers at all, how long it takes, how many distinct domains
|
|
|
6
6
|
it returns, and whether a page on a known official domain appears in the top 8.
|
|
7
7
|
The failures are part of the result.
|
|
8
8
|
|
|
9
|
-
> **Version note (2026-11-02):** 0.24.0 added Windows system-proxy discovery, and 0.24.1 and 0.24.2 are documentation/metadata patches; 0.24.3
|
|
9
|
+
> **Version note (2026-11-02):** 0.24.0 added Windows system-proxy discovery, and 0.24.1 and 0.24.2 are documentation/metadata patches; 0.24.3–0.24.6 fix fetch/proxy/markdown/cache/tool reliability without changing the measured search path. These patches do not change the search, ranking or source-adapter path measured below, so the 0.23.0 numbers remain the latest comparison.
|
|
10
10
|
|
|
11
11
|
## Method
|
|
12
12
|
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
<rect x="70" y="620" width="330" height="76" rx="14" fill="#101d31" stroke="#26364f"/>
|
|
53
53
|
<text x="92" y="651" class="m" font-size="13">Engines</text><text x="92" y="677" class="t" font-size="20" font-weight="700">8 key-free paths</text>
|
|
54
54
|
<rect x="420" y="620" width="330" height="76" rx="14" fill="#101d31" stroke="#26364f"/>
|
|
55
|
-
<text x="442" y="651" class="m" font-size="13">Tests</text><text x="442" y="677" class="t" font-size="20" font-weight="700">
|
|
55
|
+
<text x="442" y="651" class="m" font-size="13">Tests</text><text x="442" y="677" class="t" font-size="20" font-weight="700">718 local cases</text>
|
|
56
56
|
<rect x="770" y="620" width="360" height="76" rx="14" fill="#101d31" stroke="#26364f"/>
|
|
57
57
|
<text x="792" y="651" class="m" font-size="13">Cross-agent</text><text x="792" y="677" class="t" font-size="20" font-weight="700">MCP stdio server</text>
|
|
58
58
|
</g>
|
|
@@ -6,7 +6,7 @@ This note answers three questions from the public 30-query comparison:
|
|
|
6
6
|
2. Can the AnySearch tail and the Chinese Rust miss be fixed?
|
|
7
7
|
3. Does the fix require a vector database or a different retrieval model?
|
|
8
8
|
|
|
9
|
-
> **Version note (2026-11-02):** 0.24.0 added Windows system-proxy discovery, and 0.24.1 and 0.24.2 are documentation/metadata patches; 0.24.3
|
|
9
|
+
> **Version note (2026-11-02):** 0.24.0 added Windows system-proxy discovery, and 0.24.1 and 0.24.2 are documentation/metadata patches; 0.24.3–0.24.6 fix fetch/proxy/markdown/cache/tool reliability without changing the measured search path. The search path is unchanged, so these 0.23.0 measurements still describe 0.24.x.
|
|
10
10
|
|
|
11
11
|
The short answer: Exa is a different architecture, not a faster RRF loop. This
|
|
12
12
|
plugin can borrow tail-tolerance and source-specific facts, but copying Exa's
|
package/docs/store-evidence.md
CHANGED
|
@@ -29,7 +29,7 @@ Only `0.2.1-rc.2` is declared, because that is the version actually exercised.
|
|
|
29
29
|
`mktemp -d`; the real `~/.dsh` was never written to. Bundled pnpm 11.28.5.
|
|
30
30
|
- **Windows CI:** GitHub Actions `windows-latest`, Node 24. Install, typecheck,
|
|
31
31
|
the full test suite, build and the entry-point import all pass. Run:
|
|
32
|
-
https://github.com/fangchenghao/dsh-web-search/actions/runs/
|
|
32
|
+
https://github.com/fangchenghao/dsh-web-search/actions/runs/44269396173
|
|
33
33
|
(the matrix also runs on macOS and Ubuntu). This is a CI environment, not a
|
|
34
34
|
claim about every Windows terminal or proxy client.
|
|
35
35
|
|
package/lib/domain-tool.d.ts
CHANGED
|
@@ -89,6 +89,8 @@ export interface DomainToolOptions {
|
|
|
89
89
|
detectProxy?: () => Promise<string | undefined>;
|
|
90
90
|
/** Registration diagnostics. */
|
|
91
91
|
warn?: (message: string) => void;
|
|
92
|
+
/** Receives the host's disposer, when registration returns one. */
|
|
93
|
+
onRegister?: (dispose: (() => void) | undefined) => void;
|
|
92
94
|
}
|
|
93
95
|
/** Format the model-facing result text. */
|
|
94
96
|
export declare function formatDomainValue(args: unknown, value: DomainToolValue): string;
|
package/lib/domain-tool.js
CHANGED
|
@@ -225,7 +225,13 @@ function report(options, error) {
|
|
|
225
225
|
export function registerDomainTool(tools, readSettings, options = {}) {
|
|
226
226
|
const name = pickDomainToolName(tools);
|
|
227
227
|
try {
|
|
228
|
-
tools.register(createDomainToolDefinition(name, readSettings, options));
|
|
228
|
+
const registered = tools.register(createDomainToolDefinition(name, readSettings, options));
|
|
229
|
+
try {
|
|
230
|
+
options.onRegister?.(typeof registered === 'function' ? registered : undefined);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
// A registration observer must not break mounting.
|
|
234
|
+
}
|
|
229
235
|
return name;
|
|
230
236
|
}
|
|
231
237
|
catch (error) {
|
package/lib/engine-test.js
CHANGED
|
@@ -17,11 +17,15 @@ function failureReason(outcome) {
|
|
|
17
17
|
return outcome.failureDetails[0]?.reason ?? outcome.failures[0];
|
|
18
18
|
}
|
|
19
19
|
/** Run `worker` over items with at most `limit` in flight, preserving order. */
|
|
20
|
-
async function mapLimit(items, limit, worker) {
|
|
20
|
+
async function mapLimit(items, limit, worker, signal) {
|
|
21
21
|
const results = new Array(items.length);
|
|
22
22
|
let next = 0;
|
|
23
23
|
const runners = Array.from({ length: Math.min(Math.max(1, limit), items.length) }, async () => {
|
|
24
24
|
for (;;) {
|
|
25
|
+
if (signal?.aborted === true) {
|
|
26
|
+
const reason = signal.reason;
|
|
27
|
+
throw reason instanceof Error ? reason : new DOMException('The operation was aborted', 'AbortError');
|
|
28
|
+
}
|
|
25
29
|
const index = next;
|
|
26
30
|
next += 1;
|
|
27
31
|
if (index >= items.length)
|
|
@@ -133,10 +137,18 @@ function parseArgs(args) {
|
|
|
133
137
|
* @returns per-engine results plus counts.
|
|
134
138
|
*/
|
|
135
139
|
export async function runEngineTestValue(runTest, engines, query, signal) {
|
|
140
|
+
if (signal?.aborted === true) {
|
|
141
|
+
const reason = signal.reason;
|
|
142
|
+
throw reason instanceof Error ? reason : new DOMException('The operation was aborted', 'AbortError');
|
|
143
|
+
}
|
|
136
144
|
const results = await mapLimit(engines, ENGINE_TEST_CONCURRENCY, async (engine) => {
|
|
137
145
|
const started = Date.now();
|
|
138
146
|
try {
|
|
139
147
|
const outcome = await runTest(engine, query, signal);
|
|
148
|
+
if (signal?.aborted === true) {
|
|
149
|
+
const reason = signal.reason;
|
|
150
|
+
throw reason instanceof Error ? reason : new DOMException('The operation was aborted', 'AbortError');
|
|
151
|
+
}
|
|
140
152
|
const latencyMs = Date.now() - started;
|
|
141
153
|
if (outcome.sources.length > 0) {
|
|
142
154
|
const first = outcome.sources[0];
|
|
@@ -162,6 +174,8 @@ export async function runEngineTestValue(runTest, engines, query, signal) {
|
|
|
162
174
|
};
|
|
163
175
|
}
|
|
164
176
|
catch (error) {
|
|
177
|
+
if (signal?.aborted === true)
|
|
178
|
+
throw error;
|
|
165
179
|
return {
|
|
166
180
|
engine,
|
|
167
181
|
ok: false,
|
|
@@ -171,7 +185,7 @@ export async function runEngineTestValue(runTest, engines, query, signal) {
|
|
|
171
185
|
reason: error instanceof Error ? error.message : String(error),
|
|
172
186
|
};
|
|
173
187
|
}
|
|
174
|
-
});
|
|
188
|
+
}, signal);
|
|
175
189
|
const ok = results.filter((result) => result.ok).length;
|
|
176
190
|
return { query, results, ok, failed: results.length - ok };
|
|
177
191
|
}
|
package/lib/engines.js
CHANGED
|
@@ -326,6 +326,10 @@ async function runTier(hosts, query, signal, timeoutMs, failures, failureDetails
|
|
|
326
326
|
const counters = limits.lead === 'all' || !hosts.some((host) => leadsQuery(host, limits.lead))
|
|
327
327
|
? () => true
|
|
328
328
|
: (host) => leadsQuery(host, limits.lead);
|
|
329
|
+
if (isAborted(signal)) {
|
|
330
|
+
const reason = signal?.reason;
|
|
331
|
+
throw reason instanceof Error ? reason : new SearchError('web search was cancelled', 'SEARCH_ABORTED', false);
|
|
332
|
+
}
|
|
329
333
|
const controller = new AbortController();
|
|
330
334
|
const relayAbort = () => controller.abort();
|
|
331
335
|
signal?.addEventListener('abort', relayAbort, { once: true });
|
|
@@ -418,6 +422,10 @@ async function runTier(hosts, query, signal, timeoutMs, failures, failureDetails
|
|
|
418
422
|
}
|
|
419
423
|
return answers;
|
|
420
424
|
}
|
|
425
|
+
/** Read an abort flag without TypeScript assuming it cannot change after a throw. */
|
|
426
|
+
function isAborted(signal) {
|
|
427
|
+
return signal !== undefined && signal.aborted;
|
|
428
|
+
}
|
|
421
429
|
/**
|
|
422
430
|
* Search the web with every configured engine and fuse the answers.
|
|
423
431
|
* @param query - the user query.
|
|
@@ -470,6 +478,8 @@ export async function search(query, signal, options) {
|
|
|
470
478
|
if (typeof query !== 'string' || query.trim().length === 0) {
|
|
471
479
|
throw new SearchError('the search query is empty', 'SEARCH_INVALID', false);
|
|
472
480
|
}
|
|
481
|
+
if (isAborted(signal))
|
|
482
|
+
throw new SearchError('web search was cancelled', 'SEARCH_ABORTED', false);
|
|
473
483
|
const limit = Math.max(1, Math.min(options.limit, 20));
|
|
474
484
|
const timeoutMs = options.timeoutMs ?? 15000;
|
|
475
485
|
const wait = options.wait ?? 'auto';
|
|
@@ -590,7 +600,7 @@ export async function search(query, signal, options) {
|
|
|
590
600
|
note = `fallback skipped: ${blockedKind} is not enabled in fallbackOn.`;
|
|
591
601
|
}
|
|
592
602
|
}
|
|
593
|
-
if (signal
|
|
603
|
+
if (isAborted(signal))
|
|
594
604
|
throw new SearchError('web search was cancelled', 'SEARCH_ABORTED', false);
|
|
595
605
|
sources = removeBlocked(sources, blocked);
|
|
596
606
|
if (key !== undefined && sources.length > 0)
|
package/lib/index.js
CHANGED
|
@@ -404,7 +404,8 @@ export function apply(ctx, config = {}) {
|
|
|
404
404
|
...(live.proxy === undefined ? {} : { proxy: live.proxy }),
|
|
405
405
|
};
|
|
406
406
|
return settings;
|
|
407
|
-
}, { warn: warnTool
|
|
407
|
+
}, { warn: warnTool, onRegister: (dispose) => { if (dispose !== undefined)
|
|
408
|
+
onDispose(ctx, dispose); } });
|
|
408
409
|
// Batch tool: same optional-registry path, same fail-safe mounting. Most
|
|
409
410
|
// queries use the `web_search` path; an explicit package-registry query
|
|
410
411
|
// can use the existing domain source instead.
|
|
@@ -520,7 +521,8 @@ export function apply(ctx, config = {}) {
|
|
|
520
521
|
truncated: outcome.truncated,
|
|
521
522
|
};
|
|
522
523
|
};
|
|
523
|
-
const platform = registerPlatformTool(toolTarget, platformRunner, { warn: warnTool
|
|
524
|
+
const platform = registerPlatformTool(toolTarget, platformRunner, { warn: warnTool, onRegister: (dispose) => { if (dispose !== undefined)
|
|
525
|
+
onDispose(ctx, dispose); } });
|
|
524
526
|
// Diagnostics: one tiny query per engine, no cache and no cooldown
|
|
525
527
|
// mutation. It is registered last because it is the least essential tool.
|
|
526
528
|
const engineTest = registerEngineTestTool(toolTarget, runEngineTest, { warn: warnTool });
|
|
@@ -531,12 +533,15 @@ export function apply(ctx, config = {}) {
|
|
|
531
533
|
// One entry point, eight actions. If the host rejects both candidate
|
|
532
534
|
// names, fall back to the legacy definitions rather than losing every
|
|
533
535
|
// optional capability.
|
|
534
|
-
const unified = registerUnifiedTool(tools, captured, { warn: warnTool
|
|
536
|
+
const unified = registerUnifiedTool(tools, captured, { warn: warnTool, onRegister: (dispose) => { if (dispose !== undefined)
|
|
537
|
+
onDispose(ctx, dispose); } });
|
|
535
538
|
if (unified === undefined && captured.length > 0) {
|
|
536
539
|
warnTool('web_tools unavailable; registering legacy tool names as a fallback');
|
|
537
540
|
for (const definition of captured) {
|
|
538
541
|
try {
|
|
539
|
-
tools.register(definition);
|
|
542
|
+
const registered = tools.register(definition);
|
|
543
|
+
if (typeof registered === 'function')
|
|
544
|
+
onDispose(ctx, registered);
|
|
540
545
|
}
|
|
541
546
|
catch (error) {
|
|
542
547
|
warnTool(`legacy fallback registration skipped: ${error instanceof Error ? error.message : String(error)}`);
|
package/lib/platform-tool.d.ts
CHANGED
|
@@ -73,5 +73,6 @@ export declare function pickPlatformToolName(tools: PlatformToolRegistryLike): s
|
|
|
73
73
|
/** Register the tool; any registry failure is contained. */
|
|
74
74
|
export declare function registerPlatformTool(tools: PlatformToolRegistryLike, run: PlatformRunner, options?: {
|
|
75
75
|
warn?: (message: string) => void;
|
|
76
|
+
onRegister?: (dispose: (() => void) | undefined) => void;
|
|
76
77
|
}): string | undefined;
|
|
77
78
|
export { MAX_PLATFORM_LIMIT };
|
package/lib/platform-tool.js
CHANGED
|
@@ -157,7 +157,13 @@ export function pickPlatformToolName(tools) {
|
|
|
157
157
|
export function registerPlatformTool(tools, run, options = {}) {
|
|
158
158
|
const name = pickPlatformToolName(tools);
|
|
159
159
|
try {
|
|
160
|
-
tools.register(createPlatformToolDefinition(name, run));
|
|
160
|
+
const registered = tools.register(createPlatformToolDefinition(name, run));
|
|
161
|
+
try {
|
|
162
|
+
options.onRegister?.(typeof registered === 'function' ? registered : undefined);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// A registration observer must not break mounting.
|
|
166
|
+
}
|
|
161
167
|
return name;
|
|
162
168
|
}
|
|
163
169
|
catch (error) {
|
package/lib/render.js
CHANGED
|
@@ -64,15 +64,67 @@ const SHELL_MARKERS = [
|
|
|
64
64
|
export function readableTextLength(html) {
|
|
65
65
|
if (html.length === 0)
|
|
66
66
|
return 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.
|
|
67
|
+
const lower = html.toLowerCase();
|
|
68
|
+
let count = 0;
|
|
69
|
+
let pendingSpace = false;
|
|
70
|
+
let index = 0;
|
|
71
|
+
const advancePast = (needle, from) => {
|
|
72
|
+
const at = lower.indexOf(needle, from);
|
|
73
|
+
if (at < 0)
|
|
74
|
+
return html.length;
|
|
75
|
+
const end = html.indexOf('>', at + needle.length);
|
|
76
|
+
return end < 0 ? html.length : end + 1;
|
|
77
|
+
};
|
|
78
|
+
while (index < html.length) {
|
|
79
|
+
if (html.startsWith('<!--', index)) {
|
|
80
|
+
const end = html.indexOf('-->', index + 4);
|
|
81
|
+
index = end < 0 ? html.length : end + 3;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (html[index] === '<') {
|
|
85
|
+
const end = html.indexOf('>', index + 1);
|
|
86
|
+
if (end < 0) {
|
|
87
|
+
// A lone '<' is text, not markup.
|
|
88
|
+
index += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const raw = html.slice(index + 1, end).trim();
|
|
92
|
+
if (raw.startsWith('!') || raw.startsWith('?')) {
|
|
93
|
+
index = end + 1;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const name = /^\/?\s*([a-zA-Z][a-zA-Z0-9:_-]*)/u.exec(raw)?.[1]?.toLowerCase();
|
|
97
|
+
if (name === 'head') {
|
|
98
|
+
index = advancePast('</head', end + 1);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (name !== undefined && ['script', 'style', 'noscript', 'template', 'svg'].includes(name)) {
|
|
102
|
+
index = advancePast(`</${name}`, end + 1);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
index = end + 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (html[index] === '&') {
|
|
109
|
+
const entity = /^&(?:#\d+|#x[0-9a-f]+|[a-z][a-z0-9]+);/iu.exec(html.slice(index));
|
|
110
|
+
if (entity !== null) {
|
|
111
|
+
pendingSpace = true;
|
|
112
|
+
index += entity[0].length;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (/\s/u.test(html[index])) {
|
|
117
|
+
pendingSpace = true;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
if (pendingSpace && count > 0)
|
|
121
|
+
count += 1;
|
|
122
|
+
pendingSpace = false;
|
|
123
|
+
count += 1;
|
|
124
|
+
}
|
|
125
|
+
index += 1;
|
|
126
|
+
}
|
|
127
|
+
return count;
|
|
76
128
|
}
|
|
77
129
|
/**
|
|
78
130
|
* Decide whether a fetched page is probably a script-rendered shell.
|
|
@@ -235,12 +287,22 @@ function isAborted(signal) {
|
|
|
235
287
|
async function closeQuietly(target) {
|
|
236
288
|
if (target === undefined)
|
|
237
289
|
return;
|
|
290
|
+
let timer;
|
|
238
291
|
try {
|
|
239
|
-
await
|
|
292
|
+
await Promise.race([
|
|
293
|
+
target.close().catch(() => undefined),
|
|
294
|
+
new Promise((resolve) => {
|
|
295
|
+
timer = setTimeout(resolve, 1_000);
|
|
296
|
+
}),
|
|
297
|
+
]);
|
|
240
298
|
}
|
|
241
299
|
catch {
|
|
242
300
|
// A close that fails is not the interesting failure.
|
|
243
301
|
}
|
|
302
|
+
finally {
|
|
303
|
+
if (timer !== undefined)
|
|
304
|
+
clearTimeout(timer);
|
|
305
|
+
}
|
|
244
306
|
}
|
|
245
307
|
/**
|
|
246
308
|
* Render one URL in a headless Chromium and return its serialised DOM.
|
|
@@ -268,26 +330,34 @@ export async function renderWithPlaywright(renderer, url, timeoutMs, signal) {
|
|
|
268
330
|
let browser;
|
|
269
331
|
let page;
|
|
270
332
|
let resolveAbort;
|
|
333
|
+
let stopped = false;
|
|
271
334
|
const aborted = new Promise((resolve) => {
|
|
272
335
|
resolveAbort = resolve;
|
|
273
336
|
});
|
|
274
|
-
const
|
|
337
|
+
const stop = () => {
|
|
338
|
+
if (stopped)
|
|
339
|
+
return;
|
|
340
|
+
stopped = true;
|
|
275
341
|
resolveAbort?.();
|
|
276
342
|
// Requirement, not optimisation: a cancelled render must not keep a
|
|
277
343
|
// browser or a page alive while the caller has already moved on.
|
|
278
344
|
void closeQuietly(page);
|
|
279
345
|
void closeQuietly(browser);
|
|
280
346
|
};
|
|
347
|
+
const onAbort = () => stop();
|
|
281
348
|
let listening = false;
|
|
282
349
|
if (signal !== undefined) {
|
|
283
350
|
if (signal.aborted) {
|
|
284
|
-
|
|
351
|
+
stop();
|
|
285
352
|
}
|
|
286
353
|
else {
|
|
287
354
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
288
355
|
listening = true;
|
|
289
356
|
}
|
|
290
357
|
}
|
|
358
|
+
// The navigation timeout does not bound launch, newPage, content or a close
|
|
359
|
+
// that never resolves. One total deadline does.
|
|
360
|
+
const timer = setTimeout(stop, Math.max(1, budget + Math.min(NETWORK_IDLE_EXTRA_MS, budget)));
|
|
291
361
|
try {
|
|
292
362
|
const launching = renderer.chromium.launch({ headless: true });
|
|
293
363
|
const winner = await Promise.race([
|
|
@@ -300,23 +370,41 @@ export async function renderWithPlaywright(renderer, url, timeoutMs, signal) {
|
|
|
300
370
|
throw abortError();
|
|
301
371
|
}
|
|
302
372
|
browser = winner.browser;
|
|
303
|
-
if (isAborted(signal))
|
|
373
|
+
if (stopped || isAborted(signal))
|
|
374
|
+
throw abortError();
|
|
375
|
+
const pageAttempt = browser.newPage();
|
|
376
|
+
const pageWinner = await Promise.race([
|
|
377
|
+
pageAttempt.then((value) => ({ page: value })),
|
|
378
|
+
aborted.then(() => ({ page: undefined })),
|
|
379
|
+
]);
|
|
380
|
+
if (pageWinner.page === undefined) {
|
|
381
|
+
void pageAttempt.then((late) => closeQuietly(late)).catch(() => undefined);
|
|
304
382
|
throw abortError();
|
|
305
|
-
|
|
306
|
-
|
|
383
|
+
}
|
|
384
|
+
page = pageWinner.page;
|
|
385
|
+
if (stopped || isAborted(signal))
|
|
307
386
|
throw abortError();
|
|
308
|
-
const response = await
|
|
387
|
+
const response = await Promise.race([
|
|
388
|
+
page.goto(url, { waitUntil: 'domcontentloaded', timeout: budget }),
|
|
389
|
+
aborted.then(() => { throw abortError(); }),
|
|
390
|
+
]);
|
|
309
391
|
const idleBudget = Math.min(NETWORK_IDLE_EXTRA_MS, budget);
|
|
310
392
|
try {
|
|
311
|
-
await
|
|
393
|
+
await Promise.race([
|
|
394
|
+
page.waitForLoadState('networkidle', { timeout: idleBudget }),
|
|
395
|
+
aborted,
|
|
396
|
+
]);
|
|
312
397
|
}
|
|
313
398
|
catch {
|
|
314
399
|
// A page that never goes idle still has a DOM; carry on.
|
|
315
400
|
}
|
|
316
|
-
if (isAborted(signal))
|
|
401
|
+
if (stopped || isAborted(signal))
|
|
317
402
|
throw abortError();
|
|
318
|
-
const html = await
|
|
319
|
-
|
|
403
|
+
const html = await Promise.race([
|
|
404
|
+
page.content(),
|
|
405
|
+
aborted.then(() => { throw abortError(); }),
|
|
406
|
+
]);
|
|
407
|
+
if (stopped || isAborted(signal))
|
|
320
408
|
throw abortError();
|
|
321
409
|
return {
|
|
322
410
|
html,
|
|
@@ -324,11 +412,18 @@ export async function renderWithPlaywright(renderer, url, timeoutMs, signal) {
|
|
|
324
412
|
url: page.url(),
|
|
325
413
|
};
|
|
326
414
|
}
|
|
415
|
+
catch (error) {
|
|
416
|
+
if (stopped || isAborted(signal))
|
|
417
|
+
throw abortError();
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
327
420
|
finally {
|
|
421
|
+
clearTimeout(timer);
|
|
328
422
|
if (listening && signal !== undefined)
|
|
329
423
|
signal.removeEventListener('abort', onAbort);
|
|
330
|
-
|
|
331
|
-
|
|
424
|
+
// Start both closes together; a page close that hangs must not prevent the
|
|
425
|
+
// browser close from running.
|
|
426
|
+
await Promise.all([closeQuietly(page), closeQuietly(browser)]);
|
|
332
427
|
}
|
|
333
428
|
}
|
|
334
429
|
/**
|
package/lib/search-many.js
CHANGED
|
@@ -130,11 +130,15 @@ function withSite(source) {
|
|
|
130
130
|
* A dedicated helper keeps the concurrency contract visible instead of relying
|
|
131
131
|
* on an unstated promise-pool behaviour.
|
|
132
132
|
*/
|
|
133
|
-
async function mapLimit(items, limit, worker) {
|
|
133
|
+
async function mapLimit(items, limit, worker, signal) {
|
|
134
134
|
const results = new Array(items.length);
|
|
135
135
|
let next = 0;
|
|
136
136
|
const runners = Array.from({ length: Math.min(Math.max(1, limit), items.length) }, async () => {
|
|
137
137
|
for (;;) {
|
|
138
|
+
if (signal?.aborted === true) {
|
|
139
|
+
const reason = signal.reason;
|
|
140
|
+
throw reason instanceof Error ? reason : new DOMException('The operation was aborted', 'AbortError');
|
|
141
|
+
}
|
|
138
142
|
const index = next;
|
|
139
143
|
next += 1;
|
|
140
144
|
if (index >= items.length)
|
|
@@ -190,9 +194,17 @@ export function createSearchManyDefinition(name, runQuery) {
|
|
|
190
194
|
isConcurrencySafe: () => true,
|
|
191
195
|
async execute(args, exec) {
|
|
192
196
|
const parsed = parseArgs(args);
|
|
197
|
+
if (exec.signal?.aborted === true) {
|
|
198
|
+
const reason = exec.signal.reason;
|
|
199
|
+
throw reason instanceof Error ? reason : new DOMException('The operation was aborted', 'AbortError');
|
|
200
|
+
}
|
|
193
201
|
const outcomes = await mapLimit(parsed.queries, SEARCH_MANY_CONCURRENCY, async (query) => {
|
|
194
202
|
try {
|
|
195
203
|
const outcome = await runQuery(query, parsed.limit, exec.signal);
|
|
204
|
+
if (exec.signal?.aborted === true) {
|
|
205
|
+
const reason = exec.signal.reason;
|
|
206
|
+
throw reason instanceof Error ? reason : new DOMException('The operation was aborted', 'AbortError');
|
|
207
|
+
}
|
|
196
208
|
const mapped = parsed.withSites
|
|
197
209
|
? outcome.sources.map(withSite)
|
|
198
210
|
: outcome.sources.map((source) => ({ ...source }));
|
|
@@ -208,6 +220,8 @@ export function createSearchManyDefinition(name, runQuery) {
|
|
|
208
220
|
};
|
|
209
221
|
}
|
|
210
222
|
catch (error) {
|
|
223
|
+
if (exec.signal?.aborted === true)
|
|
224
|
+
throw error;
|
|
211
225
|
return {
|
|
212
226
|
result: {
|
|
213
227
|
query,
|
|
@@ -217,7 +231,7 @@ export function createSearchManyDefinition(name, runQuery) {
|
|
|
217
231
|
truncated: false,
|
|
218
232
|
};
|
|
219
233
|
}
|
|
220
|
-
});
|
|
234
|
+
}, exec.signal);
|
|
221
235
|
return {
|
|
222
236
|
results: outcomes.map((entry) => entry.result),
|
|
223
237
|
truncated: outcomes.some((entry) => entry.truncated),
|
package/lib/tool-suite.d.ts
CHANGED
|
@@ -79,6 +79,8 @@ export interface UnifiedToolRegistryLike {
|
|
|
79
79
|
export interface UnifiedToolOptions {
|
|
80
80
|
/** Diagnostics for a rejected registration. */
|
|
81
81
|
warn?: (message: string) => void;
|
|
82
|
+
/** Receives the host's disposer, when registration returns one. */
|
|
83
|
+
onRegister?: (dispose: (() => void) | undefined) => void;
|
|
82
84
|
}
|
|
83
85
|
/**
|
|
84
86
|
* Build the single unified definition.
|
package/lib/tool-suite.js
CHANGED
|
@@ -174,6 +174,13 @@ export function createUnifiedToolDefinition(name, definitions) {
|
|
|
174
174
|
},
|
|
175
175
|
async execute(args, exec) {
|
|
176
176
|
const { action, rest } = parseEnvelope(args);
|
|
177
|
+
// The unified schema exposes `limit` for several actions. advanced_search's
|
|
178
|
+
// native parameter is `maxResults`; translate only when no explicit
|
|
179
|
+
// maxResults was supplied, then let its own parser validate the range.
|
|
180
|
+
if (action === 'advanced_search' && rest['maxResults'] === undefined && rest['limit'] !== undefined) {
|
|
181
|
+
rest['maxResults'] = rest['limit'];
|
|
182
|
+
delete rest['limit'];
|
|
183
|
+
}
|
|
177
184
|
const definition = byAction.get(action);
|
|
178
185
|
if (definition === undefined) {
|
|
179
186
|
throw new Error(`web_tools action ${action} is not registered in this deployment`);
|
|
@@ -208,7 +215,13 @@ export function pickUnifiedToolName(tools) {
|
|
|
208
215
|
export function registerUnifiedTool(tools, definitions, options = {}) {
|
|
209
216
|
const name = pickUnifiedToolName(tools);
|
|
210
217
|
try {
|
|
211
|
-
tools.register(createUnifiedToolDefinition(name, definitions));
|
|
218
|
+
const registered = tools.register(createUnifiedToolDefinition(name, definitions));
|
|
219
|
+
try {
|
|
220
|
+
options.onRegister?.(typeof registered === 'function' ? registered : undefined);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// A registration observer must not break mounting.
|
|
224
|
+
}
|
|
212
225
|
return name;
|
|
213
226
|
}
|
|
214
227
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fffangchenghao/dsh-web-search",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.6",
|
|
4
4
|
"description": "DSH bundle: key-free web search, page fetch and research for DeepSeek Harness; eight engines fused with RRF, 34 vertical sources, arXiv, Windows/macOS system-proxy support and a dependency-free MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|