dsh-model-select-plus 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/lib/client.cjs +205 -59
- package/package.json +2 -2
- package/src/client.js +221 -75
package/README.md
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
|
-
1. **单栏列表**:模型按 provider 分组全部展开,行高 34px(与 DSH 原生菜单一致),卡片
|
|
8
|
-
2.
|
|
9
|
-
3.
|
|
10
|
-
4.
|
|
11
|
-
5.
|
|
12
|
-
6.
|
|
13
|
-
7.
|
|
14
|
-
8.
|
|
7
|
+
1. **单栏列表**:模型按 provider 分组全部展开,行高 34px(与 DSH 原生菜单一致),卡片 360×440;没有折叠、没有 Tag 条、没有底部状态条。
|
|
8
|
+
2. **思考等级外置**:composer 里模型芯片右侧是独立的等级芯片,点开即选,立即生效;切换等级完全不用打开、也不用在列表里找当前模型。没有推理等级的模型不显示这个芯片。
|
|
9
|
+
3. **当前行展开**:只有当前模型向下展开 2 行描述,其余行保持 34px 基线;打开菜单时自动把当前模型滚到列表中间。
|
|
10
|
+
4. **搜索**:34px 单行搜索,按模型名 / 描述 / provider 过滤,带清除按钮;打开即自动聚焦。
|
|
11
|
+
5. **收藏置顶**:行尾星标(悬停出现)收藏,收藏项移动到顶部独立分组,并在行尾标出 provider;取消后回到原分组。收藏存于浏览器内存,刷新即重置。
|
|
12
|
+
6. **分组标题**:11px 吸顶,只在真正吸到顶部时铺底色,静态时是纯文字;不显示数量,也不可折叠。
|
|
13
|
+
7. **选中态**:6% 填充 + 行尾对勾 + 500 字重,不再用 10% 灰块(那读起来像禁用)。
|
|
14
|
+
8. **触发按钮**:模型芯片显示 `供应商/模型`,供应商 11px 次级色,超宽时先省略供应商、保住模型名;等级在旁边的独立芯片里。
|
|
15
|
+
9. **键盘**:模型列表里 `↑` / `↓` 移动、`Enter` 选择、`Esc` 关闭;等级菜单同样支持 `↑` / `↓` 与 `Esc`。
|
|
15
16
|
|
|
16
17
|
打开时按触发按钮在视口内的剩余空间决定向上/向下弹,收敛高度并把左右夹在视口内;浅色与深色都走主题令牌(深色下分段控件的滑块改用 active 填充),所有图标为手绘 SVG,不用文字字符充当图标。
|
|
17
18
|
|
package/lib/client.cjs
CHANGED
|
@@ -49,25 +49,25 @@ var module = { exports: {} };
|
|
|
49
49
|
var h = import_react.default.createElement;
|
|
50
50
|
var CSS = `
|
|
51
51
|
.mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
|
|
52
|
-
.mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
|
|
52
|
+
.mdsl-root { position: relative; display: inline-flex; align-items: center; gap: 2px; min-width: 0; max-width: 100%; }
|
|
53
53
|
.mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
|
|
54
54
|
|
|
55
55
|
/* Trigger: the composer's 28px chip, same as the sibling permission / plan
|
|
56
56
|
controls, so the row does not jump when this plugin replaces the seat. */
|
|
57
|
-
.mdsl-trigger { display: flex; align-items: center; gap: 4px; min-width: 0; max-width:
|
|
57
|
+
.mdsl-trigger { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 260px; max-width: min(260px, 45cqw); height: 28px; padding: 0 4px 0 8px; 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; font-weight: 400; cursor: pointer; outline: none; }
|
|
58
58
|
.mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
59
59
|
.mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
60
60
|
.mdsl-trigger:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
61
|
-
.mdsl-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
62
|
-
/* The
|
|
63
|
-
|
|
64
|
-
.mdsl-
|
|
61
|
+
.mdsl-label { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
62
|
+
/* The provider is context, the model is the subject: on overflow the level
|
|
63
|
+
collapses first, then the provider, and the model name stays whole. */
|
|
64
|
+
.mdsl-trigger-provider { flex-shrink: 100; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-tertiary); }
|
|
65
65
|
.mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
|
|
66
66
|
.mdsl-chevron-open { transform: rotate(180deg); }
|
|
67
67
|
|
|
68
|
-
/* Card: the shipped menu material.
|
|
69
|
-
|
|
70
|
-
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width:
|
|
68
|
+
/* Card: the shipped menu material. 360px keeps names whole now that the
|
|
69
|
+
level chips moved out to the composer. */
|
|
70
|
+
.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; }
|
|
71
71
|
body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
72
72
|
@keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
|
|
73
73
|
@media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
|
|
@@ -115,16 +115,25 @@ var module = { exports: {} };
|
|
|
115
115
|
.mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
116
116
|
.mdsl-star-on { color: var(--dsw-alias-brand-primary); }
|
|
117
117
|
|
|
118
|
-
/*
|
|
119
|
-
|
|
118
|
+
/* The level is its own composer control beside the model chip: switching it
|
|
119
|
+
never opens (or scrolls) the model list. */
|
|
120
|
+
.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; }
|
|
121
|
+
.mdsl-effort-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
122
|
+
.mdsl-effort-btn:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
123
|
+
.mdsl-effort-btn:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
124
|
+
.mdsl-effort-btn-open { background: var(--dsw-alias-interactive-bg-active); }
|
|
125
|
+
.mdsl-effort-label { white-space: nowrap; }
|
|
126
|
+
|
|
127
|
+
.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); }
|
|
128
|
+
body[data-ds-dark-theme] .mdsl-effort-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
129
|
+
.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; }
|
|
130
|
+
.mdsl-effort-item:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
131
|
+
.mdsl-effort-item:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
132
|
+
.mdsl-effort-item[aria-checked="true"] { font-weight: 500; }
|
|
133
|
+
.mdsl-effort-item .mdsl-check { margin-left: auto; }
|
|
134
|
+
|
|
120
135
|
.mdsl-sub { padding: 2px 8px 8px; }
|
|
121
136
|
.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; }
|
|
122
|
-
.mdsl-track { display: flex; align-items: center; gap: 2px; height: 26px; margin-top: 6px; padding: 3px; border-radius: 8px; background: var(--dsw-alias-interactive-bg-hover); }
|
|
123
|
-
.mdsl-seg { flex: 1; height: 20px; padding: 0 4px; border: 0; border-radius: 6px; background: transparent; color: var(--dsw-alias-label-tertiary); font-family: inherit; font-size: 11px; line-height: 20px; text-align: center; cursor: pointer; }
|
|
124
|
-
.mdsl-seg:hover { color: var(--dsw-alias-label-primary); }
|
|
125
|
-
.mdsl-seg:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
126
|
-
.mdsl-seg-on { background: var(--dsw-alias-bg-base, #fff); color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: 0 0 0 0.5px var(--dsw-alias-border-l2), 0 1px 2px rgba(0, 0, 0, .05); }
|
|
127
|
-
body[data-ds-dark-theme] .mdsl-seg-on { background: var(--dsw-alias-interactive-bg-active); }
|
|
128
137
|
|
|
129
138
|
.mdsl-empty { padding: 16px 8px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
130
139
|
.mdsl-error { margin: 4px 2px; padding: 6px 8px; border-radius: 8px; background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dsw-alias-state-error-primary); font-size: 11px; line-height: 16px; }
|
|
@@ -176,10 +185,14 @@ var module = { exports: {} };
|
|
|
176
185
|
const sessionId = props.sessionId;
|
|
177
186
|
const locked = props.locked === true;
|
|
178
187
|
const triggerRef = import_react.default.useRef(null);
|
|
188
|
+
const effortRef = import_react.default.useRef(null);
|
|
189
|
+
const effortMenuRef = import_react.default.useRef(null);
|
|
179
190
|
const bodyRef = import_react.default.useRef(null);
|
|
180
191
|
const searchRef = import_react.default.useRef(null);
|
|
181
192
|
const [placement, setPlacement] = import_react.default.useState(null);
|
|
182
193
|
const [open, setOpen] = import_react.default.useState(false);
|
|
194
|
+
const [effortOpen, setEffortOpen] = import_react.default.useState(false);
|
|
195
|
+
const [effortPlacement, setEffortPlacement] = import_react.default.useState(null);
|
|
183
196
|
const [data, setData] = import_react.default.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
184
197
|
const [query, setQuery] = import_react.default.useState("");
|
|
185
198
|
const [busy, setBusy] = import_react.default.useState(false);
|
|
@@ -217,7 +230,7 @@ var module = { exports: {} };
|
|
|
217
230
|
const rect = trigger.getBoundingClientRect();
|
|
218
231
|
const margin = 12;
|
|
219
232
|
const gap = 6;
|
|
220
|
-
const width = Math.min(
|
|
233
|
+
const width = Math.min(420, window.innerWidth - margin * 2);
|
|
221
234
|
const spaceAbove = rect.top - gap - margin;
|
|
222
235
|
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
223
236
|
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
@@ -236,6 +249,45 @@ var module = { exports: {} };
|
|
|
236
249
|
return next;
|
|
237
250
|
});
|
|
238
251
|
};
|
|
252
|
+
const placeEffort = () => {
|
|
253
|
+
const el = effortRef.current;
|
|
254
|
+
if (!el) return;
|
|
255
|
+
const rect = el.getBoundingClientRect();
|
|
256
|
+
const margin = 12;
|
|
257
|
+
const gap = 6;
|
|
258
|
+
const width = 156;
|
|
259
|
+
const spaceAbove = rect.top - gap - margin;
|
|
260
|
+
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
261
|
+
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
262
|
+
const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
|
|
263
|
+
setEffortPlacement({
|
|
264
|
+
side,
|
|
265
|
+
width,
|
|
266
|
+
left,
|
|
267
|
+
bottom: window.innerHeight - rect.top + gap,
|
|
268
|
+
top: rect.bottom + gap
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
import_react.default.useLayoutEffect(() => {
|
|
272
|
+
if (effortOpen) placeEffort();
|
|
273
|
+
}, [effortOpen]);
|
|
274
|
+
import_react.default.useLayoutEffect(() => {
|
|
275
|
+
if (!effortOpen) return;
|
|
276
|
+
const menu = effortMenuRef.current;
|
|
277
|
+
if (menu === null) return;
|
|
278
|
+
const active = menu.querySelector('[aria-checked="true"]') || menu.querySelector(".mdsl-effort-item");
|
|
279
|
+
if (active !== null) active.focus({ preventScroll: true });
|
|
280
|
+
}, [effortOpen, effortPlacement]);
|
|
281
|
+
import_react.default.useEffect(() => {
|
|
282
|
+
if (!effortOpen) return;
|
|
283
|
+
const reposition = () => placeEffort();
|
|
284
|
+
window.addEventListener("resize", reposition);
|
|
285
|
+
window.addEventListener("scroll", reposition, true);
|
|
286
|
+
return () => {
|
|
287
|
+
window.removeEventListener("resize", reposition);
|
|
288
|
+
window.removeEventListener("scroll", reposition, true);
|
|
289
|
+
};
|
|
290
|
+
}, [effortOpen]);
|
|
239
291
|
import_react.default.useLayoutEffect(() => {
|
|
240
292
|
if (open) placeMenu();
|
|
241
293
|
}, [open]);
|
|
@@ -279,11 +331,34 @@ var module = { exports: {} };
|
|
|
279
331
|
if (raf) cancelAnimationFrame(raf);
|
|
280
332
|
};
|
|
281
333
|
}, [open, placement, data.status, data.current, query]);
|
|
334
|
+
const locatedForOpen = import_react.default.useRef(false);
|
|
335
|
+
import_react.default.useLayoutEffect(() => {
|
|
336
|
+
if (!open) {
|
|
337
|
+
locatedForOpen.current = false;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (locatedForOpen.current || placement === null) return;
|
|
341
|
+
if (data.status !== "ready" || query !== "") return;
|
|
342
|
+
const body = bodyRef.current;
|
|
343
|
+
if (!body) return;
|
|
344
|
+
const item = body.querySelector('[data-current="true"]');
|
|
345
|
+
if (item === null) {
|
|
346
|
+
locatedForOpen.current = true;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const bodyRect = body.getBoundingClientRect();
|
|
350
|
+
const itemRect = item.getBoundingClientRect();
|
|
351
|
+
const delta = itemRect.top - bodyRect.top - (body.clientHeight - itemRect.height) / 2;
|
|
352
|
+
body.scrollTop = Math.max(0, body.scrollTop + delta);
|
|
353
|
+
locatedForOpen.current = true;
|
|
354
|
+
}, [open, placement, data.status, query]);
|
|
282
355
|
const focusTrigger = () => {
|
|
283
356
|
const el = triggerRef.current;
|
|
284
357
|
if (el) el.focus({ preventScroll: true });
|
|
285
358
|
};
|
|
286
359
|
const openMenu = () => {
|
|
360
|
+
setEffortOpen(false);
|
|
361
|
+
setEffortPlacement(null);
|
|
287
362
|
setOpen(true);
|
|
288
363
|
load();
|
|
289
364
|
};
|
|
@@ -293,7 +368,19 @@ var module = { exports: {} };
|
|
|
293
368
|
setPlacement(null);
|
|
294
369
|
focusTrigger();
|
|
295
370
|
};
|
|
296
|
-
const
|
|
371
|
+
const openEffortMenu = () => {
|
|
372
|
+
setOpen(false);
|
|
373
|
+
setQuery("");
|
|
374
|
+
setPlacement(null);
|
|
375
|
+
setEffortOpen(true);
|
|
376
|
+
};
|
|
377
|
+
const closeEffortMenu = () => {
|
|
378
|
+
setEffortOpen(false);
|
|
379
|
+
setEffortPlacement(null);
|
|
380
|
+
const el = effortRef.current;
|
|
381
|
+
if (el !== null) el.focus({ preventScroll: true });
|
|
382
|
+
};
|
|
383
|
+
const submitSelection = (sel, after) => {
|
|
297
384
|
if (busy) return;
|
|
298
385
|
setBusy(true);
|
|
299
386
|
fetch(`${API}/select`, {
|
|
@@ -309,8 +396,7 @@ var module = { exports: {} };
|
|
|
309
396
|
setBusy(false);
|
|
310
397
|
if (res && res.ok === true) {
|
|
311
398
|
setData((d) => ({ ...d, current: res.selected || null, error: null }));
|
|
312
|
-
if (
|
|
313
|
-
closeMenu();
|
|
399
|
+
if (after) after();
|
|
314
400
|
} else {
|
|
315
401
|
setData((d) => ({ ...d, error: res && res.message || "\u9009\u62E9\u5931\u8D25" }));
|
|
316
402
|
}
|
|
@@ -329,10 +415,14 @@ var module = { exports: {} };
|
|
|
329
415
|
};
|
|
330
416
|
const choose = (g, m) => {
|
|
331
417
|
const effort = m.reasoning ? m.reasoning.defaultEffort : void 0;
|
|
332
|
-
|
|
418
|
+
submitSelection({ provider: g.id, model: m.id, ...effort === void 0 ? {} : { reasoningEffort: effort } }, closeMenu);
|
|
333
419
|
};
|
|
334
|
-
const chooseEffort = (
|
|
335
|
-
|
|
420
|
+
const chooseEffort = (effort) => {
|
|
421
|
+
if (current === null || current === void 0) return;
|
|
422
|
+
submitSelection(
|
|
423
|
+
{ provider: current.provider, model: current.model, ...effort === void 0 ? {} : { reasoningEffort: effort } },
|
|
424
|
+
closeEffortMenu
|
|
425
|
+
);
|
|
336
426
|
};
|
|
337
427
|
const current = data.current;
|
|
338
428
|
const curGroup = current ? data.groups.find((g) => g.id === current.provider) : void 0;
|
|
@@ -376,8 +466,10 @@ var module = { exports: {} };
|
|
|
376
466
|
const renderRow = (g, m, showProvider) => {
|
|
377
467
|
const selected = isCurrentModel(g, m);
|
|
378
468
|
const fav = favorites.has(`${g.id}/${m.id}`);
|
|
379
|
-
const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
|
|
380
469
|
const desc = typeof m.description === "string" && m.description !== "" ? m.description : void 0;
|
|
470
|
+
const stop = (ev) => {
|
|
471
|
+
if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation();
|
|
472
|
+
};
|
|
381
473
|
const row = h(
|
|
382
474
|
"div",
|
|
383
475
|
{
|
|
@@ -407,45 +499,20 @@ var module = { exports: {} };
|
|
|
407
499
|
ev.stopPropagation();
|
|
408
500
|
toggleFav(g.id, m.id);
|
|
409
501
|
},
|
|
410
|
-
|
|
411
|
-
// keyboard handler out of the way so toggling does not select.
|
|
412
|
-
onKeyDown: (ev) => {
|
|
413
|
-
if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation();
|
|
414
|
-
}
|
|
502
|
+
onKeyDown: stop
|
|
415
503
|
},
|
|
416
504
|
star(fav)
|
|
417
505
|
),
|
|
418
506
|
selected ? h("span", { className: "mdsl-check" }, check()) : null
|
|
419
507
|
);
|
|
420
|
-
const sub = selected &&
|
|
421
|
-
"div",
|
|
422
|
-
{ className: "mdsl-sub" },
|
|
423
|
-
desc ? h("div", { className: "mdsl-desc" }, desc) : null,
|
|
424
|
-
hasEfforts ? h(
|
|
425
|
-
"div",
|
|
426
|
-
{ className: "mdsl-track", role: "group", "aria-label": "\u63A8\u7406\u7B49\u7EA7" },
|
|
427
|
-
h(
|
|
428
|
-
"button",
|
|
429
|
-
{ type: "button", "aria-pressed": pinnedEffort === void 0, className: "mdsl-seg" + (pinnedEffort === void 0 ? " mdsl-seg-on" : ""), onClick: () => chooseEffort(g, m, void 0) },
|
|
430
|
-
"\u9ED8\u8BA4"
|
|
431
|
-
),
|
|
432
|
-
m.reasoning.efforts.map((e) => h(
|
|
433
|
-
"button",
|
|
434
|
-
{
|
|
435
|
-
key: e.id,
|
|
436
|
-
type: "button",
|
|
437
|
-
title: e.description || e.name,
|
|
438
|
-
"aria-pressed": pinnedEffort === e.id,
|
|
439
|
-
className: "mdsl-seg" + (pinnedEffort === e.id ? " mdsl-seg-on" : ""),
|
|
440
|
-
onClick: () => chooseEffort(g, m, e.id)
|
|
441
|
-
},
|
|
442
|
-
e.name
|
|
443
|
-
))
|
|
444
|
-
) : null
|
|
445
|
-
) : null;
|
|
508
|
+
const sub = selected && desc !== void 0 ? h("div", { className: "mdsl-sub" }, h("div", { className: "mdsl-desc" }, desc)) : null;
|
|
446
509
|
return h(
|
|
447
510
|
"div",
|
|
448
|
-
{
|
|
511
|
+
{
|
|
512
|
+
key: `${g.id}/${m.id}`,
|
|
513
|
+
className: "mdsl-item" + (selected ? " mdsl-item-current" : ""),
|
|
514
|
+
"data-current": selected ? "true" : void 0
|
|
515
|
+
},
|
|
449
516
|
row,
|
|
450
517
|
sub
|
|
451
518
|
);
|
|
@@ -468,7 +535,12 @@ var module = { exports: {} };
|
|
|
468
535
|
const next = at === -1 ? step > 0 ? 0 : rows.length - 1 : (at + step + rows.length) % rows.length;
|
|
469
536
|
rows[next].focus();
|
|
470
537
|
};
|
|
538
|
+
const canEffort = !!(current && curModel && curModel.reasoning && curModel.reasoning.efforts && curModel.reasoning.efforts.length);
|
|
471
539
|
const triggerTitle = current ? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "") : "\u9009\u62E9\u6A21\u578B";
|
|
540
|
+
const closeAll = () => {
|
|
541
|
+
if (open) closeMenu();
|
|
542
|
+
closeEffortMenu();
|
|
543
|
+
};
|
|
472
544
|
return h(
|
|
473
545
|
"div",
|
|
474
546
|
{ className: "mdsl-root" },
|
|
@@ -487,11 +559,29 @@ var module = { exports: {} };
|
|
|
487
559
|
"aria-haspopup": "dialog",
|
|
488
560
|
"aria-expanded": open
|
|
489
561
|
},
|
|
562
|
+
current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
|
|
490
563
|
h("span", { className: "mdsl-label" }, current ? modelName : "\u9009\u62E9\u6A21\u578B"),
|
|
491
|
-
effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
|
|
492
564
|
h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown())
|
|
493
565
|
),
|
|
494
|
-
|
|
566
|
+
canEffort ? h(
|
|
567
|
+
"button",
|
|
568
|
+
{
|
|
569
|
+
ref: effortRef,
|
|
570
|
+
type: "button",
|
|
571
|
+
className: "mdsl-effort-btn" + (effortOpen ? " mdsl-effort-btn-open" : ""),
|
|
572
|
+
disabled: locked,
|
|
573
|
+
title: "\u601D\u8003\u7B49\u7EA7",
|
|
574
|
+
"aria-haspopup": "menu",
|
|
575
|
+
"aria-expanded": effortOpen,
|
|
576
|
+
onClick: () => {
|
|
577
|
+
if (effortOpen) closeEffortMenu();
|
|
578
|
+
else openEffortMenu();
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
h("span", { className: "mdsl-effort-label" }, effortLabel || "\u9ED8\u8BA4"),
|
|
582
|
+
h("span", { className: "mdsl-chevron" + (effortOpen ? " mdsl-chevron-open" : "") }, chevronDown())
|
|
583
|
+
) : null,
|
|
584
|
+
open || effortOpen ? h("div", { className: "mdsl-backdrop", onClick: closeAll }) : null,
|
|
495
585
|
open && placement !== null ? h(
|
|
496
586
|
"div",
|
|
497
587
|
{
|
|
@@ -553,6 +643,62 @@ var module = { exports: {} };
|
|
|
553
643
|
g.models.map((m) => renderRow(g, m, false))
|
|
554
644
|
))
|
|
555
645
|
)
|
|
646
|
+
) : null,
|
|
647
|
+
effortOpen && effortPlacement !== null ? h(
|
|
648
|
+
"div",
|
|
649
|
+
{
|
|
650
|
+
ref: effortMenuRef,
|
|
651
|
+
className: "mdsl-effort-menu",
|
|
652
|
+
style: {
|
|
653
|
+
left: effortPlacement.left + "px",
|
|
654
|
+
width: effortPlacement.width + "px",
|
|
655
|
+
...effortPlacement.side === "top" ? { top: "auto", bottom: effortPlacement.bottom + "px" } : { top: effortPlacement.top + "px", bottom: "auto" }
|
|
656
|
+
},
|
|
657
|
+
role: "menu",
|
|
658
|
+
"aria-label": "\u601D\u8003\u7B49\u7EA7",
|
|
659
|
+
onKeyDown: (ev) => {
|
|
660
|
+
if (ev.key === "Escape") {
|
|
661
|
+
ev.preventDefault();
|
|
662
|
+
ev.stopPropagation();
|
|
663
|
+
closeEffortMenu();
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
if (ev.key !== "ArrowDown" && ev.key !== "ArrowUp") return;
|
|
667
|
+
const items = Array.from(ev.currentTarget.querySelectorAll(".mdsl-effort-item"));
|
|
668
|
+
if (items.length === 0) return;
|
|
669
|
+
ev.preventDefault();
|
|
670
|
+
const at = items.indexOf(document.activeElement);
|
|
671
|
+
const step = ev.key === "ArrowDown" ? 1 : -1;
|
|
672
|
+
const next = at === -1 ? 0 : (at + step + items.length) % items.length;
|
|
673
|
+
items[next].focus();
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
h(
|
|
677
|
+
"button",
|
|
678
|
+
{
|
|
679
|
+
type: "button",
|
|
680
|
+
role: "menuitemradio",
|
|
681
|
+
"aria-checked": pinnedEffort === void 0,
|
|
682
|
+
className: "mdsl-effort-item",
|
|
683
|
+
onClick: () => chooseEffort(void 0)
|
|
684
|
+
},
|
|
685
|
+
"\u9ED8\u8BA4",
|
|
686
|
+
pinnedEffort === void 0 ? h("span", { className: "mdsl-check" }, check()) : null
|
|
687
|
+
),
|
|
688
|
+
(curModel.reasoning.efforts || []).map((e) => h(
|
|
689
|
+
"button",
|
|
690
|
+
{
|
|
691
|
+
key: e.id,
|
|
692
|
+
type: "button",
|
|
693
|
+
role: "menuitemradio",
|
|
694
|
+
"aria-checked": pinnedEffort === e.id,
|
|
695
|
+
title: e.description || e.name,
|
|
696
|
+
className: "mdsl-effort-item",
|
|
697
|
+
onClick: () => chooseEffort(e.id)
|
|
698
|
+
},
|
|
699
|
+
e.name,
|
|
700
|
+
pinnedEffort === e.id ? h("span", { className: "mdsl-check" }, check()) : null
|
|
701
|
+
))
|
|
556
702
|
) : null
|
|
557
703
|
);
|
|
558
704
|
}
|
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.2",
|
|
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",
|
package/src/client.js
CHANGED
|
@@ -10,20 +10,19 @@
|
|
|
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
|
-
* segmented control share one block, so every other row keeps the baseline
|
|
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
|
-
* -
|
|
26
|
-
*
|
|
24
|
+
* - the model chip shows provider/model (the provider ellipsizes first)
|
|
25
|
+
* - re-opening centers the current model instead of resetting to the top
|
|
27
26
|
*
|
|
28
27
|
* Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
|
|
29
28
|
* The seat passes `locked` (owner prop) and we inject `sessionId`.
|
|
@@ -42,25 +41,25 @@ const h = React.createElement;
|
|
|
42
41
|
|
|
43
42
|
const CSS = `
|
|
44
43
|
.mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
|
|
45
|
-
.mdsl-root { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: 100%; }
|
|
44
|
+
.mdsl-root { position: relative; display: inline-flex; align-items: center; gap: 2px; min-width: 0; max-width: 100%; }
|
|
46
45
|
.mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
|
|
47
46
|
|
|
48
47
|
/* Trigger: the composer's 28px chip, same as the sibling permission / plan
|
|
49
48
|
controls, so the row does not jump when this plugin replaces the seat. */
|
|
50
|
-
.mdsl-trigger { display: flex; align-items: center; gap: 4px; min-width: 0; max-width:
|
|
49
|
+
.mdsl-trigger { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 260px; max-width: min(260px, 45cqw); height: 28px; padding: 0 4px 0 8px; 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; font-weight: 400; cursor: pointer; outline: none; }
|
|
51
50
|
.mdsl-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
52
51
|
.mdsl-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
53
52
|
.mdsl-trigger:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
54
|
-
.mdsl-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
55
|
-
/* The
|
|
56
|
-
|
|
57
|
-
.mdsl-
|
|
53
|
+
.mdsl-label { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
54
|
+
/* The provider is context, the model is the subject: on overflow the level
|
|
55
|
+
collapses first, then the provider, and the model name stays whole. */
|
|
56
|
+
.mdsl-trigger-provider { flex-shrink: 100; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-tertiary); }
|
|
58
57
|
.mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
|
|
59
58
|
.mdsl-chevron-open { transform: rotate(180deg); }
|
|
60
59
|
|
|
61
|
-
/* Card: the shipped menu material.
|
|
62
|
-
|
|
63
|
-
.mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width:
|
|
60
|
+
/* Card: the shipped menu material. 360px keeps names whole now that the
|
|
61
|
+
level chips moved out to the composer. */
|
|
62
|
+
.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; }
|
|
64
63
|
body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
65
64
|
@keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
|
|
66
65
|
@media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
|
|
@@ -108,16 +107,25 @@ const CSS = `
|
|
|
108
107
|
.mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
109
108
|
.mdsl-star-on { color: var(--dsw-alias-brand-primary); }
|
|
110
109
|
|
|
111
|
-
/*
|
|
112
|
-
|
|
110
|
+
/* The level is its own composer control beside the model chip: switching it
|
|
111
|
+
never opens (or scrolls) the model list. */
|
|
112
|
+
.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; }
|
|
113
|
+
.mdsl-effort-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
114
|
+
.mdsl-effort-btn:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
|
|
115
|
+
.mdsl-effort-btn:disabled { color: var(--dsw-alias-label-dimmed); cursor: default; }
|
|
116
|
+
.mdsl-effort-btn-open { background: var(--dsw-alias-interactive-bg-active); }
|
|
117
|
+
.mdsl-effort-label { white-space: nowrap; }
|
|
118
|
+
|
|
119
|
+
.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); }
|
|
120
|
+
body[data-ds-dark-theme] .mdsl-effort-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
|
|
121
|
+
.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; }
|
|
122
|
+
.mdsl-effort-item:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
123
|
+
.mdsl-effort-item:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
124
|
+
.mdsl-effort-item[aria-checked="true"] { font-weight: 500; }
|
|
125
|
+
.mdsl-effort-item .mdsl-check { margin-left: auto; }
|
|
126
|
+
|
|
113
127
|
.mdsl-sub { padding: 2px 8px 8px; }
|
|
114
128
|
.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; }
|
|
115
|
-
.mdsl-track { display: flex; align-items: center; gap: 2px; height: 26px; margin-top: 6px; padding: 3px; border-radius: 8px; background: var(--dsw-alias-interactive-bg-hover); }
|
|
116
|
-
.mdsl-seg { flex: 1; height: 20px; padding: 0 4px; border: 0; border-radius: 6px; background: transparent; color: var(--dsw-alias-label-tertiary); font-family: inherit; font-size: 11px; line-height: 20px; text-align: center; cursor: pointer; }
|
|
117
|
-
.mdsl-seg:hover { color: var(--dsw-alias-label-primary); }
|
|
118
|
-
.mdsl-seg:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
|
|
119
|
-
.mdsl-seg-on { background: var(--dsw-alias-bg-base, #fff); color: var(--dsw-alias-label-primary); font-weight: 500; box-shadow: 0 0 0 0.5px var(--dsw-alias-border-l2), 0 1px 2px rgba(0, 0, 0, .05); }
|
|
120
|
-
body[data-ds-dark-theme] .mdsl-seg-on { background: var(--dsw-alias-interactive-bg-active); }
|
|
121
129
|
|
|
122
130
|
.mdsl-empty { padding: 16px 8px; text-align: center; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
123
131
|
.mdsl-error { margin: 4px 2px; padding: 6px 8px; border-radius: 8px; background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dsw-alias-state-error-primary); font-size: 11px; line-height: 16px; }
|
|
@@ -172,10 +180,14 @@ function ModelSelectLite(props) {
|
|
|
172
180
|
const sessionId = props.sessionId;
|
|
173
181
|
const locked = props.locked === true;
|
|
174
182
|
const triggerRef = React.useRef(null);
|
|
183
|
+
const effortRef = React.useRef(null);
|
|
184
|
+
const effortMenuRef = React.useRef(null);
|
|
175
185
|
const bodyRef = React.useRef(null);
|
|
176
186
|
const searchRef = React.useRef(null);
|
|
177
187
|
const [placement, setPlacement] = React.useState(null);
|
|
178
188
|
const [open, setOpen] = React.useState(false);
|
|
189
|
+
const [effortOpen, setEffortOpen] = React.useState(false);
|
|
190
|
+
const [effortPlacement, setEffortPlacement] = React.useState(null);
|
|
179
191
|
const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
180
192
|
const [query, setQuery] = React.useState("");
|
|
181
193
|
const [busy, setBusy] = React.useState(false);
|
|
@@ -231,7 +243,7 @@ function ModelSelectLite(props) {
|
|
|
231
243
|
const rect = trigger.getBoundingClientRect();
|
|
232
244
|
const margin = 12;
|
|
233
245
|
const gap = 6;
|
|
234
|
-
const width = Math.min(
|
|
246
|
+
const width = Math.min(420, window.innerWidth - margin * 2);
|
|
235
247
|
const spaceAbove = rect.top - gap - margin;
|
|
236
248
|
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
237
249
|
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
@@ -261,6 +273,51 @@ function ModelSelectLite(props) {
|
|
|
261
273
|
});
|
|
262
274
|
};
|
|
263
275
|
|
|
276
|
+
// The level menu is a small fixed card anchored to its chip, opening upward
|
|
277
|
+
// unless the chip sits near the top of the window.
|
|
278
|
+
const placeEffort = () => {
|
|
279
|
+
const el = effortRef.current;
|
|
280
|
+
if (!el) return;
|
|
281
|
+
const rect = el.getBoundingClientRect();
|
|
282
|
+
const margin = 12;
|
|
283
|
+
const gap = 6;
|
|
284
|
+
const width = 156;
|
|
285
|
+
const spaceAbove = rect.top - gap - margin;
|
|
286
|
+
const spaceBelow = window.innerHeight - rect.bottom - gap - margin;
|
|
287
|
+
const side = spaceAbove >= spaceBelow ? "top" : "bottom";
|
|
288
|
+
const left = Math.min(Math.max(margin, rect.right - width), window.innerWidth - width - margin);
|
|
289
|
+
setEffortPlacement({
|
|
290
|
+
side,
|
|
291
|
+
width,
|
|
292
|
+
left,
|
|
293
|
+
bottom: window.innerHeight - rect.top + gap,
|
|
294
|
+
top: rect.bottom + gap,
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
React.useLayoutEffect(() => {
|
|
299
|
+
if (effortOpen) placeEffort();
|
|
300
|
+
}, [effortOpen]);
|
|
301
|
+
|
|
302
|
+
React.useLayoutEffect(() => {
|
|
303
|
+
if (!effortOpen) return;
|
|
304
|
+
const menu = effortMenuRef.current;
|
|
305
|
+
if (menu === null) return;
|
|
306
|
+
const active = menu.querySelector('[aria-checked="true"]') || menu.querySelector(".mdsl-effort-item");
|
|
307
|
+
if (active !== null) active.focus({ preventScroll: true });
|
|
308
|
+
}, [effortOpen, effortPlacement]);
|
|
309
|
+
|
|
310
|
+
React.useEffect(() => {
|
|
311
|
+
if (!effortOpen) return;
|
|
312
|
+
const reposition = () => placeEffort();
|
|
313
|
+
window.addEventListener("resize", reposition);
|
|
314
|
+
window.addEventListener("scroll", reposition, true);
|
|
315
|
+
return () => {
|
|
316
|
+
window.removeEventListener("resize", reposition);
|
|
317
|
+
window.removeEventListener("scroll", reposition, true);
|
|
318
|
+
};
|
|
319
|
+
}, [effortOpen]);
|
|
320
|
+
|
|
264
321
|
React.useLayoutEffect(() => {
|
|
265
322
|
if (open) placeMenu();
|
|
266
323
|
}, [open]);
|
|
@@ -309,19 +366,55 @@ function ModelSelectLite(props) {
|
|
|
309
366
|
};
|
|
310
367
|
}, [open, placement, data.status, data.current, query]);
|
|
311
368
|
|
|
369
|
+
// Re-opening lands on the current model instead of the top of the list.
|
|
370
|
+
// useLayoutEffect so the jump happens before the card is painted.
|
|
371
|
+
const locatedForOpen = React.useRef(false);
|
|
372
|
+
React.useLayoutEffect(() => {
|
|
373
|
+
if (!open) { locatedForOpen.current = false; return; }
|
|
374
|
+
if (locatedForOpen.current || placement === null) return;
|
|
375
|
+
if (data.status !== "ready" || query !== "") return;
|
|
376
|
+
const body = bodyRef.current;
|
|
377
|
+
if (!body) return;
|
|
378
|
+
const item = body.querySelector('[data-current="true"]');
|
|
379
|
+
if (item === null) { locatedForOpen.current = true; return; }
|
|
380
|
+
const bodyRect = body.getBoundingClientRect();
|
|
381
|
+
const itemRect = item.getBoundingClientRect();
|
|
382
|
+
const delta = itemRect.top - bodyRect.top - (body.clientHeight - itemRect.height) / 2;
|
|
383
|
+
body.scrollTop = Math.max(0, body.scrollTop + delta);
|
|
384
|
+
locatedForOpen.current = true;
|
|
385
|
+
}, [open, placement, data.status, query]);
|
|
386
|
+
|
|
312
387
|
const focusTrigger = () => {
|
|
313
388
|
const el = triggerRef.current;
|
|
314
389
|
if (el) el.focus({ preventScroll: true });
|
|
315
390
|
};
|
|
316
|
-
const openMenu = () => {
|
|
391
|
+
const openMenu = () => {
|
|
392
|
+
setEffortOpen(false);
|
|
393
|
+
setEffortPlacement(null);
|
|
394
|
+
setOpen(true);
|
|
395
|
+
load();
|
|
396
|
+
};
|
|
317
397
|
const closeMenu = () => {
|
|
318
398
|
setOpen(false);
|
|
319
399
|
setQuery("");
|
|
320
400
|
setPlacement(null);
|
|
321
401
|
focusTrigger();
|
|
322
402
|
};
|
|
403
|
+
const openEffortMenu = () => {
|
|
404
|
+
// One popup at a time; closing the model card here must not steal focus.
|
|
405
|
+
setOpen(false);
|
|
406
|
+
setQuery("");
|
|
407
|
+
setPlacement(null);
|
|
408
|
+
setEffortOpen(true);
|
|
409
|
+
};
|
|
410
|
+
const closeEffortMenu = () => {
|
|
411
|
+
setEffortOpen(false);
|
|
412
|
+
setEffortPlacement(null);
|
|
413
|
+
const el = effortRef.current;
|
|
414
|
+
if (el !== null) el.focus({ preventScroll: true });
|
|
415
|
+
};
|
|
323
416
|
|
|
324
|
-
const
|
|
417
|
+
const submitSelection = (sel, after) => {
|
|
325
418
|
if (busy) return;
|
|
326
419
|
setBusy(true);
|
|
327
420
|
fetch(`${API}/select`, {
|
|
@@ -339,8 +432,7 @@ function ModelSelectLite(props) {
|
|
|
339
432
|
setBusy(false);
|
|
340
433
|
if (res && res.ok === true) {
|
|
341
434
|
setData((d) => ({ ...d, current: res.selected || null, error: null }));
|
|
342
|
-
if (
|
|
343
|
-
closeMenu();
|
|
435
|
+
if (after) after();
|
|
344
436
|
} else {
|
|
345
437
|
setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
|
|
346
438
|
}
|
|
@@ -361,13 +453,15 @@ function ModelSelectLite(props) {
|
|
|
361
453
|
|
|
362
454
|
const choose = (g, m) => {
|
|
363
455
|
const effort = m.reasoning ? m.reasoning.defaultEffort : undefined;
|
|
364
|
-
|
|
456
|
+
submitSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, closeMenu);
|
|
365
457
|
};
|
|
366
458
|
|
|
367
|
-
const chooseEffort = (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
459
|
+
const chooseEffort = (effort) => {
|
|
460
|
+
if (current === null || current === undefined) return;
|
|
461
|
+
submitSelection(
|
|
462
|
+
{ provider: current.provider, model: current.model, ...(effort === undefined ? {} : { reasoningEffort: effort }) },
|
|
463
|
+
closeEffortMenu,
|
|
464
|
+
);
|
|
371
465
|
};
|
|
372
466
|
|
|
373
467
|
const current = data.current;
|
|
@@ -420,8 +514,8 @@ function ModelSelectLite(props) {
|
|
|
420
514
|
const renderRow = (g, m, showProvider) => {
|
|
421
515
|
const selected = isCurrentModel(g, m);
|
|
422
516
|
const fav = favorites.has(`${g.id}/${m.id}`);
|
|
423
|
-
const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
|
|
424
517
|
const desc = typeof m.description === "string" && m.description !== "" ? m.description : undefined;
|
|
518
|
+
const stop = (ev) => { if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation(); };
|
|
425
519
|
const row = h(
|
|
426
520
|
"div",
|
|
427
521
|
{
|
|
@@ -451,51 +545,24 @@ function ModelSelectLite(props) {
|
|
|
451
545
|
ev.stopPropagation();
|
|
452
546
|
toggleFav(g.id, m.id);
|
|
453
547
|
},
|
|
454
|
-
|
|
455
|
-
// keyboard handler out of the way so toggling does not select.
|
|
456
|
-
onKeyDown: (ev) => {
|
|
457
|
-
if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation();
|
|
458
|
-
},
|
|
548
|
+
onKeyDown: stop,
|
|
459
549
|
},
|
|
460
550
|
star(fav),
|
|
461
551
|
),
|
|
462
552
|
selected ? h("span", { className: "mdsl-check" }, check()) : null,
|
|
463
553
|
);
|
|
464
554
|
|
|
465
|
-
const sub = selected &&
|
|
466
|
-
? h(
|
|
467
|
-
"div",
|
|
468
|
-
{ className: "mdsl-sub" },
|
|
469
|
-
desc ? h("div", { className: "mdsl-desc" }, desc) : null,
|
|
470
|
-
hasEfforts
|
|
471
|
-
? h(
|
|
472
|
-
"div",
|
|
473
|
-
{ className: "mdsl-track", role: "group", "aria-label": "推理等级" },
|
|
474
|
-
h(
|
|
475
|
-
"button",
|
|
476
|
-
{ type: "button", "aria-pressed": pinnedEffort === undefined, className: "mdsl-seg" + (pinnedEffort === undefined ? " mdsl-seg-on" : ""), onClick: () => chooseEffort(g, m, undefined) },
|
|
477
|
-
"默认",
|
|
478
|
-
),
|
|
479
|
-
m.reasoning.efforts.map((e) => h(
|
|
480
|
-
"button",
|
|
481
|
-
{
|
|
482
|
-
key: e.id,
|
|
483
|
-
type: "button",
|
|
484
|
-
title: e.description || e.name,
|
|
485
|
-
"aria-pressed": pinnedEffort === e.id,
|
|
486
|
-
className: "mdsl-seg" + (pinnedEffort === e.id ? " mdsl-seg-on" : ""),
|
|
487
|
-
onClick: () => chooseEffort(g, m, e.id),
|
|
488
|
-
},
|
|
489
|
-
e.name,
|
|
490
|
-
)),
|
|
491
|
-
)
|
|
492
|
-
: null,
|
|
493
|
-
)
|
|
555
|
+
const sub = selected && desc !== undefined
|
|
556
|
+
? h("div", { className: "mdsl-sub" }, h("div", { className: "mdsl-desc" }, desc))
|
|
494
557
|
: null;
|
|
495
558
|
|
|
496
559
|
return h(
|
|
497
560
|
"div",
|
|
498
|
-
{
|
|
561
|
+
{
|
|
562
|
+
key: `${g.id}/${m.id}`,
|
|
563
|
+
className: "mdsl-item" + (selected ? " mdsl-item-current" : ""),
|
|
564
|
+
"data-current": selected ? "true" : undefined,
|
|
565
|
+
},
|
|
499
566
|
row,
|
|
500
567
|
sub,
|
|
501
568
|
);
|
|
@@ -522,9 +589,15 @@ function ModelSelectLite(props) {
|
|
|
522
589
|
rows[next].focus();
|
|
523
590
|
};
|
|
524
591
|
|
|
592
|
+
const canEffort = !!(current && curModel && curModel.reasoning
|
|
593
|
+
&& curModel.reasoning.efforts && curModel.reasoning.efforts.length);
|
|
525
594
|
const triggerTitle = current
|
|
526
595
|
? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "")
|
|
527
596
|
: "选择模型";
|
|
597
|
+
const closeAll = () => {
|
|
598
|
+
if (open) closeMenu();
|
|
599
|
+
closeEffortMenu();
|
|
600
|
+
};
|
|
528
601
|
|
|
529
602
|
return h(
|
|
530
603
|
"div",
|
|
@@ -541,11 +614,26 @@ function ModelSelectLite(props) {
|
|
|
541
614
|
"aria-haspopup": "dialog",
|
|
542
615
|
"aria-expanded": open,
|
|
543
616
|
},
|
|
617
|
+
current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
|
|
544
618
|
h("span", { className: "mdsl-label" }, current ? modelName : "选择模型"),
|
|
545
|
-
effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
|
|
546
619
|
h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
|
|
547
620
|
),
|
|
548
|
-
|
|
621
|
+
canEffort ? h(
|
|
622
|
+
"button",
|
|
623
|
+
{
|
|
624
|
+
ref: effortRef,
|
|
625
|
+
type: "button",
|
|
626
|
+
className: "mdsl-effort-btn" + (effortOpen ? " mdsl-effort-btn-open" : ""),
|
|
627
|
+
disabled: locked,
|
|
628
|
+
title: "思考等级",
|
|
629
|
+
"aria-haspopup": "menu",
|
|
630
|
+
"aria-expanded": effortOpen,
|
|
631
|
+
onClick: () => { if (effortOpen) closeEffortMenu(); else openEffortMenu(); },
|
|
632
|
+
},
|
|
633
|
+
h("span", { className: "mdsl-effort-label" }, effortLabel || "默认"),
|
|
634
|
+
h("span", { className: "mdsl-chevron" + (effortOpen ? " mdsl-chevron-open" : "") }, chevronDown()),
|
|
635
|
+
) : null,
|
|
636
|
+
open || effortOpen ? h("div", { className: "mdsl-backdrop", onClick: closeAll }) : null,
|
|
549
637
|
open && placement !== null ? h(
|
|
550
638
|
"div",
|
|
551
639
|
{
|
|
@@ -616,6 +704,64 @@ function ModelSelectLite(props) {
|
|
|
616
704
|
)),
|
|
617
705
|
),
|
|
618
706
|
) : null,
|
|
707
|
+
effortOpen && effortPlacement !== null ? h(
|
|
708
|
+
"div",
|
|
709
|
+
{
|
|
710
|
+
ref: effortMenuRef,
|
|
711
|
+
className: "mdsl-effort-menu",
|
|
712
|
+
style: {
|
|
713
|
+
left: effortPlacement.left + "px",
|
|
714
|
+
width: effortPlacement.width + "px",
|
|
715
|
+
...(effortPlacement.side === "top"
|
|
716
|
+
? { top: "auto", bottom: effortPlacement.bottom + "px" }
|
|
717
|
+
: { top: effortPlacement.top + "px", bottom: "auto" }),
|
|
718
|
+
},
|
|
719
|
+
role: "menu",
|
|
720
|
+
"aria-label": "思考等级",
|
|
721
|
+
onKeyDown: (ev) => {
|
|
722
|
+
if (ev.key === "Escape") {
|
|
723
|
+
ev.preventDefault();
|
|
724
|
+
ev.stopPropagation();
|
|
725
|
+
closeEffortMenu();
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (ev.key !== "ArrowDown" && ev.key !== "ArrowUp") return;
|
|
729
|
+
const items = Array.from(ev.currentTarget.querySelectorAll(".mdsl-effort-item"));
|
|
730
|
+
if (items.length === 0) return;
|
|
731
|
+
ev.preventDefault();
|
|
732
|
+
const at = items.indexOf(document.activeElement);
|
|
733
|
+
const step = ev.key === "ArrowDown" ? 1 : -1;
|
|
734
|
+
const next = at === -1 ? 0 : (at + step + items.length) % items.length;
|
|
735
|
+
items[next].focus();
|
|
736
|
+
},
|
|
737
|
+
},
|
|
738
|
+
h(
|
|
739
|
+
"button",
|
|
740
|
+
{
|
|
741
|
+
type: "button",
|
|
742
|
+
role: "menuitemradio",
|
|
743
|
+
"aria-checked": pinnedEffort === undefined,
|
|
744
|
+
className: "mdsl-effort-item",
|
|
745
|
+
onClick: () => chooseEffort(undefined),
|
|
746
|
+
},
|
|
747
|
+
"默认",
|
|
748
|
+
pinnedEffort === undefined ? h("span", { className: "mdsl-check" }, check()) : null,
|
|
749
|
+
),
|
|
750
|
+
(curModel.reasoning.efforts || []).map((e) => h(
|
|
751
|
+
"button",
|
|
752
|
+
{
|
|
753
|
+
key: e.id,
|
|
754
|
+
type: "button",
|
|
755
|
+
role: "menuitemradio",
|
|
756
|
+
"aria-checked": pinnedEffort === e.id,
|
|
757
|
+
title: e.description || e.name,
|
|
758
|
+
className: "mdsl-effort-item",
|
|
759
|
+
onClick: () => chooseEffort(e.id),
|
|
760
|
+
},
|
|
761
|
+
e.name,
|
|
762
|
+
pinnedEffort === e.id ? h("span", { className: "mdsl-check" }, check()) : null,
|
|
763
|
+
)),
|
|
764
|
+
) : null,
|
|
619
765
|
);
|
|
620
766
|
}
|
|
621
767
|
|