@tnnevol/dsh-failover-search 0.2.1-rc.2.7 → 6.0.0

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 CHANGED
@@ -9,7 +9,7 @@ DSH 会话内网页搜索的多来源插件:按 **TinyFish → Tavily → 官
9
9
  插件随 `fn-deepseek-harness` 自动安装。其他 DSH 环境手动安装,要求 DSH `0.2.0-rc.2`:
10
10
 
11
11
  ```sh
12
- dsh plugin --profile web add @tnnevol/dsh-failover-search@0.2.1-rc.2.7
12
+ dsh plugin --profile web add @tnnevol/dsh-failover-search@6.0.0
13
13
  ```
14
14
 
15
15
  ## 这个包做什么
@@ -18,8 +18,17 @@ dsh plugin --profile web add @tnnevol/dsh-failover-search@0.2.1-rc.2.7
18
18
  - 平台顺序内遍历;同平台多账号按轮转分摊,账号失败或额度不足时先换同平台账号,再落到下一平台。
19
19
  - 用量快照(Tavily 账户用量、TinyFish 钱包,均为免费查询)驱动请求前探测,并在插件详情页展示。
20
20
  - 三方全不可用时沿用用户既有的官方凭据回落官方搜索。
21
+ - 网页抓取(`web_fetch`)同样接管:本地 HTTP 抓取为第一跳,本地失败且平台有账号时按 TinyFish Fetch → Tavily Extract 转取(平台侧取回,不受本机 DNS/代理影响)。
21
22
 
22
- 网页抓取(fetch)不在本包范围内,仍由官方抓取提供方承担。
23
+ ## 注意:官方「网络搜索」设置页会覆盖本插件
24
+
25
+ 本插件通过 `web` 行的 `searchProvider` / `fetchProvider` 接管搜索与抓取,而接缝是**固定选择**语义:配了哪个 provider id 就只用那个,其它 provider 即使注册成功也不会被走到。
26
+
27
+ 官方「设置 → 插件 → 内置插件设置 → 网络搜索」页保存时会把这两个键写成官方 id,于是插件虽然已加载、账号与用量都正常,网页工具却走官方端点(官方余额耗尽时直接返回 HTTP 402)。因此:
28
+
29
+ - **安装本插件前**先关掉官方的搜索/抓取通道,安装后不要再去那页保存;
30
+ - 已经被覆盖时,把消息框左下角的「智能搜索」开关**关闭再打开**即可写回本插件,无需重装;
31
+ - 也可以手改 profile 的 `cordis.patch.yml` 中 `- id: web` 的两个键(整行替换,必须一起写)后重启。
23
32
 
24
33
  ## 兼容性
25
34
 
@@ -4,7 +4,7 @@
4
4
  "node": "^22.19.0 || >=24.0.0"
5
5
  },
6
6
  "dshPluginApi": {
7
- "version": "0.2.1-rc.2",
7
+ "version": "0.2.1-rc.3",
8
8
  "packages": [
9
9
  "@deepseek-ai/dsh-agent",
10
10
  "@deepseek-ai/dsh-client-connection",
package/lib/index.d.ts CHANGED
@@ -448,6 +448,49 @@ declare class UsageStore {
448
448
  */
449
449
  declare function usageFingerprint(settings: FailoverSearchSettings): string;
450
450
  //#endregion
451
+ //#region src/host/web-selection.d.ts
452
+ /** settings 服务中本模块用到的一条配置条目(投影后的有效值)。 */
453
+ interface SettingsEntryLike {
454
+ /** profile 条目 id,即配置命名空间。 */
455
+ readonly ns: string;
456
+ /** 当前**生效**的配置值(已合并 bundle 层与覆盖层)。 */
457
+ readonly value: unknown;
458
+ }
459
+ /**
460
+ * settings 服务的最小可写面。
461
+ *
462
+ * 只声明用到的两个方法:本插件不 import 官方 settings 包的具体导出(服务访问型
463
+ * peer 依赖的既有约定),形状在这里收敛,避免把上层实现绑死。
464
+ */
465
+ interface SettingsFormsLike {
466
+ /** 列出可配置条目及其生效值。 */
467
+ describe: () => readonly SettingsEntryLike[];
468
+ /** 合并写入某条目的可编辑字段。 */
469
+ update: (ns: string, patch: Record<string, unknown>) => Promise<void>;
470
+ }
471
+ /** 一次接管尝试的结局。 */
472
+ type WebSelectionOutcome =
473
+ /** 两个键本来就已经指向本插件,没有写入。 */
474
+ 'already' |
475
+ /** 已写入两个键。 */
476
+ 'updated' |
477
+ /** 缺少 settings 服务或 `web` 条目不可配置,无法写入。 */
478
+ 'skipped';
479
+ /**
480
+ * 确保 `web` 接缝的搜索与抓取都选中本插件。
481
+ *
482
+ * 判定依据是 `describe()` 投影出的**生效值**(`value`),而不是覆盖层:这样在
483
+ * 「无覆盖、bundle 层已经指向本插件」时不会产生一次多余写入,也不会把等价的覆盖
484
+ * 写进 profile。
485
+ *
486
+ * 写入失败由调用方处理:这里不吞异常,让上层决定是记日志还是上报(开关本身
487
+ * 不能因为配置写不进去而失败)。
488
+ *
489
+ * @param settings - settings 服务(可能尚未就绪)。
490
+ * @returns 接管结局。
491
+ */
492
+ declare function ensureWebSelection(settings: SettingsFormsLike | undefined): Promise<WebSelectionOutcome>;
493
+ //#endregion
451
494
  //#region src/host/account-pool.d.ts
452
495
  /** 池中一个账号:key 与展示用代号。 */
453
496
  interface PoolAccount {
@@ -532,4 +575,4 @@ declare const inject: string[];
532
575
  */
533
576
  declare function apply(ctx: Context, config?: FailoverSearchConfig): void;
534
577
  //#endregion
535
- export { type AccountConfig, Config, FAILOVER_ACCOUNTS_ENDPOINT, FAILOVER_PROVIDER_ID, FAILOVER_REFRESH_ENDPOINT, FAILOVER_REVEAL_ENDPOINT, FAILOVER_ROW_ID, FAILOVER_SETTINGS_NAMESPACE, FAILOVER_TOGGLE_ENDPOINT, FAILOVER_TOGGLE_SET_ENDPOINT, FAILOVER_USAGE_CHANNEL, FAILOVER_USAGE_ENDPOINT, type FailoverSearchConfig, FailoverSearchProvider, type FailoverSearchSettings, SessionToggleStore, type UsageSnapshot, UsageStore, apply, buildPool, inject, maskApiKey, name, parsePublishedAt, usageFingerprint };
578
+ export { type AccountConfig, Config, FAILOVER_ACCOUNTS_ENDPOINT, FAILOVER_PROVIDER_ID, FAILOVER_REFRESH_ENDPOINT, FAILOVER_REVEAL_ENDPOINT, FAILOVER_ROW_ID, FAILOVER_SETTINGS_NAMESPACE, FAILOVER_TOGGLE_ENDPOINT, FAILOVER_TOGGLE_SET_ENDPOINT, FAILOVER_USAGE_CHANNEL, FAILOVER_USAGE_ENDPOINT, type FailoverSearchConfig, FailoverSearchProvider, type FailoverSearchSettings, SessionToggleStore, type UsageSnapshot, UsageStore, apply, buildPool, ensureWebSelection, inject, maskApiKey, name, parsePublishedAt, usageFingerprint };
package/lib/index.js CHANGED
@@ -1526,6 +1526,45 @@ var UsageStore = class {
1526
1526
  }
1527
1527
  };
1528
1528
  //#endregion
1529
+ //#region src/host/web-selection.ts
1530
+ /**
1531
+ * 把 `web` 接缝的提供方选择切回本插件(FNOS-010-12 补充)。
1532
+ *
1533
+ * 背景:`web` 行的 `searchProvider` / `fetchProvider` 是**固定选择**语义——配了哪个
1534
+ * id,接缝就只用那个 provider,其它 provider 即使注册成功也不会被走到(官方
1535
+ * `resolveProvider`)。官方「网络搜索」设置页保存时会把这两个键写成官方 id,于是
1536
+ * 本插件的复合提供方永远不被调用:表现为「插件页看着正常、账号也在,但
1537
+ * `web_search` / `web_fetch` 走的是官方端点」,官方余额一耗尽就直接 402。
1538
+ *
1539
+ * 这里给「智能搜索」开关的**重新开启**补上修复动作:写 `web` 命名空间的两个键。
1540
+ * 只写开启方向——关闭是会话级偏好(该会话不接入),不应影响其它会话的全局选择。
1541
+ */
1542
+ /**
1543
+ * 确保 `web` 接缝的搜索与抓取都选中本插件。
1544
+ *
1545
+ * 判定依据是 `describe()` 投影出的**生效值**(`value`),而不是覆盖层:这样在
1546
+ * 「无覆盖、bundle 层已经指向本插件」时不会产生一次多余写入,也不会把等价的覆盖
1547
+ * 写进 profile。
1548
+ *
1549
+ * 写入失败由调用方处理:这里不吞异常,让上层决定是记日志还是上报(开关本身
1550
+ * 不能因为配置写不进去而失败)。
1551
+ *
1552
+ * @param settings - settings 服务(可能尚未就绪)。
1553
+ * @returns 接管结局。
1554
+ */
1555
+ async function ensureWebSelection(settings) {
1556
+ if (settings === void 0) return "skipped";
1557
+ const entry = settings.describe().find((row) => row.ns === "web");
1558
+ if (entry === void 0) return "skipped";
1559
+ const current = readRecord(entry.value);
1560
+ if (readString(current.searchProvider) === "dsh-failover-search" && readString(current.fetchProvider) === "dsh-failover-search") return "already";
1561
+ await settings.update("web", {
1562
+ searchProvider: FAILOVER_PROVIDER_ID,
1563
+ fetchProvider: FAILOVER_PROVIDER_ID
1564
+ });
1565
+ return "updated";
1566
+ }
1567
+ //#endregion
1529
1568
  //#region src/index.ts
1530
1569
  /**
1531
1570
  * 账号配置巡检周期(毫秒)。
@@ -1718,6 +1757,11 @@ function apply(ctx, config = Config({})) {
1718
1757
  const request = payload ?? {};
1719
1758
  if (request.sessionId === void 0) throw new Error("toggle-set requires a sessionId");
1720
1759
  toggle.setEnabled(request.sessionId, request.enabled === true);
1760
+ if (request.enabled === true) try {
1761
+ if (await ensureWebSelection(ctx.get("settings")) === "updated") ctx.logger.info("[failover-search] 已把 web 接缝的搜索/抓取选择切回本插件");
1762
+ } catch (error) {
1763
+ ctx.logger.warn("[failover-search] 改写 web 接缝选择失败:%s", error instanceof Error ? error.message : String(error));
1764
+ }
1721
1765
  return {
1722
1766
  ok: true,
1723
1767
  value: { enabled: toggle.isEnabled(request.sessionId) }
@@ -1765,4 +1809,4 @@ function collectAccounts(platform, accounts) {
1765
1809
  }));
1766
1810
  }
1767
1811
  //#endregion
1768
- export { Config, FAILOVER_ACCOUNTS_ENDPOINT, FAILOVER_PROVIDER_ID, FAILOVER_REFRESH_ENDPOINT, FAILOVER_REVEAL_ENDPOINT, FAILOVER_ROW_ID, FAILOVER_SETTINGS_NAMESPACE, FAILOVER_TOGGLE_ENDPOINT, FAILOVER_TOGGLE_SET_ENDPOINT, FAILOVER_USAGE_CHANNEL, FAILOVER_USAGE_ENDPOINT, FailoverSearchProvider, SessionToggleStore, UsageStore, apply, buildPool, inject, maskApiKey, name, parsePublishedAt, usageFingerprint };
1812
+ export { Config, FAILOVER_ACCOUNTS_ENDPOINT, FAILOVER_PROVIDER_ID, FAILOVER_REFRESH_ENDPOINT, FAILOVER_REVEAL_ENDPOINT, FAILOVER_ROW_ID, FAILOVER_SETTINGS_NAMESPACE, FAILOVER_TOGGLE_ENDPOINT, FAILOVER_TOGGLE_SET_ENDPOINT, FAILOVER_USAGE_CHANNEL, FAILOVER_USAGE_ENDPOINT, FailoverSearchProvider, SessionToggleStore, UsageStore, apply, buildPool, ensureWebSelection, inject, maskApiKey, name, parsePublishedAt, usageFingerprint };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tnnevol/dsh-failover-search",
3
3
  "displayName": "Failover Search",
4
4
  "type": "module",
5
- "version": "0.2.1-rc.2.7",
5
+ "version": "6.0.0",
6
6
  "description": "Composite DSH web-search provider that fails over TinyFish → Tavily → official DeepSeek, spreads requests across multiple accounts per platform, and shows platform usage on the plugin page.",
7
7
  "author": "tnnevol",
8
8
  "license": "Apache-2.0",
@@ -49,7 +49,8 @@
49
49
  "locale"
50
50
  ],
51
51
  "engines": {
52
- "node": "^22.19.0 || >=24.0.0"
52
+ "node": "^22.19.0 || >=24.0.0",
53
+ "dsh": "0.2.1-rc.3"
53
54
  },
54
55
  "dsh": {
55
56
  "bundle": {
@@ -67,56 +68,56 @@
67
68
  },
68
69
  "peerDependencies": {
69
70
  "@deepseek-ai/cordis": "^4.0.5",
70
- "@deepseek-ai/dsh-agent": "0.2.1-rc.2",
71
- "@deepseek-ai/dsh-client-connection": "0.2.1-rc.2",
72
- "@deepseek-ai/dsh-client-locale": "0.2.1-rc.2",
73
- "@deepseek-ai/dsh-client-store": "0.2.1-rc.2",
74
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.2",
75
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-rc.2",
76
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.2",
77
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.2",
78
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.2",
79
- "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.2",
80
- "@deepseek-ai/dsh-credentials": "0.2.1-rc.2",
81
- "@deepseek-ai/dsh-launch-environment": "0.2.1-rc.2",
82
- "@deepseek-ai/dsh-settings": "0.2.1-rc.2",
83
- "@deepseek-ai/dsh-tools": "0.2.1-rc.2",
84
- "@deepseek-ai/dsh-web": "0.2.1-rc.2",
85
- "@deepseek-ai/dsh-web-fetch-http": "0.2.1-rc.2",
86
- "@deepseek-ai/dsh-web-search-deepseek": "0.2.1-rc.2",
71
+ "@deepseek-ai/dsh-agent": "0.2.1-rc.3",
72
+ "@deepseek-ai/dsh-client-connection": "0.2.1-rc.3",
73
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.3",
74
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.3",
75
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.3",
76
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-rc.3",
77
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.3",
78
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.3",
79
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
80
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.3",
81
+ "@deepseek-ai/dsh-credentials": "0.2.1-rc.3",
82
+ "@deepseek-ai/dsh-launch-environment": "0.2.1-rc.3",
83
+ "@deepseek-ai/dsh-settings": "0.2.1-rc.3",
84
+ "@deepseek-ai/dsh-tools": "0.2.1-rc.3",
85
+ "@deepseek-ai/dsh-web": "0.2.1-rc.3",
86
+ "@deepseek-ai/dsh-web-fetch-http": "0.2.1-rc.3",
87
+ "@deepseek-ai/dsh-web-search-deepseek": "0.2.1-rc.3",
87
88
  "@deepseek-ai/schemastery": "3.18.5",
88
89
  "react": "^18.3.1"
89
90
  },
90
91
  "devDependencies": {
91
92
  "@deepseek-ai/cordis": "^4.0.5",
92
- "@deepseek-ai/dsh-agent": "0.2.1-rc.2",
93
- "@deepseek-ai/dsh-client-connection": "0.2.1-rc.2",
94
- "@deepseek-ai/dsh-client-locale": "0.2.1-rc.2",
95
- "@deepseek-ai/dsh-client-store": "0.2.1-rc.2",
96
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.2",
97
- "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-rc.2",
98
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.2",
99
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.2",
100
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.2",
101
- "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.2",
102
- "@deepseek-ai/dsh-credentials": "0.2.1-rc.2",
103
- "@deepseek-ai/dsh-launch-environment": "0.2.1-rc.2",
104
- "@deepseek-ai/dsh-settings": "0.2.1-rc.2",
105
- "@deepseek-ai/dsh-tools": "0.2.1-rc.2",
106
- "@deepseek-ai/dsh-web": "0.2.1-rc.2",
107
- "@deepseek-ai/dsh-web-fetch-http": "0.2.1-rc.2",
108
- "@deepseek-ai/dsh-web-search-deepseek": "0.2.1-rc.2",
93
+ "@deepseek-ai/dsh-agent": "0.2.1-rc.3",
94
+ "@deepseek-ai/dsh-client-connection": "0.2.1-rc.3",
95
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.3",
96
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.3",
97
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.3",
98
+ "@deepseek-ai/dsh-client-ui-plugin-manager": "0.2.1-rc.3",
99
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.3",
100
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.3",
101
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
102
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.3",
103
+ "@deepseek-ai/dsh-credentials": "0.2.1-rc.3",
104
+ "@deepseek-ai/dsh-launch-environment": "0.2.1-rc.3",
105
+ "@deepseek-ai/dsh-settings": "0.2.1-rc.3",
106
+ "@deepseek-ai/dsh-tools": "0.2.1-rc.3",
107
+ "@deepseek-ai/dsh-web": "0.2.1-rc.3",
108
+ "@deepseek-ai/dsh-web-fetch-http": "0.2.1-rc.3",
109
+ "@deepseek-ai/dsh-web-search-deepseek": "0.2.1-rc.3",
109
110
  "@deepseek-ai/schemastery": "3.18.5",
110
- "@midscene/test": "1.15.1",
111
- "@midscene/web": "1.15.1",
111
+ "@midscene/test": "1.16.5",
112
+ "@midscene/web": "1.16.5",
112
113
  "@types/node": "^22.20.0",
113
114
  "@types/react": "^18.3.31",
114
115
  "react": "^18.3.1",
115
116
  "tsdown": "^0.22.2",
116
117
  "typescript": "^5.9.3",
117
118
  "vitest": "^4.1.8",
118
- "@tnnevol/dsh-e2e-kit": "5.9.0-0.2.1-rc.2.7",
119
- "@tnnevol/dsh-semi-ui": "5.9.0-0.2.1-rc.2.7"
119
+ "@tnnevol/dsh-e2e-kit": "6.0.0",
120
+ "@tnnevol/dsh-semi-ui": "6.0.0"
120
121
  },
121
122
  "scripts": {
122
123
  "build": "tsdown",