@klarkxy/dsh-current-title 0.3.1 → 0.3.3
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/README.md +7 -4
- package/docs/README.zh-CN.md +8 -5
- package/lib/client.inner.cjs +965 -280
- package/lib/client.inner.cjs.map +1 -1
- package/lib/client.js +965 -280
- package/lib/contracts.d.ts +53 -3
- package/lib/contracts.js +2 -55
- package/lib/contracts2.d.ts +2 -0
- package/lib/contracts2.js +105 -0
- package/lib/contracts2.js.map +1 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +904 -11
- package/lib/index.js.map +1 -1
- package/package.json +8 -5
- package/lib/contracts.js.map +0 -1
package/lib/client.inner.cjs
CHANGED
|
@@ -3,6 +3,206 @@ let react = require("react");
|
|
|
3
3
|
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
4
4
|
let react_dom = require("react-dom");
|
|
5
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
//#region ../dsh-model-route/src/catalog.ts
|
|
7
|
+
/** Both services are required: Cordis checks the nested namespace separately. */
|
|
8
|
+
const MODEL_CATALOG_INJECT = ["remote", "remote.session"];
|
|
9
|
+
function asRecord(value) {
|
|
10
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
11
|
+
}
|
|
12
|
+
function asText(value) {
|
|
13
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
14
|
+
}
|
|
15
|
+
/** A useful diagnostic even when a transport rejects with a plain object. */
|
|
16
|
+
function modelCatalogErrorMessage(value) {
|
|
17
|
+
if (value instanceof Error && value.message) return value.message;
|
|
18
|
+
return asText(asRecord(value)?.message) ?? asText(value) ?? "Unable to load the model catalog.";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validate and unwrap a successful catalog without discarding provider failures
|
|
22
|
+
* or newer host metadata. Names and metadata remain optional for older hosts.
|
|
23
|
+
* A broken response is never presented as a successfully loaded empty menu.
|
|
24
|
+
*/
|
|
25
|
+
function checkedModelCatalog(value) {
|
|
26
|
+
const envelope = asRecord(value);
|
|
27
|
+
if (envelope?.ok === false) throw new Error(modelCatalogErrorMessage(envelope.error ?? envelope));
|
|
28
|
+
const root = envelope?.ok === true ? asRecord(envelope.value) : envelope;
|
|
29
|
+
const malformed = (field) => {
|
|
30
|
+
throw new Error(`Invalid model catalog: ${field}.`);
|
|
31
|
+
};
|
|
32
|
+
if (!root || !Array.isArray(root.groups)) return malformed("groups must be an array");
|
|
33
|
+
for (const value of root.groups) {
|
|
34
|
+
const group = asRecord(value);
|
|
35
|
+
if (!group || !asText(group.id) || !Array.isArray(group.models)) return malformed("each group needs an id and models array");
|
|
36
|
+
for (const value of group.models) {
|
|
37
|
+
const model = asRecord(value);
|
|
38
|
+
if (!model || !asText(model.id)) return malformed("each model needs an id");
|
|
39
|
+
if (model.reasoning !== void 0) {
|
|
40
|
+
const reasoning = asRecord(model.reasoning);
|
|
41
|
+
if (!reasoning || !Array.isArray(reasoning.efforts) || reasoning.efforts.some((value) => !parseEffort(value))) return malformed("reasoning efforts must be an array of identified efforts");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (root.failures !== void 0 && (!Array.isArray(root.failures) || root.failures.some((value) => {
|
|
46
|
+
const failure = asRecord(value);
|
|
47
|
+
return !failure || !asText(failure.id) || typeof failure.name !== "string" || typeof failure.message !== "string";
|
|
48
|
+
}))) return malformed("failures must be an array of provider failures");
|
|
49
|
+
return root;
|
|
50
|
+
}
|
|
51
|
+
/** Read through the injected session namespace; absence and rejection are errors. */
|
|
52
|
+
async function readModelCatalog(client) {
|
|
53
|
+
const session = client.remote?.session;
|
|
54
|
+
if (typeof session?.modelCatalog !== "function") throw new Error("Model catalog unavailable: inject both remote and remote.session.");
|
|
55
|
+
return checkedModelCatalog(await session.modelCatalog());
|
|
56
|
+
}
|
|
57
|
+
/** Provider failures are partial results, not a transport failure. */
|
|
58
|
+
function modelCatalogFailures(value) {
|
|
59
|
+
try {
|
|
60
|
+
return checkedModelCatalog(value).failures ?? [];
|
|
61
|
+
} catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function parseEffort(value) {
|
|
66
|
+
const row = asRecord(value);
|
|
67
|
+
const id = row ? asText(row.id) : void 0;
|
|
68
|
+
if (!id) return void 0;
|
|
69
|
+
return {
|
|
70
|
+
id,
|
|
71
|
+
name: row ? asText(row.name) ?? id : id
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Parse the host session catalog into flat choices, keeping a saved route selectable. */
|
|
75
|
+
function parseModelMenuChoices(value, bound) {
|
|
76
|
+
const envelope = asRecord(value);
|
|
77
|
+
const root = (envelope && envelope.ok === true ? asRecord(envelope.value) : void 0) ?? envelope ?? {};
|
|
78
|
+
const groups = Array.isArray(root.groups) ? root.groups : [];
|
|
79
|
+
const choices = [];
|
|
80
|
+
for (const group of groups) {
|
|
81
|
+
const groupRow = asRecord(group);
|
|
82
|
+
const provider = groupRow ? asText(groupRow.id) : void 0;
|
|
83
|
+
if (!provider || !groupRow || !Array.isArray(groupRow.models)) continue;
|
|
84
|
+
const providerName = asText(groupRow.name) ?? provider;
|
|
85
|
+
for (const entry of groupRow.models) {
|
|
86
|
+
const modelRow = asRecord(entry);
|
|
87
|
+
const model = modelRow ? asText(modelRow.id) : void 0;
|
|
88
|
+
if (!model || !modelRow) continue;
|
|
89
|
+
const name = asText(modelRow.name) ?? model;
|
|
90
|
+
const reasoning = asRecord(modelRow.reasoning);
|
|
91
|
+
const efforts = reasoning && Array.isArray(reasoning.efforts) ? reasoning.efforts.flatMap((effort) => {
|
|
92
|
+
const parsed = parseEffort(effort);
|
|
93
|
+
return parsed ? [parsed] : [];
|
|
94
|
+
}) : [];
|
|
95
|
+
choices.push({
|
|
96
|
+
provider,
|
|
97
|
+
model,
|
|
98
|
+
label: `${providerName} / ${name}`,
|
|
99
|
+
efforts
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (bound?.provider && bound.model && !choices.some((item) => item.provider === bound.provider && item.model === bound.model)) choices.push({
|
|
104
|
+
provider: bound.provider,
|
|
105
|
+
model: bound.model,
|
|
106
|
+
label: `${bound.provider} / ${bound.model}`,
|
|
107
|
+
efforts: []
|
|
108
|
+
});
|
|
109
|
+
return choices;
|
|
110
|
+
}
|
|
111
|
+
/** Reasoning-effort options for one choice; the saved value stays selectable. */
|
|
112
|
+
function modelMenuEffortOptions(choice, current) {
|
|
113
|
+
const listed = (choice?.efforts ?? []).map((item) => ({ ...item }));
|
|
114
|
+
if (current && !listed.some((item) => item.id === current)) listed.push({
|
|
115
|
+
id: current,
|
|
116
|
+
name: current
|
|
117
|
+
});
|
|
118
|
+
return listed;
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region ../dsh-model-route/src/menu.ts
|
|
122
|
+
/** Localize standard effort ids only when the provider has not supplied a display name. */
|
|
123
|
+
function modelMenuEffortLabel(effort, locale) {
|
|
124
|
+
if (effort.name !== effort.id) return effort.name;
|
|
125
|
+
return {
|
|
126
|
+
off: ["关闭", "Off"],
|
|
127
|
+
none: ["无", "None"],
|
|
128
|
+
minimal: ["最低", "Minimal"],
|
|
129
|
+
low: ["低", "Low"],
|
|
130
|
+
medium: ["中", "Medium"],
|
|
131
|
+
high: ["高", "High"],
|
|
132
|
+
xhigh: ["极高", "Extra high"],
|
|
133
|
+
max: ["最高", "Maximum"],
|
|
134
|
+
ultra: ["超高", "Ultra"]
|
|
135
|
+
}[effort.id]?.[locale?.toLowerCase().startsWith("zh") ? 0 : 1] ?? effort.name;
|
|
136
|
+
}
|
|
137
|
+
/** The short model label shown inside a provider group. */
|
|
138
|
+
function modelMenuShortName(choice) {
|
|
139
|
+
const sep = choice.label.indexOf(" / ");
|
|
140
|
+
return sep > 0 ? choice.label.slice(sep + 3) : choice.model;
|
|
141
|
+
}
|
|
142
|
+
/** Group catalog choices by provider and filter them by a case-insensitive query. */
|
|
143
|
+
function groupModelMenuChoices(choices, query) {
|
|
144
|
+
const needle = query.trim().toLowerCase();
|
|
145
|
+
const matched = needle ? choices.filter((choice) => choice.label.toLowerCase().includes(needle) || choice.model.toLowerCase().includes(needle) || choice.provider.toLowerCase().includes(needle)) : choices;
|
|
146
|
+
const groups = [];
|
|
147
|
+
for (const choice of matched) {
|
|
148
|
+
const sep = choice.label.indexOf(" / ");
|
|
149
|
+
const name = sep > 0 ? choice.label.slice(0, sep) : choice.provider;
|
|
150
|
+
const last = groups.at(-1);
|
|
151
|
+
if (last && last.provider === choice.provider) last.items.push(choice);
|
|
152
|
+
else groups.push({
|
|
153
|
+
provider: choice.provider,
|
|
154
|
+
name,
|
|
155
|
+
items: [choice]
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return groups;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region ../dsh-plugin-kit/src/contracts.ts
|
|
162
|
+
/** `@klarkxy/dsh-git-commit` becomes `KlarkxyDshGitCommitModelSettingsChanges`. */
|
|
163
|
+
function modelSettingsChangesIdentity(packageName) {
|
|
164
|
+
const scoped = /^@([^/]+)\/(.+)$/.exec(packageName);
|
|
165
|
+
const parts = (scoped ? `${scoped[1]}/${scoped[2]}` : packageName).split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
166
|
+
if (!parts.length) throw new Error("Model settings package name has no RPC segment");
|
|
167
|
+
const segment = `${parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}ModelSettingsChanges`;
|
|
168
|
+
if (!/^[A-Z][A-Za-z0-9]*$/.test(segment)) throw new Error(`Model settings sync name is not an RPC segment: ${segment}`);
|
|
169
|
+
return {
|
|
170
|
+
service: segment,
|
|
171
|
+
namespace: segment
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Shared "Session Management" settings section id. The section is provided by
|
|
176
|
+
* shared infrastructure (see `registerSessionSettingsItem` in `client-utils`),
|
|
177
|
+
* not by any one business plugin: every participant registers only a row into
|
|
178
|
+
* {@link SESSION_SETTINGS_ITEM_SLOT}, so any enabled subset yields the same page.
|
|
179
|
+
*/
|
|
180
|
+
const SESSION_SETTINGS_SECTION_ID = "session-manager";
|
|
181
|
+
/**
|
|
182
|
+
* Child list slot declared by the shared Session Management page. Neutral
|
|
183
|
+
* naming on purpose: participants never import each other, they only
|
|
184
|
+
* contribute `{id, order}` rows into this slot while the page is alive.
|
|
185
|
+
*/
|
|
186
|
+
const SESSION_SETTINGS_ITEM_SLOT = "dsh.session-settings.item";
|
|
187
|
+
/**
|
|
188
|
+
* Host-owned nav icon seat: a root-scoped list where each entry's `id` must
|
|
189
|
+
* equal the `settings.section` id it decorates. Owner props are
|
|
190
|
+
* `{size, active}`; icons stay `aria-hidden` so the section label remains the
|
|
191
|
+
* accessible name. Contributors into a shared section may register the same
|
|
192
|
+
* icon `id` with different priorities — the ledger keeps every entry while the
|
|
193
|
+
* host renders one icon per section.
|
|
194
|
+
*/
|
|
195
|
+
const SETTINGS_SECTION_ICON_SLOT = "settings.section.icon";
|
|
196
|
+
/** Authenticated host-RPC channel for get/set of the shared default. */
|
|
197
|
+
const AUXILIARY_MODEL_CHANNEL = "/dsh-auxiliary-model";
|
|
198
|
+
/** Model-settings namespace under which the shared default is published. */
|
|
199
|
+
const AUXILIARY_MODEL_NS = "@klarkxy/dsh-plugin-kit/auxiliary-model";
|
|
200
|
+
/**
|
|
201
|
+
* Typert identity of the shared change stream. Mounted on the root context
|
|
202
|
+
* with ownerNs filtering, so frames only carry {@link AUXILIARY_MODEL_NS}.
|
|
203
|
+
*/
|
|
204
|
+
const AUXILIARY_MODEL_CHANGES_IDENTITY = modelSettingsChangesIdentity("@klarkxy/dsh-plugin-kit");
|
|
205
|
+
//#endregion
|
|
6
206
|
//#region ../dsh-plugin-kit/src/client-utils.ts
|
|
7
207
|
/** Fixed pause for failing background reads; manual work is never replayed. */
|
|
8
208
|
function createPluginReadGate(now = Date.now) {
|
|
@@ -116,6 +316,120 @@ function useFeatureRefresh(client, sessionId, refresh, working = false, enabled
|
|
|
116
316
|
enabled
|
|
117
317
|
]);
|
|
118
318
|
}
|
|
319
|
+
/** One `<svg>` with the shared icon chrome; children are plain elements. */
|
|
320
|
+
function lineIcon(children) {
|
|
321
|
+
return function SettingsSectionIcon(props) {
|
|
322
|
+
return (0, react.createElement)("svg", {
|
|
323
|
+
"aria-hidden": "true",
|
|
324
|
+
width: props.size ?? 16,
|
|
325
|
+
height: props.size ?? 16,
|
|
326
|
+
viewBox: "0 0 16 16",
|
|
327
|
+
fill: "none",
|
|
328
|
+
stroke: "currentColor",
|
|
329
|
+
strokeWidth: 1,
|
|
330
|
+
strokeLinecap: "round",
|
|
331
|
+
strokeLinejoin: "round"
|
|
332
|
+
}, ...children.map(([tag, attrs], index) => (0, react.createElement)(tag, {
|
|
333
|
+
key: index,
|
|
334
|
+
...attrs
|
|
335
|
+
})));
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
/** Chat bubble for the shared Session Management section. */
|
|
339
|
+
const IconSessionSettings = lineIcon([["path", { d: "M8.5 13a5.5 5.5 0 0 0 5.5-5.5A5.5 5.5 0 0 0 8.5 2 5.5 5.5 0 0 0 3 7.5a5.48 5.48 0 0 0 .9 3L2.8 12.6a.5.5 0 0 0 .62.62l2.9-.98a5.48 5.48 0 0 0 2.18.76Z" }]]);
|
|
340
|
+
/** Private Cordis rendezvous; every bundled copy of this helper resolves the same root service. */
|
|
341
|
+
const SESSION_SETTINGS_PAGE_SERVICE = "dshSessionSettingsPage";
|
|
342
|
+
/** The page component renders only its declared child list: items paint their own titles and styles. */
|
|
343
|
+
function SessionSettingsPageView(props) {
|
|
344
|
+
return props.renderSlot(SESSION_SETTINGS_ITEM_SLOT, {});
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Acquire the root-owned page service, creating and providing it on first use.
|
|
348
|
+
* One counter covers participants, the section wait and the provider: the last
|
|
349
|
+
* release removes the wait and then the provider synchronously (Cordis deletes
|
|
350
|
+
* the impl before its async disposer awaits), so a later acquire sees a clean
|
|
351
|
+
* get() miss and can re-establish the page.
|
|
352
|
+
*/
|
|
353
|
+
function acquireSessionSettingsPage(root) {
|
|
354
|
+
const existing = root.get(SESSION_SETTINGS_PAGE_SERVICE, false);
|
|
355
|
+
if (existing) return existing;
|
|
356
|
+
const slots = root.slots;
|
|
357
|
+
let users = 0;
|
|
358
|
+
let stopPage;
|
|
359
|
+
let unprovide;
|
|
360
|
+
const page = {
|
|
361
|
+
retain() {
|
|
362
|
+
users += 1;
|
|
363
|
+
if (!stopPage) stopPage = slots.inject("settings.section", () => slots.register({
|
|
364
|
+
name: "settings.section",
|
|
365
|
+
id: SESSION_SETTINGS_SECTION_ID,
|
|
366
|
+
order: 30,
|
|
367
|
+
label: () => {
|
|
368
|
+
const locale = root.get("locale", false);
|
|
369
|
+
return String(locale?.getSnapshot?.().active ?? "").startsWith("zh") ? "会话管理" : "Session Management";
|
|
370
|
+
},
|
|
371
|
+
children: { [SESSION_SETTINGS_ITEM_SLOT]: {
|
|
372
|
+
kind: "list",
|
|
373
|
+
scope: "root"
|
|
374
|
+
} }
|
|
375
|
+
}, SessionSettingsPageView));
|
|
376
|
+
},
|
|
377
|
+
release() {
|
|
378
|
+
if (users <= 0) return;
|
|
379
|
+
users -= 1;
|
|
380
|
+
if (users > 0) return;
|
|
381
|
+
stopPage?.();
|
|
382
|
+
stopPage = void 0;
|
|
383
|
+
unprovide?.();
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
unprovide = root.provide(SESSION_SETTINGS_PAGE_SERVICE, page);
|
|
387
|
+
return page;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Contribute one row to the shared Session Management settings page.
|
|
391
|
+
*
|
|
392
|
+
* `ctx` is the plugin's own context: the row's slot wait unloads with the
|
|
393
|
+
* plugin, while the page itself is retained on the shared root context for as
|
|
394
|
+
* long as any contributor lives. There is no fallback seat — when every
|
|
395
|
+
* contributor is gone the section disappears with the page. Returns a disposer.
|
|
396
|
+
* Shared root-owned infrastructure (the auxiliary-model card) calls this on
|
|
397
|
+
* `ctx.root` so its row, icon and page share are owned by the root lifetime
|
|
398
|
+
* and released by the returned disposer, not by any plugin fiber.
|
|
399
|
+
*/
|
|
400
|
+
function registerSessionSettingsItem(ctx, item, component) {
|
|
401
|
+
const slots = ctx.slots;
|
|
402
|
+
const root = ctx.root;
|
|
403
|
+
const page = acquireSessionSettingsPage(root);
|
|
404
|
+
let stopItem;
|
|
405
|
+
let stopIcon;
|
|
406
|
+
try {
|
|
407
|
+
page.retain();
|
|
408
|
+
stopItem = slots.inject(SESSION_SETTINGS_ITEM_SLOT, () => slots.register({
|
|
409
|
+
name: SESSION_SETTINGS_ITEM_SLOT,
|
|
410
|
+
...item
|
|
411
|
+
}, component));
|
|
412
|
+
stopIcon = slots.inject(SETTINGS_SECTION_ICON_SLOT, () => slots.register({
|
|
413
|
+
name: SETTINGS_SECTION_ICON_SLOT,
|
|
414
|
+
id: SESSION_SETTINGS_SECTION_ID,
|
|
415
|
+
order: item.order,
|
|
416
|
+
priority: item.order
|
|
417
|
+
}, IconSessionSettings));
|
|
418
|
+
} catch (error) {
|
|
419
|
+
stopIcon?.();
|
|
420
|
+
stopItem?.();
|
|
421
|
+
page.release();
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
let disposed = false;
|
|
425
|
+
return () => {
|
|
426
|
+
if (disposed) return;
|
|
427
|
+
disposed = true;
|
|
428
|
+
stopIcon?.();
|
|
429
|
+
stopItem?.();
|
|
430
|
+
page.release();
|
|
431
|
+
};
|
|
432
|
+
}
|
|
119
433
|
Object.values({
|
|
120
434
|
/** Surfaces, from the page up to the topmost nested card. */
|
|
121
435
|
surface: [
|
|
@@ -526,20 +840,6 @@ ${scope} {
|
|
|
526
840
|
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?=\s*\{)/gm, (_match, className) => `&${className}, & ${className}`);
|
|
527
841
|
}
|
|
528
842
|
//#endregion
|
|
529
|
-
//#region ../dsh-plugin-kit/src/contracts.ts
|
|
530
|
-
/** `@klarkxy/dsh-git-commit` becomes `KlarkxyDshGitCommitModelSettingsChanges`. */
|
|
531
|
-
function modelSettingsChangesIdentity(packageName) {
|
|
532
|
-
const scoped = /^@([^/]+)\/(.+)$/.exec(packageName);
|
|
533
|
-
const parts = (scoped ? `${scoped[1]}/${scoped[2]}` : packageName).split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
534
|
-
if (!parts.length) throw new Error("Model settings package name has no RPC segment");
|
|
535
|
-
const segment = `${parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}ModelSettingsChanges`;
|
|
536
|
-
if (!/^[A-Z][A-Za-z0-9]*$/.test(segment)) throw new Error(`Model settings sync name is not an RPC segment: ${segment}`);
|
|
537
|
-
return {
|
|
538
|
-
service: segment,
|
|
539
|
-
namespace: segment
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
//#endregion
|
|
543
843
|
//#region ../dsh-plugin-kit/src/model-settings-client.ts
|
|
544
844
|
/** This stream carries invalidations only; ready is never a settings snapshot. */
|
|
545
845
|
function parseModelSettingsChangeFrame(value) {
|
|
@@ -602,265 +902,110 @@ function createModelSettingsSubscriber(ctx, packageName, identity = modelSetting
|
|
|
602
902
|
listener.error?.(message);
|
|
603
903
|
} catch {}
|
|
604
904
|
};
|
|
605
|
-
const invalidate = () => {
|
|
606
|
-
for (const listener of [...listeners]) {
|
|
607
|
-
if (!listeners.has(listener)) continue;
|
|
608
|
-
try {
|
|
609
|
-
listener.change();
|
|
610
|
-
} catch (error) {
|
|
611
|
-
try {
|
|
612
|
-
listener.error?.(error instanceof Error ? error.message : String(error));
|
|
613
|
-
} catch {}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
const start = () => {
|
|
618
|
-
const life = ++lifecycle;
|
|
619
|
-
injection = ctx.inject(["remote", `remote.${endpoint.namespace}`], (injected) => {
|
|
620
|
-
if (life !== lifecycle || !listeners.size) return;
|
|
621
|
-
const scope = injected;
|
|
622
|
-
const service = scope.remote[endpoint.namespace];
|
|
623
|
-
if (!service || !("watch" in service) || !service.watch) {
|
|
624
|
-
report("Model settings sync service unavailable");
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
627
|
-
const watch = service.watch;
|
|
628
|
-
const stream = scope.remote.$stream({
|
|
629
|
-
name: "Model settings sync",
|
|
630
|
-
open: (signal) => watch(signal),
|
|
631
|
-
ended: (accepted) => /* @__PURE__ */ new Error(`Model settings sync stream ended ${accepted ? "after" : "before"} ready; refresh or reopen the page`)
|
|
632
|
-
});
|
|
633
|
-
const session = {
|
|
634
|
-
stream,
|
|
635
|
-
active: true
|
|
636
|
-
};
|
|
637
|
-
current = session;
|
|
638
|
-
scope.effect(() => () => {
|
|
639
|
-
session.active = false;
|
|
640
|
-
if (current === session) {
|
|
641
|
-
current = void 0;
|
|
642
|
-
if (life === lifecycle && listeners.size) report("Model settings sync service unavailable");
|
|
643
|
-
}
|
|
644
|
-
return stream.dispose();
|
|
645
|
-
});
|
|
646
|
-
(async () => {
|
|
647
|
-
let generation;
|
|
648
|
-
let ready = false;
|
|
649
|
-
try {
|
|
650
|
-
for await (const item of stream) {
|
|
651
|
-
if (!session.active || life !== lifecycle || !listeners.size) break;
|
|
652
|
-
if (item.signal.aborted) continue;
|
|
653
|
-
if (generation !== item.generation) {
|
|
654
|
-
generation = item.generation;
|
|
655
|
-
ready = false;
|
|
656
|
-
}
|
|
657
|
-
const frame = parseModelSettingsChangeFrame(item.value);
|
|
658
|
-
if (frame.kind === "ready") {
|
|
659
|
-
ready = true;
|
|
660
|
-
failureMessage = void 0;
|
|
661
|
-
item.accept();
|
|
662
|
-
invalidate();
|
|
663
|
-
} else {
|
|
664
|
-
if (!ready) throw new Error("Model settings sync change arrived before ready");
|
|
665
|
-
if (accept(frame.ns)) invalidate();
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
} catch (error) {
|
|
669
|
-
if (session.active && life === lifecycle) report(error instanceof Error ? error.message : String(error));
|
|
670
|
-
} finally {
|
|
671
|
-
if (current === session) current = void 0;
|
|
672
|
-
session.active = false;
|
|
673
|
-
await stream.dispose().catch(() => {});
|
|
674
|
-
}
|
|
675
|
-
})();
|
|
676
|
-
});
|
|
677
|
-
queueMicrotask(() => {
|
|
678
|
-
if (life === lifecycle && listeners.size && !current) report("Model settings sync service unavailable");
|
|
679
|
-
});
|
|
680
|
-
};
|
|
681
|
-
return Object.freeze({ subscribe(onChange, onError) {
|
|
682
|
-
const listener = {
|
|
683
|
-
change: onChange,
|
|
684
|
-
error: onError
|
|
685
|
-
};
|
|
686
|
-
listeners.add(listener);
|
|
687
|
-
if (!injection) start();
|
|
688
|
-
else if (failureMessage) queueMicrotask(() => {
|
|
689
|
-
if (listeners.has(listener) && failureMessage) try {
|
|
690
|
-
listener.error?.(failureMessage);
|
|
691
|
-
} catch {}
|
|
692
|
-
});
|
|
693
|
-
return () => {
|
|
694
|
-
if (!listeners.delete(listener) || listeners.size) return;
|
|
695
|
-
lifecycle++;
|
|
696
|
-
if (current) {
|
|
697
|
-
current.active = false;
|
|
698
|
-
current.stream.dispose().catch(() => {});
|
|
699
|
-
}
|
|
700
|
-
current = void 0;
|
|
701
|
-
failureMessage = void 0;
|
|
702
|
-
const previous = injection;
|
|
703
|
-
injection = void 0;
|
|
704
|
-
try {
|
|
705
|
-
Promise.resolve(previous?.dispose()).catch(() => {});
|
|
706
|
-
} catch {}
|
|
707
|
-
};
|
|
708
|
-
} });
|
|
709
|
-
}
|
|
710
|
-
//#endregion
|
|
711
|
-
//#region ../dsh-model-route/src/catalog.ts
|
|
712
|
-
/** Both services are required: Cordis checks the nested namespace separately. */
|
|
713
|
-
const MODEL_CATALOG_INJECT = ["remote", "remote.session"];
|
|
714
|
-
function asRecord(value) {
|
|
715
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
716
|
-
}
|
|
717
|
-
function asText(value) {
|
|
718
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
719
|
-
}
|
|
720
|
-
/** A useful diagnostic even when a transport rejects with a plain object. */
|
|
721
|
-
function modelCatalogErrorMessage(value) {
|
|
722
|
-
if (value instanceof Error && value.message) return value.message;
|
|
723
|
-
return asText(asRecord(value)?.message) ?? asText(value) ?? "Unable to load the model catalog.";
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Validate and unwrap a successful catalog without discarding provider failures
|
|
727
|
-
* or newer host metadata. Names and metadata remain optional for older hosts.
|
|
728
|
-
* A broken response is never presented as a successfully loaded empty menu.
|
|
729
|
-
*/
|
|
730
|
-
function checkedModelCatalog(value) {
|
|
731
|
-
const envelope = asRecord(value);
|
|
732
|
-
if (envelope?.ok === false) throw new Error(modelCatalogErrorMessage(envelope.error ?? envelope));
|
|
733
|
-
const root = envelope?.ok === true ? asRecord(envelope.value) : envelope;
|
|
734
|
-
const malformed = (field) => {
|
|
735
|
-
throw new Error(`Invalid model catalog: ${field}.`);
|
|
736
|
-
};
|
|
737
|
-
if (!root || !Array.isArray(root.groups)) return malformed("groups must be an array");
|
|
738
|
-
for (const value of root.groups) {
|
|
739
|
-
const group = asRecord(value);
|
|
740
|
-
if (!group || !asText(group.id) || !Array.isArray(group.models)) return malformed("each group needs an id and models array");
|
|
741
|
-
for (const value of group.models) {
|
|
742
|
-
const model = asRecord(value);
|
|
743
|
-
if (!model || !asText(model.id)) return malformed("each model needs an id");
|
|
744
|
-
if (model.reasoning !== void 0) {
|
|
745
|
-
const reasoning = asRecord(model.reasoning);
|
|
746
|
-
if (!reasoning || !Array.isArray(reasoning.efforts) || reasoning.efforts.some((value) => !parseEffort(value))) return malformed("reasoning efforts must be an array of identified efforts");
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
if (root.failures !== void 0 && (!Array.isArray(root.failures) || root.failures.some((value) => {
|
|
751
|
-
const failure = asRecord(value);
|
|
752
|
-
return !failure || !asText(failure.id) || typeof failure.name !== "string" || typeof failure.message !== "string";
|
|
753
|
-
}))) return malformed("failures must be an array of provider failures");
|
|
754
|
-
return root;
|
|
755
|
-
}
|
|
756
|
-
/** Read through the injected session namespace; absence and rejection are errors. */
|
|
757
|
-
async function readModelCatalog(client) {
|
|
758
|
-
const session = client.remote?.session;
|
|
759
|
-
if (typeof session?.modelCatalog !== "function") throw new Error("Model catalog unavailable: inject both remote and remote.session.");
|
|
760
|
-
return checkedModelCatalog(await session.modelCatalog());
|
|
761
|
-
}
|
|
762
|
-
/** Provider failures are partial results, not a transport failure. */
|
|
763
|
-
function modelCatalogFailures(value) {
|
|
764
|
-
try {
|
|
765
|
-
return checkedModelCatalog(value).failures ?? [];
|
|
766
|
-
} catch {
|
|
767
|
-
return [];
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
function parseEffort(value) {
|
|
771
|
-
const row = asRecord(value);
|
|
772
|
-
const id = row ? asText(row.id) : void 0;
|
|
773
|
-
if (!id) return void 0;
|
|
774
|
-
return {
|
|
775
|
-
id,
|
|
776
|
-
name: row ? asText(row.name) ?? id : id
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
/** Parse the host session catalog into flat choices, keeping a saved route selectable. */
|
|
780
|
-
function parseModelMenuChoices(value, bound) {
|
|
781
|
-
const envelope = asRecord(value);
|
|
782
|
-
const root = (envelope && envelope.ok === true ? asRecord(envelope.value) : void 0) ?? envelope ?? {};
|
|
783
|
-
const groups = Array.isArray(root.groups) ? root.groups : [];
|
|
784
|
-
const choices = [];
|
|
785
|
-
for (const group of groups) {
|
|
786
|
-
const groupRow = asRecord(group);
|
|
787
|
-
const provider = groupRow ? asText(groupRow.id) : void 0;
|
|
788
|
-
if (!provider || !groupRow || !Array.isArray(groupRow.models)) continue;
|
|
789
|
-
const providerName = asText(groupRow.name) ?? provider;
|
|
790
|
-
for (const entry of groupRow.models) {
|
|
791
|
-
const modelRow = asRecord(entry);
|
|
792
|
-
const model = modelRow ? asText(modelRow.id) : void 0;
|
|
793
|
-
if (!model || !modelRow) continue;
|
|
794
|
-
const name = asText(modelRow.name) ?? model;
|
|
795
|
-
const reasoning = asRecord(modelRow.reasoning);
|
|
796
|
-
const efforts = reasoning && Array.isArray(reasoning.efforts) ? reasoning.efforts.flatMap((effort) => {
|
|
797
|
-
const parsed = parseEffort(effort);
|
|
798
|
-
return parsed ? [parsed] : [];
|
|
799
|
-
}) : [];
|
|
800
|
-
choices.push({
|
|
801
|
-
provider,
|
|
802
|
-
model,
|
|
803
|
-
label: `${providerName} / ${name}`,
|
|
804
|
-
efforts
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
if (bound?.provider && bound.model && !choices.some((item) => item.provider === bound.provider && item.model === bound.model)) choices.push({
|
|
809
|
-
provider: bound.provider,
|
|
810
|
-
model: bound.model,
|
|
811
|
-
label: `${bound.provider} / ${bound.model}`,
|
|
812
|
-
efforts: []
|
|
813
|
-
});
|
|
814
|
-
return choices;
|
|
815
|
-
}
|
|
816
|
-
/** Reasoning-effort options for one choice; the saved value stays selectable. */
|
|
817
|
-
function modelMenuEffortOptions(choice, current) {
|
|
818
|
-
const listed = (choice?.efforts ?? []).map((item) => ({ ...item }));
|
|
819
|
-
if (current && !listed.some((item) => item.id === current)) listed.push({
|
|
820
|
-
id: current,
|
|
821
|
-
name: current
|
|
822
|
-
});
|
|
823
|
-
return listed;
|
|
824
|
-
}
|
|
825
|
-
//#endregion
|
|
826
|
-
//#region ../dsh-model-route/src/menu.ts
|
|
827
|
-
/** Localize standard effort ids only when the provider has not supplied a display name. */
|
|
828
|
-
function modelMenuEffortLabel(effort, locale) {
|
|
829
|
-
if (effort.name !== effort.id) return effort.name;
|
|
830
|
-
return {
|
|
831
|
-
off: ["关闭", "Off"],
|
|
832
|
-
none: ["无", "None"],
|
|
833
|
-
minimal: ["最低", "Minimal"],
|
|
834
|
-
low: ["低", "Low"],
|
|
835
|
-
medium: ["中", "Medium"],
|
|
836
|
-
high: ["高", "High"],
|
|
837
|
-
xhigh: ["极高", "Extra high"],
|
|
838
|
-
max: ["最高", "Maximum"],
|
|
839
|
-
ultra: ["超高", "Ultra"]
|
|
840
|
-
}[effort.id]?.[locale?.toLowerCase().startsWith("zh") ? 0 : 1] ?? effort.name;
|
|
841
|
-
}
|
|
842
|
-
/** The short model label shown inside a provider group. */
|
|
843
|
-
function modelMenuShortName(choice) {
|
|
844
|
-
const sep = choice.label.indexOf(" / ");
|
|
845
|
-
return sep > 0 ? choice.label.slice(sep + 3) : choice.model;
|
|
846
|
-
}
|
|
847
|
-
/** Group catalog choices by provider and filter them by a case-insensitive query. */
|
|
848
|
-
function groupModelMenuChoices(choices, query) {
|
|
849
|
-
const needle = query.trim().toLowerCase();
|
|
850
|
-
const matched = needle ? choices.filter((choice) => choice.label.toLowerCase().includes(needle) || choice.model.toLowerCase().includes(needle) || choice.provider.toLowerCase().includes(needle)) : choices;
|
|
851
|
-
const groups = [];
|
|
852
|
-
for (const choice of matched) {
|
|
853
|
-
const sep = choice.label.indexOf(" / ");
|
|
854
|
-
const name = sep > 0 ? choice.label.slice(0, sep) : choice.provider;
|
|
855
|
-
const last = groups.at(-1);
|
|
856
|
-
if (last && last.provider === choice.provider) last.items.push(choice);
|
|
857
|
-
else groups.push({
|
|
858
|
-
provider: choice.provider,
|
|
859
|
-
name,
|
|
860
|
-
items: [choice]
|
|
905
|
+
const invalidate = () => {
|
|
906
|
+
for (const listener of [...listeners]) {
|
|
907
|
+
if (!listeners.has(listener)) continue;
|
|
908
|
+
try {
|
|
909
|
+
listener.change();
|
|
910
|
+
} catch (error) {
|
|
911
|
+
try {
|
|
912
|
+
listener.error?.(error instanceof Error ? error.message : String(error));
|
|
913
|
+
} catch {}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
const start = () => {
|
|
918
|
+
const life = ++lifecycle;
|
|
919
|
+
injection = ctx.inject(["remote", `remote.${endpoint.namespace}`], (injected) => {
|
|
920
|
+
if (life !== lifecycle || !listeners.size) return;
|
|
921
|
+
const scope = injected;
|
|
922
|
+
const service = scope.remote[endpoint.namespace];
|
|
923
|
+
if (!service || !("watch" in service) || !service.watch) {
|
|
924
|
+
report("Model settings sync service unavailable");
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const watch = service.watch;
|
|
928
|
+
const stream = scope.remote.$stream({
|
|
929
|
+
name: "Model settings sync",
|
|
930
|
+
open: (signal) => watch(signal),
|
|
931
|
+
ended: (accepted) => /* @__PURE__ */ new Error(`Model settings sync stream ended ${accepted ? "after" : "before"} ready; refresh or reopen the page`)
|
|
932
|
+
});
|
|
933
|
+
const session = {
|
|
934
|
+
stream,
|
|
935
|
+
active: true
|
|
936
|
+
};
|
|
937
|
+
current = session;
|
|
938
|
+
scope.effect(() => () => {
|
|
939
|
+
session.active = false;
|
|
940
|
+
if (current === session) {
|
|
941
|
+
current = void 0;
|
|
942
|
+
if (life === lifecycle && listeners.size) report("Model settings sync service unavailable");
|
|
943
|
+
}
|
|
944
|
+
return stream.dispose();
|
|
945
|
+
});
|
|
946
|
+
(async () => {
|
|
947
|
+
let generation;
|
|
948
|
+
let ready = false;
|
|
949
|
+
try {
|
|
950
|
+
for await (const item of stream) {
|
|
951
|
+
if (!session.active || life !== lifecycle || !listeners.size) break;
|
|
952
|
+
if (item.signal.aborted) continue;
|
|
953
|
+
if (generation !== item.generation) {
|
|
954
|
+
generation = item.generation;
|
|
955
|
+
ready = false;
|
|
956
|
+
}
|
|
957
|
+
const frame = parseModelSettingsChangeFrame(item.value);
|
|
958
|
+
if (frame.kind === "ready") {
|
|
959
|
+
ready = true;
|
|
960
|
+
failureMessage = void 0;
|
|
961
|
+
item.accept();
|
|
962
|
+
invalidate();
|
|
963
|
+
} else {
|
|
964
|
+
if (!ready) throw new Error("Model settings sync change arrived before ready");
|
|
965
|
+
if (accept(frame.ns)) invalidate();
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
} catch (error) {
|
|
969
|
+
if (session.active && life === lifecycle) report(error instanceof Error ? error.message : String(error));
|
|
970
|
+
} finally {
|
|
971
|
+
if (current === session) current = void 0;
|
|
972
|
+
session.active = false;
|
|
973
|
+
await stream.dispose().catch(() => {});
|
|
974
|
+
}
|
|
975
|
+
})();
|
|
861
976
|
});
|
|
862
|
-
|
|
863
|
-
|
|
977
|
+
queueMicrotask(() => {
|
|
978
|
+
if (life === lifecycle && listeners.size && !current) report("Model settings sync service unavailable");
|
|
979
|
+
});
|
|
980
|
+
};
|
|
981
|
+
return Object.freeze({ subscribe(onChange, onError) {
|
|
982
|
+
const listener = {
|
|
983
|
+
change: onChange,
|
|
984
|
+
error: onError
|
|
985
|
+
};
|
|
986
|
+
listeners.add(listener);
|
|
987
|
+
if (!injection) start();
|
|
988
|
+
else if (failureMessage) queueMicrotask(() => {
|
|
989
|
+
if (listeners.has(listener) && failureMessage) try {
|
|
990
|
+
listener.error?.(failureMessage);
|
|
991
|
+
} catch {}
|
|
992
|
+
});
|
|
993
|
+
return () => {
|
|
994
|
+
if (!listeners.delete(listener) || listeners.size) return;
|
|
995
|
+
lifecycle++;
|
|
996
|
+
if (current) {
|
|
997
|
+
current.active = false;
|
|
998
|
+
current.stream.dispose().catch(() => {});
|
|
999
|
+
}
|
|
1000
|
+
current = void 0;
|
|
1001
|
+
failureMessage = void 0;
|
|
1002
|
+
const previous = injection;
|
|
1003
|
+
injection = void 0;
|
|
1004
|
+
try {
|
|
1005
|
+
Promise.resolve(previous?.dispose()).catch(() => {});
|
|
1006
|
+
} catch {}
|
|
1007
|
+
};
|
|
1008
|
+
} });
|
|
864
1009
|
}
|
|
865
1010
|
//#endregion
|
|
866
1011
|
//#region ../dsh-model-route/src/catalog-ui.tsx
|
|
@@ -1689,6 +1834,488 @@ const modelMenuCss = `
|
|
|
1689
1834
|
.dsh-model-menu-cellChevron { width: 12px; height: 12px; color: var(--dsw-alias-menu-icon); flex: none; }
|
|
1690
1835
|
`;
|
|
1691
1836
|
//#endregion
|
|
1837
|
+
//#region ../dsh-plugin-kit/src/auxiliary-model-client.tsx
|
|
1838
|
+
const AUXILIARY_MODEL_PACKAGE = "@klarkxy/dsh-plugin-kit";
|
|
1839
|
+
const AUXILIARY_MODEL_SEAT_ID = "auxiliary-model";
|
|
1840
|
+
/** Private Cordis rendezvous; every bundled copy resolves the same root service. */
|
|
1841
|
+
const AUXILIARY_MODEL_CARD_SERVICE = "dshAuxiliaryModelSettingsCard";
|
|
1842
|
+
/** Theme-token-only stylesheet: officialUiCss scope plus the shared ModelMenu recipe. */
|
|
1843
|
+
const auxiliaryModelCss = `${officialUiCss("ams-root")}${modelMenuCss}
|
|
1844
|
+
.ams-root .ams-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
|
|
1845
|
+
`;
|
|
1846
|
+
const auxiliaryCopy = {
|
|
1847
|
+
zh: {
|
|
1848
|
+
title: "默认辅助模型",
|
|
1849
|
+
help: "各辅助功能(如标题生成、摘要)没有单独指定模型时使用的模型;仅影响声明使用它的功能。",
|
|
1850
|
+
model: "辅助模型",
|
|
1851
|
+
modelDefault: "跟随会话或宿主默认",
|
|
1852
|
+
modelHint: "不选择模型时,各功能按自己的规则决定对话模型。",
|
|
1853
|
+
effortDefault: "跟随模型默认",
|
|
1854
|
+
loading: "正在读取设置…",
|
|
1855
|
+
failed: "无法读取模型设置。",
|
|
1856
|
+
stale: "设置已被其他窗口更新,请刷新后重试。",
|
|
1857
|
+
saveFailed: "保存失败,原设置未更改。请重试。",
|
|
1858
|
+
saved: "已保存。",
|
|
1859
|
+
retry: "重试",
|
|
1860
|
+
refresh: "刷新设置",
|
|
1861
|
+
syncUnavailable: "自动刷新不可用,请手动刷新设置。"
|
|
1862
|
+
},
|
|
1863
|
+
en: {
|
|
1864
|
+
title: "Default Auxiliary Model",
|
|
1865
|
+
help: "The model used by auxiliary features (such as title generation or summarizing) that do not name their own model; only features that opted in are affected.",
|
|
1866
|
+
model: "Auxiliary model",
|
|
1867
|
+
modelDefault: "Follow session or host default",
|
|
1868
|
+
modelHint: "With no model selected, each feature follows its own rules for the conversation model.",
|
|
1869
|
+
effortDefault: "Follow model default",
|
|
1870
|
+
loading: "Loading settings…",
|
|
1871
|
+
failed: "Could not load model settings.",
|
|
1872
|
+
stale: "Settings were changed elsewhere; refresh and retry.",
|
|
1873
|
+
saveFailed: "Save failed; the previous setting was not changed. Try again.",
|
|
1874
|
+
saved: "Saved.",
|
|
1875
|
+
retry: "Retry",
|
|
1876
|
+
refresh: "Refresh settings",
|
|
1877
|
+
syncUnavailable: "Automatic refresh unavailable; refresh settings manually."
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
/** A failed RPC keeps its code so the card can translate known rejections. */
|
|
1881
|
+
var AuxiliaryRpcError = class extends Error {
|
|
1882
|
+
code;
|
|
1883
|
+
constructor(code, message) {
|
|
1884
|
+
super(message);
|
|
1885
|
+
this.code = code;
|
|
1886
|
+
this.name = "AuxiliaryRpcError";
|
|
1887
|
+
}
|
|
1888
|
+
};
|
|
1889
|
+
/** Host UI language, following live switches with the host's English fallback. */
|
|
1890
|
+
function useAuxiliaryLocale(client) {
|
|
1891
|
+
const subscribe = (0, react.useCallback)((listener) => client.locale?.subscribe(listener) ?? (() => {}), [client]);
|
|
1892
|
+
const snapshot = (0, react.useCallback)(() => client.locale?.getSnapshot().active ?? "en", [client]);
|
|
1893
|
+
return String((0, react.useSyncExternalStore)(subscribe, snapshot, snapshot)).startsWith("zh") ? "zh" : "en";
|
|
1894
|
+
}
|
|
1895
|
+
function isAbort(error) {
|
|
1896
|
+
return error instanceof Error && (error.name === "AbortError" || /abort|cancel/i.test(error.message));
|
|
1897
|
+
}
|
|
1898
|
+
function isStaleRejection(error) {
|
|
1899
|
+
if (!(error instanceof AuxiliaryRpcError)) return false;
|
|
1900
|
+
return error.code === "stale" || error.code === "auxiliary-model/conflict" || /changed|revision|reload|stale|conflict/i.test(error.message);
|
|
1901
|
+
}
|
|
1902
|
+
async function callAuxiliaryRpc(client, endpoint, payload = {}) {
|
|
1903
|
+
const result = await client.connection.rpc.call(AUXILIARY_MODEL_CHANNEL, endpoint, payload);
|
|
1904
|
+
if (!result || result.ok !== true) {
|
|
1905
|
+
const error = result && "error" in result ? result.error : void 0;
|
|
1906
|
+
throw new AuxiliaryRpcError(error?.code ?? "unknown", error?.message ?? `RPC ${endpoint} failed`);
|
|
1907
|
+
}
|
|
1908
|
+
return result.value;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* The shared card. All state comes from the shared host service over the
|
|
1912
|
+
* plugin-kit RPC channel; the card only renders the stored row.
|
|
1913
|
+
*/
|
|
1914
|
+
function AuxiliaryModelCard({ client, subscribe }) {
|
|
1915
|
+
const language = useAuxiliaryLocale(client);
|
|
1916
|
+
const text = auxiliaryCopy[language];
|
|
1917
|
+
const [settings, setSettings] = (0, react.useState)();
|
|
1918
|
+
const catalogState = useModelCatalog((0, react.useCallback)(() => readModelCatalog(client), [client]), { subscribe: (0, react.useCallback)((change) => client.connection.generation?.subscribe(change), [client]) });
|
|
1919
|
+
const { refresh: refreshCatalog } = catalogState;
|
|
1920
|
+
const choices = parseModelMenuChoices(catalogState.catalog, settings?.model ?? void 0);
|
|
1921
|
+
const [menuOpen, setMenuOpen] = (0, react.useState)(false);
|
|
1922
|
+
const [error, setError] = (0, react.useState)("");
|
|
1923
|
+
const [note, setNote] = (0, react.useState)(false);
|
|
1924
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
1925
|
+
const [syncError, setSyncError] = (0, react.useState)("");
|
|
1926
|
+
const operation = (0, react.useRef)({
|
|
1927
|
+
epoch: 0,
|
|
1928
|
+
active: false,
|
|
1929
|
+
reading: false,
|
|
1930
|
+
writing: false,
|
|
1931
|
+
pending: false
|
|
1932
|
+
});
|
|
1933
|
+
const refreshRef = (0, react.useRef)(() => {});
|
|
1934
|
+
const refresh = () => {
|
|
1935
|
+
const state = operation.current;
|
|
1936
|
+
if (!state.active) return;
|
|
1937
|
+
if (state.reading || state.writing) {
|
|
1938
|
+
state.pending = true;
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
state.pending = false;
|
|
1942
|
+
state.reading = true;
|
|
1943
|
+
setBusy(true);
|
|
1944
|
+
const epoch = state.epoch;
|
|
1945
|
+
callAuxiliaryRpc(client, "defaults.get").then((next) => {
|
|
1946
|
+
if (state.active && state.epoch === epoch && !state.pending) {
|
|
1947
|
+
setSettings(next);
|
|
1948
|
+
setError("");
|
|
1949
|
+
}
|
|
1950
|
+
}).catch((reason) => {
|
|
1951
|
+
if (state.active && state.epoch === epoch && !state.pending && !isAbort(reason)) setError("failed");
|
|
1952
|
+
}).finally(() => {
|
|
1953
|
+
if (!state.active || state.epoch !== epoch) return;
|
|
1954
|
+
state.reading = false;
|
|
1955
|
+
setBusy(false);
|
|
1956
|
+
if (state.pending) refreshRef.current();
|
|
1957
|
+
});
|
|
1958
|
+
};
|
|
1959
|
+
refreshRef.current = refresh;
|
|
1960
|
+
(0, react.useEffect)(() => {
|
|
1961
|
+
const state = operation.current;
|
|
1962
|
+
state.epoch++;
|
|
1963
|
+
state.active = true;
|
|
1964
|
+
state.reading = false;
|
|
1965
|
+
state.writing = false;
|
|
1966
|
+
state.pending = false;
|
|
1967
|
+
setBusy(false);
|
|
1968
|
+
setSettings(void 0);
|
|
1969
|
+
setError("");
|
|
1970
|
+
setNote(false);
|
|
1971
|
+
refreshRef.current();
|
|
1972
|
+
return () => {
|
|
1973
|
+
state.active = false;
|
|
1974
|
+
state.epoch++;
|
|
1975
|
+
};
|
|
1976
|
+
}, [client]);
|
|
1977
|
+
(0, react.useEffect)(() => {
|
|
1978
|
+
setSyncError("");
|
|
1979
|
+
let live = true;
|
|
1980
|
+
let stop;
|
|
1981
|
+
try {
|
|
1982
|
+
stop = subscribe?.(() => {
|
|
1983
|
+
if (live) {
|
|
1984
|
+
setSyncError("");
|
|
1985
|
+
refreshCatalog();
|
|
1986
|
+
refreshRef.current();
|
|
1987
|
+
}
|
|
1988
|
+
}, (message) => {
|
|
1989
|
+
if (live) setSyncError(message);
|
|
1990
|
+
});
|
|
1991
|
+
} catch {
|
|
1992
|
+
if (live) setSyncError("Model settings sync service unavailable");
|
|
1993
|
+
}
|
|
1994
|
+
return () => {
|
|
1995
|
+
live = false;
|
|
1996
|
+
try {
|
|
1997
|
+
stop?.();
|
|
1998
|
+
} catch {}
|
|
1999
|
+
};
|
|
2000
|
+
}, [subscribe, refreshCatalog]);
|
|
2001
|
+
const save = (0, react.useCallback)((model) => {
|
|
2002
|
+
const state = operation.current;
|
|
2003
|
+
if (!settings || !state.active || state.writing || state.reading) return;
|
|
2004
|
+
state.writing = true;
|
|
2005
|
+
const epoch = state.epoch;
|
|
2006
|
+
setBusy(true);
|
|
2007
|
+
setNote(false);
|
|
2008
|
+
setError("");
|
|
2009
|
+
callAuxiliaryRpc(client, "defaults.set", {
|
|
2010
|
+
model: model ?? {
|
|
2011
|
+
provider: "",
|
|
2012
|
+
model: ""
|
|
2013
|
+
},
|
|
2014
|
+
expectedRevision: settings.revision
|
|
2015
|
+
}).then((next) => {
|
|
2016
|
+
if (state.active && state.epoch === epoch) {
|
|
2017
|
+
setSettings(next);
|
|
2018
|
+
setNote(true);
|
|
2019
|
+
refreshCatalog();
|
|
2020
|
+
}
|
|
2021
|
+
}).catch((reason) => {
|
|
2022
|
+
if (state.active && state.epoch === epoch) setError(isStaleRejection(reason) ? "stale" : "saveFailed");
|
|
2023
|
+
}).finally(() => {
|
|
2024
|
+
if (!state.active || state.epoch !== epoch) return;
|
|
2025
|
+
state.writing = false;
|
|
2026
|
+
setBusy(false);
|
|
2027
|
+
if (state.pending) refreshRef.current();
|
|
2028
|
+
});
|
|
2029
|
+
}, [
|
|
2030
|
+
client,
|
|
2031
|
+
settings,
|
|
2032
|
+
refreshCatalog
|
|
2033
|
+
]);
|
|
2034
|
+
const locked = busy;
|
|
2035
|
+
if (!settings) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2036
|
+
className: "ams-root dsh-ui-card",
|
|
2037
|
+
"data-testid": "auxiliary-model-settings",
|
|
2038
|
+
children: [
|
|
2039
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2040
|
+
className: "dsh-ui-heading",
|
|
2041
|
+
children: text.title
|
|
2042
|
+
}),
|
|
2043
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2044
|
+
className: "dsh-ui-help",
|
|
2045
|
+
children: text.help
|
|
2046
|
+
}),
|
|
2047
|
+
error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2048
|
+
role: "alert",
|
|
2049
|
+
className: "dsh-ui-error",
|
|
2050
|
+
children: text[error]
|
|
2051
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2052
|
+
role: "status",
|
|
2053
|
+
className: "dsh-ui-hint",
|
|
2054
|
+
children: text.loading
|
|
2055
|
+
}),
|
|
2056
|
+
syncError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2057
|
+
role: "status",
|
|
2058
|
+
className: "dsh-ui-hint",
|
|
2059
|
+
children: text.syncUnavailable
|
|
2060
|
+
}),
|
|
2061
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2062
|
+
className: "dsh-ui-actions",
|
|
2063
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
2064
|
+
variant: "ghost",
|
|
2065
|
+
size: "sm",
|
|
2066
|
+
disabled: locked,
|
|
2067
|
+
onClick: () => refreshRef.current(),
|
|
2068
|
+
children: text.retry
|
|
2069
|
+
})
|
|
2070
|
+
})
|
|
2071
|
+
]
|
|
2072
|
+
});
|
|
2073
|
+
const current = settings.model ?? {
|
|
2074
|
+
provider: "",
|
|
2075
|
+
model: ""
|
|
2076
|
+
};
|
|
2077
|
+
const follow = !current.provider || !current.model;
|
|
2078
|
+
const selected = follow ? void 0 : choices.find((item) => item.provider === current.provider && item.model === current.model);
|
|
2079
|
+
const efforts = follow ? [] : modelMenuEffortOptions(selected, current.reasoningEffort);
|
|
2080
|
+
const currentLabel = follow ? text.modelDefault : selected?.label ?? `${current.provider} / ${current.model}`;
|
|
2081
|
+
const selectedEffort = efforts.find((item) => item.id === (current.reasoningEffort || ""));
|
|
2082
|
+
const effortName = selectedEffort ? modelMenuEffortLabel(selectedEffort, language) : void 0;
|
|
2083
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2084
|
+
className: "ams-root dsh-ui-card",
|
|
2085
|
+
"data-testid": "auxiliary-model-settings",
|
|
2086
|
+
children: [
|
|
2087
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2088
|
+
className: "dsh-ui-heading",
|
|
2089
|
+
children: text.title
|
|
2090
|
+
}),
|
|
2091
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2092
|
+
className: "dsh-ui-help",
|
|
2093
|
+
children: text.help
|
|
2094
|
+
}),
|
|
2095
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2096
|
+
className: "dsh-ui-field",
|
|
2097
|
+
children: [
|
|
2098
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2099
|
+
className: "dsh-ui-label",
|
|
2100
|
+
children: text.model
|
|
2101
|
+
}),
|
|
2102
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelCatalogStatus, {
|
|
2103
|
+
state: catalogState,
|
|
2104
|
+
locale: language
|
|
2105
|
+
}),
|
|
2106
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelMenu, {
|
|
2107
|
+
locale: language,
|
|
2108
|
+
open: menuOpen && !locked,
|
|
2109
|
+
onOpenChange: (next) => setMenuOpen(next && !locked),
|
|
2110
|
+
listClassName: "ams-root ams-menu-portal",
|
|
2111
|
+
anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
2112
|
+
type: "button",
|
|
2113
|
+
className: "dsh-model-menu-trigger",
|
|
2114
|
+
disabled: locked,
|
|
2115
|
+
"aria-label": `${text.model}: ${currentLabel}`,
|
|
2116
|
+
children: [
|
|
2117
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2118
|
+
className: "dsh-model-menu-triggerLabel",
|
|
2119
|
+
children: currentLabel
|
|
2120
|
+
}),
|
|
2121
|
+
!follow && efforts.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2122
|
+
className: "dsh-model-menu-triggerEffort",
|
|
2123
|
+
children: effortName ?? text.effortDefault
|
|
2124
|
+
}) : null,
|
|
2125
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { className: `dsh-model-menu-chevron${menuOpen && !locked ? " dsh-model-menu-chevronOpen" : ""}` })
|
|
2126
|
+
]
|
|
2127
|
+
}),
|
|
2128
|
+
choices,
|
|
2129
|
+
selected: follow ? void 0 : {
|
|
2130
|
+
provider: current.provider,
|
|
2131
|
+
model: current.model
|
|
2132
|
+
},
|
|
2133
|
+
onPick: (picked) => save({
|
|
2134
|
+
provider: picked.provider,
|
|
2135
|
+
model: picked.model
|
|
2136
|
+
}),
|
|
2137
|
+
leading: [{
|
|
2138
|
+
id: "default",
|
|
2139
|
+
label: text.modelDefault,
|
|
2140
|
+
selected: follow
|
|
2141
|
+
}],
|
|
2142
|
+
onPickLeading: () => save(null),
|
|
2143
|
+
efforts,
|
|
2144
|
+
selectedEffort: current.reasoningEffort || "",
|
|
2145
|
+
onPickEffort: (effort) => save(follow ? null : {
|
|
2146
|
+
provider: current.provider,
|
|
2147
|
+
model: current.model,
|
|
2148
|
+
...effort ? { reasoningEffort: effort } : {}
|
|
2149
|
+
}),
|
|
2150
|
+
modelLabel: text.model,
|
|
2151
|
+
modelValue: currentLabel,
|
|
2152
|
+
defaultEffortLabel: text.effortDefault
|
|
2153
|
+
}),
|
|
2154
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2155
|
+
className: "dsh-ui-hint",
|
|
2156
|
+
children: text.modelHint
|
|
2157
|
+
})
|
|
2158
|
+
]
|
|
2159
|
+
}),
|
|
2160
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2161
|
+
className: "ams-row",
|
|
2162
|
+
children: [
|
|
2163
|
+
syncError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2164
|
+
role: "status",
|
|
2165
|
+
className: "dsh-ui-hint",
|
|
2166
|
+
children: text.syncUnavailable
|
|
2167
|
+
}),
|
|
2168
|
+
error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2169
|
+
role: "alert",
|
|
2170
|
+
className: "dsh-ui-error",
|
|
2171
|
+
children: text[error]
|
|
2172
|
+
}),
|
|
2173
|
+
note && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2174
|
+
role: "status",
|
|
2175
|
+
className: "dsh-ui-notice",
|
|
2176
|
+
children: text.saved
|
|
2177
|
+
}),
|
|
2178
|
+
error || syncError ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
2179
|
+
variant: "ghost",
|
|
2180
|
+
size: "sm",
|
|
2181
|
+
disabled: locked,
|
|
2182
|
+
onClick: () => refreshRef.current(),
|
|
2183
|
+
children: text.refresh
|
|
2184
|
+
}) : null
|
|
2185
|
+
]
|
|
2186
|
+
})
|
|
2187
|
+
]
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
const AUXILIARY_MODEL_WATCH_COORDINATOR = "dshAuxiliaryModelWatchCoordinator";
|
|
2191
|
+
function acquireWatchCoordinator(root) {
|
|
2192
|
+
const existing = root.get(AUXILIARY_MODEL_WATCH_COORDINATOR, false);
|
|
2193
|
+
if (existing) return existing;
|
|
2194
|
+
let unprovide;
|
|
2195
|
+
const coordinator = {
|
|
2196
|
+
tail: Promise.resolve(),
|
|
2197
|
+
active: 0,
|
|
2198
|
+
mount() {
|
|
2199
|
+
coordinator.active += 1;
|
|
2200
|
+
const previousTail = coordinator.tail;
|
|
2201
|
+
const lease = {
|
|
2202
|
+
closed: false,
|
|
2203
|
+
done() {
|
|
2204
|
+
if (lease.closed) return;
|
|
2205
|
+
lease.closed = true;
|
|
2206
|
+
coordinator.active -= 1;
|
|
2207
|
+
const owned = lease.fiber;
|
|
2208
|
+
lease.fiber = void 0;
|
|
2209
|
+
coordinator.tail = coordinator.tail.then(() => Promise.resolve(owned?.dispose()).catch(() => {}));
|
|
2210
|
+
coordinator.tail.then(() => {
|
|
2211
|
+
if (coordinator.active > 0) return;
|
|
2212
|
+
try {
|
|
2213
|
+
if (root.get(AUXILIARY_MODEL_WATCH_COORDINATOR, false) === coordinator) Promise.resolve(unprovide?.()).catch(() => {});
|
|
2214
|
+
} catch {}
|
|
2215
|
+
});
|
|
2216
|
+
},
|
|
2217
|
+
fiber: void 0
|
|
2218
|
+
};
|
|
2219
|
+
previousTail.then(() => {
|
|
2220
|
+
if (lease.closed) return;
|
|
2221
|
+
try {
|
|
2222
|
+
lease.fiber = root.inject(["remote"], (injected) => {
|
|
2223
|
+
const scope = injected;
|
|
2224
|
+
const mounting = scope.remote.$mount(modelSettingsChangesRemote(AUXILIARY_MODEL_PACKAGE, AUXILIARY_MODEL_CHANGES_IDENTITY));
|
|
2225
|
+
mounting.catch(() => {});
|
|
2226
|
+
scope.effect(() => async () => {
|
|
2227
|
+
await (await mounting.catch(() => void 0))?.();
|
|
2228
|
+
});
|
|
2229
|
+
});
|
|
2230
|
+
} catch {}
|
|
2231
|
+
});
|
|
2232
|
+
return lease;
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
unprovide = root.provide(AUXILIARY_MODEL_WATCH_COORDINATOR, coordinator);
|
|
2236
|
+
return coordinator;
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Acquire the root-owned card service, creating it on first use. One counter
|
|
2240
|
+
* covers participants, the seat wait and the change-stream mount: the last
|
|
2241
|
+
* release removes the wait, then the watch contribution, then the provider
|
|
2242
|
+
* itself synchronously (Cordis deletes the impl before its async disposer
|
|
2243
|
+
* awaits), so a later acquire sees a clean get() miss and can re-establish.
|
|
2244
|
+
*/
|
|
2245
|
+
function acquireAuxiliaryModelCard(root, ctx) {
|
|
2246
|
+
const existing = root.get(AUXILIARY_MODEL_CARD_SERVICE, false);
|
|
2247
|
+
if (existing) return existing;
|
|
2248
|
+
let users = 0;
|
|
2249
|
+
let styleElement;
|
|
2250
|
+
let stopItem;
|
|
2251
|
+
let unprovide;
|
|
2252
|
+
const watchLease = acquireWatchCoordinator(root).mount();
|
|
2253
|
+
const subscriber = createModelSettingsSubscriber(ctx.root, AUXILIARY_MODEL_PACKAGE, AUXILIARY_MODEL_CHANGES_IDENTITY, (ns) => ns === AUXILIARY_MODEL_NS);
|
|
2254
|
+
const render = () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuxiliaryModelCard, {
|
|
2255
|
+
client: root,
|
|
2256
|
+
subscribe: subscriber.subscribe
|
|
2257
|
+
});
|
|
2258
|
+
const service = {
|
|
2259
|
+
retain() {
|
|
2260
|
+
users += 1;
|
|
2261
|
+
if (styleElement === void 0 && typeof document !== "undefined") {
|
|
2262
|
+
styleElement = document.createElement("style");
|
|
2263
|
+
styleElement.setAttribute("data-plugin", "dsh-auxiliary-model-shared");
|
|
2264
|
+
styleElement.textContent = auxiliaryModelCss;
|
|
2265
|
+
document.head.appendChild(styleElement);
|
|
2266
|
+
}
|
|
2267
|
+
if (!stopItem) stopItem = registerSessionSettingsItem(ctx.root, {
|
|
2268
|
+
id: AUXILIARY_MODEL_SEAT_ID,
|
|
2269
|
+
order: 55
|
|
2270
|
+
}, render);
|
|
2271
|
+
},
|
|
2272
|
+
release() {
|
|
2273
|
+
if (users <= 0) return;
|
|
2274
|
+
users -= 1;
|
|
2275
|
+
if (users > 0) return;
|
|
2276
|
+
stopItem?.();
|
|
2277
|
+
stopItem = void 0;
|
|
2278
|
+
styleElement?.remove();
|
|
2279
|
+
styleElement = void 0;
|
|
2280
|
+
watchLease.done();
|
|
2281
|
+
try {
|
|
2282
|
+
Promise.resolve(unprovide?.()).catch(() => {});
|
|
2283
|
+
} catch {}
|
|
2284
|
+
unprovide = void 0;
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
unprovide = root.provide(AUXILIARY_MODEL_CARD_SERVICE, service);
|
|
2288
|
+
return service;
|
|
2289
|
+
}
|
|
2290
|
+
/**
|
|
2291
|
+
* Show the shared "default auxiliary model" card while the calling plugin is
|
|
2292
|
+
* enabled.
|
|
2293
|
+
*
|
|
2294
|
+
* `ctx` is the plugin's own client context: the card itself is retained on the
|
|
2295
|
+
* shared root context for as long as any participant lives, so an arbitrary
|
|
2296
|
+
* subset of enabled plugins yields the same single card. The mount's slot wait
|
|
2297
|
+
* and the change-stream contribution are owned by the root service — the first
|
|
2298
|
+
* participant's unload cannot take the card down. Returns a disposer; it may
|
|
2299
|
+
* be invoked by both ctx.effect and an explicit caller and releases at most
|
|
2300
|
+
* once, so a double call cannot unbalance the shared refcount.
|
|
2301
|
+
*/
|
|
2302
|
+
function registerAuxiliaryModelSettings(ctx) {
|
|
2303
|
+
const root = ctx.root;
|
|
2304
|
+
const service = acquireAuxiliaryModelCard(root, ctx);
|
|
2305
|
+
try {
|
|
2306
|
+
service.retain();
|
|
2307
|
+
} catch (error) {
|
|
2308
|
+
service.release();
|
|
2309
|
+
throw error;
|
|
2310
|
+
}
|
|
2311
|
+
let disposed = false;
|
|
2312
|
+
return () => {
|
|
2313
|
+
if (disposed) return;
|
|
2314
|
+
disposed = true;
|
|
2315
|
+
service.release();
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
//#endregion
|
|
1692
2319
|
//#region src/contracts.ts
|
|
1693
2320
|
const RPC_CHANNEL = "/dsh-current-title";
|
|
1694
2321
|
const TITLE_CLIENT_SERVICE = "dshCurrentTitleClient";
|
|
@@ -1697,6 +2324,7 @@ const TITLE_CLIENT_SERVICE = "dshCurrentTitleClient";
|
|
|
1697
2324
|
const titleCopy = {
|
|
1698
2325
|
zh: {
|
|
1699
2326
|
label: "自动标题",
|
|
2327
|
+
groupHint: "标题模型、提示词与更新节奏",
|
|
1700
2328
|
session: "当前会话",
|
|
1701
2329
|
noSession: "没有打开的会话。打开一个会话后,可以在这里查看并重新生成标题。",
|
|
1702
2330
|
pinned: "已手动命名",
|
|
@@ -1708,7 +2336,8 @@ const titleCopy = {
|
|
|
1708
2336
|
promptHint: "留空用内置说明,仍返回类型和摘要;离开输入框即保存。",
|
|
1709
2337
|
loading: "正在读取标题设置…",
|
|
1710
2338
|
model: "标题模型",
|
|
1711
|
-
modelDefault: "
|
|
2339
|
+
modelDefault: "默认辅助模型",
|
|
2340
|
+
modelHint: "使用全局默认辅助模型;未设置时跟随当前会话模型,再回落到宿主默认对话模型。",
|
|
1712
2341
|
cadence: "更新节奏",
|
|
1713
2342
|
cadenceAll: "跟随当前任务(每条消息)",
|
|
1714
2343
|
cadenceFirst: "仅首条消息",
|
|
@@ -1723,6 +2352,7 @@ const titleCopy = {
|
|
|
1723
2352
|
},
|
|
1724
2353
|
en: {
|
|
1725
2354
|
label: "Auto Title",
|
|
2355
|
+
groupHint: "Title model, prompt and update cadence",
|
|
1726
2356
|
session: "Current session",
|
|
1727
2357
|
noSession: "No session is open. Open one to see its title and regenerate it here.",
|
|
1728
2358
|
pinned: "Renamed manually",
|
|
@@ -1734,7 +2364,8 @@ const titleCopy = {
|
|
|
1734
2364
|
promptHint: "Empty uses the built-in instruction; a type and summary are still returned. Saves on blur.",
|
|
1735
2365
|
loading: "Loading title settings…",
|
|
1736
2366
|
model: "Title model",
|
|
1737
|
-
modelDefault: "
|
|
2367
|
+
modelDefault: "Default auxiliary model",
|
|
2368
|
+
modelHint: "Uses the global default auxiliary model; when none is set, the current conversation model, then the host default chat model.",
|
|
1738
2369
|
cadence: "Update cadence",
|
|
1739
2370
|
cadenceAll: "Track the current task (every message)",
|
|
1740
2371
|
cadenceFirst: "First message only",
|
|
@@ -2111,7 +2742,7 @@ function TitleSettings(props) {
|
|
|
2111
2742
|
});
|
|
2112
2743
|
}
|
|
2113
2744
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2114
|
-
className: "current-title-settings ct-root
|
|
2745
|
+
className: "current-title-settings ct-root",
|
|
2115
2746
|
lang: seat.locale,
|
|
2116
2747
|
"data-testid": "current-title-settings",
|
|
2117
2748
|
children: [
|
|
@@ -2348,6 +2979,10 @@ function TitleSettings(props) {
|
|
|
2348
2979
|
modelLabel: text.model,
|
|
2349
2980
|
modelValue: currentLabel,
|
|
2350
2981
|
defaultEffortLabel: text.modelDefault
|
|
2982
|
+
}),
|
|
2983
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2984
|
+
className: "dsh-ui-meta",
|
|
2985
|
+
children: text.modelHint
|
|
2351
2986
|
})
|
|
2352
2987
|
]
|
|
2353
2988
|
}),
|
|
@@ -2377,8 +3012,56 @@ function TitleSettings(props) {
|
|
|
2377
3012
|
]
|
|
2378
3013
|
});
|
|
2379
3014
|
}
|
|
3015
|
+
/**
|
|
3016
|
+
* The settings row: a named native details group. The content mounts
|
|
3017
|
+
* on the first expand only — the shared page must not fire every plugin's
|
|
3018
|
+
* model/status requests — and stays mounted afterwards so a collapsed group
|
|
3019
|
+
* never drops an unsaved prompt draft or an in-flight write.
|
|
3020
|
+
*/
|
|
3021
|
+
function TitleSettingsItem(props) {
|
|
3022
|
+
const seat = useNativeSeat(props.client);
|
|
3023
|
+
const text = titleCopy[seat.locale];
|
|
3024
|
+
const [visited, setVisited] = (0, react.useState)(false);
|
|
3025
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
|
3026
|
+
className: "ct-root ct-item",
|
|
3027
|
+
lang: seat.locale,
|
|
3028
|
+
"data-testid": "current-title-settings-item",
|
|
3029
|
+
onToggle: (event) => {
|
|
3030
|
+
if (event.currentTarget.open) setVisited(true);
|
|
3031
|
+
},
|
|
3032
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", {
|
|
3033
|
+
className: "ct-item-summary",
|
|
3034
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3035
|
+
className: "ct-item-title",
|
|
3036
|
+
children: text.label
|
|
3037
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3038
|
+
className: "ct-item-desc",
|
|
3039
|
+
children: text.groupHint
|
|
3040
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {
|
|
3041
|
+
className: "ct-item-chevron",
|
|
3042
|
+
"aria-hidden": "true"
|
|
3043
|
+
})]
|
|
3044
|
+
}), visited ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3045
|
+
className: "ct-item-body",
|
|
3046
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TitleSettings, {
|
|
3047
|
+
client: props.client,
|
|
3048
|
+
marker: props.marker,
|
|
3049
|
+
subscribeSettings: props.subscribeSettings
|
|
3050
|
+
})
|
|
3051
|
+
}) : null]
|
|
3052
|
+
});
|
|
3053
|
+
}
|
|
2380
3054
|
const currentTitleOwnCss = `
|
|
2381
3055
|
.ct-root .ct-prompt { min-height: 96px; }
|
|
3056
|
+
.ct-root.ct-item { padding: 0; border-bottom: 0.5px solid var(--dsw-alias-border-l2); }
|
|
3057
|
+
.ct-root .ct-item-summary { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 16px 0; list-style: none; cursor: pointer; }
|
|
3058
|
+
.ct-root .ct-item-summary::-webkit-details-marker { display: none; }
|
|
3059
|
+
.ct-root .ct-item-summary > span:first-child { min-width: 0; }
|
|
3060
|
+
.ct-root .ct-item-title { display: block; font-size: 14px; line-height: 20px; color: var(--dsw-alias-label-primary); }
|
|
3061
|
+
.ct-root .ct-item-desc { display: block; margin-top: 4px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
3062
|
+
.ct-root .ct-item-chevron { width: 14px; height: 14px; color: var(--dsw-alias-label-secondary); transition: transform 0.15s ease; }
|
|
3063
|
+
.ct-root.ct-item[open] > .ct-item-summary .ct-item-chevron { transform: rotate(180deg); }
|
|
3064
|
+
.ct-root .ct-item-body { padding: 0 0 16px; }
|
|
2382
3065
|
`;
|
|
2383
3066
|
const currentTitleStyles = `${officialUiCss("ct-root")}${modelMenuCss}${currentTitleOwnCss}`;
|
|
2384
3067
|
const styles = currentTitleStyles;
|
|
@@ -2398,14 +3081,15 @@ function apply(ctx) {
|
|
|
2398
3081
|
document.head.appendChild(style);
|
|
2399
3082
|
return () => style.remove();
|
|
2400
3083
|
}, "current-title.styles");
|
|
2401
|
-
ctx.effect(() =>
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
}, () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
3084
|
+
ctx.effect(() => registerSessionSettingsItem(ctx, {
|
|
3085
|
+
id: "current-title",
|
|
3086
|
+
order: 70
|
|
3087
|
+
}, () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TitleSettingsItem, {
|
|
2405
3088
|
client,
|
|
2406
3089
|
marker,
|
|
2407
3090
|
subscribeSettings
|
|
2408
|
-
}))
|
|
3091
|
+
})), "current-title.settings");
|
|
3092
|
+
ctx.effect(() => registerAuxiliaryModelSettings(ctx), "current-title.auxiliary-model");
|
|
2409
3093
|
ctx.effect(() => {
|
|
2410
3094
|
let live = true;
|
|
2411
3095
|
client.connection.rpc.call(RPC_CHANNEL, "status", {}).then((result) => {
|
|
@@ -2423,6 +3107,7 @@ function apply(ctx) {
|
|
|
2423
3107
|
}
|
|
2424
3108
|
//#endregion
|
|
2425
3109
|
exports.TitleSettings = TitleSettings;
|
|
3110
|
+
exports.TitleSettingsItem = TitleSettingsItem;
|
|
2426
3111
|
exports.apply = apply;
|
|
2427
3112
|
exports.applyMarkerFromStatus = applyMarkerFromStatus;
|
|
2428
3113
|
exports.createTitleClientMarker = createTitleClientMarker;
|