dsh-model-select-plus 0.2.1 → 0.2.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 +4 -4
- package/lib/client.cjs +173 -49
- package/package.json +11 -7
- package/src/client.js +204 -68
package/README.md
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
|
-
1. **单栏列表**:模型按 provider 分组全部展开,行高 34px(与 DSH 原生菜单一致),卡片
|
|
8
|
-
2.
|
|
7
|
+
1. **单栏列表**:模型按 provider 分组全部展开,行高 34px(与 DSH 原生菜单一致),卡片 360×440;没有折叠、没有 Tag 条、没有底部状态条。
|
|
8
|
+
2. **思考等级外置**:composer 里模型芯片右侧是独立的等级芯片,点开即选,立即生效;切换等级完全不用打开、也不用在列表里找当前模型。没有推理等级的模型不显示这个芯片。
|
|
9
9
|
3. **当前行展开**:只有当前模型向下展开 2 行描述,其余行保持 34px 基线;打开菜单时自动把当前模型滚到列表中间。
|
|
10
10
|
4. **搜索**:34px 单行搜索,按模型名 / 描述 / provider 过滤,带清除按钮;打开即自动聚焦。
|
|
11
11
|
5. **收藏置顶**:行尾星标(悬停出现)收藏,收藏项移动到顶部独立分组,并在行尾标出 provider;取消后回到原分组。收藏存于浏览器内存,刷新即重置。
|
|
12
12
|
6. **分组标题**:11px 吸顶,只在真正吸到顶部时铺底色,静态时是纯文字;不显示数量,也不可折叠。
|
|
13
13
|
7. **选中态**:6% 填充 + 行尾对勾 + 500 字重,不再用 10% 灰块(那读起来像禁用)。
|
|
14
|
-
8.
|
|
15
|
-
9.
|
|
14
|
+
8. **触发按钮**:模型芯片显示 `供应商/模型`,供应商 11px 次级色,超宽时先省略供应商、保住模型名;等级在旁边的独立芯片里。
|
|
15
|
+
9. **键盘**:模型列表里 `↑` / `↓` 移动、`Enter` 选择、`Esc` 关闭;等级菜单同样支持 `↑` / `↓` 与 `Esc`。
|
|
16
16
|
|
|
17
17
|
打开时按触发按钮在视口内的剩余空间决定向上/向下弹,收敛高度并把左右夹在视口内;浅色与深色都走主题令牌(深色下分段控件的滑块改用 active 填充),所有图标为手绘 SVG,不用文字字符充当图标。
|
|
18
18
|
|
package/lib/client.cjs
CHANGED
|
@@ -41,6 +41,7 @@ var module = { exports: {} };
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(client_exports);
|
|
43
43
|
var import_react = __toESM(require("react"), 1);
|
|
44
|
+
var import_react_dom = require("react-dom");
|
|
44
45
|
var name = "dsh-model-select-plus";
|
|
45
46
|
var inject = ["slots"];
|
|
46
47
|
var API = "/plugins/dsh-model-select-plus/api";
|
|
@@ -49,7 +50,10 @@ var module = { exports: {} };
|
|
|
49
50
|
var h = import_react.default.createElement;
|
|
50
51
|
var CSS = `
|
|
51
52
|
.mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
|
|
52
|
-
|
|
53
|
+
/* The floating layers portal out of .mdsl-root, so they carry their own reset. */
|
|
54
|
+
.mdsl-backdrop, .mdsl-menu, .mdsl-menu *, .mdsl-menu *::before, .mdsl-menu *::after,
|
|
55
|
+
.mdsl-effort-menu, .mdsl-effort-menu *, .mdsl-effort-menu *::before, .mdsl-effort-menu *::after { box-sizing: border-box; }
|
|
56
|
+
.mdsl-root { position: relative; display: inline-flex; align-items: center; gap: 2px; min-width: 0; max-width: 100%; }
|
|
53
57
|
.mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
|
|
54
58
|
|
|
55
59
|
/* Trigger: the composer's 28px chip, same as the sibling permission / plan
|
|
@@ -62,13 +66,12 @@ var module = { exports: {} };
|
|
|
62
66
|
/* The provider is context, the model is the subject: on overflow the level
|
|
63
67
|
collapses first, then the provider, and the model name stays whole. */
|
|
64
68
|
.mdsl-trigger-provider { flex-shrink: 100; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-tertiary); }
|
|
65
|
-
.mdsl-effort { flex-shrink: 1000; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-caption); }
|
|
66
69
|
.mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
|
|
67
70
|
.mdsl-chevron-open { transform: rotate(180deg); }
|
|
68
71
|
|
|
69
|
-
/* Card: the shipped menu material.
|
|
70
|
-
|
|
71
|
-
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width:
|
|
72
|
+
/* Card: the shipped menu material. 360px keeps names whole now that the
|
|
73
|
+
level chips moved out to the composer. */
|
|
74
|
+
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 360px; max-width: calc(100vw - 24px); max-height: min(440px, calc(100vh - 120px)); padding: 4px; background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay)); -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); border: 0; border-radius: var(--dsw-radius-lg, 16px); --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); box-shadow: var(--dsw-elevation-prominent, 0 10px 36px rgba(0,0,0,.14)); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2); --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2); overflow: hidden; animation: mdsl-in .16s cubic-bezier(.22, 1, .36, 1); transform-origin: bottom right; }
|
|
72
75
|
body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
73
76
|
@keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
|
|
74
77
|
@media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
|
|
@@ -116,15 +119,22 @@ var module = { exports: {} };
|
|
|
116
119
|
.mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
117
120
|
.mdsl-star-on { color: var(--dsw-alias-brand-primary); }
|
|
118
121
|
|
|
119
|
-
/*
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.mdsl-
|
|
123
|
-
.mdsl-
|
|
124
|
-
.mdsl-
|
|
125
|
-
.mdsl-
|
|
126
|
-
.mdsl-
|
|
127
|
-
|
|
122
|
+
/* The level is its own composer control beside the model chip: switching it
|
|
123
|
+
never opens (or scrolls) the model list. */
|
|
124
|
+
.mdsl-effort-btn { display: flex; align-items: center; gap: 2px; flex: none; height: 28px; padding: 0 4px; border: 0; border-radius: var(--dsw-radius-sm, 8px); background: transparent; color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 13px; line-height: 20px; cursor: pointer; outline: none; }
|
|
125
|
+
.mdsl-effort-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
126
|
+
.mdsl-effort-btn:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
127
|
+
.mdsl-effort-btn:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
128
|
+
.mdsl-effort-btn-open { background: var(--dsw-alias-interactive-bg-active); }
|
|
129
|
+
.mdsl-effort-label { white-space: nowrap; }
|
|
130
|
+
|
|
131
|
+
.mdsl-effort-menu { position: fixed; z-index: 41; display: flex; flex-direction: column; padding: 4px; background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay)); -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); border-radius: var(--dsw-radius-md, 12px); --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); box-shadow: var(--dsw-elevation-prominent, 0 10px 36px rgba(0,0,0,.14)); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; animation: mdsl-in .16s cubic-bezier(.22, 1, .36, 1); }
|
|
132
|
+
body[data-ds-dark-theme] .mdsl-effort-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
133
|
+
.mdsl-effort-item { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; line-height: 20px; text-align: left; cursor: pointer; }
|
|
134
|
+
.mdsl-effort-item:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
135
|
+
.mdsl-effort-item:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
136
|
+
.mdsl-effort-item[aria-checked="true"] { font-weight: 500; }
|
|
137
|
+
.mdsl-effort-item .mdsl-check { margin-left: auto; }
|
|
128
138
|
|
|
129
139
|
.mdsl-sub { padding: 2px 8px 8px; }
|
|
130
140
|
.mdsl-desc { color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 16px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
|
@@ -179,10 +189,14 @@ var module = { exports: {} };
|
|
|
179
189
|
const sessionId = props.sessionId;
|
|
180
190
|
const locked = props.locked === true;
|
|
181
191
|
const triggerRef = import_react.default.useRef(null);
|
|
192
|
+
const effortRef = import_react.default.useRef(null);
|
|
193
|
+
const effortMenuRef = import_react.default.useRef(null);
|
|
182
194
|
const bodyRef = import_react.default.useRef(null);
|
|
183
195
|
const searchRef = import_react.default.useRef(null);
|
|
184
196
|
const [placement, setPlacement] = import_react.default.useState(null);
|
|
185
197
|
const [open, setOpen] = import_react.default.useState(false);
|
|
198
|
+
const [effortOpen, setEffortOpen] = import_react.default.useState(false);
|
|
199
|
+
const [effortPlacement, setEffortPlacement] = import_react.default.useState(null);
|
|
186
200
|
const [data, setData] = import_react.default.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
187
201
|
const [query, setQuery] = import_react.default.useState("");
|
|
188
202
|
const [busy, setBusy] = import_react.default.useState(false);
|
|
@@ -239,6 +253,45 @@ var module = { exports: {} };
|
|
|
239
253
|
return next;
|
|
240
254
|
});
|
|
241
255
|
};
|
|
256
|
+
const placeEffort = () => {
|
|
257
|
+
const el = effortRef.current;
|
|
258
|
+
if (!el) return;
|
|
259
|
+
const rect = el.getBoundingClientRect();
|
|
260
|
+
const margin = 12;
|
|
261
|
+
const gap = 6;
|
|
262
|
+
const width = 156;
|
|
263
|
+
const spaceAbove = rect.top - gap - margin;
|
|
264
|
+
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
265
|
+
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
266
|
+
const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
|
|
267
|
+
setEffortPlacement({
|
|
268
|
+
side,
|
|
269
|
+
width,
|
|
270
|
+
left,
|
|
271
|
+
bottom: window.innerHeight - rect.top + gap,
|
|
272
|
+
top: rect.bottom + gap
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
import_react.default.useLayoutEffect(() => {
|
|
276
|
+
if (effortOpen) placeEffort();
|
|
277
|
+
}, [effortOpen]);
|
|
278
|
+
import_react.default.useLayoutEffect(() => {
|
|
279
|
+
if (!effortOpen) return;
|
|
280
|
+
const menu = effortMenuRef.current;
|
|
281
|
+
if (menu === null) return;
|
|
282
|
+
const active = menu.querySelector('[aria-checked="true"]') || menu.querySelector(".mdsl-effort-item");
|
|
283
|
+
if (active !== null) active.focus({ preventScroll: true });
|
|
284
|
+
}, [effortOpen, effortPlacement]);
|
|
285
|
+
import_react.default.useEffect(() => {
|
|
286
|
+
if (!effortOpen) return;
|
|
287
|
+
const reposition = () => placeEffort();
|
|
288
|
+
window.addEventListener("resize", reposition);
|
|
289
|
+
window.addEventListener("scroll", reposition, true);
|
|
290
|
+
return () => {
|
|
291
|
+
window.removeEventListener("resize", reposition);
|
|
292
|
+
window.removeEventListener("scroll", reposition, true);
|
|
293
|
+
};
|
|
294
|
+
}, [effortOpen]);
|
|
242
295
|
import_react.default.useLayoutEffect(() => {
|
|
243
296
|
if (open) placeMenu();
|
|
244
297
|
}, [open]);
|
|
@@ -308,6 +361,8 @@ var module = { exports: {} };
|
|
|
308
361
|
if (el) el.focus({ preventScroll: true });
|
|
309
362
|
};
|
|
310
363
|
const openMenu = () => {
|
|
364
|
+
setEffortOpen(false);
|
|
365
|
+
setEffortPlacement(null);
|
|
311
366
|
setOpen(true);
|
|
312
367
|
load();
|
|
313
368
|
};
|
|
@@ -317,7 +372,19 @@ var module = { exports: {} };
|
|
|
317
372
|
setPlacement(null);
|
|
318
373
|
focusTrigger();
|
|
319
374
|
};
|
|
320
|
-
const
|
|
375
|
+
const openEffortMenu = () => {
|
|
376
|
+
setOpen(false);
|
|
377
|
+
setQuery("");
|
|
378
|
+
setPlacement(null);
|
|
379
|
+
setEffortOpen(true);
|
|
380
|
+
};
|
|
381
|
+
const closeEffortMenu = () => {
|
|
382
|
+
setEffortOpen(false);
|
|
383
|
+
setEffortPlacement(null);
|
|
384
|
+
const el = effortRef.current;
|
|
385
|
+
if (el !== null) el.focus({ preventScroll: true });
|
|
386
|
+
};
|
|
387
|
+
const submitSelection = (sel, after) => {
|
|
321
388
|
if (busy) return;
|
|
322
389
|
setBusy(true);
|
|
323
390
|
fetch(`${API}/select`, {
|
|
@@ -333,8 +400,7 @@ var module = { exports: {} };
|
|
|
333
400
|
setBusy(false);
|
|
334
401
|
if (res && res.ok === true) {
|
|
335
402
|
setData((d) => ({ ...d, current: res.selected || null, error: null }));
|
|
336
|
-
if (
|
|
337
|
-
closeMenu();
|
|
403
|
+
if (after) after();
|
|
338
404
|
} else {
|
|
339
405
|
setData((d) => ({ ...d, error: res && res.message || "\u9009\u62E9\u5931\u8D25" }));
|
|
340
406
|
}
|
|
@@ -353,11 +419,14 @@ var module = { exports: {} };
|
|
|
353
419
|
};
|
|
354
420
|
const choose = (g, m) => {
|
|
355
421
|
const effort = m.reasoning ? m.reasoning.defaultEffort : void 0;
|
|
356
|
-
|
|
422
|
+
submitSelection({ provider: g.id, model: m.id, ...effort === void 0 ? {} : { reasoningEffort: effort } }, closeMenu);
|
|
357
423
|
};
|
|
358
|
-
const chooseEffort = (
|
|
359
|
-
|
|
360
|
-
|
|
424
|
+
const chooseEffort = (effort) => {
|
|
425
|
+
if (current === null || current === void 0) return;
|
|
426
|
+
submitSelection(
|
|
427
|
+
{ provider: current.provider, model: current.model, ...effort === void 0 ? {} : { reasoningEffort: effort } },
|
|
428
|
+
closeEffortMenu
|
|
429
|
+
);
|
|
361
430
|
};
|
|
362
431
|
const current = data.current;
|
|
363
432
|
const curGroup = current ? data.groups.find((g) => g.id === current.provider) : void 0;
|
|
@@ -401,9 +470,7 @@ var module = { exports: {} };
|
|
|
401
470
|
const renderRow = (g, m, showProvider) => {
|
|
402
471
|
const selected = isCurrentModel(g, m);
|
|
403
472
|
const fav = favorites.has(`${g.id}/${m.id}`);
|
|
404
|
-
const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
|
|
405
473
|
const desc = typeof m.description === "string" && m.description !== "" ? m.description : void 0;
|
|
406
|
-
const rowEffort = selected ? pinnedEffort : m.reasoning ? m.reasoning.defaultEffort : void 0;
|
|
407
474
|
const stop = (ev) => {
|
|
408
475
|
if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation();
|
|
409
476
|
};
|
|
@@ -425,28 +492,6 @@ var module = { exports: {} };
|
|
|
425
492
|
},
|
|
426
493
|
h("span", { className: "mdsl-name" }, m.name),
|
|
427
494
|
showProvider ? h("span", { className: "mdsl-prov" }, g.name) : null,
|
|
428
|
-
hasEfforts ? h(
|
|
429
|
-
"span",
|
|
430
|
-
{ className: "mdsl-chips", role: "group", "aria-label": "\u63A8\u7406\u7B49\u7EA7" },
|
|
431
|
-
m.reasoning.efforts.map((e) => h(
|
|
432
|
-
"button",
|
|
433
|
-
{
|
|
434
|
-
key: e.id,
|
|
435
|
-
type: "button",
|
|
436
|
-
title: e.description || e.name,
|
|
437
|
-
"aria-pressed": rowEffort === e.id,
|
|
438
|
-
className: "mdsl-chip" + (rowEffort === e.id ? selected ? " mdsl-chip-on" : " mdsl-chip-eff" : ""),
|
|
439
|
-
onClick: (ev) => {
|
|
440
|
-
ev.stopPropagation();
|
|
441
|
-
chooseEffort(g, m, e.id);
|
|
442
|
-
},
|
|
443
|
-
// A real button fires click on Enter/Space; keep the row's own
|
|
444
|
-
// keyboard handler out of the way so the level wins.
|
|
445
|
-
onKeyDown: stop
|
|
446
|
-
},
|
|
447
|
-
e.name
|
|
448
|
-
))
|
|
449
|
-
) : null,
|
|
450
495
|
h(
|
|
451
496
|
"button",
|
|
452
497
|
{
|
|
@@ -494,7 +539,13 @@ var module = { exports: {} };
|
|
|
494
539
|
const next = at === -1 ? step > 0 ? 0 : rows.length - 1 : (at + step + rows.length) % rows.length;
|
|
495
540
|
rows[next].focus();
|
|
496
541
|
};
|
|
542
|
+
const canEffort = !!(current && curModel && curModel.reasoning && curModel.reasoning.efforts && curModel.reasoning.efforts.length);
|
|
497
543
|
const triggerTitle = current ? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "") : "\u9009\u62E9\u6A21\u578B";
|
|
544
|
+
const closeAll = () => {
|
|
545
|
+
if (open) closeMenu();
|
|
546
|
+
closeEffortMenu();
|
|
547
|
+
};
|
|
548
|
+
const overlayRoot = typeof document === "undefined" ? null : document.body;
|
|
498
549
|
return h(
|
|
499
550
|
"div",
|
|
500
551
|
{ className: "mdsl-root" },
|
|
@@ -515,11 +566,28 @@ var module = { exports: {} };
|
|
|
515
566
|
},
|
|
516
567
|
current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
|
|
517
568
|
h("span", { className: "mdsl-label" }, current ? modelName : "\u9009\u62E9\u6A21\u578B"),
|
|
518
|
-
effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
|
|
519
569
|
h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown())
|
|
520
570
|
),
|
|
521
|
-
|
|
522
|
-
|
|
571
|
+
canEffort ? h(
|
|
572
|
+
"button",
|
|
573
|
+
{
|
|
574
|
+
ref: effortRef,
|
|
575
|
+
type: "button",
|
|
576
|
+
className: "mdsl-effort-btn" + (effortOpen ? " mdsl-effort-btn-open" : ""),
|
|
577
|
+
disabled: locked,
|
|
578
|
+
title: "\u601D\u8003\u7B49\u7EA7",
|
|
579
|
+
"aria-haspopup": "menu",
|
|
580
|
+
"aria-expanded": effortOpen,
|
|
581
|
+
onClick: () => {
|
|
582
|
+
if (effortOpen) closeEffortMenu();
|
|
583
|
+
else openEffortMenu();
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
h("span", { className: "mdsl-effort-label" }, effortLabel || "\u9ED8\u8BA4"),
|
|
587
|
+
h("span", { className: "mdsl-chevron" + (effortOpen ? " mdsl-chevron-open" : "") }, chevronDown())
|
|
588
|
+
) : null,
|
|
589
|
+
(open || effortOpen) && overlayRoot !== null ? (0, import_react_dom.createPortal)(h("div", { className: "mdsl-backdrop", onClick: closeAll }), overlayRoot) : null,
|
|
590
|
+
open && placement !== null && overlayRoot !== null ? (0, import_react_dom.createPortal)(h(
|
|
523
591
|
"div",
|
|
524
592
|
{
|
|
525
593
|
className: "mdsl-menu",
|
|
@@ -580,7 +648,63 @@ var module = { exports: {} };
|
|
|
580
648
|
g.models.map((m) => renderRow(g, m, false))
|
|
581
649
|
))
|
|
582
650
|
)
|
|
583
|
-
) : null
|
|
651
|
+
), overlayRoot) : null,
|
|
652
|
+
effortOpen && effortPlacement !== null && overlayRoot !== null ? (0, import_react_dom.createPortal)(h(
|
|
653
|
+
"div",
|
|
654
|
+
{
|
|
655
|
+
ref: effortMenuRef,
|
|
656
|
+
className: "mdsl-effort-menu",
|
|
657
|
+
style: {
|
|
658
|
+
left: effortPlacement.left + "px",
|
|
659
|
+
width: effortPlacement.width + "px",
|
|
660
|
+
...effortPlacement.side === "top" ? { top: "auto", bottom: effortPlacement.bottom + "px" } : { top: effortPlacement.top + "px", bottom: "auto" }
|
|
661
|
+
},
|
|
662
|
+
role: "menu",
|
|
663
|
+
"aria-label": "\u601D\u8003\u7B49\u7EA7",
|
|
664
|
+
onKeyDown: (ev) => {
|
|
665
|
+
if (ev.key === "Escape") {
|
|
666
|
+
ev.preventDefault();
|
|
667
|
+
ev.stopPropagation();
|
|
668
|
+
closeEffortMenu();
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (ev.key !== "ArrowDown" && ev.key !== "ArrowUp") return;
|
|
672
|
+
const items = Array.from(ev.currentTarget.querySelectorAll(".mdsl-effort-item"));
|
|
673
|
+
if (items.length === 0) return;
|
|
674
|
+
ev.preventDefault();
|
|
675
|
+
const at = items.indexOf(document.activeElement);
|
|
676
|
+
const step = ev.key === "ArrowDown" ? 1 : -1;
|
|
677
|
+
const next = at === -1 ? 0 : (at + step + items.length) % items.length;
|
|
678
|
+
items[next].focus();
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
h(
|
|
682
|
+
"button",
|
|
683
|
+
{
|
|
684
|
+
type: "button",
|
|
685
|
+
role: "menuitemradio",
|
|
686
|
+
"aria-checked": pinnedEffort === void 0,
|
|
687
|
+
className: "mdsl-effort-item",
|
|
688
|
+
onClick: () => chooseEffort(void 0)
|
|
689
|
+
},
|
|
690
|
+
"\u9ED8\u8BA4",
|
|
691
|
+
pinnedEffort === void 0 ? h("span", { className: "mdsl-check" }, check()) : null
|
|
692
|
+
),
|
|
693
|
+
(curModel.reasoning.efforts || []).map((e) => h(
|
|
694
|
+
"button",
|
|
695
|
+
{
|
|
696
|
+
key: e.id,
|
|
697
|
+
type: "button",
|
|
698
|
+
role: "menuitemradio",
|
|
699
|
+
"aria-checked": pinnedEffort === e.id,
|
|
700
|
+
title: e.description || e.name,
|
|
701
|
+
className: "mdsl-effort-item",
|
|
702
|
+
onClick: () => chooseEffort(e.id)
|
|
703
|
+
},
|
|
704
|
+
e.name,
|
|
705
|
+
pinnedEffort === e.id ? h("span", { className: "mdsl-check" }, check()) : null
|
|
706
|
+
))
|
|
707
|
+
), overlayRoot) : null
|
|
584
708
|
);
|
|
585
709
|
}
|
|
586
710
|
var favorites = /* @__PURE__ */ new Set();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-select-plus",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "A calmer model-selection popup for DeepSeek Harness: provider
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "A calmer model-selection popup for DeepSeek Harness: provider/model chip with a separate reasoning-level chip beside it, provider-grouped rows at the native 34px rhythm, search and pinned favorites, replacing the composer's default ModelSelect.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/host.js",
|
|
7
7
|
"types": "lib/host.d.ts",
|
|
@@ -59,11 +59,12 @@
|
|
|
59
59
|
"esbuild": "^0.25.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@deepseek-ai/cordis": "^4.0.
|
|
63
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.
|
|
64
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
66
|
-
"react": "^18.3.1"
|
|
62
|
+
"@deepseek-ai/cordis": "^4.2.0-alpha.1",
|
|
63
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.3-alpha.2",
|
|
64
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.3-alpha.2",
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.3-alpha.2",
|
|
66
|
+
"react": "^18.3.1",
|
|
67
|
+
"react-dom": "^18.3.1"
|
|
67
68
|
},
|
|
68
69
|
"peerDependenciesMeta": {
|
|
69
70
|
"@deepseek-ai/cordis": {
|
|
@@ -80,6 +81,9 @@
|
|
|
80
81
|
},
|
|
81
82
|
"react": {
|
|
82
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"react-dom": {
|
|
86
|
+
"optional": true
|
|
83
87
|
}
|
|
84
88
|
},
|
|
85
89
|
"scripts": {
|
package/src/client.js
CHANGED
|
@@ -10,27 +10,31 @@
|
|
|
10
10
|
* through `document` (the `plugin-dashboard` / `skin-material-you` pattern).
|
|
11
11
|
*
|
|
12
12
|
* Layout (one column, native menu measures):
|
|
13
|
-
* - card
|
|
14
|
-
*
|
|
15
|
-
* -
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* expands, and only for its two-line description
|
|
13
|
+
* - card 360 x 440, shipped menu material, 16px radius
|
|
14
|
+
* - one 34px search line with a 0.5px rule; no jump rail
|
|
15
|
+
* - rows at the native 34px height: name, star, check; selection is a 6% fill
|
|
16
|
+
* plus the trailing check, and only the current row expands (for its
|
|
17
|
+
* two-line description)
|
|
18
|
+
* - the reasoning level is a second composer chip beside the model chip, with
|
|
19
|
+
* a small level menu: switching it never opens or scrolls the model list
|
|
21
20
|
* - provider headings are 11px labels that paint their group-header fill only
|
|
22
21
|
* while stuck to the top; static groups stay flat
|
|
23
22
|
* - favorites stay pinned in their own top group, and their rows carry the
|
|
24
23
|
* provider name because the same model exists under several providers
|
|
25
|
-
* - the
|
|
26
|
-
* effort level lives in the tooltip and on the row chips
|
|
24
|
+
* - the model chip shows provider/model (the provider ellipsizes first)
|
|
27
25
|
* - re-opening centers the current model instead of resetting to the top
|
|
26
|
+
* - both popups and their click-catching backdrop portal to `document.body`:
|
|
27
|
+
* the composer seat sets `will-change: transform`, which makes it the
|
|
28
|
+
* containing block for fixed descendants, and an overlay left inside it
|
|
29
|
+
* would be offset by the seat's own origin (DSH's shipped composer menus
|
|
30
|
+
* portal for the same reason)
|
|
28
31
|
*
|
|
29
32
|
* Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
|
|
30
33
|
* The seat passes `locked` (owner prop) and we inject `sessionId`.
|
|
31
34
|
*/
|
|
32
35
|
|
|
33
36
|
import React from "react";
|
|
37
|
+
import { createPortal } from "react-dom";
|
|
34
38
|
|
|
35
39
|
export const name = "dsh-model-select-plus";
|
|
36
40
|
export const inject = ["slots"];
|
|
@@ -43,7 +47,10 @@ const h = React.createElement;
|
|
|
43
47
|
|
|
44
48
|
const CSS = `
|
|
45
49
|
.mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
|
|
46
|
-
|
|
50
|
+
/* The floating layers portal out of .mdsl-root, so they carry their own reset. */
|
|
51
|
+
.mdsl-backdrop, .mdsl-menu, .mdsl-menu *, .mdsl-menu *::before, .mdsl-menu *::after,
|
|
52
|
+
.mdsl-effort-menu, .mdsl-effort-menu *, .mdsl-effort-menu *::before, .mdsl-effort-menu *::after { box-sizing: border-box; }
|
|
53
|
+
.mdsl-root { position: relative; display: inline-flex; align-items: center; gap: 2px; min-width: 0; max-width: 100%; }
|
|
47
54
|
.mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
|
|
48
55
|
|
|
49
56
|
/* Trigger: the composer's 28px chip, same as the sibling permission / plan
|
|
@@ -56,13 +63,12 @@ const CSS = `
|
|
|
56
63
|
/* The provider is context, the model is the subject: on overflow the level
|
|
57
64
|
collapses first, then the provider, and the model name stays whole. */
|
|
58
65
|
.mdsl-trigger-provider { flex-shrink: 100; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-tertiary); }
|
|
59
|
-
.mdsl-effort { flex-shrink: 1000; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-caption); }
|
|
60
66
|
.mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
|
|
61
67
|
.mdsl-chevron-open { transform: rotate(180deg); }
|
|
62
68
|
|
|
63
|
-
/* Card: the shipped menu material.
|
|
64
|
-
|
|
65
|
-
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width:
|
|
69
|
+
/* Card: the shipped menu material. 360px keeps names whole now that the
|
|
70
|
+
level chips moved out to the composer. */
|
|
71
|
+
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 360px; max-width: calc(100vw - 24px); max-height: min(440px, calc(100vh - 120px)); padding: 4px; background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay)); -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); border: 0; border-radius: var(--dsw-radius-lg, 16px); --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); box-shadow: var(--dsw-elevation-prominent, 0 10px 36px rgba(0,0,0,.14)); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2); --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2); overflow: hidden; animation: mdsl-in .16s cubic-bezier(.22, 1, .36, 1); transform-origin: bottom right; }
|
|
66
72
|
body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
67
73
|
@keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
|
|
68
74
|
@media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
|
|
@@ -110,15 +116,22 @@ const CSS = `
|
|
|
110
116
|
.mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
111
117
|
.mdsl-star-on { color: var(--dsw-alias-brand-primary); }
|
|
112
118
|
|
|
113
|
-
/*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.mdsl-
|
|
117
|
-
.mdsl-
|
|
118
|
-
.mdsl-
|
|
119
|
-
.mdsl-
|
|
120
|
-
.mdsl-
|
|
121
|
-
|
|
119
|
+
/* The level is its own composer control beside the model chip: switching it
|
|
120
|
+
never opens (or scrolls) the model list. */
|
|
121
|
+
.mdsl-effort-btn { display: flex; align-items: center; gap: 2px; flex: none; height: 28px; padding: 0 4px; border: 0; border-radius: var(--dsw-radius-sm, 8px); background: transparent; color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 13px; line-height: 20px; cursor: pointer; outline: none; }
|
|
122
|
+
.mdsl-effort-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
123
|
+
.mdsl-effort-btn:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
124
|
+
.mdsl-effort-btn:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
125
|
+
.mdsl-effort-btn-open { background: var(--dsw-alias-interactive-bg-active); }
|
|
126
|
+
.mdsl-effort-label { white-space: nowrap; }
|
|
127
|
+
|
|
128
|
+
.mdsl-effort-menu { position: fixed; z-index: 41; display: flex; flex-direction: column; padding: 4px; background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay)); -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); backdrop-filter: var(--dsw-menu-backdrop-filter, blur(20px) saturate(140%)); border-radius: var(--dsw-radius-md, 12px); --dsw-elevation-stroke-color: var(--dsw-alias-border-l1); box-shadow: var(--dsw-elevation-prominent, 0 10px 36px rgba(0,0,0,.14)); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; animation: mdsl-in .16s cubic-bezier(.22, 1, .36, 1); }
|
|
129
|
+
body[data-ds-dark-theme] .mdsl-effort-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
130
|
+
.mdsl-effort-item { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; line-height: 20px; text-align: left; cursor: pointer; }
|
|
131
|
+
.mdsl-effort-item:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
132
|
+
.mdsl-effort-item:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
133
|
+
.mdsl-effort-item[aria-checked="true"] { font-weight: 500; }
|
|
134
|
+
.mdsl-effort-item .mdsl-check { margin-left: auto; }
|
|
122
135
|
|
|
123
136
|
.mdsl-sub { padding: 2px 8px 8px; }
|
|
124
137
|
.mdsl-desc { color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 16px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
|
@@ -176,10 +189,14 @@ function ModelSelectLite(props) {
|
|
|
176
189
|
const sessionId = props.sessionId;
|
|
177
190
|
const locked = props.locked === true;
|
|
178
191
|
const triggerRef = React.useRef(null);
|
|
192
|
+
const effortRef = React.useRef(null);
|
|
193
|
+
const effortMenuRef = React.useRef(null);
|
|
179
194
|
const bodyRef = React.useRef(null);
|
|
180
195
|
const searchRef = React.useRef(null);
|
|
181
196
|
const [placement, setPlacement] = React.useState(null);
|
|
182
197
|
const [open, setOpen] = React.useState(false);
|
|
198
|
+
const [effortOpen, setEffortOpen] = React.useState(false);
|
|
199
|
+
const [effortPlacement, setEffortPlacement] = React.useState(null);
|
|
183
200
|
const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
184
201
|
const [query, setQuery] = React.useState("");
|
|
185
202
|
const [busy, setBusy] = React.useState(false);
|
|
@@ -265,6 +282,51 @@ function ModelSelectLite(props) {
|
|
|
265
282
|
});
|
|
266
283
|
};
|
|
267
284
|
|
|
285
|
+
// The level menu is a small fixed card anchored to its chip, opening upward
|
|
286
|
+
// unless the chip sits near the top of the window.
|
|
287
|
+
const placeEffort = () => {
|
|
288
|
+
const el = effortRef.current;
|
|
289
|
+
if (!el) return;
|
|
290
|
+
const rect = el.getBoundingClientRect();
|
|
291
|
+
const margin = 12;
|
|
292
|
+
const gap = 6;
|
|
293
|
+
const width = 156;
|
|
294
|
+
const spaceAbove = rect.top - gap - margin;
|
|
295
|
+
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
296
|
+
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
297
|
+
const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
|
|
298
|
+
setEffortPlacement({
|
|
299
|
+
side,
|
|
300
|
+
width,
|
|
301
|
+
left,
|
|
302
|
+
bottom: window.innerHeight - rect.top + gap,
|
|
303
|
+
top: rect.bottom + gap,
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
React.useLayoutEffect(() => {
|
|
308
|
+
if (effortOpen) placeEffort();
|
|
309
|
+
}, [effortOpen]);
|
|
310
|
+
|
|
311
|
+
React.useLayoutEffect(() => {
|
|
312
|
+
if (!effortOpen) return;
|
|
313
|
+
const menu = effortMenuRef.current;
|
|
314
|
+
if (menu === null) return;
|
|
315
|
+
const active = menu.querySelector('[aria-checked="true"]') || menu.querySelector(".mdsl-effort-item");
|
|
316
|
+
if (active !== null) active.focus({ preventScroll: true });
|
|
317
|
+
}, [effortOpen, effortPlacement]);
|
|
318
|
+
|
|
319
|
+
React.useEffect(() => {
|
|
320
|
+
if (!effortOpen) return;
|
|
321
|
+
const reposition = () => placeEffort();
|
|
322
|
+
window.addEventListener("resize", reposition);
|
|
323
|
+
window.addEventListener("scroll", reposition, true);
|
|
324
|
+
return () => {
|
|
325
|
+
window.removeEventListener("resize", reposition);
|
|
326
|
+
window.removeEventListener("scroll", reposition, true);
|
|
327
|
+
};
|
|
328
|
+
}, [effortOpen]);
|
|
329
|
+
|
|
268
330
|
React.useLayoutEffect(() => {
|
|
269
331
|
if (open) placeMenu();
|
|
270
332
|
}, [open]);
|
|
@@ -335,15 +397,33 @@ function ModelSelectLite(props) {
|
|
|
335
397
|
const el = triggerRef.current;
|
|
336
398
|
if (el) el.focus({ preventScroll: true });
|
|
337
399
|
};
|
|
338
|
-
const openMenu = () => {
|
|
400
|
+
const openMenu = () => {
|
|
401
|
+
setEffortOpen(false);
|
|
402
|
+
setEffortPlacement(null);
|
|
403
|
+
setOpen(true);
|
|
404
|
+
load();
|
|
405
|
+
};
|
|
339
406
|
const closeMenu = () => {
|
|
340
407
|
setOpen(false);
|
|
341
408
|
setQuery("");
|
|
342
409
|
setPlacement(null);
|
|
343
410
|
focusTrigger();
|
|
344
411
|
};
|
|
412
|
+
const openEffortMenu = () => {
|
|
413
|
+
// One popup at a time; closing the model card here must not steal focus.
|
|
414
|
+
setOpen(false);
|
|
415
|
+
setQuery("");
|
|
416
|
+
setPlacement(null);
|
|
417
|
+
setEffortOpen(true);
|
|
418
|
+
};
|
|
419
|
+
const closeEffortMenu = () => {
|
|
420
|
+
setEffortOpen(false);
|
|
421
|
+
setEffortPlacement(null);
|
|
422
|
+
const el = effortRef.current;
|
|
423
|
+
if (el !== null) el.focus({ preventScroll: true });
|
|
424
|
+
};
|
|
345
425
|
|
|
346
|
-
const
|
|
426
|
+
const submitSelection = (sel, after) => {
|
|
347
427
|
if (busy) return;
|
|
348
428
|
setBusy(true);
|
|
349
429
|
fetch(`${API}/select`, {
|
|
@@ -361,8 +441,7 @@ function ModelSelectLite(props) {
|
|
|
361
441
|
setBusy(false);
|
|
362
442
|
if (res && res.ok === true) {
|
|
363
443
|
setData((d) => ({ ...d, current: res.selected || null, error: null }));
|
|
364
|
-
if (
|
|
365
|
-
closeMenu();
|
|
444
|
+
if (after) after();
|
|
366
445
|
} else {
|
|
367
446
|
setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
|
|
368
447
|
}
|
|
@@ -383,16 +462,15 @@ function ModelSelectLite(props) {
|
|
|
383
462
|
|
|
384
463
|
const choose = (g, m) => {
|
|
385
464
|
const effort = m.reasoning ? m.reasoning.defaultEffort : undefined;
|
|
386
|
-
|
|
465
|
+
submitSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, closeMenu);
|
|
387
466
|
};
|
|
388
467
|
|
|
389
|
-
const chooseEffort = (
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, sameModel);
|
|
468
|
+
const chooseEffort = (effort) => {
|
|
469
|
+
if (current === null || current === undefined) return;
|
|
470
|
+
submitSelection(
|
|
471
|
+
{ provider: current.provider, model: current.model, ...(effort === undefined ? {} : { reasoningEffort: effort }) },
|
|
472
|
+
closeEffortMenu,
|
|
473
|
+
);
|
|
396
474
|
};
|
|
397
475
|
|
|
398
476
|
const current = data.current;
|
|
@@ -445,11 +523,7 @@ function ModelSelectLite(props) {
|
|
|
445
523
|
const renderRow = (g, m, showProvider) => {
|
|
446
524
|
const selected = isCurrentModel(g, m);
|
|
447
525
|
const fav = favorites.has(`${g.id}/${m.id}`);
|
|
448
|
-
const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
|
|
449
526
|
const desc = typeof m.description === "string" && m.description !== "" ? m.description : undefined;
|
|
450
|
-
// The level a click would commit: the pinned one on the current row, the
|
|
451
|
-
// provider default on every other row.
|
|
452
|
-
const rowEffort = selected ? pinnedEffort : (m.reasoning ? m.reasoning.defaultEffort : undefined);
|
|
453
527
|
const stop = (ev) => { if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation(); };
|
|
454
528
|
const row = h(
|
|
455
529
|
"div",
|
|
@@ -469,30 +543,6 @@ function ModelSelectLite(props) {
|
|
|
469
543
|
},
|
|
470
544
|
h("span", { className: "mdsl-name" }, m.name),
|
|
471
545
|
showProvider ? h("span", { className: "mdsl-prov" }, g.name) : null,
|
|
472
|
-
hasEfforts
|
|
473
|
-
? h(
|
|
474
|
-
"span",
|
|
475
|
-
{ className: "mdsl-chips", role: "group", "aria-label": "推理等级" },
|
|
476
|
-
m.reasoning.efforts.map((e) => h(
|
|
477
|
-
"button",
|
|
478
|
-
{
|
|
479
|
-
key: e.id,
|
|
480
|
-
type: "button",
|
|
481
|
-
title: e.description || e.name,
|
|
482
|
-
"aria-pressed": rowEffort === e.id,
|
|
483
|
-
className: "mdsl-chip" + (rowEffort === e.id ? (selected ? " mdsl-chip-on" : " mdsl-chip-eff") : ""),
|
|
484
|
-
onClick: (ev) => {
|
|
485
|
-
ev.stopPropagation();
|
|
486
|
-
chooseEffort(g, m, e.id);
|
|
487
|
-
},
|
|
488
|
-
// A real button fires click on Enter/Space; keep the row's own
|
|
489
|
-
// keyboard handler out of the way so the level wins.
|
|
490
|
-
onKeyDown: stop,
|
|
491
|
-
},
|
|
492
|
-
e.name,
|
|
493
|
-
)),
|
|
494
|
-
)
|
|
495
|
-
: null,
|
|
496
546
|
h(
|
|
497
547
|
"button",
|
|
498
548
|
{
|
|
@@ -548,9 +598,21 @@ function ModelSelectLite(props) {
|
|
|
548
598
|
rows[next].focus();
|
|
549
599
|
};
|
|
550
600
|
|
|
601
|
+
const canEffort = !!(current && curModel && curModel.reasoning
|
|
602
|
+
&& curModel.reasoning.efforts && curModel.reasoning.efforts.length);
|
|
551
603
|
const triggerTitle = current
|
|
552
604
|
? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "")
|
|
553
605
|
: "选择模型";
|
|
606
|
+
const closeAll = () => {
|
|
607
|
+
if (open) closeMenu();
|
|
608
|
+
closeEffortMenu();
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
// The composer seat is a containing block for fixed descendants (its CSS sets
|
|
612
|
+
// will-change: transform), so the floating layers paint against the document
|
|
613
|
+
// body instead of the seat — otherwise every coordinate would be measured from
|
|
614
|
+
// the seat's own origin and the cards would drift by the column's left inset.
|
|
615
|
+
const overlayRoot = typeof document === "undefined" ? null : document.body;
|
|
554
616
|
|
|
555
617
|
return h(
|
|
556
618
|
"div",
|
|
@@ -569,11 +631,27 @@ function ModelSelectLite(props) {
|
|
|
569
631
|
},
|
|
570
632
|
current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
|
|
571
633
|
h("span", { className: "mdsl-label" }, current ? modelName : "选择模型"),
|
|
572
|
-
effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
|
|
573
634
|
h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
|
|
574
635
|
),
|
|
575
|
-
|
|
576
|
-
|
|
636
|
+
canEffort ? h(
|
|
637
|
+
"button",
|
|
638
|
+
{
|
|
639
|
+
ref: effortRef,
|
|
640
|
+
type: "button",
|
|
641
|
+
className: "mdsl-effort-btn" + (effortOpen ? " mdsl-effort-btn-open" : ""),
|
|
642
|
+
disabled: locked,
|
|
643
|
+
title: "思考等级",
|
|
644
|
+
"aria-haspopup": "menu",
|
|
645
|
+
"aria-expanded": effortOpen,
|
|
646
|
+
onClick: () => { if (effortOpen) closeEffortMenu(); else openEffortMenu(); },
|
|
647
|
+
},
|
|
648
|
+
h("span", { className: "mdsl-effort-label" }, effortLabel || "默认"),
|
|
649
|
+
h("span", { className: "mdsl-chevron" + (effortOpen ? " mdsl-chevron-open" : "") }, chevronDown()),
|
|
650
|
+
) : null,
|
|
651
|
+
(open || effortOpen) && overlayRoot !== null
|
|
652
|
+
? createPortal(h("div", { className: "mdsl-backdrop", onClick: closeAll }), overlayRoot)
|
|
653
|
+
: null,
|
|
654
|
+
open && placement !== null && overlayRoot !== null ? createPortal(h(
|
|
577
655
|
"div",
|
|
578
656
|
{
|
|
579
657
|
className: "mdsl-menu",
|
|
@@ -642,7 +720,65 @@ function ModelSelectLite(props) {
|
|
|
642
720
|
g.models.map((m) => renderRow(g, m, false)),
|
|
643
721
|
)),
|
|
644
722
|
),
|
|
645
|
-
) : null,
|
|
723
|
+
), overlayRoot) : null,
|
|
724
|
+
effortOpen && effortPlacement !== null && overlayRoot !== null ? createPortal(h(
|
|
725
|
+
"div",
|
|
726
|
+
{
|
|
727
|
+
ref: effortMenuRef,
|
|
728
|
+
className: "mdsl-effort-menu",
|
|
729
|
+
style: {
|
|
730
|
+
left: effortPlacement.left + "px",
|
|
731
|
+
width: effortPlacement.width + "px",
|
|
732
|
+
...(effortPlacement.side === "top"
|
|
733
|
+
? { top: "auto", bottom: effortPlacement.bottom + "px" }
|
|
734
|
+
: { top: effortPlacement.top + "px", bottom: "auto" }),
|
|
735
|
+
},
|
|
736
|
+
role: "menu",
|
|
737
|
+
"aria-label": "思考等级",
|
|
738
|
+
onKeyDown: (ev) => {
|
|
739
|
+
if (ev.key === "Escape") {
|
|
740
|
+
ev.preventDefault();
|
|
741
|
+
ev.stopPropagation();
|
|
742
|
+
closeEffortMenu();
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
if (ev.key !== "ArrowDown" && ev.key !== "ArrowUp") return;
|
|
746
|
+
const items = Array.from(ev.currentTarget.querySelectorAll(".mdsl-effort-item"));
|
|
747
|
+
if (items.length === 0) return;
|
|
748
|
+
ev.preventDefault();
|
|
749
|
+
const at = items.indexOf(document.activeElement);
|
|
750
|
+
const step = ev.key === "ArrowDown" ? 1 : -1;
|
|
751
|
+
const next = at === -1 ? 0 : (at + step + items.length) % items.length;
|
|
752
|
+
items[next].focus();
|
|
753
|
+
},
|
|
754
|
+
},
|
|
755
|
+
h(
|
|
756
|
+
"button",
|
|
757
|
+
{
|
|
758
|
+
type: "button",
|
|
759
|
+
role: "menuitemradio",
|
|
760
|
+
"aria-checked": pinnedEffort === undefined,
|
|
761
|
+
className: "mdsl-effort-item",
|
|
762
|
+
onClick: () => chooseEffort(undefined),
|
|
763
|
+
},
|
|
764
|
+
"默认",
|
|
765
|
+
pinnedEffort === undefined ? h("span", { className: "mdsl-check" }, check()) : null,
|
|
766
|
+
),
|
|
767
|
+
(curModel.reasoning.efforts || []).map((e) => h(
|
|
768
|
+
"button",
|
|
769
|
+
{
|
|
770
|
+
key: e.id,
|
|
771
|
+
type: "button",
|
|
772
|
+
role: "menuitemradio",
|
|
773
|
+
"aria-checked": pinnedEffort === e.id,
|
|
774
|
+
title: e.description || e.name,
|
|
775
|
+
className: "mdsl-effort-item",
|
|
776
|
+
onClick: () => chooseEffort(e.id),
|
|
777
|
+
},
|
|
778
|
+
e.name,
|
|
779
|
+
pinnedEffort === e.id ? h("span", { className: "mdsl-check" }, check()) : null,
|
|
780
|
+
)),
|
|
781
|
+
), overlayRoot) : null,
|
|
646
782
|
);
|
|
647
783
|
}
|
|
648
784
|
|