dsh-per-message-model 0.1.6 → 0.1.8
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/lib/client.js +13 -72
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -67,48 +67,6 @@ window.__ModuleLoader__.load({
|
|
|
67
67
|
})
|
|
68
68
|
]);
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Per-message model badge as a small icon button. Missing projections
|
|
72
|
-
* degrade to the same icon with an unknown title (fail-soft, verifiable).
|
|
73
|
-
* @param value - a wire projection entry ({ provider, model, reasoningEffort, reasoningSource }).
|
|
74
|
-
* @param t - locale seat bound to this plugin's namespace.
|
|
75
|
-
*/
|
|
76
|
-
function modelBadge(value, t) {
|
|
77
|
-
const known = value !== null && typeof value === "object";
|
|
78
|
-
const provider = known && typeof value.provider === "string" ? value.provider : null;
|
|
79
|
-
const model = known && typeof value.model === "string" ? value.model : null;
|
|
80
|
-
const hasModel = provider !== null && model !== null;
|
|
81
|
-
const label = hasModel
|
|
82
|
-
? `${provider} / ${model}${t("badge.separator")}${t("badge.effort")} ${known && typeof value.reasoningEffort === "string" && value.reasoningEffort.length > 0 ? value.reasoningEffort : t("badge.effort.default")}`
|
|
83
|
-
: t("badge.unknown");
|
|
84
|
-
const title = hasModel && known && value.reasoningSource === "adapter-default"
|
|
85
|
-
? `${label}(${t("badge.effort.adapterDefault")})`
|
|
86
|
-
: hasModel ? label : t("badge.unknown.title");
|
|
87
|
-
return createElement("span", {
|
|
88
|
-
className: BADGE_PREFIX + "icon",
|
|
89
|
-
"data-dsh-per-message-model": "true",
|
|
90
|
-
"aria-label": label,
|
|
91
|
-
title
|
|
92
|
-
}, chipIcon());
|
|
93
|
-
}
|
|
94
|
-
/** Session-header occupant: current model badge (latest folded assistant message). */
|
|
95
|
-
function SessionModelBadge({ useProjection, t }) {
|
|
96
|
-
const value = useProjection("perMessageModel");
|
|
97
|
-
const current = value === void 0 || value === null || typeof value !== "object" || value.current === void 0
|
|
98
|
-
? void 0
|
|
99
|
-
: value.current;
|
|
100
|
-
return modelBadge(current, t);
|
|
101
|
-
}
|
|
102
|
-
/** Assistant-actions occupant: per-message model icon, keyed by messageId
|
|
103
|
-
* (renders inside the official per-message action row, reordered after the
|
|
104
|
-
* branch button and before the time clock via CSS flex order). */
|
|
105
|
-
function PerMessageModelBadge({ messageId, useProjection, t }) {
|
|
106
|
-
const value = useProjection("perMessageModel");
|
|
107
|
-
const entry = value === void 0 || value === null || typeof value !== "object" || value.messages === void 0
|
|
108
|
-
? void 0
|
|
109
|
-
: value.messages[messageId];
|
|
110
|
-
return modelBadge(entry, t);
|
|
111
|
-
}
|
|
112
70
|
//#endregion
|
|
113
71
|
//#region client footer
|
|
114
72
|
/**
|
|
@@ -124,13 +82,14 @@ window.__ModuleLoader__.load({
|
|
|
124
82
|
* hook-based state in dock seats; the unfold/collapse is a pure DOM class
|
|
125
83
|
* toggle plus an inline transform on the icon, so it works in any host.
|
|
126
84
|
*/
|
|
127
|
-
function
|
|
85
|
+
function MessageModelBadge({ messageId, useProjection, t }) {
|
|
128
86
|
let value = null;
|
|
129
87
|
try { value = useProjection("perMessageModel"); } catch (err) { value = null; }
|
|
130
88
|
const hasValue = value !== null && value !== void 0 && typeof value === "object";
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
89
|
+
const messages = hasValue && typeof value.messages === "object" && value.messages !== null ? value.messages : null;
|
|
90
|
+
const entry = messages !== null && typeof messageId === "string" ? messages[messageId] : null;
|
|
91
|
+
const provider = entry !== null && typeof entry === "object" && typeof entry.provider === "string" ? entry.provider : null;
|
|
92
|
+
const model = entry !== null && typeof entry === "object" && typeof entry.model === "string" ? entry.model : null;
|
|
134
93
|
let label;
|
|
135
94
|
try { label = provider !== null && model !== null ? provider + " / " + model : (typeof t === "function" ? t("badge.unknown") : "model unknown"); }
|
|
136
95
|
catch (err) { label = provider !== null && model !== null ? provider + " / " + model : "model unknown"; }
|
|
@@ -171,8 +130,7 @@ window.__ModuleLoader__.load({
|
|
|
171
130
|
"data-open": "false"
|
|
172
131
|
}, label)
|
|
173
132
|
]);
|
|
174
|
-
}
|
|
175
|
-
//#endregion //#endregion
|
|
133
|
+
}//#endregion //#endregion
|
|
176
134
|
//#region client divider
|
|
177
135
|
/** Fixed Chinese copy for the model-switch divider (user-required). */
|
|
178
136
|
const SWITCH_COPY = "模型切换:";
|
|
@@ -304,12 +262,7 @@ window.__ModuleLoader__.load({
|
|
|
304
262
|
const badgeStyle = document.createElement("style");
|
|
305
263
|
badgeStyle.dataset.dshPerMessageModel = BADGE_PREFIX;
|
|
306
264
|
badgeStyle.textContent = [
|
|
307
|
-
|
|
308
|
-
`[data-dsh-per-message-model]{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;margin:0 2px;color:var(--dsw-alias-label-tertiary);border-radius:5px;cursor:default}`,
|
|
309
|
-
`[data-dsh-per-message-model]:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base-2, var(--dsw-alias-bg-hover, rgba(128,128,128,.12)))}`,
|
|
310
|
-
// Reorder inside the official action row: copy(0) branch(0) icon(3) clock(4)
|
|
311
|
-
`[data-dsh-per-message-model]{order:3}`,
|
|
312
|
-
`div[class*="actions"]:has([data-slot="conversation.chat.assistant-actions"]) [class*="timeEnd"]{order:4}`,
|
|
265
|
+
|
|
313
266
|
// In-stream divider: full-width block, embeds in the message flow.
|
|
314
267
|
// Label (模型切换:) and arrow are gray; model names are darker/bolder.
|
|
315
268
|
`[data-dsh-model-switch]{display:flex;align-items:center;gap:8px;margin:10px 0 16px;padding:10px 14px;border:1.5px solid var(--dsw-alias-state-business-primary, #4f8cff);border-radius:10px;background:var(--dsw-alias-state-business-tertiary, rgba(79,140,255,.12));box-shadow:0 1px 3px rgba(0,0,0,.10);color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;user-select:none}`,
|
|
@@ -317,39 +270,27 @@ window.__ModuleLoader__.load({
|
|
|
317
270
|
`[data-dsh-model-switch] [class*="-divider-model"]{flex:none;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-primary);font-weight:700}`,
|
|
318
271
|
`[data-dsh-model-switch] [class*="-divider-arrow"]{flex:none;display:inline-flex;align-items:center;color:var(--dsw-alias-label-tertiary)}`,
|
|
319
272
|
// Composer-dock model button: chip icon + unfoldable label (scroll).
|
|
320
|
-
`[data-dsh-per-message-model-footer]{display:inline-flex;align-items:center;gap:
|
|
273
|
+
`[data-dsh-per-message-model-footer]{display:inline-flex;align-items:center;gap:4px;padding:2px 6px;border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.25));border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;max-width:100%;width:fit-content;flex:none;overflow:hidden;vertical-align:middle}`,
|
|
321
274
|
`[data-dsh-per-message-model-footer]:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.12))}`,
|
|
322
275
|
`[data-dsh-per-message-model-footer] [class*="-footer-icon"]{display:inline-flex;align-items:center;flex:none;transition:transform .45s cubic-bezier(.34,1.56,.64,1)}`,
|
|
323
|
-
`[data-dsh-per-message-model-footer] [class*="-footer-label"]{display:inline-block;overflow:hidden;white-space:nowrap;max-width:0;opacity:0;transition:max-width .45s cubic-bezier(.4,0,.2,1),opacity .35s ease;font-size:
|
|
276
|
+
`[data-dsh-per-message-model-footer] [class*="-footer-label"]{display:inline-block;overflow:hidden;white-space:nowrap;max-width:0;opacity:0;transition:max-width .45s cubic-bezier(.4,0,.2,1),opacity .35s ease;font-size:11px;line-height:16px;color:var(--dsw-alias-label-primary);font-weight:600}`,
|
|
324
277
|
`[data-dsh-per-message-model-footer] [class*="-footer-label"][data-open="true"]{max-width:360px;opacity:1}`
|
|
325
278
|
].join("\n");
|
|
326
279
|
document.head.appendChild(badgeStyle);
|
|
327
280
|
ctx.effect(() => () => badgeStyle.remove(), "per-message-model: css");
|
|
328
281
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "per-message-model: dictionaries");
|
|
329
|
-
ctx.slots.inject("conversation.session.header.actions", () => ctx.slots.register({
|
|
330
|
-
name: "conversation.session.header.actions",
|
|
331
|
-
id: "dsh-per-message-model-header",
|
|
332
|
-
locale: NS,
|
|
333
|
-
order: 80
|
|
334
|
-
}, SessionModelBadge));
|
|
335
|
-
ctx.slots.inject("conversation.chat.assistant-actions", () => ctx.slots.register({
|
|
336
|
-
name: "conversation.chat.assistant-actions",
|
|
337
|
-
id: "dsh-per-message-model-badge",
|
|
338
|
-
locale: NS,
|
|
339
|
-
order: 40
|
|
340
|
-
}, PerMessageModelBadge));
|
|
341
282
|
ctx.slots.inject("conversation.session.header.actions", () => ctx.slots.register({
|
|
342
283
|
name: "conversation.session.header.actions",
|
|
343
284
|
id: "dsh-per-message-model-switch",
|
|
344
285
|
locale: NS,
|
|
345
286
|
order: 90
|
|
346
287
|
}, ModelSwitchDivider));
|
|
347
|
-
ctx.slots.inject("conversation.
|
|
348
|
-
name: "conversation.
|
|
288
|
+
ctx.slots.inject("conversation.chat.assistant-actions", () => ctx.slots.register({
|
|
289
|
+
name: "conversation.chat.assistant-actions",
|
|
349
290
|
id: "dsh-per-message-model-footer",
|
|
350
291
|
locale: NS,
|
|
351
|
-
order:
|
|
352
|
-
},
|
|
292
|
+
order: 40
|
|
293
|
+
}, MessageModelBadge));
|
|
353
294
|
}
|
|
354
295
|
//#endregion
|
|
355
296
|
exports.apply = apply;
|