dsh-free-search 0.9.35 → 0.9.36
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 +10 -4
- package/lib/client.js +58 -1
- package/lib/engine_meta.js +101 -0
- package/lib/engines/aliyun.js +124 -0
- package/lib/engines/anysearch.js +69 -0
- package/lib/engines/baidu.js +81 -0
- package/lib/engines/bing.js +81 -0
- package/lib/engines/claude.js +76 -0
- package/lib/engines/ddg-lite.js +37 -0
- package/lib/engines/ddg.js +33 -0
- package/lib/engines/deepseek-official.js +73 -0
- package/lib/engines/deepseek-tools.js +72 -0
- package/lib/engines/degoog.js +73 -0
- package/lib/engines/doubao.js +92 -0
- package/lib/engines/exa.js +124 -0
- package/lib/engines/firecrawl.js +76 -0
- package/lib/engines/gemini.js +67 -0
- package/lib/engines/jina.js +41 -0
- package/lib/engines/keenable.js +124 -0
- package/lib/engines/kimi.js +72 -0
- package/lib/engines/openai.js +67 -0
- package/lib/engines/outcrawl.js +38 -0
- package/lib/engines/parallel.js +156 -0
- package/lib/engines/perplexity.js +39 -0
- package/lib/engines/searxng.js +66 -0
- package/lib/engines/serpbase.js +61 -0
- package/lib/engines/serply.js +46 -0
- package/lib/engines/shared.js +334 -0
- package/lib/engines/tavily.js +58 -0
- package/lib/engines/tinyfish.js +47 -0
- package/lib/engines/you.js +73 -0
- package/lib/engines/zhihu_global.js +23 -0
- package/lib/engines/zhihu_shared.js +41 -0
- package/lib/engines/zhihu_site.js +15 -0
- package/lib/index.js +4113 -6357
- package/package.json +126 -126
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# dsh-free-search
|
|
2
2
|
|
|
3
|
+
[](https://github.com/DDDMUC/dsh-free-search/actions/workflows/ci.yml)
|
|
4
|
+
|
|
3
5
|
**DeepSeek Harness 免费搜索插件:无需 API key,零成本,多引擎可切换。** 这是一个给 DeepSeek Harness (dsh) 添加多引擎搜索 provider 的插件,注册进 `ctx.web` seam。内置 `web_search` 工具自动选用,支持网页设置页切换引擎、配置 API key、一键测试所有引擎、弹出式命令切换引擎。
|
|
4
6
|
|
|
5
7
|
[中文](#中文) · [English](#english)
|
|
@@ -256,7 +258,7 @@ DSH 0.2.1 设置 → 网页搜索 → **DeepSeek 搜索 API** 开关会和本插
|
|
|
256
258
|
|
|
257
259
|
- `searchProvider: ddg` —— 本插件的 **provider id(固定值)**,不是"使用 DuckDuckGo 引擎";用哪个引擎由设置页的 `provider` 字段决定(`bing`/`baidu`/`auto`/…)。
|
|
258
260
|
- `fetchProvider: fs-quality-fetch` —— 本插件的抓取 provider(直接 → exa contents → firecrawl → crawl4ai)。
|
|
259
|
-
-
|
|
261
|
+
- 想改用官方搜索:设置页「抓取」段点「恢复官方搜索」,或**先删掉 `- id: web` 的两行,再在插件管理器里停用本插件**。
|
|
260
262
|
|
|
261
263
|
#### 依赖说明
|
|
262
264
|
|
|
@@ -576,7 +578,7 @@ Search engine test:
|
|
|
576
578
|
|
|
577
579
|
#### 离线自检断言(tools/)
|
|
578
580
|
|
|
579
|
-
仓库自带 **
|
|
581
|
+
仓库自带 **47 个**零依赖断言脚本(合计 **776 项**),**不需要 API key、不联网、不需要测试框架**,Node ≥ 20 即可跑:
|
|
580
582
|
|
|
581
583
|
| 脚本 | 覆盖 | 运行(项数) |
|
|
582
584
|
|---|---|---|
|
|
@@ -586,6 +588,8 @@ Search engine test:
|
|
|
586
588
|
| `assert-blocked-domains.mjs` | 域名黑名单:解析、匹配、收口,且前后端清洗同口径 | `node tools/assert-blocked-domains.mjs`(69) |
|
|
587
589
|
| `assert-multi-policy.mjs` | multi 执行策略:并发上限是天花板 / 目标成功源非硬下限 / 凭据资格在上限之前分流 / **Fast·Balanced·Deep 档位** | `node tools/assert-multi-policy.mjs`(146) |
|
|
588
590
|
| `assert-multi-limit.mjs` | multi 结果上限(#109):默认 20 / 硬上限 100 / 配置归一化、单次 maxResults 受上限约束、工具参数与本段提示词写明生效上限、设置页字段与保存 | `node tools/assert-multi-limit.mjs`(6) |
|
|
591
|
+
| `assert-maintenance.mjs` | 维护面:CI 在 Node 20/22/24 跑全部断言并过打包闸门、发布脚本会 bump / 校验 / 打 tag / 可发布、恢复官方 provider 的桥接与设置页按钮 | `node tools/assert-maintenance.mjs`(4) |
|
|
592
|
+
| `assert-engine-modules.mjs` | 引擎分层:实现文件存在且被 index 引用、引擎函数已迁出 index、设置页引擎 id 与服务端清单一致、清单覆盖 35 个引擎且免费/按次标记正确 | `node tools/assert-engine-modules.mjs`(4) |
|
|
589
593
|
| `assert-result-ranking.mjs` | 合并排序:**eTLD+1 同域判定** / 域名轮转 / `seenIn` 降为末位 / 时效仅带时间过滤时生效 | `node tools/assert-result-ranking.mjs`(31) |
|
|
590
594
|
| `assert-url-norm.mjs` | URL 规范化:只剔已审计的 tracking 参数,保留可能区分资源的参数 | `node tools/assert-url-norm.mjs`(72) |
|
|
591
595
|
| `assert-prompt-contract.mjs` | 系统提示词契约:**检索≠抓取**、不可信边界、模型内置搜索只在显式选中时运行 | `node tools/assert-prompt-contract.mjs`(9) |
|
|
@@ -902,7 +906,7 @@ Use `/free-search-engine` or this plugin's settings page to change engines, **no
|
|
|
902
906
|
|
|
903
907
|
- `searchProvider: ddg` — this plugin's **fixed provider id**, not "use the DuckDuckGo engine"; the engine is chosen by the `provider` field in settings (`bing` / `baidu` / `auto` / …).
|
|
904
908
|
- `fetchProvider: fs-quality-fetch` — this plugin's fetch provider (direct → exa contents → firecrawl → crawl4ai).
|
|
905
|
-
- To go back to official search: **remove those `- id: web` lines first, then disable this plugin** in the plugin manager.
|
|
909
|
+
- To go back to official search: click Restore official search in the Fetch section, or **remove those `- id: web` lines first, then disable this plugin** in the plugin manager.
|
|
906
910
|
|
|
907
911
|
#### Dependency Note
|
|
908
912
|
|
|
@@ -1222,7 +1226,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1222
1226
|
|
|
1223
1227
|
#### Offline self-check assertions (`tools/`)
|
|
1224
1228
|
|
|
1225
|
-
**Forty-
|
|
1229
|
+
**Forty-seven** zero-dependency assertion scripts ship with the repo (**776 assertions** total): **no API keys, no network, no test framework**, Node ≥ 20:
|
|
1226
1230
|
|
|
1227
1231
|
| Script | Covers | Run (count) |
|
|
1228
1232
|
|---|---|---|
|
|
@@ -1232,6 +1236,8 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1232
1236
|
| `assert-blocked-domains.mjs` | domain blocklist: parsing, matching, choke points, and byte-identical front/back-end sanitizing | `node tools/assert-blocked-domains.mjs` (69) |
|
|
1233
1237
|
| `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) |
|
|
1234
1238
|
| `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) |
|
|
1239
|
+
| `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) |
|
|
1240
|
+
| `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, and the catalog covers 35 engines with the right free/explicit flags | `node tools/assert-engine-modules.mjs` (4) |
|
|
1235
1241
|
| `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) |
|
|
1236
1242
|
| `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) |
|
|
1237
1243
|
| `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) |
|
package/lib/client.js
CHANGED
|
@@ -429,6 +429,12 @@ window.__ModuleLoader__.load({
|
|
|
429
429
|
marketAuto: "自动 —— 不发送 mkt(推荐用于非上列地区)",
|
|
430
430
|
fetchTakeoverLabel: "自动接管 web_fetch",
|
|
431
431
|
fetchTakeoverHint: "开启时:web.fetchProvider 未设置或仍是出厂默认 http 会接管为 fs-quality-fetch。如果你刻意 pin 了 http(例如只想用内置抓取),关掉此项。",
|
|
432
|
+
restoreOfficial: "恢复官方搜索",
|
|
433
|
+
restoreOfficialHint: "把 web.searchProvider 改回 deepseek-official、web.fetchProvider 改回 http。停用或卸载本插件前建议先点一次,避免宿主报 configured web provider \"ddg\" is not registered。",
|
|
434
|
+
restoringOfficial: "恢复中…",
|
|
435
|
+
restoreOfficialDone: "已恢复官方搜索 provider,重启 DSH 后生效。",
|
|
436
|
+
restoreOfficialNone: "当前已经是官方 provider,无需恢复。",
|
|
437
|
+
restoreOfficialFailed: (m) => `恢复失败:${m}`,
|
|
432
438
|
navLabel: "本页导航",
|
|
433
439
|
navEngines: "引擎",
|
|
434
440
|
navFallback: "回退",
|
|
@@ -579,6 +585,12 @@ window.__ModuleLoader__.load({
|
|
|
579
585
|
marketAuto: "Automatic — send no mkt (recommended outside the listed regions)",
|
|
580
586
|
fetchTakeoverLabel: "Take over web_fetch automatically",
|
|
581
587
|
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).",
|
|
588
|
+
restoreOfficial: "Restore official search",
|
|
589
|
+
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.",
|
|
590
|
+
restoringOfficial: "Restoring…",
|
|
591
|
+
restoreOfficialDone: "Official providers restored; restart DSH to apply.",
|
|
592
|
+
restoreOfficialNone: "The official providers are already active.",
|
|
593
|
+
restoreOfficialFailed: (m) => `Restore failed: ${m}`,
|
|
582
594
|
navLabel: "On this page",
|
|
583
595
|
navEngines: "Engines",
|
|
584
596
|
navFallback: "Fallback",
|
|
@@ -622,7 +634,7 @@ window.__ModuleLoader__.load({
|
|
|
622
634
|
"cache_search",
|
|
623
635
|
"domain_search",
|
|
624
636
|
];
|
|
625
|
-
const PLUGIN_VERSION = "0.9.
|
|
637
|
+
const PLUGIN_VERSION = "0.9.36";
|
|
626
638
|
const PLUGIN_REPO_URL = "https://github.com/DDDMUC/dsh-free-search";
|
|
627
639
|
// 右侧浮动目录(#85):条目顺序即页面顺序,anchor 是页面里对应 field 的 id。
|
|
628
640
|
const NAV_ITEMS = [
|
|
@@ -753,6 +765,15 @@ window.__ModuleLoader__.load({
|
|
|
753
765
|
return { domains, stats };
|
|
754
766
|
};
|
|
755
767
|
|
|
768
|
+
async function bridgeRestoreProvider() {
|
|
769
|
+
const response = await fetch(`${BRIDGE_PREFIX}/restore-provider`, {
|
|
770
|
+
method: "POST",
|
|
771
|
+
headers: { "content-type": "application/json" },
|
|
772
|
+
body: "{}",
|
|
773
|
+
});
|
|
774
|
+
return response.json();
|
|
775
|
+
}
|
|
776
|
+
|
|
756
777
|
async function bridgeCheckUpdate() {
|
|
757
778
|
const response = await fetch(`${BRIDGE_PREFIX}/check-update`, {
|
|
758
779
|
method: "POST",
|
|
@@ -954,6 +975,8 @@ window.__ModuleLoader__.load({
|
|
|
954
975
|
const [checkingUpdate, setCheckingUpdate] = react.useState(false);
|
|
955
976
|
const [upgrading, setUpgrading] = react.useState(false);
|
|
956
977
|
const [updateInfo, setUpdateInfo] = react.useState(null);
|
|
978
|
+
const [restoreRunning, setRestoreRunning] = react.useState(false);
|
|
979
|
+
const [restoreMessage, setRestoreMessage] = react.useState("");
|
|
957
980
|
const [doctorText, setDoctorText] = react.useState("");
|
|
958
981
|
const [doctorRunning, setDoctorRunning] = react.useState(false);
|
|
959
982
|
// 回退优先级/池列表行内 key 输入:引擎 id → [当前值, setter](zhihu 两引擎共享 ZHIHU_API_KEY)
|
|
@@ -1254,6 +1277,24 @@ window.__ModuleLoader__.load({
|
|
|
1254
1277
|
setSaveError("");
|
|
1255
1278
|
};
|
|
1256
1279
|
|
|
1280
|
+
const runRestoreProvider = async () => {
|
|
1281
|
+
setRestoreRunning(true);
|
|
1282
|
+
setRestoreMessage("");
|
|
1283
|
+
try {
|
|
1284
|
+
const result = await bridgeRestoreProvider();
|
|
1285
|
+
if (result.ok) {
|
|
1286
|
+
setRestoreMessage(result.value?.changed ? t.restoreOfficialDone : t.restoreOfficialNone);
|
|
1287
|
+
if (result.value?.changed) load();
|
|
1288
|
+
} else {
|
|
1289
|
+
setRestoreMessage(t.restoreOfficialFailed(result.message ?? "unknown"));
|
|
1290
|
+
}
|
|
1291
|
+
} catch (error) {
|
|
1292
|
+
setRestoreMessage(t.restoreOfficialFailed(error && error.message ? error.message : String(error)));
|
|
1293
|
+
} finally {
|
|
1294
|
+
setRestoreRunning(false);
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1257
1298
|
const runCheckUpdate = async () => {
|
|
1258
1299
|
setCheckingUpdate(true);
|
|
1259
1300
|
setUpdateInfo(null);
|
|
@@ -2263,6 +2304,22 @@ react_jsx_runtime.jsx("div", {
|
|
|
2263
2304
|
}),
|
|
2264
2305
|
],
|
|
2265
2306
|
}),
|
|
2307
|
+
react_jsx_runtime.jsx("div", {
|
|
2308
|
+
className: "dshfs-field",
|
|
2309
|
+
children: [
|
|
2310
|
+
react_jsx_runtime.jsx("button", {
|
|
2311
|
+
className: "dshfs-btn",
|
|
2312
|
+
type: "button",
|
|
2313
|
+
onClick: runRestoreProvider,
|
|
2314
|
+
disabled: restoreRunning || saving || !ready,
|
|
2315
|
+
children: restoreRunning ? t.restoringOfficial : t.restoreOfficial,
|
|
2316
|
+
}),
|
|
2317
|
+
react_jsx_runtime.jsx("p", {
|
|
2318
|
+
className: "dshfs-hint",
|
|
2319
|
+
children: restoreMessage || t.restoreOfficialHint,
|
|
2320
|
+
}),
|
|
2321
|
+
],
|
|
2322
|
+
}),
|
|
2266
2323
|
react_jsx_runtime.jsx("div", {
|
|
2267
2324
|
className: "dshfs-field",
|
|
2268
2325
|
children: [
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine catalog: the one place that defines which engines exist, their order,
|
|
3
|
+
* and their static capabilities. Routing, prompts, the settings client and the
|
|
4
|
+
* fallback chain all derive from these lists instead of keeping parallel copies
|
|
5
|
+
* (add an engine here first; the client has its own copy in the web bundle).
|
|
6
|
+
*/
|
|
7
|
+
import { SERP_ENGINE_IDS, SERP_TIME_ENGINES } from "./serp_engines.js";
|
|
8
|
+
|
|
9
|
+
// Base order is the order the settings page and prompts have always used.
|
|
10
|
+
const BASE_ENGINES = [
|
|
11
|
+
{ id: "ddg", free: true, time: true },
|
|
12
|
+
{ id: "ddg-lite", free: true, time: true },
|
|
13
|
+
{ id: "bing", free: true, time: false },
|
|
14
|
+
{ id: "searxng", free: true, time: true },
|
|
15
|
+
{ id: "degoog", free: true, time: true },
|
|
16
|
+
{ id: "anysearch", free: true, time: false },
|
|
17
|
+
{ id: "exa", free: false, time: true },
|
|
18
|
+
{ id: "tavily", free: false, time: true },
|
|
19
|
+
{ id: "keenable", free: false, time: true },
|
|
20
|
+
{ id: "firecrawl", free: false, time: true },
|
|
21
|
+
{ id: "parallel", free: false, time: true },
|
|
22
|
+
{ id: "perplexity", free: false, time: false },
|
|
23
|
+
{ id: "serpbase", free: false, time: false },
|
|
24
|
+
{ id: "serply", free: false, time: false },
|
|
25
|
+
{ id: "outcrawl", free: false, time: false },
|
|
26
|
+
{ id: "deepseek-official", free: false, time: false },
|
|
27
|
+
{ id: "deepseek-tools", free: false, time: true },
|
|
28
|
+
{ id: "you", free: false, time: false },
|
|
29
|
+
{ id: "baidu", free: false, time: true },
|
|
30
|
+
{ id: "kimi", free: false, time: false },
|
|
31
|
+
{ id: "aliyun", free: false, time: false },
|
|
32
|
+
{ id: "doubao", free: false, time: true },
|
|
33
|
+
{ id: "tinyfish", free: false, time: true },
|
|
34
|
+
{ id: "jina", free: false, time: false },
|
|
35
|
+
{ id: "zhihu_global", free: false, time: true },
|
|
36
|
+
{ id: "zhihu_site", free: false, time: false },
|
|
37
|
+
{ id: "agy", free: false, time: false },
|
|
38
|
+
{ id: "openai", free: false, time: false, explicitOnly: true },
|
|
39
|
+
{ id: "gemini", free: false, time: false, explicitOnly: true },
|
|
40
|
+
{ id: "claude", free: false, time: false, explicitOnly: true },
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
/** Every engine id, base engines first and the HTML SERP family last. */
|
|
44
|
+
export const ALL_ENGINES = [...BASE_ENGINES.map((engine) => engine.id), ...SERP_ENGINE_IDS];
|
|
45
|
+
|
|
46
|
+
/** Engines that need no credential at all. */
|
|
47
|
+
export const FREE_ENGINES = BASE_ENGINES.filter((engine) => engine.free).map((engine) => engine.id);
|
|
48
|
+
|
|
49
|
+
/** Per-call billed model searches: never auto-routed, only explicit picks. */
|
|
50
|
+
export const EXPLICIT_ONLY_ENGINES = BASE_ENGINES.filter((engine) => engine.explicitOnly).map((engine) => engine.id);
|
|
51
|
+
|
|
52
|
+
// Time-filter support. The order is deliberate (tavily before exa) and differs
|
|
53
|
+
// from the base order, so it stays explicit instead of being filtered from BASE.
|
|
54
|
+
export const TIME_ENGINES = [
|
|
55
|
+
"tavily",
|
|
56
|
+
"exa",
|
|
57
|
+
"keenable",
|
|
58
|
+
"firecrawl",
|
|
59
|
+
"parallel",
|
|
60
|
+
"searxng",
|
|
61
|
+
"degoog",
|
|
62
|
+
"ddg",
|
|
63
|
+
"ddg-lite",
|
|
64
|
+
"baidu",
|
|
65
|
+
"doubao",
|
|
66
|
+
"tinyfish",
|
|
67
|
+
"deepseek-tools",
|
|
68
|
+
"zhihu_global",
|
|
69
|
+
...SERP_TIME_ENGINES,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
/** Default fallback chain order (the settings UI exposes it as a sort list). */
|
|
73
|
+
export const DEFAULT_FALLBACK_ORDER = [
|
|
74
|
+
"exa",
|
|
75
|
+
"tavily",
|
|
76
|
+
"keenable",
|
|
77
|
+
"firecrawl",
|
|
78
|
+
"parallel",
|
|
79
|
+
"perplexity",
|
|
80
|
+
"serpbase",
|
|
81
|
+
"serply",
|
|
82
|
+
"outcrawl",
|
|
83
|
+
"agy",
|
|
84
|
+
"deepseek-tools",
|
|
85
|
+
"deepseek-official",
|
|
86
|
+
"you",
|
|
87
|
+
"baidu",
|
|
88
|
+
"kimi",
|
|
89
|
+
"aliyun",
|
|
90
|
+
"doubao",
|
|
91
|
+
"tinyfish",
|
|
92
|
+
"jina",
|
|
93
|
+
"bing",
|
|
94
|
+
"anysearch",
|
|
95
|
+
"ddg",
|
|
96
|
+
"ddg-lite",
|
|
97
|
+
"searxng",
|
|
98
|
+
"degoog",
|
|
99
|
+
"zhihu_global",
|
|
100
|
+
"zhihu_site",
|
|
101
|
+
];
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Aliyun Bailian search engine.
|
|
2
|
+
import { TINYFISH_URL, JINA_URL, DOUBAO_SEARCH_URL, snippetCap, stripTags, uniqueSources } from "./shared.js";
|
|
3
|
+
import { TIME_ENGINES } from "../engine_meta.js";
|
|
4
|
+
|
|
5
|
+
export async function searchAliyun(query, maxResults, apiKey, timeRange, signal) {
|
|
6
|
+
if (!apiKey) throw new Error("Aliyun search requires DASHSCOPE_API_KEY");
|
|
7
|
+
const trimmed = String(query).trim();
|
|
8
|
+
const q = trimmed.length < 2 ? `${trimmed} ` : trimmed.slice(0, 500);
|
|
9
|
+
|
|
10
|
+
const rpcBody = {
|
|
11
|
+
jsonrpc: "2.0",
|
|
12
|
+
id: 1,
|
|
13
|
+
method: "tools/call",
|
|
14
|
+
params: {
|
|
15
|
+
name: "search_pro",
|
|
16
|
+
arguments: { query: q },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const timer = setTimeout(() => controller.abort(), 35000);
|
|
22
|
+
const onAbort = () => controller.abort();
|
|
23
|
+
signal?.addEventListener("abort", onAbort);
|
|
24
|
+
let response;
|
|
25
|
+
try {
|
|
26
|
+
response = await fetch("https://dashscope.aliyuncs.com/api/v1/mcps/EnhancedSearch/mcp", {
|
|
27
|
+
method: "POST",
|
|
28
|
+
redirect: "error",
|
|
29
|
+
headers: {
|
|
30
|
+
authorization: `Bearer ${apiKey}`,
|
|
31
|
+
"content-type": "application/json",
|
|
32
|
+
accept: "application/json, text/event-stream",
|
|
33
|
+
"user-agent": "deepseek-harness/free-search",
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify(rpcBody),
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (signal?.aborted) throw error;
|
|
40
|
+
throw new Error(`Aliyun search request failed: ${error?.message ?? String(error)}`);
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
signal?.removeEventListener("abort", onAbort);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const detail = await response.text().catch(() => "");
|
|
48
|
+
if (response.status === 401 || response.status === 403) {
|
|
49
|
+
throw new Error(`Aliyun API key is invalid (HTTP ${response.status}) - update it in Settings > Plugins > Free Search`);
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Aliyun API error (HTTP ${response.status}): ${detail.slice(0, 200)}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const rawText = await response.text();
|
|
55
|
+
let envelope;
|
|
56
|
+
try {
|
|
57
|
+
envelope = JSON.parse(rawText);
|
|
58
|
+
} catch {
|
|
59
|
+
// 处理可能的 SSE 帧 (data: { ... })
|
|
60
|
+
const dataLine = rawText.split("\n").find((l) => l.startsWith("data:"));
|
|
61
|
+
if (dataLine) {
|
|
62
|
+
try {
|
|
63
|
+
envelope = JSON.parse(dataLine.slice(5).trim());
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throw new Error(`Aliyun MCP response SSE parse failed: ${rawText.slice(0, 200)}`);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
throw new Error(`Aliyun MCP response is not valid JSON: ${rawText.slice(0, 200)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (envelope.error) {
|
|
73
|
+
throw new Error(`Aliyun MCP error ${envelope.error.code}: ${envelope.error.message}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const callResult = envelope.result;
|
|
77
|
+
if (!callResult || typeof callResult !== "object") {
|
|
78
|
+
throw new Error(`Aliyun MCP result missing: ${JSON.stringify(envelope).slice(0, 200)}`);
|
|
79
|
+
}
|
|
80
|
+
if (callResult.isError) {
|
|
81
|
+
throw new Error(`Aliyun tool error: ${JSON.stringify(callResult).slice(0, 200)}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const contents = callResult.content;
|
|
85
|
+
if (!Array.isArray(contents) || contents.length === 0) {
|
|
86
|
+
return { sources: [], truncated: false };
|
|
87
|
+
}
|
|
88
|
+
const textItem = contents.find((c) => c && c.type === "text" && typeof c.text === "string");
|
|
89
|
+
if (!textItem) {
|
|
90
|
+
return { sources: [], truncated: false };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let inner;
|
|
94
|
+
try {
|
|
95
|
+
inner = JSON.parse(textItem.text);
|
|
96
|
+
} catch (err) {
|
|
97
|
+
throw new Error(`Aliyun inner content JSON parse error: ${textItem.text.slice(0, 200)}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const pages = inner.pages;
|
|
101
|
+
if (!Array.isArray(pages)) {
|
|
102
|
+
return { sources: [], truncated: false };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const sources = pages
|
|
106
|
+
.filter((p) => p && p.url)
|
|
107
|
+
.map((p) => ({
|
|
108
|
+
url: p.url,
|
|
109
|
+
...(p.title ? { title: String(p.title) } : {}),
|
|
110
|
+
...(p.snippet ? { snippet: String(p.snippet).slice(0, 300) } : {}),
|
|
111
|
+
...(p.published_at ? { publishedAt: String(p.published_at) } : {}),
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
return { sources: uniqueSources(sources, maxResults ?? 10), truncated: false };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// ── 知乎开放平台 MCP(developer.zhihu.com/api/mcp/v1)─────────────────────────
|
|
119
|
+
// 两个引擎共用一套 MCP 适配器(lib/mcp_adapter.js,方案 v4.3 §2.7):
|
|
120
|
+
// zhihu_global → tools/call global_search(全网,filter 支持 publish_time>=unix秒 → 入 TIME_ENGINES)
|
|
121
|
+
// zhihu_site → tools/call zhihu_search(站内,未验证时间过滤 → 不入 TIME_ENGINES)
|
|
122
|
+
// 服务端为无状态 streamable-http:实测直连 tools/call 即可(initialize 非必需,也无 session 头),
|
|
123
|
+
// 响应可能是纯 JSON 或 SSE 帧——两种格式由适配器统一解析。
|
|
124
|
+
// key = ZHIHU_API_KEY(凭据中心 → 本条目 config zhihuApiKey → 环境变量,三级解析;无 key 时引擎跳过不阻断回退链)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// AnySearch AI engine (anonymous tier, optional key).
|
|
2
|
+
import { uniqueSources, fetchHtmlWithRetry, stripTags, decodeEntities, approximateTimeRange, SEARXNG_INSTANCES, SEARXNG_TIME, ANYSEARCH_URL, EXA_MCP_URL, extractDdgUrl, MARKET_TO_LANG, LANG_PROFILES, BING_URL, DDG_HTML_URL, DDG_LITE_URL, activeAcceptLanguage, USER_AGENT, searchLanguage, configLanguage, activeOutputLanguage } from "./shared.js";
|
|
3
|
+
|
|
4
|
+
let ignoredAnysearchKey = "";
|
|
5
|
+
|
|
6
|
+
const ANYSEARCH_KEY_INVALID_NOTE_ZH = "AnySearch key 无效,本次已忽略该 key,改回免费匿名档";
|
|
7
|
+
|
|
8
|
+
const ANYSEARCH_KEY_INVALID_NOTE_EN = "AnySearch key was rejected; ignored it and used the anonymous tier";
|
|
9
|
+
|
|
10
|
+
function anysearchKeyNote() {
|
|
11
|
+
return activeOutputLanguage === "zh" ? ANYSEARCH_KEY_INVALID_NOTE_ZH : ANYSEARCH_KEY_INVALID_NOTE_EN;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function searchAnysearch(query, maxResults, signal, apiKey) {
|
|
15
|
+
const trimmedKey = typeof apiKey === "string" ? apiKey.trim() : "";
|
|
16
|
+
// 本进程已判定无效的 key 不再发送;若配置里仍有该值,结果仍带忽略提示
|
|
17
|
+
const keyIgnoredSticky = Boolean(trimmedKey) && trimmedKey === ignoredAnysearchKey;
|
|
18
|
+
const sendKey = trimmedKey && !keyIgnoredSticky ? trimmedKey : "";
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
const timer = setTimeout(() => controller.abort(), 12000);
|
|
21
|
+
const onAbort = () => controller.abort();
|
|
22
|
+
signal?.addEventListener("abort", onAbort);
|
|
23
|
+
const doFetch = async (key) => {
|
|
24
|
+
const headers = { "content-type": "application/json" };
|
|
25
|
+
if (key) headers.authorization = `Bearer ${key}`;
|
|
26
|
+
return await fetch(ANYSEARCH_URL, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers,
|
|
29
|
+
body: JSON.stringify({ query, max_results: maxResults ?? 5 }),
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
let response;
|
|
34
|
+
let keyRejected = false;
|
|
35
|
+
try {
|
|
36
|
+
response = await doFetch(sendKey);
|
|
37
|
+
if ((response.status === 401 || response.status === 403) && sendKey) {
|
|
38
|
+
ignoredAnysearchKey = sendKey;
|
|
39
|
+
keyRejected = true;
|
|
40
|
+
response = await doFetch("");
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (signal?.aborted) throw error;
|
|
44
|
+
throw new Error(`AnySearch request failed: ${error?.message ?? String(error)}`);
|
|
45
|
+
} finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
signal?.removeEventListener("abort", onAbort);
|
|
48
|
+
}
|
|
49
|
+
if (response.status === 401 || response.status === 403) {
|
|
50
|
+
throw new Error(keyRejected ? `${anysearchKeyNote()} (HTTP ${response.status})` : `AnySearch API error (HTTP ${response.status})`);
|
|
51
|
+
}
|
|
52
|
+
if (!response.ok) throw new Error(`AnySearch API error (HTTP ${response.status})`);
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
if (data.code !== 0) throw new Error(`AnySearch API error: ${data.message ?? data.code}`);
|
|
55
|
+
const results = data.data?.results ?? [];
|
|
56
|
+
return {
|
|
57
|
+
sources: results
|
|
58
|
+
.filter((r) => r.url)
|
|
59
|
+
.map((r) => ({
|
|
60
|
+
url: r.url,
|
|
61
|
+
...(r.title ? { title: String(r.title) } : {}),
|
|
62
|
+
...(r.snippet ? { snippet: String(r.snippet).slice(0, 300) } : {}),
|
|
63
|
+
})),
|
|
64
|
+
truncated: false,
|
|
65
|
+
...(keyRejected || keyIgnoredSticky ? { content: anysearchKeyNote() } : {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Exa MCP: 匿名公开 MCP(无 key),web_search_exa 工具
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Baidu Qianfan AI Search engine.
|
|
2
|
+
import { TINYFISH_URL, JINA_URL, DOUBAO_SEARCH_URL, snippetCap, stripTags, uniqueSources } from "./shared.js";
|
|
3
|
+
import { TIME_ENGINES } from "../engine_meta.js";
|
|
4
|
+
|
|
5
|
+
export async function searchBaidu(query, maxResults, apiKey, timeRange, signal) {
|
|
6
|
+
if (!apiKey) throw new Error("Baidu search requires BAIDU_API_KEY");
|
|
7
|
+
const count = Math.min(Math.max(maxResults ?? 10, 1), 50);
|
|
8
|
+
const searchFilter = {};
|
|
9
|
+
if (timeRange) {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
const end = new Date(now.getTime() + 86400000).toISOString().slice(0, 10);
|
|
12
|
+
let start;
|
|
13
|
+
if (timeRange.after) {
|
|
14
|
+
start = timeRange.after;
|
|
15
|
+
} else if (timeRange.days !== undefined) {
|
|
16
|
+
start = new Date(now.getTime() - timeRange.days * 86400000).toISOString().slice(0, 10);
|
|
17
|
+
}
|
|
18
|
+
if (start) {
|
|
19
|
+
searchFilter.range = { page_time: { gte: start, lt: end } };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const body = {
|
|
24
|
+
messages: [{ content: query, role: "user" }],
|
|
25
|
+
search_source: "baidu_search_v2",
|
|
26
|
+
resource_type_filter: [{ type: "web", top_k: count }],
|
|
27
|
+
search_filter: searchFilter,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => controller.abort(), 15000);
|
|
32
|
+
const onAbort = () => controller.abort();
|
|
33
|
+
signal?.addEventListener("abort", onAbort);
|
|
34
|
+
let response;
|
|
35
|
+
try {
|
|
36
|
+
response = await fetch("https://qianfan.baidubce.com/v2/ai_search/web_search", {
|
|
37
|
+
method: "POST",
|
|
38
|
+
redirect: "error",
|
|
39
|
+
headers: {
|
|
40
|
+
"content-type": "application/json",
|
|
41
|
+
authorization: `Bearer ${apiKey}`,
|
|
42
|
+
"X-Appbuilder-From": "openclaw",
|
|
43
|
+
"user-agent": "deepseek-harness/free-search",
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify(body),
|
|
46
|
+
signal: controller.signal,
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (signal?.aborted) throw error;
|
|
50
|
+
throw new Error(`Baidu search request failed: ${error?.message ?? String(error)}`);
|
|
51
|
+
} finally {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
signal?.removeEventListener("abort", onAbort);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const detail = await response.text().catch(() => "");
|
|
58
|
+
if (response.status === 401 || response.status === 403) {
|
|
59
|
+
throw new Error(`Baidu API key is invalid (HTTP ${response.status}) - update it in Settings > Plugins > Free Search`);
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Baidu API error (HTTP ${response.status}): ${detail.slice(0, 200)}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const results = await response.json();
|
|
65
|
+
if (results.code) {
|
|
66
|
+
throw new Error(`Baidu API error: ${results.message ?? JSON.stringify(results)}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const sources = (results.references ?? [])
|
|
70
|
+
.filter((r) => r.url)
|
|
71
|
+
.map((r) => ({
|
|
72
|
+
url: r.url,
|
|
73
|
+
...(r.title ? { title: String(r.title) } : {}),
|
|
74
|
+
...(r.content ? { snippet: String(r.content).slice(0, 300) } : {}),
|
|
75
|
+
...(r.date ? { publishedAt: String(r.date) } : {}),
|
|
76
|
+
}));
|
|
77
|
+
return { sources: uniqueSources(sources, maxResults ?? 10), truncated: false };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Kimi (Moonshot) 开放平台联网搜索 basic (/v1/tools/search)
|
|
81
|
+
// key = MOONSHOT_API_KEY
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Bing HTML engine; one fetch, no retry loop (see assert-engines).
|
|
2
|
+
import { uniqueSources, fetchHtmlWithRetry, stripTags, decodeEntities, approximateTimeRange, SEARXNG_INSTANCES, SEARXNG_TIME, ANYSEARCH_URL, EXA_MCP_URL, extractDdgUrl, MARKET_TO_LANG, LANG_PROFILES, BING_URL, DDG_HTML_URL, DDG_LITE_URL, activeAcceptLanguage, USER_AGENT, searchLanguage, configLanguage, activeOutputLanguage } from "./shared.js";
|
|
3
|
+
|
|
4
|
+
function queryOverlapTokens(query) {
|
|
5
|
+
const tokens = new Set();
|
|
6
|
+
for (const run of String(query).match(/[\u4e00-\u9fff]+/g) ?? []) {
|
|
7
|
+
if (run.length <= 2) tokens.add(run);
|
|
8
|
+
for (let i = 0; i + 1 < run.length; i++) tokens.add(run.slice(i, i + 2));
|
|
9
|
+
}
|
|
10
|
+
for (const word of String(query).toLowerCase().split(/[^a-z0-9]+/)) {
|
|
11
|
+
if (word.length >= 2) tokens.add(word);
|
|
12
|
+
}
|
|
13
|
+
return [...tokens];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function looksRelevant(query, sources) {
|
|
17
|
+
const tokens = queryOverlapTokens(query);
|
|
18
|
+
if (tokens.length === 0) return true; // 纯符号查询无法判定,不拦截
|
|
19
|
+
return sources.some((s) => {
|
|
20
|
+
const hay = `${s.title ?? ""} ${s.snippet ?? ""} ${s.url ?? ""}`.toLowerCase();
|
|
21
|
+
return tokens.some((t) => hay.includes(t.toLowerCase()));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Bing 会把结果 URL 包成 bing.com/ck/a 跳转链接:真实地址在 u 参数(base64url,a1 前缀)
|
|
26
|
+
|
|
27
|
+
function extractBingUrl(href) {
|
|
28
|
+
if (!href) return href;
|
|
29
|
+
const url = decodeEntities(href); // & -> &
|
|
30
|
+
if (!/^https?:\/\/(www\.)?bing\.com\/ck\/a/i.test(url)) return href;
|
|
31
|
+
try {
|
|
32
|
+
const u = new URL(url).searchParams.get("u");
|
|
33
|
+
if (!u) return href;
|
|
34
|
+
const b64 = u.startsWith("a1") ? u.slice(2) : u;
|
|
35
|
+
const decoded = Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8");
|
|
36
|
+
return /^https?:\/\//i.test(decoded) ? decoded : href;
|
|
37
|
+
} catch {
|
|
38
|
+
return href;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function searchBing(query, maxResults, options, signal) {
|
|
43
|
+
// mkt:仅显式 bingMarket 才发。默认不发——mkt=zh-CN 在部分地区/线路会返回空 SERP 容器
|
|
44
|
+
// (#71:海外 IP + mkt=zh-CN → b_algo=0),Bing 会按 Accept-Language 自行本地化。
|
|
45
|
+
const profile = LANG_PROFILES[searchLanguage(configLanguage(options))];
|
|
46
|
+
const params = new URLSearchParams({ q: query });
|
|
47
|
+
if (options?.bingMarket) params.set("mkt", options.bingMarket);
|
|
48
|
+
// Accept-Language:显式 bingMarket 时按 market 反推(避免中文 header 污染),否则用 lang 档案
|
|
49
|
+
const acceptLang = options?.bingMarket
|
|
50
|
+
? (MARKET_TO_LANG[options.bingMarket] ?? activeAcceptLanguage)
|
|
51
|
+
: (profile.acceptLang ?? activeAcceptLanguage);
|
|
52
|
+
const adlt = options?.safeSearch ?? "off";
|
|
53
|
+
if (adlt === "off") params.set("adlt", "off");
|
|
54
|
+
else if (adlt === "moderate") params.set("adlt", "moderate");
|
|
55
|
+
else if (adlt === "strict") params.set("adlt", "strict");
|
|
56
|
+
// 注意(2026-10-13 实测):Bing 会对可疑出口 IP 间歇性返回约 91KB 的「空 SERP」(b_algo 块数 0),
|
|
57
|
+
// 表现为按请求频率收紧、减少请求后又自行恢复。曾加过「空 SERP 时多试一次」的兜底,但实测
|
|
58
|
+
// 请求数翻倍反而更容易被压死,且根因在出口 IP 而非解析,故撤掉——修法应让 bing 不走可疑代理
|
|
59
|
+
// (启动脚本的 NO_PROXY 排除 .bing.com 即可恢复)。
|
|
60
|
+
const html = await fetchHtmlWithRetry(`${BING_URL}?${params}`, signal, acceptLang);
|
|
61
|
+
const blocks = html.match(/<li class="b_algo"[\s\S]*?<\/li>/g) ?? [];
|
|
62
|
+
const sources = [];
|
|
63
|
+
for (const block of blocks) {
|
|
64
|
+
const hrefMatch = block.match(/<a[^>]*href="(https?:\/\/[^"]+)"/);
|
|
65
|
+
const titleMatch = block.match(/<h2[^>]*>[\s\S]*?<a[^>]*>(.*?)<\/a>[\s\S]*?<\/h2>/);
|
|
66
|
+
const snippetMatch = block.match(/<p[^>]*>([\s\S]*?)<\/p>/);
|
|
67
|
+
if (!hrefMatch) continue;
|
|
68
|
+
sources.push({
|
|
69
|
+
url: extractBingUrl(hrefMatch[1]),
|
|
70
|
+
...(titleMatch ? { title: stripTags(titleMatch[1]) } : {}),
|
|
71
|
+
...(snippetMatch ? { snippet: stripTags(snippetMatch[1]) } : {}),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Bing 无结果时会返回无关的缓存页:判为 0 结果,交给统一回退链换下一个引擎
|
|
75
|
+
if (sources.length > 0 && !looksRelevant(query, sources)) {
|
|
76
|
+
return { sources: [], truncated: false };
|
|
77
|
+
}
|
|
78
|
+
return { sources: uniqueSources(sources, maxResults ?? 10), truncated: false };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#region searxng (meta-search, free instances, auto-failover)
|