@lynn123411/dsh-model-submenu 0.3.16 → 0.3.18

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/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Model picker",
4
- "description": "Enhances the composer model menu: the model row opens a cross-provider dialog, and the reasoning row becomes a colored slider.",
4
+ "description": "Open the quick list from the model row, or use its right arrow to browse all models. Adjust reasoning effort with a colored slider.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "模型选择",
4
- "description": "增强输入框的模型菜单:第一行「模型」直接打开跨供应商的弹窗,第二行「推理等级」是可拖动的滑块,档位带配色。",
4
+ "description": "点击模型行切换当前或收藏的模型,点击右侧箭头浏览全部模型。推理等级可用带配色的滑块调整。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lynn123411/dsh-model-submenu",
3
- "version": "0.3.16",
4
- "description": "增强输入框的模型菜单:第一行直接打开跨供应商的模型弹窗,第二行的推理等级是可拖动的滑块,档位带配色。",
3
+ "version": "0.3.18",
4
+ "description": "点击模型行切换当前或收藏的模型,点击右侧箭头浏览全部模型。推理等级可用带配色的滑块调整。",
5
5
  "license": "MIT",
6
6
  "packageManager": "pnpm@11.7.0",
7
7
  "publishConfig": {
@@ -1,10 +1,11 @@
1
1
  /**
2
- * Bridge the Host's own model menu: the model cell opens the all-provider
3
- * picker, and the effort cell carries the reasoning-level slider.
2
+ * Bridge the Host's own model menu: the model cell opens a short list, its
3
+ * trailing button opens the all-provider picker, and the effort cell carries
4
+ * the reasoning-level slider.
4
5
  *
5
6
  * The Host owns the root menu's model and effort cells and opens a submenu for each.
6
- * While the root pane is open, this entry redirects the first cell to the model
7
- * dialog and mounts the slider in the second cell.
7
+ * While the root pane is open, this entry redirects the first cell to a detail
8
+ * pane and mounts the slider in the second cell.
8
9
  *
9
10
  * Only the model menu's own direct buttons with the expected label, value and
10
11
  * chevron are recognized. The options slot output sits in its own wrapper,
@@ -16,9 +17,11 @@
16
17
  */
17
18
  import { useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
18
19
  import { createPortal } from 'react-dom';
20
+ import { IconChevronRightOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives';
19
21
  import type { ModelSelectInjected } from '@deepseek-ai/dsh-client-ui-model-selection/client';
20
22
  import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
21
23
  import { EffortSlider } from './EffortSlider.tsx';
24
+ import { QUICK_MODELS_PANE } from './QuickModels.tsx';
22
25
  import type { PickerStore } from './picker-state.ts';
23
26
  import { effortChoices, liveReasoning, planEffortCommit, selectionOf, type Selection } from './selection.ts';
24
27
  import css from './ModelOptions.module.css';
@@ -51,11 +54,13 @@ export type ModelMenuBridgeProps = PropsRuntime<'conversation.input.model.option
51
54
  * @returns an inert marker plus the slider while the effort cell is present.
52
55
  */
53
56
  export function ModelMenuBridge({
54
- sessionId, picker, locked, dismiss, reportFailure, available, directory, select, t,
57
+ sessionId, picker, locked, dismiss, openPane, reportFailure, available, directory, select, t,
55
58
  }: ModelMenuBridgeProps) {
56
59
  const markerRef = useRef<HTMLSpanElement | null>(null);
57
60
  const sliderRef = useRef<HTMLDivElement | null>(null);
58
61
  const [surface, setSurface] = useState<HTMLElement | null>(null);
62
+ const [modelRow, setModelRow] = useState<HTMLButtonElement | null>(null);
63
+ const [browseMount, setBrowseMount] = useState<HTMLElement | null>(null);
59
64
  const [effortRow, setEffortRow] = useState<HTMLElement | null>(null);
60
65
  const [rowLabel, setRowLabel] = useState<string | null>(null);
61
66
 
@@ -77,6 +82,7 @@ export function ModelMenuBridge({
77
82
  const defaultIndex = declared >= 0 ? declared : 0;
78
83
  const busy = locked || state.pending !== null;
79
84
  const canDefault = !busy && !defaultActive;
85
+ const showQuickModels = available && modelRow !== null && browseMount !== null;
80
86
  // One detent is not a choice: leave the Host's row exactly as it is.
81
87
  const showSlider = available && levels.length >= 2 && effortRow !== null;
82
88
 
@@ -91,6 +97,35 @@ export function ModelMenuBridge({
91
97
  if (nextLabel !== (rowLabel ?? '')) setRowLabel(nextLabel);
92
98
  });
93
99
 
100
+ useLayoutEffect(() => {
101
+ const menu = markerRef.current?.closest<HTMLElement>('[data-model-menu][role="menu"]');
102
+ const row = available && menu ? hostCell(menu, 0) : null;
103
+ if (row === null) {
104
+ setModelRow(null);
105
+ setBrowseMount(null);
106
+ return;
107
+ }
108
+ const mount = row.ownerDocument.createElement('span');
109
+ mount.style.display = 'contents';
110
+ row.after(mount);
111
+ // Set this before the Host's return-focus effect runs on a pane switch.
112
+ const previousPane = row.dataset.modelMenuPane;
113
+ const previousPopup = row.getAttribute('aria-haspopup');
114
+ row.dataset.modelMenuPane = QUICK_MODELS_PANE;
115
+ row.setAttribute('aria-haspopup', 'menu');
116
+ row.classList.add(css.modelCell!);
117
+ setModelRow(row);
118
+ setBrowseMount(mount);
119
+ return () => {
120
+ mount.remove();
121
+ row.classList.remove(css.modelCell!);
122
+ if (previousPane === undefined) delete row.dataset.modelMenuPane;
123
+ else row.dataset.modelMenuPane = previousPane;
124
+ if (previousPopup === null) row.removeAttribute('aria-haspopup');
125
+ else row.setAttribute('aria-haspopup', previousPopup);
126
+ };
127
+ }, [available]);
128
+
94
129
  const submit = (selection: Selection | null): void => {
95
130
  if (selection === null || busy || directory.getSnapshot().pending !== null) return;
96
131
  void select(selection).then((result) => {
@@ -112,11 +147,11 @@ export function ModelMenuBridge({
112
147
  submit(planEffortCommit(live, undefined));
113
148
  };
114
149
 
115
- // The Host rebuilds `dismiss` on every render, so the listener reads the
116
- // current one through a ref instead of being torn down and reinstalled.
117
- const latest = useRef({ sessionId, picker, dismiss, available, busy, showSlider, effortRow, canDefault, commitDefault });
150
+ // The listener reads current controls without reinstalling on every render.
151
+ const openQuickModels = () => openPane({ key: QUICK_MODELS_PANE, title: t('picker.quick') });
152
+ const latest = useRef({ modelRow, showQuickModels, openQuickModels, busy, showSlider, effortRow, canDefault, commitDefault });
118
153
  useLayoutEffect(() => {
119
- latest.current = { sessionId, picker, dismiss, available, busy, showSlider, effortRow, canDefault, commitDefault };
154
+ latest.current = { modelRow, showQuickModels, openQuickModels, busy, showSlider, effortRow, canDefault, commitDefault };
120
155
  });
121
156
 
122
157
  useLayoutEffect(() => {
@@ -124,16 +159,13 @@ export function ModelMenuBridge({
124
159
  const redirect = (event: MouseEvent): void => {
125
160
  const target = event.target;
126
161
  const request = latest.current;
127
- if (!(target instanceof Node) || event.defaultPrevented || !request.available) return;
128
- const modelCell = hostCell(surface, 0);
129
- if (modelCell?.contains(target)) {
162
+ if (!(target instanceof Node) || event.defaultPrevented) return;
163
+ if (request.showQuickModels && request.modelRow?.contains(target)) {
130
164
  // Capture on the surface runs before the React root's bubble listener, so
131
165
  // stopping here keeps the cell's own drill handler from ever running.
132
166
  event.preventDefault();
133
167
  event.stopPropagation();
134
- if (request.busy) return;
135
- request.dismiss();
136
- request.picker.open(request.sessionId);
168
+ if (!request.busy) request.openQuickModels();
137
169
  return;
138
170
  }
139
171
  const row = request.effortRow;
@@ -186,6 +218,25 @@ export function ModelMenuBridge({
186
218
 
187
219
  return <>
188
220
  <span ref={markerRef} hidden />
221
+ {showQuickModels && createPortal(
222
+ <button
223
+ className={css.modelBrowse}
224
+ type="button"
225
+ role="menuitem"
226
+ aria-haspopup="dialog"
227
+ aria-label={t('picker.browseAll')}
228
+ title={t('picker.browseAll')}
229
+ disabled={busy}
230
+ onClick={() => {
231
+ if (directory.getSnapshot().pending !== null) return;
232
+ dismiss();
233
+ picker.open(sessionId);
234
+ }}
235
+ >
236
+ <IconChevronRightOutlineRegular size={12} />
237
+ </button>,
238
+ browseMount,
239
+ )}
189
240
  {showSlider && effortRow !== null && createPortal(
190
241
  <div ref={sliderRef} className={css.sliderCell}>
191
242
  <EffortSlider
@@ -11,6 +11,92 @@
11
11
  display: contents;
12
12
  }
13
13
 
14
+ /* Align the separate dialog button over the root model row's trailing edge. */
15
+ .modelCell.modelCell {
16
+ anchor-name: --dsh-quick-model-row;
17
+ padding-inline-end: 14px;
18
+ }
19
+
20
+ .modelCell > svg:last-child {
21
+ visibility: hidden;
22
+ }
23
+
24
+ .modelBrowse {
25
+ position: absolute;
26
+ position-anchor: --dsh-quick-model-row;
27
+ top: anchor(top);
28
+ bottom: anchor(bottom);
29
+ inset-inline-end: anchor(end);
30
+ width: 32px;
31
+ display: grid;
32
+ place-items: center;
33
+ padding: 0;
34
+ border: 0;
35
+ border-radius: var(--dsw-radius-md);
36
+ background: transparent;
37
+ color: var(--dsw-alias-label-tertiary);
38
+ cursor: pointer;
39
+ }
40
+
41
+ .modelBrowse:hover:not(:disabled),
42
+ .modelBrowse:focus-visible {
43
+ background: var(--dsw-alias-interactive-bg-hover);
44
+ color: var(--dsw-alias-label-primary);
45
+ }
46
+
47
+ .quickOption {
48
+ display: flex;
49
+ align-items: center;
50
+ gap: 6px;
51
+ width: 100%;
52
+ min-height: 34px;
53
+ padding: 5px 7px;
54
+ border: 0;
55
+ border-radius: var(--dsw-radius-md);
56
+ outline: none;
57
+ background: transparent;
58
+ color: inherit;
59
+ text-align: start;
60
+ font-size: 13px;
61
+ font-weight: 400;
62
+ line-height: 18px;
63
+ cursor: pointer;
64
+ }
65
+
66
+ .quickOption:hover:not([aria-disabled='true']),
67
+ .quickOption:focus-visible {
68
+ background: var(--dsw-alias-interactive-bg-hover);
69
+ }
70
+
71
+ .quickOption[aria-disabled='true'] {
72
+ color: var(--dsw-alias-label-dimmed);
73
+ cursor: default;
74
+ }
75
+
76
+ .quickCopy {
77
+ display: flex;
78
+ align-items: center;
79
+ gap: 4px;
80
+ flex: 1;
81
+ min-width: 0;
82
+ }
83
+
84
+ .quickName {
85
+ overflow: hidden;
86
+ white-space: nowrap;
87
+ text-overflow: ellipsis;
88
+ }
89
+
90
+ .quickBadge {
91
+ flex: none;
92
+ }
93
+
94
+ .quickCheck {
95
+ display: grid;
96
+ place-items: center;
97
+ flex: 0 0 14px;
98
+ }
99
+
14
100
  /* ── the reasoning-level slider ──────────────────────────────────────────── */
15
101
 
16
102
  /* The Host's effort cell is a flex row: label, value, chevron. The slider takes
@@ -288,7 +374,8 @@
288
374
 
289
375
  /* ── the picker dialog ───────────────────────────────────────────────────── */
290
376
 
291
- .pickerDialog {
377
+ /* Keep the picker dimensions when the host Modal stylesheet loads later. */
378
+ .pickerDialog.pickerDialog {
292
379
  width: min(680px, 100%);
293
380
  height: min(640px, 80vh);
294
381
  gap: 0;
@@ -391,4 +478,3 @@
391
478
  display: flex;
392
479
  flex-wrap: wrap;
393
480
  }
394
-
@@ -13,9 +13,9 @@ import { ModelPicker } from './ModelPicker.tsx';
13
13
  import type { FactsSource } from './facts-source.ts';
14
14
  import {
15
15
  readFavorites,
16
+ storageOf,
16
17
  toggleFavorite,
17
18
  type FavoriteModel,
18
- type FavoritesStorage,
19
19
  } from './favorites.ts';
20
20
  import {
21
21
  effortFor,
@@ -160,12 +160,3 @@ export function ModelPickerFallback({ sessionId, picker, available, directory, t
160
160
  {t('picker.browse')}
161
161
  </Button>;
162
162
  }
163
-
164
- /** Isolate the browser's storage so a locked-down browser reads as "no favorites". */
165
- function storageOf(): FavoritesStorage | undefined {
166
- try {
167
- return globalThis.localStorage;
168
- } catch {
169
- return undefined;
170
- }
171
- }
@@ -0,0 +1,90 @@
1
+ import { useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react'
2
+ import { IconCheckOutlineRegular, MenuGroup, StateDot, Tag } from '@deepseek-ai/dsh-client-ui-primitives'
3
+ import type { ModelDirectoryState, ModelSelectInjected } from '@deepseek-ai/dsh-client-ui-model-selection/client'
4
+ import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
5
+ import { effortFor, readEfforts } from './effort-memory.ts'
6
+ import { isFavorite, readFavorites, storageOf } from './favorites.ts'
7
+ import { planModelCommit, sameModel, selectionOf } from './selection.ts'
8
+ import type { CatalogModel } from './rows.ts'
9
+ import css from './ModelOptions.module.css'
10
+
11
+ export const QUICK_MODELS_PANE = 'lynn-quick-models'
12
+
13
+ type QuickModelsProps = PropsRuntime<'conversation.input.model.pane'>
14
+ & PropsLocale<'modelSubmenu'>
15
+ & Pick<ModelSelectInjected, 'directory' | 'resolveText' | 'select'>
16
+
17
+ /** The current model and available favorites, grouped like the Host's picker. */
18
+ export function QuickModels({ locked, dismiss, reportFailure, directory, resolveText, select, t }: QuickModelsProps) {
19
+ const state = useSyncExternalStore<ModelDirectoryState>((listener) => directory.subscribe(listener), () => directory.getSnapshot())
20
+ const [favorites] = useState(() => readFavorites(storageOf()))
21
+ const open = useRef(false)
22
+ useLayoutEffect(() => {
23
+ open.current = true
24
+ return () => { open.current = false }
25
+ }, [])
26
+
27
+ const live = selectionOf(state)
28
+ const busy = locked || state.pending !== null
29
+ const groups = state.groups.flatMap((group) => {
30
+ const models = group.models.filter((model) =>
31
+ (live !== null && sameModel(live, group.id, model.id)) || isFavorite(favorites, group.id, model.id))
32
+ return models.length === 0 ? [] : [{ ...group, models }]
33
+ })
34
+
35
+ const choose = async (provider: string, model: CatalogModel): Promise<void> => {
36
+ if (busy || directory.getSnapshot().pending !== null) return
37
+ const remembered = effortFor(readEfforts(storageOf()), provider, model.id)
38
+ const selection = planModelCommit(live, provider, model.id, () => model.reasoning, remembered)
39
+ if (selection === null) {
40
+ dismiss()
41
+ return
42
+ }
43
+ const result = await select(selection)
44
+ if (result === undefined) return
45
+ if (result.ok) {
46
+ if (open.current) dismiss()
47
+ return
48
+ }
49
+ reportFailure(result.error.code === 'session/writer-held'
50
+ ? t('error.sessionInUse')
51
+ : t('error.action', { message: `${result.error.code}: ${result.error.message}` }))
52
+ }
53
+
54
+ return <div role="menu" aria-label={t('picker.quick')} aria-busy={busy}>
55
+ {groups.length === 0 && <div className={css.notice} role="status">
56
+ {t(state.status === 'loading' ? 'status.loading' : 'status.empty')}
57
+ </div>}
58
+ {groups.map((group) => <MenuGroup key={group.id} label={group.name}>
59
+ {group.models.map((model) => {
60
+ const selected = live !== null && sameModel(live, group.id, model.id)
61
+ const pending = state.pending !== null && sameModel(state.pending, group.id, model.id)
62
+ return <button
63
+ key={model.id}
64
+ type="button"
65
+ role="menuitemradio"
66
+ aria-checked={selected}
67
+ aria-disabled={busy}
68
+ autoFocus={selected}
69
+ className={css.quickOption}
70
+ title={model.name}
71
+ onClick={() => { void choose(group.id, model) }}
72
+ onKeyDown={(event) => {
73
+ if (event.key !== 'Tab' || event.shiftKey || event.nativeEvent.isComposing) return
74
+ event.preventDefault()
75
+ event.stopPropagation()
76
+ void choose(group.id, model)
77
+ }}
78
+ >
79
+ <span className={css.quickCopy}>
80
+ <span className={css.quickName}>{model.name}</span>
81
+ {model.badge !== undefined && <Tag className={css.quickBadge} tone={model.badge.tone}>{resolveText(model.badge.text)}</Tag>}
82
+ </span>
83
+ <span className={css.quickCheck} aria-hidden="true">
84
+ {pending ? <StateDot state="ongoing" /> : selected && <IconCheckOutlineRegular size={14} />}
85
+ </span>
86
+ </button>
87
+ })}
88
+ </MenuGroup>)}
89
+ </div>
90
+ }
@@ -20,6 +20,15 @@ export const FAVORITES_KEY = 'dsh-model-submenu.favorites'
20
20
  /** The part of `Storage` this module uses; absent or throwing reads mean "none". */
21
21
  export type FavoritesStorage = Pick<Storage, 'getItem' | 'setItem'>
22
22
 
23
+ /** A browser can withhold access to localStorage itself. */
24
+ export function storageOf(): FavoritesStorage | undefined {
25
+ try {
26
+ return globalThis.localStorage
27
+ } catch {
28
+ return undefined
29
+ }
30
+ }
31
+
23
32
  /**
24
33
  * Read the table, keeping only rows that name both halves.
25
34
  * @param storage - browser storage, or undefined when the browser withholds it.
@@ -13,6 +13,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
13
13
  import { EffortTint } from './EffortTint.tsx'
14
14
  import { ModelMenuBridge } from './ModelMenuBridge.tsx'
15
15
  import { ModelPickerFallback, ModelPickerHost } from './ModelPickerHost.tsx'
16
+ import { QUICK_MODELS_PANE, QuickModels } from './QuickModels.tsx'
16
17
  import { createPickerStore } from './picker-state.ts'
17
18
  import { createFactsSource, type DescribeFace } from './facts-source.ts'
18
19
  import { NS, en, zh } from './locales.ts'
@@ -108,6 +109,13 @@ export function apply(ctx: ClientContext): void {
108
109
  locale: NS,
109
110
  inject: faceOf,
110
111
  }, ModelMenuBridge))
112
+ scope.slots.inject('conversation.input.model.pane', () => scope.slots.register({
113
+ name: 'conversation.input.model.pane',
114
+ key: QUICK_MODELS_PANE,
115
+ registrant: '@lynn123411/dsh-model-submenu',
116
+ locale: NS,
117
+ inject: faceOf,
118
+ }, QuickModels))
111
119
  scope.slots.inject('conversation.input.overlay', () => scope.slots.register({
112
120
  name: 'conversation.input.overlay',
113
121
  id: 'model-picker',
@@ -14,6 +14,8 @@ export type ModelSubmenuLocaleKey =
14
14
  | 'error.sessionInUse'
15
15
  | 'picker.title'
16
16
  | 'picker.browse'
17
+ | 'picker.browseAll'
18
+ | 'picker.quick'
17
19
  | 'picker.close'
18
20
  | 'picker.search'
19
21
  | 'picker.searchEmpty'
@@ -45,6 +47,8 @@ export const zh: Record<ModelSubmenuLocaleKey, string> = {
45
47
  'error.sessionInUse': '当前会话已被占用,可能是其他正在运行的 DSH 导致的(如其他 dsh web、桌面端),请退出其他正在运行的 DSH 后重试。',
46
48
  'picker.title': '切换模型',
47
49
  'picker.browse': '浏览模型',
50
+ 'picker.browseAll': '浏览全部模型',
51
+ 'picker.quick': '快捷切换模型',
48
52
  'picker.close': '关闭',
49
53
  'picker.search': '搜索模型或提供商…',
50
54
  'picker.searchEmpty': '没有匹配的模型。',
@@ -70,6 +74,8 @@ export const en: Record<ModelSubmenuLocaleKey, string> = {
70
74
  'error.sessionInUse': 'This session is already in use, possibly by another running DSH instance (such as dsh web or the desktop app). Quit other running DSH instances and try again.',
71
75
  'picker.title': 'Switch model',
72
76
  'picker.browse': 'Browse models',
77
+ 'picker.browseAll': 'Browse all models',
78
+ 'picker.quick': 'Quick model selection',
73
79
  'picker.close': 'Close',
74
80
  'picker.search': 'Search models or providers…',
75
81
  'picker.searchEmpty': 'No matching models.',