dsh-subagent-default-model 0.3.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 ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 (2026-08-23)
4
+
5
+ ### Features
6
+
7
+ - **推理强度选择**: 设置面板每行模型路由新增「推理强度」(Reasoning Strength) 下拉菜单,模型支持时自动加载可选强度(如 `high`/`medium`/`low`),不支持时显示「Default」
8
+ - **Host 侧支持**: schema 和 resolve 逻辑透传 `reasoningEffort` 到子代理的 `agentOptions`,覆盖单模型和多模型两种配置模式
9
+ - **Web UI 适配**: 设置面板 grid 从 3 列扩展为 4 列,新增中英文 locale 字段
10
+
11
+ ### Fixes
12
+
13
+ - **序列化兼容**: `normalizeDefaultModels` 修复模型条目缺 `provider` 时继承顶层 provider 的逻辑
14
+ - **保存校验**: `serializeDefaultModels` 正确处理 `reasoningEffort` 字段序列化
15
+
16
+ ## 0.2.0 (2026-08-19)
17
+
18
+ ### Features
19
+
20
+ - 多模型支持:`models` 列表 + `round-robin` / `random` 策略
21
+ - 设置热重载:配置变更立即生效,无需重启
22
+
23
+ ## 0.1.1 (2026-08-18)
24
+
25
+ ### Features
26
+
27
+ - Web 设置面板(通用设置 → 子代理默认模型)
28
+ - 保存成功 Toast 通知
29
+
30
+ ## 0.1.0 (2026-08-16)
31
+
32
+ ### Features
33
+
34
+ - 初始版本:单模型默认注入
35
+ - Host 侧 `ctx.subagents` 服务包装(`start` / `startContinuable`)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 dingminhua
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # dsh-subagent-default-model
2
+
3
+ Default model for subagent delegations in [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/deepseek-harness), configurable via `~/.dsh/settings.yaml`.
4
+
5
+ When a subagent is created without an explicit `model`, this plugin injects the configured default — so every `subagent`, `subagent_fork`, and any tool that omits `agentOptions` routes through it. Explicit per-call overrides always win; an absent or incomplete settings section keeps the historical behavior (children inherit the parent route).
6
+
7
+ ## Features
8
+
9
+ - **Single model** — all subagents run on one configured model.
10
+ - **Multi-model** — a `models` list with `round-robin` or `random` strategy spreads parallel subagents across models.
11
+ - **Reasoning strength** — optionally specify `reasoningEffort` per model entry (e.g. `high`, `medium`, `low`); the Web UI loads available efforts from the model catalog.
12
+ - **Hot-reload** — settings changes apply to the very next delegation.
13
+ - **Clean teardown** — Cordis disposal restores the original service methods.
14
+
15
+ ## Screenshots
16
+
17
+ **Settings panel** (`Settings → General → Subagent default model`): configure one or more model routes with `round-robin` / `random` strategy and per-route reasoning effort.
18
+
19
+ ![Subagent default model settings panel](https://raw.githubusercontent.com/dingminhua/dsh-subagent-default-model/main/assets/pic_01.png)
20
+
21
+ **Effect verification**: 10 subagents split 5/5 between `deepseek-v4-flash` and `Kimi-k3` (round-robin).
22
+
23
+ ![Subagent default model distribution](https://raw.githubusercontent.com/dingminhua/dsh-subagent-default-model/main/assets/pic_02.png)
24
+
25
+ ## Marketplace
26
+
27
+ [![dshfind plugin](https://dshfind.com/api/badge/dingminhua/dsh-subagent-default-model)](https://dshfind.com/plugins/dingminhua/dsh-subagent-default-model)
28
+
29
+ ## Install
30
+
31
+ 从 npm registry 安装:
32
+
33
+ ```sh
34
+ npm install dsh-subagent-default-model
35
+ ```
36
+
37
+ 或通过 DSH 插件命令(等价,内部同样走 npm):
38
+
39
+ ```sh
40
+ dsh plugin --profile desktop add dsh-subagent-default-model
41
+ ```
42
+
43
+ ## Release / Publish
44
+
45
+ 发布到 npm registry:
46
+
47
+ ```sh
48
+ # 1. 更新版本号(plugin/package.json 的 version 字段)和 CHANGELOG.md
49
+ # 2. 提交并打标签
50
+ git add -A
51
+ git commit -m "feat: ..."
52
+ git tag v0.3.1
53
+ git push origin main --tags
54
+
55
+ # 3. 发布到 npm
56
+ cd plugin
57
+ npm login # 首次发布前登录一次
58
+ npm publish
59
+ ```
60
+
61
+ > ⚠️ 发布前先跑一遍测试:`npm --prefix plugin test`。
62
+ > `package.json` 的 `files` 字段已限定只发布 `lib/`、`cordis.patch.yml`、`LICENSE`、`README.md`、`CHANGELOG.md`,`test/` 和 `node_modules/` 不会进入发布包。
63
+
64
+ 本地安装(DSH Desktop / desktop profile):
65
+
66
+ ```sh
67
+ # 在 ~/.dsh/profiles/desktop 下执行(或使用 dsh plugin 命令)
68
+ npm install dsh-subagent-default-model
69
+ # 或本地开发:dsh plugin --profile desktop add /路径/plugin(link: 安装,改码即时生效)
70
+ ```
71
+
72
+ 说明:
73
+
74
+ - 本地开发用 `link:` 安装:`dsh plugin --profile desktop add /Users/dmh2002/DshProject/dsh-subagent-default-model/plugin`,node_modules 里是源码软链,改代码后**重启 DSH Desktop** 生效
75
+ - 正式安装 / 他机安装使用 npm registry 版本(见上方 Install)
76
+
77
+ ## Configuration
78
+
79
+ Add to `~/.dsh/settings.yaml`:
80
+
81
+ ```yaml
82
+ # Single model
83
+ subagent-default-model:
84
+ provider: deepseek-official
85
+ model: deepseek-v4-pro
86
+
87
+ # Or multiple models
88
+ subagent-default-model:
89
+ provider: deepseek-official
90
+ models:
91
+ - deepseek-v4-pro
92
+ - deepseek-v4-flash
93
+ strategy: round-robin # round-robin | random
94
+
95
+ # With reasoning strength
96
+ subagent-default-model:
97
+ provider: deepseek-official
98
+ models:
99
+ - model: deepseek-v4-reasoner
100
+ reasoningEffort: high
101
+ - provider: other-provider
102
+ model: gpt-5.6
103
+ reasoningEffort: max
104
+ strategy: round-robin # round-robin | random
105
+ ```
106
+
107
+ | Field | Type | Default | Description |
108
+ | --- | --- | --- | --- |
109
+ | `provider` | string | — | Provider for string-type model entries. |
110
+ | `model` | string | — | Single model id (backward compatible). |
111
+ | `models` | array | `[]` | List of model entries (string or `{provider, model, reasoningEffort?}` pair). |
112
+ | `strategy` | string | `round-robin` | Selection strategy: `round-robin` or `random`. |
113
+ | `reasoningEffort` | string | — | Optional reasoning strength for a model entry (e.g. `high`, `max`). |
114
+
115
+ ## How it works
116
+
117
+ ```text
118
+ Explicit agentOptions on the request
119
+ → subagent-default-model settings
120
+ → inherit parent session route
121
+ ```
122
+
123
+ The plugin wraps the host `ctx.subagents` service (`start` / `startContinuable`), so it covers every delegation path — built-in `subagent` / `subagent_fork` tools and any custom tool that calls the service without providing `agentOptions`.
124
+
125
+ ## License
126
+
127
+ [MIT](LICENSE)
@@ -0,0 +1,8 @@
1
+ # dsh-subagent-default-model bundle patch: one host plugin row that registers
2
+ # the `subagent-default-model` settings section and wraps the host subagents
3
+ # service, so every delegation without an explicit `agentOptions` (the stock
4
+ # `subagent` / `subagent_fork` tools and any other tool that omits model or
5
+ # provider) runs the child on the configured default model.
6
+ - insert:
7
+ - id: dsh-subagent-default-model
8
+ name: 'dsh-subagent-default-model'
package/lib/client.js ADDED
@@ -0,0 +1,369 @@
1
+ // dsh-subagent-default-model client — settings panel for the subagent default model.
2
+ // Extracted from @aaravarr/dsh-subagent-max (licensed MIT) and adapted as a
3
+ // standalone client entry for this plugin.
4
+
5
+ window.__ModuleLoader__.load({
6
+ id: "dsh-subagent-default-model",
7
+ factory: function (require) {
8
+ var React = require("react");
9
+ var primitives = require("@deepseek-ai/dsh-client-ui-primitives");
10
+ var Button = primitives.Button;
11
+ var Toast = primitives.Toast;
12
+
13
+ // ── CSS ──────────────────────────────────────────────────────────────
14
+ var SETTINGS_CSS = ".dsm-model-settings{display:flex;flex-direction:column;gap:14px;margin:20px 0;padding:14px 16px;background:var(--dsw-alias-bg-module-platform,var(--dsw-alias-bg-layer-1,#1c1d21));border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:12px}.dsm-model-settings-head{display:flex;flex-direction:column;gap:4px}.dsm-model-settings-title{font-size:14px;line-height:20px;font-weight:600;color:var(--dsw-alias-label-primary,#e6e6e6)}.dsm-model-settings-desc{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-list{display:flex;flex-direction:column;gap:8px}.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:8px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px}.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%;height:32px;padding:0 28px 0 9px;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}.dsm-model-settings-select:focus{outline:2px solid var(--dsw-alias-state-business-primary,#5686fe);outline-offset:1px}.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}.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:end;justify-content:space-between;gap:12px;flex-wrap:wrap}.dsm-model-settings-strategy{min-width:180px}.dsm-model-settings-actions{display:flex;align-items:center;gap:8px}.dsm-model-settings-status{font-size:12px;line-height:18px;color:var(--dsw-alias-state-success-primary,#22c55e)}.dsm-model-settings-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}";
15
+
16
+ if (typeof document !== "undefined") {
17
+ var cssId = "dsh-subagent-default-model/client.css";
18
+ if (!document.querySelector("style[data-plugin-css='" + cssId + "']")) {
19
+ var styleTag = document.createElement("style");
20
+ styleTag.dataset.plugin = "dsh-subagent-default-model";
21
+ styleTag.dataset.pluginCss = cssId;
22
+ styleTag.textContent = SETTINGS_CSS;
23
+ document.head.appendChild(styleTag);
24
+ }
25
+ }
26
+
27
+ // ── locale ───────────────────────────────────────────────────────────
28
+ var SUBAGENT_ROW_LOCALE = "settings.subagentModel";
29
+ var SUBAGENT_ROW_ZH = {
30
+ "row.title": "子代理默认模型",
31
+ "row.desc": "为 subagent / subagent_fork 选择一个或多个默认路由;清空后子代理继承父会话路由。",
32
+ "row.provider": "Provider",
33
+ "row.model": "Model",
34
+ "row.effort": "推理强度",
35
+ "row.add": "添加模型",
36
+ "row.remove": "移除模型",
37
+ "row.strategy": "分配策略",
38
+ "row.roundRobin": "轮换",
39
+ "row.random": "随机",
40
+ "row.inherit": "(继承父会话路由)",
41
+ "row.empty": "尚未指定默认模型,子代理将继承父会话路由。",
42
+ "row.effortDefault": "Default",
43
+ "row.save": "保存",
44
+ "row.saved": "已保存",
45
+ "row.incomplete": "请为每个模型路由选择 Provider 和 Model。",
46
+ "row.saveFailed": "保存失败,请重试。",
47
+ "row.toastSaved": "子代理默认模型设置已保存。"
48
+ };
49
+ var SUBAGENT_ROW_EN = {
50
+ "row.title": "Subagent default model",
51
+ "row.desc": "Choose one or more default routes for subagent / subagent_fork; clear them to inherit the parent session route.",
52
+ "row.provider": "Provider",
53
+ "row.model": "Model",
54
+ "row.effort": "Reasoning strength",
55
+ "row.add": "Add model",
56
+ "row.remove": "Remove model",
57
+ "row.strategy": "Distribution",
58
+ "row.roundRobin": "Round-robin",
59
+ "row.random": "Random",
60
+ "row.inherit": "(inherit parent route)",
61
+ "row.effortDefault": "Default",
62
+ "row.empty": "No default model is selected; subagents inherit the parent route.",
63
+ "row.save": "Save",
64
+ "row.saved": "Saved",
65
+ "row.incomplete": "Choose a provider and model for every route.",
66
+ "row.saveFailed": "Could not save the setting. Try again.",
67
+ "row.toastSaved": "Subagent default model settings saved."
68
+ };
69
+
70
+ // ── helpers ──────────────────────────────────────────────────────────
71
+ var SUBAGENT_MODEL_SETTINGS_NS = "subagent-default-model";
72
+
73
+ function normalizeDefaultModels(value) {
74
+ var result = [];
75
+ if (Array.isArray(value.models) && value.models.length > 0) {
76
+ for (var i = 0; i < value.models.length; i++) {
77
+ var entry = value.models[i];
78
+ if (typeof entry === "string") result.push({ provider: value.provider || "", model: entry, reasoningEffort: "" });
79
+ else if (entry && typeof entry === "object") result.push({ provider: entry.provider || value.provider || "", model: entry.model || "", reasoningEffort: entry.reasoningEffort || "" });
80
+ }
81
+ } else if (value.provider || value.model) {
82
+ result.push({ provider: value.provider || "", model: value.model || "", reasoningEffort: value.reasoningEffort || "" });
83
+ }
84
+ return result;
85
+ }
86
+
87
+ function serializeDefaultModels(previousValue, routes, strategy) {
88
+ var next = Object.assign({}, previousValue || {});
89
+ if (routes.length === 0) {
90
+ next.provider = "";
91
+ next.model = "";
92
+ next.models = [];
93
+ next.strategy = "round-robin";
94
+ delete next.reasoningEffort;
95
+ return next;
96
+ }
97
+ var provider = routes[0].provider;
98
+ var sharedEffort = routes[0].reasoningEffort;
99
+ var allSameEffort = routes.every(function (route) { return route.reasoningEffort === sharedEffort; });
100
+ next.provider = provider;
101
+ next.model = "";
102
+ next.models = routes.map(function (route) {
103
+ if (route.provider === provider && !route.reasoningEffort) {
104
+ return route.model;
105
+ }
106
+ var base = { provider: route.provider, model: route.model };
107
+ if (route.reasoningEffort) {
108
+ base.reasoningEffort = route.reasoningEffort;
109
+ }
110
+ return base;
111
+ });
112
+ next.strategy = strategy === "random" ? "random" : "round-robin";
113
+ if (allSameEffort && sharedEffort) {
114
+ next.reasoningEffort = sharedEffort;
115
+ } else {
116
+ delete next.reasoningEffort;
117
+ }
118
+ return next;
119
+ }
120
+
121
+ function persistDefaultModels(scope, value) {
122
+ return Promise.resolve().then(function () { return scope.set("provider", value.provider); }).then(function () {
123
+ return scope.set("model", value.model);
124
+ }).then(function () {
125
+ return scope.set("models", value.models);
126
+ }).then(function () {
127
+ return scope.set("strategy", value.strategy);
128
+ }).then(function () {
129
+ return scope.set("reasoningEffort", value.reasoningEffort || "");
130
+ });
131
+ }
132
+
133
+ function useSettingsScopeSnapshot(scope) {
134
+ var snapshotState = React.useState(scope.getSnapshot());
135
+ React.useEffect(function () {
136
+ function update() { snapshotState[1](scope.getSnapshot()); }
137
+ return scope.subscribe(update);
138
+ }, [scope]);
139
+ return snapshotState[0];
140
+ }
141
+
142
+ // ── SubagentModelRow component ───────────────────────────────────────
143
+ function SubagentModelRow(props) {
144
+ var t = props.t;
145
+ var snap = useSettingsScopeSnapshot(props.settingsScope);
146
+ var value = (snap && snap.status === "ready" && snap.value) || {};
147
+ var groupsState = React.useState([]);
148
+ var routesState = React.useState(normalizeDefaultModels(value));
149
+ var strategyState = React.useState(value.strategy === "random" ? "random" : "round-robin");
150
+ var savedState = React.useState(false);
151
+ var saveErrorState = React.useState(false);
152
+ var toastState = React.useState(null);
153
+ var toastSeq = React.useRef(0);
154
+ var dirtyState = React.useState(false);
155
+ var busyState = React.useState(false);
156
+ React.useEffect(function () {
157
+ var alive = true;
158
+ props.loadCatalog().then(function (groups) {
159
+ if (alive) groupsState[1](groups);
160
+ }).catch(function () {});
161
+ return function () { alive = false; };
162
+ }, []);
163
+ React.useEffect(function () {
164
+ if (dirtyState[0] || busyState[0]) return;
165
+ routesState[1](normalizeDefaultModels(value));
166
+ strategyState[1](value.strategy === "random" ? "random" : "round-robin");
167
+ savedState[1](false);
168
+ saveErrorState[1](false);
169
+ }, [snap ? snap.revision : -1, dirtyState[0], busyState[0]]);
170
+ function updateRoute(index, field, nextValue) {
171
+ routesState[1](function (routes) {
172
+ return routes.map(function (route, routeIndex) {
173
+ if (routeIndex !== index) return route;
174
+ var next = { provider: route.provider, model: route.model, reasoningEffort: route.reasoningEffort || "" };
175
+ next[field] = nextValue;
176
+ if (field === "provider") {
177
+ next.model = "";
178
+ next.reasoningEffort = "";
179
+ }
180
+ return next;
181
+ });
182
+ });
183
+ savedState[1](false);
184
+ saveErrorState[1](false);
185
+ dirtyState[1](true);
186
+ }
187
+ function addRoute() {
188
+ var firstGroup = groupsState[0][0];
189
+ routesState[1](function (routes) {
190
+ return routes.concat({ provider: firstGroup ? firstGroup.id : "", model: "", reasoningEffort: "" });
191
+ });
192
+ savedState[1](false);
193
+ saveErrorState[1](false);
194
+ dirtyState[1](true);
195
+ }
196
+ function removeRoute(index) {
197
+ routesState[1](function (routes) { return routes.filter(function (_, routeIndex) { return routeIndex !== index; }); });
198
+ savedState[1](false);
199
+ saveErrorState[1](false);
200
+ dirtyState[1](true);
201
+ }
202
+ function save() {
203
+ if (!snap || snap.status !== "ready" || snap.writable === false || busyState[0]) return;
204
+ var nextValue = serializeDefaultModels(value, routesState[0], strategyState[0]);
205
+ savedState[1](false);
206
+ saveErrorState[1](false);
207
+ busyState[1](true);
208
+ Promise.resolve().then(function () {
209
+ return props.write(nextValue);
210
+ }).then(function () {
211
+ var accepted = props.settingsScope.getSnapshot();
212
+ var acceptedValue = (accepted && accepted.status === "ready" && accepted.value) || {};
213
+ 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 || [])) {
214
+ throw new Error("settings write was not accepted");
215
+ }
216
+ routesState[1](normalizeDefaultModels(acceptedValue));
217
+ strategyState[1](acceptedValue.strategy === "random" ? "random" : "round-robin");
218
+ dirtyState[1](false);
219
+ busyState[1](false);
220
+ savedState[1](true);
221
+ toastSeq.current = toastSeq.current + 1;
222
+ toastState[1]({ seq: toastSeq.current, text: t("row.toastSaved") });
223
+ }).catch(function () {
224
+ busyState[1](false);
225
+ saveErrorState[1](true);
226
+ });
227
+ }
228
+ var hasIncompleteRoute = routesState[0].some(function (route) { return !route.provider || !route.model; });
229
+ var saveDisabled = !snap || snap.status !== "ready" || snap.writable === false || busyState[0] || hasIncompleteRoute;
230
+ var routes = routesState[0].map(function (route, index) {
231
+ var group = null;
232
+ for (var groupIndex = 0; groupIndex < groupsState[0].length; groupIndex++) {
233
+ if (groupsState[0][groupIndex].id === route.provider) { group = groupsState[0][groupIndex]; break; }
234
+ }
235
+ var providerChoices = groupsState[0].slice();
236
+ if (route.provider && !group) providerChoices.unshift({ id: route.provider, name: route.provider });
237
+ var modelChoices = group ? (group.models || []).slice() : [];
238
+ if (route.model && !modelChoices.some(function (candidate) { return candidate.id === route.model; })) {
239
+ modelChoices.unshift({ id: route.model, name: route.model });
240
+ }
241
+ var selectedModel = null;
242
+ for (var modelIndex = 0; modelIndex < modelChoices.length; modelIndex++) {
243
+ if (modelChoices[modelIndex].id === route.model) { selectedModel = modelChoices[modelIndex]; break; }
244
+ }
245
+ var effortChoices = selectedModel && selectedModel.reasoning && Array.isArray(selectedModel.reasoning.efforts) ? selectedModel.reasoning.efforts.slice() : [];
246
+ if (route.reasoningEffort && !effortChoices.some(function (candidate) { return candidate.id === route.reasoningEffort; })) {
247
+ effortChoices.unshift({ id: route.reasoningEffort, name: route.reasoningEffort });
248
+ }
249
+ return React.createElement("div", { className: "dsm-model-settings-route", key: index },
250
+ React.createElement("label", { className: "dsm-model-settings-field" },
251
+ t("row.provider"),
252
+ React.createElement("select", {
253
+ className: "dsm-model-settings-select",
254
+ value: route.provider,
255
+ onChange: function (event) { updateRoute(index, "provider", event.target.value); }
256
+ },
257
+ React.createElement("option", { value: "" }, t("row.inherit")),
258
+ providerChoices.map(function (candidate) {
259
+ return React.createElement("option", { key: candidate.id, value: candidate.id }, candidate.name + " (" + candidate.id + ")");
260
+ })
261
+ )
262
+ ),
263
+ React.createElement("label", { className: "dsm-model-settings-field" },
264
+ t("row.model"),
265
+ React.createElement("select", {
266
+ className: "dsm-model-settings-select",
267
+ value: route.model,
268
+ disabled: !route.provider,
269
+ onChange: function (event) { updateRoute(index, "model", event.target.value); }
270
+ },
271
+ React.createElement("option", { value: "" }, t("row.inherit")),
272
+ modelChoices.map(function (candidate) {
273
+ return React.createElement("option", { key: candidate.id, value: candidate.id }, candidate.name || candidate.id);
274
+ })
275
+ )
276
+ ),
277
+ React.createElement("label", { className: "dsm-model-settings-field" },
278
+ t("row.effort"),
279
+ React.createElement("select", {
280
+ className: "dsm-model-settings-select",
281
+ value: route.reasoningEffort || "",
282
+ disabled: !route.model,
283
+ onChange: function (event) { updateRoute(index, "reasoningEffort", event.target.value); }
284
+ },
285
+ React.createElement("option", { value: "" }, t("row.effortDefault")),
286
+ effortChoices.map(function (candidate) {
287
+ return React.createElement("option", { key: candidate.id, value: candidate.id }, candidate.name || candidate.id);
288
+ })
289
+ )
290
+ ),
291
+ React.createElement("button", {
292
+ className: "dsm-model-settings-remove",
293
+ type: "button",
294
+ "aria-label": t("row.remove"),
295
+ title: t("row.remove"),
296
+ onClick: function () { removeRoute(index); }
297
+ }, "\u00d7")
298
+ );
299
+ });
300
+ return React.createElement("section", { className: "dsm-model-settings" },
301
+ React.createElement("div", { className: "dsm-model-settings-head" },
302
+ React.createElement("div", { className: "dsm-model-settings-title" }, t("row.title")),
303
+ React.createElement("div", { className: "dsm-model-settings-desc" }, t("row.desc"))
304
+ ),
305
+ routes.length ? React.createElement("div", { className: "dsm-model-settings-list" }, routes) : React.createElement("div", { className: "dsm-model-settings-hint" }, t("row.empty")),
306
+ React.createElement("div", { className: "dsm-model-settings-options" },
307
+ React.createElement(Button, { type: "button", variant: "outline", size: "sm", onClick: addRoute }, t("row.add")),
308
+ routes.length > 1 ? React.createElement("label", { className: "dsm-model-settings-field dsm-model-settings-strategy" },
309
+ t("row.strategy"),
310
+ React.createElement("select", {
311
+ className: "dsm-model-settings-select",
312
+ value: strategyState[0],
313
+ onChange: function (event) { strategyState[1](event.target.value); savedState[1](false); saveErrorState[1](false); dirtyState[1](true); }
314
+ },
315
+ React.createElement("option", { value: "round-robin" }, t("row.roundRobin")),
316
+ React.createElement("option", { value: "random" }, t("row.random"))
317
+ )
318
+ ) : null
319
+ ),
320
+ hasIncompleteRoute ? React.createElement("div", { className: "dsm-model-settings-hint" }, t("row.incomplete")) : null,
321
+ saveErrorState[0] ? React.createElement("div", { className: "dsm-model-settings-hint", role: "alert" }, t("row.saveFailed")) : null,
322
+ React.createElement("div", { className: "dsm-model-settings-actions" },
323
+ React.createElement(Button, { type: "button", variant: "primary", size: "sm", disabled: saveDisabled, onClick: save }, busyState[0] ? t("row.save") + "\u2026" : (savedState[0] ? t("row.saved") : t("row.save"))),
324
+ savedState[0] ? React.createElement("span", { className: "dsm-model-settings-status" }, t("row.saved")) : null
325
+ ),
326
+ toastState[0] ? React.createElement(Toast, { key: toastState[0].seq, text: toastState[0].text, onDone: function () { toastState[1](null); } }) : null
327
+ );
328
+ }
329
+
330
+ // ── apply: inject settings row ───────────────────────────────────────
331
+ var inject = ["sessions", "connection", "slots", "locale", "settingsScope", "remote"];
332
+
333
+ function apply(ctx) {
334
+ var api = ctx.connection.api;
335
+
336
+ // Register locale for this component
337
+ ctx.locale.register(SUBAGENT_ROW_LOCALE, "zh", SUBAGENT_ROW_ZH);
338
+ ctx.locale.register(SUBAGENT_ROW_LOCALE, "en", SUBAGENT_ROW_EN);
339
+
340
+ var subagentScope = ctx.settingsScope.bind({ namespace: SUBAGENT_MODEL_SETTINGS_NS });
341
+ var subagentRowInjected = function () {
342
+ return {
343
+ settingsScope: subagentScope,
344
+ loadCatalog: function () {
345
+ return api.llm.models({}).then(function (r) {
346
+ if (!r.result.ok) throw new Error("llm.models failed: " + r.result.error.code);
347
+ return r.result.value.groups || [];
348
+ });
349
+ },
350
+ write: function (value) {
351
+ return persistDefaultModels(subagentScope, value);
352
+ }
353
+ };
354
+ };
355
+
356
+ ctx.slots.inject("settings.general.item", function () {
357
+ return ctx.slots.register({
358
+ name: "settings.general.item",
359
+ id: "subagent-model",
360
+ order: 5,
361
+ locale: SUBAGENT_ROW_LOCALE,
362
+ inject: subagentRowInjected
363
+ }, SubagentModelRow);
364
+ });
365
+ }
366
+
367
+ return { apply: apply, inject: inject };
368
+ }
369
+ });
package/lib/index.js ADDED
@@ -0,0 +1,158 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { installSettingsSection, settingsNamespace } from "@deepseek-ai/dsh-settings";
3
+
4
+ /**
5
+ * dsh-subagent-default-model — default model(s) for subagent delegations.
6
+ *
7
+ * Host-plane plugin. It registers the shared `subagent-default-model` settings
8
+ * section (`~/.dsh/settings.yaml`) and wraps the host `ctx.subagents` service
9
+ * (`start` / `startContinuable`), so any delegation whose request carries no
10
+ * explicit `agentOptions` (the stock `subagent` / `subagent_fork` tools and
11
+ * every other tool that omits model/provider) creates the child with a
12
+ * configured default model. Explicit per-call overrides (e.g.
13
+ * `subagent_with_model`) always win; an absent or incomplete settings section
14
+ * keeps the historical behavior: children inherit the parent session route.
15
+ *
16
+ * Multiple models are supported: the `models` list is picked from on every
17
+ * delegation either round-robin (default) or at random (`strategy`), so a
18
+ * batch of parallel subagents spreads across the configured models. The
19
+ * selection is re-evaluated on every call (settings hot-reload + live picker
20
+ * state), so configuration changes apply to the very next delegation.
21
+ *
22
+ * The wrap lives on the service, not on any tool, so it covers every
23
+ * delegation path without touching the core `dsh-tool-subagent` package.
24
+ */
25
+
26
+ export const name = "dsh-subagent-default-model";
27
+ export const inject = ["subagents"];
28
+
29
+ /** Settings namespace: default model route for subagent runs without an explicit `agentOptions`. */
30
+ const SUBAGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE = settingsNamespace("subagent-default-model");
31
+ /** One model entry: a bare model id (uses the section `provider`) or an explicit `{provider, model}` pair. */
32
+ const MODEL_ENTRY = z.union([
33
+ z.string(),
34
+ z.object({
35
+ provider: z.string(),
36
+ model: z.string(),
37
+ reasoningEffort: z.string()
38
+ })
39
+ ]);
40
+ /** Schema of the `subagent-default-model` settings section; an absent section keeps inheriting the parent route. */
41
+ const SUBAGENT_DEFAULT_MODEL_SETTINGS_SCHEMA = z.object({
42
+ provider: z.string(),
43
+ model: z.string(),
44
+ models: z.array(MODEL_ENTRY).default([]),
45
+ strategy: z.union([z.const("round-robin"), z.const("random")]).default("round-robin")
46
+ }).default({});
47
+
48
+ /** State retained on the raw host service while this plugin fiber is active. */
49
+ const WRAPPED = Symbol.for("dsh-subagent-default-model.wrapped");
50
+
51
+ /** Resolve one model entry to `{provider, model}`, or undefined. */
52
+ function resolveEntry(section, entry) {
53
+ if (typeof entry === "string") {
54
+ if (entry.length === 0) return void 0;
55
+ if (typeof section.provider !== "string" || section.provider.length === 0) return void 0;
56
+ return { provider: section.provider, model: entry };
57
+ }
58
+ if (entry !== null && typeof entry === "object") {
59
+ if (typeof entry.provider !== "string" || entry.provider.length === 0) return void 0;
60
+ if (typeof entry.model !== "string" || entry.model.length === 0) return void 0;
61
+ const resolved = { provider: entry.provider, model: entry.model };
62
+ if (typeof entry.reasoningEffort === "string" && entry.reasoningEffort.length > 0) {
63
+ resolved.reasoningEffort = entry.reasoningEffort;
64
+ }
65
+ return resolved;
66
+ }
67
+ return void 0;
68
+ }
69
+
70
+ /** Pick the next default model from the live settings section, or undefined to inherit the parent route. */
71
+ function defaultModel(state) {
72
+ const section = state.settingsSource?.();
73
+ if (section === void 0 || section === null) return void 0;
74
+
75
+ // Multi-model list wins; pick per strategy.
76
+ const entries = Array.isArray(section.models) ? section.models.filter((entry) => resolveEntry(section, entry) !== void 0) : [];
77
+ if (entries.length > 0) {
78
+ const picked = section.strategy === "random"
79
+ ? entries[Math.floor(Math.random() * entries.length)]
80
+ : entries[state.rrCursor++ % entries.length];
81
+ return resolveEntry(section, picked);
82
+ }
83
+
84
+ // Single-model form (backward compatible).
85
+ if (typeof section.model === "string" && section.model.length > 0) {
86
+ if (typeof section.provider !== "string" || section.provider.length === 0) return void 0;
87
+ const result = { provider: section.provider, model: section.model };
88
+ if (typeof section.reasoningEffort === "string" && section.reasoningEffort.length > 0) {
89
+ result.reasoningEffort = section.reasoningEffort;
90
+ }
91
+ return result;
92
+ }
93
+
94
+ return void 0;
95
+ }
96
+
97
+ /** Inject the default model into one delegation request unless it already names one. */
98
+ function applyDefaultModel(state, request) {
99
+ if (request === void 0 || request === null) return request;
100
+ if (request.agentOptions !== void 0) return request;
101
+ const model = defaultModel(state);
102
+ if (model === void 0) return request;
103
+ return { ...request, agentOptions: model };
104
+ }
105
+
106
+ export function apply(ctx) {
107
+ const state = {
108
+ settingsSource: void 0,
109
+ rrCursor: 0
110
+ };
111
+
112
+ // The settings seam owns its own injected lifecycle and provides a live
113
+ // source thunk. Register it unconditionally so the web settings row
114
+ // (`subagent-default-model` namespace) is available even when the host
115
+ // `subagents` service is not yet mounted or a previous fiber already wrapped
116
+ // it — the service-method guard below must never gate settings registration.
117
+ installSettingsSection(ctx, SUBAGENT_DEFAULT_MODEL_SETTINGS_NAMESPACE, SUBAGENT_DEFAULT_MODEL_SETTINGS_SCHEMA, {}, {
118
+ setSource: (current) => {
119
+ state.settingsSource = current;
120
+ },
121
+ onChange: () => {}
122
+ });
123
+
124
+ // `ctx.subagents` is a per-call Cordis traceable proxy, so reach the raw
125
+ // service object behind it for a stable handle and to install own methods.
126
+ const raw = ctx.subagents?.[Symbol.for("cordis.original")] ?? ctx.subagents;
127
+ if (raw === void 0 || raw[WRAPPED] !== void 0) return;
128
+
129
+ const originalStart = raw.start;
130
+ const originalStartContinuable = raw.startContinuable;
131
+ const wrappedStart = typeof originalStart === "function"
132
+ ? async (name, request) => originalStart.call(raw, name, applyDefaultModel(state, request))
133
+ : void 0;
134
+ const wrappedStartContinuable = typeof originalStartContinuable === "function"
135
+ ? async (spec) => {
136
+ if (spec === void 0 || spec === null) return originalStartContinuable.call(raw, spec);
137
+ return originalStartContinuable.call(raw, {
138
+ ...spec,
139
+ request: applyDefaultModel(state, spec.request)
140
+ });
141
+ }
142
+ : void 0;
143
+
144
+ if (wrappedStart === void 0 && wrappedStartContinuable === void 0) return;
145
+ if (wrappedStart !== void 0) raw.start = wrappedStart;
146
+ if (wrappedStartContinuable !== void 0) raw.startContinuable = wrappedStartContinuable;
147
+ raw[WRAPPED] = state;
148
+
149
+ // Service method replacement is not a Cordis-managed contribution by itself.
150
+ // Restore only our own wrappers so disposal cannot overwrite a later wrapper.
151
+ ctx.effect(() => () => {
152
+ if (wrappedStart !== void 0 && raw.start === wrappedStart) raw.start = originalStart;
153
+ if (wrappedStartContinuable !== void 0 && raw.startContinuable === wrappedStartContinuable) raw.startContinuable = originalStartContinuable;
154
+ if (raw[WRAPPED] === state) delete raw[WRAPPED];
155
+ state.settingsSource = void 0;
156
+ state.rrCursor = 0;
157
+ });
158
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "dsh-subagent-default-model",
3
+ "version": "0.3.0",
4
+ "description": "Default model for subagent delegations, configurable via the `subagent-default-model` settings section (no explicit per-call model keeps inheriting the parent route).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/dingminhua/dsh-subagent-default-model.git"
9
+ },
10
+ "type": "module",
11
+ "main": "lib/index.js",
12
+ "exports": {
13
+ ".": "./lib/index.js",
14
+ "./client": "./lib/client.js",
15
+ "./cordis.patch.yml": "./cordis.patch.yml",
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": [
19
+ "lib",
20
+ "cordis.patch.yml",
21
+ "LICENSE",
22
+ "README.md",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "scripts": {
26
+ "test": "node --test test/*.test.mjs"
27
+ },
28
+ "dsh": {
29
+ "bundle": {
30
+ "patch": "./cordis.patch.yml"
31
+ },
32
+ "client": {
33
+ "platform": "web",
34
+ "inject": [
35
+ "@deepseek-ai/dsh-client-ui-primitives"
36
+ ]
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "@deepseek-ai/schemastery": "^3.18.1"
41
+ },
42
+ "peerDependencies": {
43
+ "@deepseek-ai/dsh-settings": "0.1.0-rc.6",
44
+ "@deepseek-ai/dsh-subagent": "0.1.0-rc.6",
45
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.6"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@deepseek-ai/dsh-client-ui-primitives": { "optional": true }
49
+ },
50
+ "devDependencies": {
51
+ "@deepseek-ai/cordis": "^4.0.1",
52
+ "@deepseek-ai/dsh-settings": "0.1.0-rc.6"
53
+ }
54
+ }