dsh-free-search 0.9.6 → 0.9.7
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 -6
- package/lib/client.js +152 -1
- package/lib/index.js +164 -40
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@ dsh 默认的搜索 provider 依赖 DeepSeek 官方 API key(`DEEPSEEK_API_KEY`
|
|
|
30
30
|
|
|
31
31
|
- **零成本** —— 多个免费引擎,无需 key、无需注册
|
|
32
32
|
- **多引擎可选**:DuckDuckGo(html/lite)、Bing、SearXNG(元搜索,支持自定义实例)、AnySearch、Exa、Tavily、Keenable、Firecrawl、Parallel、Perplexity、SerpBase、Serply、DeepSeek 官方、DeepSeek 原生搜索 API、You.com、百度千帆、Kimi、阿里云百炼、火山联网搜索(豆包搜索)、知乎全网/站内(`zhihu_global`/`zhihu_site`,经知乎开放平台 MCP)、OpenAI / Gemini / Claude 模型内置搜索
|
|
33
|
-
- **网页设置页** —— 引擎切换 + API key 配置(UI 中 key 脱敏显示"已配置")+ 中英文切换;入口在左侧「插件」页的组件行配置(`plugins.row.config`,DSH 0.1.7-rc.1
|
|
33
|
+
- **网页设置页** —— 引擎切换 + API key 配置(UI 中 key 脱敏显示"已配置")+ 中英文切换;入口在左侧「插件」页的组件行配置(`plugins.row.config`,DSH 0.1.7-rc.1+)。远程访问(VPS / 反向代理 / 自定义域名)下也能用:桥接接口沿用宿主的 Host 围栏,`--trusted-host` 与 `--public-url` 声明的地址会放行(#84)
|
|
34
|
+
- **右侧浮动目录** —— 卡片右侧的页面留白里浮出「引擎 / 回退 / 语言池 / 搜索行为 / 抓取 / 性能」六个快捷跳转,滚动自动高亮当前项、点击平滑跳转;不占用正文宽度(正文布局与 0.9.6 一致),右侧留白不足时自动隐藏
|
|
34
35
|
- **弹出式切换命令** —— 聊天框输入 `/free-search-engine`,弹出引擎选择窗口,点选即切换(等效设置页 + 保存)
|
|
35
36
|
- **引擎测试** —— `free_search_test` 工具让 agent 一键测试所有引擎;设置页也有"测试引擎"按钮(直测当前引擎,不走回退链,付费引擎无 key 会明确报错)
|
|
36
37
|
- **全局引擎开关与回退优先级** —— 设置页可勾选/取消引擎(取消后全局生效:普通搜索 / Auto / `advanced_search` / `multi_search` / 引擎测试都不再用它),并可用 ↑↓ 调整全局回退顺序(一键恢复默认)
|
|
@@ -459,7 +460,7 @@ Search engine test:
|
|
|
459
460
|
|
|
460
461
|
#### 离线自检断言(tools/)
|
|
461
462
|
|
|
462
|
-
仓库自带 **
|
|
463
|
+
仓库自带 **18 个**零依赖断言脚本(合计 **520 项**),**不需要 API key、不联网、不需要测试框架**,Node ≥ 20 即可跑:
|
|
463
464
|
|
|
464
465
|
| 脚本 | 覆盖 | 运行(项数) |
|
|
465
466
|
|---|---|---|
|
|
@@ -479,7 +480,8 @@ Search engine test:
|
|
|
479
480
|
| `assert-killtree-win32.mjs` | Windows 子进程树终止(#74):不再依赖 `taskkill` | `node tools/assert-killtree-win32.mjs`(8) |
|
|
480
481
|
| `assert-killtree-portable.mjs` | 跨平台 `killTree` 便携版契约 | `node tools/assert-killtree-portable.mjs`(5) |
|
|
481
482
|
| `assert-parallel-mcp.mjs` | Parallel MCP 引擎:25 s 超时/调用方取消覆盖**响应体读取**、共享 SSE 解析器(通知/多行帧)、6 类错误路径、REST 精确时间过滤 | `node tools/assert-parallel-mcp.mjs`(15) |
|
|
482
|
-
| `assert-
|
|
483
|
+
| `assert-bridge-access.mjs` | 桥接 Host 围栏(#84):loopback 放行、remote peer 打 loopback Host 拒绝、`--trusted-host`(无端口匹配任意端口 / 带端口精确匹配)、`--public-url`、绑定地址、跨站与异源拒绝 | `node tools/assert-bridge-access.mjs`(11) |
|
|
484
|
+
| `assert-provider-takeover.mjs` | provider 接管:旧属性 API 与 rc.2 的 `config.*` ref 两套兼容、`settings.mutate(web)` 单批写入、显式指定的 provider 不被抢占、`fetchProviderTakeover: false` 时保留显式 `http`、describe 噪声不误报、嵌套 config 变化与 web 重建分别成行、apply 重入/重复注册不再中断、重复日志去重 | `node tools/assert-provider-takeover.mjs`(14) |
|
|
483
485
|
|
|
484
486
|
任何一个失败会以非 0 退出码结束并列出失败项;把某个旧版本文件路径作为参数传进去,可以看到修复前必红(用来证明断言不是空转)。改动发布相关逻辑后建议先跑一遍再发版。
|
|
485
487
|
|
|
@@ -529,7 +531,8 @@ This plugin provides multiple free search engines with automatic fallback, compl
|
|
|
529
531
|
|
|
530
532
|
- **Zero Cost** — Multiple free engines with no API key or registration required
|
|
531
533
|
- **Multi-Engine Support** — DuckDuckGo (HTML / Lite), Bing, AnySearch AI, SearXNG (meta-search with custom instances), Exa, Tavily, Keenable, Firecrawl, Parallel, Perplexity, SerpBase, Serply, DeepSeek Official, You.com, Baidu Qianfan, Kimi, Aliyun Bailian, Volcano Doubao, Zhihu web-wide/site search (`zhihu_global`/`zhihu_site`, via the Zhihu open-platform MCP), and the model-based OpenAI / Gemini / Claude searches
|
|
532
|
-
- **Web Settings UI** — Engine switching, API key configuration (keys masked as "configured" in the UI), and a Chinese/English toggle; the entry is the component-row config (`plugins.row.config`) on the sidebar Plugins page (DSH 0.1.7-rc.1+)
|
|
534
|
+
- **Web Settings UI** — Engine switching, API key configuration (keys masked as "configured" in the UI), and a Chinese/English toggle; the entry is the component-row config (`plugins.row.config`) on the sidebar Plugins page (DSH 0.1.7-rc.1+). Remote access (VPS, reverse proxy, custom domain) works too: the bridge reuses the host's own Host fence, so addresses declared with `--trusted-host` or `--public-url` are accepted (#84)
|
|
535
|
+
- **Right-hand section rail** — A floating list (Engines / Fallback / Language pools / Search behaviour / Fetch / Performance) sits in the page margin to the right of the card: it highlights the section you are in while scrolling and jumps smoothly on click. It is rendered in a portal and never narrows the card, so the body layout is unchanged; it hides itself when the margin is too tight.
|
|
533
536
|
- **Popup Switch Command** — Type `/free-search-engine` in the chat: a picker opens with all engines; click one to switch (equivalent to the settings page + save)
|
|
534
537
|
- **Engine Testing** — `free_search_test` for the agent to check all engines in one call; the settings UI also has a "Test engine" button that tests the selected engine directly (no fallback chain; paid engines without a key report an explicit error)
|
|
535
538
|
- **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)
|
|
@@ -959,7 +962,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
959
962
|
|
|
960
963
|
#### Offline self-check assertions (`tools/`)
|
|
961
964
|
|
|
962
|
-
**
|
|
965
|
+
**Eighteen** zero-dependency assertion scripts ship with the repo (**520 assertions** total): **no API keys, no network, no test framework**, Node ≥ 20:
|
|
963
966
|
|
|
964
967
|
| Script | Covers | Run (count) |
|
|
965
968
|
|---|---|---|
|
|
@@ -979,7 +982,8 @@ Restart `dsh web` after switching to apply changes.
|
|
|
979
982
|
| `assert-killtree-win32.mjs` | Windows process-tree termination (#74): no longer relies on `taskkill` | `node tools/assert-killtree-win32.mjs` (8) |
|
|
980
983
|
| `assert-killtree-portable.mjs` | portable `killTree` contract | `node tools/assert-killtree-portable.mjs` (5) |
|
|
981
984
|
| `assert-parallel-mcp.mjs` | Parallel MCP engine: the 25 s timeout / caller abort covers the **body read**, shared SSE parser (notifications, multiline frames), six error paths, REST precise time filtering | `node tools/assert-parallel-mcp.mjs` (15) |
|
|
982
|
-
| `assert-
|
|
985
|
+
| `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` (11) |
|
|
986
|
+
| `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, apply re-entry / duplicate registrations tolerated, and repeated logs deduplicated | `node tools/assert-provider-takeover.mjs` (14) |
|
|
983
987
|
|
|
984
988
|
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.
|
|
985
989
|
|
package/lib/client.js
CHANGED
|
@@ -5,6 +5,7 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
|
|
7
7
|
let react = require("react");
|
|
8
|
+
let react_dom = require("react-dom");
|
|
8
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
10
|
|
|
10
11
|
//#region css
|
|
@@ -29,6 +30,13 @@ window.__ModuleLoader__.load({
|
|
|
29
30
|
"@keyframes dshfsFadeIn{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}",
|
|
30
31
|
".dshfs-body{flex-direction:column;gap:20px;padding:0 20px 20px;display:flex;animation:dshfsFadeIn 240ms cubic-bezier(.4,0,.2,1) forwards}",
|
|
31
32
|
"@media (prefers-reduced-motion: reduce){.dshfs-body{animation:none}}",
|
|
33
|
+
".dshfs-rail{display:none;position:fixed;top:50%;transform:translateY(-50%);flex-direction:column;gap:2px;max-height:70vh;overflow:auto;z-index:5;padding:2px}",
|
|
34
|
+
".dshfs-railItem{display:flex;align-items:center;gap:6px;padding:3px 2px;border:0;background:none;font:inherit;font-size:12px;line-height:1.5;color:inherit;opacity:.42;text-align:left;cursor:pointer;transition:opacity 120ms}",
|
|
35
|
+
".dshfs-railItem:hover{opacity:.85}",
|
|
36
|
+
".dshfs-railItemActive{opacity:.95;font-weight:600}",
|
|
37
|
+
".dshfs-railDot{flex:none;width:4px;height:4px;border-radius:50%;background:currentColor;opacity:.45}",
|
|
38
|
+
".dshfs-railItemActive .dshfs-railDot{opacity:1;background:#0071e3}",
|
|
39
|
+
"@media (prefers-color-scheme: dark){.dshfs-railItemActive .dshfs-railDot{background:#0a84ff}}",
|
|
32
40
|
".dshfs-footer{justify-content:space-between;align-items:center;gap:12px;display:flex;flex-wrap:wrap;padding-top:4px}",
|
|
33
41
|
".dshfs-footerLeft{display:flex;align-items:center;gap:12px;flex-wrap:wrap;min-width:0}",
|
|
34
42
|
".dshfs-footerRight{display:flex;align-items:center;gap:10px;flex-wrap:wrap}",
|
|
@@ -267,6 +275,13 @@ window.__ModuleLoader__.load({
|
|
|
267
275
|
marketAuto: "自动 —— 不发送 mkt(推荐用于非上列地区)",
|
|
268
276
|
fetchTakeoverLabel: "自动接管 web_fetch",
|
|
269
277
|
fetchTakeoverHint: "开启时:web.fetchProvider 未设置或仍是出厂默认 http 会接管为 fs-quality-fetch。如果你刻意 pin 了 http(例如只想用内置抓取),关掉此项。",
|
|
278
|
+
navLabel: "本页导航",
|
|
279
|
+
navEngines: "引擎",
|
|
280
|
+
navFallback: "回退",
|
|
281
|
+
navPools: "语言池",
|
|
282
|
+
navBehavior: "搜索行为",
|
|
283
|
+
navFetch: "抓取",
|
|
284
|
+
navPerformance: "性能",
|
|
270
285
|
marketZhCN: "zh-CN —— 中国大陆(默认)",
|
|
271
286
|
marketZhTW: "zh-TW —— 台湾",
|
|
272
287
|
marketEnUS: "en-US —— 美国",
|
|
@@ -388,6 +403,13 @@ window.__ModuleLoader__.load({
|
|
|
388
403
|
marketAuto: "Automatic — send no mkt (recommended outside the listed regions)",
|
|
389
404
|
fetchTakeoverLabel: "Take over web_fetch automatically",
|
|
390
405
|
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).",
|
|
406
|
+
navLabel: "On this page",
|
|
407
|
+
navEngines: "Engines",
|
|
408
|
+
navFallback: "Fallback",
|
|
409
|
+
navPools: "Language pools",
|
|
410
|
+
navBehavior: "Search behaviour",
|
|
411
|
+
navFetch: "Fetch",
|
|
412
|
+
navPerformance: "Performance",
|
|
391
413
|
marketZhCN: "zh-CN - China (default)",
|
|
392
414
|
marketZhTW: "zh-TW - Taiwan",
|
|
393
415
|
marketEnUS: "en-US - United States",
|
|
@@ -404,8 +426,27 @@ window.__ModuleLoader__.load({
|
|
|
404
426
|
};
|
|
405
427
|
const tt = (lang) => I18N[lang === "en" ? "en" : "zh"];
|
|
406
428
|
// 当前插件版本(与 lib/index.js 的 PLUGIN_VERSION 保持一致;跟随上游 v0.7.5)
|
|
407
|
-
const PLUGIN_VERSION = "0.9.
|
|
429
|
+
const PLUGIN_VERSION = "0.9.7";
|
|
408
430
|
const PLUGIN_REPO_URL = "https://github.com/DDDMUC/dsh-free-search";
|
|
431
|
+
// 右侧浮动目录(#85):条目顺序即页面顺序,anchor 是页面里对应 field 的 id。
|
|
432
|
+
const NAV_ITEMS = [
|
|
433
|
+
{ id: "engines", anchor: "dshfs-anchor-engines" },
|
|
434
|
+
{ id: "fallback", anchor: "dshfs-anchor-fallback" },
|
|
435
|
+
{ id: "pools", anchor: "dshfs-anchor-pools" },
|
|
436
|
+
{ id: "behavior", anchor: "dshfs-anchor-behavior" },
|
|
437
|
+
{ id: "fetch", anchor: "dshfs-anchor-fetch" },
|
|
438
|
+
{ id: "performance", anchor: "dshfs-anchor-performance" },
|
|
439
|
+
];
|
|
440
|
+
// 目录跟着真正滚动的祖先走:DSH 页面通常不是 window 在滚。
|
|
441
|
+
const findScrollParent = (element) => {
|
|
442
|
+
let node = element && element.parentElement ? element.parentElement : null;
|
|
443
|
+
while (node && node !== document.body && node !== document.documentElement) {
|
|
444
|
+
const style = window.getComputedStyle(node);
|
|
445
|
+
if (/(auto|scroll|overlay)/.test(style.overflowY) && node.scrollHeight > node.clientHeight) return node;
|
|
446
|
+
node = node.parentElement;
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
};
|
|
409
450
|
const ENGINES = [
|
|
410
451
|
{ id: "auto", label: "Auto · 智能路由", badge: "AUTO", link: null },
|
|
411
452
|
{ id: "multi", label: "Multi Search · 多引擎", badge: "MULTI", link: null },
|
|
@@ -601,6 +642,9 @@ window.__ModuleLoader__.load({
|
|
|
601
642
|
// 页面自带标题/面包屑,卡片固定展开、表头不再可折叠。
|
|
602
643
|
const pageMode = !!(props && props.page);
|
|
603
644
|
const [open, setOpen] = react.useState(pageMode);
|
|
645
|
+
const [railActive, setRailActive] = react.useState(NAV_ITEMS[0].id);
|
|
646
|
+
const bodyRef = react.useRef(null);
|
|
647
|
+
const railRef = react.useRef(null);
|
|
604
648
|
const [state, setState] = react.useState({ status: "loading" });
|
|
605
649
|
const [provider, setProvider] = react.useState("bing");
|
|
606
650
|
const [disabledEngines, setDisabledEngines] = react.useState([]);
|
|
@@ -1019,9 +1063,86 @@ window.__ModuleLoader__.load({
|
|
|
1019
1063
|
}
|
|
1020
1064
|
};
|
|
1021
1065
|
|
|
1066
|
+
// 浮动目录(#85):放在卡片右侧的页面留白里,绝对定位不参与卡片布局,
|
|
1067
|
+
// 所以正文宽度和 0.9.7 完全一致;留白不足(窄窗口/卡片贴边)时直接隐藏。
|
|
1068
|
+
react.useEffect(() => {
|
|
1069
|
+
if (!open) return undefined;
|
|
1070
|
+
const place = () => {
|
|
1071
|
+
const body = bodyRef.current;
|
|
1072
|
+
const rail = railRef.current;
|
|
1073
|
+
if (!body || !rail) return;
|
|
1074
|
+
const space = window.innerWidth - body.getBoundingClientRect().right;
|
|
1075
|
+
if (space < 120) {
|
|
1076
|
+
rail.style.display = "none";
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
rail.style.display = "flex";
|
|
1080
|
+
const width = rail.getBoundingClientRect().width || 66;
|
|
1081
|
+
rail.style.right = Math.max(12, Math.round(space / 2 - width / 2)) + "px";
|
|
1082
|
+
};
|
|
1083
|
+
place();
|
|
1084
|
+
window.addEventListener("resize", place);
|
|
1085
|
+
return () => window.removeEventListener("resize", place);
|
|
1086
|
+
}, [open, state.status]);
|
|
1087
|
+
|
|
1088
|
+
// 当前分组:分组顶部越过 35% 激活线就算当前;滚到底高亮最后一组。
|
|
1089
|
+
react.useEffect(() => {
|
|
1090
|
+
if (!open) return undefined;
|
|
1091
|
+
const scroller = findScrollParent(bodyRef.current);
|
|
1092
|
+
const target = scroller ?? (typeof window === "undefined" ? null : window);
|
|
1093
|
+
if (!target) return undefined;
|
|
1094
|
+
const compute = () => {
|
|
1095
|
+
const viewportHeight = scroller ? scroller.clientHeight : window.innerHeight;
|
|
1096
|
+
const atBottom = scroller
|
|
1097
|
+
? scroller.scrollTop + scroller.clientHeight >= scroller.scrollHeight - 8
|
|
1098
|
+
: window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 8;
|
|
1099
|
+
if (atBottom) {
|
|
1100
|
+
setRailActive(NAV_ITEMS[NAV_ITEMS.length - 1].id);
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
const viewportTop = scroller ? scroller.getBoundingClientRect().top : 0;
|
|
1104
|
+
const line = viewportTop + viewportHeight * 0.35;
|
|
1105
|
+
let current = NAV_ITEMS[0].id;
|
|
1106
|
+
for (const item of NAV_ITEMS) {
|
|
1107
|
+
const section = typeof document === "undefined" ? null : document.getElementById(item.anchor);
|
|
1108
|
+
if (section && section.getBoundingClientRect().top <= line) current = item.id;
|
|
1109
|
+
}
|
|
1110
|
+
setRailActive(current);
|
|
1111
|
+
};
|
|
1112
|
+
let frame = 0;
|
|
1113
|
+
const onScroll = () => {
|
|
1114
|
+
if (frame) return;
|
|
1115
|
+
frame = requestAnimationFrame(() => {
|
|
1116
|
+
frame = 0;
|
|
1117
|
+
compute();
|
|
1118
|
+
});
|
|
1119
|
+
};
|
|
1120
|
+
compute();
|
|
1121
|
+
target.addEventListener("scroll", onScroll, { passive: true });
|
|
1122
|
+
return () => {
|
|
1123
|
+
target.removeEventListener("scroll", onScroll);
|
|
1124
|
+
if (frame) cancelAnimationFrame(frame);
|
|
1125
|
+
};
|
|
1126
|
+
}, [open, state.status]);
|
|
1127
|
+
|
|
1022
1128
|
if (state.status === "loading") return null;
|
|
1023
1129
|
const ready = state.status === "ready";
|
|
1024
1130
|
const t = tt(uiLang || (lang === "en" ? "en" : "zh"));
|
|
1131
|
+
const navLabels = {
|
|
1132
|
+
engines: t.navEngines,
|
|
1133
|
+
fallback: t.navFallback,
|
|
1134
|
+
pools: t.navPools,
|
|
1135
|
+
behavior: t.navBehavior,
|
|
1136
|
+
fetch: t.navFetch,
|
|
1137
|
+
performance: t.navPerformance,
|
|
1138
|
+
};
|
|
1139
|
+
const goToSection = (id) => {
|
|
1140
|
+
const item = NAV_ITEMS.find((entry) => entry.id === id);
|
|
1141
|
+
const section = item && typeof document !== "undefined" ? document.getElementById(item.anchor) : null;
|
|
1142
|
+
if (!section) return;
|
|
1143
|
+
setRailActive(id);
|
|
1144
|
+
section.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
1145
|
+
};
|
|
1025
1146
|
const title = "Free Search";
|
|
1026
1147
|
const description = t.description;
|
|
1027
1148
|
const enabledEngineCount = ENGINES.filter((e) => e.id !== "auto" && e.id !== "multi" && !disabledEngines.includes(e.id)).length;
|
|
@@ -1056,6 +1177,7 @@ window.__ModuleLoader__.load({
|
|
|
1056
1177
|
const candidates = ENGINE_IDS.filter((id) => !pool.includes(id) && !EXPLICIT_ONLY_ENGINES.includes(id));
|
|
1057
1178
|
return react_jsx_runtime.jsx("div", {
|
|
1058
1179
|
className: "dshfs-field",
|
|
1180
|
+
id: poolKey === "zh" ? "dshfs-anchor-pools" : undefined,
|
|
1059
1181
|
children: [
|
|
1060
1182
|
react_jsx_runtime.jsx("div", {
|
|
1061
1183
|
className: "dshfs-label",
|
|
@@ -1216,9 +1338,34 @@ window.__ModuleLoader__.load({
|
|
|
1216
1338
|
open
|
|
1217
1339
|
? react_jsx_runtime.jsx("div", {
|
|
1218
1340
|
className: "dshfs-body",
|
|
1341
|
+
ref: bodyRef,
|
|
1219
1342
|
children: [
|
|
1343
|
+
// 目录走 portal 挂到 document.body:卡片的 backdrop-filter / 动画 transform
|
|
1344
|
+
// 会成为 fixed 的包含块,留在卡片里就永远贴不到页面右侧的留白。
|
|
1345
|
+
typeof document === "undefined"
|
|
1346
|
+
? null
|
|
1347
|
+
: react_dom.createPortal(
|
|
1348
|
+
react_jsx_runtime.jsx("nav", {
|
|
1349
|
+
className: "dshfs-rail",
|
|
1350
|
+
ref: railRef,
|
|
1351
|
+
"aria-label": t.navLabel,
|
|
1352
|
+
children: NAV_ITEMS.map((item) =>
|
|
1353
|
+
react_jsx_runtime.jsx("button", {
|
|
1354
|
+
type: "button",
|
|
1355
|
+
className: "dshfs-railItem" + (railActive === item.id ? " dshfs-railItemActive" : ""),
|
|
1356
|
+
onClick: () => goToSection(item.id),
|
|
1357
|
+
children: [
|
|
1358
|
+
react_jsx_runtime.jsx("span", { className: "dshfs-railDot" }),
|
|
1359
|
+
react_jsx_runtime.jsx("span", { children: navLabels[item.id] }),
|
|
1360
|
+
],
|
|
1361
|
+
}, item.id)
|
|
1362
|
+
),
|
|
1363
|
+
}),
|
|
1364
|
+
document.body
|
|
1365
|
+
),
|
|
1220
1366
|
react_jsx_runtime.jsx("div", {
|
|
1221
1367
|
className: "dshfs-field",
|
|
1368
|
+
id: "dshfs-anchor-engines",
|
|
1222
1369
|
children: [
|
|
1223
1370
|
react_jsx_runtime.jsx("div", {
|
|
1224
1371
|
className: "dshfs-label",
|
|
@@ -1305,6 +1452,7 @@ react_jsx_runtime.jsx("div", {
|
|
|
1305
1452
|
}),
|
|
1306
1453
|
react_jsx_runtime.jsx("div", {
|
|
1307
1454
|
className: "dshfs-field",
|
|
1455
|
+
id: "dshfs-anchor-fallback",
|
|
1308
1456
|
children: [
|
|
1309
1457
|
react_jsx_runtime.jsx("div", {
|
|
1310
1458
|
className: "dshfs-label",
|
|
@@ -1478,6 +1626,7 @@ react_jsx_runtime.jsx("div", {
|
|
|
1478
1626
|
}),
|
|
1479
1627
|
react_jsx_runtime.jsx("div", {
|
|
1480
1628
|
className: "dshfs-field",
|
|
1629
|
+
id: "dshfs-anchor-behavior",
|
|
1481
1630
|
children: [
|
|
1482
1631
|
react_jsx_runtime.jsx("div", {
|
|
1483
1632
|
className: "dshfs-label",
|
|
@@ -1572,6 +1721,7 @@ react_jsx_runtime.jsx("div", {
|
|
|
1572
1721
|
}),
|
|
1573
1722
|
react_jsx_runtime.jsx("div", {
|
|
1574
1723
|
className: "dshfs-field",
|
|
1724
|
+
id: "dshfs-anchor-fetch",
|
|
1575
1725
|
children: [
|
|
1576
1726
|
react_jsx_runtime.jsx("label", {
|
|
1577
1727
|
className: "dshfs-check",
|
|
@@ -1677,6 +1827,7 @@ react_jsx_runtime.jsx("div", {
|
|
|
1677
1827
|
}),
|
|
1678
1828
|
react_jsx_runtime.jsx("div", {
|
|
1679
1829
|
className: "dshfs-field",
|
|
1830
|
+
id: "dshfs-anchor-performance",
|
|
1680
1831
|
children: [
|
|
1681
1832
|
react_jsx_runtime.jsx("div", {
|
|
1682
1833
|
className: "dshfs-label",
|
package/lib/index.js
CHANGED
|
@@ -256,7 +256,7 @@ function routeEngines(query, { timeRange, disabledEngines = [], fallbackOrder =
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
// 当前插件版本(发布时与 package.json 同步;跟随上游 v0.7.5,不在 PR 里 bump)
|
|
259
|
-
const PLUGIN_VERSION = "0.9.
|
|
259
|
+
const PLUGIN_VERSION = "0.9.7";
|
|
260
260
|
// 检查更新的 npm registry 元数据地址(dsh-free-search 是 npmjs 上的公开包)
|
|
261
261
|
const NPM_REGISTRY_URL = "https://registry.npmjs.org/dsh-free-search/latest";
|
|
262
262
|
const PLUGIN_NPM_URL = "https://www.npmjs.com/package/dsh-free-search";
|
|
@@ -2847,26 +2847,64 @@ async function searchDoubao(query, maxResults, apiKey, timeRange, signal) {
|
|
|
2847
2847
|
//#region bridge
|
|
2848
2848
|
const MAX_JSON_BODY_BYTES = 64 * 1024;
|
|
2849
2849
|
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2850
|
+
// #84:桥接接口的 Host 围栏。
|
|
2851
|
+
// DSH 宿主对 /api 已经做了同样的 Browser-trust 围栏并完成鉴权:放行 loopback、
|
|
2852
|
+
// 监听绑定的 IP 字面量,以及 --trusted-host / --public-url 声明的 authority。
|
|
2853
|
+
// 插件此前只认 loopback,于是 VPS / 反向代理 / 自定义域名下配置页整体 403、表单全灰。
|
|
2854
|
+
// 这里沿用宿主的信任集合,而不是把写接口无差别放开。
|
|
2855
|
+
const bridgeTrust = { hosts: [], publicHost: "" };
|
|
2856
|
+
|
|
2857
|
+
function parseAuthority(authority) {
|
|
2856
2858
|
try {
|
|
2857
|
-
|
|
2859
|
+
return new URL("http://" + authority);
|
|
2858
2860
|
} catch {
|
|
2859
|
-
return
|
|
2861
|
+
return null;
|
|
2860
2862
|
}
|
|
2861
|
-
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
function isLoopbackAddress(address) {
|
|
2866
|
+
const value = String(address ?? "");
|
|
2867
|
+
return value === "127.0.0.1" || value === "::1" || value === "::ffff:127.0.0.1" || /^127\./.test(value);
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
function isLoopbackHostname(hostname) {
|
|
2871
|
+
if (hostname === "localhost" || hostname === "[::1]" || hostname === "::1") return true;
|
|
2872
|
+
const parts = hostname.split(".");
|
|
2873
|
+
return parts.length === 4 && parts[0] === "127" && parts.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255);
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
// 与宿主的 isTrustedAuthority 同规则:无端口条目匹配任意端口,带端口条目精确匹配。
|
|
2877
|
+
function matchesTrustedAuthority(hostUrl, entry) {
|
|
2878
|
+
const entryUrl = parseAuthority(entry);
|
|
2879
|
+
if (entryUrl === null) return false;
|
|
2880
|
+
return entryUrl.port === "" ? entryUrl.hostname === hostUrl.hostname : entryUrl.host === hostUrl.host;
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
function isBridgeRequestAllowed(request, trust = bridgeTrust) {
|
|
2884
|
+
const host = request.headers.host;
|
|
2885
|
+
if (typeof host !== "string") return false;
|
|
2886
|
+
const hostUrl = parseAuthority(host);
|
|
2887
|
+
if (hostUrl === null) return false;
|
|
2888
|
+
// 跨站发起的请求一律拒绝(防 confused deputy);同源请求才继续看 Host。
|
|
2862
2889
|
if (request.headers["sec-fetch-site"] === "cross-site") return false;
|
|
2863
2890
|
const origin = request.headers.origin;
|
|
2864
|
-
if (origin
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2891
|
+
if (origin !== undefined) {
|
|
2892
|
+
try {
|
|
2893
|
+
if (new URL(origin).host !== hostUrl.host) return false;
|
|
2894
|
+
} catch {
|
|
2895
|
+
return false;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
if (isLoopbackHostname(hostUrl.hostname)) return isLoopbackAddress(request.socket.remoteAddress);
|
|
2899
|
+
if (trust.hosts.some((entry) => matchesTrustedAuthority(hostUrl, entry))) return true;
|
|
2900
|
+
if (trust.publicHost && matchesTrustedAuthority(hostUrl, trust.publicHost)) return true;
|
|
2901
|
+
// 直接绑定非 loopback 地址(--host 192.168.x.x / 公网 IP)时,Host 就是绑定地址。
|
|
2902
|
+
const localAddress = request.socket.localAddress;
|
|
2903
|
+
if (typeof localAddress === "string" && localAddress !== "0.0.0.0" && localAddress !== "::") {
|
|
2904
|
+
const local = parseAuthority(localAddress.includes(":") ? `[${localAddress}]` : localAddress);
|
|
2905
|
+
if (local !== null && local.hostname === hostUrl.hostname) return true;
|
|
2869
2906
|
}
|
|
2907
|
+
return false;
|
|
2870
2908
|
}
|
|
2871
2909
|
|
|
2872
2910
|
function writeJson(res, status, body) {
|
|
@@ -3116,8 +3154,8 @@ function makeBridgeRoutes(settings, search, testEngine, getCredentials) {
|
|
|
3116
3154
|
};
|
|
3117
3155
|
|
|
3118
3156
|
const guard = (req, res) => {
|
|
3119
|
-
if (!
|
|
3120
|
-
writeJson(res, 403, { error: "
|
|
3157
|
+
if (!isBridgeRequestAllowed(req)) {
|
|
3158
|
+
writeJson(res, 403, { error: "requests must come from the local host or a configured trusted host" });
|
|
3121
3159
|
return false;
|
|
3122
3160
|
}
|
|
3123
3161
|
if (req.method !== "POST") {
|
|
@@ -3434,6 +3472,46 @@ function resolveConfig(config) {
|
|
|
3434
3472
|
return out;
|
|
3435
3473
|
}
|
|
3436
3474
|
|
|
3475
|
+
// #82 诊断:深度比较 web 条目的 config,返回 `a.b: 旧 → 新` 形式的路径(最多 8 条)。
|
|
3476
|
+
// 只用于日志,不参与任何逻辑;嵌套对象会展开,数组按整体比较。
|
|
3477
|
+
function changedConfigPaths(previous, next, prefix = "", out = []) {
|
|
3478
|
+
const left = previous !== null && typeof previous === "object" ? previous : {};
|
|
3479
|
+
const right = next !== null && typeof next === "object" ? next : {};
|
|
3480
|
+
for (const key of new Set([...Object.keys(left), ...Object.keys(right)])) {
|
|
3481
|
+
if (out.length >= 8) break;
|
|
3482
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
3483
|
+
const before = left[key];
|
|
3484
|
+
const after = right[key];
|
|
3485
|
+
const nested =
|
|
3486
|
+
before !== null &&
|
|
3487
|
+
after !== null &&
|
|
3488
|
+
typeof before === "object" &&
|
|
3489
|
+
typeof after === "object" &&
|
|
3490
|
+
!Array.isArray(before) &&
|
|
3491
|
+
!Array.isArray(after);
|
|
3492
|
+
if (nested) {
|
|
3493
|
+
changedConfigPaths(before, after, path, out);
|
|
3494
|
+
continue;
|
|
3495
|
+
}
|
|
3496
|
+
if (JSON.stringify(before ?? null) !== JSON.stringify(after ?? null)) {
|
|
3497
|
+
out.push(`${path}: ${previewConfigValue(before)} → ${previewConfigValue(after)}`);
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
return out;
|
|
3501
|
+
}
|
|
3502
|
+
|
|
3503
|
+
function previewConfigValue(value) {
|
|
3504
|
+
if (value === undefined) return "undefined";
|
|
3505
|
+
let text;
|
|
3506
|
+
try {
|
|
3507
|
+
text = JSON.stringify(value);
|
|
3508
|
+
} catch {
|
|
3509
|
+
text = String(value);
|
|
3510
|
+
}
|
|
3511
|
+
if (text === undefined) text = "undefined";
|
|
3512
|
+
return text.length > 48 ? `${text.slice(0, 45)}...` : text;
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3437
3515
|
function apply(ctx, config) {
|
|
3438
3516
|
// 重入保护:同一个 ctx 上 apply 只跑一次。rc.2 的 boot 里出现过未 dispose 的重入,
|
|
3439
3517
|
// 会撞上下面的重复注册(provider / route),导致 entry 反复失败把 boot 拖死。
|
|
@@ -3460,6 +3538,25 @@ function apply(ctx, config) {
|
|
|
3460
3538
|
// credentials 服务可能晚于本插件挂载(跨 bundle 顺序),运行期动态获取而不是 apply 时缓存
|
|
3461
3539
|
const getCredentials = () => ctx.get("credentials");
|
|
3462
3540
|
|
|
3541
|
+
// #84:读取宿主的远程访问信任集合(--trusted-host / --public-url),供桥接 Host 围栏使用。
|
|
3542
|
+
// webStartup 只在 dsh web 下提供;拿不到就维持 loopback-only 的老行为。
|
|
3543
|
+
ctx.inject(["webStartup"], (sctx) => {
|
|
3544
|
+
try {
|
|
3545
|
+
const startup = sctx.get("webStartup");
|
|
3546
|
+
if (!startup) return;
|
|
3547
|
+
if (Array.isArray(startup.trustedHosts)) {
|
|
3548
|
+
bridgeTrust.hosts = startup.trustedHosts
|
|
3549
|
+
.filter((entry) => typeof entry === "string" && entry.trim())
|
|
3550
|
+
.map((entry) => entry.trim());
|
|
3551
|
+
}
|
|
3552
|
+
if (typeof startup.publicUrl === "string" && startup.publicUrl) {
|
|
3553
|
+
try {
|
|
3554
|
+
bridgeTrust.publicHost = new URL(startup.publicUrl).host;
|
|
3555
|
+
} catch {}
|
|
3556
|
+
}
|
|
3557
|
+
} catch {}
|
|
3558
|
+
});
|
|
3559
|
+
|
|
3463
3560
|
// 系统提示词动态刷新:设置变更时重新生成,避免显示旧引擎
|
|
3464
3561
|
let refreshPrompt = null;
|
|
3465
3562
|
// Multi Search 执行器在 runEngineTest 定义后初始化;provider.search 运行时再调用。
|
|
@@ -3950,33 +4047,47 @@ function apply(ctx, config) {
|
|
|
3950
4047
|
);
|
|
3951
4048
|
});
|
|
3952
4049
|
// Re-render the dynamic system-prompt engine list whenever this entry's config changes.
|
|
3953
|
-
// #82
|
|
3954
|
-
|
|
4050
|
+
// #82:dsh-settings 在 describe() 里也会 emit `settings/document-updated`(raw 快照变了就发),
|
|
4051
|
+
// 所以「收到事件」≠「有人写入」。事件只当触发信号,并且必须**推迟到 emit 栈之外**再读配置:
|
|
4052
|
+
// 在 emit 的同步栈里再调 describe() 会和设置文档的写入路径打架(0.9.7 首版实测把 web 服务卡死)。
|
|
4053
|
+
// 读到值后再对 web 条目的 uid + 整份 config 做深度比对:没变(describe 噪声)不记,变了才记一条。
|
|
4054
|
+
const snapshotWebEntry = () => {
|
|
3955
4055
|
try {
|
|
3956
|
-
|
|
4056
|
+
const descriptor = sctx.settings.describe({ redactSecrets: true }).find((entry) => String(entry.ns) === "web");
|
|
4057
|
+
if (!descriptor) return null;
|
|
4058
|
+
return { uid: descriptor.schema?.uid ?? null, config: descriptor.value ?? {} };
|
|
3957
4059
|
} catch {
|
|
3958
4060
|
return null;
|
|
3959
4061
|
}
|
|
3960
|
-
}
|
|
4062
|
+
};
|
|
4063
|
+
let lastWebEntry = null; // 首次事件只用来建立基线,不当成「变化」
|
|
4064
|
+
let webDiagLogged = false;
|
|
4065
|
+
let webDiagQueued = false;
|
|
4066
|
+
const runWebDiag = () => {
|
|
4067
|
+
const next = snapshotWebEntry();
|
|
4068
|
+
const previous = lastWebEntry;
|
|
4069
|
+
if (next !== null) lastWebEntry = next;
|
|
4070
|
+
if (previous === null || next === null || webDiagLogged) return;
|
|
4071
|
+
const changed = changedConfigPaths(previous.config, next.config);
|
|
4072
|
+
const rebuilt = previous.uid !== next.uid;
|
|
4073
|
+
if (!rebuilt && changed.length === 0) return;
|
|
4074
|
+
const parts = [];
|
|
4075
|
+
if (rebuilt) parts.push(`the web service was rebuilt (entry uid ${previous.uid} → ${next.uid})`);
|
|
4076
|
+
if (changed.length > 0) parts.push(`config ${changed.join(", ")}`);
|
|
4077
|
+
webDiagLogged = true;
|
|
4078
|
+
logger.info(
|
|
4079
|
+
`free-search: the web entry changed — ${parts.join("; ")}. A provider write rebuilds the web service and re-applies this plugin (only the first change per process is logged).`
|
|
4080
|
+
);
|
|
4081
|
+
};
|
|
3961
4082
|
sctx.on("settings/document-updated", (ns) => {
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
const keys = [...new Set([...Object.keys(previous), ...Object.keys(next)])];
|
|
3971
|
-
const changed = keys.filter((key) => JSON.stringify(next[key] ?? null) !== JSON.stringify(previous[key] ?? null));
|
|
3972
|
-
logOnce(
|
|
3973
|
-
logger,
|
|
3974
|
-
"info",
|
|
3975
|
-
`free-search: the web config was updated (changed: ${changed.join(", ") || "none visible"}) — a provider write rebuilds the web service and re-applies this plugin`
|
|
3976
|
-
);
|
|
3977
|
-
lastWebConfig = next;
|
|
3978
|
-
}
|
|
3979
|
-
} catch {}
|
|
4083
|
+
if (String(ns) === "web" && !webDiagQueued) {
|
|
4084
|
+
webDiagQueued = true;
|
|
4085
|
+
setTimeout(() => {
|
|
4086
|
+
webDiagQueued = false;
|
|
4087
|
+
try {
|
|
4088
|
+
runWebDiag();
|
|
4089
|
+
} catch {}
|
|
4090
|
+
}, 0);
|
|
3980
4091
|
}
|
|
3981
4092
|
if (String(ns) === FREE_SEARCH_NS && typeof refreshPrompt === "function") refreshPrompt();
|
|
3982
4093
|
});
|
|
@@ -4091,7 +4202,19 @@ function apply(ctx, config) {
|
|
|
4091
4202
|
return;
|
|
4092
4203
|
}
|
|
4093
4204
|
void Promise.resolve(sctx.settings.mutate("web", ops)).catch((error) => {
|
|
4094
|
-
|
|
4205
|
+
const message = error?.message ?? String(error);
|
|
4206
|
+
// #82:profile 的 package.json 原子写锁超时是另一类失败——不是 provider 冲突,
|
|
4207
|
+
// 而是同一 profile 被并发写入,写不进配置 → 运行态和配置态对不上 → 下一轮 apply 再来一次。
|
|
4208
|
+
if (/timed out waiting for the writer lock/i.test(message)) {
|
|
4209
|
+
logOnce(
|
|
4210
|
+
logger,
|
|
4211
|
+
"warn",
|
|
4212
|
+
"free-search: could not write the web provider selection — the profile's package.json writer lock timed out " +
|
|
4213
|
+
`(${message}). Another writer is holding the same profile; this plugin retries on the next apply.`
|
|
4214
|
+
);
|
|
4215
|
+
return;
|
|
4216
|
+
}
|
|
4217
|
+
logger.warn(`free-search: failed to take over the web providers (${message})`);
|
|
4095
4218
|
});
|
|
4096
4219
|
});
|
|
4097
4220
|
|
|
@@ -5106,6 +5229,7 @@ function apply(ctx, config) {
|
|
|
5106
5229
|
|
|
5107
5230
|
export {
|
|
5108
5231
|
ALL_ENGINES,
|
|
5232
|
+
isBridgeRequestAllowed,
|
|
5109
5233
|
EXPLICIT_ONLY_ENGINES,
|
|
5110
5234
|
assertSchemasterySupportsVolatile,
|
|
5111
5235
|
COOLDOWN_SESSION_MS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-free-search",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "Free web search for DeepSeek Harness: 27 engines (Bing/DuckDuckGo/AnySearch/SearXNG/Exa/Tavily/Keenable/Firecrawl/Parallel keyless; Zhihu global/site via MCP and Perplexity/SerpBase/DeepSeek (official + native tools/search)/You.com/Baidu/Kimi/Aliyun/Doubao 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",
|