@dsh-plus/subagent-model 0.1.6 → 0.1.8

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