dsh-free-search 0.9.40 → 0.9.42
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/README.md +38 -20
- package/lib/client.js +121 -4
- package/lib/dedupe.js +74 -0
- package/lib/doctor.js +15 -0
- package/lib/engine_meta.js +1 -0
- package/lib/engines/metaso.js +112 -0
- package/lib/fetch_provider.js +7 -4
- package/lib/index.js +37 -8
- package/lib/intent.js +61 -0
- package/lib/multi_policy.js +1 -0
- package/lib/quality.js +43 -0
- package/lib/research.js +22 -1
- package/lib/ssrf.js +94 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
#### 引擎与切换
|
|
35
35
|
|
|
36
36
|
- **零成本** —— 多个免费引擎,无需 key、无需注册
|
|
37
|
-
- **
|
|
37
|
+
- **37 个引擎可选**:DuckDuckGo(html/lite)、Bing、SearXNG(元搜索,支持自定义实例)、AnySearch、Exa、Tavily、Keenable、Firecrawl、Parallel、Perplexity、SerpBase、Serply、Outcrawl、Google 自定义搜索(`google`,需 API key + CSE ID)、秘塔搜索(`metaso`,官方 API,按点数计费)、DeepSeek 官方、DeepSeek 原生搜索 API、You.com、百度千帆、Kimi、阿里云百炼、火山联网搜索(豆包搜索)、知乎全网/站内(`zhihu_global`/`zhihu_site`,经知乎开放平台 MCP)、Antigravity CLI 搜索(`agy`,需本机安装)、OpenAI / Gemini / Claude 模型内置搜索。默认自动回退链覆盖其中 28 个;5 个 HTML SERP 引擎默认不参与,OpenAI / Gemini / Claude 三个模型引擎和 Metaso 都只在显式点名时运行。
|
|
38
38
|
- **5 个 HTML 搜索页引擎(默认关闭)** —— 把传统搜索页并入同一套引擎 / 回退 / 冷却 / 设置体系:`baidu-html`(百度网页)、`so360`、`sogou`、`wechat`(微信文章)、`toutiao`。免 key、免额度,代价是抓页面:验证码/反爬按 `bot-wall` 归类并让整个家族冷却 10 分钟(整段出口 IP 都会被打标),结果也没有 API 摘要。它们默认不进 auto / 回退链 / 语言池,只在显式 `engine=` 或加入语言池时运行。
|
|
39
39
|
- **引擎白名单** —— 设置页「只使用勾选的引擎」开启后,只有勾选的引擎可用,升级新增的引擎默认不启用;配置里对应 `allowedEngines`(非空时等价于把其余引擎全部禁用)。
|
|
40
40
|
- **全局引擎开关与回退优先级** —— 设置页可勾选/取消引擎(取消后全局生效:普通搜索 / Auto / `advanced_search` / `multi_search` / 引擎测试都不再用它),并可用 ↑↓ 调整全局回退顺序(一键恢复默认)。
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
|
|
49
49
|
- **统一引擎回退** —— 任何引擎失败(付费/免费,缺 key/401/限流/网络)自动轮流尝试下一个引擎:首选引擎 → 其他引擎(exa/tavily/keenable/firecrawl/parallel/you 无 key 也会尝试,因为它们自带 keyless 免费额度)→ 剩余免费引擎,搜索永不直接失败;结果顶部注明实际生效的引擎(如 `Note: perplexity unavailable or failed, using exa.`);失败按类别处理:额度/鉴权失败 → 本会话冷却该引擎,反爬 → 短退避,超时/5xx/限流 → 同引擎重试一次,解析失败/0 结果 → 不冷却(详见下文「失败分类与引擎冷却」)。
|
|
50
50
|
- **多 key 轮换** —— 任何 key 字段(或对应环境变量)都可以用逗号 / 分号 / 换行分隔多把 key;平时按请求轮流使用(round-robin,避免单 key 撞 QPS/RPM 风控),遇到 401/402/429(鉴权失败、额度耗尽、限流)先轮换同一引擎的下一把,再走引擎回退;`multi` 模式同样生效(#96)。
|
|
51
|
-
- **按 key 冷却与诊断** —— 429 与额度错误按 key 分别冷却,同一引擎的其他 key 不受牵连;冷却状态写入磁盘,重启后仍在;失败信息和日志里的 key 一律打码;设置页底部的「诊断」按钮列出每个引擎当前为什么不可用、冷却还剩多久,以及本次进程内的调用次数、成功/空/失败和平均耗时;同一引擎并发超过 2 会排队(HTML SERP 为 1
|
|
51
|
+
- **按 key 冷却与诊断** —— 429 与额度错误按 key 分别冷却,同一引擎的其他 key 不受牵连;冷却状态写入磁盘,重启后仍在;失败信息和日志里的 key 一律打码;设置页底部的「诊断」按钮列出每个引擎当前为什么不可用、冷却还剩多久,以及本次进程内的调用次数、成功/空/失败和平均耗时;同一引擎并发超过 2 会排队(HTML SERP 为 1),避免免费引擎被同时打爆;诊断还会标注当前 web search/fetch provider,被其他插件接管时给出互斥警告。
|
|
52
52
|
- **自带更新** —— 卡片底部显示当前版本和「检查更新」;npm 安装的版本可一键升级到 latest,本地 link 开发模式改为跳转 npm 页面并提示 `git pull`。
|
|
53
53
|
- **引擎测试** —— `free_search_test` 工具让 agent 一键测试所有引擎;设置页也有「测试引擎」按钮(直测当前引擎,不走回退链,付费引擎无 key 会明确报错)。
|
|
54
54
|
- **截断安全** —— 标题和摘要按码点截断,搜索结果、工具输出和 `web_fetch` 正文在离开插件前统一清除孤立代理;含 emoji 的结果不会再让会话历史出现无法序列化的字符(#108)。
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
|
|
59
59
|
#### Multi 与语言池
|
|
60
60
|
|
|
61
|
-
- **Multi 模式** —— 可把搜索引擎设为 `Multi Search`:`web_search` 按查询语言并发**对应语言池的全部**已启用引擎(不再是前 3 个;中文/英文池可在设置页编辑,每池最低 2 个引擎)、按 URL 合并去重(同站判定用 **eTLD+1**)、跨源命中的结果优先;设置页有 **Fast / Balanced / Deep** 三档强度,也可手填并发上限与目标成功源数;整轮检索共享 **30 秒总预算**,到点返回已有结果;合并结果的条数上限可在设置页调整(对应 `multiMaxResults`,默认 20,最大 100,单次 `maxResults`
|
|
61
|
+
- **Multi 模式** —— 可把搜索引擎设为 `Multi Search`:`web_search` 按查询语言并发**对应语言池的全部**已启用引擎(不再是前 3 个;中文/英文池可在设置页编辑,每池最低 2 个引擎)、按 URL 合并去重(同站判定用 **eTLD+1**)、跨源命中的结果优先;设置页有 **Fast / Balanced / Deep** 三档强度,也可手填并发上限与目标成功源数;整轮检索共享 **30 秒总预算**,到点返回已有结果;合并结果的条数上限可在设置页调整(对应 `multiMaxResults`,默认 20,最大 100,单次 `maxResults` 只能要得更少)。合并结果会用 MinHash 去掉近重复来源。代价是成倍消耗额度;multi 失败会自动退回单引擎回退链。
|
|
62
|
+
- **按意图路由** —— Auto 在未自定义回退顺序时,按查询领域(金融 / 学术 / 代码 / 新闻 / 购物)重排当前语言池;只调整已有引擎的先后,不新增引擎、不改回退集合。
|
|
62
63
|
|
|
63
64
|
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-free-search/master/assets/ui-performance.png" alt="性能:缓存与 Multi 档位" width="100%" />
|
|
64
65
|
<sub>▲ 性能:结果缓存时长与 Multi 的 Fast / Balanced / Deep 档位</sub>
|
|
@@ -76,7 +77,7 @@
|
|
|
76
77
|
|
|
77
78
|
#### 抓取与工具
|
|
78
79
|
|
|
79
|
-
- **网页抓取(web_fetch)** —— 让 agent 抓取网页内容(官方 `dsh-web-fetch-http` provider,纯 JS,零额外依赖),可自动接管 `web.fetchProvider` 为插件的直连 → 浏览器渲染 → exa / firecrawl → crawl4ai 质量链。T1.5 浏览器渲染可在设置页关闭,exa 与 firecrawl 的先后顺序也可切换;私网、回环和云元数据地址一律拒绝(SSRF 防护)。
|
|
80
|
+
- **网页抓取(web_fetch)** —— 让 agent 抓取网页内容(官方 `dsh-web-fetch-http` provider,纯 JS,零额外依赖),可自动接管 `web.fetchProvider` 为插件的直连 → 浏览器渲染 → exa / firecrawl → crawl4ai 质量链。T1.5 浏览器渲染可在设置页关闭,exa 与 firecrawl 的先后顺序也可切换;私网、回环和云元数据地址一律拒绝(SSRF 防护)。Clash / mihomo TUN 的 fake-ip 网段(常见 198.18.0.0/15)可在「额外允许的网段」里显式放行,否则系统 DNS 返回的占位地址会被当成私网拒绝。
|
|
80
81
|
|
|
81
82
|
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-free-search/master/assets/ui-fetch.png" alt="抓取与平台:web_fetch 接管、Key 存储位置与平台搜索开关" width="100%" />
|
|
82
83
|
<sub>▲ 抓取:自动接管 web_fetch、Key 存储位置与平台搜索开关</sub>
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
- **平台搜索(platform_search)** —— 搜 GitHub / V2EX / B站 / Reddit / Hacker News / Stack Overflow / 维基百科 / npm / YouTube / Vimeo / 掘金 / 豆瓣 / Qiita(公开 API 或免 key 抓取,零依赖);X (Twitter) 经本地 Grok Build CLI(需 SuperGrok / X Premium 登录)。
|
|
85
86
|
- **垂直领域直查(domain_search)** —— 41 个免 key 垂直源直查:包/版本(PyPI、crates、GitHub releases、endoflife…)、学术(arXiv、Crossref、OpenAlex、Semantic Scholar、PubMed、dblp、Zenodo…)、安全(NVD、OSV、CISA KEV)、金融(SEC EDGAR、IMF、World Bank、CFETS、Yahoo Finance、CoinGecko…)、法律(US Federal Register、US CourtListener、openlegaldata、UK legislation)、新闻(Google News、GDELT)等。
|
|
86
87
|
- **视频搜索(video_search)** —— 跨站找视频:Bing Videos + DuckDuckGo Videos(免 key,失败互相回退),返回视频链接、标题与来源/时长等元信息。
|
|
87
|
-
- **一次调用完成研究(research)** —— 多引擎并发搜索 → 候选重排 → 分层抓取正文 → 段落选窗 → 带出处的 Markdown
|
|
88
|
+
- **一次调用完成研究(research)** —— 多引擎并发搜索 → 候选重排 → 分层抓取正文 → 段落选窗 → 带出处的 Markdown 证据包;模型组件(重排/嵌入/决策模型)全部可选,缺失或失败时静默回退规则路径;输出附带证据质量闸门(high / medium / low 与结论上限),证据不足时明确提示先核验再下结论。
|
|
88
89
|
- **检索正文缓存(cache_search)** —— 全文检索 `research` 抓过的正文(`node:sqlite` 持久缓存,存储 7 天;`node:sqlite` 不可用时自动降级为 no-op,免 flag 需 ≥ 22.13,22.5–22.12 需 `--experimental-sqlite`)。
|
|
89
90
|
- **干净集成** —— 实现官方 `WebSearchProvider` seam 接口,与官方插件共存。
|
|
90
91
|
- **时间过滤** —— `advanced_search` 工具支持 `timeRange`:固定档、自定义相对值、绝对日期三种形式(详见下方逻辑说明)。
|
|
@@ -148,6 +149,7 @@
|
|
|
148
149
|
| `serply` | Serply | 付费 | 需 `SERPLY_API_KEY`(serply.io,新账户 30 天内 2,500 次免费额度);Google 网页结果,按设置页语言本地化 |
|
|
149
150
|
| `outcrawl` | Outcrawl | 付费 | 需 `OUTCRAWL_API_KEY`(outcrawl.ai,每月 1,000 credits 免费额度);网页搜索结果(标题/链接/摘要),单次最多 20 条 |
|
|
150
151
|
| `google` | Google 自定义搜索 | 免费额度 | 需 `GOOGLE_CSE_API_KEY` 和 Programmable Search Engine ID(`googleCseId` / cx);Google 官方 Custom Search JSON API,每天 100 次免费,按次计费超额;支持 `hl`、安全搜索和 `dateRestrict` 时间过滤 |
|
|
152
|
+
| `metaso` | 秘塔搜索 | 付费(点数) | 需 `METASO_API_KEY`(metaso.cn/api);官方 AI 搜索 API,按点数计费(约 0.03 元/次,新用户有体验额度);支持网页 / 文库 / 学术三种 `scope`,返回摘要和来源;不在默认回退顺序里,配 key 后显式选用 |
|
|
151
153
|
| `deepseek-official` | DeepSeek 官方 | 付费 | 需 `DEEPSEEK_API_KEY`;走 Anthropic 兼容的 `web_search` 服务端工具,每次搜索是一整个模型轮次(慢、耗 token) |
|
|
152
154
|
| `deepseek-tools` | DeepSeek 原生搜索 API | 付费 | 需 `DEEPSEEK_API_KEY`(与上一档共用);直接 `POST /v1/tools/search`,无模型参与,返回结构化 `results[]`(`title`/`url`/`summary`/`date`),同 query 实测 ~0.3s vs 上一档 ~5-6s |
|
|
153
155
|
| `baidu` | 百度千帆 AI 搜索 | 额度 | 需 `BAIDU_API_KEY`(千帆 AI 搜索,每日赠 50 次,超额按量后付费);中文全网,支持时间过滤 |
|
|
@@ -278,7 +280,7 @@ DSH 0.2.1 设置 → 网页搜索 → **DeepSeek 搜索 API** 开关会和本插
|
|
|
278
280
|
配置页提供:
|
|
279
281
|
|
|
280
282
|
- **Search engine**:下拉框切换引擎,保存即生效
|
|
281
|
-
- **API keys**:为 Exa / Tavily / Keenable / Firecrawl / Parallel / Perplexity / DeepSeek / SerpBase / Serply / Outcrawl / Google CSE / You.com 填写 key(密码框,保存后只显示"已配置";Exa / Tavily / Keenable / Firecrawl / Parallel / You.com 不填也可免 key 使用)
|
|
283
|
+
- **API keys**:为 Exa / Tavily / Keenable / Firecrawl / Parallel / Perplexity / DeepSeek / SerpBase / Serply / Outcrawl / Google CSE / Metaso / You.com 填写 key(密码框,保存后只显示"已配置";Exa / Tavily / Keenable / Firecrawl / Parallel / You.com 不填也可免 key 使用)
|
|
282
284
|
- **推荐**:付费引擎 key 建议写入 harness 凭据中心 `~/.dsh/.credentials.yaml`(如 `DEEPSEEK_API_KEY: sk-...`,与官方 LLM provider 一致,一处管理所有 key)。插件读取优先级:凭据中心 > 设置页 > 环境变量,设置页填的 key 仅作为遗留兼容。
|
|
283
285
|
- **Test engine**:直测当前引擎可用性(不走回退链,付费引擎无 key 会明确报错)
|
|
284
286
|
- **Use Bing default**:把当前搜索引擎切回稳定的免费 Bing;`Discard` 只撤销尚未保存的编辑
|
|
@@ -398,6 +400,7 @@ disabledTools: [] # 关掉的工具不再注册(例如 [domain_searc
|
|
|
398
400
|
bingMarket: zh-CN # Bing 市场;留空 = 自动(不发送 mkt)
|
|
399
401
|
fetchProviderTakeover: true # false = 保留你显式 pin 的 fetchProvider: http
|
|
400
402
|
browserFetch: true # 直连失败时用系统浏览器无头渲染
|
|
403
|
+
allowFakeIpCidrs: [] # 显式放行的保留网段,例如 Clash/mihomo fake-ip 的 198.18.0.0/15
|
|
401
404
|
fetchPrefer: exa # exa | firecrawl —— 两者都失败后先试哪个 keyed 抓取层
|
|
402
405
|
region: cn-zh # DuckDuckGo 区域(可选)
|
|
403
406
|
searxngInstances: # 自定义 SearXNG 实例(可选)
|
|
@@ -424,6 +427,8 @@ serplyApiKey: ... # 或通过设置页填写
|
|
|
424
427
|
outcrawlApiKey: ... # 或通过设置页填写
|
|
425
428
|
googleCseApiKey: ... # Google Custom Search API key
|
|
426
429
|
googleCseId: "..." # Programmable Search Engine 的 cx
|
|
430
|
+
metasoApiKey: ... # Metaso API key (metaso.cn/api)
|
|
431
|
+
metasoScope: webpage # webpage | document | scholar
|
|
427
432
|
deepseekApiKey: ...
|
|
428
433
|
```
|
|
429
434
|
|
|
@@ -511,7 +516,7 @@ Search engine test:
|
|
|
511
516
|
|
|
512
517
|
- 自动跟随重定向、解码正文(HTML 转文本)
|
|
513
518
|
- 支持超时和大小限制
|
|
514
|
-
- ⚠️ 注意:`web_fetch`
|
|
519
|
+
- ⚠️ 注意:`web_fetch` 默认拒绝回环、私网、链路本地和云元数据地址。若使用 Clash / mihomo TUN 的 fake-ip DNS,请把对应网段(常见 `198.18.0.0/15`)加入设置页的「额外允许的网段」,否则所有被代理域名都会被判成私网而抓取失败;只放行 fake-ip 保留段,不要放行 RFC1918。
|
|
515
520
|
|
|
516
521
|
#### 平台搜索(platform_search)
|
|
517
522
|
|
|
@@ -585,7 +590,7 @@ Search engine test:
|
|
|
585
590
|
|
|
586
591
|
#### 离线自检断言(tools/)
|
|
587
592
|
|
|
588
|
-
仓库自带 **
|
|
593
|
+
仓库自带 **56 个**零依赖断言脚本(合计 **839 项**),**不需要 API key、不联网、不需要测试框架**,Node ≥ 20 即可跑。一次跑全部:`npm test`。
|
|
589
594
|
|
|
590
595
|
| 脚本 | 覆盖 | 运行(项数) |
|
|
591
596
|
|---|---|---|
|
|
@@ -596,15 +601,19 @@ Search engine test:
|
|
|
596
601
|
| `assert-multi-policy.mjs` | multi 执行策略:并发上限是天花板 / 目标成功源非硬下限 / 凭据资格在上限之前分流 / **Fast·Balanced·Deep 档位** | `node tools/assert-multi-policy.mjs`(146) |
|
|
597
602
|
| `assert-multi-limit.mjs` | multi 结果上限(#109):默认 20 / 硬上限 100 / 配置归一化、单次 maxResults 受上限约束、工具参数与本段提示词写明生效上限、设置页字段与保存 | `node tools/assert-multi-limit.mjs`(6) |
|
|
598
603
|
| `assert-maintenance.mjs` | 维护面:CI 在 Node 20/22/24 跑全部断言并过打包闸门、发布脚本会 bump / 校验 / 打 tag / 可发布、恢复官方 provider 的桥接与设置页按钮 | `node tools/assert-maintenance.mjs`(4) |
|
|
599
|
-
| `assert-engine-modules.mjs` | 引擎分层:实现文件存在且被 index 引用、引擎函数已迁出 index、设置页引擎 id 与服务端清单一致、清单覆盖
|
|
604
|
+
| `assert-engine-modules.mjs` | 引擎分层:实现文件存在且被 index 引用、引擎函数已迁出 index、设置页引擎 id 与服务端清单一致、清单覆盖 37 个引擎且免费/按次标记正确、index 不引用引擎私有名 | `node tools/assert-engine-modules.mjs`(6) |
|
|
600
605
|
| `assert-bing-relevance.mjs` | Bing 相关性(#112):单字中文 token 被剔除、无关替代 SERP 被拒、真正相关的结果通过、只命中通用引擎名的整批被拒、单一 token 覆盖一半时放行、单字/纯数字查询的显式行为 | `node tools/assert-bing-relevance.mjs`(6) |
|
|
606
|
+
| `assert-quality.mjs` | 研究证据闸门:8 源 / 3 域 / 3 正文 / 2 日期为 high,3 源 / 2 域 / 1 正文为 medium,单源与失败注记为 low,空包为 low,research 的 schema/输出/brief 接线 | `node tools/assert-quality.mjs`(6) |
|
|
607
|
+
| `assert-dedupe.mjs` | 近重复去重:MinHash 同文本同签名、同 URL 去重、跨站转载去重、不同文章保留且顺序不变、阈值可调、provider 与 multi 两条路径接线 | `node tools/assert-dedupe.mjs`(6) |
|
|
608
|
+
| `assert-intent-routing.mjs` | 意图路由:五类领域与 general 分类、偏好重排稳定、Auto 头部按领域、自定义回退顺序不被重排、时间过滤仍生效、接线 | `node tools/assert-intent-routing.mjs`(6) |
|
|
601
609
|
| `assert-result-ranking.mjs` | 合并排序:**eTLD+1 同域判定** / 域名轮转 / `seenIn` 降为末位 / 时效仅带时间过滤时生效 | `node tools/assert-result-ranking.mjs`(31) |
|
|
602
610
|
| `assert-url-norm.mjs` | URL 规范化:只剔已审计的 tracking 参数,保留可能区分资源的参数 | `node tools/assert-url-norm.mjs`(72) |
|
|
603
611
|
| `assert-prompt-contract.mjs` | 系统提示词契约:**检索≠抓取**、不可信边界、模型内置搜索只在显式选中时运行 | `node tools/assert-prompt-contract.mjs`(9) |
|
|
604
612
|
| `assert-research-degradation.mjs` | research 无 key 全降级、`node:sqlite` no-op、90s 预算隔离、缓存目录可配置、`budget.exhausted` 契约名 | `node tools/assert-research-degradation.mjs`(19) |
|
|
605
613
|
| `assert-research-call-wrappers.mjs` | research 四个 `call*` 包装层的替身/底层透传(#75 回归) | `node tools/assert-research-call-wrappers.mjs`(23) |
|
|
606
614
|
| `assert-fetch-chain.mjs` | `fs-quality-fetch` 四层链序、任一层命中即停、exa 失败静默降级 firecrawl、全层失败聚合报错 | `node tools/assert-fetch-chain.mjs`(8) |
|
|
607
|
-
| `assert-fetch-ssrf.mjs` | 抓取 SSRF 防护:公网/私网/保留地址判定、DNS 解析到私网拒绝、localhost 与 IP 字面量拒绝、非 HTTPS 与带凭据 URL 拒绝、provider 接线与设置项 | `node tools/assert-fetch-ssrf.mjs`(
|
|
615
|
+
| `assert-fetch-ssrf.mjs` | 抓取 SSRF 防护:公网/私网/保留地址判定、DNS 解析到私网拒绝、localhost 与 IP 字面量拒绝、非 HTTPS 与带凭据 URL 拒绝、fake-ip 网段默认拒绝且仅按配置放行、放行后仍拒绝回环/私网、provider 接线与设置项 | `node tools/assert-fetch-ssrf.mjs`(8) |
|
|
616
|
+
| `assert-metaso.mjs` | 秘塔搜索:key 必填、请求体(q/scope/size/summary/raw/concise)、摘要与日期映射、文库数组、size 上限、无效 scope 回退、401/402/429/400 错误分类、注册与默认回退排除 | `node tools/assert-metaso.mjs`(6) |
|
|
608
617
|
| `assert-google-cse.mjs` | Google Custom Search:key+ID 必填、请求参数(q/num/start/hl/safe/dateRestrict)、结果映射与发布日期、超过 10 条分页、403/429/400 错误分类、时间档映射、全链路注册 | `node tools/assert-google-cse.mjs`(6) |
|
|
609
618
|
| `assert-engine-runtime.mjs` | 引擎运行时:按引擎并发上限(普通 2 / HTML SERP 1)、排队与 abort 清理、成功/空/失败/平均耗时统计、provider 与 runEngineTest 两条路径接线、诊断报告带 stats | `node tools/assert-engine-runtime.mjs`(4) |
|
|
610
619
|
| `assert-single-fetch-layer.mjs` | 抓取层全库只有一份实现、依赖单向、替身键不串层 | `node tools/assert-single-fetch-layer.mjs`(22) |
|
|
@@ -691,7 +700,7 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
691
700
|
#### Engines and switching
|
|
692
701
|
|
|
693
702
|
- **Zero Cost** — Multiple free engines with no API key or registration required
|
|
694
|
-
- **
|
|
703
|
+
- **37 engines available** — DuckDuckGo (HTML / Lite), Bing, AnySearch AI, SearXNG (meta-search with custom instances), Exa, Tavily, Keenable, Firecrawl, Parallel, Perplexity, SerpBase, Serply, Outcrawl, Google Programmable Search (`google`, needs an API key plus a CSE ID), Metaso (秘塔搜索, official API, billed per call), DeepSeek Official, DeepSeek Native Search API, You.com, Baidu Qianfan, Kimi, Aliyun Bailian, Volcano Doubao, Zhihu web-wide/site search (`zhihu_global`/`zhihu_site`, via the Zhihu open-platform MCP), Antigravity CLI search (`agy`, requires the local CLI), and the model-based OpenAI / Gemini / Claude searches. The default auto-fallback chain covers 28 of them; the 5 HTML SERP engines stay out by default and the per-call billed OpenAI / Gemini / Claude engines and Metaso run only when explicitly named.
|
|
695
704
|
- **5 HTML SERP engines (off by default)** — Traditional result pages join the same engine / fallback / cooldown / settings machinery: `baidu-html` (Baidu web), `so360`, `sogou`, `wechat` (WeChat articles) and `toutiao`. No key, no quota — the trade-off is scraping: captcha/anti-bot pages are classified as `bot-wall` and cool the whole family down for 10 minutes (the egress IP gets flagged as a whole), and results carry no API snippets. They never join auto routing, the fallback chain or the language pools; they only run when named via `engine=` or added to a pool.
|
|
696
705
|
- **Engine whitelist** — turn on Use only the checked engines and only those engines stay usable; engines added by later versions stay off. It maps to `allowedEngines` in the config (a non-empty list is equivalent to disabling every other engine).
|
|
697
706
|
- **Global engine enable/disable & fallback priority** — uncheck engines you never want (applies everywhere: web_search fallback, Auto routing, advanced_search, multi_search, engine tests) and reorder the global fallback chain with ↑↓ (one-click reset).
|
|
@@ -705,7 +714,7 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
705
714
|
|
|
706
715
|
- **Unified Engine Fallback** — Any engine failure (paid or free, missing key, 401, rate limit, network error) automatically tries the next engine: the configured engine first, then other engines (exa/tavily/keenable/firecrawl/parallel/you are tried even without a key because they have built-in keyless quota), then the remaining free engines (Bing/AnySearch etc.) — with a note attached to the results naming the engine that actually served them (e.g. `Note: perplexity unavailable or failed, using exa.`). Failures are classified: quota/auth failures cool the engine down for the session, anti-bot walls back off briefly, timeout/5xx/rate-limit failures retry the same engine once, and parse errors / 0 results are reported without cooling it down. Search never fails outright.
|
|
707
716
|
- **Multi-key rotation** — Any key field (or its env var) accepts several keys separated by commas, semicolons or newlines. Keys are used round-robin per request, and on 401/402/429 the same engine retries with the next key before the engine-level fallback runs. This also applies inside `multi` mode (#96).
|
|
708
|
-
- **Per-key cooldowns and diagnostics** — a 429 or quota error cools the key that hit it, not every other key of the same engine; the state is written to disk and survives a restart; keys are masked in failure text and logs; the Diagnose button at the bottom of the settings page lists why each engine is currently unavailable, how long its cooldown has left, and the in-process call count, success/empty/failure split and average latency; concurrent calls to one engine queue beyond 2 (1 for HTML SERP), so a free engine is not hammered in the same second.
|
|
717
|
+
- **Per-key cooldowns and diagnostics** — a 429 or quota error cools the key that hit it, not every other key of the same engine; the state is written to disk and survives a restart; keys are masked in failure text and logs; the Diagnose button at the bottom of the settings page lists why each engine is currently unavailable, how long its cooldown has left, and the in-process call count, success/empty/failure split and average latency; concurrent calls to one engine queue beyond 2 (1 for HTML SERP), so a free engine is not hammered in the same second; the doctor also reports the active web search/fetch provider and warns when another plugin owns it (providers are mutually exclusive).
|
|
709
718
|
- **Built-in updater** — the card footer shows the version and a Check update button; npm installs upgrade to latest in one click, while a local link install links to the npm page and points at git pull instead.
|
|
710
719
|
- **Engine Testing** — `free_search_test` for the agent to check all engines in one call; the settings UI also has a "Test engine" button that tests the selected engine directly (no fallback chain; paid engines without a key report an explicit error).
|
|
711
720
|
- **Truncation safety** — titles and snippets are cut by code point, and search results, tool output and web_fetch bodies are stripped of lone surrogates before leaving the plugin; an emoji can no longer make history unserializable (#108).
|
|
@@ -715,7 +724,8 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
715
724
|
|
|
716
725
|
#### Multi and language pools
|
|
717
726
|
|
|
718
|
-
- **Multi mode** — pick `Multi Search` as the engine: web_search queries **every enabled engine of the query's language pool** concurrently (no longer top 3; zh/en pools editable in the settings UI, minimum 2 engines each), merges/deduplicates URLs (same-site detection via **eTLD+1**) and prioritizes cross-source hits; the settings UI offers **Fast / Balanced / Deep** presets or your own cap and target numbers; the whole run shares one **30-second budget** and returns whatever it already has when time is up; the final unique-result ceiling is configurable in Settings (`multiMaxResults`, default 20, max 100, while a per-call `maxResults` can only ask for fewer). This costs more quota; a failed multi run automatically falls back to the single-engine chain.
|
|
727
|
+
- **Multi mode** — pick `Multi Search` as the engine: web_search queries **every enabled engine of the query's language pool** concurrently (no longer top 3; zh/en pools editable in the settings UI, minimum 2 engines each), merges/deduplicates URLs (same-site detection via **eTLD+1**) and prioritizes cross-source hits; the settings UI offers **Fast / Balanced / Deep** presets or your own cap and target numbers; the whole run shares one **30-second budget** and returns whatever it already has when time is up; the final unique-result ceiling is configurable in Settings (`multiMaxResults`, default 20, max 100, while a per-call `maxResults` can only ask for fewer). Merged results are de-duplicated with MinHash. This costs more quota; a failed multi run automatically falls back to the single-engine chain.
|
|
728
|
+
- **Intent routing** — when no custom fallback order is set, Auto reorders the current language pool by query domain (finance / academic / code / news / shopping); it only changes the order of engines already selected, never adds engines or changes the fallback set.
|
|
719
729
|
|
|
720
730
|
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-free-search/master/assets/ui-performance.png" alt="Performance: cache and Multi presets" width="100%" />
|
|
721
731
|
<sub>▲ Performance: result cache TTL and the Fast / Balanced / Deep Multi presets</sub>
|
|
@@ -733,7 +743,7 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
733
743
|
|
|
734
744
|
#### Fetch and tools
|
|
735
745
|
|
|
736
|
-
- **Webpage Fetching (`web_fetch`)** — Allows the agent to read full webpage contents (official `dsh-web-fetch-http` provider, pure JS, zero extra dependencies); it can take over `web.fetchProvider` with the plugin's direct → browser render → exa / firecrawl → crawl4ai quality chain. The headless browser tier can be switched off in Settings and the exa/firecrawl order is configurable; loopback, private-network and cloud-metadata addresses are rejected (SSRF guard).
|
|
746
|
+
- **Webpage Fetching (`web_fetch`)** — Allows the agent to read full webpage contents (official `dsh-web-fetch-http` provider, pure JS, zero extra dependencies); it can take over `web.fetchProvider` with the plugin's direct → browser render → exa / firecrawl → crawl4ai quality chain. The headless browser tier can be switched off in Settings and the exa/firecrawl order is configurable; loopback, private-network and cloud-metadata addresses are rejected (SSRF guard). Clash / mihomo TUN fake-ip ranges (usually 198.18.0.0/15) can be allowed explicitly under extra allowed networks, otherwise the placeholder addresses returned by system DNS are rejected as private.
|
|
737
747
|
|
|
738
748
|
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-free-search/master/assets/ui-fetch.png" alt="Fetch and platforms: web_fetch takeover, key storage and platform switches" width="100%" />
|
|
739
749
|
<sub>▲ Fetch: web_fetch takeover, key storage location and platform search switches</sub>
|
|
@@ -741,7 +751,7 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
741
751
|
- **Platform Search (`platform_search`)** — Search GitHub / V2EX / Bilibili / Reddit / Hacker News / Stack Overflow / Wikipedia / npm / YouTube / Vimeo / Juejin / Douban / Qiita (public APIs or keyless scraping, zero extra dependencies); X (Twitter) goes through the local Grok Build CLI (SuperGrok / X Premium sign-in).
|
|
742
752
|
- **Vertical Lookups (`domain_search`)** — Direct lookup in 41 keyless vertical sources: packages/versions (PyPI, crates, GitHub releases, endoflife…), academia (arXiv, Crossref, OpenAlex, Semantic Scholar, PubMed, dblp, Zenodo…), security (NVD, OSV, CISA KEV), finance (SEC EDGAR, IMF, World Bank, CFETS, Yahoo Finance, CoinGecko…), law (US Federal Register, US CourtListener, openlegaldata, UK legislation), news (Google News, GDELT) and more.
|
|
743
753
|
- **Video Search (`video_search`)** — Find videos across the web via Bing Videos + DuckDuckGo Videos (keyless, mutual fallback), returning video links with titles and publisher/duration metadata.
|
|
744
|
-
- **One-Call Research (`research`)** — Concurrent multi-engine search → candidate rerank → tiered body fetch → window selection → an evidence pack with provenance as Markdown; every model component (rerank / embedding / decision model) is optional and silently falls back to the rule path when missing or failing.
|
|
754
|
+
- **One-Call Research (`research`)** — Concurrent multi-engine search → candidate rerank → tiered body fetch → window selection → an evidence pack with provenance as Markdown; every model component (rerank / embedding / decision model) is optional and silently falls back to the rule path when missing or failing; the output carries an evidence quality gate (high / medium / low with a conclusion cap) and says so when the evidence is too thin.
|
|
745
755
|
- **Search Fetched Bodies (`cache_search`)** — Full-text search over the bodies `research` already fetched (`node:sqlite` persistent cache, 7-day retention; degrades to a no-op whenever `node:sqlite` is unavailable — unflagged from 22.13, while 22.5–22.12 needs `--experimental-sqlite`).
|
|
746
756
|
- **Clean Integration** — Implements the official `WebSearchProvider` seam interface, coexisting seamlessly with official plugins.
|
|
747
757
|
- **Time Filtering** — The `advanced_search` tool supports `timeRange`: fixed tiers, custom relative values, or an absolute date (details below).
|
|
@@ -806,6 +816,7 @@ If this plugin has been helpful, a ⭐ on [GitHub](https://github.com/DDDMUC/dsh
|
|
|
806
816
|
| `serply` | Serply | Paid | Requires `SERPLY_API_KEY` (serply.io, 2,500 free credits for the first 30 days); Google web results localized to the settings language |
|
|
807
817
|
| `outcrawl` | Outcrawl | Paid | Requires `OUTCRAWL_API_KEY` (outcrawl.ai, free tier of 1,000 credits a month); web results with title, URL and snippet, up to 20 per search |
|
|
808
818
|
| `google` | Google Programmable Search | Free quota | Requires `GOOGLE_CSE_API_KEY` and a Programmable Search Engine ID (`googleCseId` / cx); official Custom Search JSON API, 100 free queries/day then billed; supports `hl`, safe search and `dateRestrict` time filtering |
|
|
819
|
+
| `metaso` | Metaso (秘塔搜索) | Paid (credits) | Requires `METASO_API_KEY` (metaso.cn/api); official AI search API billed per call (about ¥0.03/query, trial credits for new accounts); supports webpage / document / scholar scopes and returns summaries with sources; not in the default fallback order, use it explicitly after configuring a key |
|
|
809
820
|
| `deepseek-official` | DeepSeek Official | Paid | Requires `DEEPSEEK_API_KEY`; uses the Anthropic-compatible `web_search` server tool, so every search is a full model turn (slow, token-billed) |
|
|
810
821
|
| `deepseek-tools` | DeepSeek Native Search API | Paid | Requires `DEEPSEEK_API_KEY` (shared with the row above); calls `POST /v1/tools/search` directly, no model involved, returns structured `results[]` (`title`/`url`/`summary`/`date`) — measured ~0.3s vs ~5-6s for the row above on the same query |
|
|
811
822
|
| `baidu` | Baidu Qianfan AI Search | Quota | Requires `BAIDU_API_KEY` (Qianfan AI Search, 50 free calls/day then pay-as-you-go); Chinese web-wide, supports time filtering |
|
|
@@ -937,7 +948,7 @@ After installation, open the config page (DSH 0.2.1-rc.2+):
|
|
|
937
948
|
The config page provides:
|
|
938
949
|
|
|
939
950
|
- **Search engine**: Select an engine from the dropdown; changes take effect immediately upon saving.
|
|
940
|
-
- **API keys**: Enter keys for Exa / Tavily / Keenable / Firecrawl / Parallel / Perplexity / DeepSeek / Google CSE / You.com (password fields; displayed as "configured" once saved; Exa / Tavily / Keenable / Firecrawl / Parallel / You.com work without a key too).
|
|
951
|
+
- **API keys**: Enter keys for Exa / Tavily / Keenable / Firecrawl / Parallel / Perplexity / DeepSeek / Google CSE / Metaso / You.com (password fields; displayed as "configured" once saved; Exa / Tavily / Keenable / Firecrawl / Parallel / You.com work without a key too).
|
|
941
952
|
- **Recommended**: store paid-engine keys in the harness credential center `~/.dsh/.credentials.yaml` (e.g. `DEEPSEEK_API_KEY: sk-...`, same as the official LLM providers — one place for all keys). Resolution order: credentials center > settings page > environment variable; the settings-page fields remain for backward compatibility.
|
|
942
953
|
- **Test engine**: Tests the selected engine directly (no fallback chain; paid engines without a key report an explicit error).
|
|
943
954
|
- **Use Bing default**: stage a switch back to the stable free Bing engine; `Discard` only cancels unsaved edits
|
|
@@ -1057,6 +1068,7 @@ disabledTools: [] # tools that are not registered at all (e.g. [domain
|
|
|
1057
1068
|
bingMarket: zh-CN # Bing market; empty = automatic (no mkt sent)
|
|
1058
1069
|
fetchProviderTakeover: true # false = keep the fetchProvider: http you pinned yourself
|
|
1059
1070
|
browserFetch: true # use the system browser headless renderer when direct fetch fails
|
|
1071
|
+
allowFakeIpCidrs: [] # reserved ranges to allow explicitly, e.g. 198.18.0.0/15 for Clash/mihomo fake-ip
|
|
1060
1072
|
fetchPrefer: exa # exa | firecrawl — which keyed fetch tier to try first
|
|
1061
1073
|
region: cn-zh # DuckDuckGo region (optional)
|
|
1062
1074
|
searxngInstances: # Custom SearXNG instances (optional)
|
|
@@ -1083,6 +1095,8 @@ serplyApiKey: ... # Or configure via the web settings UI
|
|
|
1083
1095
|
outcrawlApiKey: ... # Or configure via the web settings UI
|
|
1084
1096
|
googleCseApiKey: ... # Google Custom Search API key
|
|
1085
1097
|
googleCseId: "..." # Programmable Search Engine cx
|
|
1098
|
+
metasoApiKey: ... # Metaso API key (metaso.cn/api)
|
|
1099
|
+
metasoScope: webpage # webpage | document | scholar
|
|
1086
1100
|
deepseekApiKey: ...
|
|
1087
1101
|
```
|
|
1088
1102
|
|
|
@@ -1170,7 +1184,7 @@ After searching, the agent can **read full webpage content** (e.g., *"Open the f
|
|
|
1170
1184
|
|
|
1171
1185
|
- Automatically follows redirects and decodes HTML to plain text.
|
|
1172
1186
|
- Supports timeout and response size limits.
|
|
1173
|
-
- ⚠️ Note: `web_fetch`
|
|
1187
|
+
- ⚠️ Note: `web_fetch` rejects loopback, private, link-local and cloud-metadata addresses by default. Under Clash / mihomo TUN fake-ip DNS, add the fake-ip range (usually `198.18.0.0/15`) to extra allowed networks in Settings, otherwise every proxied host resolves to a placeholder address and is rejected; only allow fake-ip reserved ranges, never RFC1918.
|
|
1174
1188
|
|
|
1175
1189
|
#### Platform Search (`platform_search`)
|
|
1176
1190
|
|
|
@@ -1244,7 +1258,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1244
1258
|
|
|
1245
1259
|
#### Offline self-check assertions (`tools/`)
|
|
1246
1260
|
|
|
1247
|
-
**Fifty-
|
|
1261
|
+
**Fifty-six** zero-dependency assertion scripts ship with the repo (**839 assertions** total): **no API keys, no network, no test framework**, Node ≥ 20. Run everything with `npm test`.
|
|
1248
1262
|
|
|
1249
1263
|
| Script | Covers | Run (count) |
|
|
1250
1264
|
|---|---|---|
|
|
@@ -1255,15 +1269,19 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1255
1269
|
| `assert-multi-policy.mjs` | multi execution policy: ceiling semantics / target-is-not-a-hard-minimum / credential eligibility before the ceiling / **Fast·Balanced·Deep presets** | `node tools/assert-multi-policy.mjs` (146) |
|
|
1256
1270
|
| `assert-multi-limit.mjs` | Multi result ceiling (#109): default 20 / hard max 100 / config normalisation, per-call maxResults clamped to the ceiling, tool copy and prompt state name the effective limit, settings field and save path | `node tools/assert-multi-limit.mjs` (6) |
|
|
1257
1271
|
| `assert-maintenance.mjs` | Maintenance surface: CI runs every assertion on Node 20/22/24 plus the packaging gate, the release script bumps / verifies / tags / can publish, and the restore-official-provider bridge and settings button are wired | `node tools/assert-maintenance.mjs` (4) |
|
|
1258
|
-
| `assert-engine-modules.mjs` | Engine layout: module files exist and are imported, implementations have left index.js, the client engine ids match the server catalog, the catalog covers
|
|
1272
|
+
| `assert-engine-modules.mjs` | Engine layout: module files exist and are imported, implementations have left index.js, the client engine ids match the server catalog, the catalog covers 37 engines with the right free/explicit flags, and index never reads an engine-private name | `node tools/assert-engine-modules.mjs` (6) |
|
|
1259
1273
|
| `assert-bing-relevance.mjs` | Bing relevance (#112): single-character CJK tokens removed, an unrelated substituted SERP rejected, genuinely relevant results accepted, a batch matching only a generic engine name rejected, one distinctive token covering half the query accepted, and explicit single-character/numeric behaviour | `node tools/assert-bing-relevance.mjs` (6) |
|
|
1274
|
+
| `assert-quality.mjs` | Research evidence gate: 8 sources / 3 domains / 3 bodies / 2 dates is high, 3 / 2 / 1 is medium, a single source or a degraded note is low, an empty package is low, and research wires the gate into schema, output and brief | `node tools/assert-quality.mjs` (6) |
|
|
1275
|
+
| `assert-dedupe.mjs` | Near-duplicate removal: identical text shares a MinHash signature, exact URLs and cross-site copies are dropped, different articles survive in order, the threshold is configurable, and both the provider and multi paths run it | `node tools/assert-dedupe.mjs` (6) |
|
|
1276
|
+
| `assert-intent-routing.mjs` | Intent routing: the five domains plus general, stable preference reordering, Auto head follows the domain, a custom fallback order is never reordered, time filtering still applies, and the wiring | `node tools/assert-intent-routing.mjs` (6) |
|
|
1260
1277
|
| `assert-result-ranking.mjs` | merged ranking: **eTLD+1 same-site detection** / domain round-robin / `seenIn` demoted / freshness only under a time filter | `node tools/assert-result-ranking.mjs` (31) |
|
|
1261
1278
|
| `assert-url-norm.mjs` | URL normalization: strips only audited tracking params, keeps params that may identify different resources | `node tools/assert-url-norm.mjs` (72) |
|
|
1262
1279
|
| `assert-prompt-contract.mjs` | system-prompt contract: **search ≠ fetch**, untrusted-data boundary, model engines only when explicitly selected | `node tools/assert-prompt-contract.mjs` (9) |
|
|
1263
1280
|
| `assert-research-degradation.mjs` | research degrades fully without keys, `node:sqlite` no-op, 90s budget isolation, configurable cache dir, `budget.exhausted` contract names | `node tools/assert-research-degradation.mjs` (19) |
|
|
1264
1281
|
| `assert-research-call-wrappers.mjs` | the four research `call*` wrappers proxy to stubs / the real layer (#75 regression) | `node tools/assert-research-call-wrappers.mjs` (23) |
|
|
1265
1282
|
| `assert-fetch-chain.mjs` | `fs-quality-fetch` tier ordering, stop-on-first-success, silent firecrawl degradation, aggregated all-tiers failure | `node tools/assert-fetch-chain.mjs` (8) |
|
|
1266
|
-
| `assert-fetch-ssrf.mjs` | Fetch SSRF guard: public/private/reserved address classification, DNS resolving to a private address rejected, localhost and IP literals rejected, non-HTTPS and credential URLs rejected, provider wiring and settings | `node tools/assert-fetch-ssrf.mjs` (
|
|
1283
|
+
| `assert-fetch-ssrf.mjs` | Fetch SSRF guard: public/private/reserved address classification, DNS resolving to a private address rejected, localhost and IP literals rejected, non-HTTPS and credential URLs rejected, fake-ip ranges blocked by default and allowed only when configured, loopback/RFC1918 still blocked after opt-in, provider wiring and settings | `node tools/assert-fetch-ssrf.mjs` (8) |
|
|
1284
|
+
| `assert-metaso.mjs` | Metaso search: key required, request body (q/scope/size/summary/raw/concise), summary and date mapping, document array, size clamp, invalid scope fallback, 401/402/429/400 error classes, registration and default-chain exclusion | `node tools/assert-metaso.mjs` (6) |
|
|
1267
1285
|
| `assert-google-cse.mjs` | Google Custom Search: key + ID required, request params (q/num/start/hl/safe/dateRestrict), result mapping with dates, pagination past ten results, 403/429/400 classification, time-range mapping, full registration | `node tools/assert-google-cse.mjs` (6) |
|
|
1268
1286
|
| `assert-engine-runtime.mjs` | Engine runtime: per-engine concurrency caps (2 normally, 1 for HTML SERP), queueing with abort cleanup, ok/empty/fail/average-latency stats, wiring on both the provider and runEngineTest paths, and stats in the doctor report | `node tools/assert-engine-runtime.mjs` (4) |
|
|
1269
1287
|
| `assert-single-fetch-layer.mjs` | exactly one fetch implementation repo-wide, one-way deps, seams owned by the right layer | `node tools/assert-single-fetch-layer.mjs` (22) |
|
package/lib/client.js
CHANGED
|
@@ -431,12 +431,21 @@ window.__ModuleLoader__.load({
|
|
|
431
431
|
fetchTakeoverHint: "开启时:web.fetchProvider 未设置或仍是出厂默认 http 会接管为 fs-quality-fetch。如果你刻意 pin 了 http(例如只想用内置抓取),关掉此项。",
|
|
432
432
|
browserFetchLabel: "用本机浏览器渲染",
|
|
433
433
|
browserFetchHint: "直连失败时用系统 Chrome/Edge 无头加载页面,能过 JS 挑战;没有浏览器时自动跳过。",
|
|
434
|
+
fakeIpCidrsLabel: "额外允许的网段(fake-ip 透明代理)",
|
|
435
|
+
fakeIpCidrsHint: "一行一个 CIDR。Clash/mihomo TUN 的 fake-ip 通常是 198.18.0.0/15;只豁免这里列出的保留段,回环、私网、链路本地和云元数据仍会被拦截。",
|
|
434
436
|
fetchPreferLabel: "抓取质量链顺序",
|
|
435
437
|
fetchPreferExa: "Exa 优先",
|
|
436
438
|
fetchPreferFirecrawl: "Firecrawl 优先",
|
|
437
439
|
fetchPreferHint: "直连和浏览器都失败后先试哪个;只有两个都配了 key 时才有区别。",
|
|
438
440
|
googleCseIdLabel: "Google 搜索引擎 ID",
|
|
439
441
|
googleCseIdHint: "Programmable Search Engine 的 cx(形如 0123…:abc…);配合 GOOGLE_CSE_API_KEY 使用,免费 100 次/天。",
|
|
442
|
+
metasoKeyLabel: "秘塔 API key",
|
|
443
|
+
metasoKeyHint: "在 metaso.cn/api 创建;按点数计费,新用户有体验额度。",
|
|
444
|
+
metasoScopeLabel: "秘塔搜索范围",
|
|
445
|
+
metasoScopeWebpage: "网页",
|
|
446
|
+
metasoScopeDocument: "文库",
|
|
447
|
+
metasoScopeScholar: "学术",
|
|
448
|
+
metasoScopeHint: "网页最通用;文库面向 PDF/文档,学术面向论文,单次消耗更高。",
|
|
440
449
|
restoreOfficial: "恢复官方搜索",
|
|
441
450
|
restoreOfficialHint: "把 web.searchProvider 改回 deepseek-official、web.fetchProvider 改回 http。停用或卸载本插件前建议先点一次,避免宿主报 configured web provider \"ddg\" is not registered。",
|
|
442
451
|
restoringOfficial: "恢复中…",
|
|
@@ -595,12 +604,21 @@ window.__ModuleLoader__.load({
|
|
|
595
604
|
fetchTakeoverHint: "On: when web.fetchProvider is unset or still the factory default http, it is taken over as fs-quality-fetch. Turn this off if you deliberately pinned http (e.g. you only want the built-in fetcher).",
|
|
596
605
|
browserFetchLabel: "Render with the local browser",
|
|
597
606
|
browserFetchHint: "When direct fetch fails, load the page in headless Chrome/Edge to pass JS challenges; skipped when no browser is installed.",
|
|
607
|
+
fakeIpCidrsLabel: "Extra allowed networks (fake-ip proxy)",
|
|
608
|
+
fakeIpCidrsHint: "One CIDR per line. Clash/mihomo TUN fake-ip commonly uses 198.18.0.0/15; only the ranges listed here are exempted. Loopback, RFC1918, link-local and cloud metadata stay blocked.",
|
|
598
609
|
fetchPreferLabel: "Fetch quality-chain order",
|
|
599
610
|
fetchPreferExa: "Exa first",
|
|
600
611
|
fetchPreferFirecrawl: "Firecrawl first",
|
|
601
612
|
fetchPreferHint: "Which keyed tier to try first after direct and browser both fail; only matters when both keys are configured.",
|
|
602
613
|
googleCseIdLabel: "Google Programmable Search engine ID",
|
|
603
614
|
googleCseIdHint: "The cx from Programmable Search Engine (looks like 0123…:abc…); used with GOOGLE_CSE_API_KEY, free 100 queries/day.",
|
|
615
|
+
metasoKeyLabel: "Metaso API key",
|
|
616
|
+
metasoKeyHint: "Create one at metaso.cn/api; billed per call, new accounts get trial credits.",
|
|
617
|
+
metasoScopeLabel: "Metaso search scope",
|
|
618
|
+
metasoScopeWebpage: "Webpages",
|
|
619
|
+
metasoScopeDocument: "Documents",
|
|
620
|
+
metasoScopeScholar: "Scholars",
|
|
621
|
+
metasoScopeHint: "Webpages is the general default; documents targets PDFs/files and scholars targets papers, both cost more per call.",
|
|
604
622
|
restoreOfficial: "Restore official search",
|
|
605
623
|
restoreOfficialHint: "Sets web.searchProvider back to deepseek-official and web.fetchProvider back to http. Run this before disabling or uninstalling the plugin, otherwise the host reports configured web provider \"ddg\" is not registered.",
|
|
606
624
|
restoringOfficial: "Restoring…",
|
|
@@ -650,7 +668,7 @@ window.__ModuleLoader__.load({
|
|
|
650
668
|
"cache_search",
|
|
651
669
|
"domain_search",
|
|
652
670
|
];
|
|
653
|
-
const PLUGIN_VERSION = "0.9.
|
|
671
|
+
const PLUGIN_VERSION = "0.9.42";
|
|
654
672
|
const PLUGIN_REPO_URL = "https://github.com/DDDMUC/dsh-free-search";
|
|
655
673
|
// 右侧浮动目录(#85):条目顺序即页面顺序,anchor 是页面里对应 field 的 id。
|
|
656
674
|
const NAV_ITEMS = [
|
|
@@ -691,6 +709,7 @@ window.__ModuleLoader__.load({
|
|
|
691
709
|
{ id: "serply", label: "Serply · Google", badge: "API KEY", link: "https://serply.io" },
|
|
692
710
|
{ id: "outcrawl", label: "Outcrawl", badge: "API KEY", link: "https://outcrawl.ai" },
|
|
693
711
|
{ id: "google", label: "Google · 自定义搜索", badge: "API KEY", link: "https://developers.google.com/custom-search/v1/overview" },
|
|
712
|
+
{ id: "metaso", label: "Metaso · 秘塔搜索", badge: "API KEY", link: "https://metaso.cn/api" },
|
|
694
713
|
{ id: "deepseek-official", label: "DeepSeek Official", badge: "API KEY", link: "https://platform.deepseek.com/api_keys" },
|
|
695
714
|
{ id: "deepseek-tools", label: "DeepSeek Tools API", badge: "API KEY", link: "https://api-docs.deepseek.com/zh-cn/guides/search" },
|
|
696
715
|
{ id: "you", label: "You.com", badge: "FREE", link: "https://you.com/platform/api-keys" },
|
|
@@ -714,10 +733,10 @@ window.__ModuleLoader__.load({
|
|
|
714
733
|
];
|
|
715
734
|
const ENGINE_IDS = ENGINES.filter((engine) => engine.id !== "auto" && engine.id !== "multi").map((engine) => engine.id);
|
|
716
735
|
// 与 lib/index.js 的 EXPLICIT_ONLY_ENGINES 同源:按次计费、只在显式选中时运行,因此不提供入池候选。
|
|
717
|
-
const EXPLICIT_ONLY_ENGINES = ["openai", "gemini", "claude"];
|
|
736
|
+
const EXPLICIT_ONLY_ENGINES = ["openai", "gemini", "claude", "metaso"];
|
|
718
737
|
// 与 lib/serp_engines.js 的 SERP_ENGINE_IDS 同源:HTML 抓取型引擎,默认不进自动回退链。
|
|
719
738
|
const SERP_ENGINE_IDS = ["baidu-html", "so360", "sogou", "wechat", "toutiao"];
|
|
720
|
-
const MODEL_ENGINES = ENGINES.filter((engine) => EXPLICIT_ONLY_ENGINES.includes(engine.id));
|
|
739
|
+
const MODEL_ENGINES = ENGINES.filter((engine) => EXPLICIT_ONLY_ENGINES.includes(engine.id) && engine.id !== "metaso");
|
|
721
740
|
const DEFAULT_FALLBACK_ORDER = ["exa", "tavily", "keenable", "firecrawl", "parallel", "perplexity", "serpbase", "serply", "outcrawl", "agy", "deepseek-tools", "deepseek-official", "you", "baidu", "kimi", "aliyun", "doubao", "tinyfish", "jina", "bing", "anysearch", "ddg", "ddg-lite", "searxng", "degoog", "zhihu_global", "zhihu_site"];
|
|
722
741
|
const normalizeFallbackOrder = (value) => {
|
|
723
742
|
const configured = Array.isArray(value) ? value.filter((id) => ENGINE_IDS.includes(id)) : [];
|
|
@@ -916,6 +935,7 @@ window.__ModuleLoader__.load({
|
|
|
916
935
|
const [bingMarket, setBingMarket] = react.useState("zh-CN");
|
|
917
936
|
const [fetchProviderTakeover, setFetchProviderTakeover] = react.useState(true);
|
|
918
937
|
const [browserFetch, setBrowserFetch] = react.useState(true);
|
|
938
|
+
const [allowFakeIpCidrs, setAllowFakeIpCidrs] = react.useState("");
|
|
919
939
|
const [fetchPrefer, setFetchPrefer] = react.useState("exa");
|
|
920
940
|
const [anysearchKey, setAnysearchKey] = react.useState("");
|
|
921
941
|
const [exaKey, setExaKey] = react.useState("");
|
|
@@ -930,6 +950,8 @@ window.__ModuleLoader__.load({
|
|
|
930
950
|
const [outcrawlKey, setOutcrawlKey] = react.useState("");
|
|
931
951
|
const [googleKey, setGoogleKey] = react.useState("");
|
|
932
952
|
const [googleCx, setGoogleCx] = react.useState("");
|
|
953
|
+
const [metasoKey, setMetasoKey] = react.useState("");
|
|
954
|
+
const [metasoScope, setMetasoScope] = react.useState("webpage");
|
|
933
955
|
const [youcomKey, setYoucomKey] = react.useState("");
|
|
934
956
|
const [baiduKey, setBaiduKey] = react.useState("");
|
|
935
957
|
const [kimiKey, setKimiKey] = react.useState("");
|
|
@@ -1082,6 +1104,7 @@ window.__ModuleLoader__.load({
|
|
|
1082
1104
|
setBingMarket(v.bingMarket === undefined ? "zh-CN" : v.bingMarket);
|
|
1083
1105
|
setFetchProviderTakeover(v.fetchProviderTakeover !== false);
|
|
1084
1106
|
setBrowserFetch(v.browserFetch !== false);
|
|
1107
|
+
setAllowFakeIpCidrs((Array.isArray(v.allowFakeIpCidrs) ? v.allowFakeIpCidrs : []).join("\n"));
|
|
1085
1108
|
setFetchPrefer(v.fetchPrefer === "firecrawl" ? "firecrawl" : "exa");
|
|
1086
1109
|
setLang(v.lang ?? "zh");
|
|
1087
1110
|
setUiLang(typeof v.uiLang === "string" ? v.uiLang : "");
|
|
@@ -1105,6 +1128,8 @@ window.__ModuleLoader__.load({
|
|
|
1105
1128
|
setOutcrawlKey(v.outcrawlApiKey ?? "");
|
|
1106
1129
|
setGoogleKey(v.googleCseApiKey ?? "");
|
|
1107
1130
|
setGoogleCx(v.googleCseId ?? "");
|
|
1131
|
+
setMetasoKey(v.metasoApiKey ?? "");
|
|
1132
|
+
setMetasoScope(v.metasoScope === "document" || v.metasoScope === "scholar" ? v.metasoScope : "webpage");
|
|
1108
1133
|
setYoucomKey(v.youcomApiKey ?? "");
|
|
1109
1134
|
setBaiduKey(v.baiduApiKey ?? "");
|
|
1110
1135
|
setKimiKey(v.kimiApiKey ?? "");
|
|
@@ -1154,6 +1179,7 @@ window.__ModuleLoader__.load({
|
|
|
1154
1179
|
if (path === "searxngBearerToken") configured.searxng = true;
|
|
1155
1180
|
if (path === "degoogApiKey") configured.degoog = true;
|
|
1156
1181
|
if (path === "googleCseApiKey") configured.google = true;
|
|
1182
|
+
if (path === "metasoApiKey") configured.metaso = true;
|
|
1157
1183
|
}
|
|
1158
1184
|
}
|
|
1159
1185
|
setKeysConfigured(configured);
|
|
@@ -1165,7 +1191,7 @@ window.__ModuleLoader__.load({
|
|
|
1165
1191
|
const cred = await bridgeCredentialsStatus();
|
|
1166
1192
|
if (cred.ok) {
|
|
1167
1193
|
const cc = {};
|
|
1168
|
-
const map = { anysearchApiKey: "anysearch", exaApiKey: "exa", tavilyApiKey: "tavily", keenableApiKey: "keenable", firecrawlApiKey: "firecrawl", parallelApiKey: "parallel", perplexityApiKey: "perplexity", deepseekApiKey: "deepseek", serpbaseApiKey: "serpbase", serplyApiKey: "serply", outcrawlApiKey: "outcrawl", youcomApiKey: "youcom", degoogApiKey: "degoog", googleCseApiKey: "google", baiduApiKey: "baidu", kimiApiKey: "kimi", aliyunApiKey: "aliyun", doubaoApiKey: "doubao", openaiApiKey: "openai", geminiApiKey: "gemini", claudeApiKey: "claude", zhihuApiKey: "zhihu", tinyfishApiKey: "tinyfish", jinaApiKey: "jina", searxngBearerToken: "searxng" };
|
|
1194
|
+
const map = { anysearchApiKey: "anysearch", exaApiKey: "exa", tavilyApiKey: "tavily", keenableApiKey: "keenable", firecrawlApiKey: "firecrawl", parallelApiKey: "parallel", perplexityApiKey: "perplexity", deepseekApiKey: "deepseek", serpbaseApiKey: "serpbase", serplyApiKey: "serply", outcrawlApiKey: "outcrawl", youcomApiKey: "youcom", degoogApiKey: "degoog", googleCseApiKey: "google", metasoApiKey: "metaso", baiduApiKey: "baidu", kimiApiKey: "kimi", aliyunApiKey: "aliyun", doubaoApiKey: "doubao", openaiApiKey: "openai", geminiApiKey: "gemini", claudeApiKey: "claude", zhihuApiKey: "zhihu", tinyfishApiKey: "tinyfish", jinaApiKey: "jina", searxngBearerToken: "searxng" };
|
|
1169
1195
|
for (const [k, v] of Object.entries(cred.value.configured ?? {})) {
|
|
1170
1196
|
if (map[k]) cc[map[k]] = v;
|
|
1171
1197
|
}
|
|
@@ -1214,6 +1240,7 @@ window.__ModuleLoader__.load({
|
|
|
1214
1240
|
["serplyApiKey", serplyKey],
|
|
1215
1241
|
["outcrawlApiKey", outcrawlKey],
|
|
1216
1242
|
["googleCseApiKey", googleKey],
|
|
1243
|
+
["metasoApiKey", metasoKey],
|
|
1217
1244
|
["youcomApiKey", youcomKey],
|
|
1218
1245
|
["baiduApiKey", baiduKey],
|
|
1219
1246
|
["kimiApiKey", kimiKey],
|
|
@@ -1260,7 +1287,13 @@ window.__ModuleLoader__.load({
|
|
|
1260
1287
|
ops.push({ op: "set", path: ["bingMarket"], value: bingMarket });
|
|
1261
1288
|
ops.push({ op: "set", path: ["fetchProviderTakeover"], value: fetchProviderTakeover });
|
|
1262
1289
|
ops.push({ op: "set", path: ["googleCseId"], value: googleCx.trim() });
|
|
1290
|
+
ops.push({ op: "set", path: ["metasoScope"], value: metasoScope === "document" || metasoScope === "scholar" ? metasoScope : "webpage" });
|
|
1263
1291
|
ops.push({ op: "set", path: ["browserFetch"], value: browserFetch });
|
|
1292
|
+
ops.push({
|
|
1293
|
+
op: "set",
|
|
1294
|
+
path: ["allowFakeIpCidrs"],
|
|
1295
|
+
value: [...new Set(String(allowFakeIpCidrs ?? "").split(/[\s,]+/).map((s) => s.trim()).filter(Boolean))],
|
|
1296
|
+
});
|
|
1264
1297
|
ops.push({ op: "set", path: ["fetchPrefer"], value: fetchPrefer === "firecrawl" ? "firecrawl" : "exa" });
|
|
1265
1298
|
if (keyStorage !== "credentials") {
|
|
1266
1299
|
// settings 模式:key 写入当前 profile 的插件条目 config(cordis.patch.yml)
|
|
@@ -2034,6 +2067,63 @@ react_jsx_runtime.jsx("div", {
|
|
|
2034
2067
|
}),
|
|
2035
2068
|
],
|
|
2036
2069
|
}),
|
|
2070
|
+
react_jsx_runtime.jsx("div", {
|
|
2071
|
+
className: "dshfs-field",
|
|
2072
|
+
children: [
|
|
2073
|
+
react_jsx_runtime.jsx("div", {
|
|
2074
|
+
className: "dshfs-label",
|
|
2075
|
+
children: t.metasoKeyLabel,
|
|
2076
|
+
}),
|
|
2077
|
+
react_jsx_runtime.jsx("input", {
|
|
2078
|
+
className: "dshfs-input",
|
|
2079
|
+
type: "password",
|
|
2080
|
+
value: metasoKey,
|
|
2081
|
+
spellCheck: false,
|
|
2082
|
+
placeholder: "API key",
|
|
2083
|
+
disabled: !ready || saving,
|
|
2084
|
+
onChange: (e) => {
|
|
2085
|
+
setMetasoKey(e.target.value);
|
|
2086
|
+
setDirty(true);
|
|
2087
|
+
setFailed(false);
|
|
2088
|
+
setSaveError("");
|
|
2089
|
+
},
|
|
2090
|
+
}),
|
|
2091
|
+
react_jsx_runtime.jsx("p", {
|
|
2092
|
+
className: "dshfs-hint",
|
|
2093
|
+
children: t.metasoKeyHint,
|
|
2094
|
+
}),
|
|
2095
|
+
],
|
|
2096
|
+
}),
|
|
2097
|
+
react_jsx_runtime.jsx("div", {
|
|
2098
|
+
className: "dshfs-field",
|
|
2099
|
+
children: [
|
|
2100
|
+
react_jsx_runtime.jsx("div", {
|
|
2101
|
+
className: "dshfs-label",
|
|
2102
|
+
children: t.metasoScopeLabel,
|
|
2103
|
+
}),
|
|
2104
|
+
react_jsx_runtime.jsx("select", {
|
|
2105
|
+
className: "dshfs-select",
|
|
2106
|
+
value: metasoScope,
|
|
2107
|
+
style: { colorScheme: selectColorScheme },
|
|
2108
|
+
disabled: !ready || saving,
|
|
2109
|
+
onChange: (e) => {
|
|
2110
|
+
setMetasoScope(e.target.value === "document" || e.target.value === "scholar" ? e.target.value : "webpage");
|
|
2111
|
+
setDirty(true);
|
|
2112
|
+
setFailed(false);
|
|
2113
|
+
setSaveError("");
|
|
2114
|
+
},
|
|
2115
|
+
children: [
|
|
2116
|
+
react_jsx_runtime.jsx("option", { value: "webpage", children: t.metasoScopeWebpage }),
|
|
2117
|
+
react_jsx_runtime.jsx("option", { value: "document", children: t.metasoScopeDocument }),
|
|
2118
|
+
react_jsx_runtime.jsx("option", { value: "scholar", children: t.metasoScopeScholar }),
|
|
2119
|
+
],
|
|
2120
|
+
}),
|
|
2121
|
+
react_jsx_runtime.jsx("p", {
|
|
2122
|
+
className: "dshfs-hint",
|
|
2123
|
+
children: t.metasoScopeHint,
|
|
2124
|
+
}),
|
|
2125
|
+
],
|
|
2126
|
+
}),
|
|
2037
2127
|
react_jsx_runtime.jsx("div", {
|
|
2038
2128
|
className: "dshfs-field",
|
|
2039
2129
|
id: "dshfs-anchor-fallback",
|
|
@@ -2388,6 +2478,33 @@ react_jsx_runtime.jsx("div", {
|
|
|
2388
2478
|
}),
|
|
2389
2479
|
],
|
|
2390
2480
|
}),
|
|
2481
|
+
react_jsx_runtime.jsx("div", {
|
|
2482
|
+
className: "dshfs-field",
|
|
2483
|
+
children: [
|
|
2484
|
+
react_jsx_runtime.jsx("div", {
|
|
2485
|
+
className: "dshfs-label",
|
|
2486
|
+
children: t.fakeIpCidrsLabel,
|
|
2487
|
+
}),
|
|
2488
|
+
react_jsx_runtime.jsx("textarea", {
|
|
2489
|
+
className: "dshfs-textarea",
|
|
2490
|
+
rows: 3,
|
|
2491
|
+
placeholder: "198.18.0.0/15",
|
|
2492
|
+
value: allowFakeIpCidrs,
|
|
2493
|
+
spellCheck: false,
|
|
2494
|
+
disabled: !ready || saving,
|
|
2495
|
+
onChange: (e) => {
|
|
2496
|
+
setAllowFakeIpCidrs(e.target.value);
|
|
2497
|
+
setDirty(true);
|
|
2498
|
+
setFailed(false);
|
|
2499
|
+
setSaveError("");
|
|
2500
|
+
},
|
|
2501
|
+
}),
|
|
2502
|
+
react_jsx_runtime.jsx("p", {
|
|
2503
|
+
className: "dshfs-hint",
|
|
2504
|
+
children: t.fakeIpCidrsHint,
|
|
2505
|
+
}),
|
|
2506
|
+
],
|
|
2507
|
+
}),
|
|
2391
2508
|
react_jsx_runtime.jsx("div", {
|
|
2392
2509
|
className: "dshfs-field",
|
|
2393
2510
|
children: [
|
package/lib/dedupe.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Near-duplicate removal for merged search results. Syndicated copies usually
|
|
3
|
+
* differ in URL and a few characters, so exact-URL dedupe misses them; a small
|
|
4
|
+
* MinHash signature over title+snippet catches them without model calls.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const SEEDS = Array.from({ length: 16 }, (_, i) => (i + 1) * 0x9e3779b1);
|
|
8
|
+
|
|
9
|
+
function hash32(text, seed) {
|
|
10
|
+
let hash = (2166136261 ^ seed) >>> 0;
|
|
11
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
12
|
+
hash ^= text.charCodeAt(i);
|
|
13
|
+
hash = Math.imul(hash, 16777619);
|
|
14
|
+
}
|
|
15
|
+
return hash >>> 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalize(text) {
|
|
19
|
+
return String(text ?? "")
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/https?:\/\/\S+/g, " ")
|
|
22
|
+
.replace(/[\s\p{P}\p{S}]+/gu, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function shingles(text) {
|
|
26
|
+
const value = normalize(text);
|
|
27
|
+
if (value.length === 0) return [];
|
|
28
|
+
const size = value.length >= 6 ? 3 : Math.max(1, value.length);
|
|
29
|
+
const out = [];
|
|
30
|
+
for (let i = 0; i + size <= value.length; i += 1) out.push(value.slice(i, i + size));
|
|
31
|
+
return [...new Set(out)];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function minHash(text, size = SEEDS.length) {
|
|
35
|
+
const parts = shingles(text);
|
|
36
|
+
if (parts.length === 0) return Array.from({ length: size }, () => 0);
|
|
37
|
+
return SEEDS.slice(0, size).map((seed) => {
|
|
38
|
+
let min = 0xffffffff;
|
|
39
|
+
for (const part of parts) {
|
|
40
|
+
const value = hash32(part, seed);
|
|
41
|
+
if (value < min) min = value;
|
|
42
|
+
}
|
|
43
|
+
return min;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function similarity(a, b) {
|
|
48
|
+
if (a.length === 0 || b.length === 0 || a.length !== b.length) return 0;
|
|
49
|
+
let same = 0;
|
|
50
|
+
for (let i = 0; i < a.length; i += 1) if (a[i] === b[i]) same += 1;
|
|
51
|
+
return same / a.length;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Keep the first source of a near-duplicate group. Order is preserved; exact
|
|
56
|
+
* URL duplicates are also removed. Threshold 0.8 works for syndicated copies
|
|
57
|
+
* while leaving different articles with the same topic separate.
|
|
58
|
+
*/
|
|
59
|
+
export function dedupeNearDuplicates(sources, { threshold = 0.8, textOf = (source) => `${source?.title ?? ""} ${source?.snippet ?? ""}` } = {}) {
|
|
60
|
+
const list = Array.isArray(sources) ? sources : [];
|
|
61
|
+
const kept = [];
|
|
62
|
+
const signatures = [];
|
|
63
|
+
const exactUrls = new Set();
|
|
64
|
+
for (const source of list) {
|
|
65
|
+
const url = String(source?.url ?? "");
|
|
66
|
+
if (url && exactUrls.has(url)) continue;
|
|
67
|
+
const signature = minHash(textOf(source));
|
|
68
|
+
if (signatures.some((existing) => similarity(existing, signature) >= threshold)) continue;
|
|
69
|
+
if (url) exactUrls.add(url);
|
|
70
|
+
kept.push(source);
|
|
71
|
+
signatures.push(signature);
|
|
72
|
+
}
|
|
73
|
+
return kept;
|
|
74
|
+
}
|
package/lib/doctor.js
CHANGED
|
@@ -24,6 +24,8 @@ export function buildDoctorReport({
|
|
|
24
24
|
dshHome = "",
|
|
25
25
|
provider = "",
|
|
26
26
|
effectiveProvider = "",
|
|
27
|
+
searchProvider = "",
|
|
28
|
+
fetchProvider = "",
|
|
27
29
|
promptLanguage = "en",
|
|
28
30
|
promptChars = 0,
|
|
29
31
|
promptInjected = true,
|
|
@@ -38,6 +40,19 @@ export function buildDoctorReport({
|
|
|
38
40
|
lines.push(
|
|
39
41
|
`preferred: ${provider || "auto"}${provider ? "" : ` (resolves to ${effectiveProvider || "?"})`} · prompt ${promptLanguage}, ${promptChars} chars${promptInjected ? "" : ", not injected"}`
|
|
40
42
|
);
|
|
43
|
+
lines.push(`providers: search=${searchProvider || "auto"} · fetch=${fetchProvider || "auto"}`);
|
|
44
|
+
const warnings = [];
|
|
45
|
+
if (searchProvider && searchProvider !== "ddg" && searchProvider !== "deepseek-official") {
|
|
46
|
+
warnings.push(`search is served by "${searchProvider}", not this plugin; search providers are mutually exclusive (the last takeover wins)`);
|
|
47
|
+
}
|
|
48
|
+
if (fetchProvider && fetchProvider !== "fs-quality-fetch" && fetchProvider !== "http") {
|
|
49
|
+
warnings.push(`fetch is served by "${fetchProvider}", not this plugin; fetch providers are mutually exclusive`);
|
|
50
|
+
}
|
|
51
|
+
if (warnings.length > 0) {
|
|
52
|
+
lines.push("");
|
|
53
|
+
lines.push("warnings:");
|
|
54
|
+
for (const warning of warnings) lines.push(` - ${warning}`);
|
|
55
|
+
}
|
|
41
56
|
const enabledTools = toolsKnown.filter((id) => !tools.disabled.includes(id));
|
|
42
57
|
lines.push(`tools: ${enabledTools.length}/${toolsKnown.length} on${enabledTools.length ? ` (${enabledTools.join(", ")})` : ""}`);
|
|
43
58
|
lines.push("");
|
package/lib/engine_meta.js
CHANGED
|
@@ -24,6 +24,7 @@ const BASE_ENGINES = [
|
|
|
24
24
|
{ id: "serply", free: false, time: false },
|
|
25
25
|
{ id: "outcrawl", free: false, time: false },
|
|
26
26
|
{ id: "google", free: false, time: true },
|
|
27
|
+
{ id: "metaso", free: false, time: false, explicitOnly: true },
|
|
27
28
|
{ id: "deepseek-official", free: false, time: false },
|
|
28
29
|
{ id: "deepseek-tools", free: false, time: true },
|
|
29
30
|
{ id: "you", free: false, time: false },
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Metaso (秘塔搜索) official search API.
|
|
2
|
+
// POST https://metaso.cn/api/v1/search with a Bearer key; billed per call,
|
|
3
|
+
// so this engine is keyed and deliberately absent from the default fallback.
|
|
4
|
+
import { uniqueSources } from "./shared.js";
|
|
5
|
+
|
|
6
|
+
const METASO_URL = "https://metaso.cn/api/v1/search";
|
|
7
|
+
const MAX_RESULTS = 50;
|
|
8
|
+
|
|
9
|
+
export const METASO_SCOPES = ["webpage", "document", "scholar"];
|
|
10
|
+
|
|
11
|
+
const RESULT_ARRAYS = {
|
|
12
|
+
webpage: "webpages",
|
|
13
|
+
document: "documents",
|
|
14
|
+
scholar: "scholars",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function normalizeMetasoScope(value) {
|
|
18
|
+
const scope = String(value ?? "").trim().toLowerCase();
|
|
19
|
+
return METASO_SCOPES.includes(scope) ? scope : "webpage";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function metasoErrorMessage(status, detail) {
|
|
23
|
+
let upstream = "";
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(detail);
|
|
26
|
+
upstream = parsed?.message ?? parsed?.error ?? "";
|
|
27
|
+
} catch {}
|
|
28
|
+
const suffix = upstream ? `: ${String(upstream).slice(0, 200)}` : "";
|
|
29
|
+
if (status === 401) {
|
|
30
|
+
return "Metaso API key is invalid (HTTP 401) - update it in Settings > Plugins > Free Search";
|
|
31
|
+
}
|
|
32
|
+
if (status === 402) return `Metaso account has no usable credits (HTTP 402)${suffix}`;
|
|
33
|
+
if (status === 429) return `Metaso quota/rate limit exceeded (HTTP 429)${suffix}`;
|
|
34
|
+
if (status === 400) return `Metaso search request failed (HTTP 400)${suffix} - check the API key and scope`;
|
|
35
|
+
return `Metaso API error (HTTP ${status})${suffix}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function publishedDate(value) {
|
|
39
|
+
const text = String(value ?? "").trim();
|
|
40
|
+
return /^\d{4}-\d{2}-\d{2}/.test(text) ? text.slice(0, 10) : "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function searchMetaso(query, maxResults, apiKey, scope, _timeRange, signal) {
|
|
44
|
+
if (!apiKey) throw new Error("Metaso search requires METASO_API_KEY");
|
|
45
|
+
const limit = Math.min(Math.max(Number(maxResults) || 10, 1), MAX_RESULTS);
|
|
46
|
+
const normalizedScope = normalizeMetasoScope(scope);
|
|
47
|
+
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const timer = setTimeout(() => controller.abort(), 30000);
|
|
50
|
+
const onAbort = () => controller.abort();
|
|
51
|
+
signal?.addEventListener("abort", onAbort);
|
|
52
|
+
|
|
53
|
+
let response;
|
|
54
|
+
try {
|
|
55
|
+
response = await fetch(METASO_URL, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
redirect: "error",
|
|
58
|
+
headers: {
|
|
59
|
+
authorization: `Bearer ${apiKey}`,
|
|
60
|
+
"content-type": "application/json",
|
|
61
|
+
accept: "application/json",
|
|
62
|
+
"user-agent": "deepseek-harness/free-search",
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
q: query,
|
|
66
|
+
scope: normalizedScope,
|
|
67
|
+
size: limit,
|
|
68
|
+
includeSummary: true,
|
|
69
|
+
includeRawContent: false,
|
|
70
|
+
conciseSnippet: true,
|
|
71
|
+
}),
|
|
72
|
+
signal: controller.signal,
|
|
73
|
+
});
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (signal?.aborted) throw error;
|
|
76
|
+
if (error?.name === "AbortError") throw new Error("Metaso request timed out");
|
|
77
|
+
throw new Error(`Metaso request failed: ${error?.message ?? String(error)}`);
|
|
78
|
+
} finally {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
signal?.removeEventListener("abort", onAbort);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
const detail = await response.text().catch(() => "");
|
|
85
|
+
throw new Error(metasoErrorMessage(response.status, detail));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let data;
|
|
89
|
+
try {
|
|
90
|
+
data = await response.json();
|
|
91
|
+
} catch {
|
|
92
|
+
throw new Error("Metaso returned an invalid JSON response");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const items = Array.isArray(data?.[RESULT_ARRAYS[normalizedScope]]) ? data[RESULT_ARRAYS[normalizedScope]] : [];
|
|
96
|
+
const sources = items
|
|
97
|
+
.map((item) => {
|
|
98
|
+
const url = String(item?.link ?? "").trim();
|
|
99
|
+
if (!url) return null;
|
|
100
|
+
const snippet = String(item?.summary ?? item?.snippet ?? "").trim();
|
|
101
|
+
const date = publishedDate(item?.date);
|
|
102
|
+
return {
|
|
103
|
+
url,
|
|
104
|
+
...(item?.title ? { title: String(item.title) } : {}),
|
|
105
|
+
...(snippet ? { snippet } : {}),
|
|
106
|
+
...(date ? { publishedAt: date } : {}),
|
|
107
|
+
};
|
|
108
|
+
})
|
|
109
|
+
.filter(Boolean);
|
|
110
|
+
|
|
111
|
+
return { sources: uniqueSources(sources, limit), truncated: false };
|
|
112
|
+
}
|
package/lib/fetch_provider.js
CHANGED
|
@@ -13,7 +13,7 @@ import { tmpdir } from "node:os";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import { callExa, callFirecrawl, callCrawl4ai } from "./fetch_upstream.js";
|
|
15
15
|
import { stripLoneSurrogates } from "./safe_text.js";
|
|
16
|
-
import { assertPublicUrl,
|
|
16
|
+
import { assertPublicUrl, makeSafeLookup } from "./ssrf.js";
|
|
17
17
|
|
|
18
18
|
const T1_MIN_CHARS = 300;
|
|
19
19
|
const TEXTUAL = /text\/|json|xml|javascript|application\/json/i;
|
|
@@ -303,6 +303,7 @@ export function createFetchProvider({
|
|
|
303
303
|
acceptLanguage = () => "en-US,en;q=0.9",
|
|
304
304
|
browserEnabled = () => true,
|
|
305
305
|
prefer = () => "exa",
|
|
306
|
+
allowedCidrs = () => [],
|
|
306
307
|
validateUrl = assertPublicUrl,
|
|
307
308
|
}) {
|
|
308
309
|
return {
|
|
@@ -313,13 +314,15 @@ export function createFetchProvider({
|
|
|
313
314
|
const url = String(request?.url || "");
|
|
314
315
|
if (!/^https:\/\//i.test(url)) throw new Error(`fs-quality-fetch: only https URLs are supported (got "${url.slice(0, 60)}")`);
|
|
315
316
|
// SSRF guard: never fetch loopback / private / metadata addresses, and use a
|
|
316
|
-
// lookup that re-checks every redirect hop.
|
|
317
|
-
|
|
317
|
+
// lookup that re-checks every redirect hop. Explicitly allowed CIDRs cover
|
|
318
|
+
// transparent-proxy fake-ip ranges (Clash/mihomo 198.18.0.0/15).
|
|
319
|
+
const allowed = allowedCidrs();
|
|
320
|
+
await validateUrl(url, { allowedCidrs: allowed });
|
|
318
321
|
const errors = [];
|
|
319
322
|
|
|
320
323
|
// T1:直连(文本类内容;二进制交给后层——exa 取正文,PDF 等仍由 firecrawl 处理)
|
|
321
324
|
try {
|
|
322
|
-
const r = await httpsGetFollow(url, { headers: browserishHeaders(acceptLanguage()), signal, lookup:
|
|
325
|
+
const r = await httpsGetFollow(url, { headers: browserishHeaders(acceptLanguage()), signal, lookup: makeSafeLookup(allowed) });
|
|
323
326
|
if (r.status < 400 && TEXTUAL.test(r.contentType) && r.text.length >= T1_MIN_CHARS) {
|
|
324
327
|
return { url: r.url, statusCode: r.status, body: { kind: "html", content: stripLoneSurrogates(r.text) }, truncated: false };
|
|
325
328
|
}
|
package/lib/index.js
CHANGED
|
@@ -40,7 +40,10 @@ import { searchSerpbase } from "./engines/serpbase.js";
|
|
|
40
40
|
import { searchSerply } from "./engines/serply.js";
|
|
41
41
|
import { searchOutcrawl } from "./engines/outcrawl.js";
|
|
42
42
|
import { searchGoogle } from "./engines/google.js";
|
|
43
|
+
import { searchMetaso } from "./engines/metaso.js";
|
|
43
44
|
import { createEngineRuntime, ENGINE_CONCURRENCY_LIMIT, SERP_CONCURRENCY_LIMIT } from "./engine_runtime.js";
|
|
45
|
+
import { classifyIntent, preferForIntent } from "./intent.js";
|
|
46
|
+
import { dedupeNearDuplicates } from "./dedupe.js";
|
|
44
47
|
import { searchYoucom, resolveYoucomApiKey } from "./engines/you.js";
|
|
45
48
|
import { searchTinyfish } from "./engines/tinyfish.js";
|
|
46
49
|
import { searchJina } from "./engines/jina.js";
|
|
@@ -409,14 +412,15 @@ function routeEngines(query, { timeRange, disabledEngines = [], fallbackOrder =
|
|
|
409
412
|
? enabled.filter((engine) => routeHead.includes(engine))
|
|
410
413
|
: routeHead.filter((engine) => enabledSet.has(engine));
|
|
411
414
|
|
|
415
|
+
const routerHead = hasCustomOrder ? head : preferForIntent(head, classifyIntent(query));
|
|
412
416
|
let ordered;
|
|
413
417
|
if (timeRange) {
|
|
414
|
-
const timeHead =
|
|
415
|
-
const timeOthers = enabled.filter((engine) => TIME_ENGINES.includes(engine) && !
|
|
416
|
-
const nonTimeHead =
|
|
418
|
+
const timeHead = routerHead.filter((engine) => TIME_ENGINES.includes(engine));
|
|
419
|
+
const timeOthers = enabled.filter((engine) => TIME_ENGINES.includes(engine) && !routerHead.includes(engine));
|
|
420
|
+
const nonTimeHead = routerHead.filter((engine) => !TIME_ENGINES.includes(engine));
|
|
417
421
|
ordered = [...timeHead, ...timeOthers, ...nonTimeHead];
|
|
418
422
|
} else {
|
|
419
|
-
ordered = [...
|
|
423
|
+
ordered = [...routerHead];
|
|
420
424
|
}
|
|
421
425
|
|
|
422
426
|
// 白名单是显式意图:被它单独允许的按次计费引擎也可以进入 auto 的兜底位置。
|
|
@@ -1808,6 +1812,7 @@ const KEY_REF_MAP = {
|
|
|
1808
1812
|
serplyApiKey: "SERPLY_API_KEY",
|
|
1809
1813
|
outcrawlApiKey: "OUTCRAWL_API_KEY",
|
|
1810
1814
|
googleCseApiKey: "GOOGLE_CSE_API_KEY",
|
|
1815
|
+
metasoApiKey: "METASO_API_KEY",
|
|
1811
1816
|
deepseekApiKey: "DEEPSEEK_API_KEY",
|
|
1812
1817
|
// 设置页写入的凭据槽位保持旧名,已保存的 key 不受影响;读取时 YDC_API_KEY 优先(见 resolveYoucomApiKey)
|
|
1813
1818
|
youcomApiKey: "YOUCOM_API_KEY",
|
|
@@ -1868,6 +1873,9 @@ const Config = z.object({
|
|
|
1868
1873
|
fetchProviderTakeover: z.boolean().default(true).volatile(),
|
|
1869
1874
|
// T1.5 headless browser rendering (default on, matching 0.9.x behaviour).
|
|
1870
1875
|
browserFetch: z.boolean().default(true).volatile(),
|
|
1876
|
+
// Opt-in reserved ranges for transparent-proxy fake-ip DNS (Clash/mihomo
|
|
1877
|
+
// commonly use 198.18.0.0/15). Loopback / RFC1918 / link-local stay blocked.
|
|
1878
|
+
allowFakeIpCidrs: z.array(z.string()).default([]).volatile(),
|
|
1871
1879
|
// Which keyed tier runs first after direct/browser: "exa" (default) or "firecrawl".
|
|
1872
1880
|
fetchPrefer: z.string().default("exa").volatile(),
|
|
1873
1881
|
safeSearch: z.string().default("off").volatile(),
|
|
@@ -1875,6 +1883,8 @@ const Config = z.object({
|
|
|
1875
1883
|
// degoog(自建搜索聚合器,见 https://github.com/degoog-org/degoog):需要自己的实例,默认不启用。
|
|
1876
1884
|
degoogInstances: z.array(z.string()).volatile(),
|
|
1877
1885
|
googleCseId: z.string().default("").volatile(),
|
|
1886
|
+
metasoApiKey: z.string().role("secret").volatile(),
|
|
1887
|
+
metasoScope: z.string().default("webpage").volatile(),
|
|
1878
1888
|
searxngBearerToken: z.string().role("secret").volatile(),
|
|
1879
1889
|
degoogApiKey: z.string().role("secret").volatile(),
|
|
1880
1890
|
platforms: z.array(z.string()).default(["github", "v2ex", "bilibili", "reddit", "hn", "stackoverflow", "wikipedia", "npm", "youtube", "vimeo", "juejin", "douban", "qiita", "x"]).volatile(),
|
|
@@ -2141,12 +2151,21 @@ function apply(ctx, config) {
|
|
|
2141
2151
|
});
|
|
2142
2152
|
}
|
|
2143
2153
|
const injected = composeInjectedPrompt(cfg);
|
|
2154
|
+
const webProvider = (key) => {
|
|
2155
|
+
try {
|
|
2156
|
+
return String(providerSelection(ctx.web, key).current ?? "");
|
|
2157
|
+
} catch {
|
|
2158
|
+
return "";
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2144
2161
|
return buildDoctorReport({
|
|
2145
2162
|
version: PACKAGE_VERSION,
|
|
2146
2163
|
nodeVersion: process.versions.node,
|
|
2147
2164
|
dshHome: dshHomeDir(),
|
|
2148
2165
|
provider: cfg.provider,
|
|
2149
2166
|
effectiveProvider: cfg.provider || autoDefaultProvider,
|
|
2167
|
+
searchProvider: webProvider("searchProvider"),
|
|
2168
|
+
fetchProvider: webProvider("fetchProvider"),
|
|
2150
2169
|
promptLanguage: promptLanguageOf({ promptLanguage: cfg.promptLanguage }),
|
|
2151
2170
|
promptChars: injected.length,
|
|
2152
2171
|
promptInjected: Boolean(injected),
|
|
@@ -2401,6 +2420,10 @@ function apply(ctx, config) {
|
|
|
2401
2420
|
safeSearch: cfg.safeSearch,
|
|
2402
2421
|
}, signal);
|
|
2403
2422
|
},
|
|
2423
|
+
metaso: async ({ query, maxResults, timeRange, signal }) => {
|
|
2424
|
+
const key = await requireEngineKey("METASO_API_KEY", "metasoApiKey", "Metaso", " (get one at metaso.cn/api)");
|
|
2425
|
+
return searchMetaso(query, maxResults, key, current().metasoScope, timeRange, signal);
|
|
2426
|
+
},
|
|
2404
2427
|
you: async ({ query, maxResults, signal }) =>
|
|
2405
2428
|
searchYoucom(query, maxResults, await resolveYoucomKey(), signal),
|
|
2406
2429
|
tinyfish: async ({ query, maxResults, timeRange, signal }) =>
|
|
@@ -2472,7 +2495,9 @@ function apply(ctx, config) {
|
|
|
2472
2495
|
// 轮换时机:首次失败后 keyRings 已经填充,此时再判断有几把 key。
|
|
2473
2496
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
2474
2497
|
try {
|
|
2475
|
-
|
|
2498
|
+
const safe = sanitizeSearchResult(await provider.searchOnce(request, signal));
|
|
2499
|
+
if (Array.isArray(safe.sources)) safe.sources = dedupeNearDuplicates(safe.sources);
|
|
2500
|
+
return safe;
|
|
2476
2501
|
} catch (error) {
|
|
2477
2502
|
const keys = maxKeyRingLength();
|
|
2478
2503
|
if (keys <= 1 || attempt >= keys - 1 || !isKeyRotationCandidate(error)) throw error;
|
|
@@ -2882,6 +2907,7 @@ function apply(ctx, config) {
|
|
|
2882
2907
|
acceptLanguage: () => acceptLanguageFor(current()),
|
|
2883
2908
|
browserEnabled: () => current().browserFetch !== false,
|
|
2884
2909
|
prefer: () => (current().fetchPrefer === "firecrawl" ? "firecrawl" : "exa"),
|
|
2910
|
+
allowedCidrs: () => current().allowFakeIpCidrs ?? [],
|
|
2885
2911
|
});
|
|
2886
2912
|
registerOnce(() => ctx.web.registerFetchProvider(fetchProvider), fetchProvider, "fetch provider");
|
|
2887
2913
|
|
|
@@ -3053,6 +3079,11 @@ function apply(ctx, config) {
|
|
|
3053
3079
|
safeSearch: cfg.safeSearch,
|
|
3054
3080
|
});
|
|
3055
3081
|
}
|
|
3082
|
+
case "metaso": {
|
|
3083
|
+
const key = await resolveApiKey("METASO_API_KEY", "metasoApiKey");
|
|
3084
|
+
if (!key) return { ok: false, error: "METASO_API_KEY not configured" };
|
|
3085
|
+
return await searchMetaso(q, n, key, cfg.metasoScope, tr);
|
|
3086
|
+
}
|
|
3056
3087
|
case "agy": {
|
|
3057
3088
|
if (!agyAvailable()) return { ok: false, error: "Antigravity CLI not installed (install Antigravity or set AGY_BIN)" };
|
|
3058
3089
|
return await searchAgy(q, n, {});
|
|
@@ -3419,7 +3450,7 @@ function apply(ctx, config) {
|
|
|
3419
3450
|
provider: "multi_search",
|
|
3420
3451
|
// #108: the multi tool bypasses provider.search, so sanitize here as well
|
|
3421
3452
|
content: stripLoneSurrogates(`Note: ${notes.join("; ")}`),
|
|
3422
|
-
sources: sanitizeSources(finalSources),
|
|
3453
|
+
sources: dedupeNearDuplicates(sanitizeSources(finalSources)),
|
|
3423
3454
|
truncated: false,
|
|
3424
3455
|
};
|
|
3425
3456
|
};
|
|
@@ -3925,8 +3956,6 @@ function apply(ctx, config) {
|
|
|
3925
3956
|
},
|
|
3926
3957
|
maxResults: {
|
|
3927
3958
|
type: "number",
|
|
3928
|
-
minimum: 1,
|
|
3929
|
-
maximum: MULTI_RESULTS_MAX,
|
|
3930
3959
|
description: toolParam(lang, "multi_search", "maxResults", {
|
|
3931
3960
|
limit: normalizeMultiMaxResults(current().multiMaxResults),
|
|
3932
3961
|
}),
|
package/lib/intent.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight, deterministic query intent routing. It does not replace the
|
|
3
|
+
* language pools or Auto; it only reorders the engines already selected for
|
|
4
|
+
* the query so the head matches the domain (finance, academic, code, news,
|
|
5
|
+
* shopping). Unknown/general queries keep the existing order.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const RULES = [
|
|
9
|
+
{
|
|
10
|
+
domain: "finance",
|
|
11
|
+
pattern:
|
|
12
|
+
/股票|基金|财报|利率|汇率|贷款|债券|通胀|通胀率|市值|IPO|加密货币|比特币|stock|equity|fund|earnings|inflation|interest rate|forex|lpr|crypto|bitcoin|nasdaq|nyse/i,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
domain: "academic",
|
|
16
|
+
pattern:
|
|
17
|
+
/论文|文献|学术|引用|期刊|会议|研究综述|arxiv|doi|citation|paper|study|pubmed|scholar|journal|conference|preprint/i,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
domain: "code",
|
|
21
|
+
pattern:
|
|
22
|
+
/代码|报错|编译|函数|接口|依赖|仓库|github|gitlab|npm|pypi|python|javascript|typescript|rust|golang|java|docker|kubernetes|stack trace|exception|regex|api error/i,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
domain: "news",
|
|
26
|
+
pattern:
|
|
27
|
+
/新闻|最新|今天|昨天|本周|本月|今年|发布|突发|breaking|today|latest|this week|this month|announced|launch/i,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
domain: "shopping",
|
|
31
|
+
pattern:
|
|
32
|
+
/价格|购买|优惠|折扣|测评|推荐|哪款|性价比|price|buy|discount|deal|review|best|cheap/i,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export const INTENT_PREFERENCES = {
|
|
37
|
+
finance: ["baidu", "bing", "anysearch", "exa", "tavily", "ddg"],
|
|
38
|
+
academic: ["exa", "tavily", "parallel", "bing", "anysearch", "ddg"],
|
|
39
|
+
code: ["bing", "ddg", "exa", "tavily", "degoog", "anysearch"],
|
|
40
|
+
news: ["bing", "baidu", "anysearch", "exa", "ddg"],
|
|
41
|
+
shopping: ["baidu", "bing", "anysearch", "ddg", "exa"],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function classifyIntent(query) {
|
|
45
|
+
const text = String(query ?? "");
|
|
46
|
+
for (const rule of RULES) {
|
|
47
|
+
if (rule.pattern.test(text)) return { domain: rule.domain, matched: true };
|
|
48
|
+
}
|
|
49
|
+
return { domain: "general", matched: false };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Stable reorder of an existing engine list by the domain preference. */
|
|
53
|
+
export function preferForIntent(engines, intent) {
|
|
54
|
+
const preference = INTENT_PREFERENCES[intent?.domain] ?? [];
|
|
55
|
+
if (preference.length === 0 || engines.length === 0) return [...engines];
|
|
56
|
+
const rank = new Map(preference.map((id, index) => [id, index]));
|
|
57
|
+
return engines
|
|
58
|
+
.map((id, index) => ({ id, index }))
|
|
59
|
+
.sort((a, b) => (rank.get(a.id) ?? 999) - (rank.get(b.id) ?? 999) || a.index - b.index)
|
|
60
|
+
.map((entry) => entry.id);
|
|
61
|
+
}
|
package/lib/multi_policy.js
CHANGED
|
@@ -221,6 +221,7 @@ export const REQUIRED_CREDENTIALS = {
|
|
|
221
221
|
serply: [{ env: "SERPLY_API_KEY", settings: "serplyApiKey" }],
|
|
222
222
|
outcrawl: [{ env: "OUTCRAWL_API_KEY", settings: "outcrawlApiKey" }],
|
|
223
223
|
google: [{ env: "GOOGLE_CSE_API_KEY", settings: "googleCseApiKey" }],
|
|
224
|
+
metaso: [{ env: "METASO_API_KEY", settings: "metasoApiKey" }],
|
|
224
225
|
tinyfish: [{ env: "TINYFISH_API_KEY", settings: "tinyfishApiKey" }],
|
|
225
226
|
jina: [{ env: "JINA_API_KEY", settings: "jinaApiKey" }],
|
|
226
227
|
baidu: [{ env: "BAIDU_API_KEY", settings: "baiduApiKey" }],
|
package/lib/quality.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evidence quality gate for the research tool. The goal is not to score
|
|
3
|
+
* relevance again; it is to tell the model how much the returned package can
|
|
4
|
+
* support a conclusion, and to cap the wording when the evidence is thin.
|
|
5
|
+
*
|
|
6
|
+
* high: at least 8 sources across 3 domains, 3 fetched documents, 2 dated sources
|
|
7
|
+
* medium: at least 3 sources, 2 domains, 1 fetched document
|
|
8
|
+
* low: anything less, or a failed/partial run recorded in notes
|
|
9
|
+
*/
|
|
10
|
+
function hostOf(url) {
|
|
11
|
+
try {
|
|
12
|
+
return new URL(String(url)).hostname.replace(/^www\./i, "").toLowerCase();
|
|
13
|
+
} catch {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function assessEvidenceQuality({ sources = [], documents = [], notes = [] } = {}) {
|
|
19
|
+
const list = Array.isArray(sources) ? sources : [];
|
|
20
|
+
const docs = Array.isArray(documents) ? documents : [];
|
|
21
|
+
const noteList = Array.isArray(notes) ? notes : [];
|
|
22
|
+
const domains = new Set(list.map((source) => hostOf(source?.url)).filter(Boolean)).size;
|
|
23
|
+
const dated = list.filter((source) => typeof source?.publishedAt === "string" && source.publishedAt.length > 0).length;
|
|
24
|
+
const fetched = docs.length;
|
|
25
|
+
|
|
26
|
+
const degraded = noteList.some((note) =>
|
|
27
|
+
/search failed|budget_exhausted|budget exhausted|all fetches failed|notEvaluated|deadline_hit/i.test(String(note))
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
let level = "low";
|
|
31
|
+
if (list.length >= 8 && domains >= 3 && fetched >= 3 && dated >= 2) level = "high";
|
|
32
|
+
else if (list.length >= 3 && domains >= 2 && fetched >= 1) level = "medium";
|
|
33
|
+
if (degraded) level = "low";
|
|
34
|
+
|
|
35
|
+
const note =
|
|
36
|
+
level === "high"
|
|
37
|
+
? "enough independent sources and fetched bodies for a confident answer"
|
|
38
|
+
: level === "medium"
|
|
39
|
+
? "thin evidence: verify the key claims against the listed sources before concluding"
|
|
40
|
+
: "insufficient evidence: do not state conclusions as fact; fetch more sources or report the gap";
|
|
41
|
+
|
|
42
|
+
return { level, cap: level, sources: list.length, domains, dated, fetched, note };
|
|
43
|
+
}
|
package/lib/research.js
CHANGED
|
@@ -9,6 +9,7 @@ import { rerank, embed, cosineMatrix, decide, judgeQueryIntent } from "./rerank.
|
|
|
9
9
|
import { promptLanguageOf, toolDescription, toolParam, localizedEffect } from "./prompt_i18n.js";
|
|
10
10
|
import { httpsJson, htmlToText, callExa, callFirecrawl, callCrawl4ai } from "./fetch_upstream.js";
|
|
11
11
|
import { isDomainBlocked } from "./domain_filter.js";
|
|
12
|
+
import { assessEvidenceQuality } from "./quality.js";
|
|
12
13
|
|
|
13
14
|
// 模型组件的受控替身(测试/评审用;抓取层的替身在 fetch_upstream.js 的 CONTROLLED_STUBS)
|
|
14
15
|
export const CONTROLLED_STUBS = { rerank: null, embed: null, decide: null, judgeQueryIntent: null };
|
|
@@ -838,6 +839,19 @@ export function registerResearchTool(ctx, { provider, resolveApiKey, wrapUntrust
|
|
|
838
839
|
sources: { type: "array", items: { type: "object", additionalProperties: false, properties: RESEARCH_SOURCE_FIELDS } },
|
|
839
840
|
documents: { type: "array", items: { type: "object", additionalProperties: false, properties: DOC_FIELDS } },
|
|
840
841
|
notes: { type: "array", items: { type: "string" } },
|
|
842
|
+
quality: {
|
|
843
|
+
type: "object",
|
|
844
|
+
additionalProperties: false,
|
|
845
|
+
properties: {
|
|
846
|
+
level: { type: "string" },
|
|
847
|
+
cap: { type: "string" },
|
|
848
|
+
sources: { type: "number" },
|
|
849
|
+
domains: { type: "number" },
|
|
850
|
+
dated: { type: "number" },
|
|
851
|
+
fetched: { type: "number" },
|
|
852
|
+
note: { type: "string" },
|
|
853
|
+
},
|
|
854
|
+
},
|
|
841
855
|
},
|
|
842
856
|
},
|
|
843
857
|
render(_args, value) {
|
|
@@ -862,9 +876,15 @@ export function registerResearchTool(ctx, { provider, resolveApiKey, wrapUntrust
|
|
|
862
876
|
return `### ${d.title || d.url}${mark}\n[${d.url}]\n_${meta}_\n\n${d.content}`;
|
|
863
877
|
});
|
|
864
878
|
const notes = value.notes.length ? `\n## Notes\n${value.notes.map((n) => `- ${n}`).join("\n")}` : "";
|
|
879
|
+
const q = value.quality;
|
|
880
|
+
const quality = q
|
|
881
|
+
? `_evidence: ${q.level} · ${q.sources} sources · ${q.domains} domains · ${q.dated} dated · ${q.fetched} fetched — ${q.note}_\n`
|
|
882
|
+
: "";
|
|
865
883
|
const brief =
|
|
866
884
|
`# Research: ${value.question}\n` +
|
|
867
|
-
`_engines: ${value.engines} · sources: ${value.sources.length} · documents: ${value.documents.length} · ~${value.estimatedTokens} tokens_\n
|
|
885
|
+
`_engines: ${value.engines} · sources: ${value.sources.length} · documents: ${value.documents.length} · ~${value.estimatedTokens} tokens_\n` +
|
|
886
|
+
quality +
|
|
887
|
+
`\n` +
|
|
868
888
|
`## Sources\n${src.join("\n") || "No results found."}\n\n` +
|
|
869
889
|
`## Documents\n${docs.join("\n\n") || "(no documents fetched — snippets above are all we have)"}` +
|
|
870
890
|
notes;
|
|
@@ -1344,6 +1364,7 @@ export function registerResearchTool(ctx, { provider, resolveApiKey, wrapUntrust
|
|
|
1344
1364
|
out.estimatedTokens = estimateTokens(
|
|
1345
1365
|
out.sources.map((s) => s.title + s.snippet).join("") + out.documents.map((d) => d.content).join("")
|
|
1346
1366
|
);
|
|
1367
|
+
out.quality = assessEvidenceQuality(out);
|
|
1347
1368
|
return out;
|
|
1348
1369
|
} finally {
|
|
1349
1370
|
clearTimeout(deadlineTimer);
|
package/lib/ssrf.js
CHANGED
|
@@ -39,12 +39,74 @@ function isPublicIPv6(address) {
|
|
|
39
39
|
return true;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
function buildAllowedList(cidrs) {
|
|
43
|
+
const list = new net.BlockList();
|
|
44
|
+
for (const raw of Array.isArray(cidrs) ? cidrs : []) {
|
|
45
|
+
const text = String(raw ?? "").trim();
|
|
46
|
+
if (!text) continue;
|
|
47
|
+
const slash = text.lastIndexOf("/");
|
|
48
|
+
const address = slash >= 0 ? text.slice(0, slash) : text;
|
|
49
|
+
const family = net.isIP(address);
|
|
50
|
+
if (!family) continue;
|
|
51
|
+
const max = family === 4 ? 32 : 128;
|
|
52
|
+
const prefix = slash >= 0 ? Number(text.slice(slash + 1)) : max;
|
|
53
|
+
if (!Number.isInteger(prefix) || prefix < 0 || prefix > max) continue;
|
|
54
|
+
try {
|
|
55
|
+
list.addSubnet(address, prefix, family === 4 ? "ipv4" : "ipv6");
|
|
56
|
+
} catch {
|
|
57
|
+
// ignore malformed CIDRs; config is also editable by hand
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return list;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** True when the address falls inside one of the user-configured CIDRs. */
|
|
64
|
+
export function isAddressAllowed(address, allowedCidrs = []) {
|
|
44
65
|
const family = net.isIP(String(address));
|
|
45
|
-
if (family
|
|
46
|
-
|
|
47
|
-
|
|
66
|
+
if (!family) return false;
|
|
67
|
+
return buildAllowedList(allowedCidrs).check(String(address), family === 4 ? "ipv4" : "ipv6");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isHardBlockedIPv4(address) {
|
|
71
|
+
const parts = ipv4Parts(address);
|
|
72
|
+
if (parts === null) return false;
|
|
73
|
+
const [a, b] = parts;
|
|
74
|
+
if (a === 0 || a === 10 || a === 127) return true;
|
|
75
|
+
if (a === 169 && b === 254) return true;
|
|
76
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
77
|
+
if (a === 192 && b === 168) return true;
|
|
78
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
79
|
+
return a >= 224;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Ranges that stay blocked even if a user lists them in allowFakeIpCidrs. */
|
|
83
|
+
function isHardBlocked(address) {
|
|
84
|
+
const family = net.isIP(address);
|
|
85
|
+
if (family === 4) return isHardBlockedIPv4(address);
|
|
86
|
+
if (family !== 6) return true;
|
|
87
|
+
const value = address.toLowerCase();
|
|
88
|
+
if (value === "::" || value === "::1") return true;
|
|
89
|
+
if (value.startsWith("::ffff:")) return isHardBlockedIPv4(value.slice(7));
|
|
90
|
+
if (value.startsWith("fc") || value.startsWith("fd")) return true;
|
|
91
|
+
if (/^fe[89ab]/.test(value)) return true;
|
|
92
|
+
return value.startsWith("ff");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* True only for globally routable addresses; unknown input is treated as unsafe.
|
|
97
|
+
* `allowedCidrs` is an explicit opt-in for reserved ranges (e.g. Clash/mihomo
|
|
98
|
+
* fake-ip 198.18.0.0/15). Loopback, RFC1918, link-local and multicast stay
|
|
99
|
+
* blocked even when listed.
|
|
100
|
+
*/
|
|
101
|
+
export function isPublicAddress(address, { allowedCidrs = [], allowedList } = {}) {
|
|
102
|
+
const text = String(address);
|
|
103
|
+
const family = net.isIP(text);
|
|
104
|
+
if (!family) return false;
|
|
105
|
+
if (isHardBlocked(text)) return false;
|
|
106
|
+
const allowed = allowedList ?? buildAllowedList(allowedCidrs);
|
|
107
|
+
if (allowed.check(text, family === 4 ? "ipv4" : "ipv6")) return true;
|
|
108
|
+
if (family === 4) return isPublicIPv4(text);
|
|
109
|
+
return isPublicIPv6(text);
|
|
48
110
|
}
|
|
49
111
|
|
|
50
112
|
function bareHost(hostname) {
|
|
@@ -52,32 +114,37 @@ function bareHost(hostname) {
|
|
|
52
114
|
}
|
|
53
115
|
|
|
54
116
|
/** dns.lookup replacement that refuses to connect to private addresses (redirects included). */
|
|
55
|
-
export function
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
117
|
+
export function makeSafeLookup(allowedCidrs = []) {
|
|
118
|
+
const allowedList = buildAllowedList(allowedCidrs);
|
|
119
|
+
return function lookup(hostname, options, callback) {
|
|
120
|
+
const host = bareHost(hostname);
|
|
121
|
+
dns.lookup(host, { ...options, all: true }, (error, addresses) => {
|
|
122
|
+
if (error) {
|
|
123
|
+
callback(error);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const list = Array.isArray(addresses) ? addresses : [];
|
|
127
|
+
const blocked = list.find((entry) => !isPublicAddress(entry.address, { allowedList }));
|
|
128
|
+
if (blocked) {
|
|
129
|
+
callback(new Error(`SSRF blocked: ${host} resolves to private address ${blocked.address}`));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (options?.all) {
|
|
133
|
+
callback(null, list);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
callback(null, list[0]?.address, list[0]?.family);
|
|
137
|
+
});
|
|
138
|
+
};
|
|
74
139
|
}
|
|
75
140
|
|
|
141
|
+
export const safeLookup = makeSafeLookup();
|
|
142
|
+
|
|
76
143
|
/**
|
|
77
144
|
* Reject non-HTTPS URLs and hosts that resolve (or literally point) to a private
|
|
78
145
|
* address. A custom lookup is allowed for tests.
|
|
79
146
|
*/
|
|
80
|
-
export async function assertPublicUrl(rawUrl, { lookup = dns.promises.lookup } = {}) {
|
|
147
|
+
export async function assertPublicUrl(rawUrl, { lookup = dns.promises.lookup, allowedCidrs = [] } = {}) {
|
|
81
148
|
let target;
|
|
82
149
|
try {
|
|
83
150
|
target = new URL(String(rawUrl ?? ""));
|
|
@@ -89,7 +156,7 @@ export async function assertPublicUrl(rawUrl, { lookup = dns.promises.lookup } =
|
|
|
89
156
|
const host = bareHost(target.hostname);
|
|
90
157
|
if (host === "") throw new Error("URL has no host");
|
|
91
158
|
if (net.isIP(host)) {
|
|
92
|
-
if (!isPublicAddress(host)) throw new Error(`SSRF blocked: ${host} is a private address`);
|
|
159
|
+
if (!isPublicAddress(host, { allowedCidrs })) throw new Error(`SSRF blocked: ${host} is a private address`);
|
|
93
160
|
return target;
|
|
94
161
|
}
|
|
95
162
|
let addresses;
|
|
@@ -99,7 +166,7 @@ export async function assertPublicUrl(rawUrl, { lookup = dns.promises.lookup } =
|
|
|
99
166
|
throw new Error(`cannot resolve host "${host}"`);
|
|
100
167
|
}
|
|
101
168
|
const list = Array.isArray(addresses) ? addresses : [addresses];
|
|
102
|
-
const blocked = list.find((entry) => !isPublicAddress(entry?.address ?? entry));
|
|
169
|
+
const blocked = list.find((entry) => !isPublicAddress(entry?.address ?? entry, { allowedCidrs }));
|
|
103
170
|
if (blocked) {
|
|
104
171
|
throw new Error(`SSRF blocked: ${host} resolves to private address ${blocked.address ?? blocked}`);
|
|
105
172
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-free-search",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "Free web search for DeepSeek Harness:
|
|
3
|
+
"version": "0.9.42",
|
|
4
|
+
"description": "Free web search for DeepSeek Harness: 37 engines (Bing/DuckDuckGo/AnySearch/SearXNG/Exa/Tavily/Keenable/Firecrawl/Parallel/You.com keyless; Zhihu global/site via MCP and Perplexity/SerpBase/DeepSeek (official + native tools/search)/Baidu/Kimi/Aliyun/Doubao/Google CSE/Metaso with key; OpenAI/Gemini/Claude model built-in search, explicit-only) + auto smart routing + global engine enable/disable & fallback priority + editable zh/en language pools + multi mode (parallel full language-pool merge) + multi_search cross-source tool + failure-aware fallback (quota/auth cooldown, transient retry, fallbackOn) + time filtering + platform search + domain blocklist (blockedDomains) + web_fetch, with web settings UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|