dsh-tool-manager 1.2.13 → 1.4.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 +18 -0
- package/DESIGN.md +18 -8
- package/README.md +32 -3
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +1 -1
- package/dist/catalog.js.map +1 -1
- package/dist/client.js +374 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt-affinity.d.ts +87 -0
- package/dist/prompt-affinity.d.ts.map +1 -0
- package/dist/prompt-affinity.js +617 -0
- package/dist/prompt-affinity.js.map +1 -0
- package/dist/runtime.d.ts +14 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +57 -25
- package/dist/runtime.js.map +1 -1
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/snapshot.js +14 -3
- package/dist/snapshot.js.map +1 -1
- package/dist/stats.d.ts +28 -1
- package/dist/stats.d.ts.map +1 -1
- package/dist/stats.js +81 -1
- package/dist/stats.js.map +1 -1
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/images/tool-manager.png +0 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -15,11 +15,13 @@ window.__ModuleLoader__.load({
|
|
|
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
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
|
-
".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}",
|
|
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;position:relative}.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_token{display:inline-flex;align-items:center;margin-left:6px;padding:1px 6px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.22));border-radius:999px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.09));font:600 10px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace;color:var(--dsw-alias-label-secondary,#9097a4);white-space:nowrap;vertical-align:middle}.tm_tool>.tm_token{margin-left:auto;flex:0 0 auto}.tm_stat_extra{margin-top:2px;font-size:10px;color:var(--dsw-alias-label-secondary,#9097a4);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
|
|
24
|
+
".tm_help{display:inline-flex;align-items:center;justify-content:center;width:15px;height:15px;margin-left:6px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.28));border-radius:50%;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.08));color:var(--dsw-alias-label-secondary,#9097a4);font:700 10px/1 ui-sans-serif,system-ui,sans-serif;cursor:help;vertical-align:middle;outline:none}.tm_help:hover,.tm_help:focus-visible{border-color:#7c8cff;color:#9da8ff}.tm_help::after{content:attr(data-tip);position:absolute;left:0;top:calc(100% + 6px);width:min(520px,calc(100vw - 48px));max-width:100%;padding:10px 12px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.28));border-radius:9px;background:var(--dsw-alias-bg-base,#17191d);box-shadow:0 14px 40px rgba(0,0,0,.35);color:var(--dsw-alias-label-primary,#e7e9ed);font:400 12px/1.65 ui-sans-serif,system-ui,sans-serif;white-space:pre-line;text-align:left;opacity:0;visibility:hidden;pointer-events:none;z-index:30;transition:opacity .12s ease}.tm_help:hover::after,.tm_help:focus-visible::after{opacity:1;visibility:visible}",
|
|
23
25
|
".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
26
|
".tm_group{border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.13))}.tm_group:last-child{border-bottom:0}",
|
|
25
27
|
".tm_group_bar{display:flex;align-items:center;gap:8px;padding:11px 14px}",
|
|
@@ -36,7 +38,7 @@ window.__ModuleLoader__.load({
|
|
|
36
38
|
".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
39
|
".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
40
|
".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
|
-
".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}",
|
|
41
|
+
".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}.tm_copy_meta{font-size:11px;color:var(--dsw-alias-label-secondary,#9097a4);line-height:1.45;margin-top:3px;overflow-wrap:anywhere}",
|
|
40
42
|
".tm_banner{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);z-index:10001;display:flex;align-items:flex-start;gap:14px;width:min(720px,calc(100vw - 32px));padding:12px 14px;border:1px solid #b45309;border-radius:12px;background:color-mix(in srgb,#f59e0b 18%,var(--dsw-alias-bg-base,#17191d));box-shadow:0 16px 48px rgba(0,0,0,.42);font-size:12px;line-height:1.55;color:var(--dsw-alias-label-primary,#e7e9ed)}",
|
|
41
43
|
".tm_banner_body{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}.tm_banner_line{overflow-wrap:anywhere}",
|
|
42
44
|
].join("");
|
|
@@ -93,6 +95,45 @@ window.__ModuleLoader__.load({
|
|
|
93
95
|
})),
|
|
94
96
|
};
|
|
95
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Project one Preset's whole policy onto another Preset.
|
|
100
|
+
*
|
|
101
|
+
* The target is meant to be overwritten, so its current groups and
|
|
102
|
+
* disabled names are ignored. Copy only what the target can actually
|
|
103
|
+
* expose: group membership is limited to tools present in both
|
|
104
|
+
* Presets, and a group whose members all disappear is skipped instead
|
|
105
|
+
* of becoming an invalid empty group. Old wildcard patterns are
|
|
106
|
+
* expanded to exact names, matching what the group editor shows.
|
|
107
|
+
*/
|
|
108
|
+
function copyPresetPolicy(sourcePreset, targetPreset) {
|
|
109
|
+
const sourceTools = sourcePreset.tools || [];
|
|
110
|
+
const sourcePolicy = sourcePreset.policy || { disabled: [], groups: [] };
|
|
111
|
+
const targetNames = new Set((targetPreset.tools || []).map((tool) => tool.name));
|
|
112
|
+
const sourceNames = new Set(sourceTools.map((tool) => tool.name));
|
|
113
|
+
const disabled = (sourcePolicy.disabled || [])
|
|
114
|
+
.filter((name) => sourceNames.has(name) && targetNames.has(name));
|
|
115
|
+
const claimed = new Set(disabled);
|
|
116
|
+
const groups = [];
|
|
117
|
+
const skippedGroups = [];
|
|
118
|
+
for (const group of sourcePolicy.groups || []) {
|
|
119
|
+
const members = [];
|
|
120
|
+
for (const tool of matchingTools(sourceTools, group.patterns || [])) {
|
|
121
|
+
if (!targetNames.has(tool.name) || claimed.has(tool.name)) continue;
|
|
122
|
+
claimed.add(tool.name);
|
|
123
|
+
members.push(tool.name);
|
|
124
|
+
}
|
|
125
|
+
if (members.length === 0) {
|
|
126
|
+
skippedGroups.push(group.name || "未命名分组");
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
groups.push({
|
|
130
|
+
name: group.name,
|
|
131
|
+
...(group.description ? { description: group.description } : {}),
|
|
132
|
+
patterns: members,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return { disabled, groups, skippedGroups };
|
|
136
|
+
}
|
|
96
137
|
function settingsPayload(value) {
|
|
97
138
|
const settings = { presets: {} };
|
|
98
139
|
for (const item of value && value.presets || []) settings.presets[item.id] = policyPayload(item.policy);
|
|
@@ -153,6 +194,115 @@ window.__ModuleLoader__.load({
|
|
|
153
194
|
}
|
|
154
195
|
return { totalTools: (preset.tools || []).length, groupCount: (preset.policy.groups || []).length, ungroupedTools, onDemandTools, disabledTools };
|
|
155
196
|
}
|
|
197
|
+
// Token estimates mirror the Host's `@deepseek-ai/dsh-token-meter/estimate`
|
|
198
|
+
// (4 characters per token) so the editor updates live while groups are
|
|
199
|
+
// dragged around in the draft, before a save reaches the Host snapshot.
|
|
200
|
+
function estimateToolTokens(tool) {
|
|
201
|
+
try {
|
|
202
|
+
return Math.ceil(JSON.stringify({
|
|
203
|
+
name: tool.name,
|
|
204
|
+
description: tool.description,
|
|
205
|
+
parameters: tool.parameters,
|
|
206
|
+
}).length / 4);
|
|
207
|
+
} catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function estimateToolsTokens(tools) {
|
|
212
|
+
const list = (tools || []).map((tool) => ({
|
|
213
|
+
name: tool.name,
|
|
214
|
+
description: tool.description,
|
|
215
|
+
parameters: tool.parameters,
|
|
216
|
+
}));
|
|
217
|
+
if (list.length === 0) return 0;
|
|
218
|
+
try {
|
|
219
|
+
return Math.ceil(JSON.stringify(list).length / 4) + 4;
|
|
220
|
+
} catch {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function escapeCatalogText(value) {
|
|
225
|
+
return String(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
226
|
+
}
|
|
227
|
+
function renderCatalogLine(group, members) {
|
|
228
|
+
const heading = "- " + escapeCatalogText(group.name || "") + " (" + members.length + " tools)"
|
|
229
|
+
+ (group.description ? ": " + escapeCatalogText(group.description) : "");
|
|
230
|
+
return heading + "\n Tools: " + members.map((tool) => escapeCatalogText(tool.name)).join(", ");
|
|
231
|
+
}
|
|
232
|
+
function estimateGroupTokens(group, members) {
|
|
233
|
+
if (members.length === 0) return { schema: 0, catalog: 0, net: 0 };
|
|
234
|
+
let schema = 0;
|
|
235
|
+
for (const tool of members) {
|
|
236
|
+
const tokens = estimateToolTokens(tool);
|
|
237
|
+
if (tokens === null) return null;
|
|
238
|
+
schema += tokens;
|
|
239
|
+
}
|
|
240
|
+
const catalog = Math.ceil(renderCatalogLine(group, members).length / 4);
|
|
241
|
+
return { schema, catalog, net: schema - catalog };
|
|
242
|
+
}
|
|
243
|
+
function activeGroupViews(preset) {
|
|
244
|
+
const disabled = new Set(preset.policy.disabled || []);
|
|
245
|
+
const claimed = new Set();
|
|
246
|
+
const active = [];
|
|
247
|
+
for (const group of preset.policy.groups || []) {
|
|
248
|
+
const members = matchingTools(preset.tools, group.patterns)
|
|
249
|
+
.filter((tool) => !disabled.has(tool.name) && !claimed.has(tool.name));
|
|
250
|
+
if (members.length === 0) continue;
|
|
251
|
+
for (const tool of members) claimed.add(tool.name);
|
|
252
|
+
active.push({ group, members });
|
|
253
|
+
}
|
|
254
|
+
return { active, claimed, disabled };
|
|
255
|
+
}
|
|
256
|
+
function presetTokenStats(preset) {
|
|
257
|
+
const { active, claimed, disabled } = activeGroupViews(preset);
|
|
258
|
+
const allTools = preset.tools || [];
|
|
259
|
+
const alwaysOn = allTools.filter((tool) => !disabled.has(tool.name) && !claimed.has(tool.name));
|
|
260
|
+
const onDemand = allTools.filter((tool) => claimed.has(tool.name));
|
|
261
|
+
const disabledTools = allTools.filter((tool) => disabled.has(tool.name));
|
|
262
|
+
let onDemandTokens = 0;
|
|
263
|
+
let onDemandSavings = 0;
|
|
264
|
+
for (const item of active) {
|
|
265
|
+
const tokens = estimateGroupTokens(item.group, item.members);
|
|
266
|
+
if (tokens) {
|
|
267
|
+
onDemandTokens += tokens.schema;
|
|
268
|
+
onDemandSavings += tokens.net;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
totalTokens: estimateToolsTokens(allTools),
|
|
273
|
+
alwaysOnTools: alwaysOn.length,
|
|
274
|
+
alwaysOnTokens: estimateToolsTokens(alwaysOn),
|
|
275
|
+
onDemandTools: onDemand.length,
|
|
276
|
+
onDemandTokens,
|
|
277
|
+
onDemandGroups: active.length,
|
|
278
|
+
onDemandSavings,
|
|
279
|
+
disabledTools: disabledTools.length,
|
|
280
|
+
disabledTokens: estimateToolsTokens(disabledTools),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function groupTokenEstimates(preset) {
|
|
284
|
+
const map = new Map();
|
|
285
|
+
for (const item of activeGroupViews(preset).active) {
|
|
286
|
+
map.set(item.group._key || item.group.name, estimateGroupTokens(item.group, item.members));
|
|
287
|
+
}
|
|
288
|
+
return map;
|
|
289
|
+
}
|
|
290
|
+
function formatTokenCount(value) {
|
|
291
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return "—";
|
|
292
|
+
if (Math.abs(value) >= 1000) {
|
|
293
|
+
return String(Math.round(value / 100) / 10).replace(/\.0$/, "") + "k";
|
|
294
|
+
}
|
|
295
|
+
return String(Math.round(value));
|
|
296
|
+
}
|
|
297
|
+
function formatTokenAmount(value) {
|
|
298
|
+
return typeof value === "number" && Number.isFinite(value) ? "~" + formatTokenCount(value) : "—";
|
|
299
|
+
}
|
|
300
|
+
function tokenBadge(tokens, title) {
|
|
301
|
+
if (typeof tokens !== "number" || !Number.isFinite(tokens)) {
|
|
302
|
+
return h("span", { className: "tm_token", title: "估算不可用(4 字符/token)" }, "—");
|
|
303
|
+
}
|
|
304
|
+
return h("span", { className: "tm_token", title: title || "估算(4 字符/token)" }, "~" + formatTokenCount(tokens) + " tok");
|
|
305
|
+
}
|
|
156
306
|
function matchesQuery(tool, needle) {
|
|
157
307
|
if (!needle) return true;
|
|
158
308
|
return tool.name.toLowerCase().includes(needle) || (tool.description || "").toLowerCase().includes(needle);
|
|
@@ -246,6 +396,12 @@ window.__ModuleLoader__.load({
|
|
|
246
396
|
);
|
|
247
397
|
}
|
|
248
398
|
|
|
399
|
+
const TOOL_CATALOG_HELP = [
|
|
400
|
+
"关掉后立刻对模型隐藏。按需组默认隐藏,模型要先调用 tool_list 打开所在组才能使用。",
|
|
401
|
+
"",
|
|
402
|
+
"tool_list 只在当前 Preset 有有效按需组时才出现(保存后从下一个模型步骤生效),没有有效按需组时模型看不到它;它由插件自动管理,不出现在本页工具目录中,也不能在这里开关或分组。",
|
|
403
|
+
].join("\n");
|
|
404
|
+
|
|
249
405
|
function ToolManagerSection() {
|
|
250
406
|
const [snapshot, setSnapshot] = react.useState(null);
|
|
251
407
|
const [draft, setDraft] = react.useState(null);
|
|
@@ -259,6 +415,7 @@ window.__ModuleLoader__.load({
|
|
|
259
415
|
const [autoGrouping, setAutoGrouping] = react.useState(false);
|
|
260
416
|
const [autoGroupError, setAutoGroupError] = react.useState("");
|
|
261
417
|
const [autoPreview, setAutoPreview] = react.useState(null);
|
|
418
|
+
const [copyDialog, setCopyDialog] = react.useState(null);
|
|
262
419
|
const [expanded, setExpanded] = react.useState({});
|
|
263
420
|
const [aiConfirm, setAiConfirm] = react.useState(null);
|
|
264
421
|
const [suggestionTimeoutSeconds, setSuggestionTimeoutSeconds] = react.useState("60");
|
|
@@ -269,7 +426,7 @@ window.__ModuleLoader__.load({
|
|
|
269
426
|
setBusy(true); setError("");
|
|
270
427
|
return api("/snapshot").then((value) => {
|
|
271
428
|
const next = withGroupKeys(value);
|
|
272
|
-
setSnapshot(value); setDraft(next); setModal(null); setAutoPreview(null); setAutoGroupError("");
|
|
429
|
+
setSnapshot(value); setDraft(next); setModal(null); setAutoPreview(null); setCopyDialog(null); setAutoGroupError("");
|
|
273
430
|
setActive((current) => current && value.presets.some((p) => p.id === current) ? current : (value.presets[0] && value.presets[0].id) || "");
|
|
274
431
|
}).catch((e) => {
|
|
275
432
|
// The Host swaps the preset registry instance when its node
|
|
@@ -294,17 +451,18 @@ window.__ModuleLoader__.load({
|
|
|
294
451
|
return () => window.removeEventListener("beforeunload", onBeforeUnload);
|
|
295
452
|
}, [dirty]);
|
|
296
453
|
react.useEffect(() => {
|
|
297
|
-
if (!modal && !aiConfirm && !autoPreview) return undefined;
|
|
454
|
+
if (!modal && !aiConfirm && !autoPreview && !copyDialog) return undefined;
|
|
298
455
|
function onKeyDown(event) {
|
|
299
456
|
if (event.key === "Escape") {
|
|
300
457
|
if (aiConfirm) setAiConfirm(null);
|
|
301
458
|
else if (autoPreview) setAutoPreview(null);
|
|
459
|
+
else if (copyDialog) setCopyDialog(null);
|
|
302
460
|
else if (modal) setModal(null);
|
|
303
461
|
}
|
|
304
462
|
}
|
|
305
463
|
window.addEventListener("keydown", onKeyDown);
|
|
306
464
|
return () => window.removeEventListener("keydown", onKeyDown);
|
|
307
|
-
}, [modal, aiConfirm, autoPreview]);
|
|
465
|
+
}, [modal, aiConfirm, autoPreview, copyDialog]);
|
|
308
466
|
|
|
309
467
|
if (!draft) return h("div", { className: "tm_root" }, error ? h("div", { className: "tm_error" }, error) : h("div", { className: "tm_muted" }, "正在读取工具目录…"));
|
|
310
468
|
const preset = draft.presets.find((item) => item.id === active) || draft.presets[0];
|
|
@@ -341,6 +499,82 @@ window.__ModuleLoader__.load({
|
|
|
341
499
|
});
|
|
342
500
|
}
|
|
343
501
|
|
|
502
|
+
function resetPresetConfig() {
|
|
503
|
+
if (!hasPresetConfig) return;
|
|
504
|
+
if (!window.confirm("确定重置当前 Preset 的配置吗?这会清空它的全部按需组和已关闭工具;只修改页面草稿,保存后生效。")) return;
|
|
505
|
+
mutatePreset((target) => {
|
|
506
|
+
target.policy = { disabled: [], groups: [] };
|
|
507
|
+
});
|
|
508
|
+
setQuery("");
|
|
509
|
+
setFilter("all");
|
|
510
|
+
setExpanded({});
|
|
511
|
+
setMessage("已重置当前 Preset 的配置(草稿);点击保存后生效。");
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function openCopyDialog() {
|
|
515
|
+
if (!hasPresetConfig || copyTargetCount === 0) return;
|
|
516
|
+
setCopyDialog({ sourceId: preset.id, selected: [] });
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function toggleCopyTarget(id) {
|
|
520
|
+
setCopyDialog((current) => {
|
|
521
|
+
if (!current) return current;
|
|
522
|
+
const selected = new Set(current.selected || []);
|
|
523
|
+
if (selected.has(id)) selected.delete(id); else selected.add(id);
|
|
524
|
+
return { ...current, selected: [...selected] };
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function selectAllCopyTargets(ids) {
|
|
529
|
+
setCopyDialog((current) => current ? { ...current, selected: [...ids] } : current);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function clearCopyTargets() {
|
|
533
|
+
setCopyDialog((current) => current ? { ...current, selected: [] } : current);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function confirmCopy() {
|
|
537
|
+
if (!copyDialog) return;
|
|
538
|
+
const source = draft.presets.find((item) => item.id === copyDialog.sourceId);
|
|
539
|
+
if (!source) { setCopyDialog(null); return; }
|
|
540
|
+
const selected = new Set(copyDialog.selected || []);
|
|
541
|
+
const plans = [];
|
|
542
|
+
for (const target of draft.presets) {
|
|
543
|
+
if (target.id === source.id || !selected.has(target.id) || target.broken) continue;
|
|
544
|
+
const copied = copyPresetPolicy(source, target);
|
|
545
|
+
const before = JSON.stringify(policyPayload(target.policy));
|
|
546
|
+
const after = JSON.stringify(policyPayload({ disabled: copied.disabled, groups: copied.groups }));
|
|
547
|
+
plans.push({ targetId: target.id, label: target.name || target.id, copied, changed: before !== after });
|
|
548
|
+
}
|
|
549
|
+
if (!plans.length) { setCopyDialog(null); return; }
|
|
550
|
+
setDraft((current) => {
|
|
551
|
+
const next = clone(current);
|
|
552
|
+
for (const plan of plans) {
|
|
553
|
+
const target = next.presets.find((item) => item.id === plan.targetId);
|
|
554
|
+
if (!target) continue;
|
|
555
|
+
target.policy = {
|
|
556
|
+
disabled: [...plan.copied.disabled],
|
|
557
|
+
groups: plan.copied.groups.map((group) => ({ ...group, _key: newKey() })),
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
return next;
|
|
561
|
+
});
|
|
562
|
+
const changed = plans.filter((plan) => plan.changed);
|
|
563
|
+
const unchanged = plans.length - changed.length;
|
|
564
|
+
const skipped = plans.flatMap((plan) => plan.copied.skippedGroups.map((name) => plan.label + ":" + name));
|
|
565
|
+
const parts = [];
|
|
566
|
+
if (changed.length) {
|
|
567
|
+
parts.push("已将「" + (source.name || source.id) + "」的配置复制到 "
|
|
568
|
+
+ changed.map((plan) => "「" + plan.label + "」").join("、") + "(草稿),请检查后保存。");
|
|
569
|
+
} else {
|
|
570
|
+
parts.push("所选 Preset 的配置已与当前 Preset 一致,没有产生修改。");
|
|
571
|
+
}
|
|
572
|
+
if (unchanged) parts.push(unchanged + " 个 Preset 无变化。");
|
|
573
|
+
if (skipped.length) parts.push("跳过 " + skipped.length + " 个无可用工具的分组:" + skipped.join(";"));
|
|
574
|
+
setMessage(parts.join(" "));
|
|
575
|
+
setCopyDialog(null);
|
|
576
|
+
}
|
|
577
|
+
|
|
344
578
|
function openEdit(group) {
|
|
345
579
|
const members = matchingTools(preset.tools, group.patterns || []).map((tool) => tool.name);
|
|
346
580
|
setModal({
|
|
@@ -568,7 +802,7 @@ window.__ModuleLoader__.load({
|
|
|
568
802
|
api("/save", { method: "POST", body: JSON.stringify({ expectedRevision: snapshot.revision, settings }) })
|
|
569
803
|
.then((value) => {
|
|
570
804
|
const next = withGroupKeys(value);
|
|
571
|
-
setSnapshot(value); setDraft(next); setModal(null);
|
|
805
|
+
setSnapshot(value); setDraft(next); setModal(null); setCopyDialog(null);
|
|
572
806
|
setMessage("已保存;运行中 Agent 将从下一个模型步骤应用新策略。");
|
|
573
807
|
})
|
|
574
808
|
.catch((e) => setError(String(e.message || e)))
|
|
@@ -579,6 +813,13 @@ window.__ModuleLoader__.load({
|
|
|
579
813
|
const grouped = groupedNames(preset);
|
|
580
814
|
const autoGroupCandidates = (preset.tools || []).filter((tool) => !disabled.has(tool.name) && !grouped.has(tool.name));
|
|
581
815
|
const stats = catalogStats(preset);
|
|
816
|
+
const tokenStats = presetTokenStats(preset);
|
|
817
|
+
const onDemandCatalogTokens = Math.max(0, tokenStats.onDemandTokens - tokenStats.onDemandSavings);
|
|
818
|
+
const groupTokens = groupTokenEstimates(preset);
|
|
819
|
+
const presetPolicy = preset.policy || { disabled: [], groups: [] };
|
|
820
|
+
const hasPresetConfig = !preset.broken
|
|
821
|
+
&& ((presetPolicy.groups || []).length > 0 || (presetPolicy.disabled || []).length > 0);
|
|
822
|
+
const copyTargetCount = draft.presets.filter((item) => item.id !== preset.id && !item.broken).length;
|
|
582
823
|
const needle = query.trim().toLowerCase();
|
|
583
824
|
const groups = preset.policy.groups || [];
|
|
584
825
|
const visibleGroups = groups.filter((group) => {
|
|
@@ -616,6 +857,15 @@ window.__ModuleLoader__.load({
|
|
|
616
857
|
const aiVisibleSelected = aiVisibleCandidates.filter((tool) => aiSelected.has(tool.name)).map((tool) => tool.name);
|
|
617
858
|
const aiPromptTrimmed = String(aiConfirm && aiConfirm.prompt || "").trim();
|
|
618
859
|
const aiCanConfirm = aiPromptTrimmed.length > 0 && (!aiIsAutoGroup || aiSelected.size > 0);
|
|
860
|
+
const copySource = copyDialog ? draft.presets.find((item) => item.id === copyDialog.sourceId) : null;
|
|
861
|
+
const copyPreviewRows = copySource
|
|
862
|
+
? draft.presets
|
|
863
|
+
.filter((item) => item.id !== copySource.id)
|
|
864
|
+
.map((target) => ({ target, preview: copyPresetPolicy(copySource, target) }))
|
|
865
|
+
: [];
|
|
866
|
+
const copySelectableIds = copyPreviewRows.filter((row) => !row.target.broken).map((row) => row.target.id);
|
|
867
|
+
const copySelected = new Set(copyDialog ? copyDialog.selected || [] : []);
|
|
868
|
+
const copySelectedCount = copySelectableIds.filter((id) => copySelected.has(id)).length;
|
|
619
869
|
|
|
620
870
|
function updateAutoGroupSelection(nextSelectedNames) {
|
|
621
871
|
const nextSelected = [...new Set(nextSelectedNames)];
|
|
@@ -633,6 +883,7 @@ window.__ModuleLoader__.load({
|
|
|
633
883
|
const key = group._key;
|
|
634
884
|
const open = !!expanded[key];
|
|
635
885
|
const members = matchingTools(preset.tools, group.patterns);
|
|
886
|
+
const estimate = groupTokens.get(key) || null;
|
|
636
887
|
const title = (group.name || "").trim() || "未命名分组";
|
|
637
888
|
return h("div", { className: "tm_group", key: key },
|
|
638
889
|
h("div", { className: "tm_group_bar" },
|
|
@@ -641,15 +892,20 @@ window.__ModuleLoader__.load({
|
|
|
641
892
|
h("div", { className: "tm_group_title" }, title, h("span", { className: "tm_badge cold" }, "按需")),
|
|
642
893
|
h("div", { className: "tm_group_sub" }, group.description || "没有描述"),
|
|
643
894
|
),
|
|
895
|
+
estimate && estimate.schema > 0 ? tokenBadge(estimate.net, "估算(4 字符/token):组内工具 schema " + formatTokenAmount(estimate.schema) + " tok · 关闭时目录行 " + formatTokenAmount(estimate.catalog) + " tok · 收起净省 " + formatTokenAmount(estimate.net) + " tok/轮") : null,
|
|
644
896
|
h("span", { className: "tm_group_count" }, members.length + " 个工具"),
|
|
645
897
|
h("button", { className: "tm_btn", onClick: () => openEdit(group) }, "编辑"),
|
|
646
898
|
h("button", { className: "tm_btn", onClick: () => deleteGroup(key) }, "删除"),
|
|
647
899
|
),
|
|
648
900
|
open ? h("div", { className: "tm_group_body" }, members.length
|
|
649
|
-
? members.map((tool) =>
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
901
|
+
? members.map((tool) => {
|
|
902
|
+
const tokens = estimateToolTokens(tool);
|
|
903
|
+
const isDisabled = disabled.has(tool.name);
|
|
904
|
+
return h("div", { className: "tm_member", key: tool.name },
|
|
905
|
+
h("div", { className: "tm_tool_name" }, tool.name, isDisabled ? h("span", { className: "tm_badge off" }, "关闭") : null, tokenBadge(tokens, isDisabled ? "估算(4 字符/token):已关闭,开启后常驻 " + formatTokenAmount(tokens) + " tok/轮" : "估算(4 字符/token):单工具常驻 " + formatTokenAmount(tokens) + " tok/轮")),
|
|
906
|
+
h("div", { className: "tm_tool_desc", title: tool.description }, tool.description),
|
|
907
|
+
);
|
|
908
|
+
})
|
|
653
909
|
: h("div", { className: "tm_error" }, "无效空组:请编辑并选择至少一个可用工具,或删除该组。"),
|
|
654
910
|
) : null,
|
|
655
911
|
);
|
|
@@ -657,6 +913,7 @@ window.__ModuleLoader__.load({
|
|
|
657
913
|
|
|
658
914
|
function renderTool(tool) {
|
|
659
915
|
const enabled = !disabled.has(tool.name);
|
|
916
|
+
const tokens = estimateToolTokens(tool);
|
|
660
917
|
return h("label", { className: "tm_tool", key: tool.name },
|
|
661
918
|
h("input", { type: "checkbox", checked: enabled, onChange: () => toggleTool(tool.name) }),
|
|
662
919
|
h("span", null,
|
|
@@ -665,6 +922,7 @@ window.__ModuleLoader__.load({
|
|
|
665
922
|
),
|
|
666
923
|
h("div", { className: "tm_tool_desc", title: tool.description }, tool.description),
|
|
667
924
|
),
|
|
925
|
+
tokenBadge(tokens, enabled ? "估算(4 字符/token):单工具常驻 " + formatTokenAmount(tokens) + " tok/轮" : "估算(4 字符/token):已关闭,开启后常驻 " + formatTokenAmount(tokens) + " tok/轮"),
|
|
668
926
|
);
|
|
669
927
|
}
|
|
670
928
|
|
|
@@ -907,6 +1165,77 @@ window.__ModuleLoader__.load({
|
|
|
907
1165
|
document.body,
|
|
908
1166
|
) : null;
|
|
909
1167
|
|
|
1168
|
+
const copyDialogNode = copyDialog && copySource && typeof document !== "undefined" ? reactDom.createPortal(
|
|
1169
|
+
h("div", { className: "tm_modal", role: "dialog", "aria-modal": "true", "aria-label": "复制当前 Preset 配置" },
|
|
1170
|
+
h("div", { className: "tm_modal_mask", onMouseDown: () => setCopyDialog(null) }),
|
|
1171
|
+
h("div", { className: "tm_modal_card" },
|
|
1172
|
+
h("div", { className: "tm_modal_head" },
|
|
1173
|
+
h("div", null,
|
|
1174
|
+
h("h3", null, "复制当前 Preset 配置"),
|
|
1175
|
+
h("div", { className: "tm_muted" }, "将当前 Preset 的全部按需组和已关闭工具复制到勾选的 Preset;只改页面草稿,保存后生效。"),
|
|
1176
|
+
),
|
|
1177
|
+
h("button", { className: "tm_btn", onClick: () => setCopyDialog(null) }, "关闭"),
|
|
1178
|
+
),
|
|
1179
|
+
h("div", { className: "tm_modal_body" },
|
|
1180
|
+
h("div", { className: "tm_notice" },
|
|
1181
|
+
"源 Preset「" + (copySource.name || copySource.id) + "」:"
|
|
1182
|
+
+ (copySource.policy.groups || []).length + " 个按需组、"
|
|
1183
|
+
+ (copySource.policy.disabled || []).length + " 个已关闭工具。"
|
|
1184
|
+
+ "勾选的目标 Preset 现有分组和关闭项将被整份覆盖。",
|
|
1185
|
+
),
|
|
1186
|
+
h("div", { className: "tm_row" },
|
|
1187
|
+
h("button", {
|
|
1188
|
+
className: "tm_btn",
|
|
1189
|
+
disabled: copySelectableIds.length === 0,
|
|
1190
|
+
onClick: () => selectAllCopyTargets(copySelectableIds),
|
|
1191
|
+
}, "全选可复制项"),
|
|
1192
|
+
h("button", { className: "tm_btn", disabled: copySelectedCount === 0, onClick: clearCopyTargets }, "清空"),
|
|
1193
|
+
h("span", { className: "tm_muted" }, "已选 " + copySelectedCount + " / " + copySelectableIds.length + " 个 Preset"),
|
|
1194
|
+
),
|
|
1195
|
+
copyPreviewRows.length
|
|
1196
|
+
? h("div", { className: "tm_picker" }, copyPreviewRows.map(({ target, preview }) => {
|
|
1197
|
+
const currentGroups = (target.policy.groups || []).length;
|
|
1198
|
+
const currentDisabled = (target.policy.disabled || []).length;
|
|
1199
|
+
const meta = target.broken
|
|
1200
|
+
? "工具目录读取失败,暂不能复制"
|
|
1201
|
+
: "现有 " + currentGroups + " 个组 / " + currentDisabled + " 个关闭项 → 将复制 "
|
|
1202
|
+
+ preview.groups.length + " 个组 / " + preview.disabled.length + " 个关闭项"
|
|
1203
|
+
+ (preview.skippedGroups.length
|
|
1204
|
+
? ";跳过 " + preview.skippedGroups.length + " 个组:" + preview.skippedGroups.join("、")
|
|
1205
|
+
: "")
|
|
1206
|
+
+ ((target.tools || []).length === 0 ? ";目标没有可见工具,复制后配置为空" : "");
|
|
1207
|
+
return h("label", { className: "tm_pick", key: target.id },
|
|
1208
|
+
h("input", {
|
|
1209
|
+
type: "checkbox",
|
|
1210
|
+
checked: copySelected.has(target.id) && !target.broken,
|
|
1211
|
+
disabled: !!target.broken,
|
|
1212
|
+
onChange: () => toggleCopyTarget(target.id),
|
|
1213
|
+
}),
|
|
1214
|
+
h("span", null,
|
|
1215
|
+
h("div", { className: "tm_tool_name" },
|
|
1216
|
+
target.name ? target.name + " · " + target.id : target.id,
|
|
1217
|
+
target.broken ? h("span", { className: "tm_badge off" }, "不可用") : null,
|
|
1218
|
+
),
|
|
1219
|
+
h("div", { className: "tm_copy_meta", title: meta }, meta),
|
|
1220
|
+
),
|
|
1221
|
+
);
|
|
1222
|
+
}))
|
|
1223
|
+
: h("div", { className: "tm_muted" }, "没有其他可复制的 Preset。"),
|
|
1224
|
+
h("div", { className: "tm_muted" }, "提示:分组按目标 Preset 实际拥有的工具裁剪;整组都没有可用工具时会自动跳过。"),
|
|
1225
|
+
),
|
|
1226
|
+
h("div", { className: "tm_modal_foot" },
|
|
1227
|
+
h("button", { className: "tm_btn", onClick: () => setCopyDialog(null) }, "取消"),
|
|
1228
|
+
h("button", {
|
|
1229
|
+
className: "tm_btn primary",
|
|
1230
|
+
disabled: copySelectedCount === 0,
|
|
1231
|
+
onClick: confirmCopy,
|
|
1232
|
+
}, "复制到 " + copySelectedCount + " 个 Preset"),
|
|
1233
|
+
),
|
|
1234
|
+
),
|
|
1235
|
+
),
|
|
1236
|
+
document.body,
|
|
1237
|
+
) : null;
|
|
1238
|
+
|
|
910
1239
|
const empty = listedGroups.length === 0 && visibleTools.length === 0;
|
|
911
1240
|
|
|
912
1241
|
return h("div", { className: "tm_root" },
|
|
@@ -930,7 +1259,7 @@ window.__ModuleLoader__.load({
|
|
|
930
1259
|
className: "tm_preset_select",
|
|
931
1260
|
value: preset.id,
|
|
932
1261
|
disabled: autoGrouping,
|
|
933
|
-
onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setAutoGroupError(""); setExpanded({}); },
|
|
1262
|
+
onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setCopyDialog(null); setAutoGroupError(""); setExpanded({}); },
|
|
934
1263
|
}, draft.presets.map((item) => h("option", { key: item.id, value: item.id }, (item.name || item.id) + " · " + (item.tools || []).length + " 个工具" + (item.isDefault ? " · 默认" : "") + (item.trust === "user" ? " · 用户" : "")))),
|
|
935
1264
|
),
|
|
936
1265
|
),
|
|
@@ -939,18 +1268,38 @@ window.__ModuleLoader__.load({
|
|
|
939
1268
|
h("section", { className: "tm_panel" },
|
|
940
1269
|
h("div", { className: "tm_panel_head" },
|
|
941
1270
|
h("div", null,
|
|
942
|
-
h("b", null, "工具目录"),
|
|
943
|
-
h("div", { className: "tm_muted" }, "关掉后立刻对模型隐藏。按需组默认隐藏,模型要先调用 tool_list 打开所在组才能使用。"),
|
|
944
|
-
h("div", { className: "tm_muted" }, "tool_list 只在当前 Preset 有有效按需组时才出现(保存后从下一个模型步骤生效),没有有效按需组时模型看不到它;它由插件自动管理,不出现在本页工具目录中,也不能在这里开关或分组。"),
|
|
1271
|
+
h("b", null, "工具目录", h("span", { className: "tm_help", tabIndex: 0, "aria-label": "工具目录说明", "data-tip": TOOL_CATALOG_HELP }, "?")),
|
|
945
1272
|
),
|
|
946
1273
|
h("div", { className: "tm_row" },
|
|
947
1274
|
h("button", { className: "tm_btn", onClick: startAutoGroup, disabled: autoGrouping || autoGroupCandidates.length === 0, title: autoGroupCandidates.length ? "用默认模型对未分组且未关闭的工具进行聚类" : "没有可自动分组的工具" }, autoGrouping ? "自动分组中…" : "自动分组"),
|
|
948
1275
|
h("button", { className: "tm_btn", onClick: openCreate, disabled: autoGrouping }, "手动分组"),
|
|
1276
|
+
h("button", {
|
|
1277
|
+
className: "tm_btn",
|
|
1278
|
+
onClick: resetPresetConfig,
|
|
1279
|
+
disabled: autoGrouping || busy || !draft.writable || !hasPresetConfig,
|
|
1280
|
+
title: hasPresetConfig
|
|
1281
|
+
? "清空当前 Preset 的全部按需组和已关闭工具"
|
|
1282
|
+
: "当前 Preset 没有可重置的配置",
|
|
1283
|
+
}, "重置配置"),
|
|
1284
|
+
h("button", {
|
|
1285
|
+
className: "tm_btn",
|
|
1286
|
+
onClick: openCopyDialog,
|
|
1287
|
+
disabled: autoGrouping || busy || !draft.writable || !hasPresetConfig || copyTargetCount === 0,
|
|
1288
|
+
title: hasPresetConfig
|
|
1289
|
+
? "把当前 Preset 的分组和已关闭工具复制到其他 Preset"
|
|
1290
|
+
: "当前 Preset 没有可复制的分组或已关闭工具",
|
|
1291
|
+
}, "复制配置"),
|
|
949
1292
|
),
|
|
950
1293
|
),
|
|
951
1294
|
h("div", { className: "tm_stats" },
|
|
952
|
-
[
|
|
953
|
-
|
|
1295
|
+
[
|
|
1296
|
+
["工具总量", stats.totalTools, formatTokenAmount(tokenStats.totalTokens) + " tok", "全部 " + stats.totalTools + " 个工具 schema 合计 " + formatTokenAmount(tokenStats.totalTokens) + " tok/轮(全部常驻时)"],
|
|
1297
|
+
["分组数量", stats.groupCount, "省 " + formatTokenAmount(tokenStats.onDemandSavings) + " tok", "全部 " + tokenStats.onDemandGroups + " 个按需组收起:工具 schema 合计 " + formatTokenAmount(tokenStats.onDemandTokens) + " tok − 关闭态目录行 " + formatTokenAmount(onDemandCatalogTokens) + " tok = 净省 " + formatTokenAmount(tokenStats.onDemandSavings) + " tok/轮"],
|
|
1298
|
+
["未分组工具", stats.ungroupedTools, formatTokenAmount(tokenStats.alwaysOnTokens) + " tok", "未分组且未关闭的 " + tokenStats.alwaysOnTools + " 个工具每轮常驻 " + formatTokenAmount(tokenStats.alwaysOnTokens) + " tok"],
|
|
1299
|
+
["按需工具", stats.onDemandTools, formatTokenAmount(tokenStats.onDemandTokens) + " tok", "按需组内 " + tokenStats.onDemandTools + " 个工具 schema 合计 " + formatTokenAmount(tokenStats.onDemandTokens) + " tok;收起后仍会注入目录行 " + formatTokenAmount(onDemandCatalogTokens) + " tok,实际净省见「分组数量」卡"],
|
|
1300
|
+
["已关闭工具", stats.disabledTools, formatTokenAmount(tokenStats.disabledTokens) + " tok", "已关闭的 " + tokenStats.disabledTools + " 个工具关闭可省 " + formatTokenAmount(tokenStats.disabledTokens) + " tok/轮"],
|
|
1301
|
+
].map(([label, value, extra, title]) =>
|
|
1302
|
+
h("div", { className: "tm_stat", key: label }, h("div", { className: "tm_stat_value" }, value), h("div", { className: "tm_stat_label" }, label), h("div", { className: "tm_stat_extra", title }, extra)),
|
|
954
1303
|
),
|
|
955
1304
|
),
|
|
956
1305
|
h("div", { className: "tm_row", style: { padding: "10px 14px" } },
|
|
@@ -974,6 +1323,7 @@ window.__ModuleLoader__.load({
|
|
|
974
1323
|
dialog,
|
|
975
1324
|
aiConfirmDialog,
|
|
976
1325
|
previewDialog,
|
|
1326
|
+
copyDialogNode,
|
|
977
1327
|
);
|
|
978
1328
|
}
|
|
979
1329
|
|
|
@@ -995,6 +1345,14 @@ window.__ModuleLoader__.load({
|
|
|
995
1345
|
|
|
996
1346
|
exports.apply = apply;
|
|
997
1347
|
exports.inject = inject;
|
|
1348
|
+
// Pure policy projection, exported for unit tests. DSH only consumes
|
|
1349
|
+
// apply/inject, so this does not widen the client plugin contract.
|
|
1350
|
+
exports.copyPresetPolicy = copyPresetPolicy;
|
|
1351
|
+
exports.estimateToolTokens = estimateToolTokens;
|
|
1352
|
+
exports.estimateToolsTokens = estimateToolsTokens;
|
|
1353
|
+
exports.estimateGroupTokens = estimateGroupTokens;
|
|
1354
|
+
exports.presetTokenStats = presetTokenStats;
|
|
1355
|
+
exports.formatTokenCount = formatTokenCount;
|
|
998
1356
|
return module.exports;
|
|
999
1357
|
},
|
|
1000
1358
|
});
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EAEX,eAAe,EACf,cAAc,EACf,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAwC,iBAAiB,EAAa,MAAM,aAAa,CAAC;AAmBjG,eAAO,MAAM,IAAI,qBAAqB,CAAC;AACvC,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { buildSnapshot, mergeSchemas } from "./snapshot.js";
|
|
|
8
8
|
import { DISCOVERY_TOOL_NAME, PTC_TRANSPORT_NAME, TOOL_MANAGER_PROBE_SESSION_ID, } from "./types.js";
|
|
9
9
|
import { generateAutoGroups, generateGroupSuggestion, normalizeCustomPrompt, normalizeGroupNames, validateGenerationTimeout, selectSuggestionTools, } from "./suggest.js";
|
|
10
10
|
export const name = "dsh-tool-manager";
|
|
11
|
-
export const inject = ["agentPresets", "agents", "tools"];
|
|
11
|
+
export const inject = ["agentPresets", "agents", "tools", "systemPrompt"];
|
|
12
12
|
/**
|
|
13
13
|
* A single live probe prevents one persistent Session per request or Preset.
|
|
14
14
|
* Preset switches are serialized because `recompose()` mutates this Agent's
|