@lynn123411/dsh-model-submenu 0.3.19 → 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.
@@ -1,4 +1,4 @@
1
-
1
+ import { ACCOUNT_FACTS_PATH, type AccountModelFacts } from '../account-model-facts.ts'
2
2
  import type { ModelFacts } from './model-facts.ts'
3
3
  import {
4
4
  buildModelFacts,
@@ -29,18 +29,17 @@ const EMPTY: ModelFactsLookup = () => ({ contextWindow: undefined, images: 'unkn
29
29
  export function createFactsSource(deps: {
30
30
  readonly describe: DescribeFace
31
31
  readonly listProviders: () => Promise<DirectoryAnswer>
32
- }): { readonly source: FactsSource; readonly start: () => () => void } {
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
+ } {
33
39
  const listeners = new Set<() => void>()
34
- let providers: readonly ConfigurableProviderRow[] = []
35
40
  let lookup: ModelFactsLookup = EMPTY
36
-
37
- const rebuild = () => {
38
- const namespaces = deps.describe.getSnapshot().view?.namespaces ?? []
39
- lookup = providers.length === 0 || namespaces.length === 0
40
- ? EMPTY
41
- : buildModelFacts(providers, namespaces)
42
- for (const listener of [...listeners]) listener()
43
- }
41
+ let stop: (() => void) | undefined
42
+ let readOnDemand: (() => void) | undefined
44
43
 
45
44
  return {
46
45
  source: {
@@ -50,21 +49,90 @@ export function createFactsSource(deps: {
50
49
  return () => { listeners.delete(listener) }
51
50
  },
52
51
  },
52
+ refresh: () => readOnDemand?.(),
53
53
  start: () => {
54
- const off = deps.describe.subscribe(rebuild)
55
- void deps.describe.ensure().catch(() => { })
56
- void deps.listProviders().then(
57
- (answer) => {
58
- providers = answer.ok && answer.value !== undefined ? answer.value : []
59
- rebuild()
60
- },
61
- () => { },
62
- )
63
- rebuild()
64
- return () => {
65
- off()
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?.()
66
96
  listeners.clear()
97
+ readOnDemand = undefined
98
+ stop = undefined
67
99
  }
100
+ rebuild()
101
+ refresh()
102
+ void deps.describe.ensure().catch(() => {})
103
+ return stop
68
104
  },
69
105
  }
70
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
+ }
@@ -5,16 +5,14 @@ import type {} from '@deepseek-ai/dsh-api-remotes/client'
5
5
  import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
6
6
  import type {} from '@deepseek-ai/dsh-client-ui-model-selection/client'
7
7
  import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
8
- import { EffortTint } from './EffortTint.tsx'
9
8
  import { ModelMenuBridge } from './ModelMenuBridge.tsx'
10
9
  import { ModelPickerFallback, ModelPickerHost } from './ModelPickerHost.tsx'
11
10
  import { QUICK_MODELS_PANE, QuickModels } from './QuickModels.tsx'
12
11
  import { createPickerStore } from './picker-state.ts'
13
- import { createFactsSource, type DescribeFace } from './facts-source.ts'
12
+ import { createFactsSource, readAccountModels, type DescribeFace } from './facts-source.ts'
14
13
  import { NS, en, zh } from './locales.ts'
15
14
  import { stylesheet } from './ModelOptions.module.css'
16
15
 
17
- export { EffortTint } from './EffortTint.tsx'
18
16
  export { ModelMenuBridge } from './ModelMenuBridge.tsx'
19
17
  export { ModelPickerHost } from './ModelPickerHost.tsx'
20
18
  export { createPickerStore } from './picker-state.ts'
@@ -49,6 +47,15 @@ export function apply(ctx: ClientContext): void {
49
47
  const facts = createFactsSource({
50
48
  describe: scope.configForms.describe() as DescribeFace,
51
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
+ },
52
59
  })
53
60
  scope.effect(() => facts.start(), 'dsh-model-submenu: model metadata')
54
61
  const faceOf = (sessionId: string) => {
@@ -62,7 +69,9 @@ export function apply(ctx: ClientContext): void {
62
69
  directory: directory.store,
63
70
  factsSource: facts.source,
64
71
  load: () => {
65
- if (available) directory.load().catch(() => {})
72
+ if (!available) return
73
+ facts.refresh()
74
+ directory.load().catch(() => {})
66
75
  },
67
76
  resolveText: (text: Parameters<typeof ctx.locale.resolveText>[0]) => ctx.locale.resolveText(text),
68
77
  select: (selection: Parameters<typeof directory.select>[0]) => available
@@ -98,11 +107,5 @@ export function apply(ctx: ClientContext): void {
98
107
  locale: NS,
99
108
  inject: faceOf,
100
109
  }, ModelPickerFallback))
101
- scope.slots.inject('conversation.input.overlay', () => scope.slots.register({
102
- name: 'conversation.input.overlay',
103
- id: 'model-effort-tint',
104
- registrant: '@lynn123411/dsh-model-submenu',
105
- inject: faceOf,
106
- }, EffortTint))
107
110
  })
108
111
  }
@@ -23,9 +23,6 @@ export type ModelSubmenuLocaleKey =
23
23
  | 'picker.hintFavorites'
24
24
  | 'meta.effort'
25
25
  | 'meta.images'
26
- | 'effort.label'
27
- | 'effort.providerDefault'
28
- | 'effort.useDefault'
29
26
 
30
27
  declare module '@deepseek-ai/dsh-client-ui-slots' {
31
28
  interface LocaleNamespaceMap {
@@ -55,9 +52,6 @@ export const zh: Record<ModelSubmenuLocaleKey, string> = {
55
52
  'picker.hintFavorites': '收藏的模型置顶,并加入快捷菜单',
56
53
  'meta.effort': '思考',
57
54
  'meta.images': '图片输入',
58
- 'effort.label': '推理等级',
59
- 'effort.providerDefault': 'Default',
60
- 'effort.useDefault': '切换为默认档位',
61
55
  }
62
56
 
63
57
  export const en: Record<ModelSubmenuLocaleKey, string> = {
@@ -82,7 +76,4 @@ export const en: Record<ModelSubmenuLocaleKey, string> = {
82
76
  'picker.hintFavorites': 'Favorites first, also in the quick menu',
83
77
  'meta.effort': 'Effort',
84
78
  'meta.images': 'Images',
85
- 'effort.label': 'Reasoning effort',
86
- 'effort.providerDefault': 'Default',
87
- 'effort.useDefault': 'Switch to the provider default',
88
79
  }
@@ -1,17 +1,7 @@
1
+ import { ACCOUNT_PROVIDER, type AccountModelFacts } from '../account-model-facts.ts'
1
2
 
2
3
  export type ImageAnswer = 'yes' | 'no' | 'unknown'
3
4
 
4
- const FAMILY_DEFAULTS: Readonly<Record<string, readonly {
5
- readonly id: string
6
- readonly contextWindow: number
7
- readonly images: boolean
8
- }[]>> = {
9
- 'deepseek-account': [
10
- { id: 'deepseek-flash', contextWindow: 1_000_000, images: true },
11
- { id: 'deepseek-v4-pro', contextWindow: 1_000_000, images: false },
12
- ],
13
- }
14
-
15
5
  export interface ModelFacts {
16
6
  readonly contextWindow: number | undefined
17
7
  readonly images: ImageAnswer
@@ -39,8 +29,10 @@ type Record_ = Record<string, unknown>
39
29
  export function buildModelFacts(
40
30
  providers: readonly ConfigurableProviderRow[],
41
31
  namespaces: readonly NamespaceRow[],
32
+ accountModels: readonly AccountModelFacts[] = [],
42
33
  ): (provider: string, model: string) => ModelFacts {
43
34
  const byName = new Map(namespaces.map((row) => [row.ns, row.value]))
35
+ const accountById = new Map(accountModels.map((model) => [model.id, model]))
44
36
  const profiles = new Map<string, ProfileView>()
45
37
  for (const row of providers) {
46
38
  const section = byName.get(row.settingsNs)
@@ -49,32 +41,24 @@ export function buildModelFacts(
49
41
  }
50
42
  return (provider, model) => {
51
43
  const profile = profiles.get(provider)
52
- const entry = profile?.models === undefined
53
- ? undefined
54
- : profile.models.find((candidate) => candidate.id === model)
55
- if (profile !== undefined && entry !== undefined) {
56
- const window = typeof entry.contextWindow === 'number' && entry.contextWindow > 0
57
- ? entry.contextWindow
58
- : undefined
59
- 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) }
60
47
  }
61
48
  const override = readOverride(profile, model)
62
- if (override !== undefined) {
63
- const window = typeof override.contextWindow === 'number' && override.contextWindow > 0
64
- ? override.contextWindow
65
- : undefined
66
- return {
67
- contextWindow: window,
68
- images: Array.isArray(override.inputModalities) ? containsImage(override.inputModalities) : 'unknown',
69
- }
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),
70
54
  }
71
- const family = FAMILY_DEFAULTS[provider]?.find((candidate) => candidate.id === model)
72
- return family === undefined
73
- ? { contextWindow: undefined, images: 'unknown' }
74
- : { contextWindow: family.contextWindow, images: family.images ? 'yes' : 'no' }
75
55
  }
76
56
  }
77
57
 
58
+ function contextWindow(value: unknown): number | undefined {
59
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : undefined
60
+ }
61
+
78
62
  function imageAnswer(entry: Record_, profile: ProfileView): ImageAnswer {
79
63
  if (Array.isArray(entry.inputModalities)) return containsImage(entry.inputModalities)
80
64
  const defaultInput = Array.isArray(profile.defaultInput) ? profile.defaultInput : undefined
@@ -8,30 +8,6 @@ export interface Selection {
8
8
  readonly reasoningEffort?: string
9
9
  }
10
10
 
11
- export interface EffortChoice {
12
- readonly key: string
13
- readonly effort: string | undefined
14
- readonly label: string
15
- }
16
-
17
- export function effortChoices(reasoning: ModelReasoning | undefined): readonly EffortChoice[] {
18
- if (reasoning === undefined) return []
19
- return reasoning.efforts.map((level) => ({
20
- key: level.id,
21
- effort: level.id as string | undefined,
22
- label: level.name,
23
- }))
24
- }
25
-
26
- export function planEffortCommit(live: Selection, effort: string | undefined): Selection | null {
27
- if (sameEffort(live.reasoningEffort, effort)) return null
28
- return {
29
- provider: live.provider,
30
- model: live.model,
31
- ...effort === undefined ? {} : { reasoningEffort: effort },
32
- }
33
- }
34
-
35
11
  export function planModelCommit(
36
12
  live: Selection | null,
37
13
  provider: string,
@@ -51,10 +27,6 @@ export function planModelCommit(
51
27
  }
52
28
  }
53
29
 
54
- export function liveReasoning(state: ModelDirectoryState): ModelReasoning | undefined {
55
- return currentCatalogModel(state)?.reasoning
56
- }
57
-
58
30
  export function currentCatalogModel(state: ModelDirectoryState) {
59
31
  const current = state.current
60
32
  if (current === null) return undefined
@@ -77,7 +49,3 @@ export function selectionOf(state: ModelDirectoryState): Selection | null {
77
49
  export function sameModel(live: Selection, provider: string, model: string): boolean {
78
50
  return live.provider === provider && live.model === model
79
51
  }
80
-
81
- export function sameEffort(liveEffort: string | undefined, effort: string | undefined): boolean {
82
- return liveEffort === effort
83
- }
package/src/index.ts CHANGED
@@ -1 +1,35 @@
1
- export function apply(): void {}
1
+ import type { Context } from '@deepseek-ai/cordis'
2
+ import type { HostConnectionHandle } from '@deepseek-ai/dsh-client-connection'
3
+ import type {} from '@deepseek-ai/dsh-llm'
4
+ import { ACCOUNT_FACTS_PATH, ACCOUNT_PROVIDER, type AccountModelFacts } from './account-model-facts.ts'
5
+
6
+ export function apply(ctx: Context): void {
7
+ ctx.inject(['connection', 'llm'], (scope) => {
8
+ const { connection } = scope as Context & { connection: HostConnectionHandle }
9
+ return connection.fetch.register({
10
+ path: ACCOUNT_FACTS_PATH,
11
+ methods: ['GET'],
12
+ requestBody: 'buffered',
13
+ async fetch(request) {
14
+ try {
15
+ const llm = scope.llm
16
+ const models = llm.listProviders().some((provider) => provider.id === ACCOUNT_PROVIDER)
17
+ ? await llm.listModels(ACCOUNT_PROVIDER)
18
+ : []
19
+ const resolved = await Promise.allSettled(models.map(async (model): Promise<AccountModelFacts> => {
20
+ const info = await llm.resolveModelInfo(ACCOUNT_PROVIDER, model.id, request.signal)
21
+ return {
22
+ id: model.id,
23
+ ...(info.context === undefined ? {} : { contextWindow: info.context.contextWindow }),
24
+ ...(info.inputModalities === undefined ? {} : { inputModalities: info.inputModalities }),
25
+ }
26
+ }))
27
+ const rows = resolved.flatMap((result) => result.status === 'fulfilled' ? [result.value] : [])
28
+ return Response.json(rows, { headers: { 'Cache-Control': 'no-store' } })
29
+ } catch {
30
+ return new Response(null, { status: 503 })
31
+ }
32
+ },
33
+ })
34
+ })
35
+ }
@@ -1,142 +0,0 @@
1
- import { useEffect, useRef, useState, type KeyboardEvent, type PointerEvent } from 'react';
2
- import type { EffortChoice } from './selection.ts';
3
- import { LEVEL_GRADIENT, isTopLevel, levelColor } from './level-color.ts';
4
- import { detentAt, fillWidth, fractionAt, knobOffset, offsetOf } from './slider.ts';
5
- import css from './ModelOptions.module.css';
6
-
7
- export interface EffortSliderProps {
8
- readonly steps: readonly EffortChoice[];
9
- readonly current: number;
10
- readonly defaultActive: boolean;
11
- readonly defaultIndex: number;
12
- readonly defaultLabel: string;
13
- readonly busy: boolean;
14
- readonly label: string;
15
- readonly onCommit: (index: number) => void;
16
- }
17
-
18
- export function EffortSlider({
19
- steps, current, defaultActive, defaultIndex, defaultLabel, busy, label, onCommit,
20
- }: EffortSliderProps) {
21
- const trackRef = useRef<HTMLDivElement | null>(null);
22
- const dragRef = useRef<number | null>(null);
23
- const pointerRef = useRef<number | null>(null);
24
- const [drag, setDrag] = useState<number | null>(null);
25
- const [hold, setHold] = useState<number | null>(null);
26
- const dragging = drag !== null;
27
- const resting = defaultActive ? defaultIndex : current;
28
- const active = dragging ? detentAt(drag, steps.length) : resting;
29
- const knobFraction = drag ?? hold ?? offsetOf(resting, steps.length);
30
- const shown = dragging || hold !== null ? detentAt(knobFraction, steps.length) : resting;
31
- const beginDrag = (fraction: number | null): void => {
32
- dragRef.current = fraction;
33
- setDrag(fraction);
34
- };
35
-
36
- useEffect(() => {
37
- if (!busy) {
38
- setHold(null);
39
- return;
40
- }
41
- pointerRef.current = null;
42
- dragRef.current = null;
43
- setDrag(null);
44
- }, [busy]);
45
- useEffect(() => {
46
- setHold(null);
47
- }, [current, defaultActive]);
48
-
49
- const fractionAtPointer = (clientX: number): number => {
50
- const track = trackRef.current;
51
- if (track === null) return dragRef.current ?? knobFraction;
52
- const rect = track.getBoundingClientRect();
53
- return fractionAt(clientX, rect.left, rect.width);
54
- };
55
-
56
- const onPointerDown = (event: PointerEvent<HTMLDivElement>): void => {
57
- if (busy || event.button !== 0 || pointerRef.current !== null) return;
58
- event.preventDefault();
59
- event.stopPropagation();
60
- setHold(null);
61
- pointerRef.current = event.pointerId;
62
- beginDrag(fractionAtPointer(event.clientX));
63
- try {
64
- event.currentTarget.setPointerCapture(event.pointerId);
65
- } catch {
66
- }
67
- event.currentTarget.focus();
68
- };
69
-
70
- const onPointerMove = (event: PointerEvent<HTMLDivElement>): void => {
71
- if (pointerRef.current !== event.pointerId || busy) return;
72
- beginDrag(fractionAtPointer(event.clientX));
73
- };
74
-
75
- const settle = (event: PointerEvent<HTMLDivElement>, commit: boolean): void => {
76
- if (pointerRef.current !== event.pointerId) return;
77
- pointerRef.current = null;
78
- beginDrag(null);
79
- if (!commit || busy) return;
80
- const next = detentAt(fractionAtPointer(event.clientX), steps.length);
81
- if (next !== current || defaultActive) {
82
- setHold(offsetOf(next, steps.length));
83
- onCommit(next);
84
- }
85
- };
86
-
87
- const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {
88
- if (event.nativeEvent.isComposing) return;
89
- const last = steps.length - 1;
90
- const next = event.key === 'ArrowRight' || event.key === 'ArrowUp'
91
- ? Math.min(active + 1, last)
92
- : event.key === 'ArrowLeft' || event.key === 'ArrowDown'
93
- ? Math.max(active - 1, 0)
94
- : event.key === 'Home'
95
- ? 0
96
- : event.key === 'End'
97
- ? last
98
- : null;
99
- if (next === null) return;
100
- event.preventDefault();
101
- event.stopPropagation();
102
- if (!busy && (next !== current || defaultActive)) onCommit(next);
103
- };
104
-
105
- const offset = knobOffset(knobFraction);
106
- const idle = defaultActive && !dragging && hold === null;
107
- const filled = idle ? 0 : knobFraction;
108
- const fill = isTopLevel(shown, steps.length) ? LEVEL_GRADIENT : levelColor(shown, steps.length);
109
- return <div
110
- ref={trackRef}
111
- className={css.slider}
112
- role="slider"
113
- tabIndex={0}
114
- aria-label={label}
115
- aria-valuemin={0}
116
- aria-valuemax={Math.max(0, steps.length - 1)}
117
- aria-valuenow={active}
118
- aria-valuetext={defaultActive && !dragging ? defaultLabel : steps[active]?.label}
119
- aria-disabled={busy || undefined}
120
- data-busy={busy ? '' : undefined}
121
- data-dragging={dragging ? '' : undefined}
122
- data-default={idle ? '' : undefined}
123
- onPointerDown={onPointerDown}
124
- onPointerMove={onPointerMove}
125
- onPointerUp={(event) => { settle(event, true); }}
126
- onPointerCancel={(event) => { settle(event, false); }}
127
- onLostPointerCapture={(event) => { settle(event, false); }}
128
- onKeyDown={onKeyDown}
129
- onClick={(event) => { event.stopPropagation(); }}
130
- >
131
- <div className={css.sliderTrack} aria-hidden="true">
132
- <div className={css.sliderFill} style={{ width: fillWidth(filled), background: fill }} />
133
- {steps.map((step, index) => <span
134
- key={step.key}
135
- className={css.sliderTick}
136
- data-on={index <= shown && !idle ? '' : undefined}
137
- style={{ left: knobOffset(offsetOf(index, steps.length)) }}
138
- />)}
139
- <div className={css.sliderKnob} style={{ left: offset }} />
140
- </div>
141
- </div>;
142
- }
@@ -1,40 +0,0 @@
1
- import { useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
2
- import type { ModelSelectInjected } from '@deepseek-ai/dsh-client-ui-model-selection/client';
3
- import { levelColor } from './level-color.ts';
4
- import { effortChoices, liveReasoning } from './selection.ts';
5
-
6
- export type EffortTintProps = Pick<ModelSelectInjected, 'available' | 'directory'>;
7
-
8
- export function EffortTint({ available, directory }: EffortTintProps) {
9
- const markerRef = useRef<HTMLSpanElement | null>(null);
10
- const [caption, setCaption] = useState<HTMLElement | null>(null);
11
- const state = useSyncExternalStore(
12
- (listener) => directory.subscribe(listener),
13
- () => directory.getSnapshot(),
14
- );
15
- const levels = effortChoices(liveReasoning(state));
16
- const effort = state.current?.reasoningEffort;
17
- const chosen = effort === undefined ? -1 : levels.findIndex((level) => level.effort === effort);
18
- const color = available && chosen >= 0 && levels.length >= 2
19
- ? levelColor(chosen, levels.length)
20
- : null;
21
-
22
- useLayoutEffect(() => {
23
- const card = markerRef.current?.closest('[data-composer-card]');
24
- const next = card?.querySelector<HTMLElement>(
25
- '[data-slot="conversation.input.model"] button[aria-haspopup="menu"] span[class*="triggerEffort"]',
26
- ) ?? null;
27
- if (next !== caption) setCaption(next);
28
- });
29
-
30
- useLayoutEffect(() => {
31
- if (caption === null || color === null) return;
32
- const saved = caption.style.color;
33
- caption.style.color = color;
34
- return () => {
35
- caption.style.color = saved;
36
- };
37
- }, [caption, color]);
38
-
39
- return <span ref={markerRef} hidden />;
40
- }
@@ -1,24 +0,0 @@
1
-
2
- const NEUTRAL = 'var(--dsw-alias-label-dimmed)';
3
-
4
- const LOW = [77, 147, 248] as const;
5
-
6
- const HIGH = [147, 51, 234] as const;
7
-
8
- function ramp(t: number): string {
9
- const mix = (from: number, to: number): number => Math.round(from + (to - from) * t);
10
- return `rgb(${mix(LOW[0], HIGH[0])}, ${mix(LOW[1], HIGH[1])}, ${mix(LOW[2], HIGH[2])})`;
11
- }
12
-
13
- export function levelColor(index: number, count: number): string {
14
- if (index <= 0) return NEUTRAL;
15
- if (isTopLevel(index, count)) return ramp(1);
16
- const span = Math.max(1, count - 2);
17
- return ramp(Math.min(Math.max((index - 1) / span, 0), 1));
18
- }
19
-
20
- export function isTopLevel(index: number, count: number): boolean {
21
- return count > 1 && index === count - 1;
22
- }
23
-
24
- export const LEVEL_GRADIENT = `linear-gradient(90deg, ${ramp(0)}, ${ramp(1)})`;
@@ -1,40 +0,0 @@
1
-
2
- export const TRACK_HEIGHT = 16;
3
-
4
- export const KNOB_SIZE = 20;
5
-
6
- const KNOB_RADIUS = KNOB_SIZE / 2;
7
-
8
- export function offsetOf(index: number, count: number): number {
9
- if (count <= 1) return 0;
10
- const clamped = Math.min(Math.max(index, 0), count - 1);
11
- return clamped / (count - 1);
12
- }
13
-
14
- export function fractionAt(clientX: number, left: number, width: number): number {
15
- const usable = width - KNOB_SIZE;
16
- if (usable <= 0) return 0;
17
- const fraction = (clientX - left - KNOB_RADIUS) / usable;
18
- return Math.min(Math.max(fraction, 0), 1);
19
- }
20
-
21
- export function detentAt(fraction: number, count: number): number {
22
- if (count <= 1) return 0;
23
- const clamped = Math.min(Math.max(fraction, 0), 1);
24
- return Math.round(clamped * (count - 1));
25
- }
26
-
27
- export function stepAt(clientX: number, left: number, width: number, count: number): number {
28
- if (count <= 1) return 0;
29
- return detentAt(fractionAt(clientX, left, width), count);
30
- }
31
-
32
- export function knobOffset(fraction: number): string {
33
- const clamped = Math.min(Math.max(fraction, 0), 1);
34
- return `calc(${KNOB_RADIUS}px + ${clamped} * (100% - ${KNOB_SIZE}px))`;
35
- }
36
-
37
- export function fillWidth(fraction: number): string {
38
- const clamped = Math.min(Math.max(fraction, 0), 1);
39
- return `calc(${TRACK_HEIGHT}px + ${clamped} * (100% - ${TRACK_HEIGHT}px))`;
40
- }