@lynn123411/dsh-model-submenu 0.3.14 → 0.3.15
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 +11 -10
- package/lib/client.js +1752 -122
- package/lib/client.js.map +1 -1
- package/package.json +15 -14
- package/src/client/EffortSlider.tsx +18 -8
- package/src/client/ModelMenuBridge.tsx +44 -41
- package/src/client/ModelPicker.tsx +9 -20
- package/src/client/ModelPickerHost.tsx +34 -9
- package/src/client/index.ts +24 -8
- package/src/client/locales.ts +3 -0
- package/src/client/picker-state.ts +6 -4
- package/src/client/rows.ts +8 -36
- package/src/client/selection.ts +5 -1
- package/src/css-modules.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynn123411/dsh-model-submenu",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "增强输入框的模型菜单:第一行直接打开跨供应商的模型弹窗,第二行的推理等级是可拖动的滑块,档位带配色。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"packageManager": "pnpm@11.7.0",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": "^22.19.0 || >=24.0.0",
|
|
13
|
-
"dsh": ">=0.2.
|
|
13
|
+
"dsh": ">=0.2.3-alpha.2"
|
|
14
14
|
},
|
|
15
15
|
"main": "lib/index.js",
|
|
16
16
|
"exports": {
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"test": "node scripts/test-favorites.mjs && node scripts/test-facts.mjs && node scripts/test-commit.mjs && node scripts/test-rows.mjs && node scripts/test-effort-memory.mjs && node scripts/test-slider.mjs && node scripts/test-render.mjs"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@deepseek-ai/cordis": "^4.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.
|
|
67
|
+
"@deepseek-ai/cordis": "^4.2.0-alpha.1",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.3-alpha.2",
|
|
69
69
|
"react": "^18.2.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
@@ -74,16 +74,17 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@deepseek-ai/cordis": "^4.
|
|
78
|
-
"@deepseek-ai/dsh-api-remotes": ">=0.2.
|
|
79
|
-
"@deepseek-ai/dsh-api-session-controller": ">=0.2.
|
|
80
|
-
"@deepseek-ai/dsh-client-locale": ">=0.2.
|
|
81
|
-
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.
|
|
82
|
-
"@deepseek-ai/dsh-client-ui-model-selection": ">=0.2.
|
|
83
|
-
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.
|
|
84
|
-
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.
|
|
85
|
-
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.
|
|
86
|
-
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.
|
|
77
|
+
"@deepseek-ai/cordis": "^4.2.0-alpha.1",
|
|
78
|
+
"@deepseek-ai/dsh-api-remotes": ">=0.2.3-alpha.2",
|
|
79
|
+
"@deepseek-ai/dsh-api-session-controller": ">=0.2.3-alpha.2",
|
|
80
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.3-alpha.2",
|
|
81
|
+
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.3-alpha.2",
|
|
82
|
+
"@deepseek-ai/dsh-client-ui-model-selection": ">=0.2.3-alpha.2",
|
|
83
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.3-alpha.2",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.3-alpha.2",
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.3-alpha.2",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.3-alpha.2",
|
|
87
|
+
"@deepseek-ai/dsh-util-text-search": ">=0.2.3-alpha.2",
|
|
87
88
|
"@types/node": "^22.20.0",
|
|
88
89
|
"@types/react": "~18.3.1",
|
|
89
90
|
"@types/react-dom": "~18.3.0",
|
|
@@ -53,6 +53,7 @@ export function EffortSlider({
|
|
|
53
53
|
// The drag position lives in a ref as well as in state: a press and a release
|
|
54
54
|
// can arrive in one task, and the release must not read a render that never ran.
|
|
55
55
|
const dragRef = useRef<number | null>(null);
|
|
56
|
+
const pointerRef = useRef<number | null>(null);
|
|
56
57
|
// While dragging this is where the pointer is along the travel, not a level:
|
|
57
58
|
// the knob has to move with the pointer, or the drag reads as a series of jumps.
|
|
58
59
|
const [drag, setDrag] = useState<number | null>(null);
|
|
@@ -74,7 +75,13 @@ export function EffortSlider({
|
|
|
74
75
|
// The hold ends as soon as the write does, whether it landed on the new level
|
|
75
76
|
// or was rejected: the displayed level is the truth again either way.
|
|
76
77
|
useEffect(() => {
|
|
77
|
-
if (!busy)
|
|
78
|
+
if (!busy) {
|
|
79
|
+
setHold(null);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
pointerRef.current = null;
|
|
83
|
+
dragRef.current = null;
|
|
84
|
+
setDrag(null);
|
|
78
85
|
}, [busy]);
|
|
79
86
|
useEffect(() => {
|
|
80
87
|
setHold(null);
|
|
@@ -88,12 +95,13 @@ export function EffortSlider({
|
|
|
88
95
|
};
|
|
89
96
|
|
|
90
97
|
const onPointerDown = (event: PointerEvent<HTMLDivElement>): void => {
|
|
91
|
-
if (busy) return;
|
|
98
|
+
if (busy || event.button !== 0 || pointerRef.current !== null) return;
|
|
92
99
|
// The Host's menu cell owns this subtree; without these the press would
|
|
93
100
|
// also settle the cell and pull focus out of the slider.
|
|
94
101
|
event.preventDefault();
|
|
95
102
|
event.stopPropagation();
|
|
96
103
|
setHold(null);
|
|
104
|
+
pointerRef.current = event.pointerId;
|
|
97
105
|
beginDrag(fractionAtPointer(event.clientX));
|
|
98
106
|
try {
|
|
99
107
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
@@ -104,15 +112,16 @@ export function EffortSlider({
|
|
|
104
112
|
};
|
|
105
113
|
|
|
106
114
|
const onPointerMove = (event: PointerEvent<HTMLDivElement>): void => {
|
|
107
|
-
if (
|
|
115
|
+
if (pointerRef.current !== event.pointerId || busy) return;
|
|
108
116
|
beginDrag(fractionAtPointer(event.clientX));
|
|
109
117
|
};
|
|
110
118
|
|
|
111
119
|
const settle = (event: PointerEvent<HTMLDivElement>, commit: boolean): void => {
|
|
112
|
-
if (
|
|
113
|
-
|
|
120
|
+
if (pointerRef.current !== event.pointerId) return;
|
|
121
|
+
pointerRef.current = null;
|
|
114
122
|
beginDrag(null);
|
|
115
|
-
if (!commit) return;
|
|
123
|
+
if (!commit || busy) return;
|
|
124
|
+
const next = detentAt(fractionAtPointer(event.clientX), steps.length);
|
|
116
125
|
// Leaving the provider default is a change even when the knob lands where
|
|
117
126
|
// the default already pointed.
|
|
118
127
|
if (next !== current || defaultActive) {
|
|
@@ -122,7 +131,7 @@ export function EffortSlider({
|
|
|
122
131
|
};
|
|
123
132
|
|
|
124
133
|
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {
|
|
125
|
-
if (
|
|
134
|
+
if (event.nativeEvent.isComposing) return;
|
|
126
135
|
const last = steps.length - 1;
|
|
127
136
|
const next = event.key === 'ArrowRight' || event.key === 'ArrowUp'
|
|
128
137
|
? Math.min(active + 1, last)
|
|
@@ -137,7 +146,7 @@ export function EffortSlider({
|
|
|
137
146
|
// The menu walks rows with the arrow keys; a slider keeps them for itself.
|
|
138
147
|
event.preventDefault();
|
|
139
148
|
event.stopPropagation();
|
|
140
|
-
if (next !== current || defaultActive) onCommit(next);
|
|
149
|
+
if (!busy && (next !== current || defaultActive)) onCommit(next);
|
|
141
150
|
};
|
|
142
151
|
|
|
143
152
|
const offset = knobOffset(knobFraction);
|
|
@@ -164,6 +173,7 @@ export function EffortSlider({
|
|
|
164
173
|
onPointerMove={onPointerMove}
|
|
165
174
|
onPointerUp={(event) => { settle(event, true); }}
|
|
166
175
|
onPointerCancel={(event) => { settle(event, false); }}
|
|
176
|
+
onLostPointerCapture={(event) => { settle(event, false); }}
|
|
167
177
|
onKeyDown={onKeyDown}
|
|
168
178
|
onClick={(event) => { event.stopPropagation(); }}
|
|
169
179
|
>
|
|
@@ -2,24 +2,19 @@
|
|
|
2
2
|
* Bridge the Host's own model menu: the model cell opens the all-provider
|
|
3
3
|
* picker, and the effort cell carries the reasoning-level slider.
|
|
4
4
|
*
|
|
5
|
-
* The Host
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Host exposes no hook for either. This entry is mounted exactly while the root
|
|
9
|
-
* pane is open, so it can take the click on the menu surface before the cells'
|
|
10
|
-
* own handlers run and mount the slider into the effort cell.
|
|
5
|
+
* 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.
|
|
11
8
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* cell is missing the model declares no reasoning levels and the row is left
|
|
16
|
-
* alone; when the first is missing the click falls through to the Host.
|
|
9
|
+
* Only the model menu's own direct buttons with the expected label, value and
|
|
10
|
+
* chevron are recognized. The options slot output sits in its own wrapper,
|
|
11
|
+
* so other plugins' rows never join that list.
|
|
17
12
|
*
|
|
18
13
|
* Clicking the cell's label switches to the provider default, which is a state
|
|
19
14
|
* rather than a detent: the slider shows it as an empty track under a hollow
|
|
20
15
|
* knob, so it never reads as the weakest level.
|
|
21
16
|
*/
|
|
22
|
-
import {
|
|
17
|
+
import { useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
23
18
|
import { createPortal } from 'react-dom';
|
|
24
19
|
import type { ModelSelectInjected } from '@deepseek-ai/dsh-client-ui-model-selection/client';
|
|
25
20
|
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
@@ -28,6 +23,17 @@ import type { PickerStore } from './picker-state.ts';
|
|
|
28
23
|
import { effortChoices, liveReasoning, planEffortCommit, selectionOf, type Selection } from './selection.ts';
|
|
29
24
|
import css from './ModelOptions.module.css';
|
|
30
25
|
|
|
26
|
+
const cellLabel = ':scope > span[class*="cellLabel"]';
|
|
27
|
+
const cellValue = ':scope > span[class*="cellValue"]';
|
|
28
|
+
const cellChevron = ':scope > svg[class*="cellChevron"]';
|
|
29
|
+
|
|
30
|
+
/** Match only the host-owned buttons in the root model menu. */
|
|
31
|
+
function hostCell(surface: HTMLElement, index: number): HTMLButtonElement | null {
|
|
32
|
+
const button = surface.querySelectorAll<HTMLButtonElement>(':scope > button[role="menuitem"]')[index];
|
|
33
|
+
if (!button?.querySelector(cellLabel) || !button.querySelector(cellValue) || !button.querySelector(cellChevron)) return null;
|
|
34
|
+
return button;
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
/** Props of the bridge: menu state, the owning session, and the seat's injected face. */
|
|
32
38
|
export type ModelMenuBridgeProps = PropsRuntime<'conversation.input.model.options'>
|
|
33
39
|
& PropsLocale<'modelSubmenu'>
|
|
@@ -45,7 +51,7 @@ export type ModelMenuBridgeProps = PropsRuntime<'conversation.input.model.option
|
|
|
45
51
|
* @returns an inert marker plus the slider while the effort cell is present.
|
|
46
52
|
*/
|
|
47
53
|
export function ModelMenuBridge({
|
|
48
|
-
sessionId, picker, dismiss, reportFailure, available, directory, select, t,
|
|
54
|
+
sessionId, picker, locked, dismiss, reportFailure, available, directory, select, t,
|
|
49
55
|
}: ModelMenuBridgeProps) {
|
|
50
56
|
const markerRef = useRef<HTMLSpanElement | null>(null);
|
|
51
57
|
const sliderRef = useRef<HTMLDivElement | null>(null);
|
|
@@ -69,28 +75,24 @@ export function ModelMenuBridge({
|
|
|
69
75
|
const defaultActive = current !== null && current.reasoningEffort === undefined;
|
|
70
76
|
const currentIndex = chosen >= 0 ? chosen : declared >= 0 ? declared : 0;
|
|
71
77
|
const defaultIndex = declared >= 0 ? declared : 0;
|
|
72
|
-
const
|
|
73
|
-
const
|
|
78
|
+
const busy = locked || state.pending !== null;
|
|
79
|
+
const canDefault = !busy && !defaultActive;
|
|
74
80
|
// One detent is not a choice: leave the Host's row exactly as it is.
|
|
75
81
|
const showSlider = available && levels.length >= 2 && effortRow !== null;
|
|
76
82
|
|
|
77
83
|
// The Host rebuilds its cells on every render, so the surface and the effort
|
|
78
84
|
// cell are re-read after each one; the identity guards keep that from looping.
|
|
79
85
|
useLayoutEffect(() => {
|
|
80
|
-
const
|
|
81
|
-
const nextSurface = foundSurface instanceof HTMLElement ? foundSurface : null;
|
|
86
|
+
const nextSurface = markerRef.current?.closest<HTMLElement>('[data-model-menu][role="menu"]') ?? null;
|
|
82
87
|
if (nextSurface !== surface) setSurface(nextSurface);
|
|
83
|
-
const
|
|
84
|
-
? []
|
|
85
|
-
: [...nextSurface.querySelectorAll<HTMLElement>(':scope > button[role="menuitem"]')];
|
|
86
|
-
const nextRow = cells.length >= 2 ? cells[1] ?? null : null;
|
|
88
|
+
const nextRow = nextSurface === null ? null : hostCell(nextSurface, 1);
|
|
87
89
|
if (nextRow !== effortRow) setEffortRow(nextRow);
|
|
88
|
-
const nextLabel = nextRow?.querySelector(
|
|
90
|
+
const nextLabel = nextRow?.querySelector(cellLabel)?.textContent?.trim() ?? '';
|
|
89
91
|
if (nextLabel !== (rowLabel ?? '')) setRowLabel(nextLabel);
|
|
90
92
|
});
|
|
91
93
|
|
|
92
94
|
const submit = (selection: Selection | null): void => {
|
|
93
|
-
if (selection === null) return;
|
|
95
|
+
if (selection === null || busy || directory.getSnapshot().pending !== null) return;
|
|
94
96
|
void select(selection).then((result) => {
|
|
95
97
|
if (result === undefined || result.ok) return;
|
|
96
98
|
reportFailure(result.error.code === 'session/writer-held'
|
|
@@ -112,35 +114,35 @@ export function ModelMenuBridge({
|
|
|
112
114
|
|
|
113
115
|
// The Host rebuilds `dismiss` on every render, so the listener reads the
|
|
114
116
|
// current one through a ref instead of being torn down and reinstalled.
|
|
115
|
-
const latest = useRef({ sessionId, picker, dismiss, showSlider, canDefault, commitDefault });
|
|
116
|
-
|
|
117
|
+
const latest = useRef({ sessionId, picker, dismiss, available, busy, showSlider, effortRow, canDefault, commitDefault });
|
|
118
|
+
useLayoutEffect(() => {
|
|
119
|
+
latest.current = { sessionId, picker, dismiss, available, busy, showSlider, effortRow, canDefault, commitDefault };
|
|
120
|
+
});
|
|
117
121
|
|
|
118
|
-
|
|
122
|
+
useLayoutEffect(() => {
|
|
119
123
|
if (surface === null) return;
|
|
120
124
|
const redirect = (event: MouseEvent): void => {
|
|
121
125
|
const target = event.target;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const modelCell =
|
|
125
|
-
if (modelCell
|
|
126
|
+
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)) {
|
|
126
130
|
// Capture on the surface runs before the React root's bubble listener, so
|
|
127
131
|
// stopping here keeps the cell's own drill handler from ever running.
|
|
128
132
|
event.preventDefault();
|
|
129
133
|
event.stopPropagation();
|
|
130
|
-
|
|
134
|
+
if (request.busy) return;
|
|
131
135
|
request.dismiss();
|
|
132
136
|
request.picker.open(request.sessionId);
|
|
133
137
|
return;
|
|
134
138
|
}
|
|
135
|
-
const row =
|
|
136
|
-
if (row ===
|
|
137
|
-
// The slider owns its own presses; only the label and the value are inert.
|
|
138
|
-
if (sliderRef.current?.contains(target) === true) return;
|
|
139
|
+
const row = request.effortRow;
|
|
140
|
+
if (row === null || !surface.contains(row) || !row.contains(target) || !request.showSlider) return;
|
|
139
141
|
event.preventDefault();
|
|
140
142
|
event.stopPropagation();
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
143
|
+
if (request.busy || sliderRef.current?.contains(target)) return;
|
|
144
|
+
if (request.canDefault && row.querySelector(cellLabel)?.contains(target)) {
|
|
145
|
+
request.commitDefault();
|
|
144
146
|
return;
|
|
145
147
|
}
|
|
146
148
|
sliderRef.current?.querySelector<HTMLElement>('[role="slider"]')?.focus();
|
|
@@ -156,9 +158,9 @@ export function ModelMenuBridge({
|
|
|
156
158
|
// row no longer drills anywhere. Every write is recorded and put back.
|
|
157
159
|
useLayoutEffect(() => {
|
|
158
160
|
if (effortRow === null || !showSlider) return;
|
|
159
|
-
const label = effortRow.querySelector<HTMLElement>(
|
|
160
|
-
const value = effortRow.querySelector<HTMLElement>(
|
|
161
|
-
const chevron = effortRow.querySelector<SVGElement>(
|
|
161
|
+
const label = effortRow.querySelector<HTMLElement>(cellLabel);
|
|
162
|
+
const value = effortRow.querySelector<HTMLElement>(cellValue);
|
|
163
|
+
const chevron = effortRow.querySelector<SVGElement>(cellChevron);
|
|
162
164
|
const saved = {
|
|
163
165
|
value: value?.style.display ?? '',
|
|
164
166
|
chevron: chevron?.style.display ?? '',
|
|
@@ -187,6 +189,7 @@ export function ModelMenuBridge({
|
|
|
187
189
|
{showSlider && effortRow !== null && createPortal(
|
|
188
190
|
<div ref={sliderRef} className={css.sliderCell}>
|
|
189
191
|
<EffortSlider
|
|
192
|
+
key={JSON.stringify([current?.provider, current?.model])}
|
|
190
193
|
steps={levels}
|
|
191
194
|
current={currentIndex}
|
|
192
195
|
defaultActive={defaultActive}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The model picker: the centered dialog opened from the menu's
|
|
2
|
+
* The model picker: the centered dialog opened from the menu's model row.
|
|
3
3
|
*
|
|
4
4
|
* It is the one place every provider is visible at once — a search field, a tab
|
|
5
5
|
* per provider with a model, and one flat list with each model's metadata line.
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
Input,
|
|
15
15
|
Modal,
|
|
16
16
|
ShortcutKeys,
|
|
17
|
-
rankByName,
|
|
18
17
|
} from '@deepseek-ai/dsh-client-ui-primitives'
|
|
19
18
|
import type { ModelDirectoryState } from '@deepseek-ai/dsh-client-ui-model-selection/client'
|
|
20
19
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
@@ -28,7 +27,7 @@ import {
|
|
|
28
27
|
pickerTabs,
|
|
29
28
|
reasoningOf,
|
|
30
29
|
rowsForTab,
|
|
31
|
-
|
|
30
|
+
createModelSearch,
|
|
32
31
|
type CatalogModel,
|
|
33
32
|
type ModelRow as CatalogRow,
|
|
34
33
|
} from './rows.ts'
|
|
@@ -80,35 +79,26 @@ export function ModelPicker({
|
|
|
80
79
|
open, resolveText, state, live, facts, favorites, busy, rememberedOf, onPick, onToggleFavorite, onReload, onClose, t,
|
|
81
80
|
}: ModelPickerProps & PropsLocale<'modelSubmenu'>) {
|
|
82
81
|
const id = useId()
|
|
83
|
-
const searchRef = useRef<HTMLInputElement | null>(null)
|
|
84
82
|
const listRef = useRef<HTMLDivElement | null>(null)
|
|
85
83
|
const [query, setQuery] = useState('')
|
|
86
84
|
const [tab, setTab] = useState(ALL_TAB)
|
|
87
85
|
|
|
88
86
|
const tabs = useMemo(() => pickerTabs(state.groups, t('picker.all')), [state.groups, t])
|
|
89
87
|
const reason = useMemo(() => reasoningOf(state.groups), [state.groups])
|
|
90
|
-
const
|
|
91
|
-
rowsForTab(flattenGroups(state.groups), tab),
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
// Search runs inside the favorite partition, never across it: a query must not
|
|
95
|
-
// pull an unstarred model above a starred one, because favorites lead the list
|
|
96
|
-
// whether or not a query is typed.
|
|
88
|
+
const search = useMemo(
|
|
89
|
+
() => createModelSearch(rowsForTab(flattenGroups(state.groups), tab)),
|
|
90
|
+
[state.groups, tab],
|
|
91
|
+
)
|
|
97
92
|
const visible = useMemo(() => orderWithFavorites(
|
|
98
|
-
|
|
93
|
+
search.search(query),
|
|
99
94
|
(row) => isFavorite(favorites, row.provider, row.model),
|
|
100
|
-
), [
|
|
95
|
+
), [search, query, favorites])
|
|
101
96
|
|
|
102
97
|
useEffect(() => {
|
|
103
98
|
if (!open) return
|
|
104
99
|
setQuery('')
|
|
105
100
|
setTab(ALL_TAB)
|
|
106
101
|
if (listRef.current !== null) listRef.current.scrollTop = 0
|
|
107
|
-
// 粗指针设备不自动聚焦文本输入:移动端弹键盘会顶起布局,宿主座位也这样守。
|
|
108
|
-
const frame = requestAnimationFrame(() => {
|
|
109
|
-
if (!isMobileDevice()) searchRef.current?.focus()
|
|
110
|
-
})
|
|
111
|
-
return () => { cancelAnimationFrame(frame) }
|
|
112
102
|
}, [open])
|
|
113
103
|
|
|
114
104
|
if (!open) return null
|
|
@@ -135,7 +125,6 @@ export function ModelPicker({
|
|
|
135
125
|
>
|
|
136
126
|
<div className={css.pickerSearch}>
|
|
137
127
|
<Input
|
|
138
|
-
ref={searchRef}
|
|
139
128
|
className={css.pickerSearchInput ?? ''}
|
|
140
129
|
type="text"
|
|
141
130
|
role="searchbox"
|
|
@@ -146,7 +135,7 @@ export function ModelPicker({
|
|
|
146
135
|
value={query}
|
|
147
136
|
readOnly={busy}
|
|
148
137
|
onChange={(event) => { setQuery(event.target.value) }}
|
|
149
|
-
data-modal-autofocus=
|
|
138
|
+
data-modal-autofocus={isMobileDevice() ? undefined : ''}
|
|
150
139
|
/>
|
|
151
140
|
</div>
|
|
152
141
|
<div className={css.pickerTabs} role="tablist" aria-label={t('picker.title')}>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The composer overlay's picker view: the dialog, its catalog, and its verbs.
|
|
3
3
|
*
|
|
4
|
-
* It lives in `conversation.input.overlay`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* It lives in `conversation.input.overlay` so it can open after the Host's menu
|
|
5
|
+
* closes or from the toolbar when the current model is missing. Its data comes
|
|
6
|
+
* from the slot entry's injected face.
|
|
7
7
|
*/
|
|
8
8
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
9
|
-
import { IconWarningOutlineRegular, Toast } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
9
|
+
import { Button, IconWarningOutlineRegular, Toast } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
10
10
|
import type { ModelSelectInjected } from '@deepseek-ai/dsh-client-ui-model-selection/client';
|
|
11
11
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
12
12
|
import { ModelPicker } from './ModelPicker.tsx';
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
rememberEffort,
|
|
24
24
|
type RememberedEffort,
|
|
25
25
|
} from './effort-memory.ts';
|
|
26
|
-
import { selectionOf, type Selection } from './selection.ts';
|
|
26
|
+
import { currentCatalogModel, selectionOf, type Selection } from './selection.ts';
|
|
27
27
|
import type { PickerStore } from './picker-state.ts';
|
|
28
28
|
import css from './ModelOptions.module.css';
|
|
29
29
|
|
|
@@ -55,10 +55,19 @@ export function ModelPickerHost({
|
|
|
55
55
|
const toastSeq = useRef(0);
|
|
56
56
|
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
57
57
|
|
|
58
|
-
const busy = state.
|
|
58
|
+
const busy = state.pending !== null;
|
|
59
59
|
const live = useMemo(() => selectionOf(state), [state]);
|
|
60
60
|
const facts = useSyncExternalStore((listener) => factsSource.subscribe(listener), () => factsSource.getSnapshot());
|
|
61
|
-
const open = request.sessionId === sessionId;
|
|
61
|
+
const open = available && request.sessionId === sessionId;
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const trigger = request.returnFocus;
|
|
64
|
+
if (!open || trigger === undefined) return;
|
|
65
|
+
return () => {
|
|
66
|
+
if (picker.getSnapshot().sessionId === null && trigger.isConnected && !trigger.closest('[inert], [hidden]')) {
|
|
67
|
+
trigger.focus({ preventScroll: true });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, [open, picker, request]);
|
|
62
71
|
// The injected face is cached per entry and session, but the read goes through
|
|
63
72
|
// a ref anyway: a catalog load writes the store, so an unstable `load` in the
|
|
64
73
|
// dependency list would reload on every render it caused.
|
|
@@ -92,12 +101,14 @@ export function ModelPickerHost({
|
|
|
92
101
|
setToast({ seq: toastSeq.current, text });
|
|
93
102
|
};
|
|
94
103
|
const submit = (selection: Selection): void => {
|
|
104
|
+
if (directory.getSnapshot().pending !== null) return;
|
|
95
105
|
void select(selection).then((result) => {
|
|
96
|
-
if (result
|
|
106
|
+
if (result?.ok) {
|
|
97
107
|
setMemory(rememberEffort(storageOf(), selection.provider, selection.model, selection.reasoningEffort));
|
|
98
|
-
picker.close();
|
|
108
|
+
if (picker.getSnapshot() === request) picker.close();
|
|
99
109
|
return;
|
|
100
110
|
}
|
|
111
|
+
if (result === undefined || picker.getSnapshot() !== request) return;
|
|
101
112
|
raiseToast(result.error.code === 'session/writer-held'
|
|
102
113
|
? t('error.sessionInUse')
|
|
103
114
|
: t('error.action', { message: `${result.error.code}: ${result.error.message}` }));
|
|
@@ -136,6 +147,20 @@ export function ModelPickerHost({
|
|
|
136
147
|
</div>;
|
|
137
148
|
}
|
|
138
149
|
|
|
150
|
+
/** The Host skips the root menu when the current model is absent from its catalog. */
|
|
151
|
+
export function ModelPickerFallback({ sessionId, picker, available, directory, t }: Pick<
|
|
152
|
+
ModelPickerHostProps, 'sessionId' | 'picker' | 'available' | 'directory' | 't'
|
|
153
|
+
>) {
|
|
154
|
+
const state = useSyncExternalStore((listener) => directory.subscribe(listener), () => directory.getSnapshot());
|
|
155
|
+
if (!available || currentCatalogModel(state) !== undefined) return null;
|
|
156
|
+
|
|
157
|
+
return <Button variant="toolbar" size="sm" aria-haspopup="dialog" disabled={state.pending !== null} onClick={(event) => {
|
|
158
|
+
if (directory.getSnapshot().pending === null) picker.open(sessionId, event.currentTarget);
|
|
159
|
+
}}>
|
|
160
|
+
{t('picker.browse')}
|
|
161
|
+
</Button>;
|
|
162
|
+
}
|
|
163
|
+
|
|
139
164
|
/** Isolate the browser's storage so a locked-down browser reads as "no favorites". */
|
|
140
165
|
function storageOf(): FavoritesStorage | undefined {
|
|
141
166
|
try {
|
package/src/client/index.ts
CHANGED
|
@@ -12,10 +12,11 @@ import type {} from '@deepseek-ai/dsh-client-ui-model-selection/client'
|
|
|
12
12
|
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
|
-
import { ModelPickerHost } from './ModelPickerHost.tsx'
|
|
15
|
+
import { ModelPickerFallback, ModelPickerHost } from './ModelPickerHost.tsx'
|
|
16
16
|
import { createPickerStore } from './picker-state.ts'
|
|
17
17
|
import { createFactsSource, type DescribeFace } from './facts-source.ts'
|
|
18
18
|
import { NS, en, zh } from './locales.ts'
|
|
19
|
+
import { stylesheet } from './ModelOptions.module.css'
|
|
19
20
|
|
|
20
21
|
export { EffortTint } from './EffortTint.tsx'
|
|
21
22
|
export { ModelMenuBridge } from './ModelMenuBridge.tsx'
|
|
@@ -46,16 +47,24 @@ export const inject = [
|
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
* Client plugin body: register this plugin's dictionaries, then contribute the
|
|
49
|
-
* bridge
|
|
50
|
-
*
|
|
51
|
-
* the tint that keeps the collapsed trigger's effort caption on the same color.
|
|
50
|
+
* menu bridge, the toolbar entry for a missing current model, the picker
|
|
51
|
+
* overlay, and the tint for the collapsed trigger's effort caption.
|
|
52
52
|
*
|
|
53
|
-
* The
|
|
54
|
-
*
|
|
55
|
-
* survives the menu's teardown.
|
|
53
|
+
* The overlay stays mounted when the Host closes the model menu, allowing the
|
|
54
|
+
* picker to open after the menu has been removed.
|
|
56
55
|
* @param ctx - client root context.
|
|
57
56
|
*/
|
|
58
57
|
export function apply(ctx: ClientContext): void {
|
|
58
|
+
if (typeof document !== 'undefined') {
|
|
59
|
+
ctx.effect(() => {
|
|
60
|
+
const style = document.createElement('style')
|
|
61
|
+
style.dataset.plugin = '@lynn123411/dsh-model-submenu'
|
|
62
|
+
style.dataset.pluginCss = '@lynn123411/dsh-model-submenu/ModelOptions.module.css'
|
|
63
|
+
style.textContent = stylesheet
|
|
64
|
+
document.head.append(style)
|
|
65
|
+
return () => style.remove()
|
|
66
|
+
}, 'dsh-model-submenu: styles')
|
|
67
|
+
}
|
|
59
68
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-model-submenu: dictionaries')
|
|
60
69
|
ctx.inject(['slots', 'modelDirectories', 'configForms', 'remote'], (scope) => {
|
|
61
70
|
const models = scope.modelDirectories
|
|
@@ -65,7 +74,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
65
74
|
describe: scope.configForms.describe() as DescribeFace,
|
|
66
75
|
listProviders: () => scope.remote.llm.listConfigurableProviders(),
|
|
67
76
|
})
|
|
68
|
-
|
|
77
|
+
scope.effect(() => facts.start(), 'dsh-model-submenu: model metadata')
|
|
69
78
|
/**
|
|
70
79
|
* Build one entry's business face for a session.
|
|
71
80
|
* @param sessionId - the slot's session scope.
|
|
@@ -106,6 +115,13 @@ export function apply(ctx: ClientContext): void {
|
|
|
106
115
|
locale: NS,
|
|
107
116
|
inject: faceOf,
|
|
108
117
|
}, ModelPickerHost))
|
|
118
|
+
scope.slots.inject('conversation.input.right', () => scope.slots.register({
|
|
119
|
+
name: 'conversation.input.right',
|
|
120
|
+
id: 'model-picker-fallback',
|
|
121
|
+
registrant: '@lynn123411/dsh-model-submenu',
|
|
122
|
+
locale: NS,
|
|
123
|
+
inject: faceOf,
|
|
124
|
+
}, ModelPickerFallback))
|
|
109
125
|
// The trigger's effort caption lives outside the menu, so its tint needs an
|
|
110
126
|
// entry that stays mounted for the whole session.
|
|
111
127
|
scope.slots.inject('conversation.input.overlay', () => scope.slots.register({
|
package/src/client/locales.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type ModelSubmenuLocaleKey =
|
|
|
13
13
|
| 'error.action'
|
|
14
14
|
| 'error.sessionInUse'
|
|
15
15
|
| 'picker.title'
|
|
16
|
+
| 'picker.browse'
|
|
16
17
|
| 'picker.close'
|
|
17
18
|
| 'picker.search'
|
|
18
19
|
| 'picker.searchEmpty'
|
|
@@ -43,6 +44,7 @@ export const zh: Record<ModelSubmenuLocaleKey, string> = {
|
|
|
43
44
|
'error.action': '模型操作失败:{message}',
|
|
44
45
|
'error.sessionInUse': '当前会话已被占用,可能是其他正在运行的 DSH 导致的(如其他 dsh web、桌面端),请退出其他正在运行的 DSH 后重试。',
|
|
45
46
|
'picker.title': '切换模型',
|
|
47
|
+
'picker.browse': '浏览模型',
|
|
46
48
|
'picker.close': '关闭',
|
|
47
49
|
'picker.search': '搜索模型或提供商…',
|
|
48
50
|
'picker.searchEmpty': '没有匹配的模型。',
|
|
@@ -67,6 +69,7 @@ export const en: Record<ModelSubmenuLocaleKey, string> = {
|
|
|
67
69
|
'error.action': 'Model operation failed: {message}',
|
|
68
70
|
'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.',
|
|
69
71
|
'picker.title': 'Switch model',
|
|
72
|
+
'picker.browse': 'Browse models',
|
|
70
73
|
'picker.close': 'Close',
|
|
71
74
|
'picker.search': 'Search models or providers…',
|
|
72
75
|
'picker.searchEmpty': 'No matching models.',
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
export interface PickerSnapshot {
|
|
13
13
|
/** Session whose picker is open, or null when none is. */
|
|
14
14
|
readonly sessionId: string | null
|
|
15
|
+
/** Toolbar button to refocus after the dialog closes, when still present. */
|
|
16
|
+
readonly returnFocus?: HTMLButtonElement
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
/** Open and close verbs plus the observable the overlay view subscribes to. */
|
|
@@ -20,8 +22,8 @@ export interface PickerStore {
|
|
|
20
22
|
readonly getSnapshot: () => PickerSnapshot
|
|
21
23
|
/** @param listener - called after every change. @returns the unsubscribe. */
|
|
22
24
|
readonly subscribe: (listener: () => void) => () => void
|
|
23
|
-
/**
|
|
24
|
-
readonly open: (sessionId: string) => void
|
|
25
|
+
/** Open the picker for one session, optionally returning focus to its toolbar button. */
|
|
26
|
+
readonly open: (sessionId: string, returnFocus?: HTMLButtonElement) => void
|
|
25
27
|
/** Close whatever is open. */
|
|
26
28
|
readonly close: () => void
|
|
27
29
|
}
|
|
@@ -45,8 +47,8 @@ export function createPickerStore(): PickerStore {
|
|
|
45
47
|
listeners.delete(listener);
|
|
46
48
|
};
|
|
47
49
|
},
|
|
48
|
-
open: (sessionId) => {
|
|
49
|
-
publish({ sessionId });
|
|
50
|
+
open: (sessionId, returnFocus) => {
|
|
51
|
+
publish(returnFocus === undefined ? { sessionId } : { sessionId, returnFocus });
|
|
50
52
|
},
|
|
51
53
|
close: () => {
|
|
52
54
|
publish({ sessionId: null });
|