dsh-subagent-default-model 0.3.5 → 1.1.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/CHANGELOG.md +34 -0
- package/README.en.md +19 -1
- package/README.md +19 -1
- package/lib/client.js +130 -7
- package/lib/index.js +149 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0 (2026-08-31)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **轨迹视图显示模型路由**: 子代理每次请求实际用的 provider/model 会显示在**轨迹视图**里——换模型(含 failover 切换)后自动多出一行「子代理模型:`provider/model`」。基于官方 `request/context` 帧(`trajectory-subagent-model` 定义),零宿主改动。
|
|
8
|
+
- **对话视图新增模型提示行**: 子代理**对话视图**新增上下文注入行(`chat-subagent-model` 定义,基于官方 `request/header` 帧的 `reason`):
|
|
9
|
+
- 子代理开始第一句:`子代理模型:provider/model`(写清当前用的供应商与模型)
|
|
10
|
+
- failover 切换成功后:`已切换到:provider/model`(展示现在用的是哪个模型)
|
|
11
|
+
- 会话恢复时:`继续使用:provider/model`
|
|
12
|
+
- 折叠态即可见(`source.summary`),复用 DSH 原生 `ContextInjectionRow`。
|
|
13
|
+
- **切换提示文案改为 Provider**: 「连接失败时按队列与策略切换模型」的提示从「需配置 ≥2 个模型」改为「需配置 ≥2 个 Provider」。实测确认:官方重试按 `provider` 记账(`dsh-llm-retry`),同一 Provider 下多模型共享重试配额、第二个模型不重试;**每个模型配独立 Provider 时,各拿满自己的重试次数,全部失败才停**。
|
|
14
|
+
|
|
15
|
+
### Docs
|
|
16
|
+
|
|
17
|
+
- 新增 `docs/mock-failover-test.md`:本地 mock 模拟连接失败的完整测试指南(SSE 支持、`MOCK_ALL_FAIL=1` 全失败模式)。
|
|
18
|
+
- 新增 `docs/per-model-retry-design.md`:「每个模型独立重试 + 逐个切换 + 全部失败才停」的需求、根因分析(官方重试按 provider 记账)与实现方案;方案 B(每模型一个 provider)已实测通过。
|
|
19
|
+
|
|
20
|
+
### Testing / Scripts
|
|
21
|
+
|
|
22
|
+
- 新增 `plugin/test/client-trajectory.test.mjs`:轨迹 + 对话定义的单测(匹配、三种 reason 文案、节点结构、buildViewNode),测试 **36/36 通过**。
|
|
23
|
+
- 新增 `plugin/scripts/mock-llm-server.mjs`:本地 OpenAI 兼容 mock,支持 SSE 流式响应与全失败模式。
|
|
24
|
+
- 新增 `plugin/scripts/simulate-retry.mjs`:端到端 failover 模拟,输出轨迹/对话视图渲染预览。
|
|
25
|
+
|
|
26
|
+
## 1.0.0 (2026-08-29)
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
- **子代理连接失败自动切换(failover)**: 新增 `failoverEnabled` 复选框(默认勾选),子代理的模型请求遇到限流(RATE_LIMIT)、配额(QUOTA)、服务端/传输错误、空响应时,自动在 `models` 列表内按 `strategy`(轮换/随机)切换模型重试——**仅对 subagent 生效**,主代理循环不受影响。基于官方 `agent/request-error` + `agent/request` 瀑布,与社区的 `dsh-llm-fallback` / `dsh-model-failover` 插件同机制。
|
|
31
|
+
- **设置卡片新增复选框**: 设置面板「子代理默认模型」卡片的分配策略下方新增「连接失败时按队列与策略切换模型」复选框,默认勾选,保存后生效。
|
|
32
|
+
|
|
33
|
+
### Docs
|
|
34
|
+
|
|
35
|
+
- README 新增「子代理连接失败自动切换」章节,含配置示例与字段说明表。
|
|
36
|
+
|
|
3
37
|
## 0.3.5 (2026-08-28)
|
|
4
38
|
|
|
5
39
|
### Added
|
package/README.en.md
CHANGED
|
@@ -10,6 +10,7 @@ When a subagent is created without an explicit `model`, this plugin injects the
|
|
|
10
10
|
|
|
11
11
|
- **Single model** — all subagents run on one configured model.
|
|
12
12
|
- **Multi-model** — a `models` list with `round-robin` or `random` strategy spreads parallel subagents across models.
|
|
13
|
+
- **Connection-failure failover** — when a subagent hits a connection-class failure, switch to another model in the `models` list by `strategy` and retry (subagents only; the main agent is never touched).
|
|
13
14
|
- **Reasoning strength** — optionally specify `reasoningEffort` per model entry (e.g. `high`, `medium`, `low`); the Web UI loads available efforts from the model catalog.
|
|
14
15
|
- **Hot-reload** — settings changes apply to the very next delegation.
|
|
15
16
|
- **Clean teardown** — Cordis disposal restores the original service methods.
|
|
@@ -115,8 +116,23 @@ subagent-default-model:
|
|
|
115
116
|
| `model` | string | — | Single model id (backward compatible). |
|
|
116
117
|
| `models` | array | `[]` | List of model entries (string or `{provider, model, reasoningEffort?}` pair). |
|
|
117
118
|
| `strategy` | string | `round-robin` | Selection strategy: `round-robin` or `random`. |
|
|
119
|
+
| `failoverEnabled` | boolean | `true` | Switch models by queue and strategy inside the `models` list when a subagent hits a connection failure (subagents only). |
|
|
118
120
|
| `reasoningEffort` | string | — | Optional reasoning strength for a model entry (e.g. `high`, `max`). |
|
|
119
121
|
|
|
122
|
+
## Subagent connection-failure failover
|
|
123
|
+
|
|
124
|
+
With `failoverEnabled` on (the default), when a subagent's own loop hits a connection-class failure, the plugin automatically switches models inside the `models` list and retries, following `strategy`:
|
|
125
|
+
|
|
126
|
+
- **Connection-class failures** — the switch triggers only on these error codes: `RATE_LIMIT`, `QUOTA`, `SERVER`, `TIMEOUT`, `TRANSPORT`, `EMPTY_RESPONSE`. Non-connection failures (e.g. `AUTH`) do **not** trigger a switch.
|
|
127
|
+
- `round-robin`: advance to the next model in the list (the queue).
|
|
128
|
+
- `random`: pick any model (without checking whether it was used before).
|
|
129
|
+
- **Needs ≥ 2 models** — with fewer than 2 entries in `models`, the feature is inactive.
|
|
130
|
+
- **Exhaustion passes through** — once every pool entry has been tried and failed, the real error is let through; no infinite retries.
|
|
131
|
+
- **Inherited `reasoningEffort` is dropped on switch** — the new provider/model is requested at the default reasoning strength instead of forcing the primary's strength onto a provider that may not support it.
|
|
132
|
+
- **Sticky within a run** — subsequent steps of the same subagent run stay on the switched model.
|
|
133
|
+
|
|
134
|
+
It builds on the official `agent/request-error` + `agent/request` waterfalls and applies **only to subagents** — the main agent loop is never switched.
|
|
135
|
+
|
|
120
136
|
## How it works
|
|
121
137
|
|
|
122
138
|
```text
|
|
@@ -129,4 +145,6 @@ The plugin wraps the host `ctx.subagents` service (`start` / `startContinuable`)
|
|
|
129
145
|
|
|
130
146
|
## License
|
|
131
147
|
|
|
132
|
-
[MIT](LICENSE)
|
|
148
|
+
This project is open-sourced under the [MIT License](LICENSE), copyright (c) 2026 LaoDing.
|
|
149
|
+
|
|
150
|
+
The MIT License grants anyone the freedom to deal in the Software without restriction, including using, copying, modifying, merging, publishing, distributing, sublicensing, and/or selling copies, provided that all copies or substantial portions retain the above copyright notice and this permission notice; the Software is provided "AS IS", without warranty of any kind. See [LICENSE](LICENSE) for the full text.
|
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
- **单模型** —— 所有子代理运行在同一个配置模型上。
|
|
12
12
|
- **多模型** —— `models` 列表配合 `round-robin` / `random` 策略,让并行子代理分散到多个模型。
|
|
13
|
+
- **连接失败自动切换** —— 子代理遇到连接类失败时,在 `models` 列表内按 `strategy` 自动切换模型重试(仅 subagent,主代理不受影响)。
|
|
13
14
|
- **推理强度** —— 可为每个模型条目指定 `reasoningEffort`(如 `high`、`medium`、`low`);Web 界面从模型目录加载可用的强度。
|
|
14
15
|
- **热重载** —— 设置变更立即作用于下一次派发。
|
|
15
16
|
- **干净卸载** —— Cordis 销毁时还原原始服务方法。
|
|
@@ -115,8 +116,23 @@ subagent-default-model:
|
|
|
115
116
|
| `model` | string | — | 单模型 id(向后兼容)。 |
|
|
116
117
|
| `models` | array | `[]` | 模型条目列表(string 或 `{provider, model, reasoningEffort?}` 对)。 |
|
|
117
118
|
| `strategy` | string | `round-robin` | 分配策略:`round-robin` 或 `random`。 |
|
|
119
|
+
| `failoverEnabled` | boolean | `true` | 子代理连接失败时在 `models` 列表内按队列与策略切换模型(仅 subagent)。 |
|
|
118
120
|
| `reasoningEffort` | string | — | 可选推理强度(如 `high`、`max`)。 |
|
|
119
121
|
|
|
122
|
+
## 子代理连接失败自动切换
|
|
123
|
+
|
|
124
|
+
开启 `failoverEnabled`(默认开启)后,子代理自身的循环遇到连接类失败时,插件会在 `models` 列表内按 `strategy` 自动切换模型并重试:
|
|
125
|
+
|
|
126
|
+
- **连接类失败** —— 命中以下任一错误码才切换:`RATE_LIMIT`、`QUOTA`、`SERVER`、`TIMEOUT`、`TRANSPORT`、`EMPTY_RESPONSE`。认证错误(如 `AUTH`)等非连接类失败**不会**触发切换。
|
|
127
|
+
- `round-robin`:按列表顺序切到下一个模型(队列)。
|
|
128
|
+
- `random`:随机挑一个模型(不判断之前是否用过)。
|
|
129
|
+
- **需要 ≥ 2 个模型** —— 当 `models` 少于 2 项时本功能不生效。
|
|
130
|
+
- **耗尽即放行** —— 列表内全部模型轮试失败后,放行真实错误,不做无限重试。
|
|
131
|
+
- **切换时丢弃继承的 `reasoningEffort`** —— 换到新 provider/model 后按默认推理强度请求,避免把主模型的强度强加给不支持它的 provider。
|
|
132
|
+
- **Run 内粘性** —— 同一子代理 run 的后续 step 保持在切换后的模型上。
|
|
133
|
+
|
|
134
|
+
该机制基于官方 `agent/request-error` + `agent/request` 瀑布,且**仅对 subagent 生效**——主代理循环不会被切换。
|
|
135
|
+
|
|
120
136
|
## 工作原理
|
|
121
137
|
|
|
122
138
|
```text
|
|
@@ -129,4 +145,6 @@ subagent-default-model:
|
|
|
129
145
|
|
|
130
146
|
## 许可证
|
|
131
147
|
|
|
132
|
-
[MIT](LICENSE)
|
|
148
|
+
本项目采用 [MIT 许可证](LICENSE) 开源发布,版权归属:**Copyright (c) 2026 LaoDing**。
|
|
149
|
+
|
|
150
|
+
MIT 许可证授予任何人免费处理本软件(包括使用、复制、修改、合并、发布、分发、再许可及出售副本)的权利,前提是所有副本或实质性部分均保留上述版权声明与本许可声明;软件按“原样”提供,不附带任何明示或暗示的担保。完整条款见 [LICENSE](LICENSE)。
|
package/lib/client.js
CHANGED
|
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
|
|
15
15
|
// ── plugin icon (LD brand logo, 64px) ────────────────────────────────
|
|
16
16
|
var DSM_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAXGUlEQVR4nH1bC7BdVXn+1tr7nHPvzb3JvUloSAQp0JHWoAMttKOCFrWU8irQSbCTQYG21IahnTJUUTsM0FJhZCzCSIcKImOpDkhrhQ5YC7ROB3lUBU3EyCuBFBIIedzcx3ntvTr/a621TwIns3PO3mfvddf/+v7v/9c6DvYKoYBz1cZNYfJpVBcNBm7dcIhj3TBM15VzqAE6XAWEGggVADroOl0byDW+PtRr9E732rl9r2PxOMNsrCogVE7PA0Kge4Lcz5/TGI6v00UaK+h98u4QUA9quIDg4Pe2i2LTsknc++mzZu9cv37VHNaFAveSJICj/9aFUNzrXHXSTwdnznl/Y+X9MaEP1D0A/ToKaUdDASoAK0YVYcLad/G88S6C1aQcOkI2Nj9HylBFBRMYqPUeFp6EDXQfKcIUoud6LQQP59rwrsBEOdhy9KGDK/7j9mUPmBKcCf++Z4YbF6eKLw+6QFioKl/DoYILlXMsHE2KPCCzwlsqoNb3oUw4Kq+2a0k4G4MtXOX3J4HNyulzUkC0eqYI8ZAaQZQSAh9080Qx1m7jHStnL/3B3ctvXbcuFOwBH/p5OG12DA/29leV6wcHeI8hadE1rBldl/6ACs7WMEuz0PIcKawe0Gdzeyf36eTzcOHxVAEpTEQB0QtY0PRZPMYsX+t3tSqBxkteYeHh6qqu6yIsmVhaHHtE7/fu/8fJhzzF/OywunXQR+DJOO9pkLp2NJ64pIXhaOxb/IfmJM29PemSJ+NSzJP1s2dhwmucJ6uaoIYFzVjnkFDhLRTkb2XC03gQTKDrZNjSV1icXwzPv9y99Z5Hw6R/psQnqoniyLBQ1d65IoGiDqZuHwWwzyFzx8xl5RDBZR4uCZc9E8fS+8TdSfHZ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KCjmYKaWIU/ImhcpTpXi2q7UfLeH9fXVqSVsTNiMD+Rh4uraDT2mlpXu8BNaG1etcnN+3T2huPcvWg8dubS6dHJJUfD6bFVXrq5rrw3+tCaXOuGmBENzAzHpu0tvL63uNj8bykdeoCkt8QHL+SqAkRxz60wJcQ9BFh6p7CX8CYEQLtShKocTfmbpRLHs3d1LT7u+9dA99tNZ+yHxBTcNztz0mr9x74I/hnZXhD7F/PCAn6bJz+U0vrPr7K5VJUJZf5/v040NDcG02LGGJVmfOsuxdifg03U9vUZHrPz0fl7p5caGjNkiEmTFUXBooUDbjWGs5TE+Pdyy6vjqijO+MPYACb+efjwdiYsqIewMk+d8tbro1b1uXXehPrYahmn+hZmGgtefqsalNFvU1BpAhM8QXhUlCmgCmihAUnBUQixk6J2eSYqwvM9Iz5sfrApM7LDF7W651oILbef3Tky0Nk2vcfeed0dxp3Nu7h6EYr2sgOL/Aa5OuMdnE5sWAAAAAElFTkSuQmCC";
|
|
17
|
-
var SETTINGS_CSS = ".dsm-model-settings{display:flex;flex-direction:column;gap:14px;margin:0;padding:0}.dsm-model-settings-list{display:flex;flex-direction:column;gap:10px}.dsm-model-settings-route{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1fr) auto;gap:8px;align-items:end;padding:10px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:10px;background:var(--dsw-alias-bg-layer-3,#202126)}.dsm-model-settings-field{display:flex;flex-direction:column;gap:4px;min-width:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-select{width:100%;max-width:220px;height:32px;padding:0 28px 0 10px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px;background:var(--dsw-alias-bg-layer-2,#232529);color:var(--dsw-alias-label-primary,#e6e6e6);font:inherit;font-size:13px;line-height:1.5}.dsm-model-settings-select:focus{outline:2px solid var(--dsw-alias-state-business-primary,#5686fe);outline-offset:1px}.dsm-model-settings-select:disabled{color:var(--dsw-alias-label-tertiary,#999);cursor:default}.dsm-model-settings-remove{height:32px;min-width:32px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary,#b8b8b8);cursor:pointer;font-size:16px;line-height:1}.dsm-model-settings-remove:hover{color:var(--dsw-alias-state-error-primary,#ef4444);background:var(--dsw-alias-interactive-bg-hover-danger,rgba(242,90,90,.15))}.dsm-model-settings-options{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.dsm-model-settings-strategy{display:flex;align-items:center;gap:8px;white-space:nowrap;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-strategy .dsm-model-settings-select{max-width:150px}.dsm-model-settings-footer{border-top:1px solid var(--dsw-alias-border-l2,#36373b);display:flex;align-items:center;justify-content:flex-end;gap:8px;padding:12px 0 4px}.dsm-model-settings-footer-left{display:flex;align-items:center;gap:10px;flex:1;min-width:0}.dsm-model-settings-footer-status{flex:1;min-width:0;color:var(--dsw-alias-label-secondary,#b8b8b8);font-size:12px;line-height:1.5}.dsm-model-settings-footer-error{flex:1;min-width:0;color:var(--dsw-alias-label-error,#ef4444);font-size:12px;line-height:1.5}.dsm-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid transparent;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}.dsm-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:1px}.dsm-btn:disabled{opacity:.4;cursor:default}.dsm-btn-outline{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:transparent}.dsm-btn-outline:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}.dsm-btn-primary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}.dsm-btn-primary:hover:not(:disabled){opacity:.9}.dsm-model-settings-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-plugin-card{border:1px solid var(--dsw-alias-border-l2,#36373b);background:var(--dsw-alias-bg-layer-3,#202126);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}.dsm-plugin-card:hover{border-color:var(--dsw-alias-label-dimmed,#777)}.dsm-plugin-card-open{background:var(--dsw-alias-bg-layer-2,#25262b);border-color:var(--dsw-alias-label-dimmed,#777)}.dsm-plugin-card-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}.dsm-plugin-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:-2px}.dsm-plugin-card-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}.dsm-plugin-card-title{color:var(--dsw-alias-label-primary,#e6e6e6);font-size:15px;font-weight:600;line-height:1.4}.dsm-plugin-card-description{color:var(--dsw-alias-label-tertiary,#999);font-size:13px;line-height:1.5}.dsm-plugin-card-chevron{color:var(--dsw-alias-label-tertiary,#999);flex:none;display:inline-flex;transition:transform .16s}.dsm-plugin-card-chevron-open{transform:rotate(180deg)}.dsm-plugin-card-body{border-top:1px solid var(--dsw-alias-border-l2,#36373b);margin:0 16px;padding:0 0 8px}.dsm-plugin-card-body .dsm-model-settings{margin:0;padding:12px 0 0;background:transparent;border:0;border-radius:0}.dsm-plugin-card-body .dsm-model-settings-head{display:none}.dsm-plugin-card-icon{width:32px;height:32px;flex:none;border-radius:7px}.dsm-model-settings-cheer{display:inline-flex;align-items:center;gap:4px;flex:none;text-decoration:underline;text-underline-offset:2px;color:var(--dsw-alias-label-tertiary,#999);font-size:13px;line-height:1.5;transition:color .16s}.dsm-model-settings-cheer-star{font-size:12px;line-height:1;display:inline-flex}.dsm-model-settings-cheer:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}.dsm-model-settings-cheer:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:2px}";
|
|
17
|
+
var SETTINGS_CSS = ".dsm-model-settings{display:flex;flex-direction:column;gap:14px;margin:0;padding:0}.dsm-model-settings-list{display:flex;flex-direction:column;gap:10px}.dsm-model-settings-route{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1fr) auto;gap:8px;align-items:end;padding:10px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:10px;background:var(--dsw-alias-bg-layer-3,#202126)}.dsm-model-settings-field{display:flex;flex-direction:column;gap:4px;min-width:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-select{width:100%;max-width:220px;height:32px;padding:0 28px 0 10px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px;background:var(--dsw-alias-bg-layer-2,#232529);color:var(--dsw-alias-label-primary,#e6e6e6);font:inherit;font-size:13px;line-height:1.5}.dsm-model-settings-select:focus{outline:2px solid var(--dsw-alias-state-business-primary,#5686fe);outline-offset:1px}.dsm-model-settings-select:disabled{color:var(--dsw-alias-label-tertiary,#999);cursor:default}.dsm-model-settings-remove{height:32px;min-width:32px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary,#b8b8b8);cursor:pointer;font-size:16px;line-height:1}.dsm-model-settings-remove:hover{color:var(--dsw-alias-state-error-primary,#ef4444);background:var(--dsw-alias-interactive-bg-hover-danger,rgba(242,90,90,.15))}.dsm-model-settings-options{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.dsm-model-settings-strategy{display:flex;align-items:center;gap:8px;white-space:nowrap;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-strategy .dsm-model-settings-select{max-width:150px}.dsm-model-settings-failover{display:flex;align-items:center;gap:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8);cursor:pointer}.dsm-model-settings-failover input[type=checkbox]{cursor:pointer}.dsm-failover-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#999);white-space:nowrap}.dsm-model-settings-footer{border-top:1px solid var(--dsw-alias-border-l2,#36373b);display:flex;align-items:center;justify-content:flex-end;gap:8px;padding:12px 0 4px}.dsm-model-settings-footer-left{display:flex;align-items:center;gap:10px;flex:1;min-width:0}.dsm-model-settings-footer-status{flex:1;min-width:0;color:var(--dsw-alias-label-secondary,#b8b8b8);font-size:12px;line-height:1.5}.dsm-model-settings-footer-error{flex:1;min-width:0;color:var(--dsw-alias-label-error,#ef4444);font-size:12px;line-height:1.5}.dsm-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid transparent;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}.dsm-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:1px}.dsm-btn:disabled{opacity:.4;cursor:default}.dsm-btn-outline{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:transparent}.dsm-btn-outline:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}.dsm-btn-primary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}.dsm-btn-primary:hover:not(:disabled){opacity:.9}.dsm-model-settings-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-plugin-card{border:1px solid var(--dsw-alias-border-l2,#36373b);background:var(--dsw-alias-bg-layer-3,#202126);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}.dsm-plugin-card:hover{border-color:var(--dsw-alias-label-dimmed,#777)}.dsm-plugin-card-open{background:var(--dsw-alias-bg-layer-2,#25262b);border-color:var(--dsw-alias-label-dimmed,#777)}.dsm-plugin-card-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}.dsm-plugin-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:-2px}.dsm-plugin-card-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}.dsm-plugin-card-title{color:var(--dsw-alias-label-primary,#e6e6e6);font-size:15px;font-weight:600;line-height:1.4}.dsm-plugin-card-description{color:var(--dsw-alias-label-tertiary,#999);font-size:13px;line-height:1.5}.dsm-plugin-card-chevron{color:var(--dsw-alias-label-tertiary,#999);flex:none;display:inline-flex;transition:transform .16s}.dsm-plugin-card-chevron-open{transform:rotate(180deg)}.dsm-plugin-card-body{border-top:1px solid var(--dsw-alias-border-l2,#36373b);margin:0 16px;padding:0 0 8px}.dsm-plugin-card-body .dsm-model-settings{margin:0;padding:12px 0 0;background:transparent;border:0;border-radius:0}.dsm-plugin-card-body .dsm-model-settings-head{display:none}.dsm-plugin-card-icon{width:32px;height:32px;flex:none;border-radius:7px}.dsm-model-settings-cheer{display:inline-flex;align-items:center;gap:4px;flex:none;text-decoration:underline;text-underline-offset:2px;color:var(--dsw-alias-label-tertiary,#999);font-size:13px;line-height:1.5;transition:color .16s}.dsm-model-settings-cheer-star{font-size:12px;line-height:1;display:inline-flex}.dsm-model-settings-cheer:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}.dsm-model-settings-cheer:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:2px}";
|
|
18
18
|
|
|
19
19
|
if (typeof document !== "undefined") {
|
|
20
20
|
var cssId = "dsh-subagent-default-model/client.css";
|
|
@@ -49,7 +49,13 @@ window.__ModuleLoader__.load({
|
|
|
49
49
|
"row.saved": "已保存",
|
|
50
50
|
"row.incomplete": "请为每个模型路由选择 Provider 和 Model。",
|
|
51
51
|
"row.saveFailed": "保存失败,请重试。",
|
|
52
|
-
"row.toastSaved": "子代理默认模型设置已保存。"
|
|
52
|
+
"row.toastSaved": "子代理默认模型设置已保存。",
|
|
53
|
+
"row.failoverEnabled": "连接失败时按队列与策略切换模型",
|
|
54
|
+
"row.failoverHint": "(需配置 ≥2 个 Provider,切换才会生效)。",
|
|
55
|
+
"row.trajectoryModel": "子代理模型",
|
|
56
|
+
"row.chatModelInitial": "子代理模型",
|
|
57
|
+
"row.chatModelChange": "已切换到",
|
|
58
|
+
"row.chatModelResume": "继续使用"
|
|
53
59
|
};
|
|
54
60
|
var SUBAGENT_ROW_EN = {
|
|
55
61
|
"row.title": "Subagent default model (dsh-subagent-default-model)",
|
|
@@ -71,7 +77,13 @@ window.__ModuleLoader__.load({
|
|
|
71
77
|
"row.saved": "Saved",
|
|
72
78
|
"row.incomplete": "Choose a provider and model for every route.",
|
|
73
79
|
"row.saveFailed": "Could not save the setting. Try again.",
|
|
74
|
-
"row.toastSaved": "Subagent default model settings saved."
|
|
80
|
+
"row.toastSaved": "Subagent default model settings saved.",
|
|
81
|
+
"row.failoverEnabled": "Switch models by queue and strategy on connection failure",
|
|
82
|
+
"row.failoverHint": "(requires at least 2 configured providers).",
|
|
83
|
+
"row.trajectoryModel": "Subagent model",
|
|
84
|
+
"row.chatModelInitial": "Subagent model",
|
|
85
|
+
"row.chatModelChange": "Switched to",
|
|
86
|
+
"row.chatModelResume": "Resumed on"
|
|
75
87
|
};
|
|
76
88
|
|
|
77
89
|
// ── helpers ──────────────────────────────────────────────────────────
|
|
@@ -91,8 +103,9 @@ window.__ModuleLoader__.load({
|
|
|
91
103
|
return result;
|
|
92
104
|
}
|
|
93
105
|
|
|
94
|
-
function serializeDefaultModels(previousValue, routes, strategy) {
|
|
106
|
+
function serializeDefaultModels(previousValue, routes, strategy, failoverEnabled) {
|
|
95
107
|
var next = Object.assign({}, previousValue || {});
|
|
108
|
+
next.failoverEnabled = failoverEnabled === false ? false : true;
|
|
96
109
|
if (routes.length === 0) {
|
|
97
110
|
next.provider = "";
|
|
98
111
|
next.model = "";
|
|
@@ -132,6 +145,8 @@ window.__ModuleLoader__.load({
|
|
|
132
145
|
return scope.set("models", value.models);
|
|
133
146
|
}).then(function () {
|
|
134
147
|
return scope.set("strategy", value.strategy);
|
|
148
|
+
}).then(function () {
|
|
149
|
+
return scope.set("failoverEnabled", value.failoverEnabled === false ? false : true);
|
|
135
150
|
}).then(function () {
|
|
136
151
|
return scope.set("reasoningEffort", value.reasoningEffort || "");
|
|
137
152
|
});
|
|
@@ -154,6 +169,7 @@ window.__ModuleLoader__.load({
|
|
|
154
169
|
var groupsState = React.useState([]);
|
|
155
170
|
var routesState = React.useState(normalizeDefaultModels(value));
|
|
156
171
|
var strategyState = React.useState(value.strategy === "random" ? "random" : "round-robin");
|
|
172
|
+
var failoverEnabledState = React.useState(value.failoverEnabled !== false);
|
|
157
173
|
var savedState = React.useState(false);
|
|
158
174
|
var saveErrorState = React.useState(false);
|
|
159
175
|
var toastState = React.useState(null);
|
|
@@ -171,6 +187,7 @@ window.__ModuleLoader__.load({
|
|
|
171
187
|
if (dirtyState[0] || busyState[0]) return;
|
|
172
188
|
routesState[1](normalizeDefaultModels(value));
|
|
173
189
|
strategyState[1](value.strategy === "random" ? "random" : "round-robin");
|
|
190
|
+
failoverEnabledState[1](value.failoverEnabled !== false);
|
|
174
191
|
savedState[1](false);
|
|
175
192
|
saveErrorState[1](false);
|
|
176
193
|
}, [snap ? snap.revision : -1, dirtyState[0], busyState[0]]);
|
|
@@ -208,7 +225,7 @@ window.__ModuleLoader__.load({
|
|
|
208
225
|
}
|
|
209
226
|
function save() {
|
|
210
227
|
if (!snap || snap.status !== "ready" || snap.writable === false || busyState[0]) return;
|
|
211
|
-
var nextValue = serializeDefaultModels(value, routesState[0], strategyState[0]);
|
|
228
|
+
var nextValue = serializeDefaultModels(value, routesState[0], strategyState[0], failoverEnabledState[0]);
|
|
212
229
|
savedState[1](false);
|
|
213
230
|
saveErrorState[1](false);
|
|
214
231
|
busyState[1](true);
|
|
@@ -217,11 +234,12 @@ window.__ModuleLoader__.load({
|
|
|
217
234
|
}).then(function () {
|
|
218
235
|
var accepted = props.settingsScope.getSnapshot();
|
|
219
236
|
var acceptedValue = (accepted && accepted.status === "ready" && accepted.value) || {};
|
|
220
|
-
if (acceptedValue.provider !== nextValue.provider || acceptedValue.model !== nextValue.model || acceptedValue.strategy !== nextValue.strategy || (acceptedValue.reasoningEffort || "") !== (nextValue.reasoningEffort || "") || JSON.stringify(acceptedValue.models || []) !== JSON.stringify(nextValue.models || [])) {
|
|
237
|
+
if (acceptedValue.provider !== nextValue.provider || acceptedValue.model !== nextValue.model || acceptedValue.strategy !== nextValue.strategy || (acceptedValue.reasoningEffort || "") !== (nextValue.reasoningEffort || "") || (acceptedValue.failoverEnabled === false ? false : true) !== nextValue.failoverEnabled || JSON.stringify(acceptedValue.models || []) !== JSON.stringify(nextValue.models || [])) {
|
|
221
238
|
throw new Error("settings write was not accepted");
|
|
222
239
|
}
|
|
223
240
|
routesState[1](normalizeDefaultModels(acceptedValue));
|
|
224
241
|
strategyState[1](acceptedValue.strategy === "random" ? "random" : "round-robin");
|
|
242
|
+
failoverEnabledState[1](acceptedValue.failoverEnabled !== false);
|
|
225
243
|
dirtyState[1](false);
|
|
226
244
|
busyState[1](false);
|
|
227
245
|
savedState[1](true);
|
|
@@ -235,6 +253,7 @@ window.__ModuleLoader__.load({
|
|
|
235
253
|
function discard() {
|
|
236
254
|
routesState[1](normalizeDefaultModels(value));
|
|
237
255
|
strategyState[1](value.strategy === "random" ? "random" : "round-robin");
|
|
256
|
+
failoverEnabledState[1](value.failoverEnabled !== false);
|
|
238
257
|
dirtyState[1](false);
|
|
239
258
|
savedState[1](false);
|
|
240
259
|
saveErrorState[1](false);
|
|
@@ -329,6 +348,15 @@ window.__ModuleLoader__.load({
|
|
|
329
348
|
)
|
|
330
349
|
) : null
|
|
331
350
|
),
|
|
351
|
+
React.createElement("label", { className: "dsm-model-settings-failover" },
|
|
352
|
+
React.createElement("input", {
|
|
353
|
+
type: "checkbox",
|
|
354
|
+
checked: failoverEnabledState[0],
|
|
355
|
+
onChange: function (event) { failoverEnabledState[1](event.target.checked); savedState[1](false); saveErrorState[1](false); dirtyState[1](true); }
|
|
356
|
+
}),
|
|
357
|
+
React.createElement("span", null, t("row.failoverEnabled")),
|
|
358
|
+
React.createElement("span", { className: "dsm-failover-hint" }, t("row.failoverHint"))
|
|
359
|
+
),
|
|
332
360
|
hasIncompleteRoute ? React.createElement("div", { className: "dsm-model-settings-hint" }, t("row.incomplete")) : null,
|
|
333
361
|
React.createElement("div", { className: "dsm-model-settings-footer" },
|
|
334
362
|
React.createElement("div", { className: "dsm-model-settings-footer-left" },
|
|
@@ -380,7 +408,7 @@ window.__ModuleLoader__.load({
|
|
|
380
408
|
}
|
|
381
409
|
|
|
382
410
|
// ── apply: inject settings row ───────────────────────────────────────
|
|
383
|
-
var inject = ["sessions", "connection", "slots", "locale", "settingsScope", "remote"];
|
|
411
|
+
var inject = ["sessions", "connection", "slots", "locale", "settingsScope", "remote", "conversationEvents"];
|
|
384
412
|
|
|
385
413
|
function apply(ctx) {
|
|
386
414
|
var api = ctx.connection.api;
|
|
@@ -389,6 +417,101 @@ window.__ModuleLoader__.load({
|
|
|
389
417
|
ctx.locale.register(SUBAGENT_ROW_LOCALE, "zh", SUBAGENT_ROW_ZH);
|
|
390
418
|
ctx.locale.register(SUBAGENT_ROW_LOCALE, "en", SUBAGENT_ROW_EN);
|
|
391
419
|
|
|
420
|
+
// ── trajectory: surface the subagent model per request ──────────────
|
|
421
|
+
// agent-loop appends a `request/context` frame (provider/model) whenever
|
|
422
|
+
// the provider or model changes — failover switches trigger it with zero
|
|
423
|
+
// host changes. Register a trajectory definition that renders that frame
|
|
424
|
+
// as a compact "Subagent model" row inside the subagent's trajectory view.
|
|
425
|
+
if (ctx.conversationEvents && typeof ctx.conversationEvents.register === "function") {
|
|
426
|
+
var trajectoryT = ctx.locale.bind(SUBAGENT_ROW_LOCALE);
|
|
427
|
+
var modelContextDefinition = {
|
|
428
|
+
kind: "trajectory-subagent-model",
|
|
429
|
+
target: "trajectory",
|
|
430
|
+
match: function (event) {
|
|
431
|
+
return event.type === "request/context" ? { id: String(event.seq), role: "start" } : null;
|
|
432
|
+
},
|
|
433
|
+
start: function (_context, match) {
|
|
434
|
+
var event = match.event;
|
|
435
|
+
var data = event.data || {};
|
|
436
|
+
var label = trajectoryT("row.trajectoryModel") + ":" + (data.provider ? data.provider + (data.model ? "/" + data.model : "") : (data.model || ""));
|
|
437
|
+
return {
|
|
438
|
+
kind: "context",
|
|
439
|
+
seq: event.seq,
|
|
440
|
+
time: event.time,
|
|
441
|
+
content: [{ type: "text", text: label }],
|
|
442
|
+
source: { kind: "plugin", plugin: "dsh-subagent-default-model", form: "notice" }
|
|
443
|
+
};
|
|
444
|
+
},
|
|
445
|
+
update: function (context) { return context.state; },
|
|
446
|
+
buildViewNode: function (context) {
|
|
447
|
+
if (context.state === void 0) return null;
|
|
448
|
+
return {
|
|
449
|
+
key: context.key,
|
|
450
|
+
kind: context.kind,
|
|
451
|
+
id: context.id,
|
|
452
|
+
target: "trajectory",
|
|
453
|
+
anchorSeq: context.state.seq,
|
|
454
|
+
location: context.start && context.start.location ? context.start.location : { kind: "unresolved" },
|
|
455
|
+
data: { kind: "node", node: context.state }
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
ctx.conversationEvents.register(modelContextDefinition);
|
|
460
|
+
|
|
461
|
+
// ── chat: surface the subagent model in the conversation view ──
|
|
462
|
+
// agent-loop writes a `request/header` frame with a `reason` the first
|
|
463
|
+
// time the subagent builds a request ("initial"), on every provider /
|
|
464
|
+
// model change ("change" — including failover switches), and when a
|
|
465
|
+
// persisted session resumes ("resume"). The frame header carries the
|
|
466
|
+
// full config (provider/model), so the conversation can show exactly
|
|
467
|
+
// which route is in use — no host-side changes required.
|
|
468
|
+
// The chat view renders `kind: "context"` nodes via ContextMessageNodeView
|
|
469
|
+
// (content/source/provenance/form), reusing the built-in injection row.
|
|
470
|
+
var chatT = ctx.locale.bind(SUBAGENT_ROW_LOCALE);
|
|
471
|
+
var chatModelDefinition = {
|
|
472
|
+
kind: "chat-subagent-model",
|
|
473
|
+
target: "chat",
|
|
474
|
+
match: function (event) {
|
|
475
|
+
return event.type === "request/header" ? { id: String(event.seq), role: "start" } : null;
|
|
476
|
+
},
|
|
477
|
+
start: function (_context, match) {
|
|
478
|
+
var event = match.event;
|
|
479
|
+
var data = event.data || {};
|
|
480
|
+
var header = data.header || {};
|
|
481
|
+
var config = header.config || {};
|
|
482
|
+
var reason = data.reason === "change" ? "row.chatModelChange" : data.reason === "resume" ? "row.chatModelResume" : "row.chatModelInitial";
|
|
483
|
+
var label = chatT(reason) + ":" + (config.provider ? config.provider + (config.model ? "/" + config.model : "") : (config.model || ""));
|
|
484
|
+
return {
|
|
485
|
+
kind: "context",
|
|
486
|
+
seq: event.seq,
|
|
487
|
+
time: event.time,
|
|
488
|
+
content: [{ type: "text", text: label }],
|
|
489
|
+
// `summary` is the collapsed row's one-line account (notice form):
|
|
490
|
+
// without it the row only shows the provenance label and hides the
|
|
491
|
+
// model behind expansion.
|
|
492
|
+
source: { kind: "plugin", plugin: "dsh-subagent-default-model", form: "notice", summary: label },
|
|
493
|
+
provenance: { role: "inject", label: "dsh-subagent-default-model" },
|
|
494
|
+
form: "notice"
|
|
495
|
+
};
|
|
496
|
+
},
|
|
497
|
+
update: function (context) { return context.state; },
|
|
498
|
+
buildViewNode: function (context) {
|
|
499
|
+
if (context.state === void 0) return null;
|
|
500
|
+
return {
|
|
501
|
+
key: context.key,
|
|
502
|
+
kind: "context",
|
|
503
|
+
id: context.id,
|
|
504
|
+
target: "chat",
|
|
505
|
+
anchorSeq: context.state.seq,
|
|
506
|
+
location: context.start && context.start.location ? context.start.location : { kind: "unresolved" },
|
|
507
|
+
visibility: "visible",
|
|
508
|
+
data: context.state
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
ctx.conversationEvents.register(chatModelDefinition);
|
|
513
|
+
}
|
|
514
|
+
|
|
392
515
|
var subagentScope = ctx.settingsScope.bind({ namespace: SUBAGENT_MODEL_SETTINGS_NS });
|
|
393
516
|
var subagentRowInjected = function () {
|
|
394
517
|
return {
|
package/lib/index.js
CHANGED
|
@@ -21,6 +21,20 @@ import { installSettingsSection, settingsNamespace } from "@deepseek-ai/dsh-sett
|
|
|
21
21
|
*
|
|
22
22
|
* The wrap lives on the service, not on any tool, so it covers every
|
|
23
23
|
* delegation path without touching the core `dsh-tool-subagent` package.
|
|
24
|
+
*
|
|
25
|
+
* Optional subagent-only error failover: with `failoverEnabled` on (the
|
|
26
|
+
* default), this plugin hooks the agent loop's `agent/request-error` and
|
|
27
|
+
* `agent/request` waterfalls (the same seams the community dsh-llm-fallback /
|
|
28
|
+
* dsh-model-failover plugins use) and — when a SUBAGENT's own loop hits a
|
|
29
|
+
* connection failure (rate limit, quota, server/transport error, empty
|
|
30
|
+
* response) — transparently retries that request on another model from the
|
|
31
|
+
* SAME `models` list, following the SAME `strategy` (round-robin advances
|
|
32
|
+
* through the list as a queue; random picks any entry without checking whether
|
|
33
|
+
* it was used before). The gate is `agent.session.header.origin ===
|
|
34
|
+
* "subagent"` (the durable marker every subagent child session carries), so the
|
|
35
|
+
* MAIN agent's loop is never touched: failover is strictly subagent-only by
|
|
36
|
+
* construction. Per-subagent state is cleaned on `agent/disposed`, so a broken
|
|
37
|
+
* subagent primary is not re-tried on every step of the same run.
|
|
24
38
|
*/
|
|
25
39
|
|
|
26
40
|
export const name = "dsh-subagent-default-model";
|
|
@@ -42,12 +56,22 @@ const SUBAGENT_DEFAULT_MODEL_SETTINGS_SCHEMA = z.object({
|
|
|
42
56
|
provider: z.string(),
|
|
43
57
|
model: z.string(),
|
|
44
58
|
models: z.array(MODEL_ENTRY).default([]),
|
|
45
|
-
strategy: z.union([z.const("round-robin"), z.const("random")]).default("round-robin")
|
|
59
|
+
strategy: z.union([z.const("round-robin"), z.const("random")]).default("round-robin"),
|
|
60
|
+
failoverEnabled: z.boolean().default(true)
|
|
46
61
|
}).default({});
|
|
47
62
|
|
|
48
63
|
/** State retained on the raw host service while this plugin fiber is active. */
|
|
49
64
|
const WRAPPED = Symbol.for("dsh-subagent-default-model.wrapped");
|
|
50
65
|
|
|
66
|
+
// ── subagent-only error failover ─────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Failure codes that count as "connection failed" (rate limit, quota, server /
|
|
70
|
+
* transport errors, empty responses). Switching on these is safe because a
|
|
71
|
+
* different model/provider may well succeed where the primary just failed.
|
|
72
|
+
*/
|
|
73
|
+
const FAILOVER_TRIGGER_CODES = ["RATE_LIMIT", "QUOTA", "SERVER", "TIMEOUT", "TRANSPORT", "EMPTY_RESPONSE"];
|
|
74
|
+
|
|
51
75
|
/** Resolve one model entry to `{provider, model}`, or undefined. */
|
|
52
76
|
function resolveEntry(section, entry) {
|
|
53
77
|
if (typeof entry === "string") {
|
|
@@ -103,6 +127,125 @@ function applyDefaultModel(state, request) {
|
|
|
103
127
|
return { ...request, agentOptions: model };
|
|
104
128
|
}
|
|
105
129
|
|
|
130
|
+
// ── subagent-only error failover ─────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
/** Read the live failover view: the `models` list as the switch pool and the strategy. */
|
|
133
|
+
function failoverView(state) {
|
|
134
|
+
const section = state.settingsSource?.();
|
|
135
|
+
if (section === void 0 || section === null) return void 0;
|
|
136
|
+
if (section.failoverEnabled === false) return void 0;
|
|
137
|
+
const entries = Array.isArray(section.models)
|
|
138
|
+
? section.models.map((entry) => resolveEntry(section, entry)).filter((entry) => entry !== void 0)
|
|
139
|
+
: [];
|
|
140
|
+
// A pool of <2 models has nothing to switch to; keep the parent route.
|
|
141
|
+
if (entries.length < 2) return void 0;
|
|
142
|
+
return { entries, strategy: section.strategy === "random" ? "random" : "round-robin" };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** True only for a SUBAGENT-origin agent (the durable session header marker). */
|
|
146
|
+
function isSubagentAgent(agent) {
|
|
147
|
+
return agent !== void 0 && agent !== null && agent.session?.header?.origin === "subagent";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Pick the next pool index for one failed subagent request.
|
|
152
|
+
*
|
|
153
|
+
* - round-robin: the next entry after the currently-served model, wrapping
|
|
154
|
+
* around the list (the "queue").
|
|
155
|
+
* - random: any entry, without checking whether it was used before — a random
|
|
156
|
+
* pick may repeat the failing model, which is fine by design (simplest).
|
|
157
|
+
*/
|
|
158
|
+
function nextFailoverIndex(view, agent, current) {
|
|
159
|
+
const { entries, strategy } = view;
|
|
160
|
+
if (strategy === "random") {
|
|
161
|
+
return Math.floor(Math.random() * entries.length);
|
|
162
|
+
}
|
|
163
|
+
if (current !== void 0) return (current.index + 1) % entries.length;
|
|
164
|
+
// First failure: locate the served route in the pool and move to the next.
|
|
165
|
+
const served = agent.session?.requestContext?.();
|
|
166
|
+
const found = served === void 0 ? -1 : entries.findIndex((entry) =>
|
|
167
|
+
entry.provider === served.provider && entry.model === served.model
|
|
168
|
+
);
|
|
169
|
+
return found < 0 ? 0 : (found + 1) % entries.length;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Install the subagent-only failover waterfalls. Both listeners no-op for the
|
|
174
|
+
* main agent (origin gate) and for subagents whose failure code is not a
|
|
175
|
+
* connection failure, so a broken subagent primary is re-tried on the next
|
|
176
|
+
* pool model without ever touching the parent loop. State is keyed per
|
|
177
|
+
* subagent run (`agent.id`) and cleaned on `agent/disposed`, so a persistently
|
|
178
|
+
* broken primary is not re-tried on every step of the same run.
|
|
179
|
+
*/
|
|
180
|
+
function installFailover(ctx, state) {
|
|
181
|
+
const pending = new Map();
|
|
182
|
+
|
|
183
|
+
// After a model failure on a subagent loop: advance the pool index and ask
|
|
184
|
+
// the loop to rebuild the request (`{ kind: "retry" }`). When every pool
|
|
185
|
+
// entry has been tried, let the real error surface untouched.
|
|
186
|
+
const disposeRequestError = ctx.on("agent/request-error", (payload, next) => {
|
|
187
|
+
const view = failoverView(state);
|
|
188
|
+
if (view === void 0) return next();
|
|
189
|
+
const { agent, turn, step, failure, signal } = payload;
|
|
190
|
+
if (signal?.aborted) return next();
|
|
191
|
+
if (!isSubagentAgent(agent)) return next();
|
|
192
|
+
if (failure === void 0 || !FAILOVER_TRIGGER_CODES.includes(failure.code)) return next();
|
|
193
|
+
const current = pending.get(agent.id);
|
|
194
|
+
// The primary already failed (that triggered the first switch), so the
|
|
195
|
+
// remaining candidates are the other pool entries: at most
|
|
196
|
+
// `entries.length - 1` switches, then let the real error surface.
|
|
197
|
+
if (current !== void 0 && current.count >= view.entries.length - 1) return next(); // pool exhausted
|
|
198
|
+
const index = nextFailoverIndex(view, agent, current);
|
|
199
|
+
pending.set(agent.id, {
|
|
200
|
+
index,
|
|
201
|
+
count: (current?.count ?? 0) + 1
|
|
202
|
+
});
|
|
203
|
+
ctx.logger.warn(
|
|
204
|
+
`[dsh-subagent-default-model] subagent %s failed with %s on turn %d step %d; switching to %s/%s (attempt %d/%d, strategy=%s)`,
|
|
205
|
+
agent.id,
|
|
206
|
+
failure.code,
|
|
207
|
+
turn,
|
|
208
|
+
step,
|
|
209
|
+
view.entries[index].provider,
|
|
210
|
+
view.entries[index].model,
|
|
211
|
+
(current?.count ?? 0) + 1,
|
|
212
|
+
view.entries.length,
|
|
213
|
+
view.strategy
|
|
214
|
+
);
|
|
215
|
+
return { kind: "retry" };
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// On the rebuilt request for that subagent: swap the seed route for the
|
|
219
|
+
// pending pool entry. Inherited reasoningEffort is dropped on a provider
|
|
220
|
+
// switch (the fallback provider may not support it).
|
|
221
|
+
const disposeRequest = ctx.on("agent/request", async (payload, next) => {
|
|
222
|
+
const view = failoverView(state);
|
|
223
|
+
if (view === void 0) return next();
|
|
224
|
+
const { agent } = payload;
|
|
225
|
+
if (!isSubagentAgent(agent)) return next();
|
|
226
|
+
const current = pending.get(agent.id);
|
|
227
|
+
if (current === void 0) return next();
|
|
228
|
+
const target = view.entries[current.index];
|
|
229
|
+
if (target === void 0) return next();
|
|
230
|
+
const seed = await next();
|
|
231
|
+
if (seed === void 0 || seed === null) return seed;
|
|
232
|
+
const { reasoningEffort: _inherited, ...rest } = seed;
|
|
233
|
+
return { ...rest, provider: target.provider, model: target.model };
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Drop per-agent state once the subagent is disposed.
|
|
237
|
+
const disposeDisposed = ctx.on("agent/disposed", ({ agent }) => {
|
|
238
|
+
pending.delete(agent.id);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
ctx.effect(() => () => {
|
|
242
|
+
disposeRequestError();
|
|
243
|
+
disposeRequest();
|
|
244
|
+
disposeDisposed();
|
|
245
|
+
pending.clear();
|
|
246
|
+
}, "dsh-subagent-default-model: failover listeners");
|
|
247
|
+
}
|
|
248
|
+
|
|
106
249
|
export function apply(ctx) {
|
|
107
250
|
const state = {
|
|
108
251
|
settingsSource: void 0,
|
|
@@ -121,6 +264,11 @@ export function apply(ctx) {
|
|
|
121
264
|
onChange: () => {}
|
|
122
265
|
});
|
|
123
266
|
|
|
267
|
+
// Subagent-only failover hooks the agent loop, not the subagents service,
|
|
268
|
+
// so it is installed unconditionally: listeners no-op when the `failover`
|
|
269
|
+
// section is absent/disabled or when the failing agent is the main loop.
|
|
270
|
+
installFailover(ctx, state);
|
|
271
|
+
|
|
124
272
|
// `ctx.subagents` is a per-call Cordis traceable proxy, so reach the raw
|
|
125
273
|
// service object behind it for a stable handle and to install own methods.
|
|
126
274
|
const raw = ctx.subagents?.[Symbol.for("cordis.original")] ?? ctx.subagents;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-subagent-default-model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Configure default model routes for DeepSeek Harness subagents, with single-model, round-robin, random, and per-route reasoning-effort options.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -44,7 +44,9 @@
|
|
|
44
44
|
"CHANGELOG.md"
|
|
45
45
|
],
|
|
46
46
|
"scripts": {
|
|
47
|
-
"test": "node --test test/*.test.mjs"
|
|
47
|
+
"test": "node --test test/*.test.mjs",
|
|
48
|
+
"mock": "node scripts/mock-llm-server.mjs",
|
|
49
|
+
"simulate": "node scripts/simulate-retry.mjs"
|
|
48
50
|
},
|
|
49
51
|
"dsh": {
|
|
50
52
|
"bundle": {
|