@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 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
- //#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",
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
- /* @__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;
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
- }, [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
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
- 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 : ""}`
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
- }).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", {
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
- 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",
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
- status.kind !== "idle" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
439
- className: `dsm-status${status.kind === "error" ? " dsm-statusError" : ""}`,
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: status.text
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)("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")
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.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")
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
- }) : 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 = `
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
- 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;
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
- 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",
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
- 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);
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
- 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;
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
  });