dsh-tool-manager 1.5.1 → 1.5.2
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 +5 -3
- package/README.md +31 -11
- package/dist/client.js +462 -33
- package/dist/config.d.ts +10 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -0
- package/dist/config.js.map +1 -1
- package/dist/dsh.d.ts +36 -0
- package/dist/dsh.d.ts.map +1 -1
- package/dist/dsh.js.map +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +173 -7
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +22 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +50 -1
- package/dist/policy.js.map +1 -1
- package/dist/suggest.d.ts +50 -1
- package/dist/suggest.d.ts.map +1 -1
- package/dist/suggest.js +113 -2
- package/dist/suggest.js.map +1 -1
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -14,6 +14,7 @@ window.__ModuleLoader__.load({
|
|
|
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
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
|
+
".tm_model_block{display:flex;flex-direction:column;gap:6px;min-width:0}.tm_model_row{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-width:0}.tm_model_row .tm_model_label{flex:0 0 auto;font-size:12px;color:var(--dsw-alias-label-secondary,#9097a4);cursor:help;white-space:nowrap}.tm_model_row .tm_select_wrap{min-width:0}.tm_model_row .tm_model_pick{flex:1 1 auto}.tm_model_row .tm_preset_select{min-width:0;width:100%}.tm_model_row .tm_effort_pick{flex:0 0 auto}.tm_model_row .tm_effort_pick .tm_preset_select{width:auto;min-width:96px}.tm_model_hints{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
17
18
|
".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
19
|
".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
20
|
".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}",
|
|
@@ -21,7 +22,7 @@ window.__ModuleLoader__.load({
|
|
|
21
22
|
".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
23
|
".tm_stats{display:flex;flex-wrap:nowrap;gap:6px;padding:8px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.13))}.tm_stat{flex:1 1 0;min-width:0;padding:6px 7px;border-radius:7px;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:15px;font-weight:700;line-height:1.15;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tm_stat_label{margin-top:2px;font-size:10px;line-height:1.3;color:var(--dsw-alias-label-secondary,#9097a4);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}@media(max-width:560px){.tm_stats{flex-wrap:wrap}.tm_stat{flex:1 1 30%}}",
|
|
23
24
|
".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:1px;font-size:9.5px;line-height:1.3;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:
|
|
25
|
+
".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:none;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}",
|
|
25
26
|
".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}.tm_badge.ptc{background:#6d28d9;border-color:#a78bfa;color:#fff}.tm_badge.native{background:#334155;border-color:#64748b;color:#fff}",
|
|
26
27
|
".tm_group{border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.13))}.tm_group:last-child{border-bottom:0}",
|
|
27
28
|
".tm_group_bar{display:flex;align-items:center;gap:8px;padding:11px 14px}",
|
|
@@ -98,7 +99,7 @@ window.__ModuleLoader__.load({
|
|
|
98
99
|
return payload;
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
|
-
*
|
|
102
|
+
* Copy one Preset's on-demand groups and disabled names onto another.
|
|
102
103
|
*
|
|
103
104
|
* The target is meant to be overwritten, so its current groups and
|
|
104
105
|
* disabled names are ignored. Copy only what the target can actually
|
|
@@ -106,6 +107,12 @@ window.__ModuleLoader__.load({
|
|
|
106
107
|
* Presets, and a group whose members all disappear is skipped instead
|
|
107
108
|
* of becoming an invalid empty group. Old wildcard patterns are
|
|
108
109
|
* expanded to exact names, matching what the group editor shows.
|
|
110
|
+
*
|
|
111
|
+
* Loading mode is not part of the copy: it says how a Preset reads the
|
|
112
|
+
* groups it owns (tool_list in default mode, tool_find in mcp mode), so
|
|
113
|
+
* it belongs to the target. Rebuilding the policy used to omit `mode`,
|
|
114
|
+
* which silently turned an MCP 按需 target back into default mode after
|
|
115
|
+
* a copy.
|
|
109
116
|
*/
|
|
110
117
|
function copyPresetPolicy(sourcePreset, targetPreset) {
|
|
111
118
|
const sourceTools = sourcePreset.tools || [];
|
|
@@ -134,13 +141,140 @@ window.__ModuleLoader__.load({
|
|
|
134
141
|
patterns: members,
|
|
135
142
|
});
|
|
136
143
|
}
|
|
137
|
-
|
|
144
|
+
const mode = targetPreset.policy && targetPreset.policy.mode === "mcp" ? "mcp" : undefined;
|
|
145
|
+
return { disabled, groups, ...(mode ? { mode } : {}), skippedGroups };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The empty policy a Preset resets to.
|
|
149
|
+
*
|
|
150
|
+
* Loading mode survives a reset for the same reason it survives a copy:
|
|
151
|
+
* it is a Preset-level choice, not one of the groups being cleared.
|
|
152
|
+
* Dropping it flipped an MCP 按需 Preset back to default mode and
|
|
153
|
+
* re-registered the discovery tool the Preset had switched away from.
|
|
154
|
+
*/
|
|
155
|
+
function resetPresetPolicy(policy) {
|
|
156
|
+
const mode = policy && policy.mode === "mcp" ? "mcp" : undefined;
|
|
157
|
+
return { disabled: [], groups: [], ...(mode ? { mode } : {}) };
|
|
138
158
|
}
|
|
139
159
|
function settingsPayload(value) {
|
|
140
160
|
const settings = { presets: {} };
|
|
141
161
|
for (const item of value && value.presets || []) settings.presets[item.id] = policyPayload(item.policy);
|
|
162
|
+
// `null` is an explicit "follow the default model again". A MISSING key
|
|
163
|
+
// is what a page loaded before this setting existed sends, and the Host
|
|
164
|
+
// reads that as "leave the stored choice alone".
|
|
165
|
+
settings.generation = generationPayload(value);
|
|
142
166
|
return settings;
|
|
143
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* The shared AI generation model, normalized for persistence.
|
|
170
|
+
*
|
|
171
|
+
* Auto-naming and auto-grouping only classify tools and print JSON, so both
|
|
172
|
+
* may run a fast model instead of a slow default one. A pinned route is
|
|
173
|
+
* stored as `{provider, model}`; an effort chosen while still running the
|
|
174
|
+
* default model is stored on its own, so the plugin keeps picking whatever
|
|
175
|
+
* the deployment default is and only overrides its reasoning effort.
|
|
176
|
+
*/
|
|
177
|
+
function generationPayload(value) {
|
|
178
|
+
const choice = value && value.generation;
|
|
179
|
+
if (!choice || typeof choice !== "object") return null;
|
|
180
|
+
const provider = typeof choice.provider === "string" ? choice.provider.trim() : "";
|
|
181
|
+
const model = typeof choice.model === "string" ? choice.model.trim() : "";
|
|
182
|
+
const reasoningEffort = typeof choice.reasoningEffort === "string" ? choice.reasoningEffort.trim() : "";
|
|
183
|
+
if (provider && model) return { provider, model, ...(reasoningEffort ? { reasoningEffort } : {}) };
|
|
184
|
+
if (reasoningEffort) return { reasoningEffort };
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The selection a generation request will run.
|
|
189
|
+
*
|
|
190
|
+
* A stored choice either pins a route or only overrides the effort of the
|
|
191
|
+
* default model; both end up here as one concrete provider/model/effort,
|
|
192
|
+
* which is what the picker shows and what the dialogs name.
|
|
193
|
+
*/
|
|
194
|
+
function effectiveGenerationModel(choice, fallback) {
|
|
195
|
+
const pinned = choice && choice.provider && choice.model ? choice : null;
|
|
196
|
+
const base = pinned || fallback;
|
|
197
|
+
if (!base || !base.provider || !base.model) return null;
|
|
198
|
+
const effort = pinned
|
|
199
|
+
? (choice.reasoningEffort || "")
|
|
200
|
+
: ((choice && choice.reasoningEffort) || (fallback && fallback.reasoningEffort) || "");
|
|
201
|
+
return { provider: base.provider, model: base.model, ...(effort ? { reasoningEffort: effort } : {}) };
|
|
202
|
+
}
|
|
203
|
+
/** Whether a selection is exactly the deployment default route. */
|
|
204
|
+
function isDefaultSelection(selection, fallback) {
|
|
205
|
+
return !!(selection && fallback && selection.provider === fallback.provider && selection.model === fallback.model);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The level a switched-to model should run, given the one in use before.
|
|
209
|
+
*
|
|
210
|
+
* Dropping the level whenever the new model does not declare it is what made
|
|
211
|
+
* switching models silently fall back to the deployment default's own level
|
|
212
|
+
* (Max here), which is the slowest possible outcome for a run the reader had
|
|
213
|
+
* just set to Off. The declared levels are ordered least to greatest, so the
|
|
214
|
+
* same relative position is carried over: Off on a four-step model lands on
|
|
215
|
+
* the cheapest step of a three-step one, Max still lands on Max.
|
|
216
|
+
*/
|
|
217
|
+
function carryReasoningEffort(previous, previousEfforts, nextEfforts, nextDefault) {
|
|
218
|
+
if (!previous) return "";
|
|
219
|
+
const ids = (list) => (list || []).map((effort) => effort.id);
|
|
220
|
+
const next = ids(nextEfforts);
|
|
221
|
+
if (next.length === 0) return "";
|
|
222
|
+
if (next.includes(previous)) return previous;
|
|
223
|
+
if (nextDefault && next.includes(nextDefault)) return nextDefault;
|
|
224
|
+
const from = ids(previousEfforts);
|
|
225
|
+
const index = from.indexOf(previous);
|
|
226
|
+
if (index < 0 || from.length < 2) return next[0];
|
|
227
|
+
const position = Math.round((index / (from.length - 1)) * (next.length - 1));
|
|
228
|
+
return next[Math.min(Math.max(position, 0), next.length - 1)];
|
|
229
|
+
}
|
|
230
|
+
/** One model picker value: JSON so provider/model ids may contain anything. */
|
|
231
|
+
function generationModelValue(choice) {
|
|
232
|
+
if (!choice || !choice.provider || !choice.model) return "";
|
|
233
|
+
return JSON.stringify([choice.provider, choice.model]);
|
|
234
|
+
}
|
|
235
|
+
/** Read a model picker value back; `""` means "follow the default model". */
|
|
236
|
+
function parseGenerationModelValue(value) {
|
|
237
|
+
if (typeof value !== "string" || !value) return null;
|
|
238
|
+
let parsed;
|
|
239
|
+
try {
|
|
240
|
+
parsed = JSON.parse(value);
|
|
241
|
+
} catch {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
if (!Array.isArray(parsed) || parsed.length !== 2) return null;
|
|
245
|
+
const [provider, model] = parsed;
|
|
246
|
+
if (typeof provider !== "string" || typeof model !== "string" || !provider || !model) return null;
|
|
247
|
+
return { provider, model };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Which model a generation request will run, named for the reader.
|
|
251
|
+
*
|
|
252
|
+
* The dialogs used to say "当前默认模型" unconditionally, which became wrong
|
|
253
|
+
* as soon as the generation model could be set separately. The name and the
|
|
254
|
+
* level come from the catalog when it lists them, so the sentence and the
|
|
255
|
+
* picker read the same: the sentence prints a level exactly when the picker
|
|
256
|
+
* has one selected.
|
|
257
|
+
*/
|
|
258
|
+
function generationTargetLabel(choice, fallback, catalog) {
|
|
259
|
+
const effective = effectiveGenerationModel(choice, fallback);
|
|
260
|
+
if (!effective) return "未配置的模型";
|
|
261
|
+
const entry = findModelEntry(catalog, effective);
|
|
262
|
+
const name = entry && entry.name ? entry.name : effective.provider + "/" + effective.model;
|
|
263
|
+
const chosen = effective.reasoningEffort || "";
|
|
264
|
+
const effort = chosen
|
|
265
|
+
? ((entry && entry.reasoning ? (entry.reasoning.efforts || []).find((item) => item.id === chosen) : null) || { name: chosen })
|
|
266
|
+
: null;
|
|
267
|
+
return "「" + name + (effort ? " · 推理 " + effort.name : "") + "」";
|
|
268
|
+
}
|
|
269
|
+
/** The catalog entry for a choice, or null when the catalog does not list it. */
|
|
270
|
+
function findModelEntry(catalog, choice) {
|
|
271
|
+
if (!catalog || !choice) return null;
|
|
272
|
+
for (const group of catalog.groups || []) {
|
|
273
|
+
if (group.id !== choice.provider) continue;
|
|
274
|
+
return (group.models || []).find((model) => model.id === choice.model) || null;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
144
278
|
function settingsSignature(value) {
|
|
145
279
|
return JSON.stringify(settingsPayload(value));
|
|
146
280
|
}
|
|
@@ -457,17 +591,38 @@ window.__ModuleLoader__.load({
|
|
|
457
591
|
"关掉后立刻对模型隐藏。按需组只声明组名与描述,组内工具不单独声明;模型用 tool_find 读取整组用法后可直接按名调用,不需要开组。",
|
|
458
592
|
"",
|
|
459
593
|
"tool_find 由插件自动注册,不出现在本页目录中,也不能在这里开关或分组;它只在当前 Preset 有有效按需组时出现。",
|
|
594
|
+
"",
|
|
595
|
+
"注意:部分供应商会限制工具调用名,此时 MCP 按需模式无法正常调用组内工具,请改用「默认」加载模式。",
|
|
460
596
|
].join("\n");
|
|
461
597
|
|
|
462
598
|
function toolCatalogHelp(mcpMode) {
|
|
463
599
|
return mcpMode ? TOOL_CATALOG_HELP_MCP : TOOL_CATALOG_HELP;
|
|
464
600
|
}
|
|
465
601
|
|
|
466
|
-
// One
|
|
467
|
-
//
|
|
468
|
-
//
|
|
469
|
-
const
|
|
470
|
-
|
|
602
|
+
// One help entry next to the mode label. Both mode explanations live
|
|
603
|
+
// there instead of on the chips, so the warning below covers the whole
|
|
604
|
+
// choice instead of looking like a property of one hovered button.
|
|
605
|
+
const LOADING_MODE_HELP = [
|
|
606
|
+
"默认:组内工具平时不声明;模型用 tool_list({ group }) 打开一组后,这组工具才进入工具表。",
|
|
607
|
+
"",
|
|
608
|
+
"MCP 按需:组内工具始终不进工具表;模型用 tool_find({ group }) 看整组参数,随时能按名字直接调用。",
|
|
609
|
+
"",
|
|
610
|
+
"注意:MCP 按需依赖模型能够直接发出未声明的工具名。部分供应商会限制工具调用名(例如 OpenCode Go),模型只能反复调用 tool_find,无法真正调用组内工具;遇到这种情况请改用「默认」加载模式。",
|
|
611
|
+
].join("\n");
|
|
612
|
+
|
|
613
|
+
// The generation model is a global choice, not a Preset one: auto-naming
|
|
614
|
+
// and auto-grouping classify tools and print JSON, so a fast model is
|
|
615
|
+
// usually enough even when the conversation runs a slow reasoning one.
|
|
616
|
+
// It is offered inside both dialogs that spend a request — 「自动分组」
|
|
617
|
+
// and the group editor's 「自动生成名称和描述」.
|
|
618
|
+
const GENERATION_MODEL_HELP = [
|
|
619
|
+
"「自动分组」和「手动分组」里生成名称、描述时共用的模型,对所有 Preset 生效。",
|
|
620
|
+
"",
|
|
621
|
+
"默认就是 DSH 当前的默认模型及其推理强度;也可以换成任意已注册的 Provider + 模型,并单独选推理强度,「模型默认」表示不额外指定。",
|
|
622
|
+
"",
|
|
623
|
+
"所选模型已不可用(被删除或未配置)时,生成会回退到默认模型并明确提示,不会静默失败。",
|
|
624
|
+
"改动立即写入配置文件,不需要再点「保存」。",
|
|
625
|
+
].join("\n");
|
|
471
626
|
|
|
472
627
|
function ToolManagerSection() {
|
|
473
628
|
const [snapshot, setSnapshot] = react.useState(null);
|
|
@@ -487,6 +642,10 @@ window.__ModuleLoader__.load({
|
|
|
487
642
|
const [aiConfirm, setAiConfirm] = react.useState(null);
|
|
488
643
|
const [suggestionTimeoutSeconds, setSuggestionTimeoutSeconds] = react.useState("60");
|
|
489
644
|
const [autoGroupTimeoutSeconds, setAutoGroupTimeoutSeconds] = react.useState("120");
|
|
645
|
+
const [models, setModels] = react.useState(null);
|
|
646
|
+
const [modelsError, setModelsError] = react.useState("");
|
|
647
|
+
const [generationSaveError, setGenerationSaveError] = react.useState("");
|
|
648
|
+
const [aiNotice, setAiNotice] = react.useState("");
|
|
490
649
|
|
|
491
650
|
const load = react.useCallback((attempt) => {
|
|
492
651
|
const tries = attempt || 0;
|
|
@@ -507,6 +666,15 @@ window.__ModuleLoader__.load({
|
|
|
507
666
|
}).finally(() => setBusy(false));
|
|
508
667
|
}, []);
|
|
509
668
|
react.useEffect(() => { load(); }, [load]);
|
|
669
|
+
// The picker is the only consumer of the model catalog, so a failure
|
|
670
|
+
// here leaves "跟随默认模型" usable instead of blocking the whole page.
|
|
671
|
+
react.useEffect(() => {
|
|
672
|
+
let live = true;
|
|
673
|
+
api("/models")
|
|
674
|
+
.then((value) => { if (live) { setModels(value); setModelsError(""); } })
|
|
675
|
+
.catch((e) => { if (live) setModelsError(String(e.message || e)); });
|
|
676
|
+
return () => { live = false; };
|
|
677
|
+
}, []);
|
|
510
678
|
const dirty = !!(snapshot && draft && settingsSignature(snapshot) !== settingsSignature(draft));
|
|
511
679
|
react.useEffect(() => {
|
|
512
680
|
if (!dirty) return undefined;
|
|
@@ -563,6 +731,103 @@ window.__ModuleLoader__.load({
|
|
|
563
731
|
});
|
|
564
732
|
}
|
|
565
733
|
|
|
734
|
+
/**
|
|
735
|
+
* Choose the shared generation model, or `null` to let the plugin pick.
|
|
736
|
+
*
|
|
737
|
+
* The choice is persisted right away — this setting belongs to no
|
|
738
|
+
* Preset, so waiting for 「保存」 would only ask the reader to save a page
|
|
739
|
+
* they did not change. The draft still moves first, so the picker and the
|
|
740
|
+
* next request see the choice even while the write is in flight.
|
|
741
|
+
*/
|
|
742
|
+
function setGenerationChoice(choice) {
|
|
743
|
+
setDraft((current) => {
|
|
744
|
+
if (!current) return current;
|
|
745
|
+
const next = clone(current);
|
|
746
|
+
if (choice) next.generation = { ...choice };
|
|
747
|
+
else delete next.generation;
|
|
748
|
+
return next;
|
|
749
|
+
});
|
|
750
|
+
setMessage("");
|
|
751
|
+
setAiNotice("");
|
|
752
|
+
persistGeneration(choice);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Write the generation model to the config file.
|
|
757
|
+
*
|
|
758
|
+
* It goes through its own route instead of the page save so it needs no
|
|
759
|
+
* page revision: the Preset policies a page may be drafting are untouched,
|
|
760
|
+
* and the store serializes this write with the next 「保存」.
|
|
761
|
+
*/
|
|
762
|
+
function persistGeneration(choice) {
|
|
763
|
+
setGenerationSaveError("");
|
|
764
|
+
api("/generation", {
|
|
765
|
+
method: "POST",
|
|
766
|
+
body: JSON.stringify({ generation: generationPayload({ generation: choice }) }),
|
|
767
|
+
}).then((result) => {
|
|
768
|
+
if (!result) return;
|
|
769
|
+
// The Host answered with the revision it ended up at. Adopt it so the
|
|
770
|
+
// next 「保存」 sends a revision the store still accepts; take the
|
|
771
|
+
// larger one when two writes of ours raced.
|
|
772
|
+
setSnapshot((current) => {
|
|
773
|
+
if (!current) return current;
|
|
774
|
+
const next = { ...current, revision: Math.max(current.revision || 0, result.revision || 0) };
|
|
775
|
+
if (result.generation) next.generation = { ...result.generation };
|
|
776
|
+
else delete next.generation;
|
|
777
|
+
return next;
|
|
778
|
+
});
|
|
779
|
+
setGenerationSaveError("");
|
|
780
|
+
}).catch((error) => {
|
|
781
|
+
setGenerationSaveError(String(error.message || error));
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Pick a model for both generation tasks.
|
|
787
|
+
*
|
|
788
|
+
* The chosen level travels with the switch whenever the new model can
|
|
789
|
+
* express it, because it describes how hard the classification should
|
|
790
|
+
* think, not which route runs it. Choosing the deployment default route
|
|
791
|
+
* stores no route at all: that keeps the plugin on whatever the default
|
|
792
|
+
* model becomes. Any other route is persisted.
|
|
793
|
+
*/
|
|
794
|
+
function chooseGenerationModel(value) {
|
|
795
|
+
const picked = parseGenerationModelValue(value);
|
|
796
|
+
if (!picked) return;
|
|
797
|
+
const entry = findModelEntry(models, picked);
|
|
798
|
+
const targetEfforts = entry && entry.reasoning ? entry.reasoning.efforts || [] : [];
|
|
799
|
+
const keep = carryReasoningEffort(
|
|
800
|
+
generationEffortValue,
|
|
801
|
+
generationEntry && generationEntry.reasoning ? generationEntry.reasoning.efforts || [] : [],
|
|
802
|
+
targetEfforts,
|
|
803
|
+
entry && entry.reasoning ? entry.reasoning.defaultEffort : undefined,
|
|
804
|
+
);
|
|
805
|
+
setGenerationChoice(isDefaultSelection(picked, defaultSelection)
|
|
806
|
+
? (keep ? { reasoningEffort: keep } : null)
|
|
807
|
+
: { provider: picked.provider, model: picked.model, ...(keep ? { reasoningEffort: keep } : {}) });
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Pick the reasoning level of whichever model the picker currently shows.
|
|
812
|
+
*
|
|
813
|
+
* The level is stored even while the model stays the default one, so the
|
|
814
|
+
* picker never has to be locked just because the route was not pinned.
|
|
815
|
+
* "默认" stores nothing, which keeps following whatever level the model
|
|
816
|
+
* or the deployment default already uses.
|
|
817
|
+
*/
|
|
818
|
+
function chooseGenerationEffort(reasoningEffort) {
|
|
819
|
+
if (!generationModel) return;
|
|
820
|
+
if (!isDefaultSelection(generationModel, defaultSelection)) {
|
|
821
|
+
setGenerationChoice({
|
|
822
|
+
provider: generationModel.provider,
|
|
823
|
+
model: generationModel.model,
|
|
824
|
+
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
825
|
+
});
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
setGenerationChoice(reasoningEffort ? { reasoningEffort } : null);
|
|
829
|
+
}
|
|
830
|
+
|
|
566
831
|
function openCreate() {
|
|
567
832
|
setModal({
|
|
568
833
|
mode: "create",
|
|
@@ -578,9 +843,9 @@ window.__ModuleLoader__.load({
|
|
|
578
843
|
|
|
579
844
|
function resetPresetConfig() {
|
|
580
845
|
if (!hasPresetConfig) return;
|
|
581
|
-
if (!window.confirm("确定重置当前 Preset
|
|
846
|
+
if (!window.confirm("确定重置当前 Preset 的配置吗?这会清空它的全部按需组和已关闭工具,加载模式保持不变;只修改页面草稿,保存后生效。")) return;
|
|
582
847
|
mutatePreset((target) => {
|
|
583
|
-
target.policy =
|
|
848
|
+
target.policy = resetPresetPolicy(target.policy);
|
|
584
849
|
});
|
|
585
850
|
setQuery("");
|
|
586
851
|
setFilter("all");
|
|
@@ -620,7 +885,7 @@ window.__ModuleLoader__.load({
|
|
|
620
885
|
if (target.id === source.id || !selected.has(target.id) || target.broken) continue;
|
|
621
886
|
const copied = copyPresetPolicy(source, target);
|
|
622
887
|
const before = JSON.stringify(policyPayload(target.policy));
|
|
623
|
-
const after = JSON.stringify(policyPayload(
|
|
888
|
+
const after = JSON.stringify(policyPayload(copied));
|
|
624
889
|
plans.push({ targetId: target.id, label: target.name || target.id, copied, changed: before !== after });
|
|
625
890
|
}
|
|
626
891
|
if (!plans.length) { setCopyDialog(null); return; }
|
|
@@ -632,6 +897,7 @@ window.__ModuleLoader__.load({
|
|
|
632
897
|
target.policy = {
|
|
633
898
|
disabled: [...plan.copied.disabled],
|
|
634
899
|
groups: plan.copied.groups.map((group) => ({ ...group, _key: newKey() })),
|
|
900
|
+
...(plan.copied.mode ? { mode: plan.copied.mode } : {}),
|
|
635
901
|
};
|
|
636
902
|
}
|
|
637
903
|
return next;
|
|
@@ -701,7 +967,6 @@ window.__ModuleLoader__.load({
|
|
|
701
967
|
setAiConfirm({
|
|
702
968
|
kind: "suggest",
|
|
703
969
|
title: "确认自动生成名称和描述",
|
|
704
|
-
message: "将所选工具的名称和描述发送给当前默认模型,并产生一次模型请求。",
|
|
705
970
|
timeoutSeconds: suggestionTimeoutSeconds,
|
|
706
971
|
prompt: initialPrompt,
|
|
707
972
|
promptCustom: false,
|
|
@@ -709,13 +974,16 @@ window.__ModuleLoader__.load({
|
|
|
709
974
|
error: "",
|
|
710
975
|
run: (timeoutMs, _tools, prompt) => {
|
|
711
976
|
setSuggestionTimeoutSeconds(String(timeoutMs / 1000));
|
|
712
|
-
|
|
977
|
+
setAiNotice("");
|
|
978
|
+
patchModal({ generating: true, generateError: "", generateNotice: "" });
|
|
713
979
|
api("/suggest-group", {
|
|
714
980
|
method: "POST",
|
|
715
|
-
body: JSON.stringify({ presetId: preset.id, toolNames, otherGroupNames, timeoutMs, prompt }),
|
|
981
|
+
body: JSON.stringify({ presetId: preset.id, toolNames, otherGroupNames, timeoutMs, prompt, generation: generationPayload(draft) }),
|
|
716
982
|
}).then((suggestion) => {
|
|
983
|
+
const notice = suggestion.modelNotice ? String(suggestion.modelNotice) : "";
|
|
984
|
+
if (notice) setAiNotice(notice);
|
|
717
985
|
setModal((current) => current && current.key === key
|
|
718
|
-
? { ...current, name: suggestion.name || current.name, description: suggestion.description || current.description, generating: false, generateError: "" }
|
|
986
|
+
? { ...current, name: suggestion.name || current.name, description: suggestion.description || current.description, generating: false, generateError: "", generateNotice: notice }
|
|
719
987
|
: current);
|
|
720
988
|
}).catch((e) => {
|
|
721
989
|
setModal((current) => current && current.key === key
|
|
@@ -772,7 +1040,6 @@ window.__ModuleLoader__.load({
|
|
|
772
1040
|
setAiConfirm({
|
|
773
1041
|
kind: "auto-group",
|
|
774
1042
|
title: "确认自动分组",
|
|
775
|
-
message: "筛选并勾选需要分组的工具,发送给当前默认模型进行聚类。",
|
|
776
1043
|
timeoutSeconds: autoGroupTimeoutSeconds,
|
|
777
1044
|
query: "",
|
|
778
1045
|
selected: allCandidateNames,
|
|
@@ -782,13 +1049,15 @@ window.__ModuleLoader__.load({
|
|
|
782
1049
|
error: "",
|
|
783
1050
|
run: (timeoutMs, selectedToolNames, prompt) => {
|
|
784
1051
|
setAutoGroupTimeoutSeconds(String(timeoutMs / 1000));
|
|
785
|
-
setAutoGrouping(true); setAutoGroupError(""); setAutoPreview(null);
|
|
1052
|
+
setAutoGrouping(true); setAutoGroupError(""); setAutoPreview(null); setAiNotice("");
|
|
786
1053
|
const signature = autoGroupSignature(selectedToolNames, otherGroupNames);
|
|
787
1054
|
api("/auto-group", {
|
|
788
1055
|
method: "POST",
|
|
789
|
-
body: JSON.stringify({ presetId: preset.id, toolNames: selectedToolNames, otherGroupNames, timeoutMs, prompt }),
|
|
1056
|
+
body: JSON.stringify({ presetId: preset.id, toolNames: selectedToolNames, otherGroupNames, timeoutMs, prompt, generation: generationPayload(draft) }),
|
|
790
1057
|
}).then((result) => {
|
|
791
|
-
|
|
1058
|
+
const notice = result.modelNotice ? String(result.modelNotice) : "";
|
|
1059
|
+
if (notice) setAiNotice(notice);
|
|
1060
|
+
setAutoPreview({ presetId: preset.id, signature, selectedTools: selectedToolNames, groups: result.groups || [], ungrouped: result.ungrouped || [], notice });
|
|
792
1061
|
}).catch((e) => setAutoGroupError(String(e.message || e))).finally(() => setAutoGrouping(false));
|
|
793
1062
|
},
|
|
794
1063
|
});
|
|
@@ -882,7 +1151,7 @@ window.__ModuleLoader__.load({
|
|
|
882
1151
|
api("/save", { method: "POST", body: JSON.stringify({ expectedRevision: snapshot.revision, settings }) })
|
|
883
1152
|
.then((value) => {
|
|
884
1153
|
const next = withGroupKeys(value);
|
|
885
|
-
setSnapshot(value); setDraft(next); setModal(null); setCopyDialog(null);
|
|
1154
|
+
setSnapshot(value); setDraft(next); setModal(null); setCopyDialog(null); setAiNotice("");
|
|
886
1155
|
setMessage("已保存;运行中 Agent 将从下一个模型步骤应用新策略。");
|
|
887
1156
|
})
|
|
888
1157
|
.catch((e) => setError(String(e.message || e)))
|
|
@@ -892,6 +1161,28 @@ window.__ModuleLoader__.load({
|
|
|
892
1161
|
const disabled = new Set(preset.policy.disabled || []);
|
|
893
1162
|
const grouped = groupedNames(preset);
|
|
894
1163
|
const mcpMode = preset.policy.mode === "mcp";
|
|
1164
|
+
const generationChoice = draft.generation || null;
|
|
1165
|
+
const defaultSelection = draft.defaultSelection || null;
|
|
1166
|
+
// What the next request will actually run: a pinned model, else the
|
|
1167
|
+
// deployment default one. The picker always shows a concrete model, so
|
|
1168
|
+
// there is no "follow the default" row to read.
|
|
1169
|
+
const generationModel = effectiveGenerationModel(generationChoice, defaultSelection);
|
|
1170
|
+
const generationEntry = findModelEntry(models, generationModel);
|
|
1171
|
+
// A provider whose own catalog failed tells us nothing about its models,
|
|
1172
|
+
// so only a readable catalog that simply lacks the model is proof.
|
|
1173
|
+
const generationCatalogFailed = !!(models && generationModel
|
|
1174
|
+
&& (models.failures || []).some((item) => item.id === generationModel.provider));
|
|
1175
|
+
const generationUnavailable = !!(generationModel && models && !generationEntry && !generationCatalogFailed);
|
|
1176
|
+
const generationEfforts = generationEntry && generationEntry.reasoning
|
|
1177
|
+
? generationEntry.reasoning.efforts || []
|
|
1178
|
+
: [];
|
|
1179
|
+
// The dropdown shows the level in effect, so "默认" is only shown while no
|
|
1180
|
+
// level is in effect at all. Following the deployment default model means
|
|
1181
|
+
// running ITS level, so the select reads Max there rather than "默认".
|
|
1182
|
+
const generationEffortValue = generationModel && generationModel.reasoningEffort
|
|
1183
|
+
? generationModel.reasoningEffort
|
|
1184
|
+
: "";
|
|
1185
|
+
const generationLabel = generationTargetLabel(generationChoice, defaultSelection, models);
|
|
895
1186
|
const saveBlocked = saveBlockReason({ busy, autoGrouping, writable: draft.writable, dirty });
|
|
896
1187
|
const errorPreset = errorPresetId(error, (draft.presets || []).map((item) => item.id));
|
|
897
1188
|
const autoGroupCandidates = (preset.tools || []).filter((tool) => !disabled.has(tool.name) && !grouped.has(tool.name));
|
|
@@ -1012,12 +1303,129 @@ window.__ModuleLoader__.load({
|
|
|
1012
1303
|
);
|
|
1013
1304
|
}
|
|
1014
1305
|
|
|
1306
|
+
/**
|
|
1307
|
+
* The confirm text, derived at render time so it follows the picker.
|
|
1308
|
+
*
|
|
1309
|
+
* It used to be frozen when the dialog opened, which made the headline
|
|
1310
|
+
* lie as soon as the model was changed in the dialog it describes.
|
|
1311
|
+
*/
|
|
1312
|
+
function aiConfirmMessage() {
|
|
1313
|
+
if (!aiConfirm) return "";
|
|
1314
|
+
return aiConfirm.kind === "auto-group"
|
|
1315
|
+
? "筛选并勾选需要分组的工具,发送给" + generationLabel + "进行聚类。"
|
|
1316
|
+
: "将所选工具的名称和描述发送给" + generationLabel + ",并产生一次模型请求。";
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* The shared generation model control, rendered inside a dialog.
|
|
1321
|
+
*
|
|
1322
|
+
* It belongs to whichever dialog is about to spend a model request —
|
|
1323
|
+
* 「自动分组」 and 「手动分组」 — so the reader can shrink the model right
|
|
1324
|
+
* where the cost is about to happen. Both dialogs edit one value. The
|
|
1325
|
+
* model and its reasoning effort share one line: the effort only matters
|
|
1326
|
+
* for the model next to it.
|
|
1327
|
+
*/
|
|
1328
|
+
function renderGenerationPicker() {
|
|
1329
|
+
const pinned = !!(generationChoice && generationChoice.provider && generationChoice.model);
|
|
1330
|
+
const listed = !!generationEntry;
|
|
1331
|
+
// A reader recognises the provider's own display name, not a route, so
|
|
1332
|
+
// the option text is just that name. The provider is appended only when
|
|
1333
|
+
// two routes would read identically; the route itself is the tooltip.
|
|
1334
|
+
const catalogGroups = models ? models.groups || [] : [];
|
|
1335
|
+
const displayName = (model) => (model.name && model.name !== model.id ? model.name : model.id);
|
|
1336
|
+
const nameCounts = new Map();
|
|
1337
|
+
for (const group of catalogGroups) {
|
|
1338
|
+
for (const model of group.models || []) {
|
|
1339
|
+
const name = displayName(model);
|
|
1340
|
+
nameCounts.set(name, (nameCounts.get(name) || 0) + 1);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const modelOptions = catalogGroups.map((group) => h("optgroup", {
|
|
1344
|
+
key: group.id,
|
|
1345
|
+
label: group.name || group.id,
|
|
1346
|
+
}, (group.models || []).map((model) => {
|
|
1347
|
+
const name = displayName(model);
|
|
1348
|
+
const unique = nameCounts.get(name) === 1;
|
|
1349
|
+
return h("option", {
|
|
1350
|
+
key: model.id,
|
|
1351
|
+
value: generationModelValue({ provider: group.id, model: model.id }),
|
|
1352
|
+
title: group.id + "/" + model.id,
|
|
1353
|
+
}, unique || !group.name ? name : name + " · " + group.name);
|
|
1354
|
+
})));
|
|
1355
|
+
// The effective model may not be in the catalog: the default route can
|
|
1356
|
+
// be unlisted, a saved route can be gone, and the catalog can still be
|
|
1357
|
+
// loading. Keep it selectable so the row never shows a wrong model.
|
|
1358
|
+
const unlistedLabel = generationModel
|
|
1359
|
+
? generationModel.provider + "/" + generationModel.model + (pinned ? "(当前不可用)" : "")
|
|
1360
|
+
: "";
|
|
1361
|
+
// An effort the catalog does not list for this route still has to be
|
|
1362
|
+
// readable, otherwise the closed select would show a different level.
|
|
1363
|
+
const undeclaredLevel = listed && generationEffortValue
|
|
1364
|
+
&& !generationEfforts.some((effort) => effort.id === generationEffortValue)
|
|
1365
|
+
? generationEffortValue
|
|
1366
|
+
: "";
|
|
1367
|
+
return h("div", { className: "tm_model_block", key: "generation" },
|
|
1368
|
+
h("div", { className: "tm_model_row" },
|
|
1369
|
+
h("span", { className: "tm_model_label", title: GENERATION_MODEL_HELP, key: "modelLabel" }, "生成模型"),
|
|
1370
|
+
h("span", { className: "tm_select_wrap tm_model_pick", key: "modelPick" },
|
|
1371
|
+
h("select", {
|
|
1372
|
+
className: "tm_preset_select",
|
|
1373
|
+
value: generationModelValue(generationModel),
|
|
1374
|
+
disabled: busy || !generationModel,
|
|
1375
|
+
title: "自动命名与自动分组共用的模型,默认是 DSH 当前的默认模型。选一个快速模型可以明显缩短生成时间。",
|
|
1376
|
+
onChange: (event) => chooseGenerationModel(event.target.value),
|
|
1377
|
+
},
|
|
1378
|
+
!generationModel ? h("option", { value: "" }, "没有可用的默认模型") : null,
|
|
1379
|
+
modelOptions,
|
|
1380
|
+
generationModel && !listed ? h("option", { value: generationModelValue(generationModel) }, unlistedLabel) : null,
|
|
1381
|
+
),
|
|
1382
|
+
),
|
|
1383
|
+
listed
|
|
1384
|
+
? [
|
|
1385
|
+
h("span", {
|
|
1386
|
+
className: "tm_model_label",
|
|
1387
|
+
key: "effortLabel",
|
|
1388
|
+
title: "该模型的推理强度,这里显示的就是本次请求会发送的档位。",
|
|
1389
|
+
}, "推理强度"),
|
|
1390
|
+
h("span", { className: "tm_select_wrap tm_effort_pick", key: "effortPick" },
|
|
1391
|
+
h("select", {
|
|
1392
|
+
className: "tm_preset_select",
|
|
1393
|
+
value: generationEffortValue,
|
|
1394
|
+
disabled: busy || !generationModel,
|
|
1395
|
+
title: "该模型的推理强度。「默认」表示不额外指定,用模型(或 DSH 默认模型)本来的档位。",
|
|
1396
|
+
onChange: (event) => chooseGenerationEffort(event.target.value),
|
|
1397
|
+
},
|
|
1398
|
+
h("option", { value: "" }, "默认"),
|
|
1399
|
+
generationEfforts.map((effort) => h("option", { key: effort.id, value: effort.id }, effort.name)),
|
|
1400
|
+
undeclaredLevel ? h("option", { value: undeclaredLevel }, undeclaredLevel) : null,
|
|
1401
|
+
),
|
|
1402
|
+
),
|
|
1403
|
+
]
|
|
1404
|
+
: h("span", { className: "tm_muted", key: "effortMissing", title: "读不到这个模型的推理强度列表,暂时不能指定。" }, "读不到该模型的推理强度"),
|
|
1405
|
+
),
|
|
1406
|
+
generationSaveError ? h("div", { className: "tm_error" }, "保存失败:" + generationSaveError) : null,
|
|
1407
|
+
generationUnavailable
|
|
1408
|
+
? h("div", { className: "tm_model_hints" },
|
|
1409
|
+
h("span", { className: "tm_badge off", title: "生成时会自动回退到默认模型,并提示原因" }, "该模型当前不可用"),
|
|
1410
|
+
h("span", { className: "tm_muted" }, "生成时会改用默认模型,并提示原因。"),
|
|
1411
|
+
)
|
|
1412
|
+
: null,
|
|
1413
|
+
modelsError
|
|
1414
|
+
? h("div", { className: "tm_muted" }, "模型列表读取失败:" + modelsError)
|
|
1415
|
+
: (models && (models.failures || []).length
|
|
1416
|
+
? h("div", {
|
|
1417
|
+
className: "tm_muted",
|
|
1418
|
+
title: models.failures.map((item) => item.name + ":" + item.message).join("\n"),
|
|
1419
|
+
}, "有 " + models.failures.length + " 个 Provider 的模型列表读取失败,未列出其模型。")
|
|
1420
|
+
: null),
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1015
1423
|
const aiConfirmDialog = aiConfirm && typeof document !== "undefined" ? reactDom.createPortal(
|
|
1016
1424
|
h("div", { className: "tm_modal", role: "dialog", "aria-modal": "true", "aria-label": aiConfirm.title },
|
|
1017
1425
|
h("div", { className: "tm_modal_mask", onMouseDown: () => setAiConfirm(null) }),
|
|
1018
1426
|
h("div", { className: "tm_modal_card" },
|
|
1019
1427
|
h("div", { className: "tm_modal_head" },
|
|
1020
|
-
h("div", null, h("h3", null, aiConfirm.title), h("div", { className: "tm_muted" },
|
|
1428
|
+
h("div", null, h("h3", null, aiConfirm.title), h("div", { className: "tm_muted" }, aiConfirmMessage())),
|
|
1021
1429
|
h("button", { className: "tm_btn", onClick: () => setAiConfirm(null) }, "关闭"),
|
|
1022
1430
|
),
|
|
1023
1431
|
h("div", { className: "tm_modal_body" },
|
|
@@ -1042,7 +1450,7 @@ window.__ModuleLoader__.load({
|
|
|
1042
1450
|
),
|
|
1043
1451
|
aiSelected.size === 0
|
|
1044
1452
|
? h("div", { className: "tm_error", key: "status" }, "请至少勾选一个工具进行分组。")
|
|
1045
|
-
: h("div", { className: "tm_muted", key: "status" }, "已勾选 " + aiSelected.size + " / " + aiCandidates.length + "
|
|
1453
|
+
: h("div", { className: "tm_muted", key: "status" }, "已勾选 " + aiSelected.size + " / " + aiCandidates.length + " 个候选工具。自动分组会调用" + generationLabel + ",结果仍可手动修改。"),
|
|
1046
1454
|
aiVisibleCandidates.length
|
|
1047
1455
|
? h("div", { className: "tm_picker", key: "picker" }, aiVisibleCandidates.map((tool) => h("label", { className: "tm_pick", key: tool.name },
|
|
1048
1456
|
h("input", {
|
|
@@ -1060,6 +1468,7 @@ window.__ModuleLoader__.load({
|
|
|
1060
1468
|
),
|
|
1061
1469
|
)))
|
|
1062
1470
|
: h("div", { className: "tm_muted", key: "empty", style: { padding: "12px" } }, aiCandidates.length ? "没有符合筛选的工具。" : "当前没有可分组的工具。"),
|
|
1471
|
+
renderGenerationPicker(),
|
|
1063
1472
|
] : null,
|
|
1064
1473
|
h("div", {
|
|
1065
1474
|
style: {
|
|
@@ -1185,7 +1594,9 @@ window.__ModuleLoader__.load({
|
|
|
1185
1594
|
h("input", { className: "tm_input", value: modal.name, placeholder: "名称(模型用这个打开)", onChange: (e) => patchModal({ name: e.target.value, generateError: "" }) }),
|
|
1186
1595
|
h("button", { className: "tm_btn", disabled: modal.generating || modalMatchedTools.length === 0 || modalInvalidSelected.length > 0, onClick: generateGroupDetails }, modal.generating ? "生成中…" : "自动生成名称和描述"),
|
|
1187
1596
|
),
|
|
1597
|
+
renderGenerationPicker(),
|
|
1188
1598
|
modal.generateError ? h("div", { className: "tm_error" }, modal.generateError) : null,
|
|
1599
|
+
modal.generateNotice ? h("div", { className: "tm_notice" }, modal.generateNotice) : null,
|
|
1189
1600
|
h("textarea", { className: "tm_input", style: { width: "100%", minHeight: "72px", resize: "vertical" }, value: modal.description, placeholder: "描述(可选)", onChange: (e) => patchModal({ description: e.target.value, generateError: "" }) }),
|
|
1190
1601
|
h("div", { className: "tm_row" },
|
|
1191
1602
|
h("input", { className: "tm_input", value: modal.query, placeholder: "筛选工具名或描述", onChange: (e) => patchModal({ query: e.target.value }) }),
|
|
@@ -1195,7 +1606,7 @@ window.__ModuleLoader__.load({
|
|
|
1195
1606
|
modalInvalidSelected.length
|
|
1196
1607
|
? h("div", { className: "tm_error" }, "以下工具已关闭或属于其他分组,不能加入当前组:" + modalInvalidSelected.join(", ") + "。请取消选择。")
|
|
1197
1608
|
: h("div", { className: modalMatchedTools.length ? "tm_muted" : "tm_error" }, modalMatchedTools.length
|
|
1198
|
-
? "已选 " + modalMatchedTools.length + "
|
|
1609
|
+
? "已选 " + modalMatchedTools.length + " 个工具。自动生成会调用" + generationLabel + ",结果仍可手动修改。"
|
|
1199
1610
|
: "每个按需组至少需要一个未关闭且未被其他组占用的工具。"),
|
|
1200
1611
|
pickerTools.length
|
|
1201
1612
|
? h("div", { className: "tm_picker" }, pickerTools.map((tool) => h("label", { className: "tm_pick", key: tool.name },
|
|
@@ -1240,6 +1651,7 @@ window.__ModuleLoader__.load({
|
|
|
1240
1651
|
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 + " 个工具")),
|
|
1241
1652
|
h("div", { style: { padding: "10px 14px" } }, group.tools.map((name) => h("div", { className: "tm_member tm_tool_name", key: name }, name))),
|
|
1242
1653
|
)),
|
|
1654
|
+
autoPreview.notice ? h("div", { className: "tm_notice" }, autoPreview.notice) : null,
|
|
1243
1655
|
autoPreview.ungrouped.length ? h("div", { className: "tm_notice" }, "保持常开、未归组:", h("span", { className: "tm_code" }, autoPreview.ungrouped.join(", "))) : null,
|
|
1244
1656
|
),
|
|
1245
1657
|
h("div", { className: "tm_modal_foot" },
|
|
@@ -1258,16 +1670,17 @@ window.__ModuleLoader__.load({
|
|
|
1258
1670
|
h("div", { className: "tm_modal_head" },
|
|
1259
1671
|
h("div", null,
|
|
1260
1672
|
h("h3", null, "复制当前 Preset 配置"),
|
|
1261
|
-
h("div", { className: "tm_muted" }, "将当前 Preset 的全部按需组和已关闭工具复制到勾选的 Preset
|
|
1673
|
+
h("div", { className: "tm_muted" }, "将当前 Preset 的全部按需组和已关闭工具复制到勾选的 Preset;加载模式不跟随复制,各 Preset 保持自己的「默认 / MCP 按需」设置;只改页面草稿,保存后生效。"),
|
|
1262
1674
|
),
|
|
1263
1675
|
h("button", { className: "tm_btn", onClick: () => setCopyDialog(null) }, "关闭"),
|
|
1264
1676
|
),
|
|
1265
1677
|
h("div", { className: "tm_modal_body" },
|
|
1266
1678
|
h("div", { className: "tm_notice" },
|
|
1267
|
-
"源 Preset「" + (copySource.name || copySource.id) + "
|
|
1679
|
+
"源 Preset「" + (copySource.name || copySource.id) + "」(加载模式:"
|
|
1680
|
+
+ (copySource.policy.mode === "mcp" ? "MCP 按需" : "默认") + "):"
|
|
1268
1681
|
+ (copySource.policy.groups || []).length + " 个按需组、"
|
|
1269
1682
|
+ (copySource.policy.disabled || []).length + " 个已关闭工具。"
|
|
1270
|
-
+ "勾选的目标 Preset
|
|
1683
|
+
+ "勾选的目标 Preset 现有分组和关闭项将被整份覆盖,加载模式不变。",
|
|
1271
1684
|
),
|
|
1272
1685
|
h("div", { className: "tm_row" },
|
|
1273
1686
|
h("button", {
|
|
@@ -1282,6 +1695,7 @@ window.__ModuleLoader__.load({
|
|
|
1282
1695
|
? h("div", { className: "tm_picker" }, copyPreviewRows.map(({ target, preview }) => {
|
|
1283
1696
|
const currentGroups = (target.policy.groups || []).length;
|
|
1284
1697
|
const currentDisabled = (target.policy.disabled || []).length;
|
|
1698
|
+
const targetMode = target.policy.mode === "mcp" ? "MCP 按需" : "默认";
|
|
1285
1699
|
const meta = target.broken
|
|
1286
1700
|
? "工具目录读取失败,暂不能复制"
|
|
1287
1701
|
: "现有 " + currentGroups + " 个组 / " + currentDisabled + " 个关闭项 → 将复制 "
|
|
@@ -1289,6 +1703,7 @@ window.__ModuleLoader__.load({
|
|
|
1289
1703
|
+ (preview.skippedGroups.length
|
|
1290
1704
|
? ";跳过 " + preview.skippedGroups.length + " 个组:" + preview.skippedGroups.join("、")
|
|
1291
1705
|
: "")
|
|
1706
|
+
+ ";加载模式保持「" + targetMode + "」"
|
|
1292
1707
|
+ ((target.tools || []).length === 0 ? ";目标没有可见工具,复制后配置为空" : "");
|
|
1293
1708
|
return h("label", { className: "tm_pick", key: target.id },
|
|
1294
1709
|
h("input", {
|
|
@@ -1357,7 +1772,7 @@ window.__ModuleLoader__.load({
|
|
|
1357
1772
|
className: "tm_preset_select",
|
|
1358
1773
|
value: preset.id,
|
|
1359
1774
|
disabled: autoGrouping,
|
|
1360
|
-
onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setCopyDialog(null); setAutoGroupError(""); setExpanded({}); },
|
|
1775
|
+
onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setCopyDialog(null); setAutoGroupError(""); setAiNotice(""); setExpanded({}); },
|
|
1361
1776
|
}, draft.presets.map((item) => h("option", { key: item.id, value: item.id }, (item.name || item.id) + " · " + (item.tools || []).length + " 个工具" + (item.isDefault ? " · 默认" : "") + (item.trust === "user" ? " · 用户" : "") + (item.id === errorPreset ? " · 保存失败" : "")))),
|
|
1362
1777
|
),
|
|
1363
1778
|
preset.broken ? null
|
|
@@ -1366,26 +1781,27 @@ window.__ModuleLoader__.load({
|
|
|
1366
1781
|
: h("span", { className: "tm_badge native", title: "本 Preset 走原生 tool-calling:工具以 JSON schema 随请求发送,token 按 JSON ÷4 估算" }, "原生"),
|
|
1367
1782
|
),
|
|
1368
1783
|
h("div", { className: "tm_row", style: { padding: "0 14px 10px" } },
|
|
1369
|
-
h("span", { className: "tm_muted" }, "加载模式"),
|
|
1370
|
-
h("button", { className: "tm_chip" + (mcpMode ? "" : " active"), onClick: () => setMode("groups")
|
|
1371
|
-
h("button", { className: "tm_chip" + (mcpMode ? " active" : ""), onClick: () => setMode("mcp")
|
|
1784
|
+
h("span", { className: "tm_muted", style: { position: "relative" } }, "加载模式", h("span", { className: "tm_help", tabIndex: 0, "aria-label": "加载模式说明", "data-tip": LOADING_MODE_HELP }, "?")),
|
|
1785
|
+
h("button", { className: "tm_chip" + (mcpMode ? "" : " active"), onClick: () => setMode("groups") }, "默认"),
|
|
1786
|
+
h("button", { className: "tm_chip" + (mcpMode ? " active" : ""), onClick: () => setMode("mcp") }, "MCP 按需"),
|
|
1372
1787
|
),
|
|
1373
1788
|
preset.broken ? h("div", { className: "tm_error" }, preset.broken) : null,
|
|
1374
1789
|
autoGroupError ? h("div", { className: "tm_error" }, autoGroupError) : null,
|
|
1790
|
+
aiNotice ? h("div", { className: "tm_notice" }, aiNotice) : null,
|
|
1375
1791
|
h("section", { className: "tm_panel" },
|
|
1376
1792
|
h("div", { className: "tm_panel_head" },
|
|
1377
1793
|
h("div", null,
|
|
1378
1794
|
h("b", null, "工具目录", h("span", { className: "tm_help", tabIndex: 0, "aria-label": "工具目录说明", "data-tip": toolCatalogHelp(mcpMode) }, "?")),
|
|
1379
1795
|
),
|
|
1380
1796
|
h("div", { className: "tm_row" },
|
|
1381
|
-
h("button", { className: "tm_btn", onClick: startAutoGroup, disabled: autoGrouping || autoGroupCandidates.length === 0, title: autoGroupCandidates.length ? "
|
|
1797
|
+
h("button", { className: "tm_btn", onClick: startAutoGroup, disabled: autoGrouping || autoGroupCandidates.length === 0, title: autoGroupCandidates.length ? "用" + generationLabel + "对未分组且未关闭的工具进行聚类" : "没有可自动分组的工具" }, autoGrouping ? "自动分组中…" : "自动分组"),
|
|
1382
1798
|
h("button", { className: "tm_btn", onClick: openCreate, disabled: autoGrouping }, "手动分组"),
|
|
1383
1799
|
h("button", {
|
|
1384
1800
|
className: "tm_btn",
|
|
1385
1801
|
onClick: resetPresetConfig,
|
|
1386
1802
|
disabled: autoGrouping || busy || !draft.writable || !hasPresetConfig,
|
|
1387
1803
|
title: hasPresetConfig
|
|
1388
|
-
? "清空当前 Preset
|
|
1804
|
+
? "清空当前 Preset 的全部按需组和已关闭工具(加载模式保持不变)"
|
|
1389
1805
|
: "当前 Preset 没有可重置的配置",
|
|
1390
1806
|
}, "重置配置"),
|
|
1391
1807
|
h("button", {
|
|
@@ -1393,7 +1809,7 @@ window.__ModuleLoader__.load({
|
|
|
1393
1809
|
onClick: openCopyDialog,
|
|
1394
1810
|
disabled: autoGrouping || busy || !draft.writable || !hasPresetConfig || copyTargetCount === 0,
|
|
1395
1811
|
title: hasPresetConfig
|
|
1396
|
-
? "把当前 Preset 的分组和已关闭工具复制到其他 Preset"
|
|
1812
|
+
? "把当前 Preset 的分组和已关闭工具复制到其他 Preset(加载模式不复制)"
|
|
1397
1813
|
: "当前 Preset 没有可复制的分组或已关闭工具",
|
|
1398
1814
|
}, "复制配置"),
|
|
1399
1815
|
),
|
|
@@ -1458,6 +1874,19 @@ window.__ModuleLoader__.load({
|
|
|
1458
1874
|
// Pure policy projection, exported for unit tests. DSH only consumes
|
|
1459
1875
|
// apply/inject, so this does not widen the client plugin contract.
|
|
1460
1876
|
exports.copyPresetPolicy = copyPresetPolicy;
|
|
1877
|
+
exports.resetPresetPolicy = resetPresetPolicy;
|
|
1878
|
+
// Generation-model projections, exported for unit tests: the persisted
|
|
1879
|
+
// payload, the picker's value codec, the effective selection the picker
|
|
1880
|
+
// shows, and the label the dialogs print.
|
|
1881
|
+
exports.settingsPayload = settingsPayload;
|
|
1882
|
+
exports.generationPayload = generationPayload;
|
|
1883
|
+
exports.effectiveGenerationModel = effectiveGenerationModel;
|
|
1884
|
+
exports.isDefaultSelection = isDefaultSelection;
|
|
1885
|
+
exports.carryReasoningEffort = carryReasoningEffort;
|
|
1886
|
+
exports.generationModelValue = generationModelValue;
|
|
1887
|
+
exports.parseGenerationModelValue = parseGenerationModelValue;
|
|
1888
|
+
exports.generationTargetLabel = generationTargetLabel;
|
|
1889
|
+
exports.findModelEntry = findModelEntry;
|
|
1461
1890
|
// Save-guard projections, exported for unit tests. The button's disabled
|
|
1462
1891
|
// state and the error banner both used to hide which Preset or which
|
|
1463
1892
|
// condition was involved; these make that answerable without a DOM.
|