@lynn123411/dsh-model-submenu 0.3.18 → 0.3.20
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 +26 -71
- package/cordis.patch.yml +0 -1
- package/lib/client.js +385 -1000
- package/lib/client.js.map +1 -1
- package/lib/index.js +31 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +5 -3
- package/src/account-model-facts.ts +8 -0
- package/src/client/ModelMenuBridge.tsx +30 -182
- package/src/client/ModelOptions.module.css +21 -162
- package/src/client/ModelPicker.tsx +83 -113
- package/src/client/ModelPickerHost.tsx +0 -26
- package/src/client/ModelRow.tsx +0 -23
- package/src/client/QuickModels.tsx +34 -10
- package/src/client/effort-memory.ts +0 -32
- package/src/client/facts-source.ts +91 -46
- package/src/client/favorites.ts +0 -40
- package/src/client/icons.tsx +0 -14
- package/src/client/index.ts +13 -44
- package/src/client/locales.ts +3 -15
- package/src/client/model-facts.ts +16 -94
- package/src/client/picker-state.ts +0 -20
- package/src/client/rows.ts +0 -37
- package/src/client/selection.ts +0 -91
- package/src/index.ts +35 -2
- package/src/client/EffortSlider.tsx +0 -191
- package/src/client/EffortTint.tsx +0 -61
- package/src/client/level-color.ts +0 -51
- package/src/client/slider.ts +0 -98
|
@@ -1,15 +1,4 @@
|
|
|
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
|
+
import { ACCOUNT_FACTS_PATH, type AccountModelFacts } from '../account-model-facts.ts'
|
|
13
2
|
import type { ModelFacts } from './model-facts.ts'
|
|
14
3
|
import {
|
|
15
4
|
buildModelFacts,
|
|
@@ -17,53 +6,40 @@ 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>
|
|
55
|
-
|
|
32
|
+
readonly loadAccountModels?: (signal: AbortSignal) => Promise<readonly AccountModelFacts[]>
|
|
33
|
+
readonly subscribeInvalidation?: (listener: () => void) => () => void
|
|
34
|
+
}): {
|
|
35
|
+
readonly source: FactsSource
|
|
36
|
+
readonly start: () => () => void
|
|
37
|
+
readonly refresh: () => void
|
|
38
|
+
} {
|
|
56
39
|
const listeners = new Set<() => void>()
|
|
57
|
-
let providers: readonly ConfigurableProviderRow[] = []
|
|
58
40
|
let lookup: ModelFactsLookup = EMPTY
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const namespaces = deps.describe.getSnapshot().view?.namespaces ?? []
|
|
62
|
-
lookup = providers.length === 0 || namespaces.length === 0
|
|
63
|
-
? EMPTY
|
|
64
|
-
: buildModelFacts(providers, namespaces)
|
|
65
|
-
for (const listener of [...listeners]) listener()
|
|
66
|
-
}
|
|
41
|
+
let stop: (() => void) | undefined
|
|
42
|
+
let readOnDemand: (() => void) | undefined
|
|
67
43
|
|
|
68
44
|
return {
|
|
69
45
|
source: {
|
|
@@ -73,21 +49,90 @@ export function createFactsSource(deps: {
|
|
|
73
49
|
return () => { listeners.delete(listener) }
|
|
74
50
|
},
|
|
75
51
|
},
|
|
52
|
+
refresh: () => readOnDemand?.(),
|
|
76
53
|
start: () => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
stop?.()
|
|
55
|
+
const lifetime = new AbortController()
|
|
56
|
+
let providers: readonly ConfigurableProviderRow[] = []
|
|
57
|
+
let accountModels: readonly AccountModelFacts[] = []
|
|
58
|
+
let view = deps.describe.getSnapshot().view
|
|
59
|
+
let accountRequested = false
|
|
60
|
+
const rebuild = () => {
|
|
61
|
+
lookup = buildModelFacts(providers, view?.namespaces ?? [], accountModels)
|
|
62
|
+
for (const listener of [...listeners]) listener()
|
|
63
|
+
}
|
|
64
|
+
const readDirectory = refreshReader(lifetime.signal, async () => {
|
|
65
|
+
const answer = await deps.listProviders()
|
|
66
|
+
return answer.ok ? answer.value : undefined
|
|
67
|
+
}, (rows) => {
|
|
68
|
+
providers = rows
|
|
69
|
+
rebuild()
|
|
70
|
+
})
|
|
71
|
+
const readAccount = refreshReader(lifetime.signal, async () => deps.loadAccountModels?.(lifetime.signal), (rows) => {
|
|
72
|
+
accountModels = rows
|
|
73
|
+
rebuild()
|
|
74
|
+
})
|
|
75
|
+
const refresh = () => {
|
|
76
|
+
readDirectory()
|
|
77
|
+
if (accountRequested) readAccount()
|
|
78
|
+
}
|
|
79
|
+
const offDescribe = deps.describe.subscribe(() => {
|
|
80
|
+
const next = deps.describe.getSnapshot().view
|
|
81
|
+
if (next === view) return
|
|
82
|
+
view = next
|
|
83
|
+
rebuild()
|
|
84
|
+
refresh()
|
|
85
|
+
})
|
|
86
|
+
const offInvalidation = deps.subscribeInvalidation?.(refresh)
|
|
87
|
+
readOnDemand = () => {
|
|
88
|
+
accountRequested = true
|
|
89
|
+
refresh()
|
|
90
|
+
}
|
|
91
|
+
stop = () => {
|
|
92
|
+
if (lifetime.signal.aborted) return
|
|
93
|
+
lifetime.abort()
|
|
94
|
+
offDescribe()
|
|
95
|
+
offInvalidation?.()
|
|
89
96
|
listeners.clear()
|
|
97
|
+
readOnDemand = undefined
|
|
98
|
+
stop = undefined
|
|
90
99
|
}
|
|
100
|
+
rebuild()
|
|
101
|
+
refresh()
|
|
102
|
+
void deps.describe.ensure().catch(() => {})
|
|
103
|
+
return stop
|
|
91
104
|
},
|
|
92
105
|
}
|
|
93
106
|
}
|
|
107
|
+
|
|
108
|
+
function refreshReader<T>(signal: AbortSignal, read: () => Promise<T | undefined>, publish: (value: T) => void): () => void {
|
|
109
|
+
let reading = false
|
|
110
|
+
let queued = false
|
|
111
|
+
return () => {
|
|
112
|
+
if (signal.aborted) return
|
|
113
|
+
if (reading) {
|
|
114
|
+
queued = true
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
reading = true
|
|
118
|
+
void (async () => {
|
|
119
|
+
try {
|
|
120
|
+
do {
|
|
121
|
+
queued = false
|
|
122
|
+
const value = await read().catch(() => undefined)
|
|
123
|
+
if (!signal.aborted && !queued && value !== undefined) publish(value)
|
|
124
|
+
} while (!signal.aborted && queued)
|
|
125
|
+
} finally {
|
|
126
|
+
reading = false
|
|
127
|
+
}
|
|
128
|
+
})()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function readAccountModels(signal: AbortSignal): Promise<readonly AccountModelFacts[]> {
|
|
133
|
+
const response = await fetch(ACCOUNT_FACTS_PATH, { signal })
|
|
134
|
+
if (!response.ok) throw new Error(`Account model metadata unavailable (${response.status})`)
|
|
135
|
+
const rows: unknown = await response.json()
|
|
136
|
+
if (!Array.isArray(rows)) throw new Error('Invalid account model metadata')
|
|
137
|
+
return rows
|
|
138
|
+
}
|
package/src/client/favorites.ts
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
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
|
-
/** A browser can withhold access to localStorage itself. */
|
|
24
10
|
export function storageOf(): FavoritesStorage | undefined {
|
|
25
11
|
try {
|
|
26
12
|
return globalThis.localStorage
|
|
@@ -29,11 +15,6 @@ export function storageOf(): FavoritesStorage | undefined {
|
|
|
29
15
|
}
|
|
30
16
|
}
|
|
31
17
|
|
|
32
|
-
/**
|
|
33
|
-
* Read the table, keeping only rows that name both halves.
|
|
34
|
-
* @param storage - browser storage, or undefined when the browser withholds it.
|
|
35
|
-
* @returns the stored favorites in stored order; empty when unreadable.
|
|
36
|
-
*/
|
|
37
18
|
export function readFavorites(storage: FavoritesStorage | undefined): FavoriteModel[] {
|
|
38
19
|
const raw = getItem(storage)
|
|
39
20
|
if (raw === null) return []
|
|
@@ -49,13 +30,6 @@ export function readFavorites(storage: FavoritesStorage | undefined): FavoriteMo
|
|
|
49
30
|
&& typeof (row as FavoriteModel).model === 'string')
|
|
50
31
|
}
|
|
51
32
|
|
|
52
|
-
/**
|
|
53
|
-
* Add or remove one model, writing the whole table back.
|
|
54
|
-
* @param storage - browser storage, or undefined when writes are unavailable.
|
|
55
|
-
* @param provider - the provider route key.
|
|
56
|
-
* @param model - the model id inside that provider.
|
|
57
|
-
* @returns the table after the change, whether or not the write landed.
|
|
58
|
-
*/
|
|
59
33
|
export function toggleFavorite(
|
|
60
34
|
storage: FavoritesStorage | undefined,
|
|
61
35
|
provider: string,
|
|
@@ -68,17 +42,10 @@ export function toggleFavorite(
|
|
|
68
42
|
try {
|
|
69
43
|
storage?.setItem(FAVORITES_KEY, JSON.stringify(next))
|
|
70
44
|
} catch {
|
|
71
|
-
// A full quota or a locked-down browser loses the star, not the menu.
|
|
72
45
|
}
|
|
73
46
|
return next
|
|
74
47
|
}
|
|
75
48
|
|
|
76
|
-
/**
|
|
77
|
-
* @param favorites - the table to search.
|
|
78
|
-
* @param provider - the provider route key.
|
|
79
|
-
* @param model - the model id inside that provider.
|
|
80
|
-
* @returns whether that exact pair is favorited.
|
|
81
|
-
*/
|
|
82
49
|
export function isFavorite(
|
|
83
50
|
favorites: readonly FavoriteModel[],
|
|
84
51
|
provider: string,
|
|
@@ -87,13 +54,6 @@ export function isFavorite(
|
|
|
87
54
|
return favorites.some((row) => row.provider === provider && row.model === model)
|
|
88
55
|
}
|
|
89
56
|
|
|
90
|
-
/**
|
|
91
|
-
* Stable-partition a catalog so favorited rows lead, each part keeping the
|
|
92
|
-
* catalog's own order.
|
|
93
|
-
* @param rows - the catalog in its display order.
|
|
94
|
-
* @param favorited - predicate answering whether one row is favorited.
|
|
95
|
-
* @returns a new list; the input order when nothing is favorited.
|
|
96
|
-
*/
|
|
97
57
|
export function orderWithFavorites<T>(
|
|
98
58
|
rows: readonly T[],
|
|
99
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,40 +1,22 @@
|
|
|
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'
|
|
10
5
|
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
11
6
|
import type {} from '@deepseek-ai/dsh-client-ui-model-selection/client'
|
|
12
7
|
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
13
|
-
import { EffortTint } from './EffortTint.tsx'
|
|
14
8
|
import { ModelMenuBridge } from './ModelMenuBridge.tsx'
|
|
15
9
|
import { ModelPickerFallback, ModelPickerHost } from './ModelPickerHost.tsx'
|
|
16
10
|
import { QUICK_MODELS_PANE, QuickModels } from './QuickModels.tsx'
|
|
17
11
|
import { createPickerStore } from './picker-state.ts'
|
|
18
|
-
import { createFactsSource, type DescribeFace } from './facts-source.ts'
|
|
12
|
+
import { createFactsSource, readAccountModels, type DescribeFace } from './facts-source.ts'
|
|
19
13
|
import { NS, en, zh } from './locales.ts'
|
|
20
14
|
import { stylesheet } from './ModelOptions.module.css'
|
|
21
15
|
|
|
22
|
-
export { EffortTint } from './EffortTint.tsx'
|
|
23
16
|
export { ModelMenuBridge } from './ModelMenuBridge.tsx'
|
|
24
17
|
export { ModelPickerHost } from './ModelPickerHost.tsx'
|
|
25
18
|
export { createPickerStore } from './picker-state.ts'
|
|
26
19
|
|
|
27
|
-
/**
|
|
28
|
-
* Cordis services required by the browser half. `slots` is the contribution
|
|
29
|
-
* registry, `sessions` tells whether a session may select a model,
|
|
30
|
-
* `modelDirectories` owns the per-session catalog snapshot both entries render
|
|
31
|
-
* from, and `configForms` carries the settings provider's shared describe
|
|
32
|
-
* mirror, which answers each model's context window and accepted modalities.
|
|
33
|
-
* `remote`, `remote.llm`, and `remote.session` are declared because a service
|
|
34
|
-
* method runs on the calling context: `directoryFor` reads
|
|
35
|
-
* `this.ctx.remote.session`, and the provider directory that names each
|
|
36
|
-
* settings address is read through `this.ctx.remote.llm`.
|
|
37
|
-
*/
|
|
38
20
|
export const inject = [
|
|
39
21
|
'configForms',
|
|
40
22
|
'locale',
|
|
@@ -46,15 +28,6 @@ export const inject = [
|
|
|
46
28
|
'slots',
|
|
47
29
|
]
|
|
48
30
|
|
|
49
|
-
/**
|
|
50
|
-
* Client plugin body: register this plugin's dictionaries, then contribute the
|
|
51
|
-
* menu bridge, the toolbar entry for a missing current model, the picker
|
|
52
|
-
* overlay, and the tint for the collapsed trigger's effort caption.
|
|
53
|
-
*
|
|
54
|
-
* The overlay stays mounted when the Host closes the model menu, allowing the
|
|
55
|
-
* picker to open after the menu has been removed.
|
|
56
|
-
* @param ctx - client root context.
|
|
57
|
-
*/
|
|
58
31
|
export function apply(ctx: ClientContext): void {
|
|
59
32
|
if (typeof document !== 'undefined') {
|
|
60
33
|
ctx.effect(() => {
|
|
@@ -74,16 +47,18 @@ export function apply(ctx: ClientContext): void {
|
|
|
74
47
|
const facts = createFactsSource({
|
|
75
48
|
describe: scope.configForms.describe() as DescribeFace,
|
|
76
49
|
listProviders: () => scope.remote.llm.listConfigurableProviders(),
|
|
50
|
+
loadAccountModels: readAccountModels,
|
|
51
|
+
subscribeInvalidation: (listener) => {
|
|
52
|
+
const off = [
|
|
53
|
+
scope.on('connection/reset', listener),
|
|
54
|
+
scope.remote.$on('llm/adapters-updated', listener),
|
|
55
|
+
scope.remote.$on('llm/models-updated', listener),
|
|
56
|
+
]
|
|
57
|
+
return () => { for (const dispose of off) dispose() }
|
|
58
|
+
},
|
|
77
59
|
})
|
|
78
60
|
scope.effect(() => facts.start(), 'dsh-model-submenu: model metadata')
|
|
79
|
-
/**
|
|
80
|
-
* Build one entry's business face for a session.
|
|
81
|
-
* @param sessionId - the slot's session scope.
|
|
82
|
-
* @returns the catalog face plus the session and store both entries need.
|
|
83
|
-
*/
|
|
84
61
|
const faceOf = (sessionId: string) => {
|
|
85
|
-
// The slot's inject parameter is typed as a bare string; the service
|
|
86
|
-
// faces carry the branded SessionId of that same runtime value.
|
|
87
62
|
const key = sessionId as Parameters<typeof models.directoryFor>[0]
|
|
88
63
|
const directory = models.directoryFor(key)
|
|
89
64
|
const available = sessions.subagentAddress(key) === undefined
|
|
@@ -94,7 +69,9 @@ export function apply(ctx: ClientContext): void {
|
|
|
94
69
|
directory: directory.store,
|
|
95
70
|
factsSource: facts.source,
|
|
96
71
|
load: () => {
|
|
97
|
-
if (available)
|
|
72
|
+
if (!available) return
|
|
73
|
+
facts.refresh()
|
|
74
|
+
directory.load().catch(() => {})
|
|
98
75
|
},
|
|
99
76
|
resolveText: (text: Parameters<typeof ctx.locale.resolveText>[0]) => ctx.locale.resolveText(text),
|
|
100
77
|
select: (selection: Parameters<typeof directory.select>[0]) => available
|
|
@@ -130,13 +107,5 @@ export function apply(ctx: ClientContext): void {
|
|
|
130
107
|
locale: NS,
|
|
131
108
|
inject: faceOf,
|
|
132
109
|
}, ModelPickerFallback))
|
|
133
|
-
// The trigger's effort caption lives outside the menu, so its tint needs an
|
|
134
|
-
// entry that stays mounted for the whole session.
|
|
135
|
-
scope.slots.inject('conversation.input.overlay', () => scope.slots.register({
|
|
136
|
-
name: 'conversation.input.overlay',
|
|
137
|
-
id: 'model-effort-tint',
|
|
138
|
-
registrant: '@lynn123411/dsh-model-submenu',
|
|
139
|
-
inject: faceOf,
|
|
140
|
-
}, EffortTint))
|
|
141
110
|
})
|
|
142
111
|
}
|
package/src/client/locales.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
/** Locale bundles for the all-provider model picker. */
|
|
2
1
|
|
|
3
|
-
/** Dictionary namespace owned by this plugin. */
|
|
4
2
|
export const NS = 'modelSubmenu'
|
|
5
3
|
|
|
6
|
-
/** Locale keys the picker renders. */
|
|
7
4
|
export type ModelSubmenuLocaleKey =
|
|
8
5
|
| 'status.loading'
|
|
9
6
|
| 'status.empty'
|
|
@@ -23,20 +20,16 @@ export type ModelSubmenuLocaleKey =
|
|
|
23
20
|
| 'picker.favorite'
|
|
24
21
|
| 'picker.unfavorite'
|
|
25
22
|
| 'picker.hintClose'
|
|
23
|
+
| 'picker.hintFavorites'
|
|
26
24
|
| 'meta.effort'
|
|
27
25
|
| 'meta.images'
|
|
28
|
-
| 'effort.label'
|
|
29
|
-
| 'effort.providerDefault'
|
|
30
|
-
| 'effort.useDefault'
|
|
31
26
|
|
|
32
27
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
33
28
|
interface LocaleNamespaceMap {
|
|
34
|
-
/** The all-provider model picker's copy. */
|
|
35
29
|
modelSubmenu: ModelSubmenuLocaleKey
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
40
33
|
export const zh: Record<ModelSubmenuLocaleKey, string> = {
|
|
41
34
|
'status.loading': '正在加载模型…',
|
|
42
35
|
'status.empty': '没有可用的模型。',
|
|
@@ -56,14 +49,11 @@ export const zh: Record<ModelSubmenuLocaleKey, string> = {
|
|
|
56
49
|
'picker.favorite': '收藏 {model}',
|
|
57
50
|
'picker.unfavorite': '取消收藏 {model}',
|
|
58
51
|
'picker.hintClose': '关闭',
|
|
52
|
+
'picker.hintFavorites': '收藏的模型置顶,并加入快捷菜单',
|
|
59
53
|
'meta.effort': '思考',
|
|
60
54
|
'meta.images': '图片输入',
|
|
61
|
-
'effort.label': '推理等级',
|
|
62
|
-
'effort.providerDefault': 'Default',
|
|
63
|
-
'effort.useDefault': '切换为默认档位',
|
|
64
55
|
}
|
|
65
56
|
|
|
66
|
-
/** English dictionary, checked complete against the zh key set. */
|
|
67
57
|
export const en: Record<ModelSubmenuLocaleKey, string> = {
|
|
68
58
|
'status.loading': 'Loading models…',
|
|
69
59
|
'status.empty': 'No models available.',
|
|
@@ -83,9 +73,7 @@ export const en: Record<ModelSubmenuLocaleKey, string> = {
|
|
|
83
73
|
'picker.favorite': 'Favorite {model}',
|
|
84
74
|
'picker.unfavorite': 'Remove {model} from favorites',
|
|
85
75
|
'picker.hintClose': 'close',
|
|
76
|
+
'picker.hintFavorites': 'Favorites first, also in the quick menu',
|
|
86
77
|
'meta.effort': 'Effort',
|
|
87
78
|
'meta.images': 'Images',
|
|
88
|
-
'effort.label': 'Reasoning effort',
|
|
89
|
-
'effort.providerDefault': 'Default',
|
|
90
|
-
'effort.useDefault': 'Switch to the provider default',
|
|
91
79
|
}
|
|
@@ -1,64 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
* What the settings document knows about one model, for the picker's metadata
|
|
3
|
-
* line.
|
|
4
|
-
*
|
|
5
|
-
* The Host's model catalog carries only a name and a reasoning list; context
|
|
6
|
-
* window and accepted modalities live in each provider's settings profile,
|
|
7
|
-
* which the settings mirror already holds in the browser. This module joins
|
|
8
|
-
* the two by the identity both agree on: the catalog's provider route key and
|
|
9
|
-
* model id are exactly the settings profile's provider key and model id.
|
|
10
|
-
*
|
|
11
|
-
* Every field is answered independently. A provider whose profile lists no
|
|
12
|
-
* models (an OAuth route such as the Kimi subscription, or the account
|
|
13
|
-
* provider) answers `unknown` rather than guessing the route default, because
|
|
14
|
-
* the line's rule is to omit what cannot be asserted.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/** Accepted-modality answer for one model. */
|
|
18
|
-
export type ImageAnswer = 'yes' | 'no' | 'unknown'
|
|
1
|
+
import { ACCOUNT_PROVIDER, type AccountModelFacts } from '../account-model-facts.ts'
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
* The model knowledge a shipped adapter carries for its own account route.
|
|
22
|
-
*
|
|
23
|
-
* The account route has no `models` list on purpose: the account listing
|
|
24
|
-
* supplies the catalog and settings only carry per-model overrides. The same
|
|
25
|
-
* adapter family ships a default catalog for its API-key route, and the account
|
|
26
|
-
* route serves the same models, so those entries answer what the account
|
|
27
|
-
* profile cannot. Ids and facts mirror the adapter's own table.
|
|
28
|
-
*/
|
|
29
|
-
const FAMILY_DEFAULTS: Readonly<Record<string, readonly {
|
|
30
|
-
readonly id: string
|
|
31
|
-
readonly contextWindow: number
|
|
32
|
-
readonly images: boolean
|
|
33
|
-
}[]>> = {
|
|
34
|
-
'deepseek-account': [
|
|
35
|
-
{ id: 'deepseek-flash', contextWindow: 1_000_000, images: true },
|
|
36
|
-
{ id: 'deepseek-v4-pro', contextWindow: 1_000_000, images: false },
|
|
37
|
-
],
|
|
38
|
-
}
|
|
3
|
+
export type ImageAnswer = 'yes' | 'no' | 'unknown'
|
|
39
4
|
|
|
40
|
-
/** The metadata the settings document can answer for one model. */
|
|
41
5
|
export interface ModelFacts {
|
|
42
|
-
/** Exact advertised capacity, or undefined when the model declares none. */
|
|
43
6
|
readonly contextWindow: number | undefined
|
|
44
|
-
/** Whether the model accepts images; `unknown` means the document is silent. */
|
|
45
7
|
readonly images: ImageAnswer
|
|
46
8
|
}
|
|
47
9
|
|
|
48
|
-
/** One provider directory row, as the Host's LLM directory reports it. */
|
|
49
10
|
export interface ConfigurableProviderRow {
|
|
50
11
|
readonly provider: string
|
|
51
12
|
readonly settingsNs: string
|
|
52
13
|
readonly settingsPath: readonly string[]
|
|
53
14
|
}
|
|
54
15
|
|
|
55
|
-
/** One settings namespace view, as the describe answer carries it. */
|
|
56
16
|
export interface NamespaceRow {
|
|
57
17
|
readonly ns: string
|
|
58
18
|
readonly value: unknown
|
|
59
19
|
}
|
|
60
20
|
|
|
61
|
-
/** What one provider's profile may carry, across both adapter families. */
|
|
62
21
|
interface ProfileView {
|
|
63
22
|
readonly models?: readonly Record<string, unknown>[]
|
|
64
23
|
readonly defaultContextWindow?: unknown
|
|
@@ -67,17 +26,13 @@ interface ProfileView {
|
|
|
67
26
|
|
|
68
27
|
type Record_ = Record<string, unknown>
|
|
69
28
|
|
|
70
|
-
/**
|
|
71
|
-
* Build the fact lookup from the settings answer.
|
|
72
|
-
* @param providers - provider directory rows giving each route's settings address.
|
|
73
|
-
* @param namespaces - the describe answer's namespace views.
|
|
74
|
-
* @returns a lookup answering both fields for one provider and model.
|
|
75
|
-
*/
|
|
76
29
|
export function buildModelFacts(
|
|
77
30
|
providers: readonly ConfigurableProviderRow[],
|
|
78
31
|
namespaces: readonly NamespaceRow[],
|
|
32
|
+
accountModels: readonly AccountModelFacts[] = [],
|
|
79
33
|
): (provider: string, model: string) => ModelFacts {
|
|
80
34
|
const byName = new Map(namespaces.map((row) => [row.ns, row.value]))
|
|
35
|
+
const accountById = new Map(accountModels.map((model) => [model.id, model]))
|
|
81
36
|
const profiles = new Map<string, ProfileView>()
|
|
82
37
|
for (const row of providers) {
|
|
83
38
|
const section = byName.get(row.settingsNs)
|
|
@@ -86,42 +41,24 @@ export function buildModelFacts(
|
|
|
86
41
|
}
|
|
87
42
|
return (provider, model) => {
|
|
88
43
|
const profile = profiles.get(provider)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (profile !== undefined && entry !== undefined) {
|
|
93
|
-
const window = typeof entry.contextWindow === 'number' && entry.contextWindow > 0
|
|
94
|
-
? entry.contextWindow
|
|
95
|
-
: undefined
|
|
96
|
-
return { contextWindow: window, images: imageAnswer(entry, profile) }
|
|
44
|
+
if (profile !== undefined && Array.isArray(profile.models)) {
|
|
45
|
+
const entry = profile.models.find((candidate) => isRecord(candidate) && candidate.id === model)
|
|
46
|
+
if (entry !== undefined) return { contextWindow: contextWindow(entry.contextWindow), images: imageAnswer(entry, profile) }
|
|
97
47
|
}
|
|
98
|
-
// A route with no model list of its own (the account route) still serves its
|
|
99
|
-
// adapter family's models; a declared override there wins over the default.
|
|
100
48
|
const override = readOverride(profile, model)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
contextWindow: window,
|
|
107
|
-
images: Array.isArray(override.inputModalities) ? containsImage(override.inputModalities) : 'unknown',
|
|
108
|
-
}
|
|
49
|
+
const account = provider === ACCOUNT_PROVIDER ? accountById.get(model) : undefined
|
|
50
|
+
const modalities = Array.isArray(override?.inputModalities) ? override.inputModalities : account?.inputModalities
|
|
51
|
+
return {
|
|
52
|
+
contextWindow: contextWindow(override?.contextWindow) ?? contextWindow(account?.contextWindow),
|
|
53
|
+
images: modalities === undefined ? 'unknown' : containsImage(modalities),
|
|
109
54
|
}
|
|
110
|
-
const family = FAMILY_DEFAULTS[provider]?.find((candidate) => candidate.id === model)
|
|
111
|
-
return family === undefined
|
|
112
|
-
? { contextWindow: undefined, images: 'unknown' }
|
|
113
|
-
: { contextWindow: family.contextWindow, images: family.images ? 'yes' : 'no' }
|
|
114
55
|
}
|
|
115
56
|
}
|
|
116
57
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* names the field `inputModalities`, and leaving it out means text only. The
|
|
122
|
-
* pi-ai family names it `input`, and an empty or absent list defers to the
|
|
123
|
-
* route's `defaultInput`; with no route default the answer stays unknown.
|
|
124
|
-
*/
|
|
58
|
+
function contextWindow(value: unknown): number | undefined {
|
|
59
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
125
62
|
function imageAnswer(entry: Record_, profile: ProfileView): ImageAnswer {
|
|
126
63
|
if (Array.isArray(entry.inputModalities)) return containsImage(entry.inputModalities)
|
|
127
64
|
const defaultInput = Array.isArray(profile.defaultInput) ? profile.defaultInput : undefined
|
|
@@ -132,7 +69,6 @@ function imageAnswer(entry: Record_, profile: ProfileView): ImageAnswer {
|
|
|
132
69
|
return defaultInput === undefined ? 'no' : containsImage(defaultInput)
|
|
133
70
|
}
|
|
134
71
|
|
|
135
|
-
/** One model's declared override, when the route keeps a `modelOverrides` table. */
|
|
136
72
|
function readOverride(profile: ProfileView | undefined, model: string): Record_ | undefined {
|
|
137
73
|
const overrides = (profile as Record_ | undefined)?.modelOverrides
|
|
138
74
|
if (!isRecord(overrides)) return undefined
|
|
@@ -144,26 +80,12 @@ function containsImage(modalities: readonly unknown[]): ImageAnswer {
|
|
|
144
80
|
return modalities.includes('image') ? 'yes' : 'no'
|
|
145
81
|
}
|
|
146
82
|
|
|
147
|
-
/**
|
|
148
|
-
* Abbreviate one capacity the way the metadata line shows it.
|
|
149
|
-
* @param tokens - exact advertised capacity in tokens.
|
|
150
|
-
* @returns e.g. `1M ctx`, `1.5M ctx`, `272k ctx`, or `512 ctx` below a thousand.
|
|
151
|
-
*/
|
|
152
83
|
export function formatContextWindow(tokens: number): string {
|
|
153
84
|
if (tokens >= 1_000_000) return `${trimNumber(tokens / 1_000_000)}M ctx`
|
|
154
85
|
if (tokens >= 1_000) return `${Math.round(tokens / 1_000)}k ctx`
|
|
155
86
|
return `${tokens} ctx`
|
|
156
87
|
}
|
|
157
88
|
|
|
158
|
-
/**
|
|
159
|
-
* Build the metadata line's segments.
|
|
160
|
-
* @param input.providerName - the provider's display name, omitted inside that provider's own tab.
|
|
161
|
-
* @param input.facts - what the settings document answered.
|
|
162
|
-
* @param input.thinks - whether the catalog advertises reasoning levels for this model.
|
|
163
|
-
* @param input.effortLabel - the localized word for the reasoning segment.
|
|
164
|
-
* @param input.imageLabel - the localized word for the image segment.
|
|
165
|
-
* @returns the segments to join; an empty list means show no line.
|
|
166
|
-
*/
|
|
167
89
|
export function metaSegments(input: {
|
|
168
90
|
readonly providerName?: string
|
|
169
91
|
readonly facts: ModelFacts
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which session's picker is open.
|
|
3
|
-
*
|
|
4
|
-
* The row that asks for the picker lives inside the composer model menu, and the
|
|
5
|
-
* Host unmounts that menu the moment a row is clicked. The dialog lives in the
|
|
6
|
-
* composer's overlay slot, which stays mounted. One plugin-wide store carries the
|
|
7
|
-
* request across that unmount — the same split the Host's own command popups use
|
|
8
|
-
* between their controller and their overlay view.
|
|
9
|
-
*/
|
|
10
1
|
|
|
11
|
-
/** What the store publishes. */
|
|
12
2
|
export interface PickerSnapshot {
|
|
13
|
-
/** Session whose picker is open, or null when none is. */
|
|
14
3
|
readonly sessionId: string | null
|
|
15
|
-
/** Toolbar button to refocus after the dialog closes, when still present. */
|
|
16
4
|
readonly returnFocus?: HTMLButtonElement
|
|
17
5
|
}
|
|
18
6
|
|
|
19
|
-
/** Open and close verbs plus the observable the overlay view subscribes to. */
|
|
20
7
|
export interface PickerStore {
|
|
21
|
-
/** @returns the current request. */
|
|
22
8
|
readonly getSnapshot: () => PickerSnapshot
|
|
23
|
-
/** @param listener - called after every change. @returns the unsubscribe. */
|
|
24
9
|
readonly subscribe: (listener: () => void) => () => void
|
|
25
|
-
/** Open the picker for one session, optionally returning focus to its toolbar button. */
|
|
26
10
|
readonly open: (sessionId: string, returnFocus?: HTMLButtonElement) => void
|
|
27
|
-
/** Close whatever is open. */
|
|
28
11
|
readonly close: () => void
|
|
29
12
|
}
|
|
30
13
|
|
|
31
|
-
/**
|
|
32
|
-
* @returns a store that starts closed.
|
|
33
|
-
*/
|
|
34
14
|
export function createPickerStore(): PickerStore {
|
|
35
15
|
let snapshot: PickerSnapshot = { sessionId: null };
|
|
36
16
|
const listeners = new Set<() => void>();
|