dsh-free-search 0.9.41 → 0.9.43
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 +36 -16
- package/lib/client.js +246 -4
- package/lib/engine_meta.js +2 -0
- package/lib/engines/metaso.js +112 -0
- package/lib/engines/yandex.js +170 -0
- package/lib/fetch_provider.js +7 -4
- package/lib/index.js +74 -2
- package/lib/multi_policy.js +2 -0
- 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
|
+
- **38 个引擎可选**:DuckDuckGo(html/lite)、Bing、SearXNG(元搜索,支持自定义实例)、AnySearch、Exa、Tavily、Keenable、Firecrawl、Parallel、Perplexity、SerpBase、Serply、Outcrawl、Google 自定义搜索(`google`,需 API key + CSE ID)、秘塔搜索(`metaso`,官方 API,按点数计费)、Yandex 搜索(`yandex`,官方 API,按请求计费,需 folder ID)、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 和 Yandex 都只在显式点名时运行。
|
|
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` / 引擎测试都不再用它),并可用 ↑↓ 调整全局回退顺序(一键恢复默认)。
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
|
|
78
78
|
#### 抓取与工具
|
|
79
79
|
|
|
80
|
-
- **网页抓取(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 返回的占位地址会被当成私网拒绝。
|
|
81
81
|
|
|
82
82
|
<img src="https://raw.githubusercontent.com/DDDMUC/dsh-free-search/master/assets/ui-fetch.png" alt="抓取与平台:web_fetch 接管、Key 存储位置与平台搜索开关" width="100%" />
|
|
83
83
|
<sub>▲ 抓取:自动接管 web_fetch、Key 存储位置与平台搜索开关</sub>
|
|
@@ -149,6 +149,8 @@
|
|
|
149
149
|
| `serply` | Serply | 付费 | 需 `SERPLY_API_KEY`(serply.io,新账户 30 天内 2,500 次免费额度);Google 网页结果,按设置页语言本地化 |
|
|
150
150
|
| `outcrawl` | Outcrawl | 付费 | 需 `OUTCRAWL_API_KEY`(outcrawl.ai,每月 1,000 credits 免费额度);网页搜索结果(标题/链接/摘要),单次最多 20 条 |
|
|
151
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 后显式选用 |
|
|
153
|
+
| `yandex` | Yandex 搜索 | 付费 | 需 `YANDEX_API_KEY` 和 `yandexFolderId`(AI Studio,按请求计费,需 billing account);官方 Search API,`searchType` 支持 RU/TR/COM/KK/BE/UZ,响应为 Base64 XML;支持 day / 2 weeks / month 时间过滤;显式专用 |
|
|
152
154
|
| `deepseek-official` | DeepSeek 官方 | 付费 | 需 `DEEPSEEK_API_KEY`;走 Anthropic 兼容的 `web_search` 服务端工具,每次搜索是一整个模型轮次(慢、耗 token) |
|
|
153
155
|
| `deepseek-tools` | DeepSeek 原生搜索 API | 付费 | 需 `DEEPSEEK_API_KEY`(与上一档共用);直接 `POST /v1/tools/search`,无模型参与,返回结构化 `results[]`(`title`/`url`/`summary`/`date`),同 query 实测 ~0.3s vs 上一档 ~5-6s |
|
|
154
156
|
| `baidu` | 百度千帆 AI 搜索 | 额度 | 需 `BAIDU_API_KEY`(千帆 AI 搜索,每日赠 50 次,超额按量后付费);中文全网,支持时间过滤 |
|
|
@@ -279,7 +281,7 @@ DSH 0.2.1 设置 → 网页搜索 → **DeepSeek 搜索 API** 开关会和本插
|
|
|
279
281
|
配置页提供:
|
|
280
282
|
|
|
281
283
|
- **Search engine**:下拉框切换引擎,保存即生效
|
|
282
|
-
- **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 使用)
|
|
284
|
+
- **API keys**:为 Exa / Tavily / Keenable / Firecrawl / Parallel / Perplexity / DeepSeek / SerpBase / Serply / Outcrawl / Google CSE / Metaso / Yandex / You.com 填写 key(密码框,保存后只显示"已配置";Exa / Tavily / Keenable / Firecrawl / Parallel / You.com 不填也可免 key 使用)
|
|
283
285
|
- **推荐**:付费引擎 key 建议写入 harness 凭据中心 `~/.dsh/.credentials.yaml`(如 `DEEPSEEK_API_KEY: sk-...`,与官方 LLM provider 一致,一处管理所有 key)。插件读取优先级:凭据中心 > 设置页 > 环境变量,设置页填的 key 仅作为遗留兼容。
|
|
284
286
|
- **Test engine**:直测当前引擎可用性(不走回退链,付费引擎无 key 会明确报错)
|
|
285
287
|
- **Use Bing default**:把当前搜索引擎切回稳定的免费 Bing;`Discard` 只撤销尚未保存的编辑
|
|
@@ -399,6 +401,7 @@ disabledTools: [] # 关掉的工具不再注册(例如 [domain_searc
|
|
|
399
401
|
bingMarket: zh-CN # Bing 市场;留空 = 自动(不发送 mkt)
|
|
400
402
|
fetchProviderTakeover: true # false = 保留你显式 pin 的 fetchProvider: http
|
|
401
403
|
browserFetch: true # 直连失败时用系统浏览器无头渲染
|
|
404
|
+
allowFakeIpCidrs: [] # 显式放行的保留网段,例如 Clash/mihomo fake-ip 的 198.18.0.0/15
|
|
402
405
|
fetchPrefer: exa # exa | firecrawl —— 两者都失败后先试哪个 keyed 抓取层
|
|
403
406
|
region: cn-zh # DuckDuckGo 区域(可选)
|
|
404
407
|
searxngInstances: # 自定义 SearXNG 实例(可选)
|
|
@@ -425,6 +428,11 @@ serplyApiKey: ... # 或通过设置页填写
|
|
|
425
428
|
outcrawlApiKey: ... # 或通过设置页填写
|
|
426
429
|
googleCseApiKey: ... # Google Custom Search API key
|
|
427
430
|
googleCseId: "..." # Programmable Search Engine 的 cx
|
|
431
|
+
metasoApiKey: ... # Metaso API key (metaso.cn/api)
|
|
432
|
+
metasoScope: webpage # webpage | document | scholar
|
|
433
|
+
yandexApiKey: ... # Yandex Search API key (AI Studio)
|
|
434
|
+
yandexFolderId: "..." # folder the key was created in
|
|
435
|
+
yandexSearchType: auto # auto | ru | tr | com | kk | be | uz
|
|
428
436
|
deepseekApiKey: ...
|
|
429
437
|
```
|
|
430
438
|
|
|
@@ -512,7 +520,7 @@ Search engine test:
|
|
|
512
520
|
|
|
513
521
|
- 自动跟随重定向、解码正文(HTML 转文本)
|
|
514
522
|
- 支持超时和大小限制
|
|
515
|
-
- ⚠️ 注意:`web_fetch`
|
|
523
|
+
- ⚠️ 注意:`web_fetch` 默认拒绝回环、私网、链路本地和云元数据地址。若使用 Clash / mihomo TUN 的 fake-ip DNS,请把对应网段(常见 `198.18.0.0/15`)加入设置页的「额外允许的网段」,否则所有被代理域名都会被判成私网而抓取失败;只放行 fake-ip 保留段,不要放行 RFC1918。
|
|
516
524
|
|
|
517
525
|
#### 平台搜索(platform_search)
|
|
518
526
|
|
|
@@ -586,7 +594,7 @@ Search engine test:
|
|
|
586
594
|
|
|
587
595
|
#### 离线自检断言(tools/)
|
|
588
596
|
|
|
589
|
-
仓库自带 **
|
|
597
|
+
仓库自带 **57 个**零依赖断言脚本(合计 **851 项**),**不需要 API key、不联网、不需要测试框架**,Node ≥ 20 即可跑。一次跑全部:`npm test`。
|
|
590
598
|
|
|
591
599
|
| 脚本 | 覆盖 | 运行(项数) |
|
|
592
600
|
|---|---|---|
|
|
@@ -597,7 +605,7 @@ Search engine test:
|
|
|
597
605
|
| `assert-multi-policy.mjs` | multi 执行策略:并发上限是天花板 / 目标成功源非硬下限 / 凭据资格在上限之前分流 / **Fast·Balanced·Deep 档位** | `node tools/assert-multi-policy.mjs`(146) |
|
|
598
606
|
| `assert-multi-limit.mjs` | multi 结果上限(#109):默认 20 / 硬上限 100 / 配置归一化、单次 maxResults 受上限约束、工具参数与本段提示词写明生效上限、设置页字段与保存 | `node tools/assert-multi-limit.mjs`(6) |
|
|
599
607
|
| `assert-maintenance.mjs` | 维护面:CI 在 Node 20/22/24 跑全部断言并过打包闸门、发布脚本会 bump / 校验 / 打 tag / 可发布、恢复官方 provider 的桥接与设置页按钮 | `node tools/assert-maintenance.mjs`(4) |
|
|
600
|
-
| `assert-engine-modules.mjs` | 引擎分层:实现文件存在且被 index 引用、引擎函数已迁出 index、设置页引擎 id 与服务端清单一致、清单覆盖
|
|
608
|
+
| `assert-engine-modules.mjs` | 引擎分层:实现文件存在且被 index 引用、引擎函数已迁出 index、设置页引擎 id 与服务端清单一致、清单覆盖 38 个引擎且免费/按次标记正确、index 不引用引擎私有名 | `node tools/assert-engine-modules.mjs`(6) |
|
|
601
609
|
| `assert-bing-relevance.mjs` | Bing 相关性(#112):单字中文 token 被剔除、无关替代 SERP 被拒、真正相关的结果通过、只命中通用引擎名的整批被拒、单一 token 覆盖一半时放行、单字/纯数字查询的显式行为 | `node tools/assert-bing-relevance.mjs`(6) |
|
|
602
610
|
| `assert-quality.mjs` | 研究证据闸门:8 源 / 3 域 / 3 正文 / 2 日期为 high,3 源 / 2 域 / 1 正文为 medium,单源与失败注记为 low,空包为 low,research 的 schema/输出/brief 接线 | `node tools/assert-quality.mjs`(6) |
|
|
603
611
|
| `assert-dedupe.mjs` | 近重复去重:MinHash 同文本同签名、同 URL 去重、跨站转载去重、不同文章保留且顺序不变、阈值可调、provider 与 multi 两条路径接线 | `node tools/assert-dedupe.mjs`(6) |
|
|
@@ -608,7 +616,9 @@ Search engine test:
|
|
|
608
616
|
| `assert-research-degradation.mjs` | research 无 key 全降级、`node:sqlite` no-op、90s 预算隔离、缓存目录可配置、`budget.exhausted` 契约名 | `node tools/assert-research-degradation.mjs`(19) |
|
|
609
617
|
| `assert-research-call-wrappers.mjs` | research 四个 `call*` 包装层的替身/底层透传(#75 回归) | `node tools/assert-research-call-wrappers.mjs`(23) |
|
|
610
618
|
| `assert-fetch-chain.mjs` | `fs-quality-fetch` 四层链序、任一层命中即停、exa 失败静默降级 firecrawl、全层失败聚合报错 | `node tools/assert-fetch-chain.mjs`(8) |
|
|
611
|
-
| `assert-fetch-ssrf.mjs` | 抓取 SSRF 防护:公网/私网/保留地址判定、DNS 解析到私网拒绝、localhost 与 IP 字面量拒绝、非 HTTPS 与带凭据 URL 拒绝、provider 接线与设置项 | `node tools/assert-fetch-ssrf.mjs`(
|
|
619
|
+
| `assert-fetch-ssrf.mjs` | 抓取 SSRF 防护:公网/私网/保留地址判定、DNS 解析到私网拒绝、localhost 与 IP 字面量拒绝、非 HTTPS 与带凭据 URL 拒绝、fake-ip 网段默认拒绝且仅按配置放行、放行后仍拒绝回环/私网、provider 接线与设置项 | `node tools/assert-fetch-ssrf.mjs`(8) |
|
|
620
|
+
| `assert-yandex.mjs` | Yandex Search:key+folder 必填、Api-Key/请求体/分组、searchType 与 period/family 映射、Base64 XML 解析与日期、错误分类、注册与显式专用 | `node tools/assert-yandex.mjs`(6) |
|
|
621
|
+
| `assert-metaso.mjs` | 秘塔搜索:key 必填、请求体(q/scope/size/summary/raw/concise)、摘要与日期映射、文库数组、size 上限、无效 scope 回退、401/402/429/400 错误分类、注册与默认回退排除 | `node tools/assert-metaso.mjs`(6) |
|
|
612
622
|
| `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) |
|
|
613
623
|
| `assert-engine-runtime.mjs` | 引擎运行时:按引擎并发上限(普通 2 / HTML SERP 1)、排队与 abort 清理、成功/空/失败/平均耗时统计、provider 与 runEngineTest 两条路径接线、诊断报告带 stats | `node tools/assert-engine-runtime.mjs`(4) |
|
|
614
624
|
| `assert-single-fetch-layer.mjs` | 抓取层全库只有一份实现、依赖单向、替身键不串层 | `node tools/assert-single-fetch-layer.mjs`(22) |
|
|
@@ -642,7 +652,7 @@ Search engine test:
|
|
|
642
652
|
| `assert-firecrawl-keyless.mjs` | Firecrawl keyless 出口判定:403 + VPN/proxy 文案才算拒绝、普通 403 与 401/429/500 不算、冷却初始未触发 | `node tools/assert-firecrawl-keyless.mjs`(5) |
|
|
643
653
|
| `assert-fetch-charset.mjs` | 抓取编码(#88):`charset=gbk` / `gb2312` 按声明解码、无声明时嗅探 `<meta charset>` 与 http-equiv 形式、默认 UTF-8、未知 label 兜底 UTF-8 不抛错 | `node tools/assert-fetch-charset.mjs`(6) |
|
|
644
654
|
| `assert-fetch-abort.mjs` | 抓取中断(#87):压缩响应中途断连必须 reject(不再永久 pending)、明文断连同样 reject、abort 能打断停滞的 gzip 流、complete 响应与重定向仍正常 | `node tools/assert-fetch-abort.mjs`(6) |
|
|
645
|
-
| `assert-bridge-access.mjs` | 桥接 Host 围栏(#84):loopback 放行、remote peer 打 loopback Host 拒绝、`--trusted-host`(无端口匹配任意端口 / 带端口精确匹配)、`--public-url
|
|
655
|
+
| `assert-bridge-access.mjs` | 桥接 Host 围栏(#84):loopback 放行、remote peer 打 loopback Host 拒绝、`--trusted-host`(无端口匹配任意端口 / 带端口精确匹配)、`--public-url`、绑定地址、跨站与异源拒绝、connection 鉴权委托与 fail-closed | `node tools/assert-bridge-access.mjs`(13) |
|
|
646
656
|
| `assert-provider-takeover.mjs` | provider 接管:旧属性 API 与 rc.2 的 `config.*` ref 两套兼容、`settings.mutate(web)` 单批写入、显式指定的 provider 不被抢占、`fetchProviderTakeover: false` 时保留显式 `http`、describe 噪声不误报、嵌套 config 变化与 web 重建分别成行、关闭 DSH 搜索开关后重新接管且不抢 `deepseek-search-api`、apply 重入/重复注册不再中断、重复日志去重 | `node tools/assert-provider-takeover.mjs`(16) |
|
|
647
657
|
|
|
648
658
|
任何一个失败会以非 0 退出码结束并列出失败项;把某个旧版本文件路径作为参数传进去,可以看到修复前必红(用来证明断言不是空转)。改动发布相关逻辑后建议先跑一遍再发版。
|
|
@@ -695,7 +705,7 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
695
705
|
#### Engines and switching
|
|
696
706
|
|
|
697
707
|
- **Zero Cost** — Multiple free engines with no API key or registration required
|
|
698
|
-
- **
|
|
708
|
+
- **38 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), Yandex Search (official API, billed per request, folder ID required), 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, Metaso and Yandex run only when explicitly named.
|
|
699
709
|
- **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.
|
|
700
710
|
- **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).
|
|
701
711
|
- **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).
|
|
@@ -738,7 +748,7 @@ This plugin solves exactly that: multiple free engines plus automatic fallback,
|
|
|
738
748
|
|
|
739
749
|
#### Fetch and tools
|
|
740
750
|
|
|
741
|
-
- **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).
|
|
751
|
+
- **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.
|
|
742
752
|
|
|
743
753
|
<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%" />
|
|
744
754
|
<sub>▲ Fetch: web_fetch takeover, key storage location and platform search switches</sub>
|
|
@@ -811,6 +821,8 @@ If this plugin has been helpful, a ⭐ on [GitHub](https://github.com/DDDMUC/dsh
|
|
|
811
821
|
| `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 |
|
|
812
822
|
| `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 |
|
|
813
823
|
| `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 |
|
|
824
|
+
| `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 |
|
|
825
|
+
| `yandex` | Yandex Search | Paid | Requires `YANDEX_API_KEY` and `yandexFolderId` (AI Studio; billed per request to a billing account); official Search API with RU/TR/COM/KK/BE/UZ search types and Base64 XML responses; supports day / 2 weeks / month time filters; explicit-only |
|
|
814
826
|
| `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) |
|
|
815
827
|
| `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 |
|
|
816
828
|
| `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 |
|
|
@@ -942,7 +954,7 @@ After installation, open the config page (DSH 0.2.1-rc.2+):
|
|
|
942
954
|
The config page provides:
|
|
943
955
|
|
|
944
956
|
- **Search engine**: Select an engine from the dropdown; changes take effect immediately upon saving.
|
|
945
|
-
- **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).
|
|
957
|
+
- **API keys**: Enter keys for Exa / Tavily / Keenable / Firecrawl / Parallel / Perplexity / DeepSeek / Google CSE / Metaso / Yandex / You.com (password fields; displayed as "configured" once saved; Exa / Tavily / Keenable / Firecrawl / Parallel / You.com work without a key too).
|
|
946
958
|
- **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.
|
|
947
959
|
- **Test engine**: Tests the selected engine directly (no fallback chain; paid engines without a key report an explicit error).
|
|
948
960
|
- **Use Bing default**: stage a switch back to the stable free Bing engine; `Discard` only cancels unsaved edits
|
|
@@ -1062,6 +1074,7 @@ disabledTools: [] # tools that are not registered at all (e.g. [domain
|
|
|
1062
1074
|
bingMarket: zh-CN # Bing market; empty = automatic (no mkt sent)
|
|
1063
1075
|
fetchProviderTakeover: true # false = keep the fetchProvider: http you pinned yourself
|
|
1064
1076
|
browserFetch: true # use the system browser headless renderer when direct fetch fails
|
|
1077
|
+
allowFakeIpCidrs: [] # reserved ranges to allow explicitly, e.g. 198.18.0.0/15 for Clash/mihomo fake-ip
|
|
1065
1078
|
fetchPrefer: exa # exa | firecrawl — which keyed fetch tier to try first
|
|
1066
1079
|
region: cn-zh # DuckDuckGo region (optional)
|
|
1067
1080
|
searxngInstances: # Custom SearXNG instances (optional)
|
|
@@ -1088,6 +1101,11 @@ serplyApiKey: ... # Or configure via the web settings UI
|
|
|
1088
1101
|
outcrawlApiKey: ... # Or configure via the web settings UI
|
|
1089
1102
|
googleCseApiKey: ... # Google Custom Search API key
|
|
1090
1103
|
googleCseId: "..." # Programmable Search Engine cx
|
|
1104
|
+
metasoApiKey: ... # Metaso API key (metaso.cn/api)
|
|
1105
|
+
metasoScope: webpage # webpage | document | scholar
|
|
1106
|
+
yandexApiKey: ... # Yandex Search API key (AI Studio)
|
|
1107
|
+
yandexFolderId: "..." # folder the key was created in
|
|
1108
|
+
yandexSearchType: auto # auto | ru | tr | com | kk | be | uz
|
|
1091
1109
|
deepseekApiKey: ...
|
|
1092
1110
|
```
|
|
1093
1111
|
|
|
@@ -1175,7 +1193,7 @@ After searching, the agent can **read full webpage content** (e.g., *"Open the f
|
|
|
1175
1193
|
|
|
1176
1194
|
- Automatically follows redirects and decodes HTML to plain text.
|
|
1177
1195
|
- Supports timeout and response size limits.
|
|
1178
|
-
- ⚠️ Note: `web_fetch`
|
|
1196
|
+
- ⚠️ 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.
|
|
1179
1197
|
|
|
1180
1198
|
#### Platform Search (`platform_search`)
|
|
1181
1199
|
|
|
@@ -1249,7 +1267,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1249
1267
|
|
|
1250
1268
|
#### Offline self-check assertions (`tools/`)
|
|
1251
1269
|
|
|
1252
|
-
**Fifty-
|
|
1270
|
+
**Fifty-seven** zero-dependency assertion scripts ship with the repo (**851 assertions** total): **no API keys, no network, no test framework**, Node ≥ 20. Run everything with `npm test`.
|
|
1253
1271
|
|
|
1254
1272
|
| Script | Covers | Run (count) |
|
|
1255
1273
|
|---|---|---|
|
|
@@ -1260,7 +1278,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1260
1278
|
| `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) |
|
|
1261
1279
|
| `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) |
|
|
1262
1280
|
| `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) |
|
|
1263
|
-
| `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
|
|
1281
|
+
| `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 38 engines with the right free/explicit flags, and index never reads an engine-private name | `node tools/assert-engine-modules.mjs` (6) |
|
|
1264
1282
|
| `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) |
|
|
1265
1283
|
| `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) |
|
|
1266
1284
|
| `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) |
|
|
@@ -1271,7 +1289,9 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1271
1289
|
| `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) |
|
|
1272
1290
|
| `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) |
|
|
1273
1291
|
| `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) |
|
|
1274
|
-
| `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` (
|
|
1292
|
+
| `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) |
|
|
1293
|
+
| `assert-yandex.mjs` | Yandex Search: key + folder required, Api-Key/body/grouping, searchType and period/family mapping, Base64 XML parsing and dates, error classes, registration and explicit-only | `node tools/assert-yandex.mjs` (6) |
|
|
1294
|
+
| `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) |
|
|
1275
1295
|
| `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) |
|
|
1276
1296
|
| `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) |
|
|
1277
1297
|
| `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) |
|
|
@@ -1305,7 +1325,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1305
1325
|
| `assert-firecrawl-keyless.mjs` | Firecrawl keyless egress refusal: only a 403 with the VPN/proxy wording counts, plain 403 and 401/429/500 do not, and the cooldown starts inactive | `node tools/assert-firecrawl-keyless.mjs` (5) |
|
|
1306
1326
|
| `assert-fetch-charset.mjs` | fetch encoding (#88): `charset=gbk` / `gb2312` decoded as declared, `<meta charset>` and the http-equiv form sniffed when the header omits it, UTF-8 by default, and an unknown label falls back to UTF-8 instead of throwing | `node tools/assert-fetch-charset.mjs` (6) |
|
|
1307
1327
|
| `assert-fetch-abort.mjs` | fetch interruption (#87): a compressed response cut mid-body rejects instead of hanging forever, identity truncation rejects too, abort breaks a stalled gzip stream, and complete responses plus redirects still work | `node tools/assert-fetch-abort.mjs` (6) |
|
|
1308
|
-
| `assert-bridge-access.mjs` | bridge Host fence (#84): loopback allowed, a remote peer behind a loopback Host refused, `--trusted-host` (port-less matches any port, explicit port matches exactly), `--public-url`, the bind address, cross-site and foreign-Origin refused | `node tools/assert-bridge-access.mjs` (
|
|
1328
|
+
| `assert-bridge-access.mjs` | bridge Host fence (#84): loopback allowed, a remote peer behind a loopback Host refused, `--trusted-host` (port-less matches any port, explicit port matches exactly), `--public-url`, the bind address, cross-site and foreign-Origin refused, connection-auth delegation and fail-closed behavior | `node tools/assert-bridge-access.mjs` (13) |
|
|
1309
1329
|
| `assert-provider-takeover.mjs` | provider takeover: both the legacy property API and the rc.2 `config.*` refs, a single batched `settings.mutate(web)`, explicit foreign providers left untouched, an explicit `http` kept when `fetchProviderTakeover` is off, describe()-triggered events ignored when nothing changed, nested config changes and web rebuilds reported separately, re-takeover after DSH's search switch is turned off without fighting an explicit `deepseek-search-api`, apply re-entry / duplicate registrations tolerated, and repeated logs deduplicated | `node tools/assert-provider-takeover.mjs` (16) |
|
|
1310
1330
|
|
|
1311
1331
|
Any failure exits non-zero with the failing items listed. Passing the path of an older file shows the pre-fix failures (proving the assertions are not vacuous). Worth running before a release.
|
package/lib/client.js
CHANGED
|
@@ -431,12 +431,34 @@ 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/文档,学术面向论文,单次消耗更高。",
|
|
449
|
+
yandexKeyLabel: "Yandex API key",
|
|
450
|
+
yandexKeyHint: "在 Yandex AI Studio 创建,需要同时有 folder ID;按请求计费,需绑定 billing account。",
|
|
451
|
+
yandexFolderLabel: "Yandex folder ID",
|
|
452
|
+
yandexFolderHint: "创建 API key 时所在的 folder;在 AI Studio 顶部文件夹名旁复制。",
|
|
453
|
+
yandexSearchTypeLabel: "Yandex 搜索区域",
|
|
454
|
+
yandexSearchTypeAuto: "自动(按查询语言)",
|
|
455
|
+
yandexSearchTypeRu: "RU · 俄罗斯",
|
|
456
|
+
yandexSearchTypeTr: "TR · 土耳其",
|
|
457
|
+
yandexSearchTypeCom: "COM · 国际",
|
|
458
|
+
yandexSearchTypeKk: "KK · 哈萨克斯坦",
|
|
459
|
+
yandexSearchTypeBe: "BE · 白俄罗斯",
|
|
460
|
+
yandexSearchTypeUz: "UZ · 乌兹别克斯坦",
|
|
461
|
+
yandexSearchTypeHint: "自动按 lang 选择;也可以固定到某个区域。",
|
|
440
462
|
restoreOfficial: "恢复官方搜索",
|
|
441
463
|
restoreOfficialHint: "把 web.searchProvider 改回 deepseek-official、web.fetchProvider 改回 http。停用或卸载本插件前建议先点一次,避免宿主报 configured web provider \"ddg\" is not registered。",
|
|
442
464
|
restoringOfficial: "恢复中…",
|
|
@@ -595,12 +617,34 @@ window.__ModuleLoader__.load({
|
|
|
595
617
|
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
618
|
browserFetchLabel: "Render with the local browser",
|
|
597
619
|
browserFetchHint: "When direct fetch fails, load the page in headless Chrome/Edge to pass JS challenges; skipped when no browser is installed.",
|
|
620
|
+
fakeIpCidrsLabel: "Extra allowed networks (fake-ip proxy)",
|
|
621
|
+
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
622
|
fetchPreferLabel: "Fetch quality-chain order",
|
|
599
623
|
fetchPreferExa: "Exa first",
|
|
600
624
|
fetchPreferFirecrawl: "Firecrawl first",
|
|
601
625
|
fetchPreferHint: "Which keyed tier to try first after direct and browser both fail; only matters when both keys are configured.",
|
|
602
626
|
googleCseIdLabel: "Google Programmable Search engine ID",
|
|
603
627
|
googleCseIdHint: "The cx from Programmable Search Engine (looks like 0123…:abc…); used with GOOGLE_CSE_API_KEY, free 100 queries/day.",
|
|
628
|
+
metasoKeyLabel: "Metaso API key",
|
|
629
|
+
metasoKeyHint: "Create one at metaso.cn/api; billed per call, new accounts get trial credits.",
|
|
630
|
+
metasoScopeLabel: "Metaso search scope",
|
|
631
|
+
metasoScopeWebpage: "Webpages",
|
|
632
|
+
metasoScopeDocument: "Documents",
|
|
633
|
+
metasoScopeScholar: "Scholars",
|
|
634
|
+
metasoScopeHint: "Webpages is the general default; documents targets PDFs/files and scholars targets papers, both cost more per call.",
|
|
635
|
+
yandexKeyLabel: "Yandex API key",
|
|
636
|
+
yandexKeyHint: "Create one in Yandex AI Studio; a folder ID is required too, and requests are billed to a billing account.",
|
|
637
|
+
yandexFolderLabel: "Yandex folder ID",
|
|
638
|
+
yandexFolderHint: "The folder the API key was created in; copy it from the folder name in AI Studio.",
|
|
639
|
+
yandexSearchTypeLabel: "Yandex search region",
|
|
640
|
+
yandexSearchTypeAuto: "Auto (follow query language)",
|
|
641
|
+
yandexSearchTypeRu: "RU · Russia",
|
|
642
|
+
yandexSearchTypeTr: "TR · Turkey",
|
|
643
|
+
yandexSearchTypeCom: "COM · International",
|
|
644
|
+
yandexSearchTypeKk: "KK · Kazakhstan",
|
|
645
|
+
yandexSearchTypeBe: "BE · Belarus",
|
|
646
|
+
yandexSearchTypeUz: "UZ · Uzbekistan",
|
|
647
|
+
yandexSearchTypeHint: "Auto follows lang; pin a region to override.",
|
|
604
648
|
restoreOfficial: "Restore official search",
|
|
605
649
|
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
650
|
restoringOfficial: "Restoring…",
|
|
@@ -650,7 +694,7 @@ window.__ModuleLoader__.load({
|
|
|
650
694
|
"cache_search",
|
|
651
695
|
"domain_search",
|
|
652
696
|
];
|
|
653
|
-
const PLUGIN_VERSION = "0.9.
|
|
697
|
+
const PLUGIN_VERSION = "0.9.43";
|
|
654
698
|
const PLUGIN_REPO_URL = "https://github.com/DDDMUC/dsh-free-search";
|
|
655
699
|
// 右侧浮动目录(#85):条目顺序即页面顺序,anchor 是页面里对应 field 的 id。
|
|
656
700
|
const NAV_ITEMS = [
|
|
@@ -691,6 +735,8 @@ window.__ModuleLoader__.load({
|
|
|
691
735
|
{ id: "serply", label: "Serply · Google", badge: "API KEY", link: "https://serply.io" },
|
|
692
736
|
{ id: "outcrawl", label: "Outcrawl", badge: "API KEY", link: "https://outcrawl.ai" },
|
|
693
737
|
{ id: "google", label: "Google · 自定义搜索", badge: "API KEY", link: "https://developers.google.com/custom-search/v1/overview" },
|
|
738
|
+
{ id: "metaso", label: "Metaso · 秘塔搜索", badge: "API KEY", link: "https://metaso.cn/api" },
|
|
739
|
+
{ id: "yandex", label: "Yandex · 搜索 API", badge: "API KEY", link: "https://aistudio.yandex.cloud" },
|
|
694
740
|
{ id: "deepseek-official", label: "DeepSeek Official", badge: "API KEY", link: "https://platform.deepseek.com/api_keys" },
|
|
695
741
|
{ id: "deepseek-tools", label: "DeepSeek Tools API", badge: "API KEY", link: "https://api-docs.deepseek.com/zh-cn/guides/search" },
|
|
696
742
|
{ id: "you", label: "You.com", badge: "FREE", link: "https://you.com/platform/api-keys" },
|
|
@@ -714,10 +760,10 @@ window.__ModuleLoader__.load({
|
|
|
714
760
|
];
|
|
715
761
|
const ENGINE_IDS = ENGINES.filter((engine) => engine.id !== "auto" && engine.id !== "multi").map((engine) => engine.id);
|
|
716
762
|
// 与 lib/index.js 的 EXPLICIT_ONLY_ENGINES 同源:按次计费、只在显式选中时运行,因此不提供入池候选。
|
|
717
|
-
const EXPLICIT_ONLY_ENGINES = ["openai", "gemini", "claude"];
|
|
763
|
+
const EXPLICIT_ONLY_ENGINES = ["openai", "gemini", "claude", "metaso", "yandex"];
|
|
718
764
|
// 与 lib/serp_engines.js 的 SERP_ENGINE_IDS 同源:HTML 抓取型引擎,默认不进自动回退链。
|
|
719
765
|
const SERP_ENGINE_IDS = ["baidu-html", "so360", "sogou", "wechat", "toutiao"];
|
|
720
|
-
const MODEL_ENGINES = ENGINES.filter((engine) => EXPLICIT_ONLY_ENGINES.includes(engine.id));
|
|
766
|
+
const MODEL_ENGINES = ENGINES.filter((engine) => EXPLICIT_ONLY_ENGINES.includes(engine.id) && engine.id !== "metaso" && engine.id !== "yandex");
|
|
721
767
|
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
768
|
const normalizeFallbackOrder = (value) => {
|
|
723
769
|
const configured = Array.isArray(value) ? value.filter((id) => ENGINE_IDS.includes(id)) : [];
|
|
@@ -916,6 +962,7 @@ window.__ModuleLoader__.load({
|
|
|
916
962
|
const [bingMarket, setBingMarket] = react.useState("zh-CN");
|
|
917
963
|
const [fetchProviderTakeover, setFetchProviderTakeover] = react.useState(true);
|
|
918
964
|
const [browserFetch, setBrowserFetch] = react.useState(true);
|
|
965
|
+
const [allowFakeIpCidrs, setAllowFakeIpCidrs] = react.useState("");
|
|
919
966
|
const [fetchPrefer, setFetchPrefer] = react.useState("exa");
|
|
920
967
|
const [anysearchKey, setAnysearchKey] = react.useState("");
|
|
921
968
|
const [exaKey, setExaKey] = react.useState("");
|
|
@@ -930,6 +977,11 @@ window.__ModuleLoader__.load({
|
|
|
930
977
|
const [outcrawlKey, setOutcrawlKey] = react.useState("");
|
|
931
978
|
const [googleKey, setGoogleKey] = react.useState("");
|
|
932
979
|
const [googleCx, setGoogleCx] = react.useState("");
|
|
980
|
+
const [metasoKey, setMetasoKey] = react.useState("");
|
|
981
|
+
const [metasoScope, setMetasoScope] = react.useState("webpage");
|
|
982
|
+
const [yandexKey, setYandexKey] = react.useState("");
|
|
983
|
+
const [yandexFolder, setYandexFolder] = react.useState("");
|
|
984
|
+
const [yandexType, setYandexType] = react.useState("auto");
|
|
933
985
|
const [youcomKey, setYoucomKey] = react.useState("");
|
|
934
986
|
const [baiduKey, setBaiduKey] = react.useState("");
|
|
935
987
|
const [kimiKey, setKimiKey] = react.useState("");
|
|
@@ -1082,6 +1134,7 @@ window.__ModuleLoader__.load({
|
|
|
1082
1134
|
setBingMarket(v.bingMarket === undefined ? "zh-CN" : v.bingMarket);
|
|
1083
1135
|
setFetchProviderTakeover(v.fetchProviderTakeover !== false);
|
|
1084
1136
|
setBrowserFetch(v.browserFetch !== false);
|
|
1137
|
+
setAllowFakeIpCidrs((Array.isArray(v.allowFakeIpCidrs) ? v.allowFakeIpCidrs : []).join("\n"));
|
|
1085
1138
|
setFetchPrefer(v.fetchPrefer === "firecrawl" ? "firecrawl" : "exa");
|
|
1086
1139
|
setLang(v.lang ?? "zh");
|
|
1087
1140
|
setUiLang(typeof v.uiLang === "string" ? v.uiLang : "");
|
|
@@ -1105,6 +1158,11 @@ window.__ModuleLoader__.load({
|
|
|
1105
1158
|
setOutcrawlKey(v.outcrawlApiKey ?? "");
|
|
1106
1159
|
setGoogleKey(v.googleCseApiKey ?? "");
|
|
1107
1160
|
setGoogleCx(v.googleCseId ?? "");
|
|
1161
|
+
setMetasoKey(v.metasoApiKey ?? "");
|
|
1162
|
+
setMetasoScope(v.metasoScope === "document" || v.metasoScope === "scholar" ? v.metasoScope : "webpage");
|
|
1163
|
+
setYandexKey(v.yandexApiKey ?? "");
|
|
1164
|
+
setYandexFolder(v.yandexFolderId ?? "");
|
|
1165
|
+
setYandexType(["ru", "tr", "com", "kk", "be", "uz"].includes(v.yandexSearchType) ? v.yandexSearchType : "auto");
|
|
1108
1166
|
setYoucomKey(v.youcomApiKey ?? "");
|
|
1109
1167
|
setBaiduKey(v.baiduApiKey ?? "");
|
|
1110
1168
|
setKimiKey(v.kimiApiKey ?? "");
|
|
@@ -1154,6 +1212,8 @@ window.__ModuleLoader__.load({
|
|
|
1154
1212
|
if (path === "searxngBearerToken") configured.searxng = true;
|
|
1155
1213
|
if (path === "degoogApiKey") configured.degoog = true;
|
|
1156
1214
|
if (path === "googleCseApiKey") configured.google = true;
|
|
1215
|
+
if (path === "metasoApiKey") configured.metaso = true;
|
|
1216
|
+
if (path === "yandexApiKey") configured.yandex = true;
|
|
1157
1217
|
}
|
|
1158
1218
|
}
|
|
1159
1219
|
setKeysConfigured(configured);
|
|
@@ -1165,7 +1225,7 @@ window.__ModuleLoader__.load({
|
|
|
1165
1225
|
const cred = await bridgeCredentialsStatus();
|
|
1166
1226
|
if (cred.ok) {
|
|
1167
1227
|
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" };
|
|
1228
|
+
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", yandexApiKey: "yandex", baiduApiKey: "baidu", kimiApiKey: "kimi", aliyunApiKey: "aliyun", doubaoApiKey: "doubao", openaiApiKey: "openai", geminiApiKey: "gemini", claudeApiKey: "claude", zhihuApiKey: "zhihu", tinyfishApiKey: "tinyfish", jinaApiKey: "jina", searxngBearerToken: "searxng" };
|
|
1169
1229
|
for (const [k, v] of Object.entries(cred.value.configured ?? {})) {
|
|
1170
1230
|
if (map[k]) cc[map[k]] = v;
|
|
1171
1231
|
}
|
|
@@ -1214,6 +1274,8 @@ window.__ModuleLoader__.load({
|
|
|
1214
1274
|
["serplyApiKey", serplyKey],
|
|
1215
1275
|
["outcrawlApiKey", outcrawlKey],
|
|
1216
1276
|
["googleCseApiKey", googleKey],
|
|
1277
|
+
["metasoApiKey", metasoKey],
|
|
1278
|
+
["yandexApiKey", yandexKey],
|
|
1217
1279
|
["youcomApiKey", youcomKey],
|
|
1218
1280
|
["baiduApiKey", baiduKey],
|
|
1219
1281
|
["kimiApiKey", kimiKey],
|
|
@@ -1260,7 +1322,15 @@ window.__ModuleLoader__.load({
|
|
|
1260
1322
|
ops.push({ op: "set", path: ["bingMarket"], value: bingMarket });
|
|
1261
1323
|
ops.push({ op: "set", path: ["fetchProviderTakeover"], value: fetchProviderTakeover });
|
|
1262
1324
|
ops.push({ op: "set", path: ["googleCseId"], value: googleCx.trim() });
|
|
1325
|
+
ops.push({ op: "set", path: ["metasoScope"], value: metasoScope === "document" || metasoScope === "scholar" ? metasoScope : "webpage" });
|
|
1326
|
+
ops.push({ op: "set", path: ["yandexFolderId"], value: yandexFolder.trim() });
|
|
1327
|
+
ops.push({ op: "set", path: ["yandexSearchType"], value: ["ru", "tr", "com", "kk", "be", "uz"].includes(yandexType) ? yandexType : "auto" });
|
|
1263
1328
|
ops.push({ op: "set", path: ["browserFetch"], value: browserFetch });
|
|
1329
|
+
ops.push({
|
|
1330
|
+
op: "set",
|
|
1331
|
+
path: ["allowFakeIpCidrs"],
|
|
1332
|
+
value: [...new Set(String(allowFakeIpCidrs ?? "").split(/[\s,]+/).map((s) => s.trim()).filter(Boolean))],
|
|
1333
|
+
});
|
|
1264
1334
|
ops.push({ op: "set", path: ["fetchPrefer"], value: fetchPrefer === "firecrawl" ? "firecrawl" : "exa" });
|
|
1265
1335
|
if (keyStorage !== "credentials") {
|
|
1266
1336
|
// settings 模式:key 写入当前 profile 的插件条目 config(cordis.patch.yml)
|
|
@@ -2034,6 +2104,151 @@ react_jsx_runtime.jsx("div", {
|
|
|
2034
2104
|
}),
|
|
2035
2105
|
],
|
|
2036
2106
|
}),
|
|
2107
|
+
react_jsx_runtime.jsx("div", {
|
|
2108
|
+
className: "dshfs-field",
|
|
2109
|
+
children: [
|
|
2110
|
+
react_jsx_runtime.jsx("div", {
|
|
2111
|
+
className: "dshfs-label",
|
|
2112
|
+
children: t.metasoKeyLabel,
|
|
2113
|
+
}),
|
|
2114
|
+
react_jsx_runtime.jsx("input", {
|
|
2115
|
+
className: "dshfs-input",
|
|
2116
|
+
type: "password",
|
|
2117
|
+
value: metasoKey,
|
|
2118
|
+
spellCheck: false,
|
|
2119
|
+
placeholder: "API key",
|
|
2120
|
+
disabled: !ready || saving,
|
|
2121
|
+
onChange: (e) => {
|
|
2122
|
+
setMetasoKey(e.target.value);
|
|
2123
|
+
setDirty(true);
|
|
2124
|
+
setFailed(false);
|
|
2125
|
+
setSaveError("");
|
|
2126
|
+
},
|
|
2127
|
+
}),
|
|
2128
|
+
react_jsx_runtime.jsx("p", {
|
|
2129
|
+
className: "dshfs-hint",
|
|
2130
|
+
children: t.metasoKeyHint,
|
|
2131
|
+
}),
|
|
2132
|
+
],
|
|
2133
|
+
}),
|
|
2134
|
+
react_jsx_runtime.jsx("div", {
|
|
2135
|
+
className: "dshfs-field",
|
|
2136
|
+
children: [
|
|
2137
|
+
react_jsx_runtime.jsx("div", {
|
|
2138
|
+
className: "dshfs-label",
|
|
2139
|
+
children: t.metasoScopeLabel,
|
|
2140
|
+
}),
|
|
2141
|
+
react_jsx_runtime.jsx("select", {
|
|
2142
|
+
className: "dshfs-select",
|
|
2143
|
+
value: metasoScope,
|
|
2144
|
+
style: { colorScheme: selectColorScheme },
|
|
2145
|
+
disabled: !ready || saving,
|
|
2146
|
+
onChange: (e) => {
|
|
2147
|
+
setMetasoScope(e.target.value === "document" || e.target.value === "scholar" ? e.target.value : "webpage");
|
|
2148
|
+
setDirty(true);
|
|
2149
|
+
setFailed(false);
|
|
2150
|
+
setSaveError("");
|
|
2151
|
+
},
|
|
2152
|
+
children: [
|
|
2153
|
+
react_jsx_runtime.jsx("option", { value: "webpage", children: t.metasoScopeWebpage }),
|
|
2154
|
+
react_jsx_runtime.jsx("option", { value: "document", children: t.metasoScopeDocument }),
|
|
2155
|
+
react_jsx_runtime.jsx("option", { value: "scholar", children: t.metasoScopeScholar }),
|
|
2156
|
+
],
|
|
2157
|
+
}),
|
|
2158
|
+
react_jsx_runtime.jsx("p", {
|
|
2159
|
+
className: "dshfs-hint",
|
|
2160
|
+
children: t.metasoScopeHint,
|
|
2161
|
+
}),
|
|
2162
|
+
],
|
|
2163
|
+
}),
|
|
2164
|
+
react_jsx_runtime.jsx("div", {
|
|
2165
|
+
className: "dshfs-field",
|
|
2166
|
+
children: [
|
|
2167
|
+
react_jsx_runtime.jsx("div", {
|
|
2168
|
+
className: "dshfs-label",
|
|
2169
|
+
children: t.yandexKeyLabel,
|
|
2170
|
+
}),
|
|
2171
|
+
react_jsx_runtime.jsx("input", {
|
|
2172
|
+
className: "dshfs-input",
|
|
2173
|
+
type: "password",
|
|
2174
|
+
value: yandexKey,
|
|
2175
|
+
spellCheck: false,
|
|
2176
|
+
placeholder: "API key",
|
|
2177
|
+
disabled: !ready || saving,
|
|
2178
|
+
onChange: (e) => {
|
|
2179
|
+
setYandexKey(e.target.value);
|
|
2180
|
+
setDirty(true);
|
|
2181
|
+
setFailed(false);
|
|
2182
|
+
setSaveError("");
|
|
2183
|
+
},
|
|
2184
|
+
}),
|
|
2185
|
+
react_jsx_runtime.jsx("p", {
|
|
2186
|
+
className: "dshfs-hint",
|
|
2187
|
+
children: t.yandexKeyHint,
|
|
2188
|
+
}),
|
|
2189
|
+
],
|
|
2190
|
+
}),
|
|
2191
|
+
react_jsx_runtime.jsx("div", {
|
|
2192
|
+
className: "dshfs-field",
|
|
2193
|
+
children: [
|
|
2194
|
+
react_jsx_runtime.jsx("div", {
|
|
2195
|
+
className: "dshfs-label",
|
|
2196
|
+
children: t.yandexFolderLabel,
|
|
2197
|
+
}),
|
|
2198
|
+
react_jsx_runtime.jsx("input", {
|
|
2199
|
+
className: "dshfs-input",
|
|
2200
|
+
type: "text",
|
|
2201
|
+
value: yandexFolder,
|
|
2202
|
+
spellCheck: false,
|
|
2203
|
+
placeholder: "b1g...",
|
|
2204
|
+
disabled: !ready || saving,
|
|
2205
|
+
onChange: (e) => {
|
|
2206
|
+
setYandexFolder(e.target.value);
|
|
2207
|
+
setDirty(true);
|
|
2208
|
+
setFailed(false);
|
|
2209
|
+
setSaveError("");
|
|
2210
|
+
},
|
|
2211
|
+
}),
|
|
2212
|
+
react_jsx_runtime.jsx("p", {
|
|
2213
|
+
className: "dshfs-hint",
|
|
2214
|
+
children: t.yandexFolderHint,
|
|
2215
|
+
}),
|
|
2216
|
+
],
|
|
2217
|
+
}),
|
|
2218
|
+
react_jsx_runtime.jsx("div", {
|
|
2219
|
+
className: "dshfs-field",
|
|
2220
|
+
children: [
|
|
2221
|
+
react_jsx_runtime.jsx("div", {
|
|
2222
|
+
className: "dshfs-label",
|
|
2223
|
+
children: t.yandexSearchTypeLabel,
|
|
2224
|
+
}),
|
|
2225
|
+
react_jsx_runtime.jsx("select", {
|
|
2226
|
+
className: "dshfs-select",
|
|
2227
|
+
value: yandexType,
|
|
2228
|
+
style: { colorScheme: selectColorScheme },
|
|
2229
|
+
disabled: !ready || saving,
|
|
2230
|
+
onChange: (e) => {
|
|
2231
|
+
setYandexType(["ru", "tr", "com", "kk", "be", "uz"].includes(e.target.value) ? e.target.value : "auto");
|
|
2232
|
+
setDirty(true);
|
|
2233
|
+
setFailed(false);
|
|
2234
|
+
setSaveError("");
|
|
2235
|
+
},
|
|
2236
|
+
children: [
|
|
2237
|
+
react_jsx_runtime.jsx("option", { value: "auto", children: t.yandexSearchTypeAuto }),
|
|
2238
|
+
react_jsx_runtime.jsx("option", { value: "ru", children: t.yandexSearchTypeRu }),
|
|
2239
|
+
react_jsx_runtime.jsx("option", { value: "tr", children: t.yandexSearchTypeTr }),
|
|
2240
|
+
react_jsx_runtime.jsx("option", { value: "com", children: t.yandexSearchTypeCom }),
|
|
2241
|
+
react_jsx_runtime.jsx("option", { value: "kk", children: t.yandexSearchTypeKk }),
|
|
2242
|
+
react_jsx_runtime.jsx("option", { value: "be", children: t.yandexSearchTypeBe }),
|
|
2243
|
+
react_jsx_runtime.jsx("option", { value: "uz", children: t.yandexSearchTypeUz }),
|
|
2244
|
+
],
|
|
2245
|
+
}),
|
|
2246
|
+
react_jsx_runtime.jsx("p", {
|
|
2247
|
+
className: "dshfs-hint",
|
|
2248
|
+
children: t.yandexSearchTypeHint,
|
|
2249
|
+
}),
|
|
2250
|
+
],
|
|
2251
|
+
}),
|
|
2037
2252
|
react_jsx_runtime.jsx("div", {
|
|
2038
2253
|
className: "dshfs-field",
|
|
2039
2254
|
id: "dshfs-anchor-fallback",
|
|
@@ -2388,6 +2603,33 @@ react_jsx_runtime.jsx("div", {
|
|
|
2388
2603
|
}),
|
|
2389
2604
|
],
|
|
2390
2605
|
}),
|
|
2606
|
+
react_jsx_runtime.jsx("div", {
|
|
2607
|
+
className: "dshfs-field",
|
|
2608
|
+
children: [
|
|
2609
|
+
react_jsx_runtime.jsx("div", {
|
|
2610
|
+
className: "dshfs-label",
|
|
2611
|
+
children: t.fakeIpCidrsLabel,
|
|
2612
|
+
}),
|
|
2613
|
+
react_jsx_runtime.jsx("textarea", {
|
|
2614
|
+
className: "dshfs-textarea",
|
|
2615
|
+
rows: 3,
|
|
2616
|
+
placeholder: "198.18.0.0/15",
|
|
2617
|
+
value: allowFakeIpCidrs,
|
|
2618
|
+
spellCheck: false,
|
|
2619
|
+
disabled: !ready || saving,
|
|
2620
|
+
onChange: (e) => {
|
|
2621
|
+
setAllowFakeIpCidrs(e.target.value);
|
|
2622
|
+
setDirty(true);
|
|
2623
|
+
setFailed(false);
|
|
2624
|
+
setSaveError("");
|
|
2625
|
+
},
|
|
2626
|
+
}),
|
|
2627
|
+
react_jsx_runtime.jsx("p", {
|
|
2628
|
+
className: "dshfs-hint",
|
|
2629
|
+
children: t.fakeIpCidrsHint,
|
|
2630
|
+
}),
|
|
2631
|
+
],
|
|
2632
|
+
}),
|
|
2391
2633
|
react_jsx_runtime.jsx("div", {
|
|
2392
2634
|
className: "dshfs-field",
|
|
2393
2635
|
children: [
|
package/lib/engine_meta.js
CHANGED
|
@@ -24,6 +24,8 @@ 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 },
|
|
28
|
+
{ id: "yandex", free: false, time: false, explicitOnly: true },
|
|
27
29
|
{ id: "deepseek-official", free: false, time: false },
|
|
28
30
|
{ id: "deepseek-tools", free: false, time: true },
|
|
29
31
|
{ 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
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Yandex Search API (official, paid). REST returns Base64-encoded XML in
|
|
2
|
+
// rawData; the engine decodes it and maps <doc> entries to the common shape.
|
|
3
|
+
import { stripTags, uniqueSources } from "./shared.js";
|
|
4
|
+
|
|
5
|
+
const YANDEX_URL = "https://searchapi.api.cloud.yandex.net/v2/web/search";
|
|
6
|
+
const MAX_RESULTS = 50;
|
|
7
|
+
|
|
8
|
+
export const YANDEX_SEARCH_TYPES = ["auto", "ru", "tr", "com", "kk", "be", "uz"];
|
|
9
|
+
|
|
10
|
+
const SEARCH_TYPE_BY_LANG = {
|
|
11
|
+
ru: "SEARCH_TYPE_RU",
|
|
12
|
+
tr: "SEARCH_TYPE_TR",
|
|
13
|
+
kk: "SEARCH_TYPE_KK",
|
|
14
|
+
be: "SEARCH_TYPE_BE",
|
|
15
|
+
uz: "SEARCH_TYPE_UZ",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const PERIODS = [
|
|
19
|
+
{ maxDays: 1, period: "PERIOD_DAY" },
|
|
20
|
+
{ maxDays: 14, period: "PERIOD_2_WEEKS" },
|
|
21
|
+
{ maxDays: 31, period: "PERIOD_MONTH" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export function normalizeYandexSearchType(value, lang = "en") {
|
|
25
|
+
const choice = String(value ?? "").trim().toLowerCase();
|
|
26
|
+
if (choice !== "" && choice !== "auto" && YANDEX_SEARCH_TYPES.includes(choice)) {
|
|
27
|
+
return `SEARCH_TYPE_${choice.toUpperCase()}`;
|
|
28
|
+
}
|
|
29
|
+
return SEARCH_TYPE_BY_LANG[String(lang ?? "").toLowerCase()] ?? "SEARCH_TYPE_COM";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function yandexPeriod(timeRange) {
|
|
33
|
+
if (!timeRange) return undefined;
|
|
34
|
+
const days = timeRange.after
|
|
35
|
+
? Math.max(1, Math.ceil((Date.now() - Date.parse(`${timeRange.after}T00:00:00Z`)) / 86_400_000))
|
|
36
|
+
: Number(timeRange.days);
|
|
37
|
+
if (!Number.isFinite(days) || days <= 0) return undefined;
|
|
38
|
+
return PERIODS.find((entry) => days <= entry.maxDays)?.period;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function familyMode(safeSearch) {
|
|
42
|
+
if (safeSearch === "strict") return "FAMILY_MODE_STRICT";
|
|
43
|
+
if (safeSearch === "moderate") return "FAMILY_MODE_MODERATE";
|
|
44
|
+
if (safeSearch === "off") return "FAMILY_MODE_NONE";
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function yandexErrorMessage(status, detail) {
|
|
49
|
+
let upstream = "";
|
|
50
|
+
try {
|
|
51
|
+
const parsed = JSON.parse(detail);
|
|
52
|
+
upstream = parsed?.message ?? parsed?.error?.message ?? "";
|
|
53
|
+
} catch {}
|
|
54
|
+
const suffix = upstream ? `: ${String(upstream).slice(0, 200)}` : "";
|
|
55
|
+
if (status === 401 || status === 403) {
|
|
56
|
+
return `Yandex API key or folder is invalid, or the key lacks the search-api.webSearch.user role (HTTP ${status})${suffix}`;
|
|
57
|
+
}
|
|
58
|
+
if (status === 429) return `Yandex quota/rate limit exceeded (HTTP 429)${suffix}`;
|
|
59
|
+
if (status === 400) return `Yandex search request failed (HTTP 400)${suffix} - check yandexFolderId and the query`;
|
|
60
|
+
return `Yandex API error (HTTP ${status})${suffix}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function xmlText(raw) {
|
|
64
|
+
return stripTags(String(raw ?? "").replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, "$1")).trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function publishedDate(raw) {
|
|
68
|
+
const text = String(raw ?? "").trim();
|
|
69
|
+
const match = text.match(/^(\d{4})(\d{2})(\d{2})(?:T|$)/);
|
|
70
|
+
return match ? `${match[1]}-${match[2]}-${match[3]}` : "";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function parseYandexXml(xml) {
|
|
74
|
+
const sources = [];
|
|
75
|
+
const docs = String(xml ?? "").matchAll(/<doc(?:\s[^>]*)?>([\s\S]*?)<\/doc>/g);
|
|
76
|
+
for (const match of docs) {
|
|
77
|
+
const block = match[1];
|
|
78
|
+
const url = xmlText(block.match(/<url>([\s\S]*?)<\/url>/)?.[1]);
|
|
79
|
+
if (!url) continue;
|
|
80
|
+
const title = xmlText(block.match(/<title>([\s\S]*?)<\/title>/)?.[1]);
|
|
81
|
+
const passages = [...block.matchAll(/<passage>([\s\S]*?)<\/passage>/g)]
|
|
82
|
+
.map((entry) => xmlText(entry[1]))
|
|
83
|
+
.filter(Boolean);
|
|
84
|
+
const snippet = passages.slice(0, 3).join(" ").slice(0, 1000);
|
|
85
|
+
const date = publishedDate(xmlText(block.match(/<modtime>([\s\S]*?)<\/modtime>/)?.[1]));
|
|
86
|
+
sources.push({
|
|
87
|
+
url,
|
|
88
|
+
...(title ? { title } : {}),
|
|
89
|
+
...(snippet ? { snippet } : {}),
|
|
90
|
+
...(date ? { publishedAt: date } : {}),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return sources;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function searchYandex(query, maxResults, apiKey, folderId, options = {}, timeRange, signal) {
|
|
97
|
+
if (!apiKey) throw new Error("Yandex search requires YANDEX_API_KEY");
|
|
98
|
+
if (!folderId) throw new Error("Yandex search requires a folder ID (yandexFolderId)");
|
|
99
|
+
const limit = Math.min(Math.max(Number(maxResults) || 10, 1), MAX_RESULTS);
|
|
100
|
+
const searchType = normalizeYandexSearchType(options.searchType, options.lang);
|
|
101
|
+
const family = familyMode(options.safeSearch);
|
|
102
|
+
const period = yandexPeriod(timeRange);
|
|
103
|
+
|
|
104
|
+
const controller = new AbortController();
|
|
105
|
+
const timer = setTimeout(() => controller.abort(), 30000);
|
|
106
|
+
const onAbort = () => controller.abort();
|
|
107
|
+
signal?.addEventListener("abort", onAbort);
|
|
108
|
+
|
|
109
|
+
let response;
|
|
110
|
+
try {
|
|
111
|
+
response = await fetch(YANDEX_URL, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
redirect: "error",
|
|
114
|
+
headers: {
|
|
115
|
+
authorization: `Api-Key ${apiKey}`,
|
|
116
|
+
"content-type": "application/json",
|
|
117
|
+
accept: "application/json",
|
|
118
|
+
"user-agent": "deepseek-harness/free-search",
|
|
119
|
+
},
|
|
120
|
+
body: JSON.stringify({
|
|
121
|
+
query: {
|
|
122
|
+
searchType,
|
|
123
|
+
queryText: String(query),
|
|
124
|
+
...(family === undefined ? {} : { familyMode: family }),
|
|
125
|
+
},
|
|
126
|
+
groupSpec: {
|
|
127
|
+
groupMode: "GROUP_MODE_FLAT",
|
|
128
|
+
groupsOnPage: String(limit),
|
|
129
|
+
docsInGroup: "1",
|
|
130
|
+
},
|
|
131
|
+
maxPassages: "3",
|
|
132
|
+
...(options.region ? { region: String(options.region) } : {}),
|
|
133
|
+
folderId,
|
|
134
|
+
responseFormat: "FORMAT_XML",
|
|
135
|
+
...(period === undefined ? {} : { period }),
|
|
136
|
+
}),
|
|
137
|
+
signal: controller.signal,
|
|
138
|
+
});
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (signal?.aborted) throw error;
|
|
141
|
+
if (error?.name === "AbortError") throw new Error("Yandex request timed out");
|
|
142
|
+
throw new Error(`Yandex request failed: ${error?.message ?? String(error)}`);
|
|
143
|
+
} finally {
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
signal?.removeEventListener("abort", onAbort);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
const detail = await response.text().catch(() => "");
|
|
150
|
+
throw new Error(yandexErrorMessage(response.status, detail));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let data;
|
|
154
|
+
try {
|
|
155
|
+
data = await response.json();
|
|
156
|
+
} catch {
|
|
157
|
+
throw new Error("Yandex returned an invalid JSON response");
|
|
158
|
+
}
|
|
159
|
+
if (typeof data?.rawData !== "string" || data.rawData === "") {
|
|
160
|
+
throw new Error("Yandex response has no rawData");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let xml;
|
|
164
|
+
try {
|
|
165
|
+
xml = Buffer.from(data.rawData, "base64").toString("utf8");
|
|
166
|
+
} catch {
|
|
167
|
+
throw new Error("Yandex rawData is not valid Base64");
|
|
168
|
+
}
|
|
169
|
+
return { sources: uniqueSources(parseYandexXml(xml), limit), truncated: false };
|
|
170
|
+
}
|
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,6 +40,8 @@ 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";
|
|
44
|
+
import { searchYandex } from "./engines/yandex.js";
|
|
43
45
|
import { createEngineRuntime, ENGINE_CONCURRENCY_LIMIT, SERP_CONCURRENCY_LIMIT } from "./engine_runtime.js";
|
|
44
46
|
import { classifyIntent, preferForIntent } from "./intent.js";
|
|
45
47
|
import { dedupeNearDuplicates } from "./dedupe.js";
|
|
@@ -1357,7 +1359,23 @@ function toView(descriptor) {
|
|
|
1357
1359
|
};
|
|
1358
1360
|
}
|
|
1359
1361
|
|
|
1360
|
-
|
|
1362
|
+
/**
|
|
1363
|
+
* The plugin's exact routes are longer than DSH's `/api` prefix, so they run
|
|
1364
|
+
* before the host's admission check. Ask the connection service for the same
|
|
1365
|
+
* decision; if it is unavailable, fail closed instead of exposing the bridge.
|
|
1366
|
+
*/
|
|
1367
|
+
export function bridgeAuthRejection(request, connection) {
|
|
1368
|
+
if (connection === undefined || connection === null) return 503;
|
|
1369
|
+
const reject = connection.requestRejection;
|
|
1370
|
+
if (typeof reject !== "function") return 503;
|
|
1371
|
+
try {
|
|
1372
|
+
return reject.call(connection, request) ?? undefined;
|
|
1373
|
+
} catch {
|
|
1374
|
+
return 503;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
function makeBridgeRoutes(settings, search, testEngine, getCredentials, getConfig = () => ({}), doctor = async () => "", connection = () => undefined) {
|
|
1361
1379
|
const allowlisted = () =>
|
|
1362
1380
|
settings
|
|
1363
1381
|
.describe({ redactSecrets: true })
|
|
@@ -1602,6 +1620,11 @@ function makeBridgeRoutes(settings, search, testEngine, getCredentials, getConfi
|
|
|
1602
1620
|
};
|
|
1603
1621
|
|
|
1604
1622
|
const guard = (req, res) => {
|
|
1623
|
+
const rejection = bridgeAuthRejection(req, connection());
|
|
1624
|
+
if (rejection !== undefined) {
|
|
1625
|
+
writeJson(res, rejection, { error: "host authentication required" });
|
|
1626
|
+
return false;
|
|
1627
|
+
}
|
|
1605
1628
|
if (!isBridgeRequestAllowed(req)) {
|
|
1606
1629
|
writeJson(res, 403, { error: "requests must come from the local host or a configured trusted host" });
|
|
1607
1630
|
return false;
|
|
@@ -1811,6 +1834,8 @@ const KEY_REF_MAP = {
|
|
|
1811
1834
|
serplyApiKey: "SERPLY_API_KEY",
|
|
1812
1835
|
outcrawlApiKey: "OUTCRAWL_API_KEY",
|
|
1813
1836
|
googleCseApiKey: "GOOGLE_CSE_API_KEY",
|
|
1837
|
+
metasoApiKey: "METASO_API_KEY",
|
|
1838
|
+
yandexApiKey: "YANDEX_API_KEY",
|
|
1814
1839
|
deepseekApiKey: "DEEPSEEK_API_KEY",
|
|
1815
1840
|
// 设置页写入的凭据槽位保持旧名,已保存的 key 不受影响;读取时 YDC_API_KEY 优先(见 resolveYoucomApiKey)
|
|
1816
1841
|
youcomApiKey: "YOUCOM_API_KEY",
|
|
@@ -1871,6 +1896,9 @@ const Config = z.object({
|
|
|
1871
1896
|
fetchProviderTakeover: z.boolean().default(true).volatile(),
|
|
1872
1897
|
// T1.5 headless browser rendering (default on, matching 0.9.x behaviour).
|
|
1873
1898
|
browserFetch: z.boolean().default(true).volatile(),
|
|
1899
|
+
// Opt-in reserved ranges for transparent-proxy fake-ip DNS (Clash/mihomo
|
|
1900
|
+
// commonly use 198.18.0.0/15). Loopback / RFC1918 / link-local stay blocked.
|
|
1901
|
+
allowFakeIpCidrs: z.array(z.string()).default([]).volatile(),
|
|
1874
1902
|
// Which keyed tier runs first after direct/browser: "exa" (default) or "firecrawl".
|
|
1875
1903
|
fetchPrefer: z.string().default("exa").volatile(),
|
|
1876
1904
|
safeSearch: z.string().default("off").volatile(),
|
|
@@ -1878,6 +1906,11 @@ const Config = z.object({
|
|
|
1878
1906
|
// degoog(自建搜索聚合器,见 https://github.com/degoog-org/degoog):需要自己的实例,默认不启用。
|
|
1879
1907
|
degoogInstances: z.array(z.string()).volatile(),
|
|
1880
1908
|
googleCseId: z.string().default("").volatile(),
|
|
1909
|
+
metasoApiKey: z.string().role("secret").volatile(),
|
|
1910
|
+
metasoScope: z.string().default("webpage").volatile(),
|
|
1911
|
+
yandexApiKey: z.string().role("secret").volatile(),
|
|
1912
|
+
yandexFolderId: z.string().default("").volatile(),
|
|
1913
|
+
yandexSearchType: z.string().default("auto").volatile(),
|
|
1881
1914
|
searxngBearerToken: z.string().role("secret").volatile(),
|
|
1882
1915
|
degoogApiKey: z.string().role("secret").volatile(),
|
|
1883
1916
|
platforms: z.array(z.string()).default(["github", "v2ex", "bilibili", "reddit", "hn", "stackoverflow", "wikipedia", "npm", "youtube", "vimeo", "juejin", "douban", "qiita", "x"]).volatile(),
|
|
@@ -2413,6 +2446,22 @@ function apply(ctx, config) {
|
|
|
2413
2446
|
safeSearch: cfg.safeSearch,
|
|
2414
2447
|
}, signal);
|
|
2415
2448
|
},
|
|
2449
|
+
metaso: async ({ query, maxResults, timeRange, signal }) => {
|
|
2450
|
+
const key = await requireEngineKey("METASO_API_KEY", "metasoApiKey", "Metaso", " (get one at metaso.cn/api)");
|
|
2451
|
+
return searchMetaso(query, maxResults, key, current().metasoScope, timeRange, signal);
|
|
2452
|
+
},
|
|
2453
|
+
yandex: async ({ query, maxResults, timeRange, signal }) => {
|
|
2454
|
+
const key = await requireEngineKey("YANDEX_API_KEY", "yandexApiKey", "Yandex", " (create one at aistudio.yandex.cloud)");
|
|
2455
|
+
const cfg = current();
|
|
2456
|
+
if (!cfg.yandexFolderId) {
|
|
2457
|
+
throw new EngineSkip("Yandex requires a folder ID (yandexFolderId)", "yandexFolderId is not configured");
|
|
2458
|
+
}
|
|
2459
|
+
return searchYandex(query, maxResults, key, cfg.yandexFolderId, {
|
|
2460
|
+
searchType: cfg.yandexSearchType,
|
|
2461
|
+
lang: searchLanguage(configLanguage(cfg)),
|
|
2462
|
+
safeSearch: cfg.safeSearch,
|
|
2463
|
+
}, timeRange, signal);
|
|
2464
|
+
},
|
|
2416
2465
|
you: async ({ query, maxResults, signal }) =>
|
|
2417
2466
|
searchYoucom(query, maxResults, await resolveYoucomKey(), signal),
|
|
2418
2467
|
tinyfish: async ({ query, maxResults, timeRange, signal }) =>
|
|
@@ -2852,7 +2901,14 @@ function apply(ctx, config) {
|
|
|
2852
2901
|
},
|
|
2853
2902
|
getCredentials,
|
|
2854
2903
|
current,
|
|
2855
|
-
doctorReport
|
|
2904
|
+
doctorReport,
|
|
2905
|
+
() => {
|
|
2906
|
+
try {
|
|
2907
|
+
return sctx.get("connection");
|
|
2908
|
+
} catch {
|
|
2909
|
+
return undefined;
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2856
2912
|
).map((route) => registerOnce(() => sctx.get("webServer").register(route), { id: route.path }, "bridge route"));
|
|
2857
2913
|
return () => {
|
|
2858
2914
|
for (const dispose of disposers) dispose();
|
|
@@ -2896,6 +2952,7 @@ function apply(ctx, config) {
|
|
|
2896
2952
|
acceptLanguage: () => acceptLanguageFor(current()),
|
|
2897
2953
|
browserEnabled: () => current().browserFetch !== false,
|
|
2898
2954
|
prefer: () => (current().fetchPrefer === "firecrawl" ? "firecrawl" : "exa"),
|
|
2955
|
+
allowedCidrs: () => current().allowFakeIpCidrs ?? [],
|
|
2899
2956
|
});
|
|
2900
2957
|
registerOnce(() => ctx.web.registerFetchProvider(fetchProvider), fetchProvider, "fetch provider");
|
|
2901
2958
|
|
|
@@ -3067,6 +3124,21 @@ function apply(ctx, config) {
|
|
|
3067
3124
|
safeSearch: cfg.safeSearch,
|
|
3068
3125
|
});
|
|
3069
3126
|
}
|
|
3127
|
+
case "metaso": {
|
|
3128
|
+
const key = await resolveApiKey("METASO_API_KEY", "metasoApiKey");
|
|
3129
|
+
if (!key) return { ok: false, error: "METASO_API_KEY not configured" };
|
|
3130
|
+
return await searchMetaso(q, n, key, cfg.metasoScope, tr);
|
|
3131
|
+
}
|
|
3132
|
+
case "yandex": {
|
|
3133
|
+
const key = await resolveApiKey("YANDEX_API_KEY", "yandexApiKey");
|
|
3134
|
+
if (!key) return { ok: false, error: "YANDEX_API_KEY not configured" };
|
|
3135
|
+
if (!cfg.yandexFolderId) return { ok: false, error: "yandexFolderId not configured" };
|
|
3136
|
+
return await searchYandex(q, n, key, cfg.yandexFolderId, {
|
|
3137
|
+
searchType: cfg.yandexSearchType,
|
|
3138
|
+
lang: searchLanguage(configLanguage(cfg)),
|
|
3139
|
+
safeSearch: cfg.safeSearch,
|
|
3140
|
+
}, tr);
|
|
3141
|
+
}
|
|
3070
3142
|
case "agy": {
|
|
3071
3143
|
if (!agyAvailable()) return { ok: false, error: "Antigravity CLI not installed (install Antigravity or set AGY_BIN)" };
|
|
3072
3144
|
return await searchAgy(q, n, {});
|
package/lib/multi_policy.js
CHANGED
|
@@ -221,6 +221,8 @@ 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" }],
|
|
225
|
+
yandex: [{ env: "YANDEX_API_KEY", settings: "yandexApiKey" }],
|
|
224
226
|
tinyfish: [{ env: "TINYFISH_API_KEY", settings: "tinyfishApiKey" }],
|
|
225
227
|
jina: [{ env: "JINA_API_KEY", settings: "jinaApiKey" }],
|
|
226
228
|
baidu: [{ env: "BAIDU_API_KEY", settings: "baiduApiKey" }],
|
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.43",
|
|
4
|
+
"description": "Free web search for DeepSeek Harness: 38 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/Yandex 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": {
|