dsh-free-search 0.9.83 → 0.9.84
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 +22 -5
- package/lib/client.js +1 -537
- package/lib/index.js +13 -129
- package/package.json +3 -8
- package/lib/activity.js +0 -341
package/README.md
CHANGED
|
@@ -257,6 +257,16 @@ dsh web
|
|
|
257
257
|
Error: configured web provider "ddg" is not registered
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
+
**已经卸掉了、忘了删?** 插件不在也能修——新增的 `restore` 命令直接改配置文件,不加载插件:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
npx dsh-free-search restore # 所有 profile
|
|
264
|
+
npx dsh-free-search restore --profile web # 只清一个
|
|
265
|
+
npx dsh-free-search restore --dry-run # 只看会改什么,不写
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
它只删本插件自己写进去的两个值(`searchProvider: ddg`、`fetchProvider: fs-quality-fetch`);你自己显式选的 provider 不动;删完只剩 `id` + `name` 的行整行去掉;注释、顺序、引号风格和 CRLF 都保留;写入前先备份成 `*.bak-before-free-search-restore`。改完重启 `dsh` 让 web 服务重建。
|
|
269
|
+
|
|
260
270
|
更早的 DSH(0.1.x)由 patch 静态覆盖 config,不需要也更不该手写这段,这里不再赘述。
|
|
261
271
|
|
|
262
272
|
#### DSH 的「DeepSeek 搜索 API」开关
|
|
@@ -642,7 +652,7 @@ npx -y -p dsh-free-search dsh-free-search-mcp
|
|
|
642
652
|
|
|
643
653
|
#### 离线自检断言(tools/)
|
|
644
654
|
|
|
645
|
-
仓库自带 **
|
|
655
|
+
仓库自带 **105 个**零依赖断言脚本(合计 **1329 项**)
|
|
646
656
|
|
|
647
657
|
| 脚本 | 覆盖 | 运行(项数) |
|
|
648
658
|
|---|---|---|
|
|
@@ -682,9 +692,6 @@ npx -y -p dsh-free-search dsh-free-search-mcp
|
|
|
682
692
|
| `assert-serper.mjs` | Serper.dev 引擎(#157):端点常量、`X-API-KEY` 鉴权(非 Bearer)、`num` 上限 100、`tbs` 时间语法(含绝对日期 `cd_min`)、`organic` 映射、401/403/429 错误分类、缺 key 快速失败、catalog 与 MCP/设置页接线 | `node tools/assert-serper.mjs`(10) |
|
|
683
693
|
| `assert-tavily-endpoint.mjs` | Tavily 兼容端点(#153):留空 = 官方地址、base 自动补 `/search`、query/hash 被剥离、非 http(s) 拒绝、key 只走 Authorization 头、401 点名端点、配置与设置页接线 | `node tools/assert-tavily-endpoint.mjs`(8) |
|
|
684
694
|
| `assert-hint-card.mjs` | 字段说明悬停卡:长说明不再占正文、卡片经 portal 挂到 body(否则被卡片 `overflow:clip` 裁掉)、Esc 关闭、聚焦打开/失焦关闭、悬停有延迟、触屏可点、卡片不越出视口、深浅色都覆盖、标签文字在图标按钮外(否则被压成一字一行)、点图标不连带切换复选框 | `node tools/assert-hint-card.mjs`(14) |
|
|
685
|
-
| `assert-activity-panel.mjs` | 右侧栏搜索动态(#144):记录只在内存不落盘、历史上限 50、来源上限 8、按会话隔离、进行中/完成状态、引擎结果分类(成功/失败类别/跳过原因)、清空、默认关闭、旧宿主无右侧栏服务时整体跳过、tab 正文+标题+引导入口注册、bridge 路由走统一守卫、工具分发携带会话、轮询随卸载停止、中英文案 | `node tools/assert-activity-panel.mjs`(15) |
|
|
686
|
-
| `assert-activity-wiring.mjs` | 搜索动态接线(#144 回归):配置项默认关闭且能完整往返、座位标志只在服务注入后才置位、加载时已开启也能挂载、tab id 三处共用、引导入口带 commandId 且标题/描述是函数、package.json 声明 `dsh-client-ui-sidebar-right` 为可选 peer 与 client inject、服务缺失时有 try/catch 兜底 | `node tools/assert-activity-wiring.mjs`(8) |
|
|
687
|
-
| `assert-activity-pipeline.mjs` | 搜索动态数据面端到端:工具钩子把会话带进搜索链、记录归属该会话、进行中可见当前引擎、结束后离开 in-flight、引擎结果与来源往返完好、无归属记录仍可见、会话之间不串、底部计数已接线、两条 bridge 路由都过统一守卫、面板轮询随卸载停止 | `node tools/assert-activity-pipeline.mjs`(20) |
|
|
688
695
|
| `assert-restore-cli.mjs` | 卸载后清理入口(#159):`restore` 子命令不依赖插件运行时、只删插件自己写进去的 `searchProvider: ddg` / `fetchProvider: fs-quality-fetch`、用户显式选的 provider 不动、只剩 id+name 的空行整行删除、注释/顺序/引号/CRLF 保留、写入前备份、重复运行无副作用、`--dry-run` 不写、`--profile` 只清指定 profile、参数不明时拒绝写入 | `node tools/assert-restore-cli.mjs`(12) |
|
|
689
696
|
| `assert-upgrade-version.mjs` | 一键升级以实际安装结果为准(#163):读回 profile 里真正落下的版本、与 registry 比较、冷却拦截单独报 `upgrade-blocked`、成功路径报 installed 而非 latest、读不到安装状态时不算成功、界面 toast 用 installed、被拦截时用告警色并保留原文案 | `node tools/assert-upgrade-version.mjs`(8) |
|
|
690
697
|
| `assert-search-proxy.mjs` | 搜索代理(#155)的规则层:http/https/socks5 地址解析、凭据百分号解码、无 scheme 视为 http、socks5h 交给代理解析、非法协议拒绝、`no_proxy` 优先于显式设置、空设置不接管环境变量代理、活动代理是配置层写入的模块状态、搜索路径不再直连全局 `fetch`、该设置只管引擎(天气/更新检查/抓取层保持平台 fetch)、界面中英双语文案、SOCKS5 由本仓库自己实现、重定向三档语义、abort/timeout 保持原生 error 名、HTTP/1.1 请求必须走我们自己的隧道 socket(`agent: false` 与 `https.request` 都会静默绕过代理)、新增依赖为零 | `node tools/assert-search-proxy.mjs`(18) |
|
|
@@ -1043,6 +1050,16 @@ So **remove those `- id: web` lines before disabling or uninstalling this plugin
|
|
|
1043
1050
|
Error: configured web provider "ddg" is not registered
|
|
1044
1051
|
```
|
|
1045
1052
|
|
|
1053
|
+
**Already uninstalled and forgot?** The `restore` command fixes the profile patch without loading the plugin:
|
|
1054
|
+
|
|
1055
|
+
```
|
|
1056
|
+
npx dsh-free-search restore # every profile
|
|
1057
|
+
npx dsh-free-search restore --profile web # one profile
|
|
1058
|
+
npx dsh-free-search restore --dry-run # report only, write nothing
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
It removes only the two values this plugin wrote (`searchProvider: ddg`, `fetchProvider: fs-quality-fetch`); a provider you chose yourself is left alone; a row left with just `id` + `name` is dropped entirely; comments, ordering, quoting and CRLF survive; and it writes a `*.bak-before-free-search-restore` backup first. Restart `dsh` afterwards so the web service rebuilds.
|
|
1062
|
+
|
|
1046
1063
|
Older DSH (0.1.x) used a static patch layer for this; writing that row by hand there is neither needed nor recommended.
|
|
1047
1064
|
|
|
1048
1065
|
#### DSH's "DeepSeek search API" switch
|
|
@@ -1425,7 +1442,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1425
1442
|
|
|
1426
1443
|
#### Offline self-check assertions (`tools/`)
|
|
1427
1444
|
|
|
1428
|
-
**One hundred and
|
|
1445
|
+
**One hundred and five** zero-dependency assertion scripts ship with the repo (**1329 assertions** total)
|
|
1429
1446
|
|
|
1430
1447
|
| Script | Covers | Run (count) |
|
|
1431
1448
|
|---|---|---|
|
package/lib/client.js
CHANGED
|
@@ -388,86 +388,6 @@ window.__ModuleLoader__.load({
|
|
|
388
388
|
".dshfs-mobileNav{background:rgba(30,30,32,.94);border-bottom-color:rgba(255,255,255,.1)}",
|
|
389
389
|
".dshfs-mobileNavItem{background:rgba(255,255,255,.06);border-color:rgba(255,255,255,.1)}",
|
|
390
390
|
".dshfs-mobileNavItemActive{color:#0a84ff;background:rgba(10,132,255,.18);border-color:rgba(10,132,255,.35)}",
|
|
391
|
-
"}",
|
|
392
|
-
|
|
393
|
-
// ---------- #144 右侧栏「搜索动态」 ----------
|
|
394
|
-
// 宿主给的是窄栏(约 300-420px),所以一律单列、靠左,不用横向布局。
|
|
395
|
-
".dsfs-act{display:flex;flex-direction:column;height:100%;min-height:0;font-family:inherit;color:inherit;font-size:13px}",
|
|
396
|
-
".dsfs-act-scroll{flex:1;min-height:0;overflow-y:auto;padding:12px 14px;display:flex;flex-direction:column;gap:14px}",
|
|
397
|
-
".dsfs-act-card{border:1px solid rgba(0,0,0,.09);border-radius:10px;background:rgba(0,0,0,.03);padding:10px 11px;display:flex;flex-direction:column;gap:8px}",
|
|
398
|
-
".dsfs-act-line{display:flex;align-items:center;gap:8px;min-width:0}",
|
|
399
|
-
".dsfs-act-k{font-size:11px;color:#6e6e73;flex:none}",
|
|
400
|
-
".dsfs-act-q{font-size:13px;font-weight:500;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
401
|
-
".dsfs-act-back{margin-left:auto;flex:none;font-size:11.5px;color:#6e6e73}",
|
|
402
|
-
".dsfs-act-back b{color:inherit;font-weight:600}",
|
|
403
|
-
".dsfs-act-bar{height:4px;border-radius:99px;border:1px solid rgba(0,0,0,.09);background:rgba(0,0,0,.03);overflow:hidden}",
|
|
404
|
-
".dsfs-act-bar i{display:block;height:100%;width:42%;border-radius:99px;background:#0071e3;animation:dsfsActSlide 1.6s ease-in-out infinite}",
|
|
405
|
-
"@keyframes dsfsActSlide{0%{margin-left:-42%}100%{margin-left:100%}}",
|
|
406
|
-
"@media (prefers-reduced-motion: reduce){.dsfs-act-bar i{animation:none;width:60%}}",
|
|
407
|
-
".dsfs-act-metrics{display:flex;align-items:center;gap:5px;font-size:12px;color:#6e6e73;flex-wrap:wrap}",
|
|
408
|
-
".dsfs-act-metrics b{color:inherit;font-weight:600;font-variant-numeric:tabular-nums}",
|
|
409
|
-
".dsfs-act-sep{opacity:.45}",
|
|
410
|
-
".dsfs-act-sec{display:flex;flex-direction:column;gap:6px}",
|
|
411
|
-
".dsfs-act-secTitle{font-size:11px;color:#6e6e73;letter-spacing:.04em;text-transform:uppercase}",
|
|
412
|
-
".dsfs-act-chips{display:flex;flex-wrap:wrap;gap:5px}",
|
|
413
|
-
".dsfs-act-chip{display:inline-flex;align-items:center;gap:4px;font-size:11px;line-height:1;padding:5px 8px;border-radius:999px;border:1px solid rgba(0,0,0,.09);background:#fff;white-space:nowrap}",
|
|
414
|
-
".dsfs-act-dot{width:6px;height:6px;border-radius:50%;background:#c7c7cc;flex:none}",
|
|
415
|
-
".dsfs-act-chip .dsfs-act-dot{background:#c7c7cc}",
|
|
416
|
-
".dsfs-act-chip.is-ok .dsfs-act-dot{background:#34c759}",
|
|
417
|
-
".dsfs-act-chip.is-run .dsfs-act-dot{background:#0071e3}",
|
|
418
|
-
".dsfs-act-chip.is-bad{color:#ff3b30;border-color:rgba(255,59,48,.28)}",
|
|
419
|
-
".dsfs-act-chip.is-bad .dsfs-act-dot{background:#ff3b30}",
|
|
420
|
-
".dsfs-act-chip.is-skip{opacity:.55}",
|
|
421
|
-
".dsfs-act-chipN{color:#6e6e73;font-variant-numeric:tabular-nums}",
|
|
422
|
-
".dsfs-act-chipTag{opacity:.85}",
|
|
423
|
-
".dsfs-act-srcList{display:flex;flex-direction:column;gap:1px}",
|
|
424
|
-
".dsfs-act-src{display:flex;align-items:flex-start;gap:9px;padding:7px 6px;border-radius:8px;color:inherit;text-decoration:none}",
|
|
425
|
-
".dsfs-act-src:hover{background:rgba(0,0,0,.04)}",
|
|
426
|
-
".dsfs-act-fav{width:14px;height:14px;border-radius:3px;border:1px solid rgba(0,0,0,.09);background:rgba(0,0,0,.03);flex:none;margin-top:2px}",
|
|
427
|
-
".dsfs-act-srcBody{min-width:0;display:flex;flex-direction:column;gap:2px}",
|
|
428
|
-
".dsfs-act-srcTitle{font-size:12.5px;line-height:1.35;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}",
|
|
429
|
-
".dsfs-act-srcHost{font-size:11px;color:#6e6e73;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
430
|
-
".dsfs-act-more{align-self:flex-start;font-size:11.5px;color:#0071e3;background:none;border:0;cursor:pointer;padding:2px 6px}",
|
|
431
|
-
".dsfs-act-emptyLine{margin:0;font-size:12px;color:#6e6e73}",
|
|
432
|
-
".dsfs-act-foot{border-top:1px solid rgba(0,0,0,.09);padding:8px 12px;display:flex;align-items:center;gap:6px;flex:none}",
|
|
433
|
-
".dsfs-act-ghost{font-size:11.5px;color:#6e6e73;background:none;border:0;cursor:pointer;padding:4px 6px;border-radius:6px}",
|
|
434
|
-
".dsfs-act-ghost:hover{background:rgba(0,0,0,.04);color:inherit}",
|
|
435
|
-
".dsfs-act-state{margin-left:auto;display:inline-flex;align-items:center;gap:5px;font-size:11px;color:#6e6e73}",
|
|
436
|
-
".dsfs-act-diag{font-size:10px;color:#8e8e93;font-variant-numeric:tabular-nums;opacity:.75;white-space:normal;overflow-wrap:anywhere;line-height:1.35}",
|
|
437
|
-
".dsfs-act-dot-run{background:#0071e3;animation:dsfsActPulse 1.4s ease-in-out infinite}",
|
|
438
|
-
".dsfs-act-dot-done{background:#34c759}",
|
|
439
|
-
".dsfs-act-dot-idle{background:#c7c7cc}",
|
|
440
|
-
"@keyframes dsfsActPulse{0%,100%{opacity:1}50%{opacity:.35}}",
|
|
441
|
-
"@media (prefers-reduced-motion: reduce){.dsfs-act-dot-run{animation:none}}",
|
|
442
|
-
".dsfs-act-sub{display:flex;align-items:center;gap:8px;padding:10px 14px;border-bottom:1px solid rgba(0,0,0,.09);flex:none}",
|
|
443
|
-
".dsfs-act-subTitle{font-size:13px;font-weight:600;flex:1}",
|
|
444
|
-
".dsfs-act-subCount{font-size:11px;color:#6e6e73;font-variant-numeric:tabular-nums}",
|
|
445
|
-
".dsfs-act-icon{width:22px;height:22px;border-radius:6px;border:0;background:transparent;color:#6e6e73;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;font-size:13px}",
|
|
446
|
-
".dsfs-act-icon:hover{background:rgba(0,0,0,.04);color:inherit}",
|
|
447
|
-
".dsfs-act-hist{display:flex;align-items:center;gap:8px;padding:8px 6px;border:0;border-radius:8px;background:none;font:inherit;font-size:12px;color:inherit;text-align:left;cursor:pointer}",
|
|
448
|
-
".dsfs-act-hist:hover{background:rgba(0,0,0,.04)}",
|
|
449
|
-
".dsfs-act-histQ{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
450
|
-
".dsfs-act-histN{flex:none;font-size:11px;color:#6e6e73;font-variant-numeric:tabular-nums}",
|
|
451
|
-
".dsfs-act-histTurn{flex:none;font-size:10.5px;color:#8e8e93;padding:1px 5px;border-radius:5px;background:rgba(0,0,0,.04);white-space:nowrap}",
|
|
452
|
-
".dsfs-act-histT{flex:none;font-size:11px;color:#6e6e73}",
|
|
453
|
-
"@media (prefers-color-scheme: dark){",
|
|
454
|
-
".dsfs-act-card{border-color:rgba(255,255,255,.1);background:rgba(255,255,255,.05)}",
|
|
455
|
-
".dsfs-act-k,.dsfs-act-back,.dsfs-act-secTitle,.dsfs-act-srcHost,.dsfs-act-emptyLine,.dsfs-act-ghost,.dsfs-act-state,.dsfs-act-subCount,.dsfs-act-histN,.dsfs-act-histT,.dsfs-act-chipN{color:#a1a1a6}",
|
|
456
|
-
".dsfs-act-bar{border-color:rgba(255,255,255,.1);background:rgba(255,255,255,.05)}",
|
|
457
|
-
".dsfs-act-bar i{background:#0a84ff}",
|
|
458
|
-
".dsfs-act-chip{border-color:rgba(255,255,255,.12);background:rgba(255,255,255,.06)}",
|
|
459
|
-
".dsfs-act-chip.is-ok .dsfs-act-dot{background:#30d158}",
|
|
460
|
-
".dsfs-act-chip.is-run .dsfs-act-dot{background:#0a84ff}",
|
|
461
|
-
".dsfs-act-chip.is-bad{color:#ff453a;border-color:rgba(255,69,58,.32)}",
|
|
462
|
-
".dsfs-act-chip.is-bad .dsfs-act-dot{background:#ff453a}",
|
|
463
|
-
".dsfs-act-src:hover{background:rgba(255,255,255,.07)}",
|
|
464
|
-
".dsfs-act-fav{border-color:rgba(255,255,255,.12);background:rgba(255,255,255,.05)}",
|
|
465
|
-
".dsfs-act-more{color:#0a84ff}",
|
|
466
|
-
".dsfs-act-foot,.dsfs-act-sub{border-color:rgba(255,255,255,.1)}",
|
|
467
|
-
".dsfs-act-ghost:hover,.dsfs-act-icon:hover,.dsfs-act-hist:hover{background:rgba(255,255,255,.07)}",
|
|
468
|
-
".dsfs-act-dot-run{background:#0a84ff}",
|
|
469
|
-
".dsfs-act-dot-done{background:#30d158}",
|
|
470
|
-
".dsfs-act-dot-idle{background:#48484a}",
|
|
471
391
|
"}"
|
|
472
392
|
].join("");
|
|
473
393
|
const tagId = "dsh-free-search/card.css";
|
|
@@ -546,8 +466,6 @@ window.__ModuleLoader__.load({
|
|
|
546
466
|
description: "免费搜索 —— 免密钥引擎、可选 API 集成与智能路由",
|
|
547
467
|
keylessFirstLabel: "优先使用免 key 档",
|
|
548
468
|
keylessFirstHint: "默认关闭:配了 key 的引擎一律用 key。开启后,Exa、Tavily、Keenable、Firecrawl、Parallel、AnySearch、You.com 先走免 key 档,限流、额度用尽、鉴权或网络失败时才改用 key,省 key 的额度。",
|
|
549
|
-
activityPanelLabel: "在右侧栏显示搜索动态",
|
|
550
|
-
activityPanelHint: "默认开启:右侧栏「更多工具」里会出现「搜索动态」:本轮正在试哪个引擎、已用多久、最终命中多少条结果、来源列表。数据只存在于内存,重启即清空,可按会话清空。需要 DSH 0.2.2-rc.1 或更新版本。",
|
|
551
469
|
engineEnable: "全局启用的搜索引擎",
|
|
552
470
|
engineEnableHint: "勾选即加入启用白名单,取消即移出。未启用的引擎会从 web_search 回退链、Auto 智能路由、advanced_search、multi_search 和引擎测试中全局排除。至少保留一个引擎;新版本新增的引擎默认不启用。",
|
|
553
471
|
fallbackPriority: "全局回退优先级",
|
|
@@ -801,8 +719,6 @@ window.__ModuleLoader__.load({
|
|
|
801
719
|
description: "Free web search — keyless engines, optional API integrations, and smart routing",
|
|
802
720
|
keylessFirstLabel: "Use keyless tiers first",
|
|
803
721
|
keylessFirstHint: "Off by default: an engine with a key always uses it. When on, Exa, Tavily, Keenable, Firecrawl, Parallel, AnySearch and You.com try their keyless tier first and switch to the key only when it is rate limited, out of quota, needs auth or fails to connect, which saves the key's quota.",
|
|
804
|
-
activityPanelLabel: "Show search activity in the right sidebar",
|
|
805
|
-
activityPanelHint: "On by default: a \"Search activity\" tab appears under More tools in the right sidebar: which engine is being tried, how long it has run, how many results came back, and where they came from. Records live in memory only, are cleared by a restart, and can be cleared per session. Requires DSH 0.2.2-rc.1 or newer.",
|
|
806
722
|
engineEnable: "Globally enabled search engines",
|
|
807
723
|
engineEnableHint: "Checked engines are the enable allowlist; unchecked engines are excluded globally from web_search fallback, Auto routing, advanced_search, multi_search and engine tests. At least one engine must stay enabled, and engines added by later versions stay off.",
|
|
808
724
|
fallbackPriority: "Global fallback priority",
|
|
@@ -1018,7 +934,7 @@ window.__ModuleLoader__.load({
|
|
|
1018
934
|
"cache_search",
|
|
1019
935
|
"domain_search",
|
|
1020
936
|
];
|
|
1021
|
-
const PLUGIN_VERSION = "0.9.
|
|
937
|
+
const PLUGIN_VERSION = "0.9.84";
|
|
1022
938
|
const PLUGIN_REPO_URL = "https://github.com/DDDMUC/dsh-free-search";
|
|
1023
939
|
// 右侧浮动目录(#85):条目顺序即页面顺序,anchor 是页面里对应 field 的 id。
|
|
1024
940
|
const NAV_ITEMS = [
|
|
@@ -1274,26 +1190,6 @@ window.__ModuleLoader__.load({
|
|
|
1274
1190
|
return response.json();
|
|
1275
1191
|
}
|
|
1276
1192
|
|
|
1277
|
-
// #144:搜索动态快照。sessionId 为空时服务端返回全局视图。
|
|
1278
|
-
async function bridgeActivity(sessionId = "") {
|
|
1279
|
-
const response = await fetch(bridgeUrl("activity"), {
|
|
1280
|
-
method: "POST",
|
|
1281
|
-
headers: { "content-type": "application/json" },
|
|
1282
|
-
body: JSON.stringify({ sessionId }),
|
|
1283
|
-
signal: AbortSignal.timeout(8000),
|
|
1284
|
-
});
|
|
1285
|
-
return response.json();
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
async function bridgeActivityClear(sessionId = "") {
|
|
1289
|
-
const response = await fetch(bridgeUrl("activity-clear"), {
|
|
1290
|
-
method: "POST",
|
|
1291
|
-
headers: { "content-type": "application/json" },
|
|
1292
|
-
body: JSON.stringify({ sessionId }),
|
|
1293
|
-
});
|
|
1294
|
-
return response.json();
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
1193
|
// UI-only locale; never derive search or prompt settings from it.
|
|
1298
1194
|
const PANEL_LABELS = {
|
|
1299
1195
|
zh: "免费搜索",
|
|
@@ -1305,18 +1201,11 @@ window.__ModuleLoader__.load({
|
|
|
1305
1201
|
ru: "Бесплатный поиск",
|
|
1306
1202
|
pt: "Pesquisa grátis",
|
|
1307
1203
|
};
|
|
1308
|
-
// #144:右侧栏「搜索动态」的文案与标签。
|
|
1309
|
-
const ACTIVITY_LABELS = {
|
|
1310
|
-
zh: { title: "搜索动态", guide: "搜索动态", guideDesc: "本轮引擎、耗时与来源", turnN: "第 {n} 轮", close: "关闭", back: "返回", clear: "清空记录", hist: "历史", round: "第 {n} 轮", searching: "搜索中", done: "已完成", idle: "空闲", query: "查询", engines: "引擎", sources: "来源", more: "还有 {n} 条", empty: "还没有搜索记录", emptyHint: "这个会话发起搜索后,这里会显示引擎、耗时与来源", results: "条结果", from: "个来源", cacheHit: "缓存命中", elapsed: "已用 {t}", engineN: "引擎 {i} / {n}", running: "进行中", skipped: "跳过", noData: "暂无", ago: "前" },
|
|
1311
|
-
en: { title: "Search activity", guide: "Search activity", guideDesc: "Engines, timing and sources for this turn", turnN: "Turn {n}", close: "Close", back: "Back", clear: "Clear", hist: "History", round: "Round {n}", searching: "Searching", done: "Done", idle: "Idle", query: "Query", engines: "Engines", sources: "Sources", more: "{n} more", empty: "No searches yet", emptyHint: "Once this session runs a search, engines, timing and sources appear here", results: "results", from: "sources", cacheHit: "cache hit", elapsed: "{t} elapsed", engineN: "Engine {i} / {n}", running: "running", skipped: "skipped", noData: "none", ago: "ago" },
|
|
1312
|
-
};
|
|
1313
|
-
const activityText = (active) => ACTIVITY_LABELS[localeId(active)] ?? ACTIVITY_LABELS.en;
|
|
1314
1204
|
let localeFace = null;
|
|
1315
1205
|
let savedUiLang = "";
|
|
1316
1206
|
let uiLangRevision = 0;
|
|
1317
1207
|
let sidebarEntryController = null;
|
|
1318
1208
|
let slashCommandsController = null;
|
|
1319
|
-
let activityPanelController = null;
|
|
1320
1209
|
const uiLocaleListeners = new Set();
|
|
1321
1210
|
const subscribeUiLocale = (listener) => {
|
|
1322
1211
|
uiLocaleListeners.add(listener);
|
|
@@ -1629,328 +1518,6 @@ window.__ModuleLoader__.load({
|
|
|
1629
1518
|
});
|
|
1630
1519
|
}
|
|
1631
1520
|
|
|
1632
|
-
// #144:右侧栏「搜索动态」面板。
|
|
1633
|
-
//
|
|
1634
|
-
// 正文只渲染内容本身:标签页的标题由 sidebar.right.pane.tab.title 座位画,
|
|
1635
|
-
// 面板外框(停靠、拆分、关闭)由宿主负责。这里不重复画自己的头部。
|
|
1636
|
-
function activityAgo(ms, t) {
|
|
1637
|
-
const s = Math.max(0, Math.round(ms / 1000));
|
|
1638
|
-
if (s < 60) return `${s}s`;
|
|
1639
|
-
const m = Math.round(s / 60);
|
|
1640
|
-
if (m < 60) return `${m}m`;
|
|
1641
|
-
const h = Math.round(m / 60);
|
|
1642
|
-
if (h < 24) return `${h}h`;
|
|
1643
|
-
return `${Math.round(h / 24)}d`;
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
const activityFailureLabel = { quota: "额度", auth: "鉴权", "bot-wall": "反爬", transient: "超时", "invalid-response": "无效", unknown: "失败" };
|
|
1647
|
-
const activitySkipLabel = { "time-filter": "时间过滤", "no-key": "无 key", disabled: "已禁用", skipped: "跳过" };
|
|
1648
|
-
|
|
1649
|
-
function ActivityEngines({ record, t }) {
|
|
1650
|
-
const engines = record?.engines ?? [];
|
|
1651
|
-
if (engines.length === 0) {
|
|
1652
|
-
return react_jsx_runtime.jsx("p", { className: "dsfs-act-emptyLine", children: t.noData });
|
|
1653
|
-
}
|
|
1654
|
-
return react_jsx_runtime.jsx("div", { className: "dsfs-act-chips", children: engines.map((engine) =>
|
|
1655
|
-
react_jsx_runtime.jsx("span", {
|
|
1656
|
-
className: "dsfs-act-chip " + (
|
|
1657
|
-
engine.status === "ok" ? "is-ok"
|
|
1658
|
-
: engine.status === "failed" ? "is-bad"
|
|
1659
|
-
: engine.status === "running" ? "is-run"
|
|
1660
|
-
: "is-skip"
|
|
1661
|
-
),
|
|
1662
|
-
title: engine.status === "failed" ? `${engine.id} · ${activityFailureLabel[engine.failureClass] ?? "失败"}`
|
|
1663
|
-
: engine.status === "skipped" ? `${engine.id} · ${activitySkipLabel[engine.skipReason] ?? t.skipped}`
|
|
1664
|
-
: engine.cached === true ? `${engine.id} · ${t.cacheHit}`
|
|
1665
|
-
: engine.id,
|
|
1666
|
-
children: [
|
|
1667
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-dot" }, "·"),
|
|
1668
|
-
react_jsx_runtime.jsx("span", { children: engine.id }),
|
|
1669
|
-
engine.status === "ok" && engine.count > 0
|
|
1670
|
-
? react_jsx_runtime.jsx("span", { className: "dsfs-act-chipN", children: " " + engine.count })
|
|
1671
|
-
: null,
|
|
1672
|
-
engine.status === "failed"
|
|
1673
|
-
? react_jsx_runtime.jsx("span", { className: "dsfs-act-chipTag", children: activityFailureLabel[engine.failureClass] ?? "失败" })
|
|
1674
|
-
: null,
|
|
1675
|
-
engine.status === "skipped"
|
|
1676
|
-
? react_jsx_runtime.jsx("span", { className: "dsfs-act-chipTag", children: activitySkipLabel[engine.skipReason] ?? t.skipped })
|
|
1677
|
-
: null,
|
|
1678
|
-
engine.cached === true
|
|
1679
|
-
? react_jsx_runtime.jsx("span", { className: "dsfs-act-chipTag", children: t.cacheHit })
|
|
1680
|
-
: null,
|
|
1681
|
-
],
|
|
1682
|
-
}, engine.id + "#" + engine.status)
|
|
1683
|
-
) });
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
function ActivitySources({ record, t }) {
|
|
1687
|
-
const sources = record?.sources ?? [];
|
|
1688
|
-
const [expanded, setExpanded] = react.useState(false);
|
|
1689
|
-
if (sources.length === 0) return null;
|
|
1690
|
-
const shown = expanded ? sources : sources.slice(0, 8);
|
|
1691
|
-
const rest = sources.length - shown.length;
|
|
1692
|
-
return react_jsx_runtime.jsxs("div", {
|
|
1693
|
-
className: "dsfs-act-sec",
|
|
1694
|
-
children: [
|
|
1695
|
-
react_jsx_runtime.jsx("div", { className: "dsfs-act-secTitle", children: t.sources }),
|
|
1696
|
-
react_jsx_runtime.jsx("div", { className: "dsfs-act-srcList", children: shown.map((source, index) =>
|
|
1697
|
-
react_jsx_runtime.jsxs("a", {
|
|
1698
|
-
className: "dsfs-act-src",
|
|
1699
|
-
href: source.url || undefined,
|
|
1700
|
-
target: "_blank",
|
|
1701
|
-
rel: "noopener noreferrer",
|
|
1702
|
-
title: source.url || source.title,
|
|
1703
|
-
children: [
|
|
1704
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-fav", "aria-hidden": "true" }),
|
|
1705
|
-
react_jsx_runtime.jsxs("span", {
|
|
1706
|
-
className: "dsfs-act-srcBody",
|
|
1707
|
-
children: [
|
|
1708
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-srcTitle", children: source.title || source.url }),
|
|
1709
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-srcHost", children: source.host || "" }),
|
|
1710
|
-
],
|
|
1711
|
-
}),
|
|
1712
|
-
],
|
|
1713
|
-
}, (source.url || source.title) + "#" + index)
|
|
1714
|
-
) }),
|
|
1715
|
-
rest > 0
|
|
1716
|
-
? react_jsx_runtime.jsx("button", {
|
|
1717
|
-
type: "button",
|
|
1718
|
-
className: "dsfs-act-more",
|
|
1719
|
-
onClick: () => setExpanded(true),
|
|
1720
|
-
children: t.more.replace("{n}", String(rest)),
|
|
1721
|
-
})
|
|
1722
|
-
: null,
|
|
1723
|
-
],
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
function ActivityCurrent({ run, t }) {
|
|
1728
|
-
return react_jsx_runtime.jsxs("div", {
|
|
1729
|
-
className: "dsfs-act-card",
|
|
1730
|
-
children: [
|
|
1731
|
-
react_jsx_runtime.jsxs("div", {
|
|
1732
|
-
className: "dsfs-act-line",
|
|
1733
|
-
children: [
|
|
1734
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-k", children: t.query }),
|
|
1735
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-q", children: run.query || "—" }),
|
|
1736
|
-
],
|
|
1737
|
-
}),
|
|
1738
|
-
react_jsx_runtime.jsxs("div", {
|
|
1739
|
-
className: "dsfs-act-line",
|
|
1740
|
-
children: [
|
|
1741
|
-
react_jsx_runtime.jsx("span", {
|
|
1742
|
-
className: "dsfs-act-k",
|
|
1743
|
-
children: t.engineN.replace("{i}", String(Math.min(run.enginesDone + 1, Math.max(run.enginesTotal, 1)))).replace("{n}", String(Math.max(run.enginesTotal, 1))),
|
|
1744
|
-
}),
|
|
1745
|
-
react_jsx_runtime.jsxs("span", {
|
|
1746
|
-
className: "dsfs-act-back",
|
|
1747
|
-
children: [
|
|
1748
|
-
react_jsx_runtime.jsx("b", { children: run.currentEngine || "…" }),
|
|
1749
|
-
" · ",
|
|
1750
|
-
t.elapsed.replace("{t}", activityAgo(run.ms, t)),
|
|
1751
|
-
],
|
|
1752
|
-
}),
|
|
1753
|
-
],
|
|
1754
|
-
}),
|
|
1755
|
-
react_jsx_runtime.jsx("div", { className: "dsfs-act-bar", children: react_jsx_runtime.jsx("i", {}) }),
|
|
1756
|
-
],
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
function ActivityBody(props) {
|
|
1761
|
-
const active = getUiLocale();
|
|
1762
|
-
const activeLive = react.useSyncExternalStore(subscribeUiLocale, getUiLocale, getUiLocale);
|
|
1763
|
-
const t = activityText(activeLive);
|
|
1764
|
-
const sessionId = String(props?.sessionId ?? "");
|
|
1765
|
-
const [snapshot, setSnapshot] = react.useState(null);
|
|
1766
|
-
const [view, setView] = react.useState("current");
|
|
1767
|
-
const [tick, setTick] = react.useState(0);
|
|
1768
|
-
|
|
1769
|
-
// 只在面板可见时轮询;不可见立即停。
|
|
1770
|
-
react.useEffect(() => {
|
|
1771
|
-
let alive = true;
|
|
1772
|
-
let timer = null;
|
|
1773
|
-
const pull = async () => {
|
|
1774
|
-
try {
|
|
1775
|
-
const result = await bridgeActivity(sessionId);
|
|
1776
|
-
if (!alive) return;
|
|
1777
|
-
if (result?.ok) setSnapshot(result.value);
|
|
1778
|
-
} catch {
|
|
1779
|
-
/* 网络抖动:保持上一次快照 */
|
|
1780
|
-
}
|
|
1781
|
-
};
|
|
1782
|
-
const loop = () => {
|
|
1783
|
-
if (!alive) return;
|
|
1784
|
-
void pull().then(() => {
|
|
1785
|
-
if (!alive) return;
|
|
1786
|
-
setTick((n) => n + 1);
|
|
1787
|
-
timer = setTimeout(loop, 2000);
|
|
1788
|
-
});
|
|
1789
|
-
};
|
|
1790
|
-
loop();
|
|
1791
|
-
return () => {
|
|
1792
|
-
alive = false;
|
|
1793
|
-
if (timer !== null) clearTimeout(timer);
|
|
1794
|
-
};
|
|
1795
|
-
}, [sessionId]);
|
|
1796
|
-
|
|
1797
|
-
const current = snapshot?.current ?? [];
|
|
1798
|
-
const record = snapshot?.latest ?? null;
|
|
1799
|
-
const history = snapshot?.history ?? [];
|
|
1800
|
-
|
|
1801
|
-
const clearAll = async () => {
|
|
1802
|
-
try {
|
|
1803
|
-
await bridgeActivityClear(sessionId);
|
|
1804
|
-
setSnapshot((prev) => (prev ? { ...prev, latest: null, history: [], current: [] } : prev));
|
|
1805
|
-
} catch {
|
|
1806
|
-
/* ignore */
|
|
1807
|
-
}
|
|
1808
|
-
};
|
|
1809
|
-
|
|
1810
|
-
const state = current.length > 0 ? "run" : record ? "done" : "idle";
|
|
1811
|
-
// 临时诊断:面板空着时能区分「钩子没触发 / 没开始 / 开始了没结束」。
|
|
1812
|
-
const diag = snapshot?.stats;
|
|
1813
|
-
const diagText = diag
|
|
1814
|
-
? "hook " + diag.sawHook + " · begin " + diag.began + " · end " + diag.finished + " · hist " + diag.history + " (mine " + diag.sessionHistory + ", attr " + (diag.attributed ? "yes" : "no") + ")" + " · eng " + diag.engineCalls + "/" + diag.engineDropped + (diag.missShape ? " · miss: " + diag.missShape : "")
|
|
1815
|
-
: null;
|
|
1816
|
-
|
|
1817
|
-
if (view === "history") {
|
|
1818
|
-
return react_jsx_runtime.jsxs("div", {
|
|
1819
|
-
className: "dsfs-act",
|
|
1820
|
-
children: [
|
|
1821
|
-
react_jsx_runtime.jsxs("div", {
|
|
1822
|
-
className: "dsfs-act-sub",
|
|
1823
|
-
children: [
|
|
1824
|
-
react_jsx_runtime.jsx("button", {
|
|
1825
|
-
type: "button",
|
|
1826
|
-
className: "dsfs-act-icon",
|
|
1827
|
-
title: t.back,
|
|
1828
|
-
onClick: () => setView("current"),
|
|
1829
|
-
children: "←",
|
|
1830
|
-
}),
|
|
1831
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-subTitle", children: t.hist }),
|
|
1832
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-subCount", children: history.length }),
|
|
1833
|
-
],
|
|
1834
|
-
}),
|
|
1835
|
-
react_jsx_runtime.jsx("div", {
|
|
1836
|
-
className: "dsfs-act-scroll",
|
|
1837
|
-
children: history.length === 0
|
|
1838
|
-
? react_jsx_runtime.jsx("p", { className: "dsfs-act-emptyLine", children: t.empty })
|
|
1839
|
-
: history.map((entry) =>
|
|
1840
|
-
react_jsx_runtime.jsxs("button", {
|
|
1841
|
-
type: "button",
|
|
1842
|
-
className: "dsfs-act-hist",
|
|
1843
|
-
onClick: () => { setSnapshot((prev) => (prev ? { ...prev, latest: entry } : prev)); setView("current"); },
|
|
1844
|
-
children: [
|
|
1845
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-histQ", children: entry.query || "—" }),
|
|
1846
|
-
entry.turn > 0
|
|
1847
|
-
? react_jsx_runtime.jsx("span", { className: "dsfs-act-histTurn", children: t.turnN.replace("{n}", String(entry.turn)) })
|
|
1848
|
-
: null,
|
|
1849
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-histN", children: entry.totalResults }),
|
|
1850
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-histT", children: activityAgo(Date.now() - entry.startedAt, t) }),
|
|
1851
|
-
],
|
|
1852
|
-
}, entry.id)
|
|
1853
|
-
),
|
|
1854
|
-
}),
|
|
1855
|
-
react_jsx_runtime.jsx("div", {
|
|
1856
|
-
className: "dsfs-act-foot",
|
|
1857
|
-
children: react_jsx_runtime.jsx("button", { type: "button", className: "dsfs-act-ghost", onClick: clearAll, children: t.clear }),
|
|
1858
|
-
}),
|
|
1859
|
-
],
|
|
1860
|
-
});
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
return react_jsx_runtime.jsxs("div", {
|
|
1864
|
-
className: "dsfs-act",
|
|
1865
|
-
children: [
|
|
1866
|
-
react_jsx_runtime.jsx("div", {
|
|
1867
|
-
className: "dsfs-act-scroll",
|
|
1868
|
-
children: [
|
|
1869
|
-
current.length > 0
|
|
1870
|
-
? current.map((run) => react_jsx_runtime.jsx(ActivityCurrent, { run, t }, run.id))
|
|
1871
|
-
: null,
|
|
1872
|
-
|
|
1873
|
-
current.length === 0
|
|
1874
|
-
? react_jsx_runtime.jsxs("div", {
|
|
1875
|
-
className: "dsfs-act-card",
|
|
1876
|
-
children: [
|
|
1877
|
-
react_jsx_runtime.jsxs("div", {
|
|
1878
|
-
className: "dsfs-act-line",
|
|
1879
|
-
children: [
|
|
1880
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-k", children: t.query }),
|
|
1881
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-q", children: record?.query || "—" }),
|
|
1882
|
-
record
|
|
1883
|
-
? react_jsx_runtime.jsx("span", {
|
|
1884
|
-
className: "dsfs-act-back",
|
|
1885
|
-
children: (record.turn > 0 ? t.turnN.replace("{n}", String(record.turn)) + " · " : "") + activityAgo(record.ms, t),
|
|
1886
|
-
})
|
|
1887
|
-
: null,
|
|
1888
|
-
],
|
|
1889
|
-
}),
|
|
1890
|
-
record
|
|
1891
|
-
? react_jsx_runtime.jsxs("div", {
|
|
1892
|
-
className: "dsfs-act-metrics",
|
|
1893
|
-
children: [
|
|
1894
|
-
react_jsx_runtime.jsx("b", { children: record.totalResults }),
|
|
1895
|
-
react_jsx_runtime.jsx("span", { children: t.results }),
|
|
1896
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-sep", children: "·" }),
|
|
1897
|
-
react_jsx_runtime.jsx("b", { children: record.sources.length }),
|
|
1898
|
-
react_jsx_runtime.jsx("span", { children: t.from }),
|
|
1899
|
-
record.cache === "hit"
|
|
1900
|
-
? react_jsx_runtime.jsxs(react_jsx_runtime.Fragment, { children: [
|
|
1901
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-sep", children: "·" }),
|
|
1902
|
-
react_jsx_runtime.jsx("span", { children: t.cacheHit }),
|
|
1903
|
-
] })
|
|
1904
|
-
: null,
|
|
1905
|
-
],
|
|
1906
|
-
})
|
|
1907
|
-
: react_jsx_runtime.jsx("p", { className: "dsfs-act-emptyLine", children: t.emptyHint }),
|
|
1908
|
-
],
|
|
1909
|
-
})
|
|
1910
|
-
: null,
|
|
1911
|
-
|
|
1912
|
-
record
|
|
1913
|
-
? react_jsx_runtime.jsxs("div", {
|
|
1914
|
-
className: "dsfs-act-sec",
|
|
1915
|
-
children: [
|
|
1916
|
-
react_jsx_runtime.jsx("div", { className: "dsfs-act-secTitle", children: t.engines }),
|
|
1917
|
-
react_jsx_runtime.jsx(ActivityEngines, { record, t }),
|
|
1918
|
-
],
|
|
1919
|
-
})
|
|
1920
|
-
: null,
|
|
1921
|
-
|
|
1922
|
-
record ? react_jsx_runtime.jsx(ActivitySources, { record, t }) : null,
|
|
1923
|
-
],
|
|
1924
|
-
}),
|
|
1925
|
-
react_jsx_runtime.jsxs("div", {
|
|
1926
|
-
className: "dsfs-act-foot",
|
|
1927
|
-
children: [
|
|
1928
|
-
react_jsx_runtime.jsx("button", { type: "button", className: "dsfs-act-ghost", onClick: clearAll, children: t.clear }),
|
|
1929
|
-
diagText ? react_jsx_runtime.jsx("span", { className: "dsfs-act-diag", children: diagText }) : null,
|
|
1930
|
-
react_jsx_runtime.jsx("button", {
|
|
1931
|
-
type: "button",
|
|
1932
|
-
className: "dsfs-act-ghost",
|
|
1933
|
-
onClick: () => setView("history"),
|
|
1934
|
-
children: t.hist + (history.length > 0 ? " " + history.length : ""),
|
|
1935
|
-
}),
|
|
1936
|
-
react_jsx_runtime.jsx("span", {
|
|
1937
|
-
className: "dsfs-act-state",
|
|
1938
|
-
children: [
|
|
1939
|
-
react_jsx_runtime.jsx("span", { className: "dsfs-act-dot dsfs-act-dot-" + state }),
|
|
1940
|
-
t[state],
|
|
1941
|
-
],
|
|
1942
|
-
}),
|
|
1943
|
-
],
|
|
1944
|
-
}),
|
|
1945
|
-
],
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
function ActivityTitle(props) {
|
|
1950
|
-
const activeLive = react.useSyncExternalStore(subscribeUiLocale, getUiLocale, getUiLocale);
|
|
1951
|
-
return activityText(activeLive).title;
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
1521
|
function FreeSearchSummary() {
|
|
1955
1522
|
const active = react.useSyncExternalStore(subscribeUiLocale, getUiLocale, getUiLocale);
|
|
1956
1523
|
return tt(active).description;
|
|
@@ -1969,7 +1536,6 @@ window.__ModuleLoader__.load({
|
|
|
1969
1536
|
const [sidebarEntry, setSidebarEntry] = react.useState(true);
|
|
1970
1537
|
const [slashCommands, setSlashCommands] = react.useState(true);
|
|
1971
1538
|
const [keylessFirst, setKeylessFirst] = react.useState(false);
|
|
1972
|
-
const [activityPanel, setActivityPanel] = react.useState(true);
|
|
1973
1539
|
const [effectiveDefault, setEffectiveDefault] = react.useState("bing");
|
|
1974
1540
|
const [allowedEngines, setAllowedEngines] = react.useState(
|
|
1975
1541
|
ENGINES.filter((engine) => engine.id !== "auto" && engine.id !== "multi").map((engine) => engine.id)
|
|
@@ -2345,8 +1911,6 @@ window.__ModuleLoader__.load({
|
|
|
2345
1911
|
setSlashCommands(v.slashCommands !== false);
|
|
2346
1912
|
slashCommandsController?.(v.slashCommands !== false);
|
|
2347
1913
|
setKeylessFirst(v.keylessFirst === true);
|
|
2348
|
-
setActivityPanel(v.activityPanel !== false);
|
|
2349
|
-
activityPanelController?.(v.activityPanel !== false);
|
|
2350
1914
|
// 唯一启用列表:allowedEngines 就是白名单。
|
|
2351
1915
|
// 旧配置可能只有 disabledEngines,读入时换算一次,之后只写 allowedEngines。
|
|
2352
1916
|
const configuredAllowed = Array.isArray(v.allowedEngines)
|
|
@@ -2578,7 +2142,6 @@ window.__ModuleLoader__.load({
|
|
|
2578
2142
|
ops.push({ op: "set", path: ["sidebarEntry"], value: sidebarEntry !== false });
|
|
2579
2143
|
ops.push({ op: "set", path: ["slashCommands"], value: slashCommands !== false });
|
|
2580
2144
|
ops.push({ op: "set", path: ["keylessFirst"], value: keylessFirst === true });
|
|
2581
|
-
ops.push({ op: "set", path: ["activityPanel"], value: activityPanel !== false });
|
|
2582
2145
|
// 白名单是唯一启用来源:关闭「只使用勾选的引擎」时也写出一份完整名单,
|
|
2583
2146
|
// 让之后新增的引擎保持未启用,而不是回头依赖黑名单。
|
|
2584
2147
|
ops.push({ op: "set", path: ["disabledEngines"], value: [] });
|
|
@@ -2660,7 +2223,6 @@ window.__ModuleLoader__.load({
|
|
|
2660
2223
|
setProvider(result.value.value.provider || provider || effectiveDefault);
|
|
2661
2224
|
sidebarEntryController?.(sidebarEntry !== false);
|
|
2662
2225
|
slashCommandsController?.(slashCommands !== false);
|
|
2663
|
-
activityPanelController?.(activityPanel !== false);
|
|
2664
2226
|
setFailed(false);
|
|
2665
2227
|
setSaveError("");
|
|
2666
2228
|
load();
|
|
@@ -4276,23 +3838,6 @@ react_jsx_runtime.jsxs("div", {
|
|
|
4276
3838
|
react_jsx_runtime.jsx(HintCard, { text: t.keylessFirstHint, children: t.keylessFirstLabel }),
|
|
4277
3839
|
],
|
|
4278
3840
|
}),
|
|
4279
|
-
react_jsx_runtime.jsxs("label", {
|
|
4280
|
-
className: "dshfs-platform",
|
|
4281
|
-
children: [
|
|
4282
|
-
react_jsx_runtime.jsx("input", {
|
|
4283
|
-
type: "checkbox",
|
|
4284
|
-
checked: activityPanel,
|
|
4285
|
-
disabled: !ready || saving,
|
|
4286
|
-
onChange: (e) => {
|
|
4287
|
-
setActivityPanel(e.target.checked);
|
|
4288
|
-
setDirty(true);
|
|
4289
|
-
setFailed(false);
|
|
4290
|
-
setSaveError("");
|
|
4291
|
-
},
|
|
4292
|
-
}),
|
|
4293
|
-
react_jsx_runtime.jsx(HintCard, { text: t.activityPanelHint, children: t.activityPanelLabel }),
|
|
4294
|
-
],
|
|
4295
|
-
}),
|
|
4296
3841
|
],
|
|
4297
3842
|
}),
|
|
4298
3843
|
],
|
|
@@ -4619,87 +4164,6 @@ react_jsx_runtime.jsxs("div", {
|
|
|
4619
4164
|
: react_jsx_runtime.jsx(FreeSearchCard, { page: true })
|
|
4620
4165
|
)
|
|
4621
4166
|
);
|
|
4622
|
-
// #144:右侧栏面板。宿主 0.2.2-rc.1+ 才有 sidebarRightTabs / sidebarRight,
|
|
4623
|
-
// 旧宿主上这两个服务不存在——必须整体跳过,不能让插件因为缺服务而失败。
|
|
4624
|
-
const ACTIVITY_TAB_ID = "dsh-free-search-activity";
|
|
4625
|
-
const ACTIVITY_TAB_KIND = "free-search-activity";
|
|
4626
|
-
let activitySeatReady = false;
|
|
4627
|
-
let activityDispose = null;
|
|
4628
|
-
// 只有 ctx.inject 回调里的子上下文才有权访问 sidebarRightTabs;
|
|
4629
|
-
// 在根 ctx 上读这个属性会直接抛 "without inject"。
|
|
4630
|
-
let activityCtx = null;
|
|
4631
|
-
const mountActivity = () => {
|
|
4632
|
-
if (!activitySeatReady || activityDispose !== null) return;
|
|
4633
|
-
const owner = activityCtx;
|
|
4634
|
-
if (owner === null) return;
|
|
4635
|
-
// 夹具/旧宿主可能注入了座位但没有服务实体:没有 register 就整体跳过。
|
|
4636
|
-
if (typeof owner.sidebarRightTabs?.register !== "function") return;
|
|
4637
|
-
const disposeType = ctx.effect(
|
|
4638
|
-
() => owner.sidebarRightTabs.register({
|
|
4639
|
-
id: ACTIVITY_TAB_ID,
|
|
4640
|
-
kind: ACTIVITY_TAB_KIND,
|
|
4641
|
-
priority: "extension",
|
|
4642
|
-
title: () => activityText(getUiLocale()).title,
|
|
4643
|
-
guide: [{
|
|
4644
|
-
id: "activity",
|
|
4645
|
-
commandId: "free-search.activity",
|
|
4646
|
-
order: 20,
|
|
4647
|
-
title: () => activityText(getUiLocale()).guide,
|
|
4648
|
-
description: () => activityText(getUiLocale()).guideDesc,
|
|
4649
|
-
}],
|
|
4650
|
-
}),
|
|
4651
|
-
"free-search: activity tab type"
|
|
4652
|
-
);
|
|
4653
|
-
const bodyDispose = ctx.slots.inject("sidebar.right.pane.tab", () =>
|
|
4654
|
-
ctx.slots.register(
|
|
4655
|
-
{ name: "sidebar.right.pane.tab", key: ACTIVITY_TAB_ID },
|
|
4656
|
-
ActivityBody
|
|
4657
|
-
)
|
|
4658
|
-
);
|
|
4659
|
-
const titleDispose = ctx.slots.inject("sidebar.right.pane.tab.title", () =>
|
|
4660
|
-
ctx.slots.register(
|
|
4661
|
-
{ name: "sidebar.right.pane.tab.title", key: ACTIVITY_TAB_ID },
|
|
4662
|
-
ActivityTitle
|
|
4663
|
-
)
|
|
4664
|
-
);
|
|
4665
|
-
activityDispose = () => {
|
|
4666
|
-
titleDispose();
|
|
4667
|
-
bodyDispose();
|
|
4668
|
-
disposeType();
|
|
4669
|
-
};
|
|
4670
|
-
};
|
|
4671
|
-
const unmountActivity = () => {
|
|
4672
|
-
if (activityDispose === null) return;
|
|
4673
|
-
activityDispose();
|
|
4674
|
-
activityDispose = null;
|
|
4675
|
-
};
|
|
4676
|
-
// 服务存在才挂:ctx.inject 里拿不到就跳过,不影响其它座位。
|
|
4677
|
-
try {
|
|
4678
|
-
ctx.inject(["sidebarRightTabs"], (sctx) => {
|
|
4679
|
-
sctx.effect(() => {
|
|
4680
|
-
activityCtx = sctx;
|
|
4681
|
-
activitySeatReady = true;
|
|
4682
|
-
initialSettings
|
|
4683
|
-
.then((result) => {
|
|
4684
|
-
const view = result?.ok ? result.value.namespaces.find((n) => n.ns === NS) : undefined;
|
|
4685
|
-
if (view?.value?.activityPanel !== false) mountActivity();
|
|
4686
|
-
})
|
|
4687
|
-
.catch(() => {});
|
|
4688
|
-
return () => {
|
|
4689
|
-
activitySeatReady = false;
|
|
4690
|
-
unmountActivity();
|
|
4691
|
-
if (activityCtx === sctx) activityCtx = null;
|
|
4692
|
-
};
|
|
4693
|
-
}, "free-search: activity panel");
|
|
4694
|
-
});
|
|
4695
|
-
activityPanelController = (enabled) => {
|
|
4696
|
-
if (!activitySeatReady) return;
|
|
4697
|
-
if (enabled !== false) mountActivity();
|
|
4698
|
-
else unmountActivity();
|
|
4699
|
-
};
|
|
4700
|
-
} catch {
|
|
4701
|
-
// 旧宿主:没有右侧栏服务,面板整体不出现。
|
|
4702
|
-
}
|
|
4703
4167
|
ctx.inject(["commandUi"], (sctx) => {
|
|
4704
4168
|
const command = sctx.get("commandUi");
|
|
4705
4169
|
sctx.effect(() => {
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
|
3
3
|
import z from "@deepseek-ai/schemastery";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
|
-
import { begin as activityBegin, runWith as activityRunWith, withToolScope as activityWithToolScope, noteCacheHit as activityNoteCacheHit, currentRun as activityCurrentRun, engineStart as activityEngineStart, engineEnd as activityEngineEnd, finish as activityFinish, snapshot as activitySnapshot, clear as activityClear, noteHook as activityNoteHook, noteMiss as activityNoteMiss, stats as activityStats } from "./activity.js";
|
|
7
6
|
import os from "node:os";
|
|
8
7
|
import path from "node:path";
|
|
9
8
|
import { exec, execFile } from "node:child_process";
|
|
@@ -1172,26 +1171,6 @@ function makeBridgeRoutes(settings, search, testEngine, getCredentials, getConfi
|
|
|
1172
1171
|
writeJson(res, 200, await handlers.rawSearch(body));
|
|
1173
1172
|
},
|
|
1174
1173
|
},
|
|
1175
|
-
// #144:右侧栏「搜索动态」面板的数据面。
|
|
1176
|
-
{
|
|
1177
|
-
kind: "exact",
|
|
1178
|
-
path: `${BRIDGE_PREFIX}/activity`,
|
|
1179
|
-
handler: async (req, res) => {
|
|
1180
|
-
if (!guard(req, res)) return;
|
|
1181
|
-
const body = await readJsonBody(req);
|
|
1182
|
-
writeJson(res, 200, { ok: true, value: { ...activitySnapshot(body?.sessionId ?? ""), stats: activityStats(body?.sessionId ?? "") } });
|
|
1183
|
-
},
|
|
1184
|
-
},
|
|
1185
|
-
{
|
|
1186
|
-
kind: "exact",
|
|
1187
|
-
path: `${BRIDGE_PREFIX}/activity-clear`,
|
|
1188
|
-
handler: async (req, res) => {
|
|
1189
|
-
if (!guard(req, res)) return;
|
|
1190
|
-
const body = await readJsonBody(req);
|
|
1191
|
-
activityClear(body?.sessionId ?? "");
|
|
1192
|
-
writeJson(res, 200, { ok: true, value: { cleared: true } });
|
|
1193
|
-
},
|
|
1194
|
-
},
|
|
1195
1174
|
];
|
|
1196
1175
|
}
|
|
1197
1176
|
//#endregion
|
|
@@ -1336,8 +1315,6 @@ const Config = z.object({
|
|
|
1336
1315
|
slashCommands: z.boolean().default(true).volatile(),
|
|
1337
1316
|
// 默认 false:配了 key 的引擎一律用 key。开启后先走免 key 档,免 key 档限流/额度/鉴权/网络失败时才改用 key,省 key 的额度。
|
|
1338
1317
|
keylessFirst: z.boolean().default(false).volatile(),
|
|
1339
|
-
// #144:右侧栏「搜索动态」面板。默认开启;关掉后侧栏「更多工具」里的入口消失。
|
|
1340
|
-
activityPanel: z.boolean().default(true).volatile(),
|
|
1341
1318
|
disabledEngines: z.array(z.string()).default([]).volatile(),
|
|
1342
1319
|
// #106:白名单。非空时只有这些引擎可用(等于把其余引擎全部禁用),默认空 = 不限制。
|
|
1343
1320
|
allowedEngines: z.array(z.string()).default([]).volatile(),
|
|
@@ -2152,32 +2129,21 @@ function apply(ctx, config) {
|
|
|
2152
2129
|
async search(request, signal) {
|
|
2153
2130
|
// #108: every result and error leaving the provider must be valid Unicode —
|
|
2154
2131
|
// a lone surrogate in the history rejects every later request upstream.
|
|
2155
|
-
const activity = activityBegin({
|
|
2156
|
-
query: request?.query,
|
|
2157
|
-
engine: request?.engine,
|
|
2158
|
-
timeRange: request?.timeRange,
|
|
2159
|
-
sessionId: undefined,
|
|
2160
|
-
});
|
|
2161
2132
|
try {
|
|
2162
2133
|
// 轮换时机:首次失败后 keyRings 已经填充,此时再判断有几把 key。
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
logger.warn(`free-search: retrying with the next API key (${error?.message ?? error})`);
|
|
2173
|
-
}
|
|
2134
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
2135
|
+
try {
|
|
2136
|
+
const safe = sanitizeSearchResult(await provider.searchOnce(request, signal));
|
|
2137
|
+
if (Array.isArray(safe.sources)) safe.sources = dedupeNearDuplicates(safe.sources);
|
|
2138
|
+
return safe;
|
|
2139
|
+
} catch (error) {
|
|
2140
|
+
const keys = maxKeyRingLength();
|
|
2141
|
+
if (keys <= 1 || attempt >= keys - 1 || !isKeyRotationCandidate(error)) throw error;
|
|
2142
|
+
logger.warn(`free-search: retrying with the next API key (${error?.message ?? error})`);
|
|
2174
2143
|
}
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
activityFinish(activity, { result });
|
|
2178
|
-
return result;
|
|
2144
|
+
}
|
|
2145
|
+
throw new Error("all search engines failed");
|
|
2179
2146
|
} catch (error) {
|
|
2180
|
-
activityFinish(activity, { error });
|
|
2181
2147
|
throw sanitizeError(error);
|
|
2182
2148
|
}
|
|
2183
2149
|
},
|
|
@@ -2223,9 +2189,6 @@ function apply(ctx, config) {
|
|
|
2223
2189
|
if (signal?.aborted) throw new Error("search aborted");
|
|
2224
2190
|
searchCache.delete(cacheKey);
|
|
2225
2191
|
searchCache.set(cacheKey, hit);
|
|
2226
|
-
// #144:缓存命中不进引擎循环,用缓存里保存的 provider 补一条引擎记录,
|
|
2227
|
-
// 否则面板只能显示「引擎 暂无」。
|
|
2228
|
-
activityNoteCacheHit(activity, hit.value?.provider ?? hit.value?.engine, hit.value?.sources?.length ?? 0);
|
|
2229
2192
|
// #72:缓存命中同样过一遍黑名单——首版修复前写入的缓存里可能残留屏蔽域名
|
|
2230
2193
|
return { ...applyBlockedFilterToResult({ ...hit.value, sources: hit.value.sources?.slice() }), _cache: "hit" };
|
|
2231
2194
|
}
|
|
@@ -2322,8 +2285,6 @@ function apply(ctx, config) {
|
|
|
2322
2285
|
}
|
|
2323
2286
|
// 组合外部取消 signal + 剩余预算超时:官方 web_search 取消、引擎超时、总预算都能触发
|
|
2324
2287
|
const effSignal = AbortSignal.any([...(signal !== undefined ? [signal] : []), AbortSignal.timeout(remaining)]);
|
|
2325
|
-
const act = activityCurrentRun();
|
|
2326
|
-
if (act) activityEngineStart(act, engine);
|
|
2327
2288
|
try {
|
|
2328
2289
|
let result;
|
|
2329
2290
|
const runner = engineRunners[engine];
|
|
@@ -2348,12 +2309,10 @@ function apply(ctx, config) {
|
|
|
2348
2309
|
if (error instanceof EngineSkip) {
|
|
2349
2310
|
lastError = error;
|
|
2350
2311
|
if (engine === preferred) preferredFailure = error.preferredMessage;
|
|
2351
|
-
if (act) activityEngineEnd(act, engine, { skipped: true, error });
|
|
2352
2312
|
logger.warn(`free-search: engine "${engine}" skipped (${error.message}), trying next engine`);
|
|
2353
2313
|
continue;
|
|
2354
2314
|
}
|
|
2355
2315
|
engineRuntime.record(engine, { ms: Date.now() - startedAt, error: classifyFailure(error) });
|
|
2356
|
-
if (act) activityEngineEnd(act, engine, { error });
|
|
2357
2316
|
throw error;
|
|
2358
2317
|
}
|
|
2359
2318
|
|
|
@@ -2366,7 +2325,6 @@ function apply(ctx, config) {
|
|
|
2366
2325
|
if (result.sources.length > 0) {
|
|
2367
2326
|
usedEngine = engine;
|
|
2368
2327
|
clearCooldown(engine);
|
|
2369
|
-
if (act) activityEngineEnd(act, engine, { count: result.sources.length });
|
|
2370
2328
|
// 统一清洗 snippet:去登录/付费墙/订阅噪音,折叠空白(有值的才处理,保持 lossless JSON)
|
|
2371
2329
|
result.sources = result.sources.map((s) =>
|
|
2372
2330
|
s.snippet ? { ...s, snippet: cleanSnippet(s.snippet, snippetCap(engine)) } : s
|
|
@@ -2403,7 +2361,6 @@ function apply(ctx, config) {
|
|
|
2403
2361
|
return { ...cached, _cache: "miss" };
|
|
2404
2362
|
}
|
|
2405
2363
|
lastError = new Error(`engine "${engine}" returned 0 results`);
|
|
2406
|
-
if (act) activityEngineEnd(act, engine, { count: 0 });
|
|
2407
2364
|
if (engine === preferred) { preferredFailure = "returned 0 results"; preferredFailureClass = "invalid-response"; }
|
|
2408
2365
|
if (!fallbackOnSet.has("invalid-response")) {
|
|
2409
2366
|
blockedFailure = { engine, failure: { class: "invalid-response", message: "returned 0 results" } };
|
|
@@ -3250,8 +3207,8 @@ function apply(ctx, config) {
|
|
|
3250
3207
|
...failedEngines,
|
|
3251
3208
|
...enginesEmpty.map((engine) => `${engine} (returned 0 results)`),
|
|
3252
3209
|
...skipped.map((engine) => `${engine} (no key)`),
|
|
3253
|
-
]
|
|
3254
|
-
throw new Error(`multi search failed: ${details || "no engine returned results"}`);
|
|
3210
|
+
];
|
|
3211
|
+
throw new Error(`multi search failed: ${details.join("; ") || "no engine returned results"}`);
|
|
3255
3212
|
}
|
|
3256
3213
|
|
|
3257
3214
|
const notes = [];
|
|
@@ -3272,80 +3229,7 @@ function apply(ctx, config) {
|
|
|
3272
3229
|
};
|
|
3273
3230
|
};
|
|
3274
3231
|
|
|
3275
|
-
/**
|
|
3276
|
-
* 读当前会话的轮次。
|
|
3277
|
-
*
|
|
3278
|
-
* 宿主把投影放在 `ctx.sessionProjections` 服务上(stateOf(session, key)),
|
|
3279
|
-
* turnBoundary 投影的 lastTurn 就是当前对话轮次。
|
|
3280
|
-
* 这个服务由 dsh-agent 注入并注册 turnBoundary,所以插件这里只能可选访问:
|
|
3281
|
-
* 取不到就返回 0,面板据此不显示轮次,而不是崩掉。
|
|
3282
|
-
*/
|
|
3283
|
-
let projectionsFace = null;
|
|
3284
|
-
ctx.inject(["sessionProjections"], (sctx) => {
|
|
3285
|
-
sctx.effect(() => {
|
|
3286
|
-
try {
|
|
3287
|
-
projectionsFace = sctx.get("sessionProjections");
|
|
3288
|
-
} catch {
|
|
3289
|
-
projectionsFace = null;
|
|
3290
|
-
}
|
|
3291
|
-
return () => {
|
|
3292
|
-
projectionsFace = null;
|
|
3293
|
-
};
|
|
3294
|
-
}, "free-search: turn boundary projection");
|
|
3295
|
-
});
|
|
3296
|
-
|
|
3297
|
-
const activityTurnBoundary = (agent) => {
|
|
3298
|
-
try {
|
|
3299
|
-
const session = agent?.session;
|
|
3300
|
-
if (session === undefined || session === null) return null;
|
|
3301
|
-
if (projectionsFace === null) return null;
|
|
3302
|
-
const state = projectionsFace.stateOf(session, "turnBoundary");
|
|
3303
|
-
return state === undefined ? null : state;
|
|
3304
|
-
} catch {
|
|
3305
|
-
return null;
|
|
3306
|
-
}
|
|
3307
|
-
};
|
|
3308
|
-
|
|
3309
3232
|
ctx.inject(["tools"], (sctx) => {
|
|
3310
|
-
// #144:给每次工具分发套一层会话归属,搜索链内部任何 await 之后都还知道
|
|
3311
|
-
// 「这次是哪个会话触发的搜索」。宿主的 web_search 也走 ctx.web.search,
|
|
3312
|
-
// 一样会落进这个上下文,所以面板能按会话取到自己的记录。
|
|
3313
|
-
sctx.effect(
|
|
3314
|
-
() =>
|
|
3315
|
-
sctx.on("tools/execute", (exec, next) => {
|
|
3316
|
-
activityNoteHook();
|
|
3317
|
-
// 宿主的 Agent 只公开 `id`(就是 SessionId),没有 `sessionId` 字段。
|
|
3318
|
-
// 这里两个都认,避免某一版宿主改了字段名之后记录全部变成无归属。
|
|
3319
|
-
const agent = exec?.agent;
|
|
3320
|
-
// 取值优先级:sessionId > id > session.id。宿主不同版本把会话身份放在不同位置,
|
|
3321
|
-
// 早期只读 sessionId 时永远取不到,记录全部无归属,面板因此跨会话显示。
|
|
3322
|
-
const pick = () => {
|
|
3323
|
-
if (typeof agent?.sessionId === "string" && agent.sessionId !== "") return agent.sessionId;
|
|
3324
|
-
if (typeof agent?.id === "string" && agent.id !== "") return agent.id;
|
|
3325
|
-
const inner = agent?.session;
|
|
3326
|
-
if (typeof inner?.id === "string" && inner.id !== "") return inner.id;
|
|
3327
|
-
return "";
|
|
3328
|
-
};
|
|
3329
|
-
const sessionId = pick();
|
|
3330
|
-
// 轮次:宿主的 turnBoundary 投影给出 lastTurn。取不到就是 0,
|
|
3331
|
-
// 面板据此决定要不要显示「第 N 轮」。
|
|
3332
|
-
const turn = (() => {
|
|
3333
|
-
try {
|
|
3334
|
-
const boundary = activityTurnBoundary(agent);
|
|
3335
|
-
return Number(boundary?.lastTurn) || 0;
|
|
3336
|
-
} catch {
|
|
3337
|
-
return 0;
|
|
3338
|
-
}
|
|
3339
|
-
})();
|
|
3340
|
-
if (sessionId === "") {
|
|
3341
|
-
// 只在第一次取不到时记一条,避免每个工具调用都刷日志。
|
|
3342
|
-
activityNoteMiss(exec);
|
|
3343
|
-
return next();
|
|
3344
|
-
}
|
|
3345
|
-
return activityWithToolScope({ sessionId, turn }, () => next());
|
|
3346
|
-
}),
|
|
3347
|
-
"free-search: activity session scope"
|
|
3348
|
-
);
|
|
3349
3233
|
localizedEffect(sctx, {
|
|
3350
3234
|
label: "free-search: test engines tool",
|
|
3351
3235
|
ns: FREE_SEARCH_NS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-free-search",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.84",
|
|
4
4
|
"description": "Free web search for DeepSeek Harness: 42 engines (Bing/DuckDuckGo/AnySearch/SearXNG/Exa/Tavily/Keenable/Firecrawl/Parallel/Brave/Zhipu/You.com keyless; Zhihu global/site via MCP and Perplexity/SerpBase/DeepSeek (official + native tools/search)/Baidu/Kimi/Aliyun/Doubao/Google CSE/Metaso/Yandex/Yuanbao/SpecStream 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, plus a standalone stdio MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -76,8 +76,7 @@
|
|
|
76
76
|
"@deepseek-ai/dsh-settings": "^0.1.7-rc.1 || ^0.2.0-rc.1 || ^0.3.0-0",
|
|
77
77
|
"@deepseek-ai/dsh-tools": "^0.1.7-rc.1 || ^0.2.0-rc.1 || ^0.3.0-0",
|
|
78
78
|
"@deepseek-ai/schemastery": ">=3.18.4 <4",
|
|
79
|
-
"react": "^18.2.0"
|
|
80
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right": "^0.1.7-rc.1 || ^0.2.0-rc.1 || ^0.3.0-0"
|
|
79
|
+
"react": "^18.2.0"
|
|
81
80
|
},
|
|
82
81
|
"peerDependenciesMeta": {
|
|
83
82
|
"@deepseek-ai/cordis": {
|
|
@@ -103,9 +102,6 @@
|
|
|
103
102
|
},
|
|
104
103
|
"react": {
|
|
105
104
|
"optional": true
|
|
106
|
-
},
|
|
107
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right": {
|
|
108
|
-
"optional": true
|
|
109
105
|
}
|
|
110
106
|
},
|
|
111
107
|
"devDependencies": {
|
|
@@ -123,8 +119,7 @@
|
|
|
123
119
|
"inject": [
|
|
124
120
|
"@deepseek-ai/dsh-client-ui-commands",
|
|
125
121
|
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
126
|
-
"@deepseek-ai/dsh-client-ui-renderer"
|
|
127
|
-
"@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
122
|
+
"@deepseek-ai/dsh-client-ui-renderer"
|
|
128
123
|
],
|
|
129
124
|
"platform": "web"
|
|
130
125
|
},
|
package/lib/activity.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
// #144:搜索动态面板的数据面。
|
|
2
|
-
//
|
|
3
|
-
// 宿主的 tools/execute 是「分发前后」的 waterfall,可以把整个工具执行体包在
|
|
4
|
-
// 一个 AsyncLocalStorage 里,于是搜索链内部任何 await 之后都还知道「这次是哪个
|
|
5
|
-
// 会话调用的」。这比给 provider.search 传参更可靠:宿主自己的 web_search 也走
|
|
6
|
-
// ctx.web.search,同样会落进这个上下文。
|
|
7
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
-
|
|
9
|
-
const HISTORY_MAX = 50;
|
|
10
|
-
const SOURCES_MAX = 8;
|
|
11
|
-
const ENGINES_MAX = 48;
|
|
12
|
-
|
|
13
|
-
const storage = new AsyncLocalStorage();
|
|
14
|
-
const runStorage = new AsyncLocalStorage();
|
|
15
|
-
|
|
16
|
-
let seq = 0;
|
|
17
|
-
let history = [];
|
|
18
|
-
let inflight = [];
|
|
19
|
-
// 临时诊断:面板空着时需要能分清「钩子没触发」和「钩子触发但记录丢了」。
|
|
20
|
-
let sawHook = 0;
|
|
21
|
-
let began = 0;
|
|
22
|
-
let finished = 0;
|
|
23
|
-
let engineCalls = 0;
|
|
24
|
-
let engineDropped = 0;
|
|
25
|
-
|
|
26
|
-
/** 在给定的会话上下文里执行 fn;sessionId 为空时也照样执行,只是不带归属。 */
|
|
27
|
-
export function withSession(sessionId, fn) {
|
|
28
|
-
return storage.run({ sessionId: String(sessionId ?? "") }, fn);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 当前异步上下文里的会话 id(没有则为空串)。 */
|
|
32
|
-
export function ctxSession() {
|
|
33
|
-
return runStorage.getStore()?.sessionId ?? "";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** 当前异步上下文里的对话轮次(0 = 未知)。 */
|
|
37
|
-
export function ctxTurn() {
|
|
38
|
-
return Number(runStorage.getStore()?.turn) || 0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** 当前异步上下文里正在进行的搜索(没有则为 undefined)。 */
|
|
42
|
-
export function currentRun() {
|
|
43
|
-
return runStorage.getStore();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const now = () => Date.now();
|
|
47
|
-
|
|
48
|
-
function hostOf(url) {
|
|
49
|
-
try {
|
|
50
|
-
return new URL(String(url ?? "")).host || "";
|
|
51
|
-
} catch {
|
|
52
|
-
return "";
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function trimSources(sources) {
|
|
57
|
-
if (!Array.isArray(sources)) return [];
|
|
58
|
-
const out = [];
|
|
59
|
-
for (const source of sources) {
|
|
60
|
-
if (out.length >= SOURCES_MAX) break;
|
|
61
|
-
const url = String(source?.url ?? "");
|
|
62
|
-
const title = String(source?.title ?? "").trim() || url;
|
|
63
|
-
out.push({ title, url, host: hostOf(url) });
|
|
64
|
-
}
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 开始一次搜索。返回的句柄在结束时要交给 finish()。 */
|
|
69
|
-
export function begin({ query, engine, mode, timeRange, sessionId, turn } = {}) {
|
|
70
|
-
const run = {
|
|
71
|
-
id: `a${(seq += 1)}`,
|
|
72
|
-
// 归属:显式传入 > 工具分发上下文里的会话 > 空(全局视图)。
|
|
73
|
-
sessionId: String(sessionId ?? ctxSession() ?? ""),
|
|
74
|
-
// 轮次:同一次对话里第几轮。拿不到就是 0,面板据此决定要不要显示。
|
|
75
|
-
turn: Number.isFinite(Number(turn)) && Number(turn) > 0 ? Number(turn) : ctxTurn(),
|
|
76
|
-
query: String(query ?? "").slice(0, 400),
|
|
77
|
-
mode: String(mode ?? ""),
|
|
78
|
-
timeRange: String(timeRange ?? ""),
|
|
79
|
-
startedAt: now(),
|
|
80
|
-
currentEngine: "",
|
|
81
|
-
engines: [],
|
|
82
|
-
sources: [],
|
|
83
|
-
totalResults: 0,
|
|
84
|
-
};
|
|
85
|
-
inflight.push(run);
|
|
86
|
-
began += 1;
|
|
87
|
-
activeRun = run;
|
|
88
|
-
return run;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** 把一次搜索放进异步上下文里跑,让内部各层都能拿到它。 */
|
|
92
|
-
export function runWith(run, fn) {
|
|
93
|
-
return runStorage.run(run, fn);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** 把工具分发上下文(会话 + 轮次)套在工具体上。 */
|
|
97
|
-
export function withToolScope(scope, fn) {
|
|
98
|
-
const sessionId = String(scope?.sessionId ?? "");
|
|
99
|
-
const turn = Number(scope?.turn) || 0;
|
|
100
|
-
return runStorage.run({ sessionId, turn }, fn);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** 工具分发钩子被调用的次数(诊断用)。 */
|
|
104
|
-
export function noteHook() {
|
|
105
|
-
sawHook += 1;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** 诊断:记录一次「钩子拿到了 agent 但取不出会话 id」的形状,只留首个样本。 */
|
|
109
|
-
let missShape = null;
|
|
110
|
-
export function noteMiss(exec) {
|
|
111
|
-
if (missShape !== null) return;
|
|
112
|
-
const agent = exec?.agent;
|
|
113
|
-
const shape = agent === undefined
|
|
114
|
-
? "agent: undefined"
|
|
115
|
-
: [
|
|
116
|
-
"keys=" + Object.keys(agent).join(","),
|
|
117
|
-
"typeof id=" + typeof agent.id,
|
|
118
|
-
"idValue=" + JSON.stringify(agent.id ?? null).slice(0, 40),
|
|
119
|
-
"has session=" + (agent.session !== undefined),
|
|
120
|
-
"session keys=" + (agent.session === undefined ? "-" : Object.keys(agent.session).join(",")),
|
|
121
|
-
].join(" ");
|
|
122
|
-
missShape = shape;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 诊断快照。
|
|
127
|
-
*
|
|
128
|
-
* 关键的一对是 sessionHistory / history:只给全局总数看不出隔离是否生效,
|
|
129
|
-
* 面板到底读到的是「本会话的记录」还是「全库的记录」必须并排显示。
|
|
130
|
-
*/
|
|
131
|
-
export function stats(sessionId = "") {
|
|
132
|
-
const key = String(sessionId ?? "");
|
|
133
|
-
const owns = (entry) => key === "" || entry.sessionId === key;
|
|
134
|
-
return {
|
|
135
|
-
sawHook,
|
|
136
|
-
began,
|
|
137
|
-
finished,
|
|
138
|
-
history: history.length,
|
|
139
|
-
inflight: inflight.length,
|
|
140
|
-
sessionHistory: history.filter(owns).length,
|
|
141
|
-
sessionInflight: inflight.filter(owns).length,
|
|
142
|
-
attributed: history.some((entry) => entry.sessionId !== ""),
|
|
143
|
-
engineCalls,
|
|
144
|
-
engineDropped,
|
|
145
|
-
missShape,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function findEngine(run, engine) {
|
|
150
|
-
return run.engines.find((entry) => entry.id === engine && entry.status === "running");
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 模块级「当前 run」。
|
|
155
|
-
*
|
|
156
|
-
* 引擎事件不能只靠 AsyncLocalStorage:engineRuntime.run() 是一个并发限流器,
|
|
157
|
-
* 它把回调排进队列后,执行时的异步上下文已经换掉了,ALS 里取不到 run,
|
|
158
|
-
* 于是 engineStart/engineEnd 被静默丢弃(面板只剩「引擎 暂无」)。
|
|
159
|
-
* 这里留一个模块级引用兜底:begin 时记下,finish 时清掉。
|
|
160
|
-
*/
|
|
161
|
-
let activeRun = null;
|
|
162
|
-
|
|
163
|
-
/** 标记某个引擎开始尝试。 */
|
|
164
|
-
export function engineStart(run, engine) {
|
|
165
|
-
engineCalls += 1;
|
|
166
|
-
const target = run ?? activeRun;
|
|
167
|
-
if (!target || !engine) { engineDropped += 1; return; }
|
|
168
|
-
target.currentEngine = engine;
|
|
169
|
-
if (target.engines.length >= ENGINES_MAX) return;
|
|
170
|
-
target.engines.push({ id: String(engine), status: "running", count: 0, startedAt: now() });
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** 结束某个引擎的尝试:count>0 为成功,error 表示失败,skipped 表示跳过。 */
|
|
174
|
-
export function engineEnd(run, engine, { count = 0, error, skipped } = {}) {
|
|
175
|
-
const target = run ?? activeRun;
|
|
176
|
-
if (!target || !engine) { engineDropped += 1; return; }
|
|
177
|
-
const entry = findEngine(target, engine);
|
|
178
|
-
if (!entry) return;
|
|
179
|
-
entry.count = Number(count) || 0;
|
|
180
|
-
entry.ms = Math.max(0, now() - (entry.startedAt ?? now()));
|
|
181
|
-
entry.status = skipped ? "skipped" : entry.count > 0 ? "ok" : "failed";
|
|
182
|
-
if (entry.status === "failed") entry.failureClass = failureClassOf(error);
|
|
183
|
-
if (entry.status === "skipped") entry.skipReason = skipReasonOf(error);
|
|
184
|
-
target.currentEngine = "";
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function failureClassOf(error) {
|
|
188
|
-
const message = String(error?.message ?? error ?? "").toLowerCase();
|
|
189
|
-
if (error?.class) return String(error.class);
|
|
190
|
-
if (/\b429\b|rate limit|too many requests/.test(message)) return "quota";
|
|
191
|
-
if (/\b40[13]\b|unauthorized|invalid api key/.test(message)) return "auth";
|
|
192
|
-
if (/403|captcha|bot|blocked/.test(message)) return "bot-wall";
|
|
193
|
-
if (/timeout|econnreset|enotfound|network|fetch failed/.test(message)) return "transient";
|
|
194
|
-
if (/0 results|parse|invalid/.test(message)) return "invalid-response";
|
|
195
|
-
return "unknown";
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function skipReasonOf(error) {
|
|
199
|
-
const message = String(error?.message ?? error ?? "").toLowerCase();
|
|
200
|
-
if (/time/.test(message)) return "time-filter";
|
|
201
|
-
if (/key|credential/.test(message)) return "no-key";
|
|
202
|
-
if (/disabled/.test(message)) return "disabled";
|
|
203
|
-
return "skipped";
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** 结束一次搜索。result 为成功结果,error 为失败。 */
|
|
207
|
-
export function finish(run, { result, error } = {}) {
|
|
208
|
-
if (!run) return;
|
|
209
|
-
inflight = inflight.filter((entry) => entry !== run);
|
|
210
|
-
if (activeRun === run) activeRun = null;
|
|
211
|
-
finished += 1;
|
|
212
|
-
|
|
213
|
-
// 缓存命中的引擎记录由 noteCacheHit 在命中点写入(那里能拿到缓存里的
|
|
214
|
-
// provider)。这里只兜底:如果命中路径没记上,至少别让引擎栏空着。
|
|
215
|
-
if (result?._cache === "hit" && run.engines.length === 0) {
|
|
216
|
-
noteCacheHit(run, result?.provider ?? result?.engine, Array.isArray(result?.sources) ? result.sources.length : 0);
|
|
217
|
-
}
|
|
218
|
-
const endedAt = now();
|
|
219
|
-
const record = {
|
|
220
|
-
id: run.id,
|
|
221
|
-
sessionId: run.sessionId,
|
|
222
|
-
query: run.query,
|
|
223
|
-
mode: run.mode,
|
|
224
|
-
timeRange: run.timeRange,
|
|
225
|
-
turn: run.turn ?? 0,
|
|
226
|
-
startedAt: run.startedAt,
|
|
227
|
-
endedAt,
|
|
228
|
-
ms: endedAt - run.startedAt,
|
|
229
|
-
ok: !error,
|
|
230
|
-
engines: run.engines.map(({ id, status, count, ms, failureClass, skipReason, cached }) => ({
|
|
231
|
-
id,
|
|
232
|
-
status,
|
|
233
|
-
count,
|
|
234
|
-
ms: Math.max(0, ms ?? 0),
|
|
235
|
-
...(failureClass === undefined ? {} : { failureClass }),
|
|
236
|
-
...(skipReason === undefined ? {} : { skipReason }),
|
|
237
|
-
...(cached === true ? { cached: true } : {}),
|
|
238
|
-
})),
|
|
239
|
-
sources: trimSources(result?.sources),
|
|
240
|
-
totalResults: Array.isArray(result?.sources) ? result.sources.length : 0,
|
|
241
|
-
cache: result?._cache === "hit" ? "hit" : "miss",
|
|
242
|
-
...(error === undefined ? {} : { error: String(error?.message ?? error).slice(0, 300) }),
|
|
243
|
-
};
|
|
244
|
-
history.unshift(record);
|
|
245
|
-
if (history.length > HISTORY_MAX) history = history.slice(0, HISTORY_MAX);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* 记一次缓存命中。
|
|
250
|
-
*
|
|
251
|
-
* 缓存命中会从 provider.search 的早退分支直接返回,根本不进引擎循环,
|
|
252
|
-
* 于是 run.engines 是空的,面板只能显示「引擎 暂无」。
|
|
253
|
-
* 缓存条目里保存着当时的 provider(= 真正跑出这批结果的引擎),用它补一条。
|
|
254
|
-
*/
|
|
255
|
-
export function noteCacheHit(run, engine, count) {
|
|
256
|
-
const id = String(engine ?? "").trim() || "cache";
|
|
257
|
-
const target = run ?? activeRun;
|
|
258
|
-
if (!target) return;
|
|
259
|
-
// 已经有同样一条就不再重复(同一引擎命中两次缓存的情况)。
|
|
260
|
-
const existing = target.engines.find((entry) => entry.id === id && entry.cached === true);
|
|
261
|
-
if (existing !== undefined) {
|
|
262
|
-
existing.count = Number(count) || existing.count;
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
target.engines.push({
|
|
266
|
-
id,
|
|
267
|
-
status: "ok",
|
|
268
|
-
count: Number(count) || 0,
|
|
269
|
-
startedAt: target.startedAt,
|
|
270
|
-
ms: 0,
|
|
271
|
-
cached: true,
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/** 某个会话的快照:进行中的条目 + 最近一次完成 + 历史。 */
|
|
276
|
-
export function snapshot(sessionId = "") {
|
|
277
|
-
const key = String(sessionId ?? "");
|
|
278
|
-
const owns = (entry) => key === "" || entry.sessionId === key;
|
|
279
|
-
const current = inflight.filter(owns).map((run) => ({
|
|
280
|
-
id: run.id,
|
|
281
|
-
query: run.query,
|
|
282
|
-
turn: run.turn ?? 0,
|
|
283
|
-
currentEngine: run.currentEngine,
|
|
284
|
-
enginesDone: run.engines.filter((entry) => entry.status !== "running").length,
|
|
285
|
-
enginesTotal: Math.max(run.engines.length, run.enginesDone),
|
|
286
|
-
engines: run.engines.map(({ id, status, count }) => ({ id, status, count })),
|
|
287
|
-
startedAt: run.startedAt,
|
|
288
|
-
ms: now() - run.startedAt,
|
|
289
|
-
}));
|
|
290
|
-
const forSession = history.filter(owns);
|
|
291
|
-
// 归因兜底:如果这条会话名下一条都没有,而全库记录也全都没带会话 id
|
|
292
|
-
// (宿主没给 agent 身份的情形),就让面板显示这些记录,否则面板永远是空的。
|
|
293
|
-
// 只要有任何记录带了别的会话 id,就不越权显示。
|
|
294
|
-
const unattributed = history.every((entry) => entry.sessionId === "");
|
|
295
|
-
const visible = forSession.length > 0 || key === "" || !unattributed ? forSession : history;
|
|
296
|
-
// 同一份兜底也要用在 in-flight 上,否则「进行中」那一块永远是空的。
|
|
297
|
-
const currentVisible = !unattributed || key === "" || current.length > 0
|
|
298
|
-
? current
|
|
299
|
-
: inflight.map((run) => ({
|
|
300
|
-
id: run.id,
|
|
301
|
-
query: run.query,
|
|
302
|
-
currentEngine: run.currentEngine,
|
|
303
|
-
enginesDone: run.engines.filter((entry) => entry.status !== "running").length,
|
|
304
|
-
enginesTotal: Math.max(run.engines.length, run.enginesDone),
|
|
305
|
-
engines: run.engines.map(({ id, status, count }) => ({ id, status, count })),
|
|
306
|
-
startedAt: run.startedAt,
|
|
307
|
-
ms: now() - run.startedAt,
|
|
308
|
-
}));
|
|
309
|
-
return {
|
|
310
|
-
current: currentVisible,
|
|
311
|
-
latest: visible[0] ?? null,
|
|
312
|
-
history: visible.slice(0, HISTORY_MAX),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/** 清空记录(只影响内存)。 */
|
|
317
|
-
export function clear(sessionId = "") {
|
|
318
|
-
const key = String(sessionId ?? "");
|
|
319
|
-
if (key === "") {
|
|
320
|
-
history = [];
|
|
321
|
-
inflight = [];
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
history = history.filter((entry) => entry.sessionId !== key);
|
|
325
|
-
inflight = inflight.filter((entry) => entry.sessionId !== key);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/** 测试用:把模块状态恢复干净。 */
|
|
329
|
-
export function resetForTests() {
|
|
330
|
-
seq = 0;
|
|
331
|
-
activeRun = null;
|
|
332
|
-
engineCalls = 0;
|
|
333
|
-
engineDropped = 0;
|
|
334
|
-
history = [];
|
|
335
|
-
inflight = [];
|
|
336
|
-
sawHook = 0;
|
|
337
|
-
began = 0;
|
|
338
|
-
finished = 0;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
export const ACTIVITY_LIMITS = { HISTORY_MAX, SOURCES_MAX, ENGINES_MAX };
|