dsh-model-select-plus 0.2.1 → 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 CHANGED
@@ -4,15 +4,15 @@
4
4
 
5
5
  ## 特性
6
6
 
7
- 1. **单栏列表**:模型按 provider 分组全部展开,行高 34px(与 DSH 原生菜单一致),卡片 420×440(原生菜单上限,一行放得下名字和等级);没有折叠、没有 Tag 条、没有底部状态条。
8
- 2. **行内等级,一次点完**:每行右侧直接给出该模型的推理等级,点等级即同时提交模型和等级;点模型名则按供应商默认等级选择。当前行的等级用 6% 填充标出,其它行用字重标出默认等级。
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. **触发按钮**:显示 `供应商/模型`;供应商 11px 次级色,超宽时先省略供应商、保住模型名。推理等级放在 tooltip 里。
15
- 9. **键盘**:`↑` / `↓` 在行间移动,`Enter` 选择,`Esc` 关闭并把焦点还给触发按钮。
14
+ 8. **触发按钮**:模型芯片显示 `供应商/模型`,供应商 11px 次级色,超宽时先省略供应商、保住模型名;等级在旁边的独立芯片里。
15
+ 9. **键盘**:模型列表里 `↑` / `↓` 移动、`Enter` 选择、`Esc` 关闭;等级菜单同样支持 `↑` / `↓` 与 `Esc`。
16
16
 
17
17
  打开时按触发按钮在视口内的剩余空间决定向上/向下弹,收敛高度并把左右夹在视口内;浅色与深色都走主题令牌(深色下分段控件的滑块改用 active 填充),所有图标为手绘 SVG,不用文字字符充当图标。
18
18
 
package/lib/client.cjs CHANGED
@@ -49,7 +49,7 @@ 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
@@ -62,13 +62,12 @@ var module = { exports: {} };
62
62
  /* The provider is context, the model is the subject: on overflow the level
63
63
  collapses first, then the provider, and the model name stays whole. */
64
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
- .mdsl-effort { flex-shrink: 1000; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-caption); }
66
65
  .mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
67
66
  .mdsl-chevron-open { transform: rotate(180deg); }
68
67
 
69
- /* Card: the shipped menu material. 420px is the native menu ceiling; the
70
- extra width is what keeps names whole once every row carries its levels. */
71
- .mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 420px; 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; }
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; }
72
71
  body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
73
72
  @keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
74
73
  @media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
@@ -116,15 +115,22 @@ var module = { exports: {} };
116
115
  .mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
117
116
  .mdsl-star-on { color: var(--dsw-alias-brand-primary); }
118
117
 
119
- /* Effort lives on the row: one click commits model + level. The provider
120
- default is the weight-only chip; the current row's pinned level gets a
121
- fill as well. Only the description still expands under the current row. */
122
- .mdsl-chips { display: flex; align-items: center; gap: 2px; flex: none; }
123
- .mdsl-chip { height: 20px; padding: 0 5px; border: 0; border-radius: 4px; background: transparent; color: var(--dsw-alias-label-tertiary); font-family: inherit; font-size: 11px; line-height: 20px; cursor: pointer; }
124
- .mdsl-chip:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
125
- .mdsl-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
126
- .mdsl-chip-eff { color: var(--dsw-alias-label-secondary); font-weight: 500; }
127
- .mdsl-chip-on { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); font-weight: 500; }
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; }
128
134
 
129
135
  .mdsl-sub { padding: 2px 8px 8px; }
130
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; }
@@ -179,10 +185,14 @@ var module = { exports: {} };
179
185
  const sessionId = props.sessionId;
180
186
  const locked = props.locked === true;
181
187
  const triggerRef = import_react.default.useRef(null);
188
+ const effortRef = import_react.default.useRef(null);
189
+ const effortMenuRef = import_react.default.useRef(null);
182
190
  const bodyRef = import_react.default.useRef(null);
183
191
  const searchRef = import_react.default.useRef(null);
184
192
  const [placement, setPlacement] = import_react.default.useState(null);
185
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);
186
196
  const [data, setData] = import_react.default.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
187
197
  const [query, setQuery] = import_react.default.useState("");
188
198
  const [busy, setBusy] = import_react.default.useState(false);
@@ -239,6 +249,45 @@ var module = { exports: {} };
239
249
  return next;
240
250
  });
241
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]);
242
291
  import_react.default.useLayoutEffect(() => {
243
292
  if (open) placeMenu();
244
293
  }, [open]);
@@ -308,6 +357,8 @@ var module = { exports: {} };
308
357
  if (el) el.focus({ preventScroll: true });
309
358
  };
310
359
  const openMenu = () => {
360
+ setEffortOpen(false);
361
+ setEffortPlacement(null);
311
362
  setOpen(true);
312
363
  load();
313
364
  };
@@ -317,7 +368,19 @@ var module = { exports: {} };
317
368
  setPlacement(null);
318
369
  focusTrigger();
319
370
  };
320
- const selectSelection = (sel, keepOpen) => {
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) => {
321
384
  if (busy) return;
322
385
  setBusy(true);
323
386
  fetch(`${API}/select`, {
@@ -333,8 +396,7 @@ var module = { exports: {} };
333
396
  setBusy(false);
334
397
  if (res && res.ok === true) {
335
398
  setData((d) => ({ ...d, current: res.selected || null, error: null }));
336
- if (keepOpen) return;
337
- closeMenu();
399
+ if (after) after();
338
400
  } else {
339
401
  setData((d) => ({ ...d, error: res && res.message || "\u9009\u62E9\u5931\u8D25" }));
340
402
  }
@@ -353,11 +415,14 @@ var module = { exports: {} };
353
415
  };
354
416
  const choose = (g, m) => {
355
417
  const effort = m.reasoning ? m.reasoning.defaultEffort : void 0;
356
- selectSelection({ provider: g.id, model: m.id, ...effort === void 0 ? {} : { reasoningEffort: effort } }, false);
418
+ submitSelection({ provider: g.id, model: m.id, ...effort === void 0 ? {} : { reasoningEffort: effort } }, closeMenu);
357
419
  };
358
- const chooseEffort = (g, m, effort) => {
359
- const sameModel = current !== null && current !== void 0 && current.provider === g.id && current.model === m.id;
360
- selectSelection({ provider: g.id, model: m.id, ...effort === void 0 ? {} : { reasoningEffort: effort } }, sameModel);
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
+ );
361
426
  };
362
427
  const current = data.current;
363
428
  const curGroup = current ? data.groups.find((g) => g.id === current.provider) : void 0;
@@ -401,9 +466,7 @@ var module = { exports: {} };
401
466
  const renderRow = (g, m, showProvider) => {
402
467
  const selected = isCurrentModel(g, m);
403
468
  const fav = favorites.has(`${g.id}/${m.id}`);
404
- const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
405
469
  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
470
  const stop = (ev) => {
408
471
  if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation();
409
472
  };
@@ -425,28 +488,6 @@ var module = { exports: {} };
425
488
  },
426
489
  h("span", { className: "mdsl-name" }, m.name),
427
490
  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
491
  h(
451
492
  "button",
452
493
  {
@@ -494,7 +535,12 @@ var module = { exports: {} };
494
535
  const next = at === -1 ? step > 0 ? 0 : rows.length - 1 : (at + step + rows.length) % rows.length;
495
536
  rows[next].focus();
496
537
  };
538
+ const canEffort = !!(current && curModel && curModel.reasoning && curModel.reasoning.efforts && curModel.reasoning.efforts.length);
497
539
  const triggerTitle = current ? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "") : "\u9009\u62E9\u6A21\u578B";
540
+ const closeAll = () => {
541
+ if (open) closeMenu();
542
+ closeEffortMenu();
543
+ };
498
544
  return h(
499
545
  "div",
500
546
  { className: "mdsl-root" },
@@ -515,10 +561,27 @@ var module = { exports: {} };
515
561
  },
516
562
  current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
517
563
  h("span", { className: "mdsl-label" }, current ? modelName : "\u9009\u62E9\u6A21\u578B"),
518
- effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
519
564
  h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown())
520
565
  ),
521
- open ? h("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
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,
522
585
  open && placement !== null ? h(
523
586
  "div",
524
587
  {
@@ -580,6 +643,62 @@ var module = { exports: {} };
580
643
  g.models.map((m) => renderRow(g, m, false))
581
644
  ))
582
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
+ ))
583
702
  ) : null
584
703
  );
585
704
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-model-select-plus",
3
- "version": "0.2.1",
4
- "description": "A calmer model-selection popup for DeepSeek Harness: provider-grouped rows at the native 34px rhythm, an inline description and reasoning-effort control on the current model, search and pinned favorites, replacing the composer's default ModelSelect.",
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,18 @@
10
10
  * through `document` (the `plugin-dashboard` / `skin-material-you` pattern).
11
11
  *
12
12
  * Layout (one column, native menu measures):
13
- * - card 420 x 440: the native menu ceiling, and the width a name plus its
14
- * levels need on one line; shipped menu material, 16px radius
15
- * - one 34px search line with a 0.5px rule; no jump rail, no chips
16
- * - rows at the native 34px height: name, inline effort chips, star, check.
17
- * A level chip commits model + level in one click; the name commits the
18
- * provider default, which is the chip drawn in the weight-only state
19
- * - selection is a 6% fill plus the trailing check; only the current row
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 trigger shows provider/model (the provider ellipsizes first); 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
28
26
  *
29
27
  * Data comes from the Host half at `/plugins/dsh-model-select-plus/api`.
@@ -43,7 +41,7 @@ const h = React.createElement;
43
41
 
44
42
  const CSS = `
45
43
  .mdsl-root, .mdsl-root *, .mdsl-root *::before, .mdsl-root *::after { box-sizing: border-box; }
46
- .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%; }
47
45
  .mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
48
46
 
49
47
  /* Trigger: the composer's 28px chip, same as the sibling permission / plan
@@ -56,13 +54,12 @@ const CSS = `
56
54
  /* The provider is context, the model is the subject: on overflow the level
57
55
  collapses first, then the provider, and the model name stays whole. */
58
56
  .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
57
  .mdsl-chevron { flex: none; display: inline-flex; color: var(--dsw-alias-label-caption); }
61
58
  .mdsl-chevron-open { transform: rotate(180deg); }
62
59
 
63
- /* Card: the shipped menu material. 420px is the native menu ceiling; the
64
- extra width is what keeps names whole once every row carries its levels. */
65
- .mdsl-menu { position: fixed; z-index: 40; display: flex; flex-direction: column; width: 420px; 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; }
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; }
66
63
  body[data-ds-dark-theme] .mdsl-menu { --dsw-elevation-stroke-color: var(--dsw-alias-border-l3); }
67
64
  @keyframes mdsl-in { from { opacity: 0; transform: translateY(4px) scale(.99); } to { opacity: 1; transform: none; } }
68
65
  @media (prefers-reduced-motion: reduce) { .mdsl-menu { animation: none; } }
@@ -110,15 +107,22 @@ const CSS = `
110
107
  .mdsl-star:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
111
108
  .mdsl-star-on { color: var(--dsw-alias-brand-primary); }
112
109
 
113
- /* Effort lives on the row: one click commits model + level. The provider
114
- default is the weight-only chip; the current row's pinned level gets a
115
- fill as well. Only the description still expands under the current row. */
116
- .mdsl-chips { display: flex; align-items: center; gap: 2px; flex: none; }
117
- .mdsl-chip { height: 20px; padding: 0 5px; border: 0; border-radius: 4px; background: transparent; color: var(--dsw-alias-label-tertiary); font-family: inherit; font-size: 11px; line-height: 20px; cursor: pointer; }
118
- .mdsl-chip:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
119
- .mdsl-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
120
- .mdsl-chip-eff { color: var(--dsw-alias-label-secondary); font-weight: 500; }
121
- .mdsl-chip-on { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); font-weight: 500; }
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; }
122
126
 
123
127
  .mdsl-sub { padding: 2px 8px 8px; }
124
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; }
@@ -176,10 +180,14 @@ function ModelSelectLite(props) {
176
180
  const sessionId = props.sessionId;
177
181
  const locked = props.locked === true;
178
182
  const triggerRef = React.useRef(null);
183
+ const effortRef = React.useRef(null);
184
+ const effortMenuRef = React.useRef(null);
179
185
  const bodyRef = React.useRef(null);
180
186
  const searchRef = React.useRef(null);
181
187
  const [placement, setPlacement] = React.useState(null);
182
188
  const [open, setOpen] = React.useState(false);
189
+ const [effortOpen, setEffortOpen] = React.useState(false);
190
+ const [effortPlacement, setEffortPlacement] = React.useState(null);
183
191
  const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
184
192
  const [query, setQuery] = React.useState("");
185
193
  const [busy, setBusy] = React.useState(false);
@@ -265,6 +273,51 @@ function ModelSelectLite(props) {
265
273
  });
266
274
  };
267
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
+
268
321
  React.useLayoutEffect(() => {
269
322
  if (open) placeMenu();
270
323
  }, [open]);
@@ -335,15 +388,33 @@ function ModelSelectLite(props) {
335
388
  const el = triggerRef.current;
336
389
  if (el) el.focus({ preventScroll: true });
337
390
  };
338
- const openMenu = () => { setOpen(true); load(); };
391
+ const openMenu = () => {
392
+ setEffortOpen(false);
393
+ setEffortPlacement(null);
394
+ setOpen(true);
395
+ load();
396
+ };
339
397
  const closeMenu = () => {
340
398
  setOpen(false);
341
399
  setQuery("");
342
400
  setPlacement(null);
343
401
  focusTrigger();
344
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
+ };
345
416
 
346
- const selectSelection = (sel, keepOpen) => {
417
+ const submitSelection = (sel, after) => {
347
418
  if (busy) return;
348
419
  setBusy(true);
349
420
  fetch(`${API}/select`, {
@@ -361,8 +432,7 @@ function ModelSelectLite(props) {
361
432
  setBusy(false);
362
433
  if (res && res.ok === true) {
363
434
  setData((d) => ({ ...d, current: res.selected || null, error: null }));
364
- if (keepOpen) return;
365
- closeMenu();
435
+ if (after) after();
366
436
  } else {
367
437
  setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
368
438
  }
@@ -383,16 +453,15 @@ function ModelSelectLite(props) {
383
453
 
384
454
  const choose = (g, m) => {
385
455
  const effort = m.reasoning ? m.reasoning.defaultEffort : undefined;
386
- selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, false);
456
+ submitSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, closeMenu);
387
457
  };
388
458
 
389
- const chooseEffort = (g, m, effort) => {
390
- // Changing the level of the model already in use keeps the card open so
391
- // the user can compare levels; picking a level on another model commits
392
- // model + level in one click and closes.
393
- const sameModel = current !== null && current !== undefined
394
- && current.provider === g.id && current.model === m.id;
395
- selectSelection({ provider: g.id, model: m.id, ...(effort === undefined ? {} : { reasoningEffort: effort }) }, sameModel);
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
+ );
396
465
  };
397
466
 
398
467
  const current = data.current;
@@ -445,11 +514,7 @@ function ModelSelectLite(props) {
445
514
  const renderRow = (g, m, showProvider) => {
446
515
  const selected = isCurrentModel(g, m);
447
516
  const fav = favorites.has(`${g.id}/${m.id}`);
448
- const hasEfforts = !!(m.reasoning && m.reasoning.efforts && m.reasoning.efforts.length);
449
517
  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
518
  const stop = (ev) => { if (ev.key === "Enter" || ev.key === " ") ev.stopPropagation(); };
454
519
  const row = h(
455
520
  "div",
@@ -469,30 +534,6 @@ function ModelSelectLite(props) {
469
534
  },
470
535
  h("span", { className: "mdsl-name" }, m.name),
471
536
  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
537
  h(
497
538
  "button",
498
539
  {
@@ -548,9 +589,15 @@ function ModelSelectLite(props) {
548
589
  rows[next].focus();
549
590
  };
550
591
 
592
+ const canEffort = !!(current && curModel && curModel.reasoning
593
+ && curModel.reasoning.efforts && curModel.reasoning.efforts.length);
551
594
  const triggerTitle = current
552
595
  ? (providerName ? providerName + " / " + modelName : modelName) + (effortLabel ? " / " + effortLabel : "")
553
596
  : "选择模型";
597
+ const closeAll = () => {
598
+ if (open) closeMenu();
599
+ closeEffortMenu();
600
+ };
554
601
 
555
602
  return h(
556
603
  "div",
@@ -569,10 +616,24 @@ function ModelSelectLite(props) {
569
616
  },
570
617
  current && providerName ? h("span", { className: "mdsl-trigger-provider" }, providerName + "/") : null,
571
618
  h("span", { className: "mdsl-label" }, current ? modelName : "选择模型"),
572
- effortLabel ? h("span", { className: "mdsl-effort" }, effortLabel) : null,
573
619
  h("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, chevronDown()),
574
620
  ),
575
- open ? h("div", { className: "mdsl-backdrop", onClick: closeMenu }) : null,
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,
576
637
  open && placement !== null ? h(
577
638
  "div",
578
639
  {
@@ -643,6 +704,64 @@ function ModelSelectLite(props) {
643
704
  )),
644
705
  ),
645
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,
646
765
  );
647
766
  }
648
767