dsh-subagent-library 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/cordis.patch.yml +7 -0
- package/lib/client.js +973 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +9582 -0
- package/lib/index.js.map +1 -0
- package/package.json +95 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,973 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({ id: "dsh-subagent-library", factory: (require) => {
|
|
2
|
+
var module = { exports: {} }; var exports = module.exports;
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
let react = require("react");
|
|
27
|
+
react = __toESM(react);
|
|
28
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
30
|
+
|
|
31
|
+
//#region src/client/LibrarySettings.tsx
|
|
32
|
+
function LibrarySettings(props) {
|
|
33
|
+
const { readView: readView$1, writeView: writeView$1, subscribeRefresh } = props;
|
|
34
|
+
const [view, setView] = (0, react.useState)(null);
|
|
35
|
+
const [entries, setEntries] = (0, react.useState)({});
|
|
36
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
37
|
+
const [status, setStatus] = (0, react.useState)(null);
|
|
38
|
+
const [newId, setNewId] = (0, react.useState)("");
|
|
39
|
+
const [newEntry, setNewEntry] = (0, react.useState)({
|
|
40
|
+
description: "",
|
|
41
|
+
provider: "",
|
|
42
|
+
model: "",
|
|
43
|
+
backgroundMode: "one-shot"
|
|
44
|
+
});
|
|
45
|
+
const alive = (0, react.useRef)(true);
|
|
46
|
+
/** Synchronous busy flag (see applyWrite's re-entry guard). */
|
|
47
|
+
const busyRef = (0, react.useRef)(false);
|
|
48
|
+
(0, react.useEffect)(() => () => {
|
|
49
|
+
alive.current = false;
|
|
50
|
+
}, []);
|
|
51
|
+
/** Revision of the last committed server state (successful write or load).
|
|
52
|
+
* document-updated pushes at or below it are our own write's echo and are
|
|
53
|
+
* skipped — applyWrite already merged the touched row, and a full reload
|
|
54
|
+
* here would wipe unsaved drafts in other rows. External pushes (higher
|
|
55
|
+
* revisions) still reload. */
|
|
56
|
+
const lastCommitted = (0, react.useRef)(null);
|
|
57
|
+
/** True while a write request is in flight: the push and the HTTP response
|
|
58
|
+
* travel on independent channels, so a push may arrive before the response
|
|
59
|
+
* commits our state. Everything in this window is skipped and the newest
|
|
60
|
+
* skipped revision is re-checked after the response. */
|
|
61
|
+
const pendingSelfWrite = (0, react.useRef)(false);
|
|
62
|
+
const skippedWhilePending = (0, react.useRef)(null);
|
|
63
|
+
const load = () => {
|
|
64
|
+
(async () => {
|
|
65
|
+
try {
|
|
66
|
+
const next = await readView$1();
|
|
67
|
+
if (!alive.current) return;
|
|
68
|
+
lastCommitted.current = next.revision;
|
|
69
|
+
setView(next);
|
|
70
|
+
setEntries(structuredClone(next.entries));
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (alive.current) setStatus({
|
|
73
|
+
kind: "error",
|
|
74
|
+
text: String(error)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
};
|
|
79
|
+
(0, react.useEffect)(() => {
|
|
80
|
+
load();
|
|
81
|
+
return subscribeRefresh((revision) => {
|
|
82
|
+
if (pendingSelfWrite.current) {
|
|
83
|
+
if (revision !== void 0) skippedWhilePending.current = Math.max(skippedWhilePending.current ?? -1, revision);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (revision !== void 0 && lastCommitted.current !== null && revision <= lastCommitted.current) return;
|
|
87
|
+
load();
|
|
88
|
+
});
|
|
89
|
+
}, [subscribeRefresh]);
|
|
90
|
+
const applyWrite = async (write, touchedId) => {
|
|
91
|
+
if (busyRef.current) return false;
|
|
92
|
+
busyRef.current = true;
|
|
93
|
+
setBusy(true);
|
|
94
|
+
setStatus(null);
|
|
95
|
+
pendingSelfWrite.current = true;
|
|
96
|
+
try {
|
|
97
|
+
const result = await writeView$1(write);
|
|
98
|
+
if (!alive.current) return false;
|
|
99
|
+
pendingSelfWrite.current = false;
|
|
100
|
+
const skipped = skippedWhilePending.current;
|
|
101
|
+
skippedWhilePending.current = null;
|
|
102
|
+
if (result.ok) {
|
|
103
|
+
lastCommitted.current = result.view.revision;
|
|
104
|
+
setView(result.view);
|
|
105
|
+
setEntries((current) => {
|
|
106
|
+
const next = { ...current };
|
|
107
|
+
const fresh = result.view.entries[touchedId];
|
|
108
|
+
if (fresh !== void 0) next[touchedId] = structuredClone(fresh);
|
|
109
|
+
else delete next[touchedId];
|
|
110
|
+
return next;
|
|
111
|
+
});
|
|
112
|
+
setStatus({
|
|
113
|
+
kind: "ok",
|
|
114
|
+
text: "已保存"
|
|
115
|
+
});
|
|
116
|
+
if (skipped !== null && skipped > result.view.revision) load();
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
skippedWhilePending.current = null;
|
|
120
|
+
if (result.conflict) {
|
|
121
|
+
setStatus({
|
|
122
|
+
kind: "error",
|
|
123
|
+
text: "配置已被其他窗口修改,已重新加载,请重试。"
|
|
124
|
+
});
|
|
125
|
+
load();
|
|
126
|
+
} else {
|
|
127
|
+
if (skipped !== null && lastCommitted.current !== null && skipped > lastCommitted.current) load();
|
|
128
|
+
setStatus({
|
|
129
|
+
kind: "error",
|
|
130
|
+
text: result.message ?? "保存失败"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
} finally {
|
|
135
|
+
pendingSelfWrite.current = false;
|
|
136
|
+
busyRef.current = false;
|
|
137
|
+
if (alive.current) setBusy(false);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** Normalize one entry for persistence: empty optional fields are dropped
|
|
141
|
+
* (they then fall back to their defaults instead of being stored as '' or
|
|
142
|
+
* stale values), and toolFilter survives only while it still scopes
|
|
143
|
+
* something — an allow list alone must NOT be deleted by an editor that
|
|
144
|
+
* only shows deny. */
|
|
145
|
+
const cleanEntry = (entry) => {
|
|
146
|
+
const clean = { ...entry };
|
|
147
|
+
if (clean.provider === "") delete clean.provider;
|
|
148
|
+
if (clean.model === "") delete clean.model;
|
|
149
|
+
if (clean.subagentProvider === "") delete clean.subagentProvider;
|
|
150
|
+
if (clean.persona === "") delete clean.persona;
|
|
151
|
+
if (clean.description === "") delete clean.description;
|
|
152
|
+
if (clean.maxDepth === void 0) delete clean.maxDepth;
|
|
153
|
+
if (clean.maxTokens === void 0) delete clean.maxTokens;
|
|
154
|
+
const filter = clean.toolFilter;
|
|
155
|
+
if (filter !== void 0 && (filter.allow === void 0 || filter.allow.length === 0) && (filter.deny === void 0 || filter.deny.length === 0)) delete clean.toolFilter;
|
|
156
|
+
return clean;
|
|
157
|
+
};
|
|
158
|
+
const updateEntry = (id, entry) => {
|
|
159
|
+
if ((entry.description ?? "").trim() === "") {
|
|
160
|
+
setStatus({
|
|
161
|
+
kind: "error",
|
|
162
|
+
text: "描述不能为空。"
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (entry.maxDepth !== void 0 && (!Number.isInteger(entry.maxDepth) || entry.maxDepth < 1)) {
|
|
167
|
+
setStatus({
|
|
168
|
+
kind: "error",
|
|
169
|
+
text: "深度上限需为 ≥1 的整数。"
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (entry.maxTokens !== void 0 && (!Number.isInteger(entry.maxTokens) || entry.maxTokens < 1)) {
|
|
174
|
+
setStatus({
|
|
175
|
+
kind: "error",
|
|
176
|
+
text: "输出上限需为 ≥1 的整数。"
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
applyWrite({
|
|
181
|
+
op: "save",
|
|
182
|
+
entries: {
|
|
183
|
+
...view?.entries ?? {},
|
|
184
|
+
[id]: cleanEntry(entry)
|
|
185
|
+
},
|
|
186
|
+
expectedRevision: view?.revision
|
|
187
|
+
}, id);
|
|
188
|
+
};
|
|
189
|
+
const removeEntry = (id) => {
|
|
190
|
+
if (!window.confirm(`确认删除子代理 "${id}"?该操作立即写入 settings.yaml。`)) return;
|
|
191
|
+
applyWrite({
|
|
192
|
+
op: "delete",
|
|
193
|
+
id,
|
|
194
|
+
expectedRevision: view?.revision
|
|
195
|
+
}, id);
|
|
196
|
+
};
|
|
197
|
+
const addEntry = () => {
|
|
198
|
+
const id = newId.trim();
|
|
199
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id) || (newEntry.description ?? "").trim() === "") {
|
|
200
|
+
setStatus({
|
|
201
|
+
kind: "error",
|
|
202
|
+
text: "ID 需为小写字母/数字/连字符,且必须有描述。"
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const serverEntries = view?.entries ?? {};
|
|
207
|
+
if (serverEntries[id] !== void 0) {
|
|
208
|
+
setStatus({
|
|
209
|
+
kind: "error",
|
|
210
|
+
text: `ID "${id}" 已存在。`
|
|
211
|
+
});
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (newEntry.maxTokens !== void 0 && (!Number.isInteger(newEntry.maxTokens) || newEntry.maxTokens < 1)) {
|
|
215
|
+
setStatus({
|
|
216
|
+
kind: "error",
|
|
217
|
+
text: "输出上限需为 ≥1 的整数。"
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
applyWrite({
|
|
222
|
+
op: "save",
|
|
223
|
+
entries: {
|
|
224
|
+
...serverEntries,
|
|
225
|
+
[id]: cleanEntry(newEntry)
|
|
226
|
+
},
|
|
227
|
+
expectedRevision: view?.revision
|
|
228
|
+
}, id).then((ok) => {
|
|
229
|
+
if (alive.current && ok) {
|
|
230
|
+
setNewId("");
|
|
231
|
+
setNewEntry({
|
|
232
|
+
description: "",
|
|
233
|
+
provider: "",
|
|
234
|
+
model: "",
|
|
235
|
+
backgroundMode: "one-shot"
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
const rowStyle = {
|
|
241
|
+
display: "flex",
|
|
242
|
+
alignItems: "center",
|
|
243
|
+
gap: "8px"
|
|
244
|
+
};
|
|
245
|
+
/** Shrinkable multi-column row: min-width 0 lets inputs shrink below their
|
|
246
|
+
* intrinsic width instead of overflowing the settings card (form controls
|
|
247
|
+
* otherwise keep their default width as a flex minimum). */
|
|
248
|
+
const colStyle = {
|
|
249
|
+
...rowStyle,
|
|
250
|
+
flex: 1,
|
|
251
|
+
minWidth: 0
|
|
252
|
+
};
|
|
253
|
+
const labelStyle = {
|
|
254
|
+
fontSize: "13px",
|
|
255
|
+
opacity: .85,
|
|
256
|
+
minWidth: "72px"
|
|
257
|
+
};
|
|
258
|
+
const inputStyle = {
|
|
259
|
+
flex: 1,
|
|
260
|
+
minWidth: 0,
|
|
261
|
+
fontSize: "13px",
|
|
262
|
+
fontFamily: "monospace",
|
|
263
|
+
padding: "4px 8px",
|
|
264
|
+
border: "1px solid var(--dsh-color-border, #3a3f4b)",
|
|
265
|
+
borderRadius: "4px",
|
|
266
|
+
background: "transparent",
|
|
267
|
+
color: "inherit"
|
|
268
|
+
};
|
|
269
|
+
const buttonStyle = {
|
|
270
|
+
padding: "3px 12px",
|
|
271
|
+
fontSize: "12px",
|
|
272
|
+
cursor: "pointer",
|
|
273
|
+
opacity: busy ? .55 : 1
|
|
274
|
+
};
|
|
275
|
+
const cardStyle = {
|
|
276
|
+
display: "flex",
|
|
277
|
+
flexDirection: "column",
|
|
278
|
+
gap: "6px",
|
|
279
|
+
padding: "10px 12px",
|
|
280
|
+
border: "1px solid var(--dsh-color-border, #3a3f4b)",
|
|
281
|
+
borderRadius: "6px"
|
|
282
|
+
};
|
|
283
|
+
const hintStyle = {
|
|
284
|
+
fontSize: "11px",
|
|
285
|
+
opacity: .6,
|
|
286
|
+
marginTop: "2px"
|
|
287
|
+
};
|
|
288
|
+
if (view === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
289
|
+
style: {
|
|
290
|
+
display: "flex",
|
|
291
|
+
flexDirection: "column",
|
|
292
|
+
gap: "8px",
|
|
293
|
+
padding: "12px 4px"
|
|
294
|
+
},
|
|
295
|
+
children: [
|
|
296
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
297
|
+
style: {
|
|
298
|
+
display: "flex",
|
|
299
|
+
alignItems: "center",
|
|
300
|
+
gap: "10px"
|
|
301
|
+
},
|
|
302
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
303
|
+
style: {
|
|
304
|
+
fontSize: "15px",
|
|
305
|
+
fontWeight: 600
|
|
306
|
+
},
|
|
307
|
+
children: "子代理库"
|
|
308
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
309
|
+
type: "button",
|
|
310
|
+
onClick: load,
|
|
311
|
+
style: {
|
|
312
|
+
...buttonStyle,
|
|
313
|
+
opacity: .7
|
|
314
|
+
},
|
|
315
|
+
children: "重试"
|
|
316
|
+
})]
|
|
317
|
+
}),
|
|
318
|
+
status !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
319
|
+
style: {
|
|
320
|
+
fontSize: "12px",
|
|
321
|
+
color: status.kind === "ok" ? "var(--dsh-color-success, #30a46c)" : "var(--dsh-color-danger, #e5484d)",
|
|
322
|
+
whiteSpace: "pre-wrap"
|
|
323
|
+
},
|
|
324
|
+
children: status.text
|
|
325
|
+
}),
|
|
326
|
+
status === null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
327
|
+
style: {
|
|
328
|
+
fontSize: "13px",
|
|
329
|
+
opacity: .8
|
|
330
|
+
},
|
|
331
|
+
children: "正在加载…(若长时间无响应,请重试或检查插件是否加载)"
|
|
332
|
+
})
|
|
333
|
+
]
|
|
334
|
+
});
|
|
335
|
+
const ids = Object.keys(entries);
|
|
336
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
337
|
+
style: {
|
|
338
|
+
display: "flex",
|
|
339
|
+
flexDirection: "column",
|
|
340
|
+
gap: "10px",
|
|
341
|
+
padding: "12px 4px",
|
|
342
|
+
maxWidth: "720px"
|
|
343
|
+
},
|
|
344
|
+
children: [
|
|
345
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
346
|
+
style: {
|
|
347
|
+
display: "flex",
|
|
348
|
+
flexDirection: "column",
|
|
349
|
+
gap: "2px"
|
|
350
|
+
},
|
|
351
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
352
|
+
style: {
|
|
353
|
+
display: "flex",
|
|
354
|
+
alignItems: "center",
|
|
355
|
+
gap: "10px"
|
|
356
|
+
},
|
|
357
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
358
|
+
style: {
|
|
359
|
+
fontSize: "15px",
|
|
360
|
+
fontWeight: 600
|
|
361
|
+
},
|
|
362
|
+
children: "子代理库"
|
|
363
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
364
|
+
type: "button",
|
|
365
|
+
onClick: load,
|
|
366
|
+
style: {
|
|
367
|
+
...buttonStyle,
|
|
368
|
+
opacity: .7
|
|
369
|
+
},
|
|
370
|
+
children: "刷新"
|
|
371
|
+
})]
|
|
372
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
373
|
+
style: hintStyle,
|
|
374
|
+
children: "管理具名角色子代理。保存后热生效:模型可在任意会话通过 list_subagents / delegate 使用。"
|
|
375
|
+
})]
|
|
376
|
+
}),
|
|
377
|
+
!view.writable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
378
|
+
style: {
|
|
379
|
+
fontSize: "12px",
|
|
380
|
+
opacity: .7
|
|
381
|
+
},
|
|
382
|
+
children: "(当前设置只读)"
|
|
383
|
+
}),
|
|
384
|
+
ids.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
385
|
+
style: {
|
|
386
|
+
fontSize: "13px",
|
|
387
|
+
opacity: .8
|
|
388
|
+
},
|
|
389
|
+
children: "库为空。添加第一个条目开始使用。"
|
|
390
|
+
}),
|
|
391
|
+
ids.map((id) => {
|
|
392
|
+
const entry = entries[id];
|
|
393
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
394
|
+
style: cardStyle,
|
|
395
|
+
children: [
|
|
396
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
397
|
+
style: {
|
|
398
|
+
display: "flex",
|
|
399
|
+
alignItems: "center",
|
|
400
|
+
gap: "10px"
|
|
401
|
+
},
|
|
402
|
+
children: [
|
|
403
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
404
|
+
style: {
|
|
405
|
+
fontSize: "13px",
|
|
406
|
+
fontWeight: 600,
|
|
407
|
+
fontFamily: "monospace"
|
|
408
|
+
},
|
|
409
|
+
children: id
|
|
410
|
+
}),
|
|
411
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
412
|
+
style: {
|
|
413
|
+
fontSize: "11px",
|
|
414
|
+
opacity: .7
|
|
415
|
+
},
|
|
416
|
+
children: [
|
|
417
|
+
entry.provider || "默认路由",
|
|
418
|
+
"/",
|
|
419
|
+
entry.model || "默认模型",
|
|
420
|
+
entry.backgroundMode === "continuable" ? " · 可续聊" : "",
|
|
421
|
+
entry.maxDepth !== void 0 ? ` · 深度${entry.maxDepth}` : "",
|
|
422
|
+
entry.maxTokens !== void 0 ? ` · ${entry.maxTokens}tok` : ""
|
|
423
|
+
]
|
|
424
|
+
}),
|
|
425
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { flex: 1 } }),
|
|
426
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
427
|
+
type: "button",
|
|
428
|
+
disabled: busy || !view.writable,
|
|
429
|
+
onClick: () => removeEntry(id),
|
|
430
|
+
style: buttonStyle,
|
|
431
|
+
children: "删除"
|
|
432
|
+
}),
|
|
433
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
434
|
+
type: "button",
|
|
435
|
+
disabled: busy || !view.writable,
|
|
436
|
+
onClick: () => updateEntry(id, entry),
|
|
437
|
+
style: buttonStyle,
|
|
438
|
+
children: "保存"
|
|
439
|
+
})
|
|
440
|
+
]
|
|
441
|
+
}),
|
|
442
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
443
|
+
style: rowStyle,
|
|
444
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
445
|
+
style: labelStyle,
|
|
446
|
+
children: "描述"
|
|
447
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
448
|
+
value: entry.description ?? "",
|
|
449
|
+
onChange: (event) => setEntries({
|
|
450
|
+
...entries,
|
|
451
|
+
[id]: {
|
|
452
|
+
...entry,
|
|
453
|
+
description: event.target.value
|
|
454
|
+
}
|
|
455
|
+
}),
|
|
456
|
+
placeholder: "角色描述(模型可见)",
|
|
457
|
+
style: inputStyle
|
|
458
|
+
})]
|
|
459
|
+
}),
|
|
460
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
461
|
+
style: {
|
|
462
|
+
display: "flex",
|
|
463
|
+
flexWrap: "wrap",
|
|
464
|
+
gap: "8px"
|
|
465
|
+
},
|
|
466
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
467
|
+
style: colStyle,
|
|
468
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
469
|
+
style: labelStyle,
|
|
470
|
+
children: "Provider"
|
|
471
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
472
|
+
value: entry.provider ?? "",
|
|
473
|
+
onChange: (event) => setEntries({
|
|
474
|
+
...entries,
|
|
475
|
+
[id]: {
|
|
476
|
+
...entry,
|
|
477
|
+
provider: event.target.value
|
|
478
|
+
}
|
|
479
|
+
}),
|
|
480
|
+
placeholder: "deepseek-official / kimi-coding",
|
|
481
|
+
style: inputStyle
|
|
482
|
+
})]
|
|
483
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
484
|
+
style: colStyle,
|
|
485
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
486
|
+
style: labelStyle,
|
|
487
|
+
children: "模型"
|
|
488
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
489
|
+
value: entry.model ?? "",
|
|
490
|
+
onChange: (event) => setEntries({
|
|
491
|
+
...entries,
|
|
492
|
+
[id]: {
|
|
493
|
+
...entry,
|
|
494
|
+
model: event.target.value
|
|
495
|
+
}
|
|
496
|
+
}),
|
|
497
|
+
placeholder: "k3-256k",
|
|
498
|
+
style: inputStyle
|
|
499
|
+
})]
|
|
500
|
+
})]
|
|
501
|
+
}),
|
|
502
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
503
|
+
style: {
|
|
504
|
+
display: "flex",
|
|
505
|
+
flexWrap: "wrap",
|
|
506
|
+
gap: "8px"
|
|
507
|
+
},
|
|
508
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
509
|
+
style: colStyle,
|
|
510
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
511
|
+
style: labelStyle,
|
|
512
|
+
children: "传输层"
|
|
513
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
514
|
+
value: entry.subagentProvider ?? "",
|
|
515
|
+
onChange: (event) => setEntries({
|
|
516
|
+
...entries,
|
|
517
|
+
[id]: {
|
|
518
|
+
...entry,
|
|
519
|
+
subagentProvider: event.target.value
|
|
520
|
+
}
|
|
521
|
+
}),
|
|
522
|
+
placeholder: "spawn(默认)",
|
|
523
|
+
style: inputStyle
|
|
524
|
+
})]
|
|
525
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
526
|
+
style: colStyle,
|
|
527
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
528
|
+
style: labelStyle,
|
|
529
|
+
children: "输出上限"
|
|
530
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
531
|
+
type: "number",
|
|
532
|
+
min: 1,
|
|
533
|
+
value: entry.maxTokens ?? "",
|
|
534
|
+
onChange: (event) => setEntries({
|
|
535
|
+
...entries,
|
|
536
|
+
[id]: {
|
|
537
|
+
...entry,
|
|
538
|
+
maxTokens: event.target.value === "" ? void 0 : Number(event.target.value)
|
|
539
|
+
}
|
|
540
|
+
}),
|
|
541
|
+
placeholder: "tokens",
|
|
542
|
+
style: {
|
|
543
|
+
...inputStyle,
|
|
544
|
+
maxWidth: "110px"
|
|
545
|
+
}
|
|
546
|
+
})]
|
|
547
|
+
})]
|
|
548
|
+
}),
|
|
549
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
550
|
+
style: {
|
|
551
|
+
display: "flex",
|
|
552
|
+
flexWrap: "wrap",
|
|
553
|
+
gap: "8px"
|
|
554
|
+
},
|
|
555
|
+
children: [
|
|
556
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
557
|
+
style: colStyle,
|
|
558
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
559
|
+
style: labelStyle,
|
|
560
|
+
children: "深度上限"
|
|
561
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
562
|
+
type: "number",
|
|
563
|
+
min: 1,
|
|
564
|
+
value: entry.maxDepth ?? "",
|
|
565
|
+
onChange: (event) => setEntries({
|
|
566
|
+
...entries,
|
|
567
|
+
[id]: {
|
|
568
|
+
...entry,
|
|
569
|
+
maxDepth: event.target.value === "" ? void 0 : Number(event.target.value)
|
|
570
|
+
}
|
|
571
|
+
}),
|
|
572
|
+
style: {
|
|
573
|
+
...inputStyle,
|
|
574
|
+
maxWidth: "80px"
|
|
575
|
+
}
|
|
576
|
+
})]
|
|
577
|
+
}),
|
|
578
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
579
|
+
style: colStyle,
|
|
580
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
581
|
+
style: labelStyle,
|
|
582
|
+
children: "后台模式"
|
|
583
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
584
|
+
value: entry.backgroundMode ?? "one-shot",
|
|
585
|
+
onChange: (event) => setEntries({
|
|
586
|
+
...entries,
|
|
587
|
+
[id]: {
|
|
588
|
+
...entry,
|
|
589
|
+
backgroundMode: event.target.value
|
|
590
|
+
}
|
|
591
|
+
}),
|
|
592
|
+
style: {
|
|
593
|
+
...inputStyle,
|
|
594
|
+
maxWidth: "140px"
|
|
595
|
+
},
|
|
596
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
597
|
+
value: "one-shot",
|
|
598
|
+
children: "one-shot"
|
|
599
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
600
|
+
value: "continuable",
|
|
601
|
+
children: "continuable"
|
|
602
|
+
})]
|
|
603
|
+
})]
|
|
604
|
+
}),
|
|
605
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
606
|
+
style: {
|
|
607
|
+
...colStyle,
|
|
608
|
+
flex: 2
|
|
609
|
+
},
|
|
610
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
611
|
+
style: labelStyle,
|
|
612
|
+
children: "禁用工具"
|
|
613
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
614
|
+
value: (entry.toolFilter?.deny ?? []).join(", "),
|
|
615
|
+
onChange: (event) => {
|
|
616
|
+
const deny = event.target.value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
617
|
+
const allow = entry.toolFilter?.allow;
|
|
618
|
+
setEntries({
|
|
619
|
+
...entries,
|
|
620
|
+
[id]: {
|
|
621
|
+
...entry,
|
|
622
|
+
toolFilter: allow !== void 0 && allow.length > 0 || deny.length > 0 ? {
|
|
623
|
+
...allow !== void 0 && allow.length > 0 ? { allow } : {},
|
|
624
|
+
...deny.length > 0 ? { deny } : {}
|
|
625
|
+
} : void 0
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
},
|
|
629
|
+
placeholder: "write, edit, todo_write, …",
|
|
630
|
+
style: inputStyle
|
|
631
|
+
})]
|
|
632
|
+
})
|
|
633
|
+
]
|
|
634
|
+
}),
|
|
635
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
636
|
+
style: rowStyle,
|
|
637
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
638
|
+
style: labelStyle,
|
|
639
|
+
children: "角色提示词"
|
|
640
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
|
|
641
|
+
value: entry.persona ?? "",
|
|
642
|
+
onChange: (event) => setEntries({
|
|
643
|
+
...entries,
|
|
644
|
+
[id]: {
|
|
645
|
+
...entry,
|
|
646
|
+
persona: event.target.value
|
|
647
|
+
}
|
|
648
|
+
}),
|
|
649
|
+
placeholder: "子代理的系统提示词(可选)",
|
|
650
|
+
rows: 3,
|
|
651
|
+
style: {
|
|
652
|
+
...inputStyle,
|
|
653
|
+
resize: "vertical",
|
|
654
|
+
fontFamily: "inherit"
|
|
655
|
+
}
|
|
656
|
+
})]
|
|
657
|
+
})
|
|
658
|
+
]
|
|
659
|
+
}, id);
|
|
660
|
+
}),
|
|
661
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
662
|
+
style: cardStyle,
|
|
663
|
+
children: [
|
|
664
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
665
|
+
style: {
|
|
666
|
+
display: "flex",
|
|
667
|
+
alignItems: "center",
|
|
668
|
+
gap: "10px"
|
|
669
|
+
},
|
|
670
|
+
children: [
|
|
671
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
672
|
+
style: {
|
|
673
|
+
fontSize: "13px",
|
|
674
|
+
fontWeight: 600
|
|
675
|
+
},
|
|
676
|
+
children: "新增子代理"
|
|
677
|
+
}),
|
|
678
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { flex: 1 } }),
|
|
679
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
680
|
+
type: "button",
|
|
681
|
+
disabled: busy || !view.writable,
|
|
682
|
+
onClick: addEntry,
|
|
683
|
+
style: buttonStyle,
|
|
684
|
+
children: "添加"
|
|
685
|
+
})
|
|
686
|
+
]
|
|
687
|
+
}),
|
|
688
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
689
|
+
style: rowStyle,
|
|
690
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
691
|
+
style: labelStyle,
|
|
692
|
+
children: "ID"
|
|
693
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
694
|
+
value: newId,
|
|
695
|
+
onChange: (event) => setNewId(event.target.value),
|
|
696
|
+
placeholder: "k3-reviewer",
|
|
697
|
+
style: {
|
|
698
|
+
...inputStyle,
|
|
699
|
+
maxWidth: "200px"
|
|
700
|
+
}
|
|
701
|
+
})]
|
|
702
|
+
}),
|
|
703
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
704
|
+
style: rowStyle,
|
|
705
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
706
|
+
style: labelStyle,
|
|
707
|
+
children: "描述"
|
|
708
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
709
|
+
value: newEntry.description ?? "",
|
|
710
|
+
onChange: (event) => setNewEntry({
|
|
711
|
+
...newEntry,
|
|
712
|
+
description: event.target.value
|
|
713
|
+
}),
|
|
714
|
+
placeholder: "角色描述(模型可见)",
|
|
715
|
+
style: inputStyle
|
|
716
|
+
})]
|
|
717
|
+
}),
|
|
718
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
719
|
+
style: {
|
|
720
|
+
display: "flex",
|
|
721
|
+
flexWrap: "wrap",
|
|
722
|
+
gap: "8px"
|
|
723
|
+
},
|
|
724
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
725
|
+
style: colStyle,
|
|
726
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
727
|
+
style: labelStyle,
|
|
728
|
+
children: "Provider"
|
|
729
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
730
|
+
value: newEntry.provider ?? "",
|
|
731
|
+
onChange: (event) => setNewEntry({
|
|
732
|
+
...newEntry,
|
|
733
|
+
provider: event.target.value
|
|
734
|
+
}),
|
|
735
|
+
placeholder: "kimi-coding",
|
|
736
|
+
style: inputStyle
|
|
737
|
+
})]
|
|
738
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
739
|
+
style: colStyle,
|
|
740
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
741
|
+
style: labelStyle,
|
|
742
|
+
children: "模型"
|
|
743
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
744
|
+
value: newEntry.model ?? "",
|
|
745
|
+
onChange: (event) => setNewEntry({
|
|
746
|
+
...newEntry,
|
|
747
|
+
model: event.target.value
|
|
748
|
+
}),
|
|
749
|
+
placeholder: "k3-256k",
|
|
750
|
+
style: inputStyle
|
|
751
|
+
})]
|
|
752
|
+
})]
|
|
753
|
+
}),
|
|
754
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
755
|
+
style: {
|
|
756
|
+
display: "flex",
|
|
757
|
+
flexWrap: "wrap",
|
|
758
|
+
gap: "8px"
|
|
759
|
+
},
|
|
760
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
761
|
+
style: colStyle,
|
|
762
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
763
|
+
style: labelStyle,
|
|
764
|
+
children: "传输层"
|
|
765
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
766
|
+
value: newEntry.subagentProvider ?? "",
|
|
767
|
+
onChange: (event) => setNewEntry({
|
|
768
|
+
...newEntry,
|
|
769
|
+
subagentProvider: event.target.value
|
|
770
|
+
}),
|
|
771
|
+
placeholder: "spawn(默认)",
|
|
772
|
+
style: inputStyle
|
|
773
|
+
})]
|
|
774
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
775
|
+
style: colStyle,
|
|
776
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
777
|
+
style: labelStyle,
|
|
778
|
+
children: "输出上限"
|
|
779
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
780
|
+
type: "number",
|
|
781
|
+
min: 1,
|
|
782
|
+
value: newEntry.maxTokens ?? "",
|
|
783
|
+
onChange: (event) => setNewEntry({
|
|
784
|
+
...newEntry,
|
|
785
|
+
maxTokens: event.target.value === "" ? void 0 : Number(event.target.value)
|
|
786
|
+
}),
|
|
787
|
+
placeholder: "tokens(可选)",
|
|
788
|
+
style: {
|
|
789
|
+
...inputStyle,
|
|
790
|
+
maxWidth: "110px"
|
|
791
|
+
}
|
|
792
|
+
})]
|
|
793
|
+
})]
|
|
794
|
+
})
|
|
795
|
+
]
|
|
796
|
+
}),
|
|
797
|
+
status !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
798
|
+
style: {
|
|
799
|
+
fontSize: "12px",
|
|
800
|
+
color: status.kind === "ok" ? "var(--dsh-color-success, #30a46c)" : "var(--dsh-color-danger, #e5484d)"
|
|
801
|
+
},
|
|
802
|
+
children: status.text
|
|
803
|
+
}),
|
|
804
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
805
|
+
style: {
|
|
806
|
+
fontSize: "11px",
|
|
807
|
+
opacity: .55,
|
|
808
|
+
paddingTop: "4px"
|
|
809
|
+
},
|
|
810
|
+
children: "配置存储于 $DSH_HOME/settings.yaml 的 subagent-library.entries。"
|
|
811
|
+
})
|
|
812
|
+
]
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/client/locales.ts
|
|
818
|
+
const zh = {
|
|
819
|
+
"settings.title": "子代理库",
|
|
820
|
+
"settings.hint": "管理具名角色子代理。保存后热生效:模型可在任意会话通过 list_subagents / delegate 使用。",
|
|
821
|
+
"settings.empty": "库为空。添加第一个条目开始使用。",
|
|
822
|
+
"settings.missing": "未找到 subagent-library 配置段(插件未加载?)。",
|
|
823
|
+
"settings.add": "添加",
|
|
824
|
+
"settings.addNew": "新增子代理",
|
|
825
|
+
"settings.delete": "删除",
|
|
826
|
+
"settings.save": "保存",
|
|
827
|
+
"settings.saved": "已保存",
|
|
828
|
+
"settings.conflict": "配置已被其他窗口修改,已重新加载,请重试。",
|
|
829
|
+
"settings.error": "保存失败:",
|
|
830
|
+
"settings.id": "ID",
|
|
831
|
+
"settings.description": "描述",
|
|
832
|
+
"settings.model": "模型",
|
|
833
|
+
"settings.persona": "角色提示词",
|
|
834
|
+
"settings.toolFilter": "禁用工具",
|
|
835
|
+
"settings.maxDepth": "深度上限",
|
|
836
|
+
"settings.background": "后台模式",
|
|
837
|
+
"settings.provider": "Provider",
|
|
838
|
+
"settings.sourceHint": "配置存储于 $DSH_HOME/settings.yaml 的 subagent-library.entries。"
|
|
839
|
+
};
|
|
840
|
+
const en = {
|
|
841
|
+
"settings.title": "Subagent Library",
|
|
842
|
+
"settings.hint": "Manage named role subagents. Changes apply live: models use them via list_subagents / delegate in any session.",
|
|
843
|
+
"settings.empty": "Library is empty. Add the first entry to get started.",
|
|
844
|
+
"settings.missing": "No subagent-library section found (plugin not loaded?).",
|
|
845
|
+
"settings.add": "Add",
|
|
846
|
+
"settings.addNew": "New subagent",
|
|
847
|
+
"settings.delete": "Delete",
|
|
848
|
+
"settings.save": "Save",
|
|
849
|
+
"settings.saved": "Saved",
|
|
850
|
+
"settings.conflict": "Config changed elsewhere; reloaded — please retry.",
|
|
851
|
+
"settings.error": "Save failed: ",
|
|
852
|
+
"settings.id": "ID",
|
|
853
|
+
"settings.description": "Description",
|
|
854
|
+
"settings.model": "Model",
|
|
855
|
+
"settings.persona": "Persona",
|
|
856
|
+
"settings.toolFilter": "Denied tools",
|
|
857
|
+
"settings.maxDepth": "Max depth",
|
|
858
|
+
"settings.background": "Background",
|
|
859
|
+
"settings.provider": "Provider",
|
|
860
|
+
"settings.sourceHint": "Stored at $DSH_HOME/settings.yaml under subagent-library.entries."
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
//#endregion
|
|
864
|
+
//#region src/client/index.tsx
|
|
865
|
+
const NS = "subagent-library";
|
|
866
|
+
const API_PATH = "/subagent-library/api";
|
|
867
|
+
/** Host error codes that carry no `message`; map them to user-facing text. */
|
|
868
|
+
const ERROR_TEXT = {
|
|
869
|
+
"not-ready": "设置服务尚未就绪,请稍后重试。",
|
|
870
|
+
"readonly": "设置当前为只读,无法写入。",
|
|
871
|
+
"content-type-json-required": "请求被拒绝:写入只接受 JSON。",
|
|
872
|
+
"cross-origin-forbidden": "请求被拒绝:跨源写入。",
|
|
873
|
+
"body-too-large": "请求体超过 1 MiB 上限。",
|
|
874
|
+
"bad-json": "请求体不是合法 JSON。",
|
|
875
|
+
"entries-object-required": "缺少 entries 对象。",
|
|
876
|
+
"invalid-id": "条目 ID 非法。",
|
|
877
|
+
"unknown-op": "未知操作。"
|
|
878
|
+
};
|
|
879
|
+
async function readView() {
|
|
880
|
+
const response = await fetch(API_PATH, { cache: "no-store" });
|
|
881
|
+
const body = await response.json();
|
|
882
|
+
if (!response.ok || typeof body !== "object" || body === null || body.ok !== true) {
|
|
883
|
+
const error = body?.error;
|
|
884
|
+
const message = body?.message;
|
|
885
|
+
throw new Error(message ?? (error !== void 0 ? ERROR_TEXT[error] : void 0) ?? "子代理库接口不可用(插件未加载?)");
|
|
886
|
+
}
|
|
887
|
+
const value = body;
|
|
888
|
+
return {
|
|
889
|
+
writable: value.writable,
|
|
890
|
+
revision: value.revision,
|
|
891
|
+
entries: value.entries ?? {}
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
async function writeView(write) {
|
|
895
|
+
try {
|
|
896
|
+
const response = await fetch(API_PATH, {
|
|
897
|
+
method: "POST",
|
|
898
|
+
headers: { "content-type": "application/json" },
|
|
899
|
+
body: JSON.stringify(write),
|
|
900
|
+
cache: "no-store"
|
|
901
|
+
});
|
|
902
|
+
const body = await response.json();
|
|
903
|
+
if (response.status === 409) return {
|
|
904
|
+
ok: false,
|
|
905
|
+
conflict: true
|
|
906
|
+
};
|
|
907
|
+
if (!response.ok || typeof body !== "object" || body === null || body.ok !== true) {
|
|
908
|
+
const message = body?.message;
|
|
909
|
+
const error = body?.error;
|
|
910
|
+
return {
|
|
911
|
+
ok: false,
|
|
912
|
+
message: message ?? (error !== void 0 ? ERROR_TEXT[error] : void 0) ?? "保存失败"
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
const value = body;
|
|
916
|
+
return {
|
|
917
|
+
ok: true,
|
|
918
|
+
view: {
|
|
919
|
+
writable: value.writable,
|
|
920
|
+
revision: value.revision,
|
|
921
|
+
entries: value.entries ?? {}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
} catch (error) {
|
|
925
|
+
return {
|
|
926
|
+
ok: false,
|
|
927
|
+
message: String(error)
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
const inject = [
|
|
932
|
+
"slots",
|
|
933
|
+
"locale",
|
|
934
|
+
"remote"
|
|
935
|
+
];
|
|
936
|
+
function apply(ctx) {
|
|
937
|
+
ctx.effect(() => ctx.locale.register(NS, {
|
|
938
|
+
zh,
|
|
939
|
+
en
|
|
940
|
+
}), "subagent-library: dictionaries");
|
|
941
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
942
|
+
const subscribeRefresh = (fn) => {
|
|
943
|
+
listeners.add(fn);
|
|
944
|
+
return () => {
|
|
945
|
+
listeners.delete(fn);
|
|
946
|
+
};
|
|
947
|
+
};
|
|
948
|
+
const refresh = (revision) => {
|
|
949
|
+
for (const fn of listeners) try {
|
|
950
|
+
fn(revision);
|
|
951
|
+
} catch {}
|
|
952
|
+
};
|
|
953
|
+
ctx.effect(() => ctx.remote.$on("settings/document-updated", (ns, revision) => {
|
|
954
|
+
if (ns === NS) refresh(revision);
|
|
955
|
+
}), "subagent-library: settings invalidation");
|
|
956
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
957
|
+
name: "settings.section",
|
|
958
|
+
id: NS,
|
|
959
|
+
order: 40,
|
|
960
|
+
label: () => "子代理库",
|
|
961
|
+
inject: () => ({
|
|
962
|
+
readView,
|
|
963
|
+
writeView,
|
|
964
|
+
subscribeRefresh
|
|
965
|
+
})
|
|
966
|
+
}, LibrarySettings));
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
//#endregion
|
|
970
|
+
exports.apply = apply;
|
|
971
|
+
exports.inject = inject;
|
|
972
|
+
return module.exports; } });
|
|
973
|
+
//# sourceMappingURL=client.js.map
|