dsh-subagent-library 0.3.6 → 0.4.1

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
@@ -28,6 +28,245 @@ react = __toESM(react);
28
28
  let react_jsx_runtime = require("react/jsx-runtime");
29
29
  react_jsx_runtime = __toESM(react_jsx_runtime);
30
30
 
31
+ //#region src/entry-id.ts
32
+ /** Entry ids are lowercase DNS-like labels. Also enforced for file names. */
33
+ const ENTRY_ID = /^[a-z0-9][a-z0-9-]*$/;
34
+ /** NTFS single component cap is 255; `<id>.yaml` plus headroom stays far below. */
35
+ const MAX_ID_LENGTH = 64;
36
+ const RESERVED_NAMES = new Set([
37
+ "con",
38
+ "prn",
39
+ "aux",
40
+ "nul",
41
+ ...Array.from({ length: 9 }, (_, index) => `com${index + 1}`),
42
+ ...Array.from({ length: 9 }, (_, index) => `lpt${index + 1}`)
43
+ ]);
44
+ function entryIdIssue(id) {
45
+ if (!id) return "required";
46
+ if (!/^[a-z0-9]/.test(id)) return "start";
47
+ if (!ENTRY_ID.test(id)) return "characters";
48
+ if (id.length > MAX_ID_LENGTH) return "length";
49
+ if (RESERVED_NAMES.has(id)) return "reserved";
50
+ }
51
+ /** Check draft member codes using the same trimming the settings writer applies. */
52
+ function memberCodeErrors(values) {
53
+ const codes = values.map((value) => value.trim());
54
+ const seen = /* @__PURE__ */ new Set();
55
+ const duplicates = /* @__PURE__ */ new Set();
56
+ for (const code of codes) {
57
+ if (seen.has(code)) duplicates.add(code);
58
+ seen.add(code);
59
+ }
60
+ return codes.map((code) => {
61
+ switch (entryIdIssue(code)) {
62
+ case "required": return "请填写成员代号。";
63
+ case "start": return "成员代号须以小写字母或数字开头。";
64
+ case "characters": return "成员代号只能使用小写字母、数字和短横线。";
65
+ case "length": return `成员代号最多 ${MAX_ID_LENGTH} 个字符。`;
66
+ case "reserved": return "这个成员代号是系统保留名称,请换一个。";
67
+ default: return duplicates.has(code) ? "此代号已在编队中使用,请换一个。" : void 0;
68
+ }
69
+ });
70
+ }
71
+
72
+ //#endregion
73
+ //#region src/client/editor-state.ts
74
+ const NEW = "@new";
75
+ const own = (rows, id) => Object.hasOwn(rows, id) ? rows[id] : void 0;
76
+ function emptyMember() {
77
+ return {
78
+ slot: "",
79
+ role: "",
80
+ assignment: ""
81
+ };
82
+ }
83
+ /** Pick an unused valid member code derived from a role ID. */
84
+ function suggestSlot(roleId, otherSlots) {
85
+ const base = roleId.trim();
86
+ if (entryIdIssue(base)) return "";
87
+ const used = new Set(otherSlots.map((slot) => slot.trim()).filter(Boolean));
88
+ if (!used.has(base)) return base;
89
+ for (let n = 2; n < 1e3; n++) {
90
+ const suffix = `-${n}`;
91
+ const candidate = `${base.slice(0, MAX_ID_LENGTH - suffix.length).replace(/-+$/, "") || "m"}${suffix}`;
92
+ if (!used.has(candidate) && !entryIdIssue(candidate)) return candidate;
93
+ }
94
+ return "";
95
+ }
96
+ /** Place enabled items before disabled items while preserving relative order within each group. */
97
+ function sortByEnabled(ids, isEnabled) {
98
+ const enabled = [];
99
+ const disabled = [];
100
+ for (const id of ids) (isEnabled(id) ? enabled : disabled).push(id);
101
+ return [...enabled, ...disabled];
102
+ }
103
+ function roleForm(id, row) {
104
+ return {
105
+ kind: "roles",
106
+ id,
107
+ enabled: row.enabled !== false,
108
+ description: row.description ?? "",
109
+ provider: row.provider ?? "",
110
+ model: row.model ?? "",
111
+ reasoningEffort: row.reasoningEffort ?? "",
112
+ maxTokens: String(row.maxTokens ?? ""),
113
+ maxDepth: String(row.maxDepth ?? ""),
114
+ subagentProvider: row.subagentProvider ?? "",
115
+ persona: row.persona ?? "",
116
+ filter: row.toolFilter,
117
+ routeNote: row.routeNote,
118
+ inherit: false,
119
+ clearToolFilter: false
120
+ };
121
+ }
122
+ function groupForm(id, group) {
123
+ return {
124
+ kind: "groups",
125
+ id,
126
+ enabled: group.enabled !== false,
127
+ description: group.description,
128
+ name: group.name ?? "",
129
+ instructions: group.instructions ?? "",
130
+ members: group.members.map(({ slot, role, assignment }) => ({
131
+ slot,
132
+ role,
133
+ assignment: assignment ?? ""
134
+ }))
135
+ };
136
+ }
137
+ function serverForm(view, tab, id) {
138
+ if (tab === "groups") {
139
+ const group = own(view.groups, id);
140
+ return group && groupForm(id, group);
141
+ }
142
+ const role = own(view.entries, id);
143
+ if (!role) return void 0;
144
+ return roleForm(id, view.profile ? role : {
145
+ ...role,
146
+ ...own(view.sharedEntries, id)
147
+ });
148
+ }
149
+ function freshDraft(view, tab, id) {
150
+ const base = serverForm(view, tab, id);
151
+ return {
152
+ form: base ?? (tab === "roles" ? roleForm("", {}) : groupForm("", {
153
+ description: "",
154
+ members: [emptyMember()]
155
+ })),
156
+ base
157
+ };
158
+ }
159
+ const equal = (a, b) => JSON.stringify(a) === JSON.stringify(b);
160
+ /** Keep edited fields and bring untouched ones forward after an explicit comparison. */
161
+ function rebase(draft, current) {
162
+ if (!current || !draft.base) return {
163
+ form: draft.form,
164
+ base: current
165
+ };
166
+ const base = draft.base;
167
+ const changes = Object.fromEntries(Object.entries(draft.form).filter(([key, value]) => !equal(value, Reflect.get(base, key))));
168
+ const form = {
169
+ ...current,
170
+ ...changes
171
+ };
172
+ if (form.kind === "roles" && form.inherit) return {
173
+ base: current,
174
+ form: {
175
+ ...form,
176
+ provider: "",
177
+ model: "",
178
+ reasoningEffort: "",
179
+ maxTokens: ""
180
+ }
181
+ };
182
+ return {
183
+ base: current,
184
+ form
185
+ };
186
+ }
187
+ function validate(form, view, isNew, base) {
188
+ const id = form.id.trim();
189
+ const idIssue = entryIdIssue(id);
190
+ if (idIssue === "reserved") return "这个 ID 是系统保留名称,请换一个。";
191
+ if (idIssue && form.kind === "groups") {
192
+ if (idIssue === "required") return "请填写编队 ID。";
193
+ if (/\s/.test(id)) return "编队 ID 中不能有空格,可以用短横线连接单词。";
194
+ return "请按上面的格式修改编队 ID,例如 review-group。";
195
+ }
196
+ if (idIssue) return "ID 可使用小写字母、数字和短横线,以字母或数字开头,最长 64 个字符。";
197
+ if (isNew && serverForm(view, form.kind, id)) return "此 ID 已存在,请换一个。";
198
+ if (!form.description.trim()) return "请填写描述。";
199
+ if (form.kind === "roles") {
200
+ for (const [value, min, label] of [[
201
+ form.maxDepth,
202
+ 0,
203
+ "深度上限"
204
+ ], [
205
+ form.maxTokens,
206
+ 1,
207
+ "输出上限"
208
+ ]]) if (value && (!Number.isSafeInteger(Number(value)) || Number(value) < min)) return `${label}需为 ≥${min} 的整数。`;
209
+ return;
210
+ }
211
+ if (!form.members.length) return "请添加至少一名编队成员。";
212
+ const codeError = memberCodeErrors(form.members.map((m) => m.slot)).find(Boolean);
213
+ if (codeError) return codeError;
214
+ for (const member of form.members) {
215
+ const unchanged = base?.kind === "groups" && base.members.some((m) => m.slot === member.slot.trim() && m.role === member.role);
216
+ if (!member.role || !unchanged && !own(view.entries, member.role)) return "请为每位成员选择名册中的角色。";
217
+ }
218
+ }
219
+ function routeFields(form) {
220
+ return {
221
+ ...form.provider.trim() && { provider: form.provider.trim() },
222
+ ...form.model.trim() && { model: form.model.trim() },
223
+ ...form.reasoningEffort.trim() && { reasoningEffort: form.reasoningEffort.trim() },
224
+ ...form.maxTokens && { maxTokens: Number(form.maxTokens) }
225
+ };
226
+ }
227
+ function saveWrite(draft, view) {
228
+ const { form, base } = draft;
229
+ const id = form.id.trim();
230
+ const expectedHash = view.hash;
231
+ const common = {
232
+ description: form.description,
233
+ ...!form.enabled && { enabled: false }
234
+ };
235
+ if (form.kind === "groups") return {
236
+ op: "save-group",
237
+ id,
238
+ expectedHash,
239
+ group: {
240
+ ...common,
241
+ ...form.name.trim() && { name: form.name.trim() },
242
+ ...form.instructions && { instructions: form.instructions },
243
+ members: form.members.map((m) => ({
244
+ slot: m.slot.trim(),
245
+ role: m.role,
246
+ ...m.assignment && { assignment: m.assignment }
247
+ }))
248
+ }
249
+ };
250
+ const fields = routeFields(form);
251
+ const previous = base?.kind === "roles" ? routeFields(base) : {};
252
+ const routeChanged = form.inherit || !equal(fields, previous);
253
+ return {
254
+ op: "save-entry",
255
+ id,
256
+ expectedHash,
257
+ entry: {
258
+ ...common,
259
+ ...form.persona && { persona: form.persona },
260
+ ...!base && form.filter && !form.clearToolFilter && { toolFilter: form.filter },
261
+ ...form.subagentProvider.trim() && { subagentProvider: form.subagentProvider.trim() },
262
+ ...form.maxDepth && { maxDepth: Number(form.maxDepth) }
263
+ },
264
+ ...routeChanged && { route: form.inherit || !Object.keys(fields).length ? { inherit: true } : fields },
265
+ ...form.clearToolFilter && { clearToolFilter: true }
266
+ };
267
+ }
268
+
269
+ //#endregion
31
270
  //#region src/client/settings-theme.ts
32
271
  /** Host theme tokens keep the roster at home in both desktop color schemes. */
33
272
  const TOKEN = {
@@ -50,9 +289,6 @@ const TOKEN = {
50
289
  danger: "var(--dsw-alias-state-error-primary, #dc2626)",
51
290
  dangerSoft: "var(--dsw-alias-state-error-secondary, rgba(220,38,38,0.12))"
52
291
  };
53
- const ACCENT = TOKEN.accent;
54
- const SUCCESS = TOKEN.success;
55
- const DANGER = TOKEN.danger;
56
292
  const MONO = "ui-monospace, SFMono-Regular, Consolas, \"Liberation Mono\", Menlo, monospace";
57
293
  const button = {
58
294
  display: "inline-flex",
@@ -65,11 +301,12 @@ const button = {
65
301
  fontFamily: "inherit",
66
302
  fontWeight: 500,
67
303
  borderRadius: 8,
68
- border: `1px solid ${TOKEN.borderStrong}`,
304
+ border: `1px solid ${TOKEN.border}`,
69
305
  background: "transparent",
70
306
  color: TOKEN.secondary,
71
307
  cursor: "pointer",
72
- whiteSpace: "nowrap"
308
+ whiteSpace: "nowrap",
309
+ transition: "background-color 140ms ease, border-color 140ms ease, color 140ms ease, filter 140ms ease"
73
310
  };
74
311
  const chip = {
75
312
  display: "inline-flex",
@@ -88,21 +325,16 @@ const S = {
88
325
  root: {
89
326
  display: "flex",
90
327
  flexDirection: "column",
91
- gap: 16,
328
+ gap: 14,
92
329
  width: "100%",
93
330
  minWidth: 0,
94
331
  maxWidth: 880,
95
332
  boxSizing: "border-box",
96
- padding: "16px 4px",
333
+ padding: "6px 4px 14px",
97
334
  color: TOKEN.primary,
98
335
  containerType: "inline-size",
99
336
  containerName: "dsh-library"
100
337
  },
101
- pageHeader: {
102
- display: "flex",
103
- flexDirection: "column",
104
- gap: 7
105
- },
106
338
  headingRow: {
107
339
  display: "flex",
108
340
  alignItems: "center",
@@ -110,66 +342,17 @@ const S = {
110
342
  flexWrap: "wrap"
111
343
  },
112
344
  heading: {
113
- fontSize: 20,
114
- lineHeight: 1.4,
345
+ fontSize: 19,
346
+ lineHeight: 1.35,
115
347
  fontWeight: 650,
116
- letterSpacing: "-0.025em",
117
- margin: 0
118
- },
119
- sub: {
120
- fontSize: 12.5,
121
- lineHeight: 1.65,
122
- color: TOKEN.muted,
348
+ letterSpacing: "-0.02em",
123
349
  margin: 0
124
350
  },
125
- band: {
126
- display: "flex",
127
- flexDirection: "column",
128
- gap: 10,
129
- padding: "13px 16px",
130
- background: TOKEN.inset,
131
- borderRadius: 10
132
- },
133
- bandStats: {
134
- display: "flex",
135
- alignItems: "baseline",
136
- gap: "8px 24px",
137
- flexWrap: "wrap"
138
- },
139
- bandStat: {
140
- display: "flex",
141
- alignItems: "baseline",
142
- gap: 6
143
- },
144
- bandValue: {
145
- fontSize: 19,
146
- fontWeight: 600,
147
- lineHeight: 1.3,
148
- fontVariantNumeric: "tabular-nums"
149
- },
150
- bandLabel: {
151
- fontSize: 11.5,
152
- color: TOKEN.muted,
153
- flexShrink: 0
154
- },
155
- bandDir: {
156
- display: "flex",
157
- alignItems: "baseline",
158
- gap: 10,
159
- minWidth: 0
160
- },
161
- bandPath: {
162
- fontFamily: MONO,
163
- fontSize: 11.5,
164
- color: TOKEN.secondary,
165
- overflowWrap: "anywhere",
166
- minWidth: 0
167
- },
168
351
  banner: {
169
352
  fontSize: 12.5,
170
353
  lineHeight: 1.65,
171
354
  padding: "10px 12px",
172
- borderRadius: 8,
355
+ borderRadius: 9,
173
356
  display: "flex",
174
357
  flexDirection: "column",
175
358
  gap: 6,
@@ -189,7 +372,6 @@ const S = {
189
372
  minWidth: 0,
190
373
  minHeight: 34,
191
374
  padding: "6px 10px",
192
- border: `1px solid ${TOKEN.borderStrong}`,
193
375
  borderRadius: 8
194
376
  },
195
377
  searchInput: {
@@ -203,39 +385,16 @@ const S = {
203
385
  fontSize: 13,
204
386
  fontFamily: "inherit"
205
387
  },
206
- listCaption: {
207
- display: "flex",
208
- justifyContent: "space-between",
209
- gap: "4px 12px",
210
- flexWrap: "wrap",
211
- fontSize: 11.5,
212
- color: TOKEN.muted,
213
- marginTop: 2,
214
- marginBottom: -7
215
- },
216
388
  list: {
217
389
  display: "flex",
218
390
  flexDirection: "column",
219
391
  gap: 10
220
392
  },
221
- row: {
222
- minWidth: 0,
223
- border: `1px solid ${TOKEN.border}`,
224
- borderRadius: 12,
225
- background: TOKEN.surface,
226
- overflow: "hidden",
227
- transition: "border-color 140ms ease, box-shadow 140ms ease"
228
- },
229
- rowOpen: {
230
- borderColor: TOKEN.accent,
231
- boxShadow: `0 0 0 1px ${TOKEN.accentSoft}`
232
- },
233
- rowOff: { background: "transparent" },
234
393
  head: {
235
394
  display: "flex",
236
395
  alignItems: "flex-start",
237
396
  gap: 12,
238
- padding: "12px 16px 0 12px"
397
+ padding: "12px 16px 2px 12px"
239
398
  },
240
399
  disclosure: {
241
400
  display: "flex",
@@ -251,7 +410,8 @@ const S = {
251
410
  borderRadius: 4,
252
411
  color: TOKEN.primary,
253
412
  background: "transparent",
254
- cursor: "pointer"
413
+ cursor: "pointer",
414
+ transition: "color 140ms ease"
255
415
  },
256
416
  titleRow: {
257
417
  display: "flex",
@@ -269,11 +429,11 @@ const S = {
269
429
  alignItems: "center",
270
430
  justifyContent: "center",
271
431
  color: TOKEN.muted,
272
- transition: "transform 140ms ease"
432
+ transition: "transform 160ms cubic-bezier(0.22, 1, 0.36, 1), color 140ms ease"
273
433
  },
274
434
  id: {
275
435
  fontSize: 14,
276
- lineHeight: 1.6,
436
+ lineHeight: 1.55,
277
437
  fontWeight: 650,
278
438
  fontFamily: MONO,
279
439
  overflowWrap: "anywhere",
@@ -287,13 +447,14 @@ const S = {
287
447
  minHeight: 28,
288
448
  fontSize: 11.5,
289
449
  color: TOKEN.muted,
290
- cursor: "pointer"
450
+ cursor: "pointer",
451
+ userSelect: "none"
291
452
  },
292
453
  overview: {
293
454
  display: "flex",
294
455
  flexDirection: "column",
295
- gap: 9,
296
- padding: "2px 16px 13px 36px",
456
+ gap: 8,
457
+ padding: "1px 16px 13px 36px",
297
458
  minWidth: 0
298
459
  },
299
460
  excerpt: {
@@ -311,7 +472,7 @@ const S = {
311
472
  display: "flex",
312
473
  flexWrap: "wrap",
313
474
  alignItems: "baseline",
314
- gap: "2px 8px",
475
+ gap: "3px 8px",
315
476
  minWidth: 0
316
477
  },
317
478
  metaLabel: {
@@ -333,79 +494,28 @@ const S = {
333
494
  fontSize: 11.5,
334
495
  color: TOKEN.muted,
335
496
  paddingLeft: 8,
336
- borderLeft: `1px solid ${TOKEN.borderStrong}`,
497
+ borderLeft: `1px solid ${TOKEN.border}`,
337
498
  overflowWrap: "anywhere",
338
499
  minWidth: 0,
339
500
  maxWidth: "100%"
340
501
  },
341
- glyphs: {
342
- display: "flex",
343
- alignItems: "center",
344
- gap: 6,
345
- flexWrap: "wrap",
346
- minWidth: 0
347
- },
348
502
  glyph: chip,
349
- metaValue: {
350
- fontFamily: MONO,
351
- fontVariantNumeric: "tabular-nums"
352
- },
353
- modeChip: {
354
- ...chip,
355
- color: TOKEN.accent,
356
- background: TOKEN.accentSoft
357
- },
358
- chip: {
359
- ...chip,
360
- fontSize: 10.5
361
- },
362
503
  dirtyChip: {
363
504
  ...chip,
364
- fontSize: 10.5,
505
+ fontSize: 11,
365
506
  color: TOKEN.warn,
366
507
  background: TOKEN.warnSoft
367
508
  },
368
- draftActions: {
369
- display: "flex",
370
- alignItems: "center",
371
- gap: 8,
372
- flexWrap: "wrap",
373
- padding: "9px 16px",
374
- borderTop: `1px solid ${TOKEN.divider}`
375
- },
376
- addHead: {
377
- display: "flex",
378
- alignItems: "center",
379
- flexWrap: "wrap",
380
- gap: 12,
381
- padding: "16px"
382
- },
383
- addIntro: {
384
- display: "flex",
385
- flex: "1 1 220px",
386
- flexDirection: "column",
387
- gap: 3,
388
- minWidth: 0
389
- },
390
509
  body: {
391
510
  display: "flex",
392
511
  flexDirection: "column",
393
- gap: 20,
394
- padding: 16,
512
+ gap: 13,
513
+ padding: "13px 15px 14px",
395
514
  borderTop: `1px solid ${TOKEN.divider}`
396
515
  },
397
- group: {
398
- display: "flex",
399
- flexDirection: "column",
400
- gap: 12
401
- },
402
- groupTitle: {
403
- fontSize: 12.5,
404
- fontWeight: 600,
405
- color: TOKEN.primary
406
- },
407
516
  fieldLabel: {
408
517
  fontSize: 12,
518
+ fontWeight: 500,
409
519
  color: TOKEN.secondary,
410
520
  marginBottom: 6,
411
521
  display: "block"
@@ -438,7 +548,6 @@ const S = {
438
548
  fontFamily: MONO,
439
549
  lineHeight: 1.5,
440
550
  padding: "6px 9px",
441
- border: `1px solid ${TOKEN.borderStrong}`,
442
551
  borderRadius: 7,
443
552
  background: "transparent",
444
553
  color: "inherit"
@@ -451,7 +560,6 @@ const S = {
451
560
  fontFamily: "inherit",
452
561
  lineHeight: 1.7,
453
562
  padding: "8px 10px",
454
- border: `1px solid ${TOKEN.borderStrong}`,
455
563
  borderRadius: 7,
456
564
  background: "transparent",
457
565
  color: "inherit",
@@ -463,18 +571,18 @@ const S = {
463
571
  primary: {
464
572
  ...button,
465
573
  padding: "5px 13px",
466
- borderColor: "transparent",
574
+ border: "1px solid transparent",
467
575
  background: TOKEN.accentFill,
468
576
  color: "#fff"
469
577
  },
470
578
  danger: {
471
579
  ...button,
472
- borderColor: TOKEN.dangerSoft,
580
+ border: `1px solid ${TOKEN.dangerSoft}`,
473
581
  color: TOKEN.danger
474
582
  },
475
583
  ghost: {
476
584
  ...button,
477
- borderColor: "transparent",
585
+ border: "1px solid transparent",
478
586
  color: TOKEN.muted
479
587
  },
480
588
  hint: {
@@ -494,24 +602,30 @@ const S = {
494
602
  borderRadius: 10
495
603
  },
496
604
  footer: {
497
- padding: "4px 0",
605
+ padding: "2px 0 4px",
498
606
  color: TOKEN.muted,
607
+ minWidth: 0,
499
608
  overflowWrap: "anywhere"
500
609
  },
501
- footerSummary: {
502
- cursor: "pointer",
610
+ footerNote: {
503
611
  fontSize: 11.5,
504
- paddingBottom: 8
612
+ lineHeight: 1.7,
613
+ color: TOKEN.muted,
614
+ margin: "4px 0 0",
615
+ paddingLeft: 18,
616
+ overflowWrap: "anywhere"
505
617
  }
506
618
  };
507
619
  const BANNER = {
508
620
  ok: {
509
621
  ...S.banner,
510
- background: TOKEN.successSoft
622
+ background: TOKEN.successSoft,
623
+ color: TOKEN.success
511
624
  },
512
625
  error: {
513
626
  ...S.banner,
514
- background: TOKEN.dangerSoft
627
+ background: TOKEN.dangerSoft,
628
+ color: TOKEN.danger
515
629
  },
516
630
  warn: {
517
631
  ...S.banner,
@@ -519,40 +633,191 @@ const BANNER = {
519
633
  },
520
634
  info: {
521
635
  ...S.banner,
522
- background: TOKEN.inset
636
+ background: TOKEN.inset,
637
+ border: `1px solid ${TOKEN.divider}`
523
638
  }
524
639
  };
525
640
  /** Scoped styles travel with the client bundle; no extra host CSS loader. */
526
641
  const SETTINGS_CSS = `
642
+ :is(:has(> .dsh-library), :has(> * > .dsh-library)) { scrollbar-gutter: stable; }
527
643
  .dsh-library *, .dsh-library *::before { box-sizing: border-box; }
528
- .dsh-library button:disabled { cursor: default !important; opacity: .5; }
529
- .dsh-library :is(button, input, textarea, select, summary):focus-visible {
530
- outline: 2px solid ${TOKEN.accent}; outline-offset: 3px;
644
+ .dsh-library button:disabled { cursor: default !important; opacity: .48; }
645
+ .dsh-library :is(button, summary):focus-visible {
646
+ outline: 2px solid ${TOKEN.accent}; outline-offset: 2px;
531
647
  }
532
- .dsh-library label:has(input[aria-label="筛选子代理"]):focus-within {
648
+ .dsh-library .dsh-library-switch:focus-visible {
533
649
  outline: 2px solid ${TOKEN.accent}; outline-offset: 2px;
534
650
  }
535
- .dsh-library input[aria-label="筛选子代理"]:focus-visible { outline: none; }
651
+ .dsh-library .library-search {
652
+ border: 1px solid ${TOKEN.border};
653
+ background: var(--dsw-alias-bg-base, transparent);
654
+ transition: border-color 140ms ease, box-shadow 140ms ease;
655
+ }
656
+ .dsh-library .library-search svg { color: ${TOKEN.muted}; flex: none; }
657
+ .dsh-library .library-search:focus-within {
658
+ border-color: ${TOKEN.accent};
659
+ box-shadow: 0 0 0 2px ${TOKEN.accentSoft};
660
+ }
661
+ .dsh-library .library-search input:focus-visible { outline: none; }
662
+ .dsh-library .library-panel {
663
+ display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0;
664
+ }
665
+ .dsh-library .library-banner code {
666
+ font-family: ${MONO}; font-size: 0.92em; padding: 1px 5px; border-radius: 4px;
667
+ background: var(--dsw-alias-bg-base, rgba(128,128,128,0.1));
668
+ }
669
+ .dsh-library .library-footer code {
670
+ font-family: ${MONO}; font-size: 0.92em; padding: 1px 5px; border-radius: 4px;
671
+ background: ${TOKEN.inset};
672
+ }
673
+ .dsh-library .library-tabs { display: flex; gap: 18px; border-bottom: 1px solid ${TOKEN.divider}; }
674
+ .dsh-library .library-tabs button {
675
+ display: inline-flex; align-items: center; gap: 6px;
676
+ padding: 6px 2px 9px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent;
677
+ background: transparent; color: ${TOKEN.secondary}; font: inherit; font-size: 13px; font-weight: 600;
678
+ cursor: pointer; transition: color 140ms ease, border-color 140ms ease;
679
+ }
680
+ .dsh-library .library-tabs button[aria-selected=true] { color: ${TOKEN.accent}; border-bottom-color: currentColor; }
681
+ .dsh-library .library-tab-count {
682
+ display: inline-flex; align-items: center; justify-content: center;
683
+ min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
684
+ font-size: 11px; font-weight: 550; line-height: 1;
685
+ background: ${TOKEN.inset}; color: ${TOKEN.muted};
686
+ transition: background-color 140ms ease, color 140ms ease;
687
+ }
688
+ .dsh-library .library-tabs button[aria-selected=true] .library-tab-count {
689
+ background: ${TOKEN.accentSoft}; color: ${TOKEN.accent};
690
+ }
691
+ .dsh-library .library-tab-dot {
692
+ width: 6px; height: 6px; border-radius: 50%; background: ${TOKEN.warn}; flex: none;
693
+ }
694
+ .dsh-library .dsh-library-card {
695
+ min-width: 0; border: 1px solid ${TOKEN.border}; border-radius: 12px;
696
+ background: ${TOKEN.surface}; overflow: hidden;
697
+ transition: border-color 160ms cubic-bezier(0.22, 1, 0.36, 1),
698
+ box-shadow 160ms cubic-bezier(0.22, 1, 0.36, 1),
699
+ background-color 160ms ease;
700
+ }
701
+ .dsh-library .dsh-library-card[data-disabled] {
702
+ background: transparent; border-color: ${TOKEN.divider};
703
+ }
704
+ .dsh-library .dsh-library-card[data-disabled] .library-card-title,
705
+ .dsh-library .dsh-library-card[data-disabled] .library-card-overview {
706
+ opacity: .68;
707
+ }
708
+ .dsh-library .dsh-library-card[data-open] {
709
+ border-color: ${TOKEN.accent};
710
+ box-shadow: 0 0 0 1px ${TOKEN.accentSoft}, 0 2px 10px rgba(0, 0, 0, 0.04);
711
+ }
712
+ .dsh-library .dsh-library-card[data-open] .library-card-head { padding-bottom: 11px; }
713
+ .dsh-library .dsh-library-card[data-open] .library-card-title { opacity: 1; }
714
+ .dsh-library .library-editor { min-width: 0; border: 0; margin: 0; }
715
+ .dsh-library .library-editor :is(input:not([type=checkbox]), textarea, select) {
716
+ border: 1px solid ${TOKEN.border};
717
+ background: var(--dsw-alias-bg-base, transparent);
718
+ transition: border-color 140ms ease, box-shadow 140ms ease;
719
+ }
720
+ .dsh-library .library-editor :is(input:not([type=checkbox]), textarea, select):focus {
721
+ outline: none;
722
+ border-color: ${TOKEN.accent};
723
+ box-shadow: 0 0 0 2px ${TOKEN.accentSoft};
724
+ }
725
+ .dsh-library h3 { margin: 0; font-size: 13px; font-weight: 650; }
726
+ .dsh-library .library-editor textarea { min-height: 51px !important; }
727
+ .dsh-library .library-editor [data-field=assignment] { min-height: 35px !important; }
728
+ .dsh-library .library-editor [data-field=instructions] { min-height: 76px !important; }
729
+ .dsh-library .library-editor [data-field=persona] { min-height: 118px !important; }
730
+ .dsh-library .library-editor input:read-only { background: ${TOKEN.inset} !important; color: ${TOKEN.secondary}; }
731
+ .dsh-library .library-advanced {
732
+ border: 1px solid ${TOKEN.divider}; border-radius: 8px;
733
+ padding: 8px 11px; background: var(--dsw-alias-bg-base, transparent);
734
+ }
735
+ .dsh-library .library-advanced > summary,
736
+ .dsh-library .library-footer > summary {
737
+ display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 6px;
738
+ cursor: pointer; list-style: none; user-select: none; border-radius: 4px;
739
+ }
740
+ .dsh-library .library-advanced > summary { font-size: 12px; font-weight: 550; color: ${TOKEN.secondary}; }
741
+ .dsh-library .library-footer > summary { font-size: 11.5px; color: ${TOKEN.muted}; padding: 2px 4px 2px 0; transition: color 140ms ease; }
742
+ .dsh-library .library-advanced > summary::-webkit-details-marker,
743
+ .dsh-library .library-footer > summary::-webkit-details-marker { display: none; }
744
+ .dsh-library .library-advanced > summary::before,
745
+ .dsh-library .library-footer > summary::before {
746
+ content: '❯'; font-size: 9.5px; color: ${TOKEN.muted};
747
+ transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1); display: inline-block; width: 12px; text-align: center;
748
+ }
749
+ .dsh-library .library-advanced[open] > summary::before,
750
+ .dsh-library .library-footer[open] > summary::before { transform: rotate(90deg); }
751
+ .dsh-library .library-advanced-body { padding-top: 10px; margin-top: 8px; border-top: 1px solid ${TOKEN.divider}; }
752
+ .dsh-library .library-member-chip { font-family: ${MONO}; font-size: 11px; }
753
+ .dsh-library .library-members-head {
754
+ display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
755
+ gap: 5px 10px; padding-top: 8px; border-top: 1px solid ${TOKEN.divider};
756
+ }
757
+ .dsh-library .library-members { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
758
+ .dsh-library .library-members li {
759
+ display: grid; gap: 7px; min-width: 0; padding: 9px 11px 11px;
760
+ border: 1px solid ${TOKEN.border}; border-radius: 9px; background: var(--dsw-alias-bg-base, transparent);
761
+ }
762
+ .dsh-library .library-member-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 12px; }
763
+ .dsh-library .library-member-head button { min-height: 27px !important; padding: 2px 6px !important; }
764
+ .dsh-library .library-link {
765
+ border: 0 !important; padding: 0 !important; min-height: 0 !important; display: inline !important;
766
+ color: ${TOKEN.accent} !important; white-space: normal !important; text-align: left; text-decoration: underline; overflow-wrap: anywhere;
767
+ background: transparent !important;
768
+ }
769
+ .dsh-library .library-field-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; padding-top: 2px; }
770
+ .dsh-library .library-field-actions > button { min-height: 24px !important; }
771
+ .dsh-library .library-field-note { padding-top: 4px; }
772
+ .dsh-library .library-field-error { color: ${TOKEN.danger}; font-size: 11.5px; line-height: 1.65; overflow-wrap: anywhere; }
773
+ .dsh-library .library-field-error:not(:empty) { margin-top: 4px; }
774
+ .dsh-library [data-field=slot][aria-invalid=true] { border-color: ${TOKEN.danger} !important; box-shadow: 0 0 0 2px ${TOKEN.dangerSoft} !important; }
775
+ .dsh-library [data-field=role-id] { user-select: text; }
776
+ .dsh-library .library-refs ul { padding-inline-start: 19px; margin: 4px 0; }
777
+ .dsh-library .library-dialog {
778
+ width: min(540px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 17px;
779
+ border: 1px solid ${TOKEN.borderStrong}; border-radius: 12px; background: var(--dsw-alias-bg-base, Canvas);
780
+ color: var(--dsw-alias-label-primary, CanvasText); box-shadow: 0 8px 30px #13182633; font: inherit; font-size: 13px;
781
+ }
782
+ .dsh-library .library-dialog::backdrop { background: #10152260; }
783
+ .dsh-library .library-compare { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; margin-top: 10px; }
784
+ .dsh-library .library-compare article { background: ${TOKEN.inset}; padding: 8px; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
785
+ .dsh-library .library-compare dl { margin: 5px 0 0; }
786
+ .dsh-library .library-compare dt, .dsh-library .library-compare dd { display: inline; margin: 0; }
787
+ .dsh-library .library-compare dt { font-weight: 600; margin-inline-end: 5px; }
536
788
  .dsh-library select option { background: ${TOKEN.surface}; color: ${TOKEN.primary}; }
537
789
  .dsh-library-switch {
538
790
  appearance: none; position: relative; display: inline-block; flex: none;
539
791
  width: 30px; height: 18px; margin: 0; border: 1px solid ${TOKEN.borderStrong};
540
792
  border-radius: 999px; background: ${TOKEN.hover}; cursor: pointer;
541
- transition: background 140ms ease;
793
+ transition: background-color 160ms ease, border-color 160ms ease;
542
794
  }
543
795
  .dsh-library-switch::before {
544
796
  content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
545
- border-radius: 50%; background: ${TOKEN.muted}; transition: transform 140ms ease;
797
+ border-radius: 50%; background: ${TOKEN.muted};
798
+ transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1), background-color 160ms ease;
546
799
  }
547
800
  .dsh-library-switch:checked { background: ${TOKEN.accentFill}; border-color: transparent; }
548
801
  .dsh-library-switch:checked::before { transform: translateX(12px); background: #fff; }
549
- @container dsh-library (max-width: 520px) {
550
- .dsh-library-grid { grid-template-columns: minmax(0, 1fr) !important; }
802
+ @container dsh-library (max-width: 285px) {
803
+ .dsh-library .library-grid, .dsh-library .library-compare { grid-template-columns: minmax(0, 1fr) !important; }
551
804
  }
552
805
  @media (hover: hover) {
553
- .dsh-library-card:hover { border-color: ${TOKEN.borderStrong}; }
554
- .dsh-library-disclosure:hover { color: ${TOKEN.accent} !important; }
555
- .dsh-library button:not(:disabled):hover { filter: brightness(.96); }
806
+ .dsh-library .dsh-library-card:not([data-open]):hover { border-color: ${TOKEN.borderStrong}; }
807
+ .dsh-library .dsh-library-disclosure:hover { color: ${TOKEN.accent} !important; }
808
+ .dsh-library .dsh-library-disclosure:hover .library-card-chevron { color: ${TOKEN.accent} !important; }
809
+ .dsh-library .library-tabs button:not([aria-selected=true]):hover { color: ${TOKEN.primary}; }
810
+ .dsh-library .library-search:not(:focus-within):hover { border-color: ${TOKEN.borderStrong}; }
811
+ .dsh-library .library-editor :is(input:not([type=checkbox]):not(:read-only), textarea, select):not(:focus):hover {
812
+ border-color: ${TOKEN.borderStrong};
813
+ }
814
+ .dsh-library .library-footer > summary:hover { color: ${TOKEN.secondary}; }
815
+ .dsh-library button[data-tone=button]:not(:disabled):not(.library-link):hover {
816
+ background: ${TOKEN.hover} !important; border-color: ${TOKEN.borderStrong} !important; color: ${TOKEN.primary} !important;
817
+ }
818
+ .dsh-library button[data-tone=primary]:not(:disabled):hover { filter: brightness(.93); }
819
+ .dsh-library button[data-tone=danger]:not(:disabled):hover { background: ${TOKEN.dangerSoft} !important; border-color: ${TOKEN.danger} !important; }
820
+ .dsh-library button[data-tone=ghost]:not(:disabled):hover { background: ${TOKEN.hover} !important; color: ${TOKEN.primary} !important; }
556
821
  }
557
822
  @media (prefers-reduced-motion: reduce) {
558
823
  .dsh-library *, .dsh-library *::before { transition: none !important; }
@@ -564,1261 +829,1408 @@ const SETTINGS_CSS = `
564
829
  `;
565
830
 
566
831
  //#endregion
567
- //#region src/client/LibrarySettings.tsx
568
- /** Deep equality for the two entry shapes we compare (server row vs draft).
569
- * JSON round-trip is enough: every field is a string, number, boolean, or
570
- * array of strings, and key order is stable because both sides are built by
571
- * the same spread-from-server path. */
572
- const sameEntry = (a, b) => JSON.stringify(a) === JSON.stringify(b);
573
- /** Content-adaptive textarea: grows with its text (clamped) so long personas
574
- * are readable without dragging while short ones stay compact. Re-measures
575
- * after every render (value changes re-render) and on input. */
576
- function AutoTextarea(props) {
577
- const { style,...rest } = props;
578
- const ref = (0, react.useRef)(null);
579
- const resize = () => {
580
- const el = ref.current;
581
- if (el === null) return;
582
- el.style.height = "auto";
583
- el.style.height = `${Math.min(Math.max(el.scrollHeight, 86), 440)}px`;
584
- };
585
- (0, react.useEffect)(() => {
586
- resize();
587
- });
588
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
589
- ...rest,
590
- ref,
591
- onInput: resize,
832
+ //#region src/client/editor-fields.tsx
833
+ function Action({ action, tone = "button", children,...props }) {
834
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
835
+ ...props,
836
+ type: "button",
837
+ "data-action": action,
838
+ "data-tone": tone,
592
839
  style: {
593
- ...style,
594
- overflow: "auto"
595
- }
840
+ ...S[tone],
841
+ ...props.style
842
+ },
843
+ children
596
844
  });
597
845
  }
598
- /** Single-line label + control, so every field in the editor lines up on the
599
- * same left edge regardless of how many share a row. */
600
- function Field(props) {
601
- const { label, hint, children } = props;
602
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
846
+ function Field({ label, name, value, change, multiline, hint, describedBy,...props }) {
847
+ const id = (0, react.useId)();
848
+ const hintId = hint ? `${id}-hint` : void 0;
849
+ const description = [describedBy, hintId].filter(Boolean).join(" ") || void 0;
850
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
603
851
  style: S.field,
604
852
  children: [
605
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
853
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
854
+ htmlFor: id,
606
855
  style: S.fieldLabel,
607
856
  children: label
608
857
  }),
609
- children,
610
- hint !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
611
- style: {
612
- ...S.hint,
613
- marginTop: 3
614
- },
858
+ multiline ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
859
+ id,
860
+ "aria-describedby": description,
861
+ "data-field": name,
862
+ value,
863
+ rows: name === "persona" ? 5 : name === "instructions" ? 3 : name === "assignment" ? 1 : 2,
864
+ placeholder: props.placeholder,
865
+ onChange: (e) => change?.(e.target.value),
866
+ style: S.prose
867
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
868
+ ...props,
869
+ id,
870
+ "aria-describedby": description,
871
+ "data-field": name,
872
+ type: props.min === void 0 ? "text" : "number",
873
+ value,
874
+ onChange: (e) => change?.(e.target.value),
875
+ style: S.input
876
+ }),
877
+ hint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
878
+ id: hintId,
879
+ className: "library-field-note",
880
+ style: S.hint,
615
881
  children: hint
616
882
  })
617
883
  ]
618
884
  });
619
885
  }
620
- /** Chevron that rotates on open — the only motion in the page, and cheap. */
621
- function Chevron(props) {
622
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
623
- style: {
624
- ...S.chevron,
625
- transform: props.open ? "rotate(90deg)" : "none"
626
- },
627
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
628
- width: "11",
629
- height: "11",
630
- viewBox: "0 0 12 12",
631
- fill: "none",
632
- stroke: "currentColor",
633
- strokeWidth: "1.6",
634
- strokeLinecap: "round",
635
- strokeLinejoin: "round",
636
- "aria-hidden": "true",
637
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M4.5 2.5L8 6l-3.5 3.5" })
638
- })
886
+ function References({ refs, view, jump, title }) {
887
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
888
+ className: "library-refs",
889
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: title }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { children: refs.map((ref) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Action, {
890
+ action: "jump",
891
+ "data-group": ref.groupId,
892
+ "data-slot-id": ref.slot,
893
+ className: "library-link",
894
+ onClick: () => jump(ref),
895
+ children: [
896
+ own(view.groups, ref.groupId)?.name || ref.groupId,
897
+ " / ",
898
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: ref.slot })
899
+ ]
900
+ }) }, ref.groupId + "/" + ref.slot)) })]
639
901
  });
640
902
  }
641
- /** Parse / render the comma-separated deny list without ever dropping a
642
- * hand-written allow list the editor does not surface. */
643
- const parseList = (value) => value.split(",").map((item) => item.trim()).filter(Boolean);
644
- const listToText = (list) => (list ?? []).join(", ");
645
- /** Draft actions disappear on success. Keep keyboard focus on their card. */
646
- function focusDisclosure(event) {
647
- if (event.detail === 0) event.currentTarget.closest("[data-entry-id]")?.querySelector("[data-row-id]")?.focus();
903
+ function availability(role) {
904
+ if (!role) return "角色缺失";
905
+ if (role.enabled === false) return "角色已停用";
906
+ if (role.toolFilter) return "旧工具限制";
907
+ if (role.launchable === false) {
908
+ if (role.routeNote === "profile-missing") return "当前 Provider 未注册";
909
+ if (role.routeNote === "overlay-broken") return "当前路由无法读取";
910
+ if (role.maxDepth === 0 || role.reason?.startsWith("maxDepth is 0")) return "深度上限为 0";
911
+ if (role.reason?.includes("native named activations")) return "宿主缺少原生具名派遣支持";
912
+ if (role.reason?.startsWith("subagent transport provider")) return "传输层未注册";
913
+ if (role.reason?.startsWith("Transport ")) return "传输层无法执行当前配置";
914
+ return "暂时无法派遣";
915
+ }
916
+ return "";
648
917
  }
649
- function LibrarySettings(props) {
650
- const { readView: readView$1, writeView: writeView$1, subscribeRefresh } = props;
651
- const sectionId = (0, react.useId)();
652
- const [view, setView] = (0, react.useState)(null);
653
- const [entries, setEntries] = (0, react.useState)({});
654
- const [busy, setBusy] = (0, react.useState)(false);
655
- const [status, setStatus] = (0, react.useState)(null);
656
- const [newId, setNewId] = (0, react.useState)("");
657
- const [newEntry, setNewEntry] = (0, react.useState)({
658
- description: "",
918
+ function memberState(view, form, member) {
919
+ if (!form.enabled) return "编队已停用";
920
+ if (!member.role) return "";
921
+ const reason = availability(own(view.entries, member.role));
922
+ if (reason) return reason;
923
+ const saved = own(view.groups, form.id);
924
+ if (saved && saved.enabled !== false && saved.members.some((m) => m.slot === member.slot && m.role === member.role && m.launchable === false)) return "暂时无法派遣";
925
+ return "";
926
+ }
927
+ const notes = {
928
+ "profile": "使用当前 profile 的独立路由。",
929
+ "inherit": "当前 profile 已设为跟随主会话模型(派遣时与主会话一致)。",
930
+ "foreign-ignored": "共享 Provider 未在此 profile 注册,当前跟随主会话模型。",
931
+ "profile-missing": "当前 profile 的 Provider 尚未注册,可更换 Provider 或改为跟随主会话模型。",
932
+ "overlay-broken": "当前 profile 的路由无法读取,可重新设置或设为跟随主会话模型。"
933
+ };
934
+ function RoleFields({ form, isNew, change, view, refs, jump, message }) {
935
+ const patch = (values) => change({
936
+ ...form,
937
+ ...values
938
+ });
939
+ const route = (field, value) => patch({
940
+ [field]: value,
941
+ inherit: false
942
+ });
943
+ const saved = own(view.entries, form.id);
944
+ const routeReadOnly = !!view.routeWriteProblem;
945
+ const hasRoute = [
946
+ form.provider,
947
+ form.model,
948
+ form.reasoningEffort,
949
+ form.maxTokens
950
+ ].some((value) => value.trim());
951
+ const savedHasRoute = Boolean(saved && [
952
+ saved.provider,
953
+ saved.model,
954
+ saved.reasoningEffort,
955
+ saved.maxTokens
956
+ ].some((v) => v !== void 0 && String(v).trim()));
957
+ const needsPin = form.routeNote === "overlay-broken" || form.routeNote === "foreign-ignored";
958
+ const pendingInherit = form.inherit || !hasRoute && savedHasRoute;
959
+ const alreadyInherit = !hasRoute && !savedHasRoute && !needsPin;
960
+ const inheritLabel = pendingInherit ? "保存后跟随主会话模型" : alreadyInherit ? "已跟随主会话模型" : hasRoute ? "改为跟随主会话模型" : "设为跟随主会话模型";
961
+ const clearRoute = (inherit) => patch({
962
+ inherit,
659
963
  provider: "",
660
964
  model: "",
661
- backgroundMode: "one-shot"
965
+ reasoningEffort: "",
966
+ maxTokens: ""
662
967
  });
663
- /** Editing is opt-in; newly created entries open to finish configuration. */
664
- const [open, setOpen] = (0, react.useState)({});
665
- const [adding, setAdding] = (0, react.useState)(false);
666
- const [filter, setFilter] = (0, react.useState)("");
667
- const alive = (0, react.useRef)(true);
668
- /** Synchronous busy flag (see applyWrite's re-entry guard). */
669
- const busyRef = (0, react.useRef)(false);
670
- (0, react.useEffect)(() => () => {
671
- alive.current = false;
672
- }, []);
673
- /** True while a write request is in flight: the push and the HTTP response
674
- * travel on independent channels, so a push may arrive before the response
675
- * commits our state. Pushes in this window are skipped and re-run after. */
676
- const pendingSelfWrite = (0, react.useRef)(false);
677
- const skippedWhilePending = (0, react.useRef)(false);
678
- const load = () => {
679
- (async () => {
680
- try {
681
- const next = await readView$1();
682
- if (!alive.current) return;
683
- setView(next);
684
- setEntries(structuredClone(next.entries));
685
- } catch (error) {
686
- if (alive.current) setStatus({
687
- kind: "error",
688
- text: String(error)
689
- });
690
- }
691
- })();
692
- };
968
+ const advancedSummary = [form.subagentProvider.trim() && `传输层 ${form.subagentProvider.trim()}`, form.maxDepth.trim() && `深度 ${form.maxDepth.trim()}`].filter(Boolean).join(" · ");
969
+ const advancedAlert = Boolean(message?.includes("深度上限") || saved?.reason?.startsWith("maxDepth is 0") || saved?.reason?.startsWith("subagent transport provider") || saved?.reason?.startsWith("Transport "));
970
+ const [advancedOpen, setAdvancedOpen] = (0, react.useState)(advancedAlert);
693
971
  (0, react.useEffect)(() => {
694
- load();
695
- return subscribeRefresh(() => {
696
- if (pendingSelfWrite.current) {
697
- skippedWhilePending.current = true;
698
- return;
699
- }
700
- load();
701
- });
702
- }, [subscribeRefresh]);
703
- const applyWrite = async (write, touchedId) => {
704
- if (busyRef.current) return false;
705
- busyRef.current = true;
706
- setBusy(true);
707
- setStatus(null);
708
- pendingSelfWrite.current = true;
709
- try {
710
- const result = await writeView$1(write);
711
- if (!alive.current) return false;
712
- pendingSelfWrite.current = false;
713
- const skipped = skippedWhilePending.current;
714
- skippedWhilePending.current = false;
715
- if (result.ok) {
716
- setView(result.view);
717
- setEntries((current) => {
718
- const next = { ...current };
719
- const fresh = result.view.entries[touchedId];
720
- if (fresh !== void 0) next[touchedId] = structuredClone(fresh);
721
- else delete next[touchedId];
722
- return next;
723
- });
724
- setStatus({
725
- kind: "ok",
726
- text: "已保存"
727
- });
728
- if (skipped) load();
729
- return true;
730
- }
731
- skippedWhilePending.current = false;
732
- if (result.conflict) {
733
- if (result.view !== void 0) setView(result.view);
734
- else load();
735
- setStatus({
736
- kind: "error",
737
- text: "名册已被其他窗口或外部修改(已切换到最新基线)。你的未保存修改已保留;再次保存将以你的版本覆盖。"
738
- });
739
- } else {
740
- if (skipped) load();
741
- setStatus({
742
- kind: "error",
743
- text: result.message ?? "保存失败"
744
- });
745
- }
746
- return false;
747
- } finally {
748
- pendingSelfWrite.current = false;
749
- busyRef.current = false;
750
- if (alive.current) setBusy(false);
751
- }
752
- };
753
- /** Normalize one entry for persistence: empty optional fields are dropped
754
- * (they then fall back to their defaults instead of being stored as '' or
755
- * stale values), and toolFilter survives only while it still scopes
756
- * something — an allow list alone must NOT be deleted by an editor that
757
- * only shows deny. */
758
- const cleanEntry = (entry) => {
759
- const clean = { ...entry };
760
- delete clean.source;
761
- delete clean.routeNote;
762
- if (clean.enabled === void 0 || clean.enabled) delete clean.enabled;
763
- if (clean.provider === "") delete clean.provider;
764
- if (clean.model === "") delete clean.model;
765
- if (clean.subagentProvider === "") delete clean.subagentProvider;
766
- if (clean.reasoningEffort === "") delete clean.reasoningEffort;
767
- if (clean.persona === "") delete clean.persona;
768
- if (clean.description === "") delete clean.description;
769
- if (clean.maxDepth === void 0) delete clean.maxDepth;
770
- if (clean.maxTokens === void 0) delete clean.maxTokens;
771
- const filter$1 = clean.toolFilter;
772
- if (filter$1 !== void 0 && (filter$1.allow === void 0 || filter$1.allow.length === 0) && (filter$1.deny === void 0 || filter$1.deny.length === 0)) delete clean.toolFilter;
773
- return clean;
774
- };
775
- const updateEntry = (id, entry) => {
776
- if ((entry.description ?? "").trim() === "") {
777
- setStatus({
778
- kind: "error",
779
- text: "描述不能为空。"
780
- });
781
- setOpen((current) => ({
782
- ...current,
783
- [id]: true
784
- }));
785
- return;
786
- }
787
- if (entry.maxDepth !== void 0 && (!Number.isInteger(entry.maxDepth) || entry.maxDepth < 1)) {
788
- setStatus({
789
- kind: "error",
790
- text: "深度上限需为 ≥1 的整数。"
791
- });
792
- setOpen((current) => ({
793
- ...current,
794
- [id]: true
795
- }));
796
- return;
797
- }
798
- if (entry.maxTokens !== void 0 && (!Number.isInteger(entry.maxTokens) || entry.maxTokens < 1)) {
799
- setStatus({
800
- kind: "error",
801
- text: "输出上限需为 ≥1 的整数。"
802
- });
803
- setOpen((current) => ({
804
- ...current,
805
- [id]: true
806
- }));
807
- return;
808
- }
809
- applyWrite({
810
- op: "save",
811
- entries: {
812
- ...view?.entries ?? {},
813
- [id]: cleanEntry(entry)
814
- },
815
- expectedHash: view?.hash
816
- }, id);
817
- };
818
- const removeEntry = (id) => {
819
- if (!window.confirm(`确认删除子代理 "${id}"?该操作立即删除其名册文件。`)) return;
820
- applyWrite({
821
- op: "delete",
822
- id,
823
- expectedHash: view?.hash
824
- }, id);
825
- };
826
- const addEntry = () => {
827
- const id = newId.trim();
828
- if (!/^[a-z0-9][a-z0-9-]*$/.test(id) || (newEntry.description ?? "").trim() === "") {
829
- setStatus({
830
- kind: "error",
831
- text: "ID 需为小写字母/数字/连字符,且必须有描述。"
832
- });
833
- return;
834
- }
835
- const serverEntries = view?.entries ?? {};
836
- if (serverEntries[id] !== void 0) {
837
- setStatus({
838
- kind: "error",
839
- text: `ID "${id}" 已存在。`
840
- });
841
- return;
972
+ if (advancedAlert) setAdvancedOpen(true);
973
+ }, [advancedAlert]);
974
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
975
+ saved?.launchable === false && saved.enabled !== false && !saved.toolFilter && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
976
+ style: BANNER.warn,
977
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: availability(saved) }), saved.reason && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: saved.reason })]
978
+ }),
979
+ isNew && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
980
+ name: "id",
981
+ label: "角色 ID",
982
+ value: form.id,
983
+ change: (id) => patch({ id }),
984
+ placeholder: "reviewer"
985
+ }),
986
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
987
+ name: "description",
988
+ label: "角色描述",
989
+ multiline: true,
990
+ value: form.description,
991
+ change: (description) => patch({ description })
992
+ }),
993
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("h3", { children: [view.profile || routeReadOnly ? "默认模型" : "共享默认模型", view.profile && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
994
+ style: S.hint,
995
+ children: [" · ", view.profile]
996
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
997
+ style: S.hint,
998
+ children: view.routeWriteProblem ?? (view.profile ? form.routeNote ? notes[form.routeNote] : "模型与思考档位按当前 profile 保存;派遣时也可按需临时切换其他授权模型。" : "这里编辑角色的共享默认模型。全部留空后保存,共享默认将跟随主会话模型。共享路由变更后,绑定旧默认路由的 profile 需重新设置。")
999
+ })] }),
1000
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1001
+ className: "library-grid",
1002
+ style: S.grid,
1003
+ children: [
1004
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1005
+ name: "provider",
1006
+ label: "Provider",
1007
+ value: form.provider,
1008
+ change: (v) => route("provider", v),
1009
+ readOnly: routeReadOnly,
1010
+ placeholder: "跟随主会话"
1011
+ }),
1012
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1013
+ name: "model",
1014
+ label: "模型",
1015
+ value: form.model,
1016
+ change: (v) => route("model", v),
1017
+ readOnly: routeReadOnly,
1018
+ placeholder: "跟随主会话"
1019
+ }),
1020
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1021
+ name: "reasoningEffort",
1022
+ label: "思考档位",
1023
+ value: form.reasoningEffort,
1024
+ change: (v) => route("reasoningEffort", v),
1025
+ readOnly: routeReadOnly,
1026
+ placeholder: "例如 high"
1027
+ }),
1028
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1029
+ name: "maxTokens",
1030
+ label: "输出上限",
1031
+ value: form.maxTokens,
1032
+ change: (v) => route("maxTokens", v),
1033
+ readOnly: routeReadOnly,
1034
+ min: 1,
1035
+ placeholder: "tokens"
1036
+ })
1037
+ ]
1038
+ }),
1039
+ !routeReadOnly && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: view.profile ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1040
+ action: "inherit",
1041
+ disabled: pendingInherit || alreadyInherit,
1042
+ onClick: () => clearRoute(true),
1043
+ children: inheritLabel
1044
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1045
+ action: "clear-shared-route",
1046
+ disabled: !hasRoute,
1047
+ onClick: () => clearRoute(false),
1048
+ children: "清空共享路由"
1049
+ }) }),
1050
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1051
+ name: "persona",
1052
+ label: "角色人设",
1053
+ multiline: true,
1054
+ value: form.persona,
1055
+ change: (persona) => patch({ persona }),
1056
+ placeholder: "定义这个角色的工作方式、检查视角或边界约束"
1057
+ }),
1058
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
1059
+ className: "library-advanced",
1060
+ open: advancedOpen,
1061
+ onToggle: (e) => setAdvancedOpen(e.currentTarget.open),
1062
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "高级选项" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1063
+ style: S.hint,
1064
+ children: advancedSummary || "传输层、深度上限"
1065
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1066
+ className: "library-advanced-body",
1067
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1068
+ className: "library-grid",
1069
+ style: S.grid,
1070
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1071
+ name: "subagentProvider",
1072
+ label: "传输层",
1073
+ value: form.subagentProvider,
1074
+ change: (subagentProvider) => patch({ subagentProvider }),
1075
+ placeholder: "spawn(默认)",
1076
+ hint: "留空使用默认 spawn(独立上下文);填 fork 可继承父会话历史。"
1077
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1078
+ name: "maxDepth",
1079
+ label: "深度上限",
1080
+ value: form.maxDepth,
1081
+ change: (maxDepth) => patch({ maxDepth }),
1082
+ min: 0,
1083
+ placeholder: "跟随宿主",
1084
+ hint: "留空时跟随宿主。填写后使用宿主与角色上限中较低的值,填 0 禁止派遣。"
1085
+ })]
1086
+ })
1087
+ })]
1088
+ }),
1089
+ form.filter && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1090
+ style: BANNER.warn,
1091
+ children: [
1092
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "旧工具限制" }),
1093
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "这个角色的工具限制无法在当前宿主执行。解除限制后可按宿主的权限派遣。" }),
1094
+ form.filter.allow && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["允许:", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: form.filter.allow.join(", ") || "空列表" })] }),
1095
+ form.filter.deny && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["禁用:", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: form.filter.deny.join(", ") || "空列表" })] }),
1096
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1097
+ type: "checkbox",
1098
+ "data-field": "clearToolFilter",
1099
+ checked: form.clearToolFilter,
1100
+ onChange: (e) => patch({ clearToolFilter: e.target.checked })
1101
+ }), " 保存时解除旧工具限制"] })
1102
+ ]
1103
+ }),
1104
+ refs.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1105
+ style: form.enabled ? BANNER.info : BANNER.warn,
1106
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(References, {
1107
+ refs,
1108
+ view,
1109
+ jump,
1110
+ title: form.enabled ? "使用此角色的编队成员" : "停用角色后,以下成员将无法派遣"
1111
+ })
1112
+ })
1113
+ ] });
1114
+ }
1115
+ function copySelection(id, doc) {
1116
+ const focused = doc.activeElement;
1117
+ const input = doc.createElement("textarea");
1118
+ input.value = id;
1119
+ input.readOnly = true;
1120
+ Object.assign(input.style, {
1121
+ position: "fixed",
1122
+ inset: "0 auto auto 0",
1123
+ opacity: "0",
1124
+ pointerEvents: "none"
1125
+ });
1126
+ doc.body.append(input);
1127
+ try {
1128
+ input.focus({ preventScroll: true });
1129
+ input.select();
1130
+ return doc.execCommand("copy");
1131
+ } catch {
1132
+ return false;
1133
+ } finally {
1134
+ input.remove();
1135
+ focused?.focus({ preventScroll: true });
1136
+ }
1137
+ }
1138
+ function RoleIdCopy({ id }) {
1139
+ const [status, setStatus] = (0, react.useState)();
1140
+ const manualInput = (0, react.useRef)(null);
1141
+ const trigger = (0, react.useRef)();
1142
+ const selectId = (0, react.useCallback)((input) => {
1143
+ manualInput.current = input;
1144
+ if (trigger.current?.matches(":focus")) {
1145
+ input?.focus({ preventScroll: true });
1146
+ input?.select();
842
1147
  }
843
- if (newEntry.maxTokens !== void 0 && (!Number.isInteger(newEntry.maxTokens) || newEntry.maxTokens < 1)) {
844
- setStatus({
845
- kind: "error",
846
- text: "输出上限需为 ≥1 的整数。"
847
- });
1148
+ }, []);
1149
+ async function copy(event) {
1150
+ const button$1 = event.currentTarget;
1151
+ trigger.current = button$1;
1152
+ try {
1153
+ await navigator.clipboard.writeText(id);
1154
+ setStatus("copied");
848
1155
  return;
1156
+ } catch {
1157
+ if (!button$1.isConnected) return;
849
1158
  }
850
- if (newEntry.maxDepth !== void 0 && (!Number.isInteger(newEntry.maxDepth) || newEntry.maxDepth < 1)) {
851
- setStatus({
852
- kind: "error",
853
- text: "深度上限需为 ≥1 的整数。"
854
- });
1159
+ if (copySelection(id, button$1.ownerDocument)) {
1160
+ setStatus("copied");
855
1161
  return;
856
1162
  }
857
- applyWrite({
858
- op: "save",
859
- entries: {
860
- ...serverEntries,
861
- [id]: cleanEntry(newEntry)
862
- },
863
- expectedHash: view?.hash
864
- }, id).then((ok) => {
865
- if (alive.current && ok) {
866
- setNewId("");
867
- setNewEntry({
868
- description: "",
869
- provider: "",
870
- model: "",
871
- backgroundMode: "one-shot"
872
- });
873
- setAdding(false);
874
- setOpen((current) => ({
875
- ...current,
876
- [id]: true
877
- }));
878
- }
879
- });
880
- };
881
- /** One row's field edit; `patch` merges onto the current draft. */
882
- const patch = (id, changes) => {
883
- setEntries((current) => ({
884
- ...current,
885
- [id]: {
886
- ...current[id],
887
- ...changes
888
- }
889
- }));
890
- };
891
- const revertEntry = (id) => {
892
- const saved = view?.entries[id];
893
- if (saved !== void 0) setEntries((current) => ({
894
- ...current,
895
- [id]: structuredClone(saved)
896
- }));
897
- };
898
- const setDeny = (id, text) => {
899
- const deny = parseList(text);
900
- const allow = entries[id]?.toolFilter?.allow;
901
- const keepAllow = allow !== void 0 && allow.length > 0;
902
- patch(id, { toolFilter: keepAllow || deny.length > 0 ? {
903
- ...keepAllow ? { allow } : {},
904
- ...deny.length > 0 ? { deny } : {}
905
- } : void 0 });
906
- };
907
- const ids = (0, react.useMemo)(() => Object.keys(entries), [entries]);
908
- const stats = (0, react.useMemo)(() => {
909
- let off = 0;
910
- let legacy = 0;
911
- for (const id of ids) {
912
- const entry = entries[id];
913
- if (entry.enabled === false) off += 1;
914
- if (entry.source === "legacy") legacy += 1;
915
- }
916
- return {
917
- total: ids.length,
918
- off,
919
- legacy
920
- };
921
- }, [ids, entries]);
922
- /** Disabled rows sink to the bottom (they are not what you came to look at),
923
- * then plain alphabetical. */
924
- const orderedIds = (0, react.useMemo)(() => [...ids].sort((a, b) => {
925
- const offA = entries[a].enabled === false ? 1 : 0;
926
- const offB = entries[b].enabled === false ? 1 : 0;
927
- if (offA !== offB) return offA - offB;
928
- return a.localeCompare(b);
929
- }), [ids, entries]);
930
- const needle = filter.trim().toLowerCase();
931
- const visibleIds = (0, react.useMemo)(() => {
932
- if (needle === "") return orderedIds;
933
- return orderedIds.filter((id) => {
934
- const entry = entries[id];
935
- return [
936
- id,
937
- entry.description,
938
- entry.model,
939
- entry.provider,
940
- entry.reasoningEffort,
941
- entry.persona
942
- ].filter((value) => typeof value === "string").join("\n").toLowerCase().includes(needle);
943
- });
944
- }, [
945
- orderedIds,
946
- entries,
947
- needle
948
- ]);
949
- const dirtyIds = (0, react.useMemo)(() => {
950
- const set = /* @__PURE__ */ new Set();
951
- for (const id of ids) if (!sameEntry(entries[id], view?.entries[id])) set.add(id);
952
- return set;
953
- }, [
954
- ids,
955
- entries,
956
- view
957
- ]);
958
- const openCount = visibleIds.filter((id) => open[id] === true).length;
959
- const allOpen = visibleIds.length > 0 && openCount === visibleIds.length;
960
- const toggleAll = () => {
961
- setOpen((current) => {
962
- const next = { ...current };
963
- for (const id of visibleIds) next[id] = !allOpen;
964
- return next;
965
- });
966
- };
967
- if (view === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
968
- className: "dsh-library",
969
- style: S.root,
970
- children: [
971
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: SETTINGS_CSS }),
972
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
973
- style: S.headingRow,
974
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
975
- style: S.heading,
976
- children: "子代理库"
977
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
978
- type: "button",
979
- onClick: load,
980
- style: S.button,
981
- children: "重试"
982
- })]
983
- }),
984
- status !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
985
- style: status.kind === "ok" ? BANNER.ok : BANNER.error,
986
- children: status.text
987
- }),
988
- status === null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
989
- style: S.sub,
990
- children: "正在加载…(若长时间无响应,请重试或检查插件是否加载)"
991
- })
992
- ]
1163
+ setStatus("manual");
1164
+ selectId(manualInput.current);
1165
+ }
1166
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1167
+ className: "library-field-actions",
1168
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1169
+ action: "copy-role-id",
1170
+ className: "library-link",
1171
+ "aria-label": "复制角色 ID",
1172
+ onClick: copy,
1173
+ children: "复制 ID"
1174
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1175
+ style: S.hint,
1176
+ role: "status",
1177
+ children: status === "copied" ? "已复制" : status === "manual" ? "请手动复制下方 ID" : ""
1178
+ })]
1179
+ }), status === "manual" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1180
+ ref: selectId,
1181
+ "data-field": "role-id",
1182
+ "aria-label": "角色 ID",
1183
+ style: S.input,
1184
+ value: id,
1185
+ readOnly: true,
1186
+ onFocus: (event) => event.currentTarget.select()
1187
+ })] });
1188
+ }
1189
+ function GroupFields({ form, isNew, change, view, message }) {
1190
+ const id = (0, react.useId)();
1191
+ const rulesId = `${id}-slot-rules`;
1192
+ const list = (0, react.useRef)(null);
1193
+ const addButton = (0, react.useRef)(null);
1194
+ const slots = form.members.map((member) => member.slot);
1195
+ const slotErrors = memberCodeErrors(slots);
1196
+ const usedSlots = new Set(slots.map((slot) => slot.trim()));
1197
+ const patch = (values) => change({
1198
+ ...form,
1199
+ ...values
993
1200
  });
994
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
995
- className: "dsh-library",
996
- style: S.root,
997
- children: [
998
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: SETTINGS_CSS }),
999
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1000
- style: S.pageHeader,
1001
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1002
- style: S.headingRow,
1003
- children: [
1004
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1005
- style: S.heading,
1006
- children: "子代理库"
1007
- }),
1008
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { flex: 1 } }),
1009
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1010
- type: "button",
1011
- onClick: load,
1012
- disabled: busy,
1013
- style: S.button,
1014
- children: "刷新"
1015
- })
1016
- ]
1017
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1018
- style: S.sub,
1019
- children: "集中管理角色、模型与执行方式。展开条目编辑,保存后即刻生效。"
1020
- })]
1021
- }),
1022
- (view.diagnostics?.length ?? 0) > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1023
- style: BANNER.warn,
1024
- children: view.diagnostics.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1025
- style: {
1026
- fontWeight: item.severity === "error" ? 600 : 400,
1027
- opacity: item.severity === "info" ? .78 : 1
1028
- },
1029
- children: [
1030
- item.severity === "error" ? "错误" : item.severity === "warning" ? "警告" : "提示",
1031
- item.id !== void 0 ? ` [${item.id}]` : "",
1032
- ":",
1033
- item.message
1034
- ]
1035
- }, index))
1036
- }),
1037
- view.profile !== void 0 && view.profile !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1038
- style: BANNER.info,
1039
- children: [
1040
- "当前 profile:",
1041
- view.profile,
1042
- "。这里填写的 Provider / 模型只保存到这个 profile,不会改写另一个 profile 的路由。共享名册里的模型若未在这里注册,调用会改用本会话的模型。"
1043
- ]
1044
- }),
1045
- (view.legacyCount ?? 0) > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1046
- style: BANNER.info,
1047
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
1048
- "0.2→0.3 迁移:",
1049
- view.legacyCount,
1050
- " 个旧条目已导出为名册文件并优先生效,settings.yaml 中的旧副本仍在(仅作回滚兜底)。确认名册正常后可一键清除。"
1051
- ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1052
- type: "button",
1053
- disabled: busy,
1054
- onClick: () => {
1055
- if (window.confirm("确认清除 settings.yaml 中已迁移的旧条目副本?(名册文件不受影响)")) applyWrite({
1056
- op: "clear-legacy",
1057
- expectedHash: view?.hash
1058
- }, "");
1059
- },
1060
- style: {
1061
- ...S.button,
1062
- alignSelf: "flex-start"
1063
- },
1064
- children: "清除旧条目"
1065
- })]
1066
- }),
1067
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1068
- style: S.band,
1069
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1070
- style: S.bandStats,
1071
- children: [
1072
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1073
- style: S.bandStat,
1074
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1075
- style: S.bandValue,
1076
- children: stats.total
1077
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1078
- style: S.bandLabel,
1079
- children: "个子代理"
1080
- })]
1081
- }),
1082
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1083
- style: S.bandStat,
1084
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1085
- style: {
1086
- ...S.bandValue,
1087
- color: SUCCESS
1088
- },
1089
- children: stats.total - stats.off
1090
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1091
- style: S.bandLabel,
1092
- children: "已启用"
1093
- })]
1094
- }),
1095
- stats.off > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1096
- style: S.bandStat,
1097
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1098
- style: S.bandValue,
1099
- children: stats.off
1100
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1101
- style: S.bandLabel,
1102
- children: "已停用"
1103
- })]
1104
- }),
1105
- dirtyIds.size > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1106
- style: S.bandStat,
1107
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1108
- style: {
1109
- ...S.bandValue,
1110
- color: DANGER
1111
- },
1112
- children: dirtyIds.size
1113
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1114
- style: S.bandLabel,
1115
- children: "未保存"
1116
- })]
1117
- })
1118
- ]
1119
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1120
- style: S.bandDir,
1121
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1122
- style: S.bandLabel,
1123
- children: "名册目录"
1124
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1125
- style: S.bandPath,
1126
- title: view.dir || "~/.dsh/subagents",
1127
- children: view.dir || "~/.dsh/subagents"
1128
- })]
1129
- })]
1130
- }),
1131
- stats.total > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1132
- style: S.bar,
1201
+ const patchMember = (i, values) => patch({ members: form.members.map((member, index) => index === i ? {
1202
+ ...member,
1203
+ ...values
1204
+ } : member) });
1205
+ const focus = (i) => requestAnimationFrame(() => {
1206
+ (list.current?.children[i]?.querySelector("[data-field=\"slot\"]") ?? addButton.current?.querySelector("button"))?.focus();
1207
+ });
1208
+ function move(i, to) {
1209
+ const members = [...form.members];
1210
+ const [member] = members.splice(i, 1);
1211
+ members.splice(to, 0, member);
1212
+ patch({ members });
1213
+ focus(to);
1214
+ }
1215
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1216
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1217
+ style: BANNER.warn,
1218
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1219
+ id: rulesId,
1220
+ "data-slot-rules": true,
1133
1221
  children: [
1134
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1135
- style: S.search,
1136
- children: [
1137
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1138
- width: "12",
1139
- height: "12",
1140
- viewBox: "0 0 12 12",
1141
- fill: "none",
1142
- stroke: "currentColor",
1143
- strokeWidth: "1.5",
1144
- strokeLinecap: "round",
1145
- style: {
1146
- color: "inherit",
1147
- opacity: .6,
1148
- flex: "none"
1149
- },
1150
- "aria-hidden": "true",
1151
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
1152
- cx: "5",
1153
- cy: "5",
1154
- r: "3.4"
1155
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M7.6 7.6L10.5 10.5" })]
1156
- }),
1157
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1158
- value: filter,
1159
- onChange: (event) => setFilter(event.target.value),
1160
- placeholder: "筛选 id、描述、模型…",
1161
- "aria-label": "筛选子代理",
1162
- style: S.searchInput
1163
- }),
1164
- filter !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1165
- type: "button",
1166
- onClick: () => setFilter(""),
1167
- title: "清除筛选",
1168
- style: {
1169
- ...S.ghost,
1170
- padding: 0,
1171
- fontSize: 13,
1172
- lineHeight: 1
1173
- },
1174
- children: "×"
1175
- })
1176
- ]
1177
- }),
1178
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1179
- type: "button",
1180
- onClick: toggleAll,
1181
- disabled: visibleIds.length === 0,
1182
- style: S.button,
1183
- children: allOpen ? "全部收起" : "全部展开"
1184
- }),
1185
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1186
- type: "button",
1187
- onClick: () => setAdding((current) => !current),
1188
- style: adding ? S.button : S.primary,
1189
- children: adding ? "取消新增" : "+ 新增子代理"
1190
- })
1222
+ isNew ? "编队 ID 和成员代号" : "成员代号",
1223
+ "请用小写字母、数字或短横线,最多 ",
1224
+ MAX_ID_LENGTH,
1225
+ " 个字符。中间不能有空格,开头不能用短横线。组内代号不能重复。"
1191
1226
  ]
1192
- }),
1193
- (adding || stats.total === 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1194
- className: "dsh-library-card",
1195
- style: {
1196
- ...S.row,
1197
- ...S.rowOpen
1227
+ }), message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
1228
+ role: "alert",
1229
+ children: message
1230
+ })]
1231
+ }),
1232
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1233
+ className: "library-grid",
1234
+ style: S.grid,
1235
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1236
+ name: "name",
1237
+ label: "编队名称",
1238
+ value: form.name,
1239
+ change: (name) => patch({ name }),
1240
+ placeholder: "留空时使用编队 ID"
1241
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1242
+ name: "id",
1243
+ label: "编队 ID",
1244
+ value: form.id,
1245
+ change: (id$1) => patch({ id: id$1 }),
1246
+ describedBy: isNew ? rulesId : void 0,
1247
+ readOnly: !isNew,
1248
+ placeholder: "change-review"
1249
+ })]
1250
+ }),
1251
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1252
+ name: "description",
1253
+ label: "编队描述",
1254
+ multiline: true,
1255
+ value: form.description,
1256
+ change: (description) => patch({ description })
1257
+ }),
1258
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1259
+ name: "instructions",
1260
+ label: "共享说明",
1261
+ multiline: true,
1262
+ value: form.instructions,
1263
+ change: (instructions) => patch({ instructions })
1264
+ }),
1265
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1266
+ className: "library-members-head",
1267
+ ref: addButton,
1268
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "编队成员" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1269
+ action: "add-slot",
1270
+ onClick: () => {
1271
+ patch({ members: [...form.members, emptyMember()] });
1272
+ focus(form.members.length);
1198
1273
  },
1199
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1200
- style: S.addHead,
1201
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1202
- style: S.addIntro,
1203
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1204
- style: {
1205
- ...S.id,
1206
- color: ACCENT
1207
- },
1208
- children: "新增子代理"
1209
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1210
- style: S.sub,
1211
- children: "填写 ID 与角色描述,其余配置可稍后补充。"
1212
- })]
1213
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1214
- type: "button",
1215
- disabled: busy,
1216
- onClick: addEntry,
1217
- style: S.primary,
1218
- children: "创建子代理"
1219
- })]
1220
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1221
- style: S.body,
1274
+ children: "+ 添加成员"
1275
+ })]
1276
+ }),
1277
+ !form.members.length && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1278
+ style: S.empty,
1279
+ children: "添加至少一名成员。"
1280
+ }),
1281
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
1282
+ className: "library-members",
1283
+ ref: list,
1284
+ children: form.members.map((member, i) => {
1285
+ const role = own(view.entries, member.role);
1286
+ const state = memberState(view, form, member);
1287
+ const slotId = `${id}-slot-${i}`;
1288
+ const error = (member.slot || member.role) && slotErrors[i];
1289
+ const errorId = `${slotId}-error`;
1290
+ const canUseRoleId = role && !member.slot.trim() && !entryIdIssue(member.role);
1291
+ const roleIdUsed = canUseRoleId && usedSlots.has(member.role);
1292
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
1293
+ "data-slot": i,
1294
+ "data-slot-key": member.slot,
1222
1295
  children: [
1223
1296
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1224
- className: "dsh-library-grid",
1225
- style: S.grid,
1226
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1227
- label: "ID",
1228
- hint: "小写字母 / 数字 / 连字符",
1229
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1230
- value: newId,
1231
- onChange: (event) => setNewId(event.target.value),
1232
- placeholder: "k3-reviewer",
1233
- style: S.input
1234
- })
1235
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1236
- label: "模型",
1237
- hint: "留空随默认路由",
1238
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1239
- value: newEntry.model ?? "",
1240
- onChange: (event) => setNewEntry({
1241
- ...newEntry,
1242
- model: event.target.value
1243
- }),
1244
- placeholder: "k3-256k",
1245
- style: S.input
1246
- })
1247
- })]
1248
- }),
1249
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1250
- label: "描述(模型可见)",
1251
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
1252
- value: newEntry.description ?? "",
1253
- onChange: (event) => setNewEntry({
1254
- ...newEntry,
1255
- description: event.target.value
1256
- }),
1257
- placeholder: "一句话说明这个角色做什么——模型靠它选人",
1258
- rows: 1,
1259
- style: {
1260
- ...S.prose,
1261
- overflow: "auto"
1262
- }
1263
- })
1264
- }),
1265
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1266
- className: "dsh-library-grid",
1267
- style: S.grid,
1297
+ className: "library-member-head",
1268
1298
  children: [
1269
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1270
- label: "Provider",
1271
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1272
- value: newEntry.provider ?? "",
1273
- onChange: (event) => setNewEntry({
1274
- ...newEntry,
1275
- provider: event.target.value
1276
- }),
1277
- placeholder: "kimi-coding",
1278
- style: S.input
1279
- })
1280
- }),
1281
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1282
- label: "传输层",
1283
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1284
- value: newEntry.subagentProvider ?? "",
1285
- onChange: (event) => setNewEntry({
1286
- ...newEntry,
1287
- subagentProvider: event.target.value
1288
- }),
1289
- placeholder: "spawn(默认)",
1290
- style: S.input
1291
- })
1299
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("strong", { children: ["成员 ", i + 1] }),
1300
+ state && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1301
+ style: S.dirtyChip,
1302
+ children: state
1292
1303
  }),
1293
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1294
- label: "后台模式",
1295
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
1296
- value: newEntry.backgroundMode ?? "one-shot",
1297
- onChange: (event) => setNewEntry({
1298
- ...newEntry,
1299
- backgroundMode: event.target.value
1300
- }),
1301
- style: S.input,
1302
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
1303
- value: "one-shot",
1304
- children: "one-shot"
1305
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
1306
- value: "continuable",
1307
- children: "continuable"
1308
- })]
1309
- })
1304
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
1305
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1306
+ action: "up",
1307
+ "aria-label": `上移成员 ${i + 1}`,
1308
+ title: "上移",
1309
+ disabled: i === 0,
1310
+ onClick: () => move(i, i - 1),
1311
+ children: "↑"
1310
1312
  }),
1311
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1312
- label: "深度上限",
1313
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1314
- type: "number",
1315
- min: 1,
1316
- value: newEntry.maxDepth ?? "",
1317
- onChange: (event) => setNewEntry({
1318
- ...newEntry,
1319
- maxDepth: event.target.value === "" ? void 0 : Number(event.target.value)
1320
- }),
1321
- style: S.input
1322
- })
1313
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1314
+ action: "down",
1315
+ "aria-label": `下移成员 ${i + 1}`,
1316
+ title: "下移",
1317
+ disabled: i + 1 === form.members.length,
1318
+ onClick: () => move(i, i + 1),
1319
+ children: "↓"
1323
1320
  }),
1324
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1325
- label: "输出上限",
1326
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1327
- type: "number",
1328
- min: 1,
1329
- value: newEntry.maxTokens ?? "",
1330
- onChange: (event) => setNewEntry({
1331
- ...newEntry,
1332
- maxTokens: event.target.value === "" ? void 0 : Number(event.target.value)
1333
- }),
1334
- placeholder: "tokens",
1335
- style: S.input
1336
- })
1321
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1322
+ action: "remove",
1323
+ tone: "danger",
1324
+ "aria-label": `移除成员 ${i + 1}`,
1325
+ onClick: () => {
1326
+ patch({ members: form.members.filter((_, n) => n !== i) });
1327
+ focus(Math.min(i, form.members.length - 2));
1328
+ },
1329
+ children: "移除"
1337
1330
  })
1338
1331
  ]
1339
1332
  }),
1340
1333
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1341
- className: "dsh-library-grid",
1334
+ className: "library-grid",
1342
1335
  style: S.grid,
1343
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1344
- label: "思考强度",
1345
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1346
- value: newEntry.reasoningEffort ?? "",
1347
- onChange: (event) => setNewEntry({
1348
- ...newEntry,
1349
- reasoningEffort: event.target.value === "" ? void 0 : event.target.value.trim()
1336
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1337
+ style: S.field,
1338
+ children: [
1339
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1340
+ htmlFor: slotId,
1341
+ style: S.fieldLabel,
1342
+ children: "成员代号"
1350
1343
  }),
1351
- placeholder: "max / high / medium / low(留空随父会话默认)",
1352
- style: S.input
1353
- })
1354
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1355
- label: "禁用工具",
1356
- hint: "英文逗号分隔;写入时只增删 deny,不触碰手写的 allow",
1357
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1358
- value: listToText(newEntry.toolFilter?.deny),
1359
- onChange: (event) => {
1360
- const deny = parseList(event.target.value);
1361
- const allow = newEntry.toolFilter?.allow;
1362
- const keepAllow = allow !== void 0 && allow.length > 0;
1363
- setNewEntry({
1364
- ...newEntry,
1365
- toolFilter: keepAllow || deny.length > 0 ? {
1366
- ...keepAllow ? { allow } : {},
1367
- ...deny.length > 0 ? { deny } : {}
1368
- } : void 0
1369
- });
1370
- },
1371
- placeholder: "write, edit, todo_write, …",
1372
- style: S.input
1373
- })
1344
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1345
+ id: slotId,
1346
+ style: S.input,
1347
+ "data-field": "slot",
1348
+ value: member.slot,
1349
+ placeholder: "例如 review",
1350
+ autoComplete: "off",
1351
+ autoCapitalize: "none",
1352
+ spellCheck: false,
1353
+ "aria-invalid": !!error || void 0,
1354
+ "aria-describedby": error ? `${rulesId} ${errorId}` : rulesId,
1355
+ onChange: (e) => patchMember(i, { slot: e.target.value })
1356
+ }),
1357
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1358
+ id: errorId,
1359
+ "data-slot-error": true,
1360
+ className: "library-field-error",
1361
+ "aria-live": "polite",
1362
+ children: error
1363
+ }),
1364
+ canUseRoleId && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1365
+ className: "library-field-actions",
1366
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1367
+ action: "use-role-id",
1368
+ className: "library-link",
1369
+ disabled: roleIdUsed,
1370
+ onClick: () => {
1371
+ patchMember(i, { slot: member.role });
1372
+ focus(i);
1373
+ },
1374
+ children: "用角色 ID"
1375
+ }), roleIdUsed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1376
+ style: S.hint,
1377
+ children: "此代号已使用"
1378
+ })]
1379
+ })
1380
+ ]
1381
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1382
+ style: S.field,
1383
+ children: [
1384
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1385
+ htmlFor: `${slotId}-role`,
1386
+ style: S.fieldLabel,
1387
+ children: "角色"
1388
+ }),
1389
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
1390
+ id: `${slotId}-role`,
1391
+ style: S.input,
1392
+ "data-field": "role",
1393
+ value: member.role,
1394
+ onChange: (e) => {
1395
+ const nextRole = e.target.value;
1396
+ const autoSlot = !member.slot.trim() && nextRole && own(view.entries, nextRole) ? suggestSlot(nextRole, slots.filter((_, index) => index !== i)) : "";
1397
+ patchMember(i, autoSlot ? {
1398
+ role: nextRole,
1399
+ slot: autoSlot
1400
+ } : { role: nextRole });
1401
+ },
1402
+ children: [
1403
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
1404
+ value: "",
1405
+ children: "选择名册中的角色"
1406
+ }),
1407
+ member.role && !role && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
1408
+ value: member.role,
1409
+ children: [member.role, " · 角色缺失"]
1410
+ }),
1411
+ Object.entries(view.entries).map(([id$1, row]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
1412
+ value: id$1,
1413
+ children: [id$1, availability(row) && " · " + availability(row)]
1414
+ }, id$1))
1415
+ ]
1416
+ }),
1417
+ member.role && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RoleIdCopy, { id: member.role }, member.role)
1418
+ ]
1374
1419
  })]
1375
1420
  }),
1376
1421
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1377
- label: "角色提示词(可选)",
1378
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoTextarea, {
1379
- value: newEntry.persona ?? "",
1380
- onChange: (event) => setNewEntry({
1381
- ...newEntry,
1382
- persona: event.target.value
1383
- }),
1384
- placeholder: "子代理的系统提示词",
1385
- style: S.prose
1386
- })
1422
+ name: "assignment",
1423
+ label: "默认分工",
1424
+ multiline: true,
1425
+ value: member.assignment,
1426
+ change: (assignment) => patchMember(i, { assignment }),
1427
+ placeholder: "例如:检查这次改动会不会影响已有功能"
1387
1428
  })
1388
1429
  ]
1389
- })]
1430
+ }, i);
1431
+ })
1432
+ })
1433
+ ] });
1434
+ }
1435
+
1436
+ //#endregion
1437
+ //#region src/client/LibrarySettings.tsx
1438
+ function Modal({ dialog, close }) {
1439
+ const ref = (0, react.useRef)(null);
1440
+ const id = (0, react.useId)();
1441
+ (0, react.useEffect)(() => {
1442
+ const node = ref.current;
1443
+ node?.showModal();
1444
+ return () => {
1445
+ node?.close();
1446
+ };
1447
+ }, []);
1448
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dialog", {
1449
+ className: "library-dialog",
1450
+ ref,
1451
+ "aria-labelledby": id,
1452
+ onCancel: close,
1453
+ children: [
1454
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1455
+ id,
1456
+ children: dialog.title
1390
1457
  }),
1391
- stats.total === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1392
- style: S.empty,
1458
+ dialog.content,
1459
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1460
+ style: S.actions,
1393
1461
  children: [
1394
- "库为空。在上方填一个 id 与描述即可创建第一个条目,",
1395
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("br", {}),
1396
- "或直接在名册目录放一个 ",
1397
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "<id>.yaml" }),
1398
- "。"
1462
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
1463
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1464
+ action: "cancel",
1465
+ autoFocus: true,
1466
+ onClick: close,
1467
+ children: "取消"
1468
+ }),
1469
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1470
+ action: "confirm",
1471
+ tone: dialog.destructive ? "danger" : "primary",
1472
+ onClick: () => {
1473
+ close();
1474
+ dialog.confirm();
1475
+ },
1476
+ children: dialog.label
1477
+ })
1399
1478
  ]
1479
+ })
1480
+ ]
1481
+ });
1482
+ }
1483
+ function CompareForm({ form }) {
1484
+ if (!form) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "条目已删除或尚未创建。" });
1485
+ const rows = [
1486
+ ["ID", form.id],
1487
+ ["状态", form.enabled ? "已启用" : "已停用"],
1488
+ ["描述", form.description]
1489
+ ];
1490
+ if (form.kind === "groups") {
1491
+ rows.push(["名称", form.name], ["共享说明", form.instructions]);
1492
+ form.members.forEach((m) => rows.push([m.slot || "成员", [m.role, m.assignment].filter(Boolean).join(" / ")]));
1493
+ } else {
1494
+ rows.push(["Provider", form.provider], ["模型", form.model], ["思考档位", form.reasoningEffort], ["输出上限", form.maxTokens], ["传输层", form.subagentProvider], ["深度上限", form.maxDepth], ["角色人设", form.persona]);
1495
+ if (form.inherit || form.routeNote) rows.push(["路由状态", form.inherit ? "保存后跟随主会话模型" : {
1496
+ profile: "当前 profile 路由",
1497
+ inherit: "跟随主会话模型",
1498
+ "foreign-ignored": "共享 Provider 未注册",
1499
+ "profile-missing": "当前 Provider 未注册",
1500
+ "overlay-broken": "路由无法读取"
1501
+ }[form.routeNote]]);
1502
+ if (form.filter) rows.push(["旧工具限制", form.clearToolFilter ? "保存时解除" : JSON.stringify(form.filter)]);
1503
+ }
1504
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", { children: rows.map(([name, value], i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: name }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: value || "—" })] }, i)) });
1505
+ }
1506
+ function LibrarySettings({ readView: readView$1, writeView: writeView$1, subscribeRefresh }) {
1507
+ const scope = (0, react.useId)();
1508
+ const root = (0, react.useRef)(null);
1509
+ const [view, setView] = (0, react.useState)(null);
1510
+ const [tab, setTab] = (0, react.useState)("roles");
1511
+ const [filters, setFilters] = (0, react.useState)({
1512
+ roles: "",
1513
+ groups: ""
1514
+ });
1515
+ const [expanded, setExpanded] = (0, react.useState)({});
1516
+ const [drafts, setDrafts] = (0, react.useState)({});
1517
+ const [busy, setBusy] = (0, react.useState)(false);
1518
+ const [notice, setNotice] = (0, react.useState)();
1519
+ const [dialog, setDialog] = (0, react.useState)();
1520
+ const active = (0, react.useRef)(false);
1521
+ const writing = (0, react.useRef)(false);
1522
+ const pendingRefresh = (0, react.useRef)(false);
1523
+ const readNumber = (0, react.useRef)(0);
1524
+ const load = (0, react.useCallback)(async (manual = false) => {
1525
+ if (writing.current) {
1526
+ pendingRefresh.current = true;
1527
+ return;
1528
+ }
1529
+ const request = ++readNumber.current;
1530
+ try {
1531
+ const latest = await readView$1();
1532
+ if (!active.current || request !== readNumber.current) return;
1533
+ setView(latest);
1534
+ setDrafts((rows) => {
1535
+ if (!Object.values(rows).some((row) => row.awaitingCurrent)) return rows;
1536
+ return Object.fromEntries(Object.entries(rows).map(([id, row]) => [id, row.awaitingCurrent ? {
1537
+ ...row,
1538
+ awaitingCurrent: false
1539
+ } : row]));
1540
+ });
1541
+ if (manual) setNotice({ text: "已读取当前配置。" });
1542
+ } catch (error) {
1543
+ if (active.current && request === readNumber.current) setNotice({
1544
+ text: String(error),
1545
+ error: true
1546
+ });
1547
+ }
1548
+ }, [readView$1]);
1549
+ (0, react.useEffect)(() => {
1550
+ active.current = true;
1551
+ load();
1552
+ const unsubscribe = subscribeRefresh(() => {
1553
+ load();
1554
+ });
1555
+ return () => {
1556
+ active.current = false;
1557
+ readNumber.current++;
1558
+ unsubscribe();
1559
+ };
1560
+ }, [load, subscribeRefresh]);
1561
+ const keyFor = (kind, id) => kind + "/" + id;
1562
+ const key = (id) => keyFor(tab, id);
1563
+ const label = tab === "roles" ? "角色" : "编队";
1564
+ const readonly = busy || !view?.writable;
1565
+ function put(k, draft) {
1566
+ setDrafts((current) => {
1567
+ const next = { ...current };
1568
+ if (draft) next[k] = draft;
1569
+ else delete next[k];
1570
+ return next;
1571
+ });
1572
+ }
1573
+ function reveal(id, slot, selector) {
1574
+ requestAnimationFrame(() => {
1575
+ const card = root.current?.querySelector(`[data-card="${CSS.escape(id)}"]`);
1576
+ const target = slot && card?.querySelector(`[data-slot-key="${CSS.escape(slot)}"] [data-field="slot"]`) || (selector ? card?.querySelector(selector) : null) || card?.querySelector("[data-row-id]");
1577
+ target?.focus({ preventScroll: true });
1578
+ target?.scrollIntoView({ block: "nearest" });
1579
+ });
1580
+ }
1581
+ function jump(ref) {
1582
+ setTab("groups");
1583
+ setFilters((old) => ({
1584
+ ...old,
1585
+ groups: ""
1586
+ }));
1587
+ setExpanded((old) => ({
1588
+ ...old,
1589
+ [keyFor("groups", ref.groupId)]: true
1590
+ }));
1591
+ setNotice(void 0);
1592
+ reveal(ref.groupId, ref.slot);
1593
+ }
1594
+ function changeTab(next, focus) {
1595
+ setTab(next);
1596
+ setNotice(void 0);
1597
+ if (focus) requestAnimationFrame(() => root.current?.querySelector(`[data-tab="${next}"]`)?.focus());
1598
+ }
1599
+ async function write(operation, row, success = "已保存。", options) {
1600
+ if (writing.current) return;
1601
+ writing.current = true;
1602
+ readNumber.current++;
1603
+ setBusy(true);
1604
+ setNotice(void 0);
1605
+ const k = row && key(row.id);
1606
+ try {
1607
+ const result = await writeView$1(operation);
1608
+ if (!active.current) return;
1609
+ if (result.ok) {
1610
+ setView(result.view);
1611
+ if (k && row) {
1612
+ put(k, void 0);
1613
+ if (!options?.keepExpanded) setExpanded((old) => ({
1614
+ ...old,
1615
+ [k]: false
1616
+ }));
1617
+ if (operation.op === "save-entry" || operation.op === "save-group") reveal(operation.id, void 0, options?.focusSwitch ? "[data-field=\"enabled\"]" : void 0);
1618
+ else requestAnimationFrame(() => root.current?.querySelector("[data-action=\"new\"]")?.focus());
1619
+ }
1620
+ setNotice({ text: success });
1621
+ } else {
1622
+ if (result.view) setView(result.view);
1623
+ if (k && row) {
1624
+ put(k, {
1625
+ ...row.draft,
1626
+ conflict: result.conflict,
1627
+ message: result.conflict ? void 0 : result.message ?? "保存失败。",
1628
+ references: result.references,
1629
+ awaitingCurrent: result.conflict && !result.view
1630
+ });
1631
+ setExpanded((old) => ({
1632
+ ...old,
1633
+ [k]: true
1634
+ }));
1635
+ if (result.conflict && !result.view) pendingRefresh.current = true;
1636
+ if (result.references?.length && !result.view) pendingRefresh.current = true;
1637
+ } else setNotice({
1638
+ text: result.message ?? "配置发生变化,请刷新后重试。",
1639
+ error: true
1640
+ });
1641
+ }
1642
+ } catch (error) {
1643
+ if (active.current) setNotice({
1644
+ text: String(error),
1645
+ error: true
1646
+ });
1647
+ } finally {
1648
+ writing.current = false;
1649
+ if (active.current) {
1650
+ setBusy(false);
1651
+ if (pendingRefresh.current) {
1652
+ pendingRefresh.current = false;
1653
+ load();
1654
+ }
1655
+ }
1656
+ }
1657
+ }
1658
+ if (!view) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1659
+ className: "dsh-library",
1660
+ style: S.root,
1661
+ children: [
1662
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: SETTINGS_CSS }),
1663
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1664
+ style: S.heading,
1665
+ children: "子代理库"
1400
1666
  }),
1401
- stats.total > 0 && visibleIds.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1402
- style: S.empty,
1667
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1668
+ role: "status",
1669
+ children: notice?.text ?? "正在加载…"
1670
+ }),
1671
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1672
+ action: "refresh",
1673
+ onClick: () => void load(true),
1674
+ children: "重试"
1675
+ }) })
1676
+ ]
1677
+ });
1678
+ const currentView = view;
1679
+ function add() {
1680
+ const k = key(NEW);
1681
+ put(k, freshDraft(currentView, tab, NEW));
1682
+ setExpanded((old) => ({
1683
+ ...old,
1684
+ [k]: true
1685
+ }));
1686
+ setNotice(void 0);
1687
+ reveal(NEW);
1688
+ }
1689
+ function compare(id, draft) {
1690
+ const current = serverForm(currentView, tab, id === NEW ? draft.form.id.trim() : id);
1691
+ const collision = id === NEW && !!current;
1692
+ const recreate = !current && id !== NEW;
1693
+ const competingMembers = draft.form.kind === "groups" && draft.base?.kind === "groups" && current?.kind === "groups" && !equal(draft.base.members, draft.form.members) && !equal(draft.base.members, current.members) && !equal(current.members, draft.form.members);
1694
+ setDialog({
1695
+ title: "配置版本有冲突",
1696
+ label: collision ? "返回更换 ID" : recreate ? "保留草稿为新条目" : "保留草稿,继续编辑",
1697
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1698
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1699
+ className: "library-compare",
1700
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "当前配置" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CompareForm, { form: current })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "你的草稿" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CompareForm, { form: draft.form })] })]
1701
+ }),
1702
+ competingMembers && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1703
+ style: BANNER.warn,
1704
+ children: "双方都修改了编队成员。保留草稿将采用你这份完整的成员名单和分工。"
1705
+ }),
1706
+ collision ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "这个 ID 已有配置。请为新条目更换 ID 后再创建。" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: ["保留已编辑的字段,其他字段采用当前配置。", recreate ? "再次保存将重新创建这个条目。" : "再次保存才会写入配置。"] })
1707
+ ] }),
1708
+ confirm: () => {
1709
+ if (!collision) {
1710
+ put(key(id), rebase(draft, current));
1711
+ return;
1712
+ }
1713
+ requestAnimationFrame(() => root.current?.querySelector("[data-card=\"@new\"] [data-field=\"id\"]")?.focus());
1714
+ }
1715
+ });
1716
+ }
1717
+ function remove(id, draft) {
1718
+ const refs = tab === "roles" ? own(currentView.roleUsages, id) : void 0;
1719
+ if (refs?.length) {
1720
+ put(key(id), {
1721
+ ...draft,
1722
+ references: refs
1723
+ });
1724
+ return;
1725
+ }
1726
+ setDialog({
1727
+ title: "删除" + label,
1728
+ label: "确认删除",
1729
+ destructive: true,
1730
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [
1731
+ "确定删除 ",
1732
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: draft.form.kind === "groups" && draft.form.name || id }),
1733
+ "?",
1734
+ tab === "groups" && "名册中的角色仍可单独使用。"
1735
+ ] }),
1736
+ confirm: () => void write({
1737
+ op: tab === "roles" ? "delete" : "delete-group",
1738
+ id,
1739
+ expectedHash: currentView.hash
1740
+ }, {
1741
+ id,
1742
+ draft
1743
+ }, "已删除" + label + " " + id + "。")
1744
+ });
1745
+ }
1746
+ const needle = filters[tab].trim().toLowerCase();
1747
+ const roleCount = Object.keys(view.entries).length;
1748
+ const groupCount = Object.keys(view.groups).length;
1749
+ const hasDirtyTab = (kind) => Object.entries(drafts).some(([k, d]) => k.startsWith(kind + "/") && (d.conflict || !equal(d.base, d.form)));
1750
+ const serverIds = sortByEnabled(Object.keys(tab === "roles" ? view.entries : view.groups), (id) => (tab === "roles" ? view.entries[id]?.enabled : view.groups[id]?.enabled) !== false);
1751
+ const ids = [...new Set([...Object.keys(drafts).filter((k) => k.startsWith(tab + "/") && !serverIds.includes(k.slice(tab.length + 1))).map((k) => k.slice(tab.length + 1)), ...serverIds])].filter((id) => {
1752
+ if (!needle || id === NEW || drafts[key(id)] && expanded[key(id)]) return true;
1753
+ const form = drafts[key(id)]?.form ?? serverForm(view, tab, id);
1754
+ return form && [
1755
+ id,
1756
+ form.description,
1757
+ ...form.kind === "roles" ? [
1758
+ form.model,
1759
+ form.provider,
1760
+ form.persona,
1761
+ form.reasoningEffort
1762
+ ] : [form.name]
1763
+ ].some((s) => s.toLowerCase().includes(needle));
1764
+ });
1765
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1766
+ ref: root,
1767
+ className: "dsh-library",
1768
+ style: S.root,
1769
+ children: [
1770
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: SETTINGS_CSS }),
1771
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
1772
+ style: S.headingRow,
1403
1773
  children: [
1404
- "没有匹配「",
1405
- filter,
1406
- "」的条目。"
1774
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1775
+ style: S.heading,
1776
+ children: "子代理库"
1777
+ }),
1778
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
1779
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1780
+ action: "refresh",
1781
+ disabled: busy,
1782
+ onClick: () => void load(true),
1783
+ children: "刷新"
1784
+ })
1407
1785
  ]
1408
1786
  }),
1409
- visibleIds.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1410
- style: S.listCaption,
1411
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: needle === "" ? "角色名册" : `匹配 ${visibleIds.length} / ${stats.total} 个子代理` }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "点击名称展开配置" })]
1412
- }),
1413
1787
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1414
- style: S.list,
1415
- children: visibleIds.map((id) => {
1416
- const entry = entries[id];
1417
- const isOpen = open[id] === true;
1418
- const dirty = dirtyIds.has(id);
1419
- const off = entry.enabled === false;
1420
- const model = entry.model || "";
1421
- const provider = entry.provider || "";
1422
- const route = provider !== "" && model !== "" ? `${provider}/${model}` : model !== "" ? model : provider !== "" ? provider : "默认路由";
1423
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1424
- className: "dsh-library-card",
1425
- "data-entry-id": id,
1426
- style: {
1427
- ...S.row,
1428
- ...isOpen ? S.rowOpen : null,
1429
- ...off ? S.rowOff : null
1430
- },
1431
- children: [
1432
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1433
- style: S.head,
1434
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1435
- type: "button",
1436
- className: "dsh-library-disclosure",
1437
- style: S.disclosure,
1438
- "aria-expanded": isOpen,
1439
- "aria-controls": `${sectionId}-${id}`,
1440
- "aria-label": `${isOpen ? "收起" : "展开"} ${id} 的配置`,
1441
- "data-row-id": id,
1442
- onClick: () => setOpen((current) => ({
1443
- ...current,
1444
- [id]: !isOpen
1445
- })),
1446
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Chevron, { open: isOpen }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1447
- style: S.titleRow,
1448
- children: [
1449
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1450
- style: S.id,
1451
- children: id
1452
- }),
1453
- entry.source === "legacy" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1454
- style: S.chip,
1455
- children: "旧版条目"
1456
- }),
1457
- dirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1458
- style: S.dirtyChip,
1459
- children: "未保存"
1460
- })
1461
- ]
1462
- })]
1463
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1464
- style: S.headToggle,
1465
- title: "切换后需保存此条目才会生效",
1466
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1467
- className: "dsh-library-switch",
1468
- type: "checkbox",
1469
- role: "switch",
1470
- "aria-label": `启用 ${id}`,
1471
- checked: !off,
1472
- onChange: (event) => patch(id, { enabled: event.target.checked ? void 0 : false })
1473
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: off ? "已停用" : "已启用" })]
1474
- })]
1788
+ className: "library-tabs",
1789
+ role: "tablist",
1790
+ "aria-label": "设置分类",
1791
+ children: ["roles", "groups"].map((kind) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1792
+ type: "button",
1793
+ role: "tab",
1794
+ "data-tab": kind,
1795
+ id: scope + kind,
1796
+ "aria-controls": scope + "-panel",
1797
+ "aria-selected": tab === kind,
1798
+ tabIndex: tab === kind ? 0 : -1,
1799
+ onClick: () => changeTab(kind, false),
1800
+ onKeyDown: (e) => {
1801
+ if ([
1802
+ "ArrowLeft",
1803
+ "ArrowRight",
1804
+ "Home",
1805
+ "End"
1806
+ ].includes(e.key)) {
1807
+ e.preventDefault();
1808
+ changeTab(e.key === "Home" ? "roles" : e.key === "End" ? "groups" : tab === "groups" ? "roles" : "groups", true);
1809
+ }
1810
+ },
1811
+ children: [
1812
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: kind === "roles" ? "角色名册" : "编队" }),
1813
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1814
+ className: "library-tab-count",
1815
+ children: kind === "roles" ? roleCount : groupCount
1816
+ }),
1817
+ hasDirtyTab(kind) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1818
+ className: "library-tab-dot",
1819
+ "aria-label": "有未保存修改",
1820
+ title: "有未保存修改"
1821
+ })
1822
+ ]
1823
+ }, kind))
1824
+ }),
1825
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
1826
+ role: "tabpanel",
1827
+ id: scope + "-panel",
1828
+ "aria-labelledby": scope + tab,
1829
+ className: "library-panel",
1830
+ children: [
1831
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1832
+ className: "library-banner",
1833
+ style: BANNER.info,
1834
+ children: tab === "roles" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: view.profile ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("strong", { children: ["当前 profile:", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: view.profile })] }), "(默认模型按 profile 保存)。同一角色可多次派遣并按需换模型(授权范围见「内置插件 → 子智能体」);角色配置由编队共享。"] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: "角色配置由引用它的编队共享。同一角色可多次派遣并按需换模型(授权范围见「内置插件 → 子智能体」)。" }) }) : "编队支持逐个派遣,开启或关闭智能体团队均可使用。"
1835
+ }),
1836
+ view.diagnostics?.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
1837
+ style: BANNER.warn,
1838
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: [
1839
+ "配置诊断(",
1840
+ view.diagnostics.length,
1841
+ ")"
1842
+ ] }), view.diagnostics.map((item, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
1843
+ item.file ?? item.id,
1844
+ " ",
1845
+ item.message
1846
+ ] }, i))]
1847
+ }) : null,
1848
+ tab === "roles" && (view.legacyCount ?? 0) > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1849
+ style: BANNER.info,
1850
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
1851
+ "名册已接管 ",
1852
+ view.legacyCount,
1853
+ " 个旧条目。确认迁移后可清除旧配置中的角色副本。"
1854
+ ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
1855
+ action: "clear-legacy",
1856
+ disabled: readonly,
1857
+ onClick: () => setDialog({
1858
+ title: "清除旧副本",
1859
+ label: "确认清除",
1860
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "清除旧配置中已迁移的角色副本?名册文件会保留。" }),
1861
+ destructive: true,
1862
+ confirm: () => void write({
1863
+ op: "clear-legacy",
1864
+ expectedHash: view.hash
1865
+ }, void 0, "已清除旧副本。")
1475
1866
  }),
1476
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1477
- style: S.overview,
1867
+ children: "清除旧副本"
1868
+ }) })]
1869
+ }),
1870
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1871
+ style: S.bar,
1872
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1873
+ className: "library-search",
1874
+ style: S.search,
1875
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1876
+ "aria-hidden": "true",
1877
+ width: "15",
1878
+ height: "15",
1879
+ viewBox: "0 0 24 24",
1880
+ fill: "none",
1881
+ stroke: "currentColor",
1882
+ strokeWidth: "2",
1883
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
1884
+ cx: "10.5",
1885
+ cy: "10.5",
1886
+ r: "5.5"
1887
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m15 15 5 5" })]
1888
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1889
+ type: "search",
1890
+ "aria-label": "筛选" + label,
1891
+ value: filters[tab],
1892
+ placeholder: tab === "roles" ? "筛选角色 ID、描述、模型" : "筛选编队名称、ID、描述",
1893
+ onChange: (e) => setFilters({
1894
+ ...filters,
1895
+ [tab]: e.target.value
1896
+ }),
1897
+ style: S.searchInput
1898
+ })]
1899
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Action, {
1900
+ action: "new",
1901
+ tone: "primary",
1902
+ disabled: readonly || !!drafts[key(NEW)],
1903
+ onClick: add,
1904
+ children: [
1905
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1906
+ "aria-hidden": "true",
1907
+ children: "+ "
1908
+ }),
1909
+ "新建",
1910
+ label
1911
+ ]
1912
+ })]
1913
+ }),
1914
+ notice && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1915
+ role: "status",
1916
+ style: notice.error ? BANNER.error : BANNER.ok,
1917
+ children: notice.text
1918
+ }),
1919
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1920
+ style: S.list,
1921
+ children: [!ids.length && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1922
+ style: S.empty,
1923
+ children: needle ? "没有匹配的条目。" : "暂无" + label + "。"
1924
+ }), ids.map((id) => {
1925
+ const k = key(id);
1926
+ const draft = drafts[k] ?? freshDraft(view, tab, id);
1927
+ const form = draft.form;
1928
+ const open = Boolean(expanded[k]);
1929
+ const isNew = id === NEW;
1930
+ const current = serverForm(view, tab, isNew ? form.id.trim() : id);
1931
+ const collision = isNew && !!current;
1932
+ const stale = Boolean(draft.conflict || !equal(draft.base, current));
1933
+ const dirty = !equal(draft.base, form);
1934
+ const refs = own(view.roleUsages, id) ?? [];
1935
+ const blocked = form.kind === "groups" ? form.members.filter((m) => memberState(view, form, m)).length : 0;
1936
+ const savedRole = form.kind === "roles" ? own(view.entries, id) : void 0;
1937
+ const roleState = savedRole && savedRole.enabled !== false ? availability(savedRole) : "";
1938
+ const contentId = scope + tab + id;
1939
+ function change(next) {
1940
+ put(k, equal(draft.base, next) && !stale ? void 0 : {
1941
+ ...draft,
1942
+ form: next,
1943
+ message: void 0,
1944
+ references: void 0,
1945
+ conflict: isNew && form.id !== next.id && !draft.awaitingCurrent ? false : draft.conflict
1946
+ });
1947
+ setNotice(void 0);
1948
+ }
1949
+ function toggleEnabled(checked) {
1950
+ const nextForm = {
1951
+ ...form,
1952
+ enabled: checked
1953
+ };
1954
+ if (!isNew && !dirty && !stale && current) {
1955
+ const nextDraft = {
1956
+ ...draft,
1957
+ form: nextForm,
1958
+ message: void 0,
1959
+ references: void 0
1960
+ };
1961
+ const error = validate(nextForm, currentView, false, draft.base);
1962
+ if (error) {
1963
+ put(k, {
1964
+ ...nextDraft,
1965
+ message: error
1966
+ });
1967
+ setExpanded((old) => ({
1968
+ ...old,
1969
+ [k]: true
1970
+ }));
1971
+ return;
1972
+ }
1973
+ const impact = form.kind === "roles" && !checked && refs.length ? ` ${refs.length} 名编队成员暂时无法派遣。` : "";
1974
+ write(saveWrite(nextDraft, currentView), {
1975
+ id,
1976
+ draft: nextDraft
1977
+ }, `已${checked ? "启用" : "停用"}${label} ${id}。${impact}`, {
1978
+ keepExpanded: open,
1979
+ focusSwitch: true
1980
+ });
1981
+ return;
1982
+ }
1983
+ change(nextForm);
1984
+ setExpanded((old) => ({
1985
+ ...old,
1986
+ [k]: true
1987
+ }));
1988
+ }
1989
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
1990
+ className: "dsh-library-card",
1991
+ "data-card": id,
1992
+ "data-open": open ? "" : void 0,
1993
+ "data-disabled": !form.enabled ? "" : void 0,
1478
1994
  children: [
1479
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1480
- style: S.excerpt,
1481
- title: entry.description ?? "",
1482
- children: entry.description || "暂无角色描述"
1483
- }),
1484
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1485
- style: S.route,
1486
- title: `路由:${route}`,
1487
- children: [
1488
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1489
- style: S.metaLabel,
1490
- children: "模型"
1491
- }),
1492
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1493
- style: S.model,
1494
- children: model || "跟随默认模型"
1495
- }),
1496
- provider !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1497
- style: S.provider,
1498
- children: provider
1499
- })
1500
- ]
1501
- }),
1502
1995
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1503
- style: S.glyphs,
1504
- children: [
1505
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1506
- style: entry.backgroundMode === "continuable" ? S.modeChip : S.glyph,
1507
- children: entry.backgroundMode === "continuable" ? "可续聊" : "单次任务"
1508
- }),
1509
- entry.reasoningEffort && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1510
- style: S.glyph,
1511
- children: ["思考 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1512
- style: S.metaValue,
1513
- children: entry.reasoningEffort
1514
- })]
1515
- }),
1516
- entry.maxDepth !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1517
- style: S.glyph,
1518
- children: ["深度 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1519
- style: S.metaValue,
1520
- children: entry.maxDepth
1521
- })]
1522
- }),
1523
- entry.maxTokens !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1524
- style: S.glyph,
1996
+ className: "library-card-head",
1997
+ style: S.head,
1998
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1999
+ type: "button",
2000
+ style: S.disclosure,
2001
+ className: "dsh-library-disclosure",
2002
+ "data-row-id": id,
2003
+ "data-action": "toggle",
2004
+ "aria-expanded": open,
2005
+ "aria-controls": contentId,
2006
+ onClick: () => setExpanded((old) => ({
2007
+ ...old,
2008
+ [k]: !open
2009
+ })),
2010
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2011
+ "aria-hidden": "true",
2012
+ className: "library-card-chevron",
2013
+ style: {
2014
+ ...S.chevron,
2015
+ transform: open ? "rotate(90deg)" : void 0
2016
+ },
2017
+ children: "❯"
2018
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2019
+ className: "library-card-title",
2020
+ style: S.titleRow,
1525
2021
  children: [
1526
- "输出 ",
1527
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1528
- style: S.metaValue,
1529
- children: entry.maxTokens.toLocaleString("en-US")
2022
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
2023
+ style: form.kind === "roles" ? S.id : void 0,
2024
+ children: isNew ? "新建" + label : form.kind === "groups" ? form.name || id : id
1530
2025
  }),
1531
- " tokens"
1532
- ]
1533
- }),
1534
- entry.persona && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1535
- style: S.glyph,
1536
- children: "角色提示词"
1537
- }),
1538
- (entry.toolFilter?.deny?.length ?? 0) > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1539
- style: S.glyph,
1540
- children: [
1541
- "禁用 ",
1542
- entry.toolFilter.deny.length,
1543
- " 项工具"
1544
- ]
1545
- }),
1546
- (entry.toolFilter?.allow?.length ?? 0) > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1547
- style: S.glyph,
1548
- children: [
1549
- "允许 ",
1550
- entry.toolFilter.allow.length,
1551
- " 项工具"
2026
+ dirty && !isNew && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2027
+ style: S.dirtyChip,
2028
+ children: "未保存"
2029
+ }),
2030
+ stale && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2031
+ style: S.dirtyChip,
2032
+ children: "版本冲突"
2033
+ })
1552
2034
  ]
1553
- })
1554
- ]
1555
- })
1556
- ]
1557
- }),
1558
- dirty && !isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1559
- style: S.draftActions,
1560
- children: [
1561
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1562
- style: S.hint,
1563
- children: "保存后生效"
1564
- }),
1565
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
1566
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1567
- type: "button",
1568
- disabled: busy,
1569
- onClick: (event) => {
1570
- focusDisclosure(event);
1571
- revertEntry(id);
1572
- },
1573
- style: S.ghost,
1574
- children: "还原"
1575
- }),
1576
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1577
- type: "button",
1578
- disabled: busy,
1579
- onClick: (event) => {
1580
- focusDisclosure(event);
1581
- updateEntry(id, entry);
1582
- },
1583
- style: S.primary,
1584
- children: "保存修改"
1585
- })
1586
- ]
1587
- }),
1588
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1589
- id: `${sectionId}-${id}`,
1590
- hidden: !isOpen,
1591
- children: isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1592
- style: S.body,
1593
- children: [
1594
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1595
- style: S.group,
1596
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1597
- style: S.groupTitle,
1598
- children: "概述"
1599
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1600
- label: "描述(模型可见)",
1601
- hint: "模型用 list_subagents 读到的就是这句话,写清角色与适用场景",
1602
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
1603
- value: entry.description ?? "",
1604
- onChange: (event) => patch(id, { description: event.target.value }),
1605
- placeholder: "角色描述",
1606
- rows: 1,
1607
- style: {
1608
- ...S.prose,
1609
- overflow: "auto"
1610
- }
1611
- })
1612
2035
  })]
1613
- }),
1614
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1615
- style: S.group,
1616
- children: [
1617
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1618
- style: S.groupTitle,
1619
- children: "路由与执行"
2036
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
2037
+ style: S.headToggle,
2038
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2039
+ className: "dsh-library-switch",
2040
+ type: "checkbox",
2041
+ role: "switch",
2042
+ "data-field": "enabled",
2043
+ "aria-label": label + "启用状态",
2044
+ checked: form.enabled,
2045
+ disabled: readonly,
2046
+ onChange: (e) => toggleEnabled(e.target.checked)
2047
+ }), form.enabled ? "已启用" : "已停用"]
2048
+ })]
2049
+ }),
2050
+ !open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2051
+ className: "library-card-overview",
2052
+ style: S.overview,
2053
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2054
+ style: S.excerpt,
2055
+ children: form.description || "填写" + label + "的用途。"
2056
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2057
+ style: S.route,
2058
+ children: form.kind === "groups" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2059
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2060
+ style: S.metaLabel,
2061
+ children: [form.members.length, " 名成员"]
1620
2062
  }),
1621
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1622
- className: "dsh-library-grid",
1623
- style: S.grid,
1624
- children: [
1625
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1626
- label: "Provider",
1627
- hint: entry.routeNote === "foreign-ignored" ? "共享名册里的路由当前 profile 没有,调用会改用本会话模型。留空保存不会改掉共享路由。" : entry.routeNote === "profile" ? `只保存在 profile ${view.profile ?? ""}` : entry.routeNote === "inherit" ? "本 profile 固定使用会话模型,不跟随共享名册路由" : entry.routeNote === "profile-missing" ? "这个 profile 保存的 Provider 未注册" : void 0,
1628
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1629
- value: entry.provider ?? "",
1630
- onChange: (event) => patch(id, { provider: event.target.value }),
1631
- placeholder: "deepseek-official / kimi-coding",
1632
- style: S.input
1633
- })
1634
- }),
1635
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1636
- label: "模型",
1637
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1638
- value: entry.model ?? "",
1639
- onChange: (event) => patch(id, { model: event.target.value }),
1640
- placeholder: "k3-256k",
1641
- style: S.input
1642
- })
1643
- }),
1644
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1645
- label: "传输层",
1646
- hint: "留空用 spawn",
1647
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1648
- value: entry.subagentProvider ?? "",
1649
- onChange: (event) => patch(id, { subagentProvider: event.target.value }),
1650
- placeholder: "spawn(默认)",
1651
- style: S.input
1652
- })
1653
- }),
1654
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1655
- label: "后台模式",
1656
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
1657
- value: entry.backgroundMode ?? "one-shot",
1658
- onChange: (event) => patch(id, { backgroundMode: event.target.value }),
1659
- style: S.input,
1660
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
1661
- value: "one-shot",
1662
- children: "one-shot"
1663
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
1664
- value: "continuable",
1665
- children: "continuable"
1666
- })]
1667
- })
1668
- })
1669
- ]
2063
+ form.members.slice(0, 6).map((m, idx) => {
2064
+ const mState = memberState(view, form, m);
2065
+ const chipText = !m.slot || m.slot === m.role ? m.role || m.slot || `成员 ${idx + 1}` : `${m.slot} → ${m.role}`;
2066
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2067
+ className: "library-member-chip",
2068
+ style: mState && form.enabled ? S.dirtyChip : S.glyph,
2069
+ children: chipText
2070
+ }, idx);
1670
2071
  }),
1671
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1672
- className: "dsh-library-grid",
1673
- style: S.grid,
1674
- children: [
1675
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1676
- label: "思考强度",
1677
- hint: "留空随父会话默认",
1678
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1679
- value: entry.reasoningEffort ?? "",
1680
- onChange: (event) => patch(id, { reasoningEffort: event.target.value === "" ? void 0 : event.target.value.trim() }),
1681
- placeholder: "max / high / medium / low",
1682
- style: S.input
1683
- })
1684
- }),
1685
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1686
- label: "深度上限",
1687
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1688
- type: "number",
1689
- min: 1,
1690
- value: entry.maxDepth ?? "",
1691
- onChange: (event) => patch(id, { maxDepth: event.target.value === "" ? void 0 : Number(event.target.value) }),
1692
- style: S.input
1693
- })
1694
- }),
1695
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1696
- label: "输出上限",
1697
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1698
- type: "number",
1699
- min: 1,
1700
- value: entry.maxTokens ?? "",
1701
- onChange: (event) => patch(id, { maxTokens: event.target.value === "" ? void 0 : Number(event.target.value) }),
1702
- placeholder: "tokens",
1703
- style: S.input
1704
- })
1705
- })
1706
- ]
2072
+ form.members.length > 6 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2073
+ style: S.glyph,
2074
+ children: ["+", form.members.length - 6]
2075
+ }),
2076
+ blocked > 0 && form.enabled && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2077
+ style: S.dirtyChip,
2078
+ children: [blocked, " 名暂时无法派遣"]
1707
2079
  })
1708
- ]
1709
- }),
1710
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1711
- style: S.group,
1712
- children: [
2080
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1713
2081
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1714
- style: S.groupTitle,
1715
- children: "工具与提示词"
2082
+ style: S.metaLabel,
2083
+ children: "模型"
1716
2084
  }),
1717
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1718
- label: "禁用工具",
1719
- hint: "英文逗号分隔;留空表示不限制。手写的 allow 列表会原样保留",
1720
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1721
- value: listToText(entry.toolFilter?.deny),
1722
- onChange: (event) => setDeny(id, event.target.value),
1723
- placeholder: "write, edit, todo_write, …",
1724
- style: S.input
1725
- })
2085
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
2086
+ style: S.model,
2087
+ children: form.model || "跟随主会话"
1726
2088
  }),
1727
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1728
- label: "角色提示词(可选)",
1729
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoTextarea, {
1730
- value: entry.persona ?? "",
1731
- onChange: (event) => patch(id, { persona: event.target.value }),
1732
- placeholder: "子代理的系统提示词",
1733
- style: S.prose
1734
- })
2089
+ form.provider && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
2090
+ style: S.provider,
2091
+ children: form.provider
2092
+ }),
2093
+ form.reasoningEffort && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2094
+ style: S.glyph,
2095
+ children: ["思考 ", form.reasoningEffort]
2096
+ }),
2097
+ refs.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2098
+ style: S.glyph,
2099
+ children: [refs.length, " 名编队成员在用"]
2100
+ }),
2101
+ roleState && !isNew && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2102
+ style: S.dirtyChip,
2103
+ children: roleState
1735
2104
  })
1736
- ]
1737
- }),
1738
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1739
- style: S.actions,
2105
+ ] })
2106
+ })]
2107
+ }),
2108
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2109
+ id: contentId,
2110
+ hidden: !open,
2111
+ children: open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
2112
+ disabled: readonly,
2113
+ className: "library-editor",
2114
+ style: S.body,
1740
2115
  children: [
1741
- dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1742
- style: {
1743
- ...S.hint,
1744
- color: DANGER
1745
- },
1746
- children: "此条目有未保存修改"
1747
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1748
- style: S.hint,
1749
- children: entry.source === "legacy" ? "来自 settings.yaml 的迁移副本" : "与名册文件一致"
2116
+ stale && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2117
+ role: "alert",
2118
+ style: BANNER.warn,
2119
+ children: [collision ? "这个 ID 已有配置,请更换 ID 再创建。" : "配置已在别处更新,你的草稿已保留。", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: draft.awaitingCurrent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
2120
+ action: "refresh",
2121
+ onClick: () => void load(true),
2122
+ children: "重新读取当前版本"
2123
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
2124
+ action: "compare",
2125
+ className: "library-link",
2126
+ onClick: () => compare(id, draft),
2127
+ children: "查看当前版本"
2128
+ }) })]
1750
2129
  }),
1751
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
1752
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1753
- type: "button",
1754
- disabled: busy || !dirty,
1755
- onClick: () => revertEntry(id),
1756
- style: {
1757
- ...S.ghost,
1758
- opacity: busy || !dirty ? .45 : 1
1759
- },
1760
- title: "丢弃本行的未保存修改,恢复为服务器当前值",
1761
- children: "还原"
2130
+ draft.references?.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2131
+ role: "alert",
2132
+ style: BANNER.warn,
2133
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(References, {
2134
+ refs: draft.references,
2135
+ view,
2136
+ jump,
2137
+ title: "无法删除,以下编队成员还在使用这个角色"
2138
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "请给这些成员更换角色,或将他们移出编队后再删除。" })]
2139
+ }) : form.kind === "roles" && draft.message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2140
+ role: "alert",
2141
+ style: BANNER.warn,
2142
+ children: draft.message
1762
2143
  }),
1763
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1764
- type: "button",
1765
- disabled: busy,
1766
- onClick: () => removeEntry(id),
1767
- style: {
1768
- ...S.danger,
1769
- opacity: busy ? .55 : 1
1770
- },
1771
- children: "删除"
2144
+ form.kind === "roles" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RoleFields, {
2145
+ form,
2146
+ isNew,
2147
+ change,
2148
+ view,
2149
+ refs,
2150
+ jump,
2151
+ message: draft.message
2152
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GroupFields, {
2153
+ form,
2154
+ isNew,
2155
+ change,
2156
+ view,
2157
+ message: draft.message
1772
2158
  }),
1773
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1774
- type: "button",
1775
- disabled: busy || !dirty,
1776
- onClick: () => updateEntry(id, entry),
1777
- style: {
1778
- ...S.primary,
1779
- opacity: busy || !dirty ? .5 : 1
1780
- },
1781
- children: "保存"
2159
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2160
+ style: S.actions,
2161
+ children: [
2162
+ !isNew && current && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Action, {
2163
+ action: "delete",
2164
+ tone: "danger",
2165
+ disabled: stale,
2166
+ onClick: () => remove(id, draft),
2167
+ children: ["删除", label]
2168
+ }),
2169
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: S.spacer }),
2170
+ (dirty || stale) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
2171
+ action: "revert",
2172
+ tone: "ghost",
2173
+ onClick: () => {
2174
+ put(k, void 0);
2175
+ if (isNew) requestAnimationFrame(() => root.current?.querySelector("[data-action=\"new\"]")?.focus());
2176
+ else reveal(id);
2177
+ },
2178
+ children: isNew ? "取消" : "还原草稿"
2179
+ }),
2180
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Action, {
2181
+ action: "save",
2182
+ tone: "primary",
2183
+ disabled: !dirty || stale,
2184
+ onClick: () => {
2185
+ const error = validate(form, view, isNew, draft.base);
2186
+ if (error) {
2187
+ put(k, {
2188
+ ...draft,
2189
+ message: error
2190
+ });
2191
+ return;
2192
+ }
2193
+ const impact = form.kind === "roles" && !form.enabled && draft.base?.enabled && refs.length ? ` ${refs.length} 名编队成员暂时无法派遣。` : "";
2194
+ write(saveWrite(draft, view), {
2195
+ id,
2196
+ draft
2197
+ }, `已保存${label} ${form.id.trim()}。${impact}`);
2198
+ },
2199
+ children: isNew ? "创建" + label : "保存修改"
2200
+ })
2201
+ ]
1782
2202
  })
1783
2203
  ]
1784
2204
  })
1785
- ]
1786
- })
1787
- })
1788
- ]
1789
- }, id);
1790
- })
1791
- }),
1792
- status !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1793
- role: "status",
1794
- "aria-live": "polite",
1795
- style: status.kind === "ok" ? BANNER.ok : BANNER.error,
1796
- children: status.text
2205
+ })
2206
+ ]
2207
+ }, k);
2208
+ })]
2209
+ }),
2210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
2211
+ className: "library-footer",
2212
+ style: S.footer,
2213
+ onToggle: (e) => {
2214
+ if (e.currentTarget.open) e.currentTarget.scrollIntoView({ block: "nearest" });
2215
+ },
2216
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: "存储与备份说明" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
2217
+ style: S.footerNote,
2218
+ children: [
2219
+ "角色保存在 ",
2220
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: view.dir || "~/.dsh/subagents/" }),
2221
+ ",编队位于该目录下的 ",
2222
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "_groups/" }),
2223
+ "。 备份时一并保留角色文件、编队和 ",
2224
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "_profiles/" }),
2225
+ " 中的模型路由。"
2226
+ ]
2227
+ })]
2228
+ })
2229
+ ]
1797
2230
  }),
1798
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
1799
- style: S.footer,
1800
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", {
1801
- style: S.footerSummary,
1802
- children: "存储与备份说明"
1803
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1804
- style: S.hint,
1805
- children: [
1806
- "配置存储于名册目录 ",
1807
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
1808
- style: { fontFamily: MONO },
1809
- children: view.dir || "~/.dsh/subagents"
1810
- }),
1811
- "(每具名子代理一个 ",
1812
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "<id>.yaml" }),
1813
- ",可手编、热生效;",
1814
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "_" }),
1815
- " 前缀的文件/目录为非名册内容,如 ",
1816
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "_backups/" }),
1817
- " 备份区)。 让 agent 修改条目前,建议先把原文件复制到 ",
1818
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: "_backups/" }),
1819
- " 里。 settings.yaml 中的旧 entries 仅作迁移兜底读取,文件优先生效。"
1820
- ]
1821
- })]
2231
+ dialog && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Modal, {
2232
+ dialog,
2233
+ close: () => setDialog(void 0)
1822
2234
  })
1823
2235
  ]
1824
2236
  });
@@ -1873,47 +2285,45 @@ function registerSettingsNavIcon(ctx) {
1873
2285
  //#region src/client/locales.ts
1874
2286
  const zh = {
1875
2287
  "settings.title": "子代理库",
1876
- "settings.hint": "管理具名角色子代理。保存后热生效:模型可在任意会话通过 list_subagents / delegate 使用。",
2288
+ "settings.hint": "管理名册中的角色和编队,为编队成员指定代号与默认分工。",
1877
2289
  "settings.empty": "库为空。添加第一个条目开始使用。",
1878
2290
  "settings.missing": "未找到 subagent-library 配置段(插件未加载?)。",
1879
2291
  "settings.add": "添加",
1880
- "settings.addNew": "新增子代理",
2292
+ "settings.addNew": "新建角色",
1881
2293
  "settings.delete": "删除",
1882
2294
  "settings.save": "保存",
1883
2295
  "settings.saved": "已保存",
1884
- "settings.conflict": "配置已被其他窗口修改,已重新加载,请重试。",
2296
+ "settings.conflict": "配置已在别处更新,你的草稿已保留。查看当前配置后可继续编辑。",
1885
2297
  "settings.error": "保存失败:",
1886
2298
  "settings.id": "ID",
1887
2299
  "settings.description": "描述",
1888
2300
  "settings.model": "模型",
1889
2301
  "settings.persona": "角色提示词",
1890
- "settings.toolFilter": "禁用工具",
2302
+ "settings.toolFilter": "旧工具限制",
1891
2303
  "settings.maxDepth": "深度上限",
1892
- "settings.background": "后台模式",
1893
2304
  "settings.provider": "Provider",
1894
- "settings.sourceHint": "配置存储于 $DSH_HOME/settings.yaml 的 subagent-library.entries。"
2305
+ "settings.sourceHint": "角色保存在名册目录,编队位于 _groups/,各 profile 的模型路由位于 _profiles/。"
1895
2306
  };
1896
2307
  const en = {
1897
2308
  "settings.title": "Subagent Library",
1898
- "settings.hint": "Manage named role subagents. Changes apply live: models use them via list_subagents / delegate in any session.",
2309
+ "settings.hint": "Manage roles and groups. Give each group member a code and a default assignment.",
1899
2310
  "settings.empty": "Library is empty. Add the first entry to get started.",
1900
2311
  "settings.missing": "No subagent-library section found (plugin not loaded?).",
1901
2312
  "settings.add": "Add",
1902
- "settings.addNew": "New subagent",
2313
+ "settings.addNew": "New role",
1903
2314
  "settings.delete": "Delete",
1904
2315
  "settings.save": "Save",
1905
2316
  "settings.saved": "Saved",
1906
- "settings.conflict": "Config changed elsewhere; reloaded — please retry.",
2317
+ "settings.conflict": "Settings changed elsewhere. Your draft is preserved. Review the current settings to continue editing.",
1907
2318
  "settings.error": "Save failed: ",
1908
2319
  "settings.id": "ID",
1909
2320
  "settings.description": "Description",
1910
2321
  "settings.model": "Model",
1911
2322
  "settings.persona": "Persona",
1912
- "settings.toolFilter": "Denied tools",
2323
+ "settings.toolFilter": "Legacy tool restrictions",
1913
2324
  "settings.maxDepth": "Max depth",
1914
- "settings.background": "Background",
1915
2325
  "settings.provider": "Provider",
1916
- "settings.sourceHint": "Stored at $DSH_HOME/settings.yaml under subagent-library.entries."
2326
+ "settings.sourceHint": "Roles are stored in the roster directory, groups in _groups/, and profile model routes in _profiles/."
1917
2327
  };
1918
2328
 
1919
2329
  //#endregion
@@ -1922,6 +2332,9 @@ const NS = "subagent-library";
1922
2332
  const API_PATH = "/subagent-library/api";
1923
2333
  /** Host error codes that carry no `message`; map them to user-facing text. */
1924
2334
  const ERROR_TEXT = {
2335
+ "unauthorized": "请重新登录 DSH,再打开子代理库设置。",
2336
+ "forbidden": "当前身份无权管理子代理库设置。",
2337
+ "host-authentication-unavailable": "DSH 身份验证服务暂不可用,请稍后重试。",
1925
2338
  "not-ready": "设置服务尚未就绪,请稍后重试。",
1926
2339
  "readonly": "设置服务只读,无法完成该操作。",
1927
2340
  "content-type-json-required": "请求被拒绝:写入只接受 JSON。",
@@ -1933,7 +2346,10 @@ const ERROR_TEXT = {
1933
2346
  "unknown-op": "未知操作。",
1934
2347
  "roster-unreadable": "名册目录读取失败。",
1935
2348
  "write-failed": "名册文件写入失败。",
1936
- "profile-path": "当前 profile 名称不能保存独立模型路由。"
2349
+ "profile-path": "当前 profile 名称不能保存独立模型路由。",
2350
+ "role-in-use": "有编队成员还在使用这个角色。",
2351
+ "conflict": "配置已在别处更新,你的草稿已保留。",
2352
+ "roster-busy": "名册正在保存其他修改,请稍后再试。"
1937
2353
  };
1938
2354
  /** Map a wire view onto the UI model. Exported for the wire-contract tests —
1939
2355
  * a dropped field here silently kills UI features (k3 review: legacyCount). */
@@ -1942,16 +2358,29 @@ const parseView = (value) => ({
1942
2358
  dir: value.dir ?? "",
1943
2359
  hash: value.hash ?? "",
1944
2360
  entries: value.entries ?? {},
2361
+ sharedEntries: value.sharedEntries ?? {},
2362
+ groups: value.groups ?? {},
2363
+ roleUsages: value.roleUsages ?? {},
1945
2364
  diagnostics: value.diagnostics ?? [],
1946
2365
  legacyCount: value.legacyCount ?? 0,
1947
- ...typeof value.profile === "string" && value.profile !== "" ? { profile: value.profile } : {}
2366
+ ...typeof value.profile === "string" && value.profile !== "" ? { profile: value.profile } : {},
2367
+ ...value.routeWriteProblem && { routeWriteProblem: value.routeWriteProblem }
1948
2368
  });
2369
+ async function readSettingsBody(response) {
2370
+ if (!response.headers.get("content-type")?.includes("application/json")) {
2371
+ if (response.status === 401) return { error: "unauthorized" };
2372
+ if (response.status === 403) return { error: "forbidden" };
2373
+ if (response.status === 503) return { error: "not-ready" };
2374
+ }
2375
+ const body = await response.json();
2376
+ return typeof body === "object" && body !== null ? body : {};
2377
+ }
1949
2378
  async function readView() {
1950
2379
  const response = await fetch(API_PATH, { cache: "no-store" });
1951
- const body = await response.json();
1952
- if (!response.ok || typeof body !== "object" || body === null || body.ok !== true) {
1953
- const error = body?.error;
1954
- const message = body?.message;
2380
+ const body = await readSettingsBody(response);
2381
+ if (!response.ok || body.ok !== true) {
2382
+ const error = body.error;
2383
+ const message = body.message;
1955
2384
  throw new Error(message ?? (error !== void 0 ? ERROR_TEXT[error] : void 0) ?? "子代理库接口不可用(插件未加载?)");
1956
2385
  }
1957
2386
  return parseView(body);
@@ -1964,16 +2393,14 @@ async function writeView(write) {
1964
2393
  body: JSON.stringify(write),
1965
2394
  cache: "no-store"
1966
2395
  });
1967
- const body = await response.json();
1968
- const wire = typeof body === "object" && body !== null ? body : {};
1969
- if (response.status === 409) return {
1970
- ok: false,
1971
- conflict: true,
1972
- view: wire.view !== void 0 ? parseView(wire.view) : void 0
1973
- };
2396
+ const wire = await readSettingsBody(response);
1974
2397
  if (!response.ok || wire.ok !== true) return {
1975
2398
  ok: false,
1976
- message: wire.message ?? (wire.error !== void 0 ? ERROR_TEXT[wire.error] : void 0) ?? "保存失败"
2399
+ error: wire.error,
2400
+ conflict: response.status === 409 && wire.error === "conflict",
2401
+ message: wire.message?.replace(/^Error:\s*/, "") ?? (wire.error ? ERROR_TEXT[wire.error] : void 0) ?? "保存失败",
2402
+ view: wire.view && parseView(wire.view),
2403
+ references: wire.references
1977
2404
  };
1978
2405
  return {
1979
2406
  ok: true,