@lynn123411/dsh-model-submenu 0.3.18 → 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.
@@ -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>();
@@ -1,49 +1,29 @@
1
- /**
2
- * Catalog flattening, tab derivation, and query matching for the picker.
3
- *
4
- * The model catalog groups models by provider; the picker shows one flat list
5
- * with a tab per provider. The shared text search index matches model and
6
- * provider names and IDs.
7
- */
8
1
 
9
2
  import type { ModelDirectoryState } from '@deepseek-ai/dsh-client-ui-model-selection/client'
10
3
  import { TextSearchIndex } from '@deepseek-ai/dsh-util-text-search'
11
4
 
12
- /** One provider group of the shared catalog. */
13
5
  export type ProviderGroup = ModelDirectoryState['groups'][number]
14
6
 
15
- /** One model inside a provider group. */
16
7
  export type CatalogModel = ProviderGroup['models'][number]
17
8
 
18
- /** One flat catalog row, carrying the provider identity beside the model. */
19
9
  export interface ModelRow extends ModelRef {
20
10
  readonly providerName: string
21
- /** The model id inside its provider, the other half of a selection. */
22
11
  readonly model: string
23
- /** The catalog entry itself, for name and reasoning metadata. */
24
12
  readonly entry: CatalogModel
25
13
  }
26
14
 
27
- /** A provider and one of its models: the pair every selection and favorite names. */
28
15
  export interface ModelRef {
29
16
  readonly provider: string
30
17
  readonly model: string
31
18
  }
32
19
 
33
- /** One picker tab. */
34
20
  export interface PickerTab {
35
21
  readonly id: string
36
22
  readonly label: string
37
23
  }
38
24
 
39
- /** The tab id standing for every provider. */
40
25
  export const ALL_TAB = '*'
41
26
 
42
- /**
43
- * Flatten the catalog to one row per model.
44
- * @param groups - the shared directory's provider groups, in display order.
45
- * @returns the rows in catalog order.
46
- */
47
27
  export function flattenGroups(groups: readonly ProviderGroup[]): readonly ModelRow[] {
48
28
  return groups.flatMap((group) => group.models.map((model) => ({
49
29
  provider: group.id,
@@ -53,12 +33,6 @@ export function flattenGroups(groups: readonly ProviderGroup[]): readonly ModelR
53
33
  })))
54
34
  }
55
35
 
56
- /**
57
- * Build the picker's tabs: the all-tab, then one per provider that has a model.
58
- * @param groups - the shared directory's provider groups.
59
- * @param allLabel - localized label for the all-tab.
60
- * @returns the tabs in catalog order.
61
- */
62
36
  export function pickerTabs(groups: readonly ProviderGroup[], allLabel = 'All'): readonly PickerTab[] {
63
37
  return [
64
38
  { id: ALL_TAB, label: allLabel },
@@ -66,27 +40,16 @@ export function pickerTabs(groups: readonly ProviderGroup[], allLabel = 'All'):
66
40
  ]
67
41
  }
68
42
 
69
- /**
70
- * @param rows - the flat catalog.
71
- * @param tab - the tab id; the all-tab keeps every row.
72
- * @returns the rows the tab shows, in their current order.
73
- */
74
43
  export function rowsForTab(rows: readonly ModelRow[], tab: string): readonly ModelRow[] {
75
44
  return tab === ALL_TAB ? rows : rows.filter((row) => row.provider === tab)
76
45
  }
77
46
 
78
- /** Build a reusable search index for the rows in the current provider tab. */
79
47
  export function createModelSearch(rows: readonly ModelRow[]): TextSearchIndex<ModelRow> {
80
48
  return new TextSearchIndex(rows, (row) => ({
81
49
  fuzzy: [row.entry.name, row.model, row.providerName, row.provider],
82
50
  }))
83
51
  }
84
52
 
85
- /**
86
- * Read the reasoning metadata the catalog advertises for one model.
87
- * @param groups - the shared directory's provider groups.
88
- * @returns the metadata, or undefined when that model advertises none.
89
- */
90
53
  export function reasoningOf(
91
54
  groups: readonly ProviderGroup[],
92
55
  ): (provider: string, model: string) => CatalogModel['reasoning'] {
@@ -1,39 +1,19 @@
1
- /**
2
- * When the composer menu writes a selection.
3
- *
4
- * Both gestures are immediate: clicking a level submits it, clicking a model
5
- * submits it. The only quiet path is clicking the model already in use — that
6
- * closes the menu without a write. A model click also restores the level this
7
- * browser last used for that model, so switching away and back never silently
8
- * resets the effort.
9
- */
10
1
 
11
2
  import type { ModelReasoning } from '@deepseek-ai/dsh-api-session-controller/types'
12
3
  import type { ModelDirectoryState } from '@deepseek-ai/dsh-client-ui-model-selection/client'
13
4
 
14
- /** One complete selection, as the directory's `select` takes it. */
15
5
  export interface Selection {
16
6
  readonly provider: string
17
7
  readonly model: string
18
8
  readonly reasoningEffort?: string
19
9
  }
20
10
 
21
- /** One segment of the reasoning row. */
22
11
  export interface EffortChoice {
23
12
  readonly key: string
24
13
  readonly effort: string | undefined
25
14
  readonly label: string
26
15
  }
27
16
 
28
- /**
29
- * Build the slider's detents for one model.
30
- *
31
- * The provider default is deliberately absent: it is a state, not a level, and
32
- * giving it a detent would read as the weakest reasoning instead of "let the
33
- * provider decide". The label above the track switches to it.
34
- * @param reasoning - the catalog's reasoning metadata, undefined when the model has none.
35
- * @returns one detent per advertised level, in catalog order.
36
- */
37
17
  export function effortChoices(reasoning: ModelReasoning | undefined): readonly EffortChoice[] {
38
18
  if (reasoning === undefined) return []
39
19
  return reasoning.efforts.map((level) => ({
@@ -43,12 +23,6 @@ export function effortChoices(reasoning: ModelReasoning | undefined): readonly E
43
23
  }))
44
24
  }
45
25
 
46
- /**
47
- * The selection a level click submits.
48
- * @param live - the selection in force right now.
49
- * @param effort - the clicked level, undefined meaning the provider default.
50
- * @returns the selection to submit, or null when the level already is the live one.
51
- */
52
26
  export function planEffortCommit(live: Selection, effort: string | undefined): Selection | null {
53
27
  if (sameEffort(live.reasoningEffort, effort)) return null
54
28
  return {
@@ -58,15 +32,6 @@ export function planEffortCommit(live: Selection, effort: string | undefined): S
58
32
  }
59
33
  }
60
34
 
61
- /**
62
- * The selection a model click submits.
63
- * @param live - the selection in force right now, null before a first selection resolves.
64
- * @param provider - the clicked model's provider.
65
- * @param model - the clicked model id.
66
- * @param reasoningOf - the catalog's reasoning metadata for one provider and model.
67
- * @param remembered - the level this browser last used for the target model, if any.
68
- * @returns the selection to submit, or null when the click changes nothing.
69
- */
70
35
  export function planModelCommit(
71
36
  live: Selection | null,
72
37
  provider: string,
@@ -76,8 +41,6 @@ export function planModelCommit(
76
41
  ): Selection | null {
77
42
  if (live !== null && sameModel(live, provider, model)) return null
78
43
  const offered = reasoningOf(provider, model)
79
- // The target model's own memory is restored, so switching away and back never
80
- // silently resets the effort.
81
44
  const carried = offered !== undefined
82
45
  && remembered !== undefined
83
46
  && offered.efforts.some((level) => level.id === remembered)
@@ -88,16 +51,10 @@ export function planModelCommit(
88
51
  }
89
52
  }
90
53
 
91
- /**
92
- * The reasoning metadata the catalog advertises for the model in force.
93
- * @param state - the session's directory snapshot.
94
- * @returns the metadata, or undefined when no model is live or it advertises none.
95
- */
96
54
  export function liveReasoning(state: ModelDirectoryState): ModelReasoning | undefined {
97
55
  return currentCatalogModel(state)?.reasoning
98
56
  }
99
57
 
100
- /** Find the current model by its provider and model IDs. */
101
58
  export function currentCatalogModel(state: ModelDirectoryState) {
102
59
  const current = state.current
103
60
  if (current === null) return undefined
@@ -106,11 +63,6 @@ export function currentCatalogModel(state: ModelDirectoryState) {
106
63
  ?.models.find((model) => model.id === current.model)
107
64
  }
108
65
 
109
- /**
110
- * The selection in force, or null while the Host has not resolved one.
111
- * @param state - the session's directory snapshot.
112
- * @returns the live selection, with the effort only when one is set.
113
- */
114
66
  export function selectionOf(state: ModelDirectoryState): Selection | null {
115
67
  if (state.current === null) return null
116
68
  return state.current.reasoningEffort === undefined
@@ -122,21 +74,10 @@ export function selectionOf(state: ModelDirectoryState): Selection | null {
122
74
  }
123
75
  }
124
76
 
125
- /**
126
- * @param live - one selection.
127
- * @param provider - the provider to compare.
128
- * @param model - the model id to compare.
129
- * @returns whether both name the same model.
130
- */
131
77
  export function sameModel(live: Selection, provider: string, model: string): boolean {
132
78
  return live.provider === provider && live.model === model
133
79
  }
134
80
 
135
- /**
136
- * @param liveEffort - the level in force, undefined meaning the provider default.
137
- * @param effort - the level in question.
138
- * @returns whether they name the same level.
139
- */
140
81
  export function sameEffort(liveEffort: string | undefined, effort: string | undefined): boolean {
141
82
  return liveEffort === effort
142
83
  }
@@ -1,48 +1,16 @@
1
- /**
2
- * Geometry of the discrete effort slider.
3
- *
4
- * The track is a capsule and the knob a slightly larger circle riding on it, so
5
- * the knob overhangs the track instead of merging with its rounded end. The
6
- * knob's centre travels between two points inset by the knob's radius, so the
7
- * knob never runs past either end. A pointer position becomes a position along
8
- * that travel; a position becomes the detent nearest it, or the CSS lengths that
9
- * put the knob and the fill there.
10
- */
11
1
 
12
- /**
13
- * Track height in CSS pixels; the stylesheet keeps the same value. Half of it is
14
- * the radius of the track's ends and of the fill's cap.
15
- */
16
2
  export const TRACK_HEIGHT = 16;
17
3
 
18
- /**
19
- * Knob diameter in CSS pixels. It is larger than the track, so the knob reads as
20
- * a knob riding on the track rather than as the track's own end cap.
21
- */
22
4
  export const KNOB_SIZE = 20;
23
5
 
24
- /** The knob's centre keeps its own radius away from either end of the track. */
25
6
  const KNOB_RADIUS = KNOB_SIZE / 2;
26
7
 
27
- /**
28
- * @param index - detent index.
29
- * @param count - number of detents.
30
- * @returns the knob centre as a fraction of the track, 0 at the first detent and 1 at the last.
31
- */
32
8
  export function offsetOf(index: number, count: number): number {
33
9
  if (count <= 1) return 0;
34
10
  const clamped = Math.min(Math.max(index, 0), count - 1);
35
11
  return clamped / (count - 1);
36
12
  }
37
13
 
38
- /**
39
- * Where a pointer sits along the knob's travel. The drag reads this rather than a
40
- * detent, so the knob follows the pointer instead of jumping a level at a time.
41
- * @param clientX - pointer position in viewport coordinates.
42
- * @param left - the track's left edge in viewport coordinates.
43
- * @param width - the track's width in pixels.
44
- * @returns the position as a fraction of the travel, clamped to 0 and 1.
45
- */
46
14
  export function fractionAt(clientX: number, left: number, width: number): number {
47
15
  const usable = width - KNOB_SIZE;
48
16
  if (usable <= 0) return 0;
@@ -50,48 +18,22 @@ export function fractionAt(clientX: number, left: number, width: number): number
50
18
  return Math.min(Math.max(fraction, 0), 1);
51
19
  }
52
20
 
53
- /**
54
- * @param fraction - a knob position between 0 and 1.
55
- * @param count - number of detents.
56
- * @returns the detent nearest that position.
57
- */
58
21
  export function detentAt(fraction: number, count: number): number {
59
22
  if (count <= 1) return 0;
60
23
  const clamped = Math.min(Math.max(fraction, 0), 1);
61
24
  return Math.round(clamped * (count - 1));
62
25
  }
63
26
 
64
- /**
65
- * @param clientX - pointer position in viewport coordinates.
66
- * @param left - the track's left edge in viewport coordinates.
67
- * @param width - the track's width in pixels.
68
- * @param count - number of detents.
69
- * @returns the detent nearest the pointer, clamped to the two ends.
70
- */
71
27
  export function stepAt(clientX: number, left: number, width: number, count: number): number {
72
28
  if (count <= 1) return 0;
73
29
  return detentAt(fractionAt(clientX, left, width), count);
74
30
  }
75
31
 
76
- /**
77
- * @param fraction - a knob position between 0 and 1.
78
- * @returns the CSS length that puts the knob centre there, inset at both ends.
79
- */
80
32
  export function knobOffset(fraction: number): string {
81
33
  const clamped = Math.min(Math.max(fraction, 0), 1);
82
34
  return `calc(${KNOB_RADIUS}px + ${clamped} * (100% - ${KNOB_SIZE}px))`;
83
35
  }
84
36
 
85
- /**
86
- * Width of the colored fill for a knob position.
87
- *
88
- * The fill is the track's own shape cut at the knob: its right cap carries the
89
- * track's radius and ends under the knob, so the color runs into the knob
90
- * instead of stopping at a straight edge, and the last detent reaches the track's
91
- * end rather than the knob's centre.
92
- * @param fraction - a knob position between 0 and 1.
93
- * @returns the CSS width of the fill.
94
- */
95
37
  export function fillWidth(fraction: number): string {
96
38
  const clamped = Math.min(Math.max(fraction, 0), 1);
97
39
  return `calc(${TRACK_HEIGHT}px + ${clamped} * (100% - ${TRACK_HEIGHT}px))`;
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
- /** Host entry. This plugin is client-only; the browser half is `./client`. */
2
1
  export function apply(): void {}