@lynn123411/dsh-model-submenu 0.3.17 → 0.3.19
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 +10 -9
- package/cordis.patch.yml +0 -1
- package/lib/client.js +310 -477
- package/lib/client.js.map +1 -1
- package/lib/index.js +0 -1
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/src/client/EffortSlider.tsx +0 -49
- package/src/client/EffortTint.tsx +0 -21
- package/src/client/ModelMenuBridge.tsx +60 -46
- package/src/client/ModelOptions.module.css +98 -51
- package/src/client/ModelPicker.tsx +1 -32
- package/src/client/ModelPickerHost.tsx +1 -36
- package/src/client/ModelRow.tsx +0 -23
- package/src/client/QuickModels.tsx +114 -0
- package/src/client/effort-memory.ts +0 -32
- package/src/client/facts-source.ts +2 -25
- package/src/client/favorites.ts +8 -39
- package/src/client/icons.tsx +0 -14
- package/src/client/index.ts +8 -34
- package/src/client/level-color.ts +0 -27
- package/src/client/locales.ts +9 -6
- package/src/client/model-facts.ts +1 -63
- package/src/client/picker-state.ts +0 -20
- package/src/client/rows.ts +0 -37
- package/src/client/selection.ts +0 -59
- package/src/client/slider.ts +0 -58
- package/src/index.ts +0 -1
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The model picker: the centered dialog opened from the menu's model row.
|
|
3
|
-
*
|
|
4
|
-
* It is the one place every provider is visible at once — a search field, a tab
|
|
5
|
-
* per provider with a model, and one flat list with each model's metadata line.
|
|
6
|
-
* Favorites lead the list and can be toggled from a row's star without
|
|
7
|
-
* selecting that row. A click commits at once; a rejected commit keeps the
|
|
8
|
-
* dialog open so the user can retry or pick another model.
|
|
9
|
-
*/
|
|
10
1
|
|
|
11
2
|
import { useEffect, useId, useMemo, useRef, useState } from 'react'
|
|
12
3
|
import {
|
|
@@ -37,44 +28,21 @@ import type { Selection } from './selection.ts'
|
|
|
37
28
|
import { planModelCommit } from './selection.ts'
|
|
38
29
|
import css from './ModelOptions.module.css'
|
|
39
30
|
|
|
40
|
-
/** Props the seat hands the picker. */
|
|
41
31
|
export interface ModelPickerProps {
|
|
42
|
-
/** Whether the dialog is showing. */
|
|
43
32
|
readonly open: boolean
|
|
44
|
-
/** Resolve a catalog badge's localized text for the active language. */
|
|
45
33
|
readonly resolveText: (text: NonNullable<CatalogModel['badge']>['text']) => string
|
|
46
|
-
/** The shared directory snapshot. */
|
|
47
34
|
readonly state: ModelDirectoryState
|
|
48
|
-
/** The selection in force, null before a first selection resolves. */
|
|
49
35
|
readonly live: Selection | null
|
|
50
|
-
/** The metadata lookup for the current settings answer. */
|
|
51
36
|
readonly facts: ModelFactsLookup
|
|
52
|
-
/** The favorite table right now. */
|
|
53
37
|
readonly favorites: readonly { readonly provider: string; readonly model: string }[]
|
|
54
|
-
/** Whether a selection is in flight. */
|
|
55
38
|
readonly busy: boolean
|
|
56
|
-
/**
|
|
57
|
-
* The reasoning level this browser last used for one model, if any.
|
|
58
|
-
* @param provider - the provider route key.
|
|
59
|
-
* @param model - the model id inside that provider.
|
|
60
|
-
* @returns the remembered level, or undefined when none is remembered.
|
|
61
|
-
*/
|
|
62
39
|
readonly rememberedOf?: (provider: string, model: string) => string | undefined
|
|
63
|
-
/** Submit one selection. */
|
|
64
40
|
readonly onPick: (selection: Selection) => void
|
|
65
|
-
/** Toggle one model's favorite. */
|
|
66
41
|
readonly onToggleFavorite: (provider: string, model: string) => void
|
|
67
|
-
/** Reload the catalog after a failure. */
|
|
68
42
|
readonly onReload: () => void
|
|
69
|
-
/** Close the dialog, optionally returning focus. */
|
|
70
43
|
readonly onClose: () => void
|
|
71
44
|
}
|
|
72
45
|
|
|
73
|
-
/**
|
|
74
|
-
* Render the picker.
|
|
75
|
-
* @param props - the catalog, the live selection, and the picker's verbs.
|
|
76
|
-
* @returns the dialog; nothing while closed.
|
|
77
|
-
*/
|
|
78
46
|
export function ModelPicker({
|
|
79
47
|
open, resolveText, state, live, facts, favorites, busy, rememberedOf, onPick, onToggleFavorite, onReload, onClose, t,
|
|
80
48
|
}: ModelPickerProps & PropsLocale<'modelSubmenu'>) {
|
|
@@ -204,6 +172,7 @@ export function ModelPicker({
|
|
|
204
172
|
<ShortcutKeys keys={['Esc']} />
|
|
205
173
|
<span>{t('picker.hintClose')}</span>
|
|
206
174
|
</span>
|
|
175
|
+
<span className={css.footerFavorites}>{t('picker.hintFavorites')}</span>
|
|
207
176
|
</div>
|
|
208
177
|
</Modal>
|
|
209
178
|
)
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The composer overlay's picker view: the dialog, its catalog, and its verbs.
|
|
3
|
-
*
|
|
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
|
-
*/
|
|
8
1
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
9
2
|
import { Button, IconWarningOutlineRegular, Toast } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
10
3
|
import type { ModelSelectInjected } from '@deepseek-ai/dsh-client-ui-model-selection/client';
|
|
@@ -13,9 +6,9 @@ import { ModelPicker } from './ModelPicker.tsx';
|
|
|
13
6
|
import type { FactsSource } from './facts-source.ts';
|
|
14
7
|
import {
|
|
15
8
|
readFavorites,
|
|
9
|
+
storageOf,
|
|
16
10
|
toggleFavorite,
|
|
17
11
|
type FavoriteModel,
|
|
18
|
-
type FavoritesStorage,
|
|
19
12
|
} from './favorites.ts';
|
|
20
13
|
import {
|
|
21
14
|
effortFor,
|
|
@@ -27,23 +20,14 @@ import { currentCatalogModel, selectionOf, type Selection } from './selection.ts
|
|
|
27
20
|
import type { PickerStore } from './picker-state.ts';
|
|
28
21
|
import css from './ModelOptions.module.css';
|
|
29
22
|
|
|
30
|
-
/** Props of the overlay view: the session, the store, and the seat's injected face. */
|
|
31
23
|
export type ModelPickerHostProps = PropsLocale<'modelSubmenu'>
|
|
32
24
|
& ModelSelectInjected
|
|
33
25
|
& {
|
|
34
|
-
/** Session whose catalog this view renders. */
|
|
35
26
|
readonly sessionId: string;
|
|
36
|
-
/** The request written by the menu row. */
|
|
37
27
|
readonly picker: PickerStore;
|
|
38
|
-
/** The settings-derived metadata the picker's line reads. */
|
|
39
28
|
readonly factsSource: FactsSource;
|
|
40
29
|
}
|
|
41
30
|
|
|
42
|
-
/**
|
|
43
|
-
* Render the picker for this session.
|
|
44
|
-
* @param props - session, store, catalog face, and localized copy.
|
|
45
|
-
* @returns the dialog while the store names this session; otherwise nothing.
|
|
46
|
-
*/
|
|
47
31
|
export function ModelPickerHost({
|
|
48
32
|
sessionId, picker, available, directory, load, select, resolveText, factsSource, t,
|
|
49
33
|
}: ModelPickerHostProps) {
|
|
@@ -68,22 +52,13 @@ export function ModelPickerHost({
|
|
|
68
52
|
}
|
|
69
53
|
};
|
|
70
54
|
}, [open, picker, request]);
|
|
71
|
-
// The injected face is cached per entry and session, but the read goes through
|
|
72
|
-
// a ref anyway: a catalog load writes the store, so an unstable `load` in the
|
|
73
|
-
// dependency list would reload on every render it caused.
|
|
74
55
|
const loadRef = useRef(load);
|
|
75
56
|
loadRef.current = load;
|
|
76
57
|
|
|
77
|
-
// Opening reads the catalog again: another client may have changed it, and a
|
|
78
|
-
// failed load has to be retryable from the same gesture.
|
|
79
58
|
useEffect(() => {
|
|
80
59
|
if (open) loadRef.current();
|
|
81
60
|
}, [open]);
|
|
82
61
|
|
|
83
|
-
// The Host's own menu changes the reasoning level without passing through this
|
|
84
|
-
// plugin, so the memory is written from the directory snapshot too — a picker
|
|
85
|
-
// click alone would only ever record levels chosen in the dialog. The key guard
|
|
86
|
-
// keeps one write per distinct selection instead of one per snapshot.
|
|
87
62
|
const current = state.current;
|
|
88
63
|
const rememberedRef = useRef<string | null>(null);
|
|
89
64
|
useEffect(() => {
|
|
@@ -147,7 +122,6 @@ export function ModelPickerHost({
|
|
|
147
122
|
</div>;
|
|
148
123
|
}
|
|
149
124
|
|
|
150
|
-
/** The Host skips the root menu when the current model is absent from its catalog. */
|
|
151
125
|
export function ModelPickerFallback({ sessionId, picker, available, directory, t }: Pick<
|
|
152
126
|
ModelPickerHostProps, 'sessionId' | 'picker' | 'available' | 'directory' | 't'
|
|
153
127
|
>) {
|
|
@@ -160,12 +134,3 @@ export function ModelPickerFallback({ sessionId, picker, available, directory, t
|
|
|
160
134
|
{t('picker.browse')}
|
|
161
135
|
</Button>;
|
|
162
136
|
}
|
|
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
|
-
}
|
package/src/client/ModelRow.tsx
CHANGED
|
@@ -1,45 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One pickable model in the picker.
|
|
3
|
-
*
|
|
4
|
-
* The star is its own control, because favouriting there must not switch the
|
|
5
|
-
* model: the row button picks, the star toggles, and the check marks the model
|
|
6
|
-
* in use.
|
|
7
|
-
*/
|
|
8
1
|
|
|
9
2
|
import type { ReactNode } from 'react';
|
|
10
3
|
import { IconCheckOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
11
4
|
import { StarIcon } from './icons.tsx';
|
|
12
5
|
import css from './ModelOptions.module.css';
|
|
13
6
|
|
|
14
|
-
/** Props of one row. */
|
|
15
7
|
export interface ModelRowProps {
|
|
16
|
-
/** The model's catalog name. */
|
|
17
8
|
readonly name: string;
|
|
18
|
-
/** Optional catalog badge shown beside the name. */
|
|
19
9
|
readonly badge?: ReactNode | undefined;
|
|
20
|
-
/** Whether this row is the model in use. */
|
|
21
10
|
readonly selected: boolean;
|
|
22
|
-
/** Whether a selection is in flight, which locks the row. */
|
|
23
11
|
readonly busy: boolean;
|
|
24
|
-
/** Whether the model is favorited right now. */
|
|
25
12
|
readonly favorited: boolean;
|
|
26
|
-
/** The metadata line's text. */
|
|
27
13
|
readonly meta?: string | undefined;
|
|
28
|
-
/** Localized accessible name for the star control. */
|
|
29
14
|
readonly starLabel?: string | undefined;
|
|
30
|
-
/** Pick this row. */
|
|
31
15
|
readonly onPick: () => void;
|
|
32
|
-
/** Toggle this row's favorite. */
|
|
33
16
|
readonly onToggleFavorite: () => void;
|
|
34
|
-
/** Extra row content, such as the picker's disabled reason. */
|
|
35
17
|
readonly children?: ReactNode;
|
|
36
18
|
}
|
|
37
19
|
|
|
38
|
-
/**
|
|
39
|
-
* Render one model row.
|
|
40
|
-
* @param props - the row's content and behaviour.
|
|
41
|
-
* @returns the row element.
|
|
42
|
-
*/
|
|
43
20
|
export function ModelRow({
|
|
44
21
|
name, badge, selected, busy, favorited, meta, starLabel,
|
|
45
22
|
onPick, onToggleFavorite, children,
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState, useSyncExternalStore, type KeyboardEvent } from 'react'
|
|
2
|
+
import { IconCheckOutlineRegular, IconChevronRightOutlineRegular, 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 type { PickerStore } from './picker-state.ts'
|
|
8
|
+
import { planModelCommit, sameModel, selectionOf } from './selection.ts'
|
|
9
|
+
import type { CatalogModel } from './rows.ts'
|
|
10
|
+
import css from './ModelOptions.module.css'
|
|
11
|
+
|
|
12
|
+
export const QUICK_MODELS_PANE = 'lynn-quick-models'
|
|
13
|
+
|
|
14
|
+
function confirmOnTab(event: KeyboardEvent<HTMLButtonElement>): void {
|
|
15
|
+
if (event.key !== 'Tab' || event.shiftKey || event.nativeEvent.isComposing) return
|
|
16
|
+
event.preventDefault()
|
|
17
|
+
event.stopPropagation()
|
|
18
|
+
event.currentTarget.click()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type QuickModelsProps = PropsRuntime<'conversation.input.model.pane'>
|
|
22
|
+
& PropsLocale<'modelSubmenu'>
|
|
23
|
+
& Pick<ModelSelectInjected, 'directory' | 'resolveText' | 'select'>
|
|
24
|
+
& {
|
|
25
|
+
readonly sessionId: string
|
|
26
|
+
readonly picker: PickerStore
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function QuickModels({ sessionId, picker, locked, dismiss, reportFailure, directory, resolveText, select, t }: QuickModelsProps) {
|
|
30
|
+
const state = useSyncExternalStore<ModelDirectoryState>((listener) => directory.subscribe(listener), () => directory.getSnapshot())
|
|
31
|
+
const [favorites] = useState(() => readFavorites(storageOf()))
|
|
32
|
+
const open = useRef(false)
|
|
33
|
+
useLayoutEffect(() => {
|
|
34
|
+
open.current = true
|
|
35
|
+
return () => { open.current = false }
|
|
36
|
+
}, [])
|
|
37
|
+
|
|
38
|
+
const live = selectionOf(state)
|
|
39
|
+
const busy = locked || state.pending !== null
|
|
40
|
+
const groups = state.groups.flatMap((group) => {
|
|
41
|
+
const models = group.models.filter((model) =>
|
|
42
|
+
(live !== null && sameModel(live, group.id, model.id)) || isFavorite(favorites, group.id, model.id))
|
|
43
|
+
return models.length === 0 ? [] : [{ ...group, models }]
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const choose = async (provider: string, model: CatalogModel): Promise<void> => {
|
|
47
|
+
if (busy || directory.getSnapshot().pending !== null) return
|
|
48
|
+
const remembered = effortFor(readEfforts(storageOf()), provider, model.id)
|
|
49
|
+
const selection = planModelCommit(live, provider, model.id, () => model.reasoning, remembered)
|
|
50
|
+
if (selection === null) {
|
|
51
|
+
dismiss()
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
const result = await select(selection)
|
|
55
|
+
if (result === undefined) return
|
|
56
|
+
if (result.ok) {
|
|
57
|
+
if (open.current) dismiss()
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
reportFailure(result.error.code === 'session/writer-held'
|
|
61
|
+
? t('error.sessionInUse')
|
|
62
|
+
: t('error.action', { message: `${result.error.code}: ${result.error.message}` }))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return <div role="menu" aria-label={t('picker.quick')} aria-busy={busy}>
|
|
66
|
+
{groups.length === 0 && <div className={css.notice} role="status">
|
|
67
|
+
{t(state.status === 'loading' ? 'status.loading' : 'status.empty')}
|
|
68
|
+
</div>}
|
|
69
|
+
{groups.map((group) => <MenuGroup key={group.id} label={group.name}>
|
|
70
|
+
{group.models.map((model) => {
|
|
71
|
+
const selected = live !== null && sameModel(live, group.id, model.id)
|
|
72
|
+
const pending = state.pending !== null && sameModel(state.pending, group.id, model.id)
|
|
73
|
+
return <button
|
|
74
|
+
key={model.id}
|
|
75
|
+
type="button"
|
|
76
|
+
role="menuitemradio"
|
|
77
|
+
aria-checked={selected}
|
|
78
|
+
aria-disabled={busy}
|
|
79
|
+
autoFocus={selected}
|
|
80
|
+
className={css.quickOption}
|
|
81
|
+
title={model.name}
|
|
82
|
+
onClick={() => { void choose(group.id, model) }}
|
|
83
|
+
onKeyDown={confirmOnTab}
|
|
84
|
+
>
|
|
85
|
+
<span className={css.quickCopy}>
|
|
86
|
+
<span className={css.quickName}>{model.name}</span>
|
|
87
|
+
{model.badge !== undefined && <Tag className={css.quickBadge} tone={model.badge.tone}>{resolveText(model.badge.text)}</Tag>}
|
|
88
|
+
</span>
|
|
89
|
+
<span className={css.quickCheck} aria-hidden="true">
|
|
90
|
+
{pending ? <StateDot state="ongoing" /> : selected && <IconCheckOutlineRegular size={14} />}
|
|
91
|
+
</span>
|
|
92
|
+
</button>
|
|
93
|
+
})}
|
|
94
|
+
</MenuGroup>)}
|
|
95
|
+
<div className={css.quickFooter}>
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
role="menuitem"
|
|
99
|
+
aria-haspopup="dialog"
|
|
100
|
+
className={css.quickOption}
|
|
101
|
+
disabled={busy}
|
|
102
|
+
onClick={() => {
|
|
103
|
+
if (busy || directory.getSnapshot().pending !== null) return
|
|
104
|
+
dismiss()
|
|
105
|
+
picker.open(sessionId)
|
|
106
|
+
}}
|
|
107
|
+
onKeyDown={confirmOnTab}
|
|
108
|
+
>
|
|
109
|
+
<span className={css.quickCopy}>{t('picker.browseAll')}</span>
|
|
110
|
+
<IconChevronRightOutlineRegular size={12} />
|
|
111
|
+
</button>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
}
|
|
@@ -1,31 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The per-model reasoning level this browser last chose.
|
|
3
|
-
*
|
|
4
|
-
* The Host stores one level per session, so switching models away and back
|
|
5
|
-
* forgets what was picked for the first one. This module keeps that memory
|
|
6
|
-
* beside the favorite table, keyed the same way: provider route key plus model
|
|
7
|
-
* id. Remembering the provider default removes the row, so "follow the
|
|
8
|
-
* provider" stays distinguishable from "remembered a level".
|
|
9
|
-
*/
|
|
10
1
|
|
|
11
|
-
/** One remembered reasoning level. */
|
|
12
2
|
export interface RememberedEffort {
|
|
13
3
|
readonly provider: string
|
|
14
4
|
readonly model: string
|
|
15
5
|
readonly effort: string
|
|
16
6
|
}
|
|
17
7
|
|
|
18
|
-
/** The single browser-wide storage key holding the whole memory. */
|
|
19
8
|
export const EFFORTS_KEY = 'dsh-model-submenu.efforts'
|
|
20
9
|
|
|
21
|
-
/** The part of `Storage` this module uses; absent or throwing reads mean "none". */
|
|
22
10
|
export type EffortStorage = Pick<Storage, 'getItem' | 'setItem'>
|
|
23
11
|
|
|
24
|
-
/**
|
|
25
|
-
* Read the memory, keeping only rows naming both halves and a level.
|
|
26
|
-
* @param storage - browser storage, or undefined when the browser withholds it.
|
|
27
|
-
* @returns the remembered rows; empty when unreadable.
|
|
28
|
-
*/
|
|
29
12
|
export function readEfforts(storage: EffortStorage | undefined): RememberedEffort[] {
|
|
30
13
|
const raw = getItem(storage)
|
|
31
14
|
if (raw === null) return []
|
|
@@ -43,12 +26,6 @@ export function readEfforts(storage: EffortStorage | undefined): RememberedEffor
|
|
|
43
26
|
&& (row as RememberedEffort).effort !== '')
|
|
44
27
|
}
|
|
45
28
|
|
|
46
|
-
/**
|
|
47
|
-
* @param memory - the rows to search.
|
|
48
|
-
* @param provider - the provider route key.
|
|
49
|
-
* @param model - the model id inside that provider.
|
|
50
|
-
* @returns the level last chosen for that exact model, or undefined.
|
|
51
|
-
*/
|
|
52
29
|
export function effortFor(
|
|
53
30
|
memory: readonly RememberedEffort[],
|
|
54
31
|
provider: string,
|
|
@@ -57,14 +34,6 @@ export function effortFor(
|
|
|
57
34
|
return memory.find((row) => row.provider === provider && row.model === model)?.effort
|
|
58
35
|
}
|
|
59
36
|
|
|
60
|
-
/**
|
|
61
|
-
* Remember one model's level, or forget it when the choice is the provider default.
|
|
62
|
-
* @param storage - browser storage, or undefined when writes are unavailable.
|
|
63
|
-
* @param provider - the provider route key.
|
|
64
|
-
* @param model - the model id inside that provider.
|
|
65
|
-
* @param effort - the chosen level, undefined meaning the provider default.
|
|
66
|
-
* @returns the memory after the change, whether or not the write landed.
|
|
67
|
-
*/
|
|
68
37
|
export function rememberEffort(
|
|
69
38
|
storage: EffortStorage | undefined,
|
|
70
39
|
provider: string,
|
|
@@ -76,7 +45,6 @@ export function rememberEffort(
|
|
|
76
45
|
try {
|
|
77
46
|
storage?.setItem(EFFORTS_KEY, JSON.stringify(next))
|
|
78
47
|
} catch {
|
|
79
|
-
// A full quota or a locked-down browser loses the memory, not the menu.
|
|
80
48
|
}
|
|
81
49
|
return next
|
|
82
50
|
}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The browser's live answer to "what does the settings document know about this
|
|
3
|
-
* model?".
|
|
4
|
-
*
|
|
5
|
-
* Two host answers meet here: the shared settings mirror (which the settings
|
|
6
|
-
* page already keeps warm) and the LLM provider directory that says which
|
|
7
|
-
* settings namespace holds each provider's profile. Both can change while the
|
|
8
|
-
* page is open — a saved profile, a reconnected host — so the join is rebuilt
|
|
9
|
-
* whenever the mirror or the directory reports a change, and readers subscribe
|
|
10
|
-
* to the lookup itself.
|
|
11
|
-
*/
|
|
12
1
|
|
|
13
2
|
import type { ModelFacts } from './model-facts.ts'
|
|
14
3
|
import {
|
|
@@ -17,38 +6,26 @@ import {
|
|
|
17
6
|
type NamespaceRow,
|
|
18
7
|
} from './model-facts.ts'
|
|
19
8
|
|
|
20
|
-
/** One lookup answering both metadata fields for a provider and model. */
|
|
21
9
|
export type ModelFactsLookup = (provider: string, model: string) => ModelFacts
|
|
22
10
|
|
|
23
|
-
/** The mirror face this source reads; a subset of the settings provider's. */
|
|
24
11
|
export interface DescribeFace {
|
|
25
12
|
getSnapshot(): { readonly view: { readonly namespaces: readonly NamespaceRow[] } | undefined }
|
|
26
13
|
subscribe(listener: () => void): () => void
|
|
27
14
|
ensure(): Promise<void>
|
|
28
15
|
}
|
|
29
16
|
|
|
30
|
-
/** One remote answer, as the gateway returns it. */
|
|
31
17
|
export interface DirectoryAnswer {
|
|
32
18
|
readonly ok: boolean
|
|
33
19
|
readonly value?: readonly ConfigurableProviderRow[]
|
|
34
20
|
}
|
|
35
21
|
|
|
36
|
-
/** A stable, subscribable lookup over the current settings answer. */
|
|
37
22
|
export interface FactsSource {
|
|
38
|
-
/** @returns the lookup for the current answer; the identity changes on every rebuild. */
|
|
39
23
|
getSnapshot(): ModelFactsLookup
|
|
40
|
-
/** @param listener - called after each rebuild. @returns the disposer. */
|
|
41
24
|
subscribe(listener: () => void): () => void
|
|
42
25
|
}
|
|
43
26
|
|
|
44
27
|
const EMPTY: ModelFactsLookup = () => ({ contextWindow: undefined, images: 'unknown' })
|
|
45
28
|
|
|
46
|
-
/**
|
|
47
|
-
* Join the settings mirror with the provider directory.
|
|
48
|
-
* @param deps.describe - the settings mirror's describe face.
|
|
49
|
-
* @param deps.listProviders - reads the LLM provider directory once.
|
|
50
|
-
* @returns the source, plus `start` which wires both reads and returns its disposer.
|
|
51
|
-
*/
|
|
52
29
|
export function createFactsSource(deps: {
|
|
53
30
|
readonly describe: DescribeFace
|
|
54
31
|
readonly listProviders: () => Promise<DirectoryAnswer>
|
|
@@ -75,13 +52,13 @@ export function createFactsSource(deps: {
|
|
|
75
52
|
},
|
|
76
53
|
start: () => {
|
|
77
54
|
const off = deps.describe.subscribe(rebuild)
|
|
78
|
-
void deps.describe.ensure().catch(() => {
|
|
55
|
+
void deps.describe.ensure().catch(() => { })
|
|
79
56
|
void deps.listProviders().then(
|
|
80
57
|
(answer) => {
|
|
81
58
|
providers = answer.ok && answer.value !== undefined ? answer.value : []
|
|
82
59
|
rebuild()
|
|
83
60
|
},
|
|
84
|
-
() => {
|
|
61
|
+
() => { },
|
|
85
62
|
)
|
|
86
63
|
rebuild()
|
|
87
64
|
return () => {
|
package/src/client/favorites.ts
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The favorite-model table the picker keeps in the browser.
|
|
3
|
-
*
|
|
4
|
-
* One browser-wide key holds `{ provider, model }` rows: the provider route key
|
|
5
|
-
* and the model id are the catalog's own identity, so a favorite survives a
|
|
6
|
-
* display-name change and never collides across providers. A value that cannot
|
|
7
|
-
* be read or does not parse reads as an empty table — a privacy-mode browser or
|
|
8
|
-
* a hand-edited row must never keep the menu from opening. Rows whose provider
|
|
9
|
-
* leaves the catalog are kept, so restoring the provider restores the star.
|
|
10
|
-
*/
|
|
11
1
|
|
|
12
2
|
import type { ModelRef } from './rows.ts'
|
|
13
3
|
|
|
14
|
-
/** One favorited model, identified the way the catalog identifies it. */
|
|
15
4
|
export type FavoriteModel = ModelRef
|
|
16
5
|
|
|
17
|
-
/** The single browser-wide storage key holding the whole table. */
|
|
18
6
|
export const FAVORITES_KEY = 'dsh-model-submenu.favorites'
|
|
19
7
|
|
|
20
|
-
/** The part of `Storage` this module uses; absent or throwing reads mean "none". */
|
|
21
8
|
export type FavoritesStorage = Pick<Storage, 'getItem' | 'setItem'>
|
|
22
9
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
export function storageOf(): FavoritesStorage | undefined {
|
|
11
|
+
try {
|
|
12
|
+
return globalThis.localStorage
|
|
13
|
+
} catch {
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
28
18
|
export function readFavorites(storage: FavoritesStorage | undefined): FavoriteModel[] {
|
|
29
19
|
const raw = getItem(storage)
|
|
30
20
|
if (raw === null) return []
|
|
@@ -40,13 +30,6 @@ export function readFavorites(storage: FavoritesStorage | undefined): FavoriteMo
|
|
|
40
30
|
&& typeof (row as FavoriteModel).model === 'string')
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
/**
|
|
44
|
-
* Add or remove one model, writing the whole table back.
|
|
45
|
-
* @param storage - browser storage, or undefined when writes are unavailable.
|
|
46
|
-
* @param provider - the provider route key.
|
|
47
|
-
* @param model - the model id inside that provider.
|
|
48
|
-
* @returns the table after the change, whether or not the write landed.
|
|
49
|
-
*/
|
|
50
33
|
export function toggleFavorite(
|
|
51
34
|
storage: FavoritesStorage | undefined,
|
|
52
35
|
provider: string,
|
|
@@ -59,17 +42,10 @@ export function toggleFavorite(
|
|
|
59
42
|
try {
|
|
60
43
|
storage?.setItem(FAVORITES_KEY, JSON.stringify(next))
|
|
61
44
|
} catch {
|
|
62
|
-
// A full quota or a locked-down browser loses the star, not the menu.
|
|
63
45
|
}
|
|
64
46
|
return next
|
|
65
47
|
}
|
|
66
48
|
|
|
67
|
-
/**
|
|
68
|
-
* @param favorites - the table to search.
|
|
69
|
-
* @param provider - the provider route key.
|
|
70
|
-
* @param model - the model id inside that provider.
|
|
71
|
-
* @returns whether that exact pair is favorited.
|
|
72
|
-
*/
|
|
73
49
|
export function isFavorite(
|
|
74
50
|
favorites: readonly FavoriteModel[],
|
|
75
51
|
provider: string,
|
|
@@ -78,13 +54,6 @@ export function isFavorite(
|
|
|
78
54
|
return favorites.some((row) => row.provider === provider && row.model === model)
|
|
79
55
|
}
|
|
80
56
|
|
|
81
|
-
/**
|
|
82
|
-
* Stable-partition a catalog so favorited rows lead, each part keeping the
|
|
83
|
-
* catalog's own order.
|
|
84
|
-
* @param rows - the catalog in its display order.
|
|
85
|
-
* @param favorited - predicate answering whether one row is favorited.
|
|
86
|
-
* @returns a new list; the input order when nothing is favorited.
|
|
87
|
-
*/
|
|
88
57
|
export function orderWithFavorites<T>(
|
|
89
58
|
rows: readonly T[],
|
|
90
59
|
favorited: (row: T) => boolean,
|
package/src/client/icons.tsx
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one glyph this plugin draws itself.
|
|
3
|
-
*
|
|
4
|
-
* The shared icon library carries no star, so the favorite mark is defined here:
|
|
5
|
-
* a five-point star whose outline and fill use the same path, which keeps the
|
|
6
|
-
* hover-only outline and the standing filled state identical in geometry.
|
|
7
|
-
*/
|
|
8
1
|
|
|
9
|
-
/**
|
|
10
|
-
* Render the favorite star.
|
|
11
|
-
* @param props.filled - draw the solid star; otherwise the outline.
|
|
12
|
-
* @param props.size - square edge in pixels, matching the shared icon set's default.
|
|
13
|
-
* @param props.className - extra class for colour and placement.
|
|
14
|
-
* @returns the inline SVG.
|
|
15
|
-
*/
|
|
16
2
|
export function StarIcon({ filled, size = 14, className }: {
|
|
17
3
|
readonly filled: boolean
|
|
18
4
|
readonly size?: number | undefined
|
package/src/client/index.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
2
|
-
// Type-only: `slots` and its LocaleNamespaceMap merge come from the renderer and
|
|
3
|
-
// the slot package; the model menu's options slot and the composer overlay from
|
|
4
|
-
// ui-conversation; the `modelDirectories` service and the seat's injected face
|
|
5
|
-
// from ui-model-selection's browser half; `configForms` from the settings
|
|
6
|
-
// provider, whose shared mirror answers the metadata line.
|
|
7
2
|
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
8
3
|
import type {} from '@deepseek-ai/dsh-client-locale/client'
|
|
9
4
|
import type {} from '@deepseek-ai/dsh-api-remotes/client'
|
|
@@ -13,6 +8,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
|
13
8
|
import { EffortTint } from './EffortTint.tsx'
|
|
14
9
|
import { ModelMenuBridge } from './ModelMenuBridge.tsx'
|
|
15
10
|
import { ModelPickerFallback, ModelPickerHost } from './ModelPickerHost.tsx'
|
|
11
|
+
import { QUICK_MODELS_PANE, QuickModels } from './QuickModels.tsx'
|
|
16
12
|
import { createPickerStore } from './picker-state.ts'
|
|
17
13
|
import { createFactsSource, type DescribeFace } from './facts-source.ts'
|
|
18
14
|
import { NS, en, zh } from './locales.ts'
|
|
@@ -23,17 +19,6 @@ export { ModelMenuBridge } from './ModelMenuBridge.tsx'
|
|
|
23
19
|
export { ModelPickerHost } from './ModelPickerHost.tsx'
|
|
24
20
|
export { createPickerStore } from './picker-state.ts'
|
|
25
21
|
|
|
26
|
-
/**
|
|
27
|
-
* Cordis services required by the browser half. `slots` is the contribution
|
|
28
|
-
* registry, `sessions` tells whether a session may select a model,
|
|
29
|
-
* `modelDirectories` owns the per-session catalog snapshot both entries render
|
|
30
|
-
* from, and `configForms` carries the settings provider's shared describe
|
|
31
|
-
* mirror, which answers each model's context window and accepted modalities.
|
|
32
|
-
* `remote`, `remote.llm`, and `remote.session` are declared because a service
|
|
33
|
-
* method runs on the calling context: `directoryFor` reads
|
|
34
|
-
* `this.ctx.remote.session`, and the provider directory that names each
|
|
35
|
-
* settings address is read through `this.ctx.remote.llm`.
|
|
36
|
-
*/
|
|
37
22
|
export const inject = [
|
|
38
23
|
'configForms',
|
|
39
24
|
'locale',
|
|
@@ -45,15 +30,6 @@ export const inject = [
|
|
|
45
30
|
'slots',
|
|
46
31
|
]
|
|
47
32
|
|
|
48
|
-
/**
|
|
49
|
-
* Client plugin body: register this plugin's dictionaries, then contribute the
|
|
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
|
-
*
|
|
53
|
-
* The overlay stays mounted when the Host closes the model menu, allowing the
|
|
54
|
-
* picker to open after the menu has been removed.
|
|
55
|
-
* @param ctx - client root context.
|
|
56
|
-
*/
|
|
57
33
|
export function apply(ctx: ClientContext): void {
|
|
58
34
|
if (typeof document !== 'undefined') {
|
|
59
35
|
ctx.effect(() => {
|
|
@@ -75,14 +51,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
75
51
|
listProviders: () => scope.remote.llm.listConfigurableProviders(),
|
|
76
52
|
})
|
|
77
53
|
scope.effect(() => facts.start(), 'dsh-model-submenu: model metadata')
|
|
78
|
-
/**
|
|
79
|
-
* Build one entry's business face for a session.
|
|
80
|
-
* @param sessionId - the slot's session scope.
|
|
81
|
-
* @returns the catalog face plus the session and store both entries need.
|
|
82
|
-
*/
|
|
83
54
|
const faceOf = (sessionId: string) => {
|
|
84
|
-
// The slot's inject parameter is typed as a bare string; the service
|
|
85
|
-
// faces carry the branded SessionId of that same runtime value.
|
|
86
55
|
const key = sessionId as Parameters<typeof models.directoryFor>[0]
|
|
87
56
|
const directory = models.directoryFor(key)
|
|
88
57
|
const available = sessions.subagentAddress(key) === undefined
|
|
@@ -108,6 +77,13 @@ export function apply(ctx: ClientContext): void {
|
|
|
108
77
|
locale: NS,
|
|
109
78
|
inject: faceOf,
|
|
110
79
|
}, ModelMenuBridge))
|
|
80
|
+
scope.slots.inject('conversation.input.model.pane', () => scope.slots.register({
|
|
81
|
+
name: 'conversation.input.model.pane',
|
|
82
|
+
key: QUICK_MODELS_PANE,
|
|
83
|
+
registrant: '@lynn123411/dsh-model-submenu',
|
|
84
|
+
locale: NS,
|
|
85
|
+
inject: faceOf,
|
|
86
|
+
}, QuickModels))
|
|
111
87
|
scope.slots.inject('conversation.input.overlay', () => scope.slots.register({
|
|
112
88
|
name: 'conversation.input.overlay',
|
|
113
89
|
id: 'model-picker',
|
|
@@ -122,8 +98,6 @@ export function apply(ctx: ClientContext): void {
|
|
|
122
98
|
locale: NS,
|
|
123
99
|
inject: faceOf,
|
|
124
100
|
}, ModelPickerFallback))
|
|
125
|
-
// The trigger's effort caption lives outside the menu, so its tint needs an
|
|
126
|
-
// entry that stays mounted for the whole session.
|
|
127
101
|
scope.slots.inject('conversation.input.overlay', () => scope.slots.register({
|
|
128
102
|
name: 'conversation.input.overlay',
|
|
129
103
|
id: 'model-effort-tint',
|