@dsh-plus/subagent-model 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +625 -649
- package/lib/index.d.ts +0 -3
- package/lib/index.js +42 -35
- package/package.json +7 -7
package/lib/client.js
CHANGED
|
@@ -3,553 +3,531 @@ window.__ModuleLoader__.load({
|
|
|
3
3
|
factory: (require) => {
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* @module subagent-model/ns
|
|
43
|
-
*/
|
|
44
|
-
const SETTINGS_NS = "dsh-plus-subagent-model";
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/client/api.ts
|
|
48
|
-
const ROUTE_CATALOG = "/dsh-plus/subagent-model/catalog";
|
|
49
|
-
async function parse(res) {
|
|
50
|
-
const body = await res.json();
|
|
51
|
-
if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`);
|
|
52
|
-
return body;
|
|
53
|
-
}
|
|
54
|
-
async function fetchCatalog() {
|
|
55
|
-
return parse(await fetch(ROUTE_CATALOG, { credentials: "same-origin" }));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/client/fields.tsx
|
|
60
|
-
function CheckRow(props) {
|
|
61
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
62
|
-
className: "dsm-checkRow",
|
|
63
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
64
|
-
id: props.id,
|
|
65
|
-
type: "checkbox",
|
|
66
|
-
checked: props.checked,
|
|
67
|
-
disabled: props.disabled === true,
|
|
68
|
-
onChange: (event) => props.onEdit(event.target.checked)
|
|
69
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
70
|
-
htmlFor: props.id,
|
|
71
|
-
children: props.label
|
|
72
|
-
})]
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function SelectField(props) {
|
|
76
|
-
const invalid = props.invalid === true;
|
|
77
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
78
|
-
className: "dsm-field",
|
|
79
|
-
children: [
|
|
80
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
81
|
-
className: "dsm-head",
|
|
82
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
83
|
-
className: "dsm-label",
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
//#region src/ns.ts
|
|
10
|
+
/**
|
|
11
|
+
* settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
|
|
12
|
+
* 服务端经 settingsNamespace() 品牌化后使用(config.ts),浏览器半将其作为
|
|
13
|
+
* settings.plugin.item keyed 槽位的 key —— 同一字面量两处共用,防止漂移。
|
|
14
|
+
* 契约:dsh rc7 起该槽位按「卡片编辑的 settings 命名空间」作 key 分发,
|
|
15
|
+
* 官方配置页只渲染 key 命中 Host 已注册命名空间的卡片。
|
|
16
|
+
* @module subagent-model/ns
|
|
17
|
+
*/
|
|
18
|
+
const SETTINGS_NS = "dsh-plus-subagent-model";
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/client/api.ts
|
|
21
|
+
const ROUTE_CATALOG = "/dsh-plus/subagent-model/catalog";
|
|
22
|
+
async function parse(res) {
|
|
23
|
+
const body = await res.json();
|
|
24
|
+
if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`);
|
|
25
|
+
return body;
|
|
26
|
+
}
|
|
27
|
+
async function fetchCatalog() {
|
|
28
|
+
return parse(await fetch(ROUTE_CATALOG, { credentials: "same-origin" }));
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/client/fields.tsx
|
|
32
|
+
function CheckRow(props) {
|
|
33
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
34
|
+
className: "dsm-checkRow",
|
|
35
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
36
|
+
id: props.id,
|
|
37
|
+
type: "checkbox",
|
|
38
|
+
checked: props.checked,
|
|
39
|
+
disabled: props.disabled === true,
|
|
40
|
+
onChange: (event) => props.onEdit(event.target.checked)
|
|
41
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
84
42
|
htmlFor: props.id,
|
|
85
43
|
children: props.label
|
|
86
|
-
})
|
|
87
|
-
}),
|
|
88
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
89
|
-
id: props.id,
|
|
90
|
-
className: "dsm-select",
|
|
91
|
-
"aria-invalid": invalid || void 0,
|
|
92
|
-
value: props.value,
|
|
93
|
-
disabled: props.disabled === true,
|
|
94
|
-
onChange: (event) => props.onEdit(event.target.value),
|
|
95
|
-
children: props.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
96
|
-
value: option.value,
|
|
97
|
-
children: option.label
|
|
98
|
-
}, option.value))
|
|
99
|
-
}),
|
|
100
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
101
|
-
className: invalid ? "dsm-invalid" : "dsm-hint",
|
|
102
|
-
children: invalid ? props.invalidLabel ?? "" : props.hint ?? ""
|
|
103
|
-
})
|
|
104
|
-
]
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/client/card.tsx
|
|
110
|
-
const IDLE_STATUS = {
|
|
111
|
-
kind: "idle",
|
|
112
|
-
text: ""
|
|
113
|
-
};
|
|
114
|
-
const EMPTY_ROW = {
|
|
115
|
-
enabled: false,
|
|
116
|
-
provider: "",
|
|
117
|
-
model: "",
|
|
118
|
-
reasoningEffort: "inherit"
|
|
119
|
-
};
|
|
120
|
-
const EFFORT_INHERIT = "inherit";
|
|
121
|
-
const EFFORT_DEFAULT = "default";
|
|
122
|
-
function draftFrom(value, catalog) {
|
|
123
|
-
const rows = {};
|
|
124
|
-
const names = /* @__PURE__ */ new Set();
|
|
125
|
-
for (const name$1 of catalog?.subagentProviders ?? []) names.add(name$1);
|
|
126
|
-
for (const name$1 of Object.keys(value.entries).sort()) names.add(name$1);
|
|
127
|
-
for (const name$1 of names) {
|
|
128
|
-
const entry = value.entries[name$1];
|
|
129
|
-
rows[name$1] = entry === void 0 ? { ...EMPTY_ROW } : {
|
|
130
|
-
enabled: entry.enabled,
|
|
131
|
-
provider: entry.provider,
|
|
132
|
-
model: entry.model,
|
|
133
|
-
reasoningEffort: entry.reasoningEffort
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
enabled: value.enabled,
|
|
138
|
-
rows
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function toPatch(draft) {
|
|
142
|
-
return {
|
|
143
|
-
enabled: draft.enabled,
|
|
144
|
-
entries: draft.rows
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function unknownOption(value, label) {
|
|
148
|
-
return {
|
|
149
|
-
value,
|
|
150
|
-
label: `${value}(${label})`
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function providerOptions(catalog, row, t) {
|
|
154
|
-
const options = [{
|
|
155
|
-
value: "",
|
|
156
|
-
label: t("inheritProvider")
|
|
157
|
-
}];
|
|
158
|
-
for (const provider of catalog?.providers ?? []) options.push({
|
|
159
|
-
value: provider.id,
|
|
160
|
-
label: provider.name
|
|
161
|
-
});
|
|
162
|
-
if (row.provider.length > 0 && !options.some((o) => o.value === row.provider)) options.push(unknownOption(row.provider, t("unknownValue")));
|
|
163
|
-
return options;
|
|
164
|
-
}
|
|
165
|
-
function modelOptions(catalog, row, t) {
|
|
166
|
-
const options = [{
|
|
167
|
-
value: "",
|
|
168
|
-
label: t("inheritModel")
|
|
169
|
-
}];
|
|
170
|
-
const provider = catalog?.providers.find((p) => p.id === row.provider);
|
|
171
|
-
for (const model of provider?.models ?? []) options.push({
|
|
172
|
-
value: model.id,
|
|
173
|
-
label: model.name
|
|
174
|
-
});
|
|
175
|
-
if (row.model.length > 0 && !options.some((o) => o.value === row.model)) options.push(unknownOption(row.model, t("unknownValue")));
|
|
176
|
-
return options;
|
|
177
|
-
}
|
|
178
|
-
function effortOptions(catalog, row, t) {
|
|
179
|
-
const options = [{
|
|
180
|
-
value: EFFORT_INHERIT,
|
|
181
|
-
label: t("effortInherit")
|
|
182
|
-
}, {
|
|
183
|
-
value: EFFORT_DEFAULT,
|
|
184
|
-
label: t("effortDefault")
|
|
185
|
-
}];
|
|
186
|
-
const model = (catalog?.providers.find((p) => p.id === row.provider))?.models.find((m) => m.id === row.model);
|
|
187
|
-
for (const effort of model?.reasoning?.efforts ?? []) options.push({
|
|
188
|
-
value: effort.id,
|
|
189
|
-
label: effort.name
|
|
190
|
-
});
|
|
191
|
-
if (row.reasoningEffort.length > 0 && !options.some((o) => o.value === row.reasoningEffort)) options.push(unknownOption(row.reasoningEffort, t("unknownValue")));
|
|
192
|
-
return options;
|
|
193
|
-
}
|
|
194
|
-
function RowBlock(props) {
|
|
195
|
-
const { name: name$1, row, catalog, disabled, t, onEdit } = props;
|
|
196
|
-
const invalidModel = row.model.length > 0 && row.provider.length === 0;
|
|
197
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
198
|
-
className: "dsm-row",
|
|
199
|
-
children: [
|
|
200
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
201
|
-
className: "dsm-rowHead",
|
|
202
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
203
|
-
className: "dsm-rowName",
|
|
204
|
-
children: name$1
|
|
205
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
206
|
-
id: `dsm-row-${name$1}`,
|
|
207
|
-
label: t("rowEnabled"),
|
|
208
|
-
checked: row.enabled,
|
|
209
|
-
disabled,
|
|
210
|
-
onEdit: (v) => onEdit({
|
|
211
|
-
...row,
|
|
212
|
-
enabled: v
|
|
213
|
-
})
|
|
214
44
|
})]
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const snapshot = (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot());
|
|
264
|
-
const value = snapshot.value;
|
|
265
|
-
const [open, setOpen] = (0, react.useState)(false);
|
|
266
|
-
const [draft, setDraft] = (0, react.useState)(null);
|
|
267
|
-
const [catalog, setCatalog] = (0, react.useState)(null);
|
|
268
|
-
const [catalogFailed, setCatalogFailed] = (0, react.useState)(false);
|
|
269
|
-
const [saving, setSaving] = (0, react.useState)(false);
|
|
270
|
-
const [status, setStatus] = (0, react.useState)(IDLE_STATUS);
|
|
271
|
-
(0, react.useEffect)(() => {
|
|
272
|
-
if (value === void 0) return;
|
|
273
|
-
setDraft((current) => {
|
|
274
|
-
if (current === null) return draftFrom(value, catalog);
|
|
275
|
-
if (catalog === null) return current;
|
|
276
|
-
const rows = { ...current.rows };
|
|
277
|
-
let changed = false;
|
|
278
|
-
for (const name$1 of catalog.subagentProviders) {
|
|
279
|
-
if (name$1 in rows) continue;
|
|
280
|
-
rows[name$1] = { ...EMPTY_ROW };
|
|
281
|
-
changed = true;
|
|
282
|
-
}
|
|
283
|
-
return changed ? {
|
|
284
|
-
...current,
|
|
285
|
-
rows
|
|
286
|
-
} : current;
|
|
287
|
-
});
|
|
288
|
-
}, [value, catalog]);
|
|
289
|
-
(0, react.useEffect)(() => {
|
|
290
|
-
if (!open || catalog !== null) return;
|
|
291
|
-
let alive = true;
|
|
292
|
-
fetchCatalog().then((loaded) => {
|
|
293
|
-
if (!alive) return;
|
|
294
|
-
setCatalog(loaded);
|
|
295
|
-
setCatalogFailed(false);
|
|
296
|
-
}).catch(() => {
|
|
297
|
-
if (alive) setCatalogFailed(true);
|
|
298
|
-
});
|
|
299
|
-
return () => {
|
|
300
|
-
alive = false;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function SelectField(props) {
|
|
48
|
+
const invalid = props.invalid === true;
|
|
49
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
50
|
+
className: "dsm-field",
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
53
|
+
className: "dsm-head",
|
|
54
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
55
|
+
className: "dsm-label",
|
|
56
|
+
htmlFor: props.id,
|
|
57
|
+
children: props.label
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
61
|
+
id: props.id,
|
|
62
|
+
className: "dsm-select",
|
|
63
|
+
"aria-invalid": invalid || void 0,
|
|
64
|
+
value: props.value,
|
|
65
|
+
disabled: props.disabled === true,
|
|
66
|
+
onChange: (event) => props.onEdit(event.target.value),
|
|
67
|
+
children: props.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
68
|
+
value: option.value,
|
|
69
|
+
children: option.label
|
|
70
|
+
}, option.value))
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
73
|
+
className: invalid ? "dsm-invalid" : "dsm-hint",
|
|
74
|
+
children: invalid ? props.invalidLabel ?? "" : props.hint ?? ""
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/client/card.tsx
|
|
81
|
+
/**
|
|
82
|
+
* 「子代理模型配置」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
|
|
83
|
+
* 交互对齐官方卡片:折叠/展开、staged draft、未保存标记、保存/放弃。
|
|
84
|
+
* 配置读写走官方 settingsScope 传输(scope.ts):value 为 schema 解析后的
|
|
85
|
+
* 命名空间值(enabled + entries),行集合 = 目录返回的已注册子代理 provider
|
|
86
|
+
* ∪ 已配置条目,保存时全量写回 entries(未配置的新 provider 行以默认空值
|
|
87
|
+
* 落盘,自文档化);「模型目录」为唯一保留的自定义端点。
|
|
88
|
+
* @module subagent-model/client/card
|
|
89
|
+
*/
|
|
90
|
+
const IDLE_STATUS = {
|
|
91
|
+
kind: "idle",
|
|
92
|
+
text: ""
|
|
301
93
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const editRow = (name$1, row) => {
|
|
324
|
-
setDraft({
|
|
325
|
-
...draft,
|
|
326
|
-
rows: {
|
|
327
|
-
...draft.rows,
|
|
328
|
-
[name$1]: row
|
|
94
|
+
const EMPTY_ROW = {
|
|
95
|
+
enabled: false,
|
|
96
|
+
provider: "",
|
|
97
|
+
model: "",
|
|
98
|
+
reasoningEffort: "inherit"
|
|
99
|
+
};
|
|
100
|
+
const EFFORT_INHERIT = "inherit";
|
|
101
|
+
const EFFORT_DEFAULT = "default";
|
|
102
|
+
function draftFrom(value, catalog) {
|
|
103
|
+
const rows = {};
|
|
104
|
+
const names = /* @__PURE__ */ new Set();
|
|
105
|
+
for (const name of catalog?.subagentProviders ?? []) names.add(name);
|
|
106
|
+
for (const name of Object.keys(value.entries).sort()) names.add(name);
|
|
107
|
+
for (const name of names) {
|
|
108
|
+
const entry = value.entries[name];
|
|
109
|
+
rows[name] = entry === void 0 ? { ...EMPTY_ROW } : {
|
|
110
|
+
enabled: entry.enabled,
|
|
111
|
+
provider: entry.provider,
|
|
112
|
+
model: entry.model,
|
|
113
|
+
reasoningEffort: entry.reasoningEffort
|
|
114
|
+
};
|
|
329
115
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
116
|
+
return {
|
|
117
|
+
enabled: value.enabled,
|
|
118
|
+
rows
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function toPatch(draft) {
|
|
122
|
+
return {
|
|
123
|
+
enabled: draft.enabled,
|
|
124
|
+
entries: draft.rows
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function unknownOption(value, label) {
|
|
128
|
+
return {
|
|
129
|
+
value,
|
|
130
|
+
label: `${value}(${label})`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function providerOptions(catalog, row, t) {
|
|
134
|
+
const options = [{
|
|
135
|
+
value: "",
|
|
136
|
+
label: t("inheritProvider")
|
|
137
|
+
}];
|
|
138
|
+
for (const provider of catalog?.providers ?? []) options.push({
|
|
139
|
+
value: provider.id,
|
|
140
|
+
label: provider.name
|
|
350
141
|
});
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
142
|
+
if (row.provider.length > 0 && !options.some((o) => o.value === row.provider)) options.push(unknownOption(row.provider, t("unknownValue")));
|
|
143
|
+
return options;
|
|
144
|
+
}
|
|
145
|
+
function modelOptions(catalog, row, t) {
|
|
146
|
+
const options = [{
|
|
147
|
+
value: "",
|
|
148
|
+
label: t("inheritModel")
|
|
149
|
+
}];
|
|
150
|
+
const provider = catalog?.providers.find((p) => p.id === row.provider);
|
|
151
|
+
for (const model of provider?.models ?? []) options.push({
|
|
152
|
+
value: model.id,
|
|
153
|
+
label: model.name
|
|
154
|
+
});
|
|
155
|
+
if (row.model.length > 0 && !options.some((o) => o.value === row.model)) options.push(unknownOption(row.model, t("unknownValue")));
|
|
156
|
+
return options;
|
|
157
|
+
}
|
|
158
|
+
function effortOptions(catalog, row, t) {
|
|
159
|
+
const options = [{
|
|
160
|
+
value: EFFORT_INHERIT,
|
|
161
|
+
label: t("effortInherit")
|
|
162
|
+
}, {
|
|
163
|
+
value: EFFORT_DEFAULT,
|
|
164
|
+
label: t("effortDefault")
|
|
165
|
+
}];
|
|
166
|
+
const model = (catalog?.providers.find((p) => p.id === row.provider))?.models.find((m) => m.id === row.model);
|
|
167
|
+
for (const effort of model?.reasoning?.efforts ?? []) options.push({
|
|
168
|
+
value: effort.id,
|
|
169
|
+
label: effort.name
|
|
170
|
+
});
|
|
171
|
+
if (row.reasoningEffort.length > 0 && !options.some((o) => o.value === row.reasoningEffort)) options.push(unknownOption(row.reasoningEffort, t("unknownValue")));
|
|
172
|
+
return options;
|
|
173
|
+
}
|
|
174
|
+
function RowBlock(props) {
|
|
175
|
+
const { name, row, catalog, disabled, t, onEdit } = props;
|
|
176
|
+
const invalidModel = row.model.length > 0 && row.provider.length === 0;
|
|
177
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
178
|
+
className: "dsm-row",
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
181
|
+
className: "dsm-rowHead",
|
|
182
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
183
|
+
className: "dsm-rowName",
|
|
184
|
+
children: name
|
|
185
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
186
|
+
id: `dsm-row-${name}`,
|
|
187
|
+
label: t("rowEnabled"),
|
|
188
|
+
checked: row.enabled,
|
|
189
|
+
disabled,
|
|
190
|
+
onEdit: (v) => onEdit({
|
|
191
|
+
...row,
|
|
192
|
+
enabled: v
|
|
193
|
+
})
|
|
194
|
+
})]
|
|
195
|
+
}),
|
|
196
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
197
|
+
className: "dsm-rowHint",
|
|
198
|
+
children: t("rowHint")
|
|
199
|
+
}),
|
|
200
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, {
|
|
201
|
+
id: `dsm-provider-${name}`,
|
|
202
|
+
label: t("provider"),
|
|
203
|
+
hint: t("providerHint"),
|
|
204
|
+
value: row.provider,
|
|
205
|
+
options: providerOptions(catalog, row, t),
|
|
206
|
+
disabled,
|
|
207
|
+
onEdit: (v) => onEdit({
|
|
208
|
+
...row,
|
|
209
|
+
provider: v
|
|
210
|
+
})
|
|
211
|
+
}),
|
|
212
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, {
|
|
213
|
+
id: `dsm-model-${name}`,
|
|
214
|
+
label: t("model"),
|
|
215
|
+
hint: t("modelHint"),
|
|
216
|
+
value: row.model,
|
|
217
|
+
options: modelOptions(catalog, row, t),
|
|
218
|
+
disabled: disabled || row.provider.length === 0,
|
|
219
|
+
invalid: invalidModel,
|
|
220
|
+
invalidLabel: t("invalidModel"),
|
|
221
|
+
onEdit: (v) => onEdit({
|
|
222
|
+
...row,
|
|
223
|
+
model: v
|
|
224
|
+
})
|
|
225
|
+
}),
|
|
226
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, {
|
|
227
|
+
id: `dsm-effort-${name}`,
|
|
228
|
+
label: t("effort"),
|
|
229
|
+
hint: t("effortHint"),
|
|
230
|
+
value: row.reasoningEffort,
|
|
231
|
+
options: effortOptions(catalog, row, t),
|
|
232
|
+
disabled,
|
|
233
|
+
onEdit: (v) => onEdit({
|
|
234
|
+
...row,
|
|
235
|
+
reasoningEffort: v
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
]
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function SubagentModelCard(props) {
|
|
242
|
+
const { t, scope, api } = props;
|
|
243
|
+
const snapshot = (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot());
|
|
244
|
+
const value = snapshot.value;
|
|
245
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
246
|
+
const [draft, setDraft] = (0, react.useState)(null);
|
|
247
|
+
const [catalog, setCatalog] = (0, react.useState)(null);
|
|
248
|
+
const [catalogFailed, setCatalogFailed] = (0, react.useState)(false);
|
|
249
|
+
const [saving, setSaving] = (0, react.useState)(false);
|
|
250
|
+
const [status, setStatus] = (0, react.useState)(IDLE_STATUS);
|
|
251
|
+
(0, react.useEffect)(() => {
|
|
252
|
+
if (value === void 0) return;
|
|
253
|
+
setDraft((current) => {
|
|
254
|
+
if (current === null) return draftFrom(value, catalog);
|
|
255
|
+
if (catalog === null) return current;
|
|
256
|
+
const rows = { ...current.rows };
|
|
257
|
+
let changed = false;
|
|
258
|
+
for (const name of catalog.subagentProviders) {
|
|
259
|
+
if (name in rows) continue;
|
|
260
|
+
rows[name] = { ...EMPTY_ROW };
|
|
261
|
+
changed = true;
|
|
262
|
+
}
|
|
263
|
+
return changed ? {
|
|
264
|
+
...current,
|
|
265
|
+
rows
|
|
266
|
+
} : current;
|
|
267
|
+
});
|
|
268
|
+
}, [value, catalog]);
|
|
269
|
+
(0, react.useEffect)(() => {
|
|
270
|
+
if (!open || catalog !== null) return;
|
|
271
|
+
let alive = true;
|
|
272
|
+
fetchCatalog().then((loaded) => {
|
|
273
|
+
if (!alive) return;
|
|
274
|
+
setCatalog(loaded);
|
|
275
|
+
setCatalogFailed(false);
|
|
276
|
+
}).catch(() => {
|
|
277
|
+
if (alive) setCatalogFailed(true);
|
|
278
|
+
});
|
|
279
|
+
return () => {
|
|
280
|
+
alive = false;
|
|
281
|
+
};
|
|
282
|
+
}, [open, catalog]);
|
|
283
|
+
const dirty = (0, react.useMemo)(() => value !== void 0 && draft !== null && JSON.stringify(toPatch(draft)) !== JSON.stringify(toPatch(draftFrom(value, catalog))), [
|
|
284
|
+
value,
|
|
285
|
+
draft,
|
|
286
|
+
catalog
|
|
287
|
+
]);
|
|
288
|
+
const invalid = (0, react.useMemo)(() => draft !== null && Object.values(draft.rows).some((row) => row.model.length > 0 && row.provider.length === 0), [draft]);
|
|
289
|
+
if (value === void 0 || draft === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
290
|
+
className: "dsm-card",
|
|
291
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
419
292
|
className: "dsm-empty",
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
293
|
+
children: t("loading")
|
|
294
|
+
})
|
|
295
|
+
});
|
|
296
|
+
const edit = (key, editValue) => {
|
|
297
|
+
setDraft({
|
|
298
|
+
...draft,
|
|
299
|
+
[key]: editValue
|
|
300
|
+
});
|
|
301
|
+
setStatus(IDLE_STATUS);
|
|
302
|
+
};
|
|
303
|
+
const editRow = (name, row) => {
|
|
304
|
+
setDraft({
|
|
305
|
+
...draft,
|
|
306
|
+
rows: {
|
|
307
|
+
...draft.rows,
|
|
308
|
+
[name]: row
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
setStatus(IDLE_STATUS);
|
|
312
|
+
};
|
|
313
|
+
const onSave = () => {
|
|
314
|
+
setSaving(true);
|
|
315
|
+
const revision = scope.getSnapshot().revision;
|
|
316
|
+
api.update({
|
|
317
|
+
ns: SETTINGS_NS,
|
|
318
|
+
patch: toPatch(draft),
|
|
319
|
+
...revision !== void 0 ? { expectedRevision: revision } : {}
|
|
320
|
+
}).then(async (response) => {
|
|
321
|
+
if (!response.result.ok) throw new Error(response.result.error?.message ?? t("saveFailed"));
|
|
322
|
+
await scope.load();
|
|
323
|
+
const next = scope.getSnapshot().value;
|
|
324
|
+
if (next !== void 0) setDraft(draftFrom(next, catalog));
|
|
325
|
+
setStatus(IDLE_STATUS);
|
|
326
|
+
}).catch((error) => {
|
|
327
|
+
setStatus({
|
|
328
|
+
kind: "error",
|
|
329
|
+
text: `${t("saveFailed")}${error instanceof Error ? error.message : ""}`
|
|
330
|
+
});
|
|
331
|
+
}).finally(() => setSaving(false));
|
|
332
|
+
};
|
|
333
|
+
const onRetryCatalog = () => {
|
|
334
|
+
setCatalog(null);
|
|
335
|
+
setCatalogFailed(false);
|
|
336
|
+
};
|
|
337
|
+
const disabled = !snapshot.writable;
|
|
338
|
+
const rowNames = Object.keys(draft.rows).sort();
|
|
339
|
+
const providerCount = (catalog?.providers ?? []).length;
|
|
340
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
341
|
+
className: `dsm-card${open ? " dsm-cardOpen" : ""}`,
|
|
342
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
343
|
+
type: "button",
|
|
344
|
+
className: "dsm-header",
|
|
345
|
+
"aria-expanded": open,
|
|
346
|
+
"aria-label": `${t(open ? "collapse" : "expand")}: ${t("title")}`,
|
|
347
|
+
onClick: () => setOpen(!open),
|
|
437
348
|
children: [
|
|
438
|
-
|
|
439
|
-
className:
|
|
349
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
350
|
+
className: "dsm-headText",
|
|
351
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
352
|
+
className: "dsm-name",
|
|
353
|
+
children: t("title")
|
|
354
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
355
|
+
className: "dsm-description",
|
|
356
|
+
children: t("description")
|
|
357
|
+
})]
|
|
358
|
+
}),
|
|
359
|
+
dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
360
|
+
className: "dsm-pending",
|
|
361
|
+
children: t("unsaved")
|
|
362
|
+
}) : null,
|
|
363
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
364
|
+
className: `dsm-chevron${open ? " dsm-chevronOpen" : ""}`,
|
|
365
|
+
children: "▾"
|
|
366
|
+
})
|
|
367
|
+
]
|
|
368
|
+
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
369
|
+
className: "dsm-body",
|
|
370
|
+
children: [
|
|
371
|
+
disabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
372
|
+
className: "dsm-empty",
|
|
373
|
+
role: "status",
|
|
374
|
+
children: t("readOnly")
|
|
375
|
+
}) : null,
|
|
376
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
377
|
+
id: "dsm-enabled",
|
|
378
|
+
label: t("enabled"),
|
|
379
|
+
checked: draft.enabled,
|
|
380
|
+
disabled,
|
|
381
|
+
onEdit: (v) => edit("enabled", v)
|
|
382
|
+
}),
|
|
383
|
+
catalogFailed ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
384
|
+
className: "dsm-banner",
|
|
440
385
|
role: "status",
|
|
441
|
-
children:
|
|
386
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("catalogError") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
387
|
+
type: "button",
|
|
388
|
+
className: "dsm-bannerRetry",
|
|
389
|
+
onClick: onRetryCatalog,
|
|
390
|
+
children: t("catalogRetry")
|
|
391
|
+
})]
|
|
442
392
|
}) : null,
|
|
443
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
children: t("
|
|
393
|
+
catalog === null && !catalogFailed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
394
|
+
className: "dsm-empty",
|
|
395
|
+
role: "status",
|
|
396
|
+
children: t("catalogLoading")
|
|
397
|
+
}) : null,
|
|
398
|
+
rowNames.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
399
|
+
className: "dsm-empty",
|
|
400
|
+
role: "status",
|
|
401
|
+
children: t("noRows")
|
|
402
|
+
}) : null,
|
|
403
|
+
rowNames.map((name) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowBlock, {
|
|
404
|
+
name,
|
|
405
|
+
row: draft.rows[name] ?? { ...EMPTY_ROW },
|
|
406
|
+
catalog,
|
|
407
|
+
disabled,
|
|
408
|
+
t,
|
|
409
|
+
onEdit: (row) => editRow(name, row)
|
|
410
|
+
}, name)),
|
|
411
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
412
|
+
className: "dsm-hint dsm-rowHint",
|
|
413
|
+
children: providerCount > 0 ? t("rowDesc") : ""
|
|
452
414
|
}),
|
|
453
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
415
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
416
|
+
className: "dsm-footer",
|
|
417
|
+
children: [
|
|
418
|
+
status.kind !== "idle" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
419
|
+
className: `dsm-status${status.kind === "error" ? " dsm-statusError" : ""}`,
|
|
420
|
+
role: "status",
|
|
421
|
+
children: status.text
|
|
422
|
+
}) : null,
|
|
423
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
424
|
+
type: "button",
|
|
425
|
+
className: "dsm-btn dsm-btnGhost",
|
|
426
|
+
disabled: !dirty || saving,
|
|
427
|
+
onClick: () => {
|
|
428
|
+
setDraft(draftFrom(value, catalog));
|
|
429
|
+
setStatus(IDLE_STATUS);
|
|
430
|
+
},
|
|
431
|
+
children: t("discard")
|
|
432
|
+
}),
|
|
433
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
434
|
+
type: "button",
|
|
435
|
+
className: "dsm-btn dsm-btnPrimary",
|
|
436
|
+
disabled: !dirty || invalid || saving || disabled,
|
|
437
|
+
onClick: onSave,
|
|
438
|
+
children: t(saving ? "saving" : "save")
|
|
439
|
+
})
|
|
440
|
+
]
|
|
459
441
|
})
|
|
460
442
|
]
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
*/
|
|
550
|
-
const PLUGIN_ID = "@dsh-plus/subagent-model";
|
|
551
|
-
const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`;
|
|
552
|
-
const cardCss = `
|
|
443
|
+
}) : null]
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/client/i18n.ts
|
|
448
|
+
/**
|
|
449
|
+
* 配置卡片文案(zh/en)。经 ctx.locale.register 注册、bind 取用,与官方卡片同机制。
|
|
450
|
+
* @module subagent-model/client/i18n
|
|
451
|
+
*/
|
|
452
|
+
const NS = "dsh-plus-subagent-model";
|
|
453
|
+
const zh = {
|
|
454
|
+
title: "子代理模型配置",
|
|
455
|
+
description: "为 subagent / subagent_fork 等子代理单独指定提供商、模型与思考程度,或继承主代理。",
|
|
456
|
+
enabled: "启用插件",
|
|
457
|
+
rowEnabled: "启用该行",
|
|
458
|
+
provider: "提供商",
|
|
459
|
+
model: "模型",
|
|
460
|
+
effort: "思考程度",
|
|
461
|
+
inheritProvider: "继承主代理",
|
|
462
|
+
inheritModel: "继承主代理",
|
|
463
|
+
effortInherit: "继承主代理",
|
|
464
|
+
effortDefault: "跟随模型默认",
|
|
465
|
+
providerHint: "留空 = 子代理沿用主代理的提供商与模型。",
|
|
466
|
+
modelHint: "留空 = 沿用主代理的模型(需与所选提供商匹配)。",
|
|
467
|
+
effortHint: "inherit = 不干预(fork 会随会话继承);default = 显式使用模型默认档位。",
|
|
468
|
+
rowHint: "按子代理 provider 名匹配;standard preset 中 spawn ↔ subagent 工具、fork ↔ subagent_fork 工具。",
|
|
469
|
+
rowDesc: "未注册的 provider 行不生效,可保留待用。",
|
|
470
|
+
noRows: "当前未发现子代理 provider;配置将在 provider 注册后生效。",
|
|
471
|
+
catalogError: "提供商目录加载失败:",
|
|
472
|
+
catalogRetry: "重试",
|
|
473
|
+
catalogLoading: "目录加载中…",
|
|
474
|
+
unknownValue: "目录外",
|
|
475
|
+
save: "保存",
|
|
476
|
+
saving: "保存中…",
|
|
477
|
+
discard: "放弃",
|
|
478
|
+
unsaved: "未保存",
|
|
479
|
+
saveFailed: "保存失败:",
|
|
480
|
+
loading: "加载中…",
|
|
481
|
+
unavailable: "配置服务不可用。",
|
|
482
|
+
readOnly: "当前部署无 settings provider,配置为只读;请编辑 settings.yaml。",
|
|
483
|
+
expand: "展开",
|
|
484
|
+
collapse: "收起",
|
|
485
|
+
invalidModel: "模型不能脱离提供商单独配置。"
|
|
486
|
+
};
|
|
487
|
+
const en = {
|
|
488
|
+
title: "Subagent model config",
|
|
489
|
+
description: "Pick a provider, model, and thinking effort for subagent / subagent_fork children, or inherit from the main agent.",
|
|
490
|
+
enabled: "Enable plugin",
|
|
491
|
+
rowEnabled: "Enable row",
|
|
492
|
+
provider: "Provider",
|
|
493
|
+
model: "Model",
|
|
494
|
+
effort: "Effort",
|
|
495
|
+
inheritProvider: "Inherit from main agent",
|
|
496
|
+
inheritModel: "Inherit from main agent",
|
|
497
|
+
effortInherit: "Inherit from main agent",
|
|
498
|
+
effortDefault: "Follow model default",
|
|
499
|
+
providerHint: "Empty = the child follows the main agent’s provider and model.",
|
|
500
|
+
modelHint: "Empty = follow the main agent’s model (must match the chosen provider).",
|
|
501
|
+
effortHint: "inherit = do not touch (forks inherit via session seed); default = explicitly use the model’s default level.",
|
|
502
|
+
rowHint: "Matched by subagent provider name; in the standard preset spawn ↔ subagent tool, fork ↔ subagent_fork tool.",
|
|
503
|
+
rowDesc: "Rows for unregistered providers are inert; keep them for later.",
|
|
504
|
+
noRows: "No subagent provider registered yet; config takes effect once one appears.",
|
|
505
|
+
catalogError: "Failed to load provider catalog: ",
|
|
506
|
+
catalogRetry: "Retry",
|
|
507
|
+
catalogLoading: "Loading catalog…",
|
|
508
|
+
unknownValue: "outside catalog",
|
|
509
|
+
save: "Save",
|
|
510
|
+
saving: "Saving…",
|
|
511
|
+
discard: "Discard",
|
|
512
|
+
unsaved: "Unsaved",
|
|
513
|
+
saveFailed: "Save failed: ",
|
|
514
|
+
loading: "Loading…",
|
|
515
|
+
unavailable: "Configuration service unavailable.",
|
|
516
|
+
readOnly: "No settings provider in this deployment; edit settings.yaml instead.",
|
|
517
|
+
expand: "Expand",
|
|
518
|
+
collapse: "Collapse",
|
|
519
|
+
invalidModel: "Model cannot be set without a provider."
|
|
520
|
+
};
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/client/styles.ts
|
|
523
|
+
/**
|
|
524
|
+
* 配置卡片样式:沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),
|
|
525
|
+
* 视觉对齐官方卡片(--dsw-alias-* 变量),不覆盖上游任何选择器。
|
|
526
|
+
* @module subagent-model/client/styles
|
|
527
|
+
*/
|
|
528
|
+
const PLUGIN_ID = "@dsh-plus/subagent-model";
|
|
529
|
+
const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`;
|
|
530
|
+
const cardCss = `
|
|
553
531
|
.dsm-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
|
|
554
532
|
.dsm-card:hover{border-color:var(--dsw-alias-label-dimmed)}
|
|
555
533
|
.dsm-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
|
|
@@ -592,125 +570,123 @@ const cardCss = `
|
|
|
592
570
|
.dsm-btn:disabled{opacity:.4;cursor:default}
|
|
593
571
|
.dsm-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
594
572
|
`;
|
|
595
|
-
/** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
|
|
596
|
-
function injectStyle() {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
//#endregion
|
|
608
|
-
//#region src/client/client.ts
|
|
609
|
-
const name = "dsh-plus-subagent-model";
|
|
610
|
-
/** 浏览器半需要的 cordis 服务 key(loader 据此注入;package.json 的 dsh.client.inject 管包加载顺序)。 */
|
|
611
|
-
const inject = [
|
|
612
|
-
"slots",
|
|
613
|
-
"locale",
|
|
614
|
-
"connection",
|
|
615
|
-
"remote"
|
|
616
|
-
];
|
|
617
|
-
/**
|
|
618
|
-
* api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
|
|
619
|
-
* 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
|
|
620
|
-
* 刷新:remote `settings/document-updated`(按命名空间过滤)与
|
|
621
|
-
* `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
|
|
622
|
-
* (loopback 或 tailnet 信任域名)下行为一致。
|
|
623
|
-
*/
|
|
624
|
-
function createApiScope(api, ns, c) {
|
|
625
|
-
let state = {
|
|
626
|
-
status: "loading",
|
|
627
|
-
value: void 0,
|
|
628
|
-
revision: void 0,
|
|
629
|
-
writable: false
|
|
630
|
-
};
|
|
631
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
632
|
-
let generation = 0;
|
|
633
|
-
const publish = (next) => {
|
|
634
|
-
state = next;
|
|
635
|
-
for (const listener of [...listeners]) listener();
|
|
636
|
-
};
|
|
637
|
-
const load = async () => {
|
|
638
|
-
const gen = ++generation;
|
|
639
|
-
let response;
|
|
640
|
-
try {
|
|
641
|
-
response = await api.describe({});
|
|
642
|
-
} catch {
|
|
643
|
-
return;
|
|
573
|
+
/** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
|
|
574
|
+
function injectStyle() {
|
|
575
|
+
if (typeof document === "undefined") return null;
|
|
576
|
+
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`) !== null) return null;
|
|
577
|
+
const tag = document.createElement("style");
|
|
578
|
+
tag.dataset.plugin = PLUGIN_ID;
|
|
579
|
+
tag.dataset.pluginCss = STYLE_TAG_ID;
|
|
580
|
+
tag.textContent = cardCss;
|
|
581
|
+
document.head.appendChild(tag);
|
|
582
|
+
return tag;
|
|
644
583
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region src/client/client.ts
|
|
586
|
+
const name = "dsh-plus-subagent-model";
|
|
587
|
+
/** 浏览器半需要的 cordis 服务 key(loader 据此注入;package.json 的 dsh.client.inject 管包加载顺序)。 */
|
|
588
|
+
const inject = [
|
|
589
|
+
"slots",
|
|
590
|
+
"locale",
|
|
591
|
+
"connection",
|
|
592
|
+
"remote"
|
|
593
|
+
];
|
|
594
|
+
/**
|
|
595
|
+
* api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
|
|
596
|
+
* 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
|
|
597
|
+
* 刷新:remote `settings/document-updated`(按命名空间过滤)与
|
|
598
|
+
* `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
|
|
599
|
+
* (loopback 或 tailnet 信任域名)下行为一致。
|
|
600
|
+
*/
|
|
601
|
+
function createApiScope(api, ns, c) {
|
|
602
|
+
let state = {
|
|
603
|
+
status: "loading",
|
|
651
604
|
value: void 0,
|
|
652
605
|
revision: void 0,
|
|
653
|
-
writable
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
606
|
+
writable: false
|
|
607
|
+
};
|
|
608
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
609
|
+
let generation = 0;
|
|
610
|
+
const publish = (next) => {
|
|
611
|
+
state = next;
|
|
612
|
+
for (const listener of [...listeners]) listener();
|
|
613
|
+
};
|
|
614
|
+
const load = async () => {
|
|
615
|
+
const gen = ++generation;
|
|
616
|
+
let response;
|
|
617
|
+
try {
|
|
618
|
+
response = await api.describe({});
|
|
619
|
+
} catch {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (gen !== generation || !response.result.ok) return;
|
|
623
|
+
const writable = response.result.value?.writable ?? false;
|
|
624
|
+
const view = response.result.value?.namespaces.find((candidate) => candidate.ns === ns);
|
|
625
|
+
if (view === void 0) {
|
|
626
|
+
publish({
|
|
627
|
+
status: "unavailable",
|
|
628
|
+
value: void 0,
|
|
629
|
+
revision: void 0,
|
|
630
|
+
writable
|
|
631
|
+
});
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
publish({
|
|
635
|
+
status: "ready",
|
|
636
|
+
value: view.value,
|
|
637
|
+
revision: view.revision,
|
|
638
|
+
writable
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
const refresh = (namespace) => {
|
|
642
|
+
if (namespace !== void 0 && namespace !== ns) return;
|
|
643
|
+
load();
|
|
681
644
|
};
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
645
|
+
const disposers = [c.get("remote").$on("settings/document-updated", refresh), c.on("connection/reset", () => {
|
|
646
|
+
load();
|
|
647
|
+
})];
|
|
648
|
+
c.effect(() => () => {
|
|
649
|
+
for (const dispose of disposers) dispose();
|
|
650
|
+
}, "subagent-model: settings scope");
|
|
651
|
+
load();
|
|
652
|
+
return {
|
|
653
|
+
getSnapshot: () => state,
|
|
654
|
+
subscribe: (listener) => {
|
|
655
|
+
listeners.add(listener);
|
|
656
|
+
return () => {
|
|
657
|
+
listeners.delete(listener);
|
|
658
|
+
};
|
|
659
|
+
},
|
|
660
|
+
load
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
function apply(ctx) {
|
|
664
|
+
const c = ctx;
|
|
665
|
+
const tag = injectStyle();
|
|
666
|
+
c.effect(() => () => {
|
|
667
|
+
tag?.remove();
|
|
668
|
+
}, "subagent-model: style");
|
|
669
|
+
c.effect(() => c.locale.register(NS, {
|
|
670
|
+
zh,
|
|
671
|
+
en
|
|
672
|
+
}), "subagent-model: locale");
|
|
673
|
+
const api = c.get("connection").api.settings;
|
|
674
|
+
const scope = createApiScope(api, SETTINGS_NS, c);
|
|
675
|
+
c.slots.inject("settings.plugin.item", () => c.slots.register({
|
|
676
|
+
name: "settings.plugin.item",
|
|
677
|
+
key: SETTINGS_NS,
|
|
678
|
+
locale: NS,
|
|
679
|
+
inject: () => ({
|
|
680
|
+
t: c.locale.bind(NS),
|
|
681
|
+
scope,
|
|
682
|
+
api
|
|
683
|
+
})
|
|
684
|
+
}, SubagentModelCard));
|
|
685
|
+
}
|
|
686
|
+
//#endregion
|
|
687
|
+
exports.apply = apply;
|
|
688
|
+
exports.inject = inject;
|
|
689
|
+
exports.name = name;
|
|
714
690
|
return module.exports;
|
|
715
691
|
}
|
|
716
692
|
});
|