dsh-tool-manager 1.1.1 → 1.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/CHANGELOG.md +19 -0
- package/DESIGN.md +17 -10
- package/README.md +8 -6
- package/dist/catalog.d.ts +2 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +14 -7
- package/dist/catalog.js.map +1 -1
- package/dist/client.js +421 -61
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -4
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +15 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +52 -7
- package/dist/policy.js.map +1 -1
- package/dist/runtime.d.ts +14 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +67 -61
- package/dist/runtime.js.map +1 -1
- package/dist/suggest.d.ts +11 -2
- package/dist/suggest.d.ts.map +1 -1
- package/dist/suggest.js +54 -7
- package/dist/suggest.js.map +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -13,14 +13,14 @@ window.__ModuleLoader__.load({
|
|
|
13
13
|
".tm_root{display:flex;flex-direction:column;gap:14px;max-width:1040px;padding:2px 0 30px;color:var(--dsw-alias-label-primary,#e7e9ed)}",
|
|
14
14
|
".tm_head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}",
|
|
15
15
|
".tm_head h2{font-size:18px;margin:0 0 5px}.tm_muted{color:var(--dsw-alias-label-secondary,#9097a4);font-size:12px;line-height:1.5}",
|
|
16
|
-
".tm_preset_picker{display:flex;align-items:center;gap:9px;flex-wrap:wrap}.tm_preset_picker label{font-size:12px;color:var(--dsw-alias-label-secondary,#9097a4)}.tm_preset_select,.tm_btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.28));border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.08));color:inherit;padding:7px 10px;font:inherit;font-size:12px}.tm_preset_select{min-width:min(360px,100%);cursor:pointer}.tm_preset_select option{background:var(--dsw-alias-bg-base,#17191d);color:inherit}.tm_btn{cursor:pointer}.tm_btn.primary{background:#5367e8;border-color:#5367e8;color:#fff}.tm_btn:disabled{opacity:.5;cursor:not-allowed}",
|
|
16
|
+
".tm_preset_picker{display:flex;align-items:center;gap:9px;flex-wrap:wrap}.tm_preset_picker label{font-size:12px;color:var(--dsw-alias-label-secondary,#9097a4)}.tm_select_wrap{position:relative;display:inline-flex;max-width:100%}.tm_select_wrap:after{content:'';position:absolute;right:12px;top:50%;width:7px;height:7px;border-right:2px solid currentColor;border-bottom:2px solid currentColor;transform:translateY(-70%) rotate(45deg);pointer-events:none;opacity:.9}.tm_preset_select,.tm_btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.28));border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.08));color:inherit;padding:7px 10px;font:inherit;font-size:12px}.tm_preset_select{min-width:min(360px,100%);cursor:pointer;padding-right:34px}.tm_preset_select option{background:var(--dsw-alias-bg-base,#17191d);color:inherit}.tm_btn{cursor:pointer}.tm_btn.primary{background:#5367e8;border-color:#5367e8;color:#fff}.tm_btn:disabled{opacity:.5;cursor:not-allowed}",
|
|
17
17
|
".tm_panel{border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.24));border-radius:12px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.06));overflow:hidden}",
|
|
18
18
|
".tm_panel_head{padding:13px 14px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.2));display:flex;justify-content:space-between;gap:12px;align-items:center;flex-wrap:wrap}.tm_panel_head b{font-size:14px}",
|
|
19
19
|
".tm_tools{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:0}.tm_tool{display:flex;gap:10px;align-items:flex-start;padding:11px 14px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.13))}.tm_tool_name{font:600 12px ui-monospace,SFMono-Regular,Consolas,monospace}.tm_tool_desc{font-size:11px;color:var(--dsw-alias-label-secondary,#9097a4);line-height:1.4;margin-top:3px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}",
|
|
20
20
|
".tm_row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.tm_input{box-sizing:border-box;min-width:130px;flex:1;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.3));border-radius:7px;background:var(--dsw-alias-bg-base,#17191d);color:inherit;padding:7px 9px;font:inherit;font-size:12px}.tm_code{font:11px ui-monospace,SFMono-Regular,Consolas,monospace;color:#9da8ff}.tm_notice{padding:12px;border-radius:9px;background:color-mix(in srgb,#f59e0b 12%,transparent);font-size:12px}.tm_error{padding:12px;border-radius:9px;background:color-mix(in srgb,#ef4444 12%,transparent);color:#fca5a5;font-size:12px}",
|
|
21
21
|
".tm_filters{display:flex;gap:6px;flex-wrap:wrap;align-items:center}.tm_chip{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.28));border-radius:999px;background:transparent;color:inherit;padding:4px 9px;cursor:pointer;font:inherit;font-size:11px}.tm_chip.active{border-color:#7c8cff;background:color-mix(in srgb,#7c8cff 16%,transparent)}",
|
|
22
22
|
".tm_stats{display:grid;grid-template-columns:repeat(5,minmax(100px,1fr));gap:8px;padding:10px 14px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.13))}.tm_stat{min-width:0;padding:9px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.07));border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.15))}.tm_stat_value{font-size:18px;font-weight:700;line-height:1.2}.tm_stat_label{margin-top:3px;font-size:11px;color:var(--dsw-alias-label-secondary,#9097a4)}@media(max-width:720px){.tm_stats{grid-template-columns:repeat(2,minmax(100px,1fr))}}",
|
|
23
|
-
".tm_badge{display:inline-block;margin-left:6px;padding:1px
|
|
23
|
+
".tm_badge{display:inline-block;margin-left:6px;padding:2px 7px;border:1px solid transparent;border-radius:999px;font-size:10px;font-weight:700;line-height:1.35;letter-spacing:.02em;vertical-align:middle;color:#fff}.tm_badge.off{background:#b42318;border-color:#d92d20;color:#fff}.tm_badge.cold{background:#4338ca;border-color:#6366f1;color:#fff}.tm_badge.live{background:#15803d;border-color:#22c55e;color:#fff}",
|
|
24
24
|
".tm_group{border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.13))}.tm_group:last-child{border-bottom:0}",
|
|
25
25
|
".tm_group_bar{display:flex;align-items:center;gap:8px;padding:11px 14px}",
|
|
26
26
|
".tm_chevron{appearance:none;border:0;background:transparent;color:inherit;width:28px;height:28px;border-radius:7px;cursor:pointer;font:16px/1 inherit;flex:0 0 auto}.tm_chevron:hover{background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.1))}",
|
|
@@ -32,9 +32,9 @@ window.__ModuleLoader__.load({
|
|
|
32
32
|
".tm_modal{position:fixed;inset:0;z-index:10000;display:flex;align-items:center;justify-content:center;padding:24px}",
|
|
33
33
|
".tm_modal_mask{position:absolute;inset:0;background:rgba(0,0,0,.55)}",
|
|
34
34
|
".tm_modal_card{position:relative;z-index:1;width:min(720px,100%);max-height:min(84vh,760px);display:flex;flex-direction:column;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.28));border-radius:14px;background:var(--dsw-alias-bg-base,#17191d);box-shadow:0 24px 80px rgba(0,0,0,.45)}",
|
|
35
|
-
".tm_modal_head{padding:16px 16px 12px;display:flex;align-items:flex-start;justify-content:space-between;gap:12px}.tm_modal_head h3{margin:0;font-size:16px}",
|
|
36
|
-
".tm_modal_body{padding:0 16px 12px;display:flex;flex-direction:column;gap:10px;min-height:0;flex:1;overflow:auto}",
|
|
37
|
-
".tm_modal_foot{padding:12px 16px 16px;display:flex;justify-content:flex-end;gap:8px;border-top:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18))}",
|
|
35
|
+
".tm_modal_head{padding:16px 16px 12px;display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex:0 0 auto}.tm_modal_head h3{margin:0;font-size:16px}",
|
|
36
|
+
".tm_modal_body{padding:0 16px 12px;display:flex;flex-direction:column;gap:10px;min-height:0;flex:1 1 auto;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable}",
|
|
37
|
+
".tm_modal_foot{padding:12px 16px 16px;display:flex;justify-content:flex-end;gap:8px;border-top:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18));flex:0 0 auto}.tm_confirm_card{width:min(460px,100%)}.tm_timeout_field{display:flex;align-items:center;gap:8px}.tm_timeout_field .tm_input{max-width:120px;flex:0 0 120px}.tm_preview_body{padding-right:10px}.tm_preview_panel{flex:0 0 auto;overflow:visible}.tm_preview_meta{min-width:0;flex:1}.tm_preview_desc{margin-top:4px;white-space:normal;overflow-wrap:anywhere;word-break:break-word;color:var(--dsw-alias-label-secondary,#9097a4);font-size:12px;line-height:1.55}",
|
|
38
38
|
".tm_picker{min-height:180px;max-height:min(46vh,420px);overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18));border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.06))}",
|
|
39
39
|
".tm_pick{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.1))}.tm_pick:last-child{border-bottom:0}",
|
|
40
40
|
].join("");
|
|
@@ -97,13 +97,37 @@ window.__ModuleLoader__.load({
|
|
|
97
97
|
function matchingTools(tools, patterns) {
|
|
98
98
|
return (tools || []).filter((tool) => (patterns || []).some((pattern) => matchesPattern(tool.name, pattern)));
|
|
99
99
|
}
|
|
100
|
-
function groupedNames(preset) {
|
|
100
|
+
function groupedNames(preset, exceptKey) {
|
|
101
101
|
const names = new Set();
|
|
102
102
|
for (const group of preset.policy.groups || []) {
|
|
103
|
+
if (exceptKey && group._key === exceptKey) continue;
|
|
103
104
|
for (const tool of matchingTools(preset.tools, group.patterns)) names.add(tool.name);
|
|
104
105
|
}
|
|
105
106
|
return names;
|
|
106
107
|
}
|
|
108
|
+
function eligibleGroupTools(preset, exceptKey) {
|
|
109
|
+
const disabled = new Set(preset.policy.disabled || []);
|
|
110
|
+
const occupied = groupedNames(preset, exceptKey);
|
|
111
|
+
return (preset.tools || []).filter((tool) => !disabled.has(tool.name) && !occupied.has(tool.name));
|
|
112
|
+
}
|
|
113
|
+
function groupDraftIssues(preset) {
|
|
114
|
+
const disabled = new Set(preset.policy.disabled || []);
|
|
115
|
+
const owners = new Map();
|
|
116
|
+
const empty = [];
|
|
117
|
+
const disabledMembers = [];
|
|
118
|
+
for (const group of preset.policy.groups || []) {
|
|
119
|
+
const members = matchingTools(preset.tools, group.patterns);
|
|
120
|
+
if (!members.some((tool) => !disabled.has(tool.name))) empty.push(group.name || "未命名分组");
|
|
121
|
+
for (const tool of members) {
|
|
122
|
+
if (disabled.has(tool.name)) disabledMembers.push({ tool: tool.name, group: group.name || "未命名分组" });
|
|
123
|
+
const groups = owners.get(tool.name) || [];
|
|
124
|
+
groups.push(group.name || "未命名分组");
|
|
125
|
+
owners.set(tool.name, groups);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const duplicates = [...owners].filter(([, groups]) => groups.length > 1);
|
|
129
|
+
return { empty, disabledMembers, duplicates };
|
|
130
|
+
}
|
|
107
131
|
function catalogStats(preset) {
|
|
108
132
|
const disabled = new Set(preset.policy.disabled || []);
|
|
109
133
|
const grouped = groupedNames(preset);
|
|
@@ -128,6 +152,47 @@ window.__ModuleLoader__.load({
|
|
|
128
152
|
return name;
|
|
129
153
|
}
|
|
130
154
|
|
|
155
|
+
function defaultAutoGroupPrompt(tools, otherGroupNames) {
|
|
156
|
+
const list = (tools || []).map((tool) => ({
|
|
157
|
+
name: String(tool.name || "").slice(0, 160),
|
|
158
|
+
description: String(tool.description || "").trim().replace(/\s+/g, " ").slice(0, 600),
|
|
159
|
+
}));
|
|
160
|
+
const forbidden = (otherGroupNames && otherGroupNames.length > 0) ? otherGroupNames : ["(无)"];
|
|
161
|
+
return [
|
|
162
|
+
"请把以下尚未分组的工具按共同能力和使用场景聚类成多个按需工具组,并为每组生成中文名称和描述。",
|
|
163
|
+
"要求:",
|
|
164
|
+
"1. 每个工具最多出现在一个组;tools 必须使用输入中的精确工具名。",
|
|
165
|
+
"2. 不要为了覆盖全部工具而制造不合理分组;不适合归组的工具放入 ungrouped。",
|
|
166
|
+
"3. 避免只有一个工具的碎片组,也避免含义模糊、规模过大的杂项组;组数由工具语义决定。",
|
|
167
|
+
"4. 每组名称使用简洁自然的中文,建议 2 到 10 个汉字;描述用一句简洁中文概括用途。",
|
|
168
|
+
"5. 新组名称互不重复,且不得与这些现有分组重名:" + forbidden.join("、") + "。",
|
|
169
|
+
"6. 最多生成 32 个组;名称不超过 40 个字符,描述不超过 240 个字符。",
|
|
170
|
+
"7. 只输出一个 JSON 对象,不要输出 Markdown、解释或额外字段。",
|
|
171
|
+
'格式:{"groups":[{"name":"...","description":"...","tools":["exact_name"]}],"ungrouped":["exact_name"]}',
|
|
172
|
+
"候选工具:",
|
|
173
|
+
JSON.stringify(list, null, 2),
|
|
174
|
+
].join("\n");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function defaultGroupSuggestionPrompt(tools, otherGroupNames) {
|
|
178
|
+
const list = (tools || []).map((tool) => ({
|
|
179
|
+
name: String(tool.name || "").slice(0, 160),
|
|
180
|
+
description: String(tool.description || "").trim().replace(/\s+/g, " ").slice(0, 600),
|
|
181
|
+
}));
|
|
182
|
+
const forbidden = (otherGroupNames && otherGroupNames.length > 0) ? otherGroupNames : ["(无)"];
|
|
183
|
+
return [
|
|
184
|
+
"请根据以下已选择的工具,为一个按需工具组生成名称和描述。",
|
|
185
|
+
"要求:",
|
|
186
|
+
"1. 名称使用简洁自然的中文,概括共同用途,建议 2 到 10 个汉字。",
|
|
187
|
+
"2. 描述使用一句简洁中文,说明该组适合完成什么任务,不要逐个罗列工具。",
|
|
188
|
+
"3. 名称不得与这些其他分组重名:" + forbidden.join("、") + "。",
|
|
189
|
+
"4. 名称不超过 40 个字符,描述不超过 240 个字符。",
|
|
190
|
+
'5. 只输出一个 JSON 对象,不要输出 Markdown、解释或额外字段。格式:{"name":"...","description":"..."}',
|
|
191
|
+
"已选择工具:",
|
|
192
|
+
JSON.stringify(list, null, 2),
|
|
193
|
+
].join("\n");
|
|
194
|
+
}
|
|
195
|
+
|
|
131
196
|
function ToolManagerSection() {
|
|
132
197
|
const [snapshot, setSnapshot] = react.useState(null);
|
|
133
198
|
const [draft, setDraft] = react.useState(null);
|
|
@@ -142,6 +207,9 @@ window.__ModuleLoader__.load({
|
|
|
142
207
|
const [autoGroupError, setAutoGroupError] = react.useState("");
|
|
143
208
|
const [autoPreview, setAutoPreview] = react.useState(null);
|
|
144
209
|
const [expanded, setExpanded] = react.useState({});
|
|
210
|
+
const [aiConfirm, setAiConfirm] = react.useState(null);
|
|
211
|
+
const [suggestionTimeoutSeconds, setSuggestionTimeoutSeconds] = react.useState("60");
|
|
212
|
+
const [autoGroupTimeoutSeconds, setAutoGroupTimeoutSeconds] = react.useState("120");
|
|
145
213
|
|
|
146
214
|
const load = react.useCallback(() => {
|
|
147
215
|
setBusy(true); setError("");
|
|
@@ -163,13 +231,17 @@ window.__ModuleLoader__.load({
|
|
|
163
231
|
return () => window.removeEventListener("beforeunload", onBeforeUnload);
|
|
164
232
|
}, [dirty]);
|
|
165
233
|
react.useEffect(() => {
|
|
166
|
-
if (!modal) return undefined;
|
|
234
|
+
if (!modal && !aiConfirm && !autoPreview) return undefined;
|
|
167
235
|
function onKeyDown(event) {
|
|
168
|
-
if (event.key === "Escape")
|
|
236
|
+
if (event.key === "Escape") {
|
|
237
|
+
if (aiConfirm) setAiConfirm(null);
|
|
238
|
+
else if (autoPreview) setAutoPreview(null);
|
|
239
|
+
else if (modal) setModal(null);
|
|
240
|
+
}
|
|
169
241
|
}
|
|
170
242
|
window.addEventListener("keydown", onKeyDown);
|
|
171
243
|
return () => window.removeEventListener("keydown", onKeyDown);
|
|
172
|
-
}, [modal]);
|
|
244
|
+
}, [modal, aiConfirm, autoPreview]);
|
|
173
245
|
|
|
174
246
|
if (!draft) return h("div", { className: "tm_root" }, error ? h("div", { className: "tm_error" }, error) : h("div", { className: "tm_muted" }, "正在读取工具目录…"));
|
|
175
247
|
const preset = draft.presets.find((item) => item.id === active) || draft.presets[0];
|
|
@@ -207,12 +279,13 @@ window.__ModuleLoader__.load({
|
|
|
207
279
|
}
|
|
208
280
|
|
|
209
281
|
function openEdit(group) {
|
|
282
|
+
const members = matchingTools(preset.tools, group.patterns || []).map((tool) => tool.name);
|
|
210
283
|
setModal({
|
|
211
284
|
mode: "edit",
|
|
212
285
|
key: group._key,
|
|
213
286
|
name: group.name || "",
|
|
214
287
|
description: group.description || "",
|
|
215
|
-
patterns:
|
|
288
|
+
patterns: members,
|
|
216
289
|
query: "",
|
|
217
290
|
generating: false,
|
|
218
291
|
generateError: "",
|
|
@@ -231,6 +304,10 @@ window.__ModuleLoader__.load({
|
|
|
231
304
|
setModal((current) => current ? { ...current, ...patch } : current);
|
|
232
305
|
}
|
|
233
306
|
|
|
307
|
+
function patchAiConfirm(patch) {
|
|
308
|
+
setAiConfirm((current) => current ? { ...current, ...patch } : current);
|
|
309
|
+
}
|
|
310
|
+
|
|
234
311
|
function generateGroupDetails() {
|
|
235
312
|
if (!modal || modal.generating || !(modal.patterns || []).length) return;
|
|
236
313
|
const key = modal.key;
|
|
@@ -238,23 +315,40 @@ window.__ModuleLoader__.load({
|
|
|
238
315
|
.filter((group) => group._key !== key)
|
|
239
316
|
.map((group) => group.name)
|
|
240
317
|
.filter(Boolean);
|
|
241
|
-
const
|
|
318
|
+
const eligible = new Set(eligibleGroupTools(preset, key).map((tool) => tool.name));
|
|
319
|
+
const selectedTools = matchingTools(preset.tools, modal.patterns || [])
|
|
320
|
+
.filter((tool) => eligible.has(tool.name));
|
|
321
|
+
const toolNames = selectedTools.map((tool) => tool.name);
|
|
242
322
|
if (!toolNames.length) {
|
|
243
323
|
patchModal({ generateError: "所选模式当前没有匹配到工具,请重新勾选。" });
|
|
244
324
|
return;
|
|
245
325
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
326
|
+
const initialPrompt = defaultGroupSuggestionPrompt(selectedTools, otherGroupNames);
|
|
327
|
+
setAiConfirm({
|
|
328
|
+
kind: "suggest",
|
|
329
|
+
title: "确认自动生成名称和描述",
|
|
330
|
+
message: "将所选工具的名称和描述发送给当前默认模型,并产生一次模型请求。",
|
|
331
|
+
timeoutSeconds: suggestionTimeoutSeconds,
|
|
332
|
+
prompt: initialPrompt,
|
|
333
|
+
promptCustom: false,
|
|
334
|
+
showPrompt: false,
|
|
335
|
+
error: "",
|
|
336
|
+
run: (timeoutMs, _tools, prompt) => {
|
|
337
|
+
setSuggestionTimeoutSeconds(String(timeoutMs / 1000));
|
|
338
|
+
patchModal({ generating: true, generateError: "" });
|
|
339
|
+
api("/suggest-group", {
|
|
340
|
+
method: "POST",
|
|
341
|
+
body: JSON.stringify({ presetId: preset.id, toolNames, otherGroupNames, timeoutMs, prompt }),
|
|
342
|
+
}).then((suggestion) => {
|
|
343
|
+
setModal((current) => current && current.key === key
|
|
344
|
+
? { ...current, name: suggestion.name || current.name, description: suggestion.description || current.description, generating: false, generateError: "" }
|
|
345
|
+
: current);
|
|
346
|
+
}).catch((e) => {
|
|
347
|
+
setModal((current) => current && current.key === key
|
|
348
|
+
? { ...current, generating: false, generateError: String(e.message || e) }
|
|
349
|
+
: current);
|
|
350
|
+
});
|
|
351
|
+
},
|
|
258
352
|
});
|
|
259
353
|
}
|
|
260
354
|
|
|
@@ -262,8 +356,9 @@ window.__ModuleLoader__.load({
|
|
|
262
356
|
if (!modal) return;
|
|
263
357
|
const name = String(modal.name || "").trim().replace(/\s+/g, " ");
|
|
264
358
|
const description = String(modal.description || "").trim();
|
|
265
|
-
const
|
|
266
|
-
|
|
359
|
+
const eligible = new Set(eligibleGroupTools(preset, modal.key).map((tool) => tool.name));
|
|
360
|
+
const patterns = [...new Set(modal.patterns || [])].filter((toolName) => eligible.has(toolName));
|
|
361
|
+
if (!name || patterns.length === 0) return;
|
|
267
362
|
const created = modal.mode === "create";
|
|
268
363
|
const key = modal.key;
|
|
269
364
|
mutatePreset((target) => {
|
|
@@ -284,8 +379,8 @@ window.__ModuleLoader__.load({
|
|
|
284
379
|
if (created) setExpanded((current) => ({ ...current, [key]: true }));
|
|
285
380
|
}
|
|
286
381
|
|
|
287
|
-
function autoGroupSignature(toolNames) {
|
|
288
|
-
return preset.id + "\n" + [...toolNames].sort().join("\n");
|
|
382
|
+
function autoGroupSignature(toolNames, otherGroupNames = []) {
|
|
383
|
+
return preset.id + "\n" + [...toolNames].sort().join("\n") + "\n---\n" + [...otherGroupNames].sort().join("\n");
|
|
289
384
|
}
|
|
290
385
|
|
|
291
386
|
function startAutoGroup() {
|
|
@@ -297,29 +392,77 @@ window.__ModuleLoader__.load({
|
|
|
297
392
|
setAutoGroupError("当前没有未分组且未关闭的工具。");
|
|
298
393
|
return;
|
|
299
394
|
}
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
395
|
+
const allCandidateNames = candidates.map((tool) => tool.name);
|
|
396
|
+
const otherGroupNames = (preset.policy.groups || []).map((group) => group.name).filter(Boolean);
|
|
397
|
+
const initialPrompt = defaultAutoGroupPrompt(candidates, otherGroupNames);
|
|
398
|
+
setAiConfirm({
|
|
399
|
+
kind: "auto-group",
|
|
400
|
+
title: "确认自动分组",
|
|
401
|
+
message: "筛选并勾选需要分组的工具,发送给当前默认模型进行聚类。",
|
|
402
|
+
timeoutSeconds: autoGroupTimeoutSeconds,
|
|
403
|
+
query: "",
|
|
404
|
+
selected: allCandidateNames,
|
|
405
|
+
prompt: initialPrompt,
|
|
406
|
+
promptCustom: false,
|
|
407
|
+
showPrompt: false,
|
|
408
|
+
error: "",
|
|
409
|
+
run: (timeoutMs, selectedToolNames, prompt) => {
|
|
410
|
+
setAutoGroupTimeoutSeconds(String(timeoutMs / 1000));
|
|
411
|
+
setAutoGrouping(true); setAutoGroupError(""); setAutoPreview(null);
|
|
412
|
+
const signature = autoGroupSignature(selectedToolNames, otherGroupNames);
|
|
413
|
+
api("/auto-group", {
|
|
414
|
+
method: "POST",
|
|
415
|
+
body: JSON.stringify({ presetId: preset.id, toolNames: selectedToolNames, otherGroupNames, timeoutMs, prompt }),
|
|
416
|
+
}).then((result) => {
|
|
417
|
+
setAutoPreview({ presetId: preset.id, signature, selectedTools: selectedToolNames, groups: result.groups || [], ungrouped: result.ungrouped || [] });
|
|
418
|
+
}).catch((e) => setAutoGroupError(String(e.message || e))).finally(() => setAutoGrouping(false));
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function confirmAiRequest() {
|
|
424
|
+
if (!aiConfirm) return;
|
|
425
|
+
const seconds = Number(aiConfirm.timeoutSeconds);
|
|
426
|
+
if (!Number.isInteger(seconds) || seconds < 5 || seconds > 600) {
|
|
427
|
+
patchAiConfirm({ error: "超时时间必须是 5 到 600 之间的整数秒。" });
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const selected = aiConfirm.selected || [];
|
|
431
|
+
let prompt = String(aiConfirm.prompt || "").trim();
|
|
432
|
+
if (!prompt) {
|
|
433
|
+
patchAiConfirm({ error: "提示词不能为空,请输入有效提示词或点击重置为默认。" });
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (prompt.length > 32000) {
|
|
437
|
+
patchAiConfirm({ error: "提示词不能超过 32000 个字符。" });
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (aiConfirm.kind === "auto-group") {
|
|
441
|
+
if (selected.length === 0) {
|
|
442
|
+
patchAiConfirm({ error: "请至少勾选一个工具进行分组。" });
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (selected.length > 120) {
|
|
446
|
+
patchAiConfirm({ error: "一次最多勾选 120 个工具进行分组。" });
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
const run = aiConfirm.run;
|
|
451
|
+
setAiConfirm(null);
|
|
452
|
+
run(seconds * 1000, selected, prompt);
|
|
313
453
|
}
|
|
314
454
|
|
|
315
455
|
function applyAutoGroups() {
|
|
316
456
|
if (!autoPreview || autoPreview.presetId !== preset.id) return;
|
|
317
457
|
const disabledNames = new Set(preset.policy.disabled || []);
|
|
318
458
|
const alreadyGrouped = groupedNames(preset);
|
|
319
|
-
const
|
|
320
|
-
|
|
459
|
+
const allPresetToolNames = new Set((preset.tools || []).map((tool) => tool.name));
|
|
460
|
+
const targetTools = autoPreview.selectedTools || (preset.tools || []).filter((tool) => !disabledNames.has(tool.name) && !alreadyGrouped.has(tool.name)).map((tool) => tool.name);
|
|
461
|
+
const validSelected = targetTools.filter((name) => allPresetToolNames.has(name) && !disabledNames.has(name) && !alreadyGrouped.has(name));
|
|
462
|
+
const currentOtherGroupNames = (preset.policy.groups || []).map((group) => group.name).filter(Boolean);
|
|
463
|
+
if (autoPreview.signature !== autoGroupSignature(validSelected, currentOtherGroupNames)) {
|
|
321
464
|
setAutoPreview(null);
|
|
322
|
-
setAutoGroupError("
|
|
465
|
+
setAutoGroupError("所选工具或分组草稿已经变化,请重新自动分组。");
|
|
323
466
|
return;
|
|
324
467
|
}
|
|
325
468
|
const addedKeys = [];
|
|
@@ -346,6 +489,27 @@ window.__ModuleLoader__.load({
|
|
|
346
489
|
}
|
|
347
490
|
|
|
348
491
|
function save() {
|
|
492
|
+
for (const item of draft.presets || []) {
|
|
493
|
+
if (item.broken) continue;
|
|
494
|
+
const issues = groupDraftIssues(item);
|
|
495
|
+
if (issues.disabledMembers.length) {
|
|
496
|
+
const issue = issues.disabledMembers[0];
|
|
497
|
+
setError("Preset “" + item.id + "”中的已关闭工具“" + issue.tool + "”不能加入分组“" + issue.group + "”。请从分组移除或重新开启该工具。");
|
|
498
|
+
setMessage("");
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (issues.duplicates.length) {
|
|
502
|
+
const issue = issues.duplicates[0];
|
|
503
|
+
setError("Preset “" + item.id + "”中的工具“" + issue[0] + "”重复属于分组:" + issue[1].join("、") + "。每个工具只能属于一个分组。");
|
|
504
|
+
setMessage("");
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (issues.empty.length) {
|
|
508
|
+
setError("Preset “" + item.id + "”中的分组“" + issues.empty[0] + "”没有可用工具。请为它选择至少一个工具,或删除该分组后再保存。");
|
|
509
|
+
setMessage("");
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
349
513
|
const settings = settingsPayload(draft);
|
|
350
514
|
setBusy(true); setError(""); setMessage("");
|
|
351
515
|
api("/save", { method: "POST", body: JSON.stringify({ expectedRevision: snapshot.revision, settings }) })
|
|
@@ -382,10 +546,36 @@ window.__ModuleLoader__.load({
|
|
|
382
546
|
const orphans = (preset.policy.disabled || []).filter((name) => !(preset.tools || []).some((tool) => tool.name === name));
|
|
383
547
|
const modalNeedle = String(modal && modal.query || "").trim().toLowerCase();
|
|
384
548
|
const modalSelected = new Set(modal ? modal.patterns || [] : []);
|
|
385
|
-
const
|
|
549
|
+
const modalEligibleTools = modal ? eligibleGroupTools(preset, modal.key) : [];
|
|
550
|
+
const modalEligibleNames = new Set(modalEligibleTools.map((tool) => tool.name));
|
|
551
|
+
const pickerTools = modal ? (preset.tools || []).filter((tool) =>
|
|
552
|
+
(modalEligibleNames.has(tool.name) || modalSelected.has(tool.name)) && matchesQuery(tool, modalNeedle)) : [];
|
|
386
553
|
const visibleSelected = pickerTools.filter((tool) => modalSelected.has(tool.name)).map((tool) => tool.name);
|
|
387
|
-
const
|
|
554
|
+
const modalMatchedTools = modal ? matchingTools(preset.tools, modal.patterns || []).filter((tool) => modalEligibleNames.has(tool.name)) : [];
|
|
555
|
+
const modalInvalidSelected = modal ? [...modalSelected].filter((name) => !modalEligibleNames.has(name)) : [];
|
|
556
|
+
const canConfirm = !!(modal && String(modal.name || "").trim() && modalMatchedTools.length > 0 && modalInvalidSelected.length === 0);
|
|
388
557
|
const listedGroups = showGroups ? visibleGroups : [];
|
|
558
|
+
const aiIsAutoGroup = !!(aiConfirm && aiConfirm.kind === "auto-group");
|
|
559
|
+
const aiNeedle = String(aiConfirm && aiConfirm.query || "").trim().toLowerCase();
|
|
560
|
+
const aiCandidates = (preset.tools || []).filter((tool) => !disabled.has(tool.name) && !grouped.has(tool.name));
|
|
561
|
+
const aiVisibleCandidates = aiIsAutoGroup ? aiCandidates.filter((tool) => matchesQuery(tool, aiNeedle)) : [];
|
|
562
|
+
const aiSelected = new Set(aiConfirm && aiConfirm.selected ? aiConfirm.selected : []);
|
|
563
|
+
const aiVisibleSelected = aiVisibleCandidates.filter((tool) => aiSelected.has(tool.name)).map((tool) => tool.name);
|
|
564
|
+
const aiPromptTrimmed = String(aiConfirm && aiConfirm.prompt || "").trim();
|
|
565
|
+
const aiPromptTooLong = String(aiConfirm && aiConfirm.prompt || "").length > 32000;
|
|
566
|
+
const aiCanConfirm = aiPromptTrimmed.length > 0 && !aiPromptTooLong && (!aiIsAutoGroup || (aiSelected.size > 0 && aiSelected.size <= 120));
|
|
567
|
+
|
|
568
|
+
function updateAutoGroupSelection(nextSelectedNames) {
|
|
569
|
+
const nextSelected = [...new Set(nextSelectedNames)];
|
|
570
|
+
const patch = { selected: nextSelected, error: "" };
|
|
571
|
+
if (aiConfirm && !aiConfirm.promptCustom) {
|
|
572
|
+
const nextSelectedSet = new Set(nextSelected);
|
|
573
|
+
const nextTools = (preset.tools || []).filter((t) => nextSelectedSet.has(t.name));
|
|
574
|
+
const otherGroupNames = (preset.policy.groups || []).map((g) => g.name).filter(Boolean);
|
|
575
|
+
patch.prompt = defaultAutoGroupPrompt(nextTools, otherGroupNames);
|
|
576
|
+
}
|
|
577
|
+
patchAiConfirm(patch);
|
|
578
|
+
}
|
|
389
579
|
|
|
390
580
|
function renderGroup(group) {
|
|
391
581
|
const key = group._key;
|
|
@@ -408,7 +598,7 @@ window.__ModuleLoader__.load({
|
|
|
408
598
|
h("div", { className: "tm_tool_name" }, tool.name, disabled.has(tool.name) ? h("span", { className: "tm_badge off" }, "关闭") : null),
|
|
409
599
|
h("div", { className: "tm_tool_desc", title: tool.description }, tool.description),
|
|
410
600
|
))
|
|
411
|
-
: h("div", { className: "
|
|
601
|
+
: h("div", { className: "tm_error" }, "无效空组:请编辑并选择至少一个可用工具,或删除该组。"),
|
|
412
602
|
) : null,
|
|
413
603
|
);
|
|
414
604
|
}
|
|
@@ -426,6 +616,166 @@ window.__ModuleLoader__.load({
|
|
|
426
616
|
);
|
|
427
617
|
}
|
|
428
618
|
|
|
619
|
+
const aiConfirmDialog = aiConfirm && typeof document !== "undefined" ? reactDom.createPortal(
|
|
620
|
+
h("div", { className: "tm_modal", role: "dialog", "aria-modal": "true", "aria-label": aiConfirm.title },
|
|
621
|
+
h("div", { className: "tm_modal_mask", onMouseDown: () => setAiConfirm(null) }),
|
|
622
|
+
h("div", { className: "tm_modal_card" },
|
|
623
|
+
h("div", { className: "tm_modal_head" },
|
|
624
|
+
h("div", null, h("h3", null, aiConfirm.title), h("div", { className: "tm_muted" }, aiConfirm.message)),
|
|
625
|
+
h("button", { className: "tm_btn", onClick: () => setAiConfirm(null) }, "关闭"),
|
|
626
|
+
),
|
|
627
|
+
h("div", { className: "tm_modal_body" },
|
|
628
|
+
aiIsAutoGroup ? [
|
|
629
|
+
h("div", { className: "tm_row", key: "row" },
|
|
630
|
+
h("input", {
|
|
631
|
+
className: "tm_input",
|
|
632
|
+
value: aiConfirm.query || "",
|
|
633
|
+
placeholder: "筛选工具名或描述",
|
|
634
|
+
onChange: (e) => patchAiConfirm({ query: e.target.value }),
|
|
635
|
+
}),
|
|
636
|
+
h("button", {
|
|
637
|
+
className: "tm_btn",
|
|
638
|
+
disabled: aiVisibleCandidates.length === 0 || aiVisibleCandidates.every((tool) => aiSelected.has(tool.name)),
|
|
639
|
+
onClick: () => updateAutoGroupSelection([...(aiConfirm.selected || []), ...aiVisibleCandidates.map((tool) => tool.name)]),
|
|
640
|
+
}, "全选当前筛选"),
|
|
641
|
+
h("button", {
|
|
642
|
+
className: "tm_btn",
|
|
643
|
+
disabled: aiVisibleSelected.length === 0,
|
|
644
|
+
onClick: () => updateAutoGroupSelection((aiConfirm.selected || []).filter((name) => !aiVisibleSelected.includes(name))),
|
|
645
|
+
}, "清除当前筛选"),
|
|
646
|
+
),
|
|
647
|
+
aiSelected.size === 0
|
|
648
|
+
? h("div", { className: "tm_error", key: "status" }, "请至少勾选一个工具进行分组。")
|
|
649
|
+
: (aiSelected.size > 120
|
|
650
|
+
? h("div", { className: "tm_error", key: "status" }, "自动分组一次最多处理 120 个工具,当前已勾选 " + aiSelected.size + " 个,请减少勾选。")
|
|
651
|
+
: h("div", { className: "tm_muted", key: "status" }, "已勾选 " + aiSelected.size + " / " + aiCandidates.length + " 个候选工具。自动分组会调用当前默认模型,结果仍可手动修改。")),
|
|
652
|
+
aiVisibleCandidates.length
|
|
653
|
+
? h("div", { className: "tm_picker", key: "picker" }, aiVisibleCandidates.map((tool) => h("label", { className: "tm_pick", key: tool.name },
|
|
654
|
+
h("input", {
|
|
655
|
+
type: "checkbox",
|
|
656
|
+
checked: aiSelected.has(tool.name),
|
|
657
|
+
onChange: (e) => {
|
|
658
|
+
const next = new Set(aiConfirm.selected || []);
|
|
659
|
+
if (e.target.checked) next.add(tool.name); else next.delete(tool.name);
|
|
660
|
+
updateAutoGroupSelection([...next]);
|
|
661
|
+
},
|
|
662
|
+
}),
|
|
663
|
+
h("span", null,
|
|
664
|
+
h("div", { className: "tm_tool_name" }, tool.name),
|
|
665
|
+
h("div", { className: "tm_tool_desc", title: tool.description }, tool.description),
|
|
666
|
+
),
|
|
667
|
+
)))
|
|
668
|
+
: h("div", { className: "tm_muted", key: "empty", style: { padding: "12px" } }, aiCandidates.length ? "没有符合筛选的工具。" : "当前没有可分组的工具。"),
|
|
669
|
+
] : null,
|
|
670
|
+
h("div", {
|
|
671
|
+
style: {
|
|
672
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, .2))",
|
|
673
|
+
borderRadius: "8px",
|
|
674
|
+
padding: "10px 12px",
|
|
675
|
+
background: "var(--dsw-alias-bg-layer-1, rgba(128, 128, 128, .04))",
|
|
676
|
+
},
|
|
677
|
+
key: "promptSection",
|
|
678
|
+
},
|
|
679
|
+
h("div", {
|
|
680
|
+
style: {
|
|
681
|
+
display: "flex",
|
|
682
|
+
alignItems: "center",
|
|
683
|
+
justifyContent: "space-between",
|
|
684
|
+
gap: "8px",
|
|
685
|
+
flexWrap: "wrap",
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: "6px" } },
|
|
689
|
+
h("button", {
|
|
690
|
+
type: "button",
|
|
691
|
+
className: "tm_btn",
|
|
692
|
+
style: { fontSize: "11px", padding: "4px 8px" },
|
|
693
|
+
onClick: () => patchAiConfirm({ showPrompt: !aiConfirm.showPrompt }),
|
|
694
|
+
}, aiConfirm.showPrompt ? "▾ 收起提示词" : "▸ 预览与编辑提示词"),
|
|
695
|
+
h("span", { className: "tm_muted" },
|
|
696
|
+
aiConfirm.promptCustom
|
|
697
|
+
? "已自定义(共 " + (aiConfirm.prompt || "").length + " 字符)"
|
|
698
|
+
: "默认提示词(共 " + (aiConfirm.prompt || "").length + " 字符)",
|
|
699
|
+
),
|
|
700
|
+
aiConfirm.promptCustom ? h("span", { className: "tm_badge cold" }, "已修改") : null,
|
|
701
|
+
),
|
|
702
|
+
aiConfirm.showPrompt ? h("button", {
|
|
703
|
+
type: "button",
|
|
704
|
+
className: "tm_btn",
|
|
705
|
+
style: { fontSize: "11px", padding: "4px 8px" },
|
|
706
|
+
disabled: !aiConfirm.promptCustom,
|
|
707
|
+
onClick: () => {
|
|
708
|
+
if (aiIsAutoGroup) {
|
|
709
|
+
const selectedTools = (preset.tools || []).filter((t) => aiSelected.has(t.name));
|
|
710
|
+
const otherGroupNames = (preset.policy.groups || []).map((g) => g.name).filter(Boolean);
|
|
711
|
+
patchAiConfirm({
|
|
712
|
+
prompt: defaultAutoGroupPrompt(selectedTools, otherGroupNames),
|
|
713
|
+
promptCustom: false,
|
|
714
|
+
error: "",
|
|
715
|
+
});
|
|
716
|
+
} else if (modal) {
|
|
717
|
+
const key = modal.key;
|
|
718
|
+
const otherGroupNames = (preset.policy.groups || [])
|
|
719
|
+
.filter((group) => group._key !== key)
|
|
720
|
+
.map((group) => group.name)
|
|
721
|
+
.filter(Boolean);
|
|
722
|
+
const eligible = new Set(eligibleGroupTools(preset, key).map((tool) => tool.name));
|
|
723
|
+
const selectedTools = matchingTools(preset.tools, modal.patterns || [])
|
|
724
|
+
.filter((tool) => eligible.has(tool.name));
|
|
725
|
+
patchAiConfirm({
|
|
726
|
+
prompt: defaultGroupSuggestionPrompt(selectedTools, otherGroupNames),
|
|
727
|
+
promptCustom: false,
|
|
728
|
+
error: "",
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
}, "重置为默认提示词") : null,
|
|
733
|
+
),
|
|
734
|
+
aiConfirm.showPrompt ? h("div", { style: { marginTop: "8px" } },
|
|
735
|
+
h("textarea", {
|
|
736
|
+
className: "tm_input",
|
|
737
|
+
style: {
|
|
738
|
+
width: "100%",
|
|
739
|
+
minHeight: "140px",
|
|
740
|
+
maxHeight: "280px",
|
|
741
|
+
resize: "vertical",
|
|
742
|
+
fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace",
|
|
743
|
+
fontSize: "11px",
|
|
744
|
+
lineHeight: "1.45",
|
|
745
|
+
whiteSpace: "pre-wrap",
|
|
746
|
+
},
|
|
747
|
+
value: aiConfirm.prompt || "",
|
|
748
|
+
placeholder: "提示词内容...",
|
|
749
|
+
onChange: (e) => patchAiConfirm({ prompt: e.target.value, promptCustom: true, error: "" }),
|
|
750
|
+
}),
|
|
751
|
+
!aiPromptTrimmed ? h("div", { className: "tm_error", style: { marginTop: "6px" } }, "提示词不能为空,请输入有效提示词或点击重置为默认。")
|
|
752
|
+
: (aiPromptTooLong ? h("div", { className: "tm_error", style: { marginTop: "6px" } }, "提示词不能超过 32000 个字符,当前共 " + (aiConfirm.prompt || "").length + " 个字符。") : null),
|
|
753
|
+
) : null,
|
|
754
|
+
),
|
|
755
|
+
h("label", { className: "tm_timeout_field" },
|
|
756
|
+
h("span", null, "超时时间"),
|
|
757
|
+
h("input", {
|
|
758
|
+
className: "tm_input",
|
|
759
|
+
type: "number",
|
|
760
|
+
min: 5,
|
|
761
|
+
max: 600,
|
|
762
|
+
step: 1,
|
|
763
|
+
value: aiConfirm.timeoutSeconds,
|
|
764
|
+
onChange: (event) => patchAiConfirm({ timeoutSeconds: event.target.value, error: "" }),
|
|
765
|
+
}),
|
|
766
|
+
h("span", { className: "tm_muted" }, "秒(5–600)"),
|
|
767
|
+
),
|
|
768
|
+
aiConfirm.error ? h("div", { className: "tm_error" }, aiConfirm.error) : null,
|
|
769
|
+
),
|
|
770
|
+
h("div", { className: "tm_modal_foot" },
|
|
771
|
+
h("button", { className: "tm_btn", onClick: () => setAiConfirm(null) }, "取消"),
|
|
772
|
+
h("button", { className: "tm_btn primary", disabled: !aiCanConfirm, onClick: confirmAiRequest }, "确认执行"),
|
|
773
|
+
),
|
|
774
|
+
),
|
|
775
|
+
),
|
|
776
|
+
document.body,
|
|
777
|
+
) : null;
|
|
778
|
+
|
|
429
779
|
const dialog = modal && typeof document !== "undefined" ? reactDom.createPortal(
|
|
430
780
|
h("div", { className: "tm_modal", role: "dialog", "aria-modal": "true", "aria-label": modal.mode === "create" ? "新建按需组" : "编辑按需组" },
|
|
431
781
|
h("div", { className: "tm_modal_mask", onMouseDown: () => setModal(null) }),
|
|
@@ -440,29 +790,36 @@ window.__ModuleLoader__.load({
|
|
|
440
790
|
h("div", { className: "tm_modal_body" },
|
|
441
791
|
h("div", { className: "tm_row" },
|
|
442
792
|
h("input", { className: "tm_input", value: modal.name, placeholder: "名称(模型用这个打开)", onChange: (e) => patchModal({ name: e.target.value, generateError: "" }) }),
|
|
443
|
-
h("button", { className: "tm_btn", disabled: modal.generating ||
|
|
793
|
+
h("button", { className: "tm_btn", disabled: modal.generating || modalMatchedTools.length === 0 || modalInvalidSelected.length > 0, onClick: generateGroupDetails }, modal.generating ? "生成中…" : "自动生成名称和描述"),
|
|
444
794
|
),
|
|
445
795
|
modal.generateError ? h("div", { className: "tm_error" }, modal.generateError) : null,
|
|
446
796
|
h("textarea", { className: "tm_input", style: { width: "100%", minHeight: "72px", resize: "vertical" }, value: modal.description, placeholder: "描述(可选)", onChange: (e) => patchModal({ description: e.target.value, generateError: "" }) }),
|
|
447
797
|
h("div", { className: "tm_row" },
|
|
448
798
|
h("input", { className: "tm_input", value: modal.query, placeholder: "筛选工具名或描述", onChange: (e) => patchModal({ query: e.target.value }) }),
|
|
449
|
-
h("button", { className: "tm_btn", disabled: pickerTools.
|
|
799
|
+
h("button", { className: "tm_btn", disabled: pickerTools.every((tool) => !modalEligibleNames.has(tool.name)), onClick: () => patchModal({ patterns: [...new Set([...(modal.patterns || []), ...pickerTools.filter((tool) => modalEligibleNames.has(tool.name)).map((tool) => tool.name)])], generateError: "" }) }, "全选当前筛选"),
|
|
450
800
|
h("button", { className: "tm_btn", disabled: visibleSelected.length === 0, onClick: () => patchModal({ patterns: (modal.patterns || []).filter((name) => !visibleSelected.includes(name)), generateError: "" }) }, "清除当前筛选"),
|
|
451
801
|
),
|
|
452
|
-
|
|
802
|
+
modalInvalidSelected.length
|
|
803
|
+
? h("div", { className: "tm_error" }, "以下工具已关闭或属于其他分组,不能加入当前组:" + modalInvalidSelected.join(", ") + "。请取消选择。")
|
|
804
|
+
: h("div", { className: modalMatchedTools.length ? "tm_muted" : "tm_error" }, modalMatchedTools.length
|
|
805
|
+
? "已选 " + modalMatchedTools.length + " 个工具。自动生成会调用当前默认模型,结果仍可手动修改。"
|
|
806
|
+
: "每个按需组至少需要一个未关闭且未被其他组占用的工具。"),
|
|
453
807
|
pickerTools.length
|
|
454
808
|
? h("div", { className: "tm_picker" }, pickerTools.map((tool) => h("label", { className: "tm_pick", key: tool.name },
|
|
455
809
|
h("input", {
|
|
456
810
|
type: "checkbox",
|
|
457
811
|
checked: modalSelected.has(tool.name),
|
|
812
|
+
disabled: !modalEligibleNames.has(tool.name) && !modalSelected.has(tool.name),
|
|
458
813
|
onChange: (e) => {
|
|
459
814
|
const next = new Set(modal.patterns || []);
|
|
460
|
-
if (e.target.checked) next.add(tool.name); else next.delete(tool.name);
|
|
815
|
+
if (e.target.checked && modalEligibleNames.has(tool.name)) next.add(tool.name); else next.delete(tool.name);
|
|
461
816
|
patchModal({ patterns: [...next], generateError: "" });
|
|
462
817
|
},
|
|
463
818
|
}),
|
|
464
819
|
h("span", null,
|
|
465
|
-
h("div", { className: "tm_tool_name" }, tool.name,
|
|
820
|
+
h("div", { className: "tm_tool_name" }, tool.name,
|
|
821
|
+
disabled.has(tool.name) ? h("span", { className: "tm_badge off" }, "已关闭")
|
|
822
|
+
: (!modalEligibleNames.has(tool.name) ? h("span", { className: "tm_badge off" }, "其他组") : null)),
|
|
466
823
|
h("div", { className: "tm_tool_desc", title: tool.description }, tool.description),
|
|
467
824
|
),
|
|
468
825
|
)))
|
|
@@ -485,9 +842,9 @@ window.__ModuleLoader__.load({
|
|
|
485
842
|
h("div", null, h("h3", null, "自动分组预览"), h("div", { className: "tm_muted" }, "确认后只加入页面草稿,仍需点击保存。")),
|
|
486
843
|
h("button", { className: "tm_btn", onClick: () => setAutoPreview(null) }, "关闭"),
|
|
487
844
|
),
|
|
488
|
-
h("div", { className: "tm_modal_body" },
|
|
489
|
-
autoPreview.groups.map((group, index) => h("div", { className: "tm_panel", key: group.name + index },
|
|
490
|
-
h("div", { className: "tm_panel_head" }, h("div",
|
|
845
|
+
h("div", { className: "tm_modal_body tm_preview_body" },
|
|
846
|
+
autoPreview.groups.map((group, index) => h("div", { className: "tm_panel tm_preview_panel", key: group.name + index },
|
|
847
|
+
h("div", { className: "tm_panel_head" }, h("div", { className: "tm_preview_meta" }, h("b", null, group.name), h("div", { className: "tm_preview_desc" }, group.description)), h("span", { className: "tm_group_count" }, group.tools.length + " 个工具")),
|
|
491
848
|
h("div", { style: { padding: "10px 14px" } }, group.tools.map((name) => h("div", { className: "tm_member tm_tool_name", key: name }, name))),
|
|
492
849
|
)),
|
|
493
850
|
autoPreview.ungrouped.length ? h("div", { className: "tm_notice" }, "保持常开、未归组:", h("span", { className: "tm_code" }, autoPreview.ungrouped.join(", "))) : null,
|
|
@@ -518,13 +875,15 @@ window.__ModuleLoader__.load({
|
|
|
518
875
|
draft.configPath ? h("div", { className: "tm_muted" }, "配置文件:", h("span", { className: "tm_code" }, draft.configPath)) : null,
|
|
519
876
|
h("div", { className: "tm_preset_picker" },
|
|
520
877
|
h("label", { htmlFor: "tm-preset-select" }, "Agent Preset"),
|
|
521
|
-
h("
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
878
|
+
h("span", { className: "tm_select_wrap" },
|
|
879
|
+
h("select", {
|
|
880
|
+
id: "tm-preset-select",
|
|
881
|
+
className: "tm_preset_select",
|
|
882
|
+
value: preset.id,
|
|
883
|
+
disabled: autoGrouping,
|
|
884
|
+
onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setAutoGroupError(""); setExpanded({}); },
|
|
885
|
+
}, draft.presets.map((item) => h("option", { key: item.id, value: item.id }, (item.name || item.id) + " · " + (item.tools || []).length + " 个工具" + (item.isDefault ? " · 默认" : "") + (item.trust === "system" ? "" : " · 用户")))),
|
|
886
|
+
),
|
|
528
887
|
),
|
|
529
888
|
preset.broken ? h("div", { className: "tm_error" }, preset.broken) : null,
|
|
530
889
|
autoGroupError ? h("div", { className: "tm_error" }, autoGroupError) : null,
|
|
@@ -560,6 +919,7 @@ window.__ModuleLoader__.load({
|
|
|
560
919
|
) : null,
|
|
561
920
|
),
|
|
562
921
|
dialog,
|
|
922
|
+
aiConfirmDialog,
|
|
563
923
|
previewDialog,
|
|
564
924
|
);
|
|
565
925
|
}
|