@surfishs/dsh-prompt-enhance 0.1.1 → 0.1.2
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/lib/client.js +1783 -644
- package/lib/index.js +12 -1
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
- package/src/client/ActionIcons.tsx +49 -0
- package/src/client/EnhanceButton.tsx +314 -5
- package/src/client/QuickSettingsMenu.tsx +163 -0
- package/src/client/ResultDock.tsx +14 -0
- package/src/client/ResultPanel.tsx +99 -51
- package/src/client/UndoBar.tsx +2 -2
- package/src/client/enhance-client.ts +4 -0
- package/src/client/index.tsx +8 -1
- package/src/client/llm-catalog.ts +55 -8
- package/src/client/locales.ts +90 -41
- package/src/client/quick-settings.ts +260 -0
- package/src/client/settings-page-controls.tsx +180 -48
- package/src/client/settings-page-copy.ts +10 -0
- package/src/client/settings-page-spec.ts +29 -3
- package/src/client/settings-page-styles.ts +59 -7
- package/src/client/settings-page.tsx +68 -10
- package/src/client/settings-source.ts +23 -0
- package/src/client/settings-writer.ts +51 -0
- package/src/client/settings.ts +24 -0
- package/src/client/shortcut.ts +45 -0
- package/src/client/styles.ts +370 -43
- package/src/client/ui-state.ts +16 -0
- package/src/config.ts +8 -0
- package/src/enhancer.ts +3 -0
- package/src/shared/defaults.ts +4 -0
- package/src/shared/protocol.ts +6 -0
|
@@ -11,7 +11,23 @@ import { fetchReasoningCapabilities } from './reasoning-options'
|
|
|
11
11
|
import type { LlmRoutingState } from './llm-catalog'
|
|
12
12
|
import type { RowProps } from './settings-page-spec'
|
|
13
13
|
import type { RowCopy } from './settings-page-copy'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
HEAD_STYLE,
|
|
16
|
+
HINT_STYLE,
|
|
17
|
+
FIELD_INPUT_STYLE,
|
|
18
|
+
FIELD_SHELL_STYLE,
|
|
19
|
+
INVALID_STYLE,
|
|
20
|
+
LABEL_STYLE,
|
|
21
|
+
NOTICE_STYLE,
|
|
22
|
+
RECORD_STYLE,
|
|
23
|
+
REFRESH_STYLE,
|
|
24
|
+
RESET_STYLE,
|
|
25
|
+
ROW_STYLE,
|
|
26
|
+
SELECT_STYLE,
|
|
27
|
+
STATUS_STYLE,
|
|
28
|
+
WARN_STYLE,
|
|
29
|
+
} from './settings-page-styles'
|
|
30
|
+
import { shortcutSpecOf } from './shortcut'
|
|
15
31
|
|
|
16
32
|
/**
|
|
17
33
|
* The "overridden" badge and its reset button, as the text rows draw them.
|
|
@@ -84,10 +100,35 @@ export function ChoiceRow(props: RowProps & { options: readonly { value: string;
|
|
|
84
100
|
* @param props - the row, its copy, state, actions, and the pinned pair.
|
|
85
101
|
* @returns the row element.
|
|
86
102
|
*/
|
|
103
|
+
/**
|
|
104
|
+
* Last capability answer per provider/model pair, for this browser session.
|
|
105
|
+
*
|
|
106
|
+
* The host already keeps a durable disk cache; this one exists so a remount or a
|
|
107
|
+
* model switch the user has already inspected renders the tier list in the same
|
|
108
|
+
* frame instead of flashing "正在读取该模型的档位…" and re-listing the control.
|
|
109
|
+
* Transport failures are not remembered.
|
|
110
|
+
*/
|
|
111
|
+
const capabilityCache = new Map<string, ReasoningCapabilities>()
|
|
112
|
+
|
|
113
|
+
/** Key of one pair (`''` when the plugin follows the session model). */
|
|
114
|
+
function capabilityKey(provider: string, model: string): string {
|
|
115
|
+
return `${provider}\u0000${model}`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Drop the session-level capability cache. Tests swap the host answer between
|
|
120
|
+
* cases; a deployment may call it after an adapter change.
|
|
121
|
+
*/
|
|
122
|
+
export function forgetReasoningCapabilities(): void {
|
|
123
|
+
capabilityCache.clear()
|
|
124
|
+
}
|
|
125
|
+
|
|
87
126
|
export function ReasoningRow(props: RowProps & { provider: string; model: string }): ReactElement {
|
|
88
127
|
const pair = props.provider !== '' && props.model !== '' ? `${props.provider}/${props.model}` : ''
|
|
89
|
-
const
|
|
90
|
-
const
|
|
128
|
+
const cacheKey = capabilityKey(props.provider, props.model)
|
|
129
|
+
const cached = capabilityCache.get(cacheKey)
|
|
130
|
+
const [phase, setPhase] = useState<'loading' | 'ready'>(cached === undefined ? 'loading' : 'ready')
|
|
131
|
+
const [capabilities, setCapabilities] = useState<ReasoningCapabilities | undefined>(cached)
|
|
91
132
|
const [refreshToken, setRefreshToken] = useState(0)
|
|
92
133
|
const [feedback, setFeedback] = useState<'idle' | 'refreshing' | 'ok' | 'failed'>('idle')
|
|
93
134
|
const forceRef = useRef(false)
|
|
@@ -97,8 +138,11 @@ export function ReasoningRow(props: RowProps & { provider: string; model: string
|
|
|
97
138
|
const controller = new AbortController()
|
|
98
139
|
const force = forceRef.current
|
|
99
140
|
forceRef.current = false
|
|
100
|
-
|
|
101
|
-
|
|
141
|
+
// Keep the last answer on screen while the fresh read is in flight: the list
|
|
142
|
+
// then swaps once, instead of collapsing to the sentinel and rebuilding.
|
|
143
|
+
const known = capabilityCache.get(cacheKey)
|
|
144
|
+
setPhase(known === undefined ? 'loading' : 'ready')
|
|
145
|
+
setCapabilities(known)
|
|
102
146
|
setFeedback(force ? 'refreshing' : 'idle')
|
|
103
147
|
if (feedbackTimer.current !== undefined) {
|
|
104
148
|
clearTimeout(feedbackTimer.current)
|
|
@@ -118,6 +162,9 @@ export function ReasoningRow(props: RowProps & { provider: string; model: string
|
|
|
118
162
|
if (controller.signal.aborted) return
|
|
119
163
|
setCapabilities(answer)
|
|
120
164
|
setPhase('ready')
|
|
165
|
+
// Remember every answer the host actually gave; a transport failure is
|
|
166
|
+
// not an answer and must be retried next time.
|
|
167
|
+
if (answer.source !== 'unavailable' || answer.reason === 'no-efforts') capabilityCache.set(cacheKey, answer)
|
|
121
168
|
settle(answer.source === 'unavailable' ? 'failed' : 'ok')
|
|
122
169
|
})
|
|
123
170
|
.catch(() => {
|
|
@@ -135,14 +182,22 @@ export function ReasoningRow(props: RowProps & { provider: string; model: string
|
|
|
135
182
|
}
|
|
136
183
|
// `pair` covers both ids; the default path reuses the empty string.
|
|
137
184
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
-
}, [pair, refreshToken])
|
|
185
|
+
}, [cacheKey, pair, refreshToken])
|
|
139
186
|
|
|
140
187
|
// Every provider — DeepSeek included — shows the adapter's own tier names;
|
|
141
|
-
// only the "
|
|
188
|
+
// only the "not specified" sentinel is plugin copy. It leads the control: the
|
|
189
|
+
// stored value can point at it, and it must not trail the concrete tiers.
|
|
142
190
|
const current = props.view.text
|
|
143
191
|
const realTierKnown = phase === 'ready' && capabilities !== undefined && capabilities.source !== 'unavailable' && capabilities.efforts.some((effort) => effort.id === current)
|
|
144
192
|
const noTiers = phase === 'ready' && capabilities !== undefined && capabilities.source === 'unavailable' && capabilities.reason === 'no-efforts'
|
|
145
193
|
const options: { value: string; label: string; title?: string }[] = []
|
|
194
|
+
// The sentinel comes first: it is the fallback state, and a config that
|
|
195
|
+
// stores it must not render its selection at the tail of the control.
|
|
196
|
+
options.push({
|
|
197
|
+
value: 'inherit',
|
|
198
|
+
label: props.copy.choice('settings.reasoning.inherit'),
|
|
199
|
+
title: props.copy.choice('settings.reasoning.inherit'),
|
|
200
|
+
})
|
|
146
201
|
// A value the route does not declare (stale config, or while the list is
|
|
147
202
|
// still loading) is kept as a visible synthetic choice. Without it the
|
|
148
203
|
// segmented control's indicator has no matching option and slides off the
|
|
@@ -163,11 +218,11 @@ export function ReasoningRow(props: RowProps & { provider: string; model: string
|
|
|
163
218
|
})
|
|
164
219
|
}
|
|
165
220
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
221
|
+
// The host control derives the indicator from `findIndex(value)`: a value the
|
|
222
|
+
// option list does not carry makes that -1, which parks the pill outside the
|
|
223
|
+
// track. Whatever the host projects (including an empty text), the control is
|
|
224
|
+
// only ever handed a value it can select.
|
|
225
|
+
const selected = options.some((option) => option.value === current) ? current : 'inherit'
|
|
171
226
|
const unsupported = !noTiers && phase === 'ready' && capabilities?.source !== 'unavailable' && current !== '' && current !== 'inherit' && !realTierKnown
|
|
172
227
|
const refreshing = feedback === 'refreshing'
|
|
173
228
|
const refresh = (): void => {
|
|
@@ -191,7 +246,7 @@ export function ReasoningRow(props: RowProps & { provider: string; model: string
|
|
|
191
246
|
// A route that declares no tiers is presented as "follow provider
|
|
192
247
|
// default"; the stored tier stays in the config and the host omits it
|
|
193
248
|
// on the call, so the displayed state matches what actually happens.
|
|
194
|
-
value={
|
|
249
|
+
value={selected}
|
|
195
250
|
options={options}
|
|
196
251
|
// "Follow provider default" stays selectable while the tier list is
|
|
197
252
|
// still loading; the tier choices themselves only appear once known.
|
|
@@ -204,12 +259,12 @@ export function ReasoningRow(props: RowProps & { provider: string; model: string
|
|
|
204
259
|
{phase === 'ready' && capabilities?.source === 'unavailable' ? <p style={STATUS_STYLE}>{props.copy.choice(noTiers ? 'settings.reasoning.noTiers' : 'settings.reasoning.unavailable')}</p> : null}
|
|
205
260
|
{unsupported ? <p style={STATUS_STYLE}>{props.copy.interpolate('settings.reasoning.unsupported', { effort: props.view.text })}</p> : null}
|
|
206
261
|
{feedback === 'ok' ? (
|
|
207
|
-
<p style={
|
|
262
|
+
<p style={NOTICE_STYLE} aria-live="polite">
|
|
208
263
|
{props.copy.choice('settings.reasoning.refreshOk')}
|
|
209
264
|
</p>
|
|
210
265
|
) : null}
|
|
211
266
|
{feedback === 'failed' ? (
|
|
212
|
-
<p style={
|
|
267
|
+
<p style={NOTICE_STYLE} aria-live="polite">
|
|
213
268
|
{props.copy.choice('settings.reasoning.refreshFailed')}
|
|
214
269
|
</p>
|
|
215
270
|
) : null}
|
|
@@ -352,7 +407,15 @@ export function ModelRow(props: RowProps & { routing: LlmRoutingState; providerV
|
|
|
352
407
|
) : null}
|
|
353
408
|
{provider !== '' ? <option value="__custom__">{props.copy.choice('settings.routing.custom')}</option> : null}
|
|
354
409
|
</SelectControl>
|
|
355
|
-
{showCustom ?
|
|
410
|
+
{showCustom ? (
|
|
411
|
+
<TextControl
|
|
412
|
+
value={current}
|
|
413
|
+
placeholder={props.copy.choice('settings.routing.customPlaceholder')}
|
|
414
|
+
disabled={props.disabled}
|
|
415
|
+
onChange={(text) => props.onEdit(text, { deferred: true })}
|
|
416
|
+
onCommit={props.onCommit}
|
|
417
|
+
/>
|
|
418
|
+
) : null}
|
|
356
419
|
<p style={HINT_STYLE}>{props.hint}</p>
|
|
357
420
|
{props.routing.models.loading ? <p style={STATUS_STYLE}>{props.copy.choice('settings.routing.modelsLoading')}</p> : null}
|
|
358
421
|
{props.routing.models.failed && !showCustom ? <p style={STATUS_STYLE}>{props.copy.choice('settings.routing.modelsFailed')}</p> : null}
|
|
@@ -392,38 +455,85 @@ export function TextControl(props: {
|
|
|
392
455
|
const showInvalid = props.invalid === true && revealedInvalid
|
|
393
456
|
const borderColor = showInvalid ? 'var(--dsw-alias-state-error-primary, #f85149)' : focused ? 'var(--dsw-alias-state-business-primary, #4f8cff)' : undefined
|
|
394
457
|
return (
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
458
|
+
// Host primitives Input: a flex shell centers a borderless inner input, so
|
|
459
|
+
// the text sits on the shell's center line instead of relying on a fixed
|
|
460
|
+
// height plus a line-height to be centered by the browser.
|
|
461
|
+
<div style={{ ...FIELD_SHELL_STYLE, ...(borderColor === undefined ? {} : { borderColor }) }}>
|
|
462
|
+
<input
|
|
463
|
+
id={props.id}
|
|
464
|
+
type="text"
|
|
465
|
+
inputMode={props.numeric === true ? 'numeric' : undefined}
|
|
466
|
+
aria-invalid={showInvalid || undefined}
|
|
467
|
+
disabled={props.disabled}
|
|
468
|
+
placeholder={props.placeholder}
|
|
469
|
+
value={props.value}
|
|
470
|
+
style={{
|
|
471
|
+
...FIELD_INPUT_STYLE,
|
|
472
|
+
...(props.disabled === true ? { color: 'var(--dsw-alias-label-tertiary, inherit)', cursor: 'default' } : {}),
|
|
473
|
+
}}
|
|
474
|
+
onFocus={() => setFocused(true)}
|
|
475
|
+
onBlur={() => {
|
|
476
|
+
setFocused(false)
|
|
477
|
+
if (props.invalid === true) setRevealedInvalid(true)
|
|
478
|
+
props.onCommit?.()
|
|
479
|
+
}}
|
|
480
|
+
onKeyDown={(event) => {
|
|
481
|
+
if (event.key !== 'Enter') return
|
|
482
|
+
event.preventDefault()
|
|
483
|
+
if (props.invalid === true) setRevealedInvalid(true)
|
|
484
|
+
props.onCommit?.()
|
|
485
|
+
}}
|
|
486
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
487
|
+
/>
|
|
488
|
+
</div>
|
|
422
489
|
)
|
|
423
490
|
}
|
|
424
491
|
|
|
425
|
-
export function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string }): ReactElement {
|
|
426
|
-
|
|
492
|
+
export function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string; invalidMessage?: string; recordable?: boolean }): ReactElement {
|
|
493
|
+
// Two sources of "invalid": the descriptor refused the staged text (numbers),
|
|
494
|
+
// and the row's own client-side validation (the shortcut format).
|
|
495
|
+
const invalid = props.view.invalid || props.invalidMessage !== undefined
|
|
496
|
+
// The client-side message waits for blur / Enter, like the number rows' border,
|
|
497
|
+
// so typing "ctrl+alt+" does not flash a warning mid-combination. A value that
|
|
498
|
+
// was already invalid when the page opened shows it immediately.
|
|
499
|
+
const [revealed, setRevealed] = useState(props.invalidMessage !== undefined)
|
|
500
|
+
useEffect(() => {
|
|
501
|
+
if (props.invalidMessage === undefined) setRevealed(false)
|
|
502
|
+
}, [props.invalidMessage])
|
|
503
|
+
const showMessage = invalid && (props.view.invalid || revealed)
|
|
504
|
+
// Recorder: one press fills the field instead of typing the spec by hand.
|
|
505
|
+
const [recording, setRecording] = useState(false)
|
|
506
|
+
const [recordRejected, setRecordRejected] = useState(false)
|
|
507
|
+
const { onEdit, onCommit } = props
|
|
508
|
+
useEffect(() => {
|
|
509
|
+
if (!recording) return
|
|
510
|
+
const onKeyDown = (event: KeyboardEvent): void => {
|
|
511
|
+
if (event.isComposing || event.repeat) return
|
|
512
|
+
const key = event.key
|
|
513
|
+
// Modifier-only presses keep waiting for the real key.
|
|
514
|
+
if (key === 'Control' || key === 'Alt' || key === 'Shift' || key === 'Meta') return
|
|
515
|
+
if (key === 'Escape' || key === 'Tab') {
|
|
516
|
+
// Escape cancels; Tab keeps its navigation and just stops recording.
|
|
517
|
+
setRecording(false)
|
|
518
|
+
setRecordRejected(false)
|
|
519
|
+
if (key === 'Escape') event.preventDefault()
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
event.preventDefault()
|
|
523
|
+
event.stopPropagation()
|
|
524
|
+
const spec = shortcutSpecOf(event)
|
|
525
|
+
if (spec === null) {
|
|
526
|
+
setRecordRejected(true)
|
|
527
|
+
return
|
|
528
|
+
}
|
|
529
|
+
setRecording(false)
|
|
530
|
+
setRecordRejected(false)
|
|
531
|
+
onEdit(spec)
|
|
532
|
+
onCommit?.()
|
|
533
|
+
}
|
|
534
|
+
window.addEventListener('keydown', onKeyDown, true)
|
|
535
|
+
return () => window.removeEventListener('keydown', onKeyDown, true)
|
|
536
|
+
}, [recording, onEdit, onCommit])
|
|
427
537
|
return (
|
|
428
538
|
<div style={ROW_STYLE}>
|
|
429
539
|
<div style={HEAD_STYLE}>
|
|
@@ -431,6 +541,21 @@ export function ValueRow(props: RowProps & { numeric: boolean; placeholder?: str
|
|
|
431
541
|
{props.label}
|
|
432
542
|
</label>
|
|
433
543
|
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
544
|
+
{props.recordable === true ? (
|
|
545
|
+
<button
|
|
546
|
+
type="button"
|
|
547
|
+
className="dsh-pe-chip-reset"
|
|
548
|
+
style={RECORD_STYLE}
|
|
549
|
+
disabled={props.disabled}
|
|
550
|
+
aria-pressed={recording}
|
|
551
|
+
onClick={() => {
|
|
552
|
+
setRecording((open) => !open)
|
|
553
|
+
setRecordRejected(false)
|
|
554
|
+
}}
|
|
555
|
+
>
|
|
556
|
+
{recording ? props.copy.labels.recordStop : props.copy.labels.record}
|
|
557
|
+
</button>
|
|
558
|
+
) : null}
|
|
434
559
|
</div>
|
|
435
560
|
<TextControl
|
|
436
561
|
id={props.id}
|
|
@@ -439,11 +564,18 @@ export function ValueRow(props: RowProps & { numeric: boolean; placeholder?: str
|
|
|
439
564
|
numeric={props.numeric}
|
|
440
565
|
invalid={invalid}
|
|
441
566
|
disabled={props.disabled}
|
|
442
|
-
onChange={
|
|
443
|
-
|
|
567
|
+
onChange={(text: string) => {
|
|
568
|
+
setRevealed(false)
|
|
569
|
+
props.onEdit(text)
|
|
570
|
+
}}
|
|
571
|
+
onCommit={() => {
|
|
572
|
+
setRevealed(true)
|
|
573
|
+
props.onCommit?.()
|
|
574
|
+
}}
|
|
444
575
|
/>
|
|
445
576
|
<p style={HINT_STYLE}>{props.hint}</p>
|
|
446
|
-
{
|
|
577
|
+
{recording ? <p style={NOTICE_STYLE}>{recordRejected ? props.copy.labels.recordNeedsModifier : props.copy.labels.recordPrompt}</p> : null}
|
|
578
|
+
{showMessage ? <p style={INVALID_STYLE}>{props.invalidMessage ?? props.copy.labels.invalidNumber}</p> : null}
|
|
447
579
|
</div>
|
|
448
580
|
)
|
|
449
581
|
}
|
|
@@ -74,6 +74,11 @@ export function sectionCopy(t: Translate, chinese: boolean): RowCopy {
|
|
|
74
74
|
advanced: t('settings.advanced'),
|
|
75
75
|
reset: t('settings.reset'),
|
|
76
76
|
invalidNumber: t('settings.invalidNumber'),
|
|
77
|
+
invalidShortcut: t('settings.invalidShortcut'),
|
|
78
|
+
record: t('settings.record'),
|
|
79
|
+
recordStop: t('settings.recordStop'),
|
|
80
|
+
recordPrompt: t('settings.recordPrompt'),
|
|
81
|
+
recordNeedsModifier: t('settings.recordNeedsModifier'),
|
|
77
82
|
},
|
|
78
83
|
title: (row) => (chinese ? `${row.key}(${t(row.label)})` : row.key),
|
|
79
84
|
hint: (row) => t(row.hint),
|
|
@@ -102,6 +107,11 @@ export function pageCopy(t: Translate): RowCopy {
|
|
|
102
107
|
advanced: t('settings.advanced'),
|
|
103
108
|
reset: t('settings.reset'),
|
|
104
109
|
invalidNumber: t('settings.invalidNumber'),
|
|
110
|
+
invalidShortcut: t('settings.invalidShortcut'),
|
|
111
|
+
record: t('settings.record'),
|
|
112
|
+
recordStop: t('settings.recordStop'),
|
|
113
|
+
recordPrompt: t('settings.recordPrompt'),
|
|
114
|
+
recordNeedsModifier: t('settings.recordNeedsModifier'),
|
|
105
115
|
},
|
|
106
116
|
title: (row) => t(row.label),
|
|
107
117
|
hint: (row) => t(row.hint),
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { SettingsFormModel, settingsNumberField, settingsTextField } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
13
13
|
import type { SettingsFieldDescriptor } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
14
14
|
import { DEFAULT_VALUES } from '../shared/defaults'
|
|
15
|
+
import { parseShortcut } from './shortcut'
|
|
15
16
|
import type { PromptEnhanceKey } from './locales'
|
|
16
17
|
import type { RowCopy, Translate } from './settings-page-copy'
|
|
17
18
|
|
|
@@ -122,6 +123,15 @@ export interface Row {
|
|
|
122
123
|
* It teaches the expected format without writing any value into the config.
|
|
123
124
|
*/
|
|
124
125
|
readonly placeholder?: PromptEnhanceKey
|
|
126
|
+
/**
|
|
127
|
+
* Whether a staged value may be written. The schema accepts the field as a
|
|
128
|
+
* plain string, so a field whose format only the client understands (the
|
|
129
|
+
* shortcut) has to refuse the write here instead of storing a dead value.
|
|
130
|
+
* Absent means "anything the descriptor stages is writable".
|
|
131
|
+
*/
|
|
132
|
+
readonly validate?: (text: string) => boolean
|
|
133
|
+
/** Offer the press-a-combination recorder next to the input (the shortcut row). */
|
|
134
|
+
readonly recordable?: boolean
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
/**
|
|
@@ -138,11 +148,22 @@ export const BASIC_ROWS: readonly Row[] = [
|
|
|
138
148
|
{ key: 'contextAware', kind: 'boolean', label: 'settings.row.contextAware.label', hint: 'settings.row.contextAware.hint' },
|
|
139
149
|
{ key: 'streaming', kind: 'boolean', label: 'settings.row.streaming.label', hint: 'settings.row.streaming.hint' },
|
|
140
150
|
{ key: 'systemPrompt', kind: 'text', label: 'settings.row.systemPrompt.label', hint: 'settings.row.systemPrompt.hint', placeholder: 'settings.row.systemPrompt.placeholder' },
|
|
141
|
-
{
|
|
151
|
+
{
|
|
152
|
+
key: 'shortcut',
|
|
153
|
+
kind: 'text',
|
|
154
|
+
label: 'settings.row.shortcut.label',
|
|
155
|
+
hint: 'settings.row.shortcut.hint',
|
|
156
|
+
placeholder: 'settings.row.shortcut.placeholder',
|
|
157
|
+
// Empty disables the shortcut, so it is valid; anything else must parse.
|
|
158
|
+
validate: (text: string) => text.trim() === '' || parseShortcut(text) !== null,
|
|
159
|
+
recordable: true,
|
|
160
|
+
},
|
|
142
161
|
]
|
|
143
162
|
|
|
144
163
|
/** Tuning and deployment limits, hidden behind the Advanced disclosure by default. */
|
|
145
164
|
export const ADVANCED_ROWS: readonly Row[] = [
|
|
165
|
+
{ key: 'foldAnimation', kind: 'boolean', label: 'settings.row.foldAnimation.label', hint: 'settings.row.foldAnimation.hint' },
|
|
166
|
+
{ key: 'autoFold', kind: 'boolean', label: 'settings.row.autoFold.label', hint: 'settings.row.autoFold.hint' },
|
|
146
167
|
{ key: 'strategyMode', kind: 'strategy', label: 'settings.row.strategyMode.label', hint: 'settings.row.strategyMode.hint' },
|
|
147
168
|
{ key: 'maxInputChars', kind: 'number', label: 'settings.row.maxInputChars.label', hint: 'settings.row.maxInputChars.hint' },
|
|
148
169
|
{ key: 'maxOutputTokens', kind: 'number', label: 'settings.row.maxOutputTokens.label', hint: 'settings.row.maxOutputTokens.hint' },
|
|
@@ -273,8 +294,13 @@ export interface RowProps {
|
|
|
273
294
|
view: FieldView
|
|
274
295
|
/** Whether writes are refused by this deployment. */
|
|
275
296
|
disabled: boolean
|
|
276
|
-
/**
|
|
277
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Stage new text for this row. deferred asks the frame to debounce the
|
|
299
|
+
* write instead of saving at once — free text (a hand-typed model id) should
|
|
300
|
+
* not write the configuration once per keystroke, while a discrete choice
|
|
301
|
+
* still saves immediately.
|
|
302
|
+
*/
|
|
303
|
+
onEdit: (text: string, options?: { deferred?: boolean }) => void
|
|
278
304
|
/** Clear the stored value so the row re-inherits the composition default. */
|
|
279
305
|
onReset: () => void
|
|
280
306
|
/** Commit the current text now, e.g. on blur or Enter. */
|
|
@@ -36,6 +36,18 @@ export const STATUS_STYLE: CSSProperties = {
|
|
|
36
36
|
lineHeight: 1.5,
|
|
37
37
|
color: 'var(--dsw-alias-label-secondary, inherit)',
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A short-lived answer to a row action (the recorder's "press a combination"
|
|
41
|
+
* prompt, the tier refetch result). One step louder than a status line: this is
|
|
42
|
+
* the row telling the user what to do right now, not background information.
|
|
43
|
+
*/
|
|
44
|
+
export const NOTICE_STYLE: CSSProperties = {
|
|
45
|
+
margin: 0,
|
|
46
|
+
fontSize: 12.5,
|
|
47
|
+
fontWeight: 500,
|
|
48
|
+
lineHeight: 1.5,
|
|
49
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
50
|
+
}
|
|
39
51
|
/** The neutral chip surface shared by the row's quiet actions. */
|
|
40
52
|
export const CHIP_STYLE: CSSProperties = {
|
|
41
53
|
display: 'inline-flex',
|
|
@@ -57,10 +69,16 @@ export const CHIP_STYLE: CSSProperties = {
|
|
|
57
69
|
export const REFRESH_STYLE: CSSProperties = { ...CHIP_STYLE, flex: 'none' }
|
|
58
70
|
/** The reset action: the neutral chip surface, with an underline for affordance. */
|
|
59
71
|
export const RESET_STYLE: CSSProperties = CHIP_STYLE
|
|
72
|
+
/** The shortcut recorder: the same neutral chip, so it reads as a row action. */
|
|
73
|
+
export const RECORD_STYLE: CSSProperties = CHIP_STYLE
|
|
60
74
|
/** One border for every form control, so focus never changes the outline width. */
|
|
61
|
-
export const FIELD_BORDER = '1px solid rgba(128, 128, 128, 0.38)'
|
|
62
|
-
/**
|
|
63
|
-
|
|
75
|
+
export const FIELD_BORDER = '1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.38))'
|
|
76
|
+
/**
|
|
77
|
+
* The form control box: the same 34px / 1px border / 12px inline padding the
|
|
78
|
+
* page always used. It is shared by the text-field shell and the select so the
|
|
79
|
+
* two controls keep one outer size.
|
|
80
|
+
*/
|
|
81
|
+
export const FIELD_BOX_STYLE: CSSProperties = {
|
|
64
82
|
boxSizing: 'border-box',
|
|
65
83
|
width: '100%',
|
|
66
84
|
height: 34,
|
|
@@ -68,11 +86,34 @@ export const INPUT_STYLE: CSSProperties = {
|
|
|
68
86
|
border: FIELD_BORDER,
|
|
69
87
|
borderRadius: 'var(--dsw-radius-md, 8px)',
|
|
70
88
|
background: 'var(--dsw-alias-bg-layer-3, transparent)',
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The text-field shell: the host primitives Input pattern (a flex box that
|
|
92
|
+
* centers a borderless inner input), so vertical centering is a layout decision
|
|
93
|
+
* instead of a fixed-height plus line-height compromise.
|
|
94
|
+
*/
|
|
95
|
+
export const FIELD_SHELL_STYLE: CSSProperties = {
|
|
96
|
+
...FIELD_BOX_STYLE,
|
|
97
|
+
display: 'flex',
|
|
98
|
+
alignItems: 'center',
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The borderless inner input (host primitives Input .input): it fills the
|
|
102
|
+
* shell, keeps the page's 13px text, and takes the host's 22px line box so the
|
|
103
|
+
* glyphs sit on the same rhythm as the shell's other text.
|
|
104
|
+
*/
|
|
105
|
+
export const FIELD_INPUT_STYLE: CSSProperties = {
|
|
106
|
+
flex: '1 1 auto',
|
|
107
|
+
minWidth: 0,
|
|
108
|
+
margin: 0,
|
|
109
|
+
padding: 0,
|
|
110
|
+
border: 'none',
|
|
111
|
+
outline: 'none',
|
|
112
|
+
background: 'transparent',
|
|
71
113
|
font: 'inherit',
|
|
72
114
|
fontSize: 13,
|
|
73
|
-
lineHeight:
|
|
115
|
+
lineHeight: '22px',
|
|
74
116
|
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
75
|
-
outline: 'none',
|
|
76
117
|
}
|
|
77
118
|
/** The error line under an invalid numeric row. */
|
|
78
119
|
export const INVALID_STYLE: CSSProperties = {
|
|
@@ -88,9 +129,20 @@ export const WARN_STYLE: CSSProperties = {
|
|
|
88
129
|
lineHeight: 1.5,
|
|
89
130
|
color: 'var(--dsw-alias-state-error-primary, #f85149)',
|
|
90
131
|
}
|
|
91
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* The provider/model select: the same box as the text field. Chromium adds
|
|
134
|
+
* about 3px of its own inline inset to a select's text (measured from the
|
|
135
|
+
* settings screenshots: 17px vs the input's 14px), so the left padding drops to
|
|
136
|
+
* 9px to put both text edges on the same line.
|
|
137
|
+
*/
|
|
92
138
|
export const SELECT_STYLE: CSSProperties = {
|
|
93
|
-
...
|
|
139
|
+
...FIELD_BOX_STYLE,
|
|
140
|
+
paddingLeft: 9,
|
|
141
|
+
font: 'inherit',
|
|
142
|
+
fontSize: 13,
|
|
143
|
+
lineHeight: 1.5,
|
|
144
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
145
|
+
outline: 'none',
|
|
94
146
|
cursor: 'pointer',
|
|
95
147
|
}
|
|
96
148
|
export const SEPARATOR_STYLE: CSSProperties = {
|
|
@@ -144,7 +144,15 @@ function SettingsRow(props: {
|
|
|
144
144
|
case 'model':
|
|
145
145
|
return <ModelRow {...shared} routing={props.routing} providerValue={props.providerValue} />
|
|
146
146
|
default:
|
|
147
|
-
return
|
|
147
|
+
return (
|
|
148
|
+
<ValueRow
|
|
149
|
+
{...shared}
|
|
150
|
+
numeric={props.row.kind === 'number'}
|
|
151
|
+
placeholder={props.copy.placeholder(props.row)}
|
|
152
|
+
invalidMessage={props.row.validate !== undefined && !props.row.validate(props.view.text) ? props.copy.labels.invalidShortcut : undefined}
|
|
153
|
+
recordable={props.row.recordable === true}
|
|
154
|
+
/>
|
|
155
|
+
)
|
|
148
156
|
}
|
|
149
157
|
}
|
|
150
158
|
|
|
@@ -181,8 +189,21 @@ function SettingsRows(props: {
|
|
|
181
189
|
}
|
|
182
190
|
}, [props.state])
|
|
183
191
|
|
|
192
|
+
const isStagedInvalid = (key: string, text: string): boolean => {
|
|
193
|
+
const row = ROWS.find((item) => item.key === key)
|
|
194
|
+
return row?.validate !== undefined && !row.validate(text)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const hasStagedInvalid = (): boolean => ROWS.some((row) => row.validate !== undefined && !row.validate(viewOf(props.state, row.key).text))
|
|
198
|
+
|
|
184
199
|
const runSave = async (key: string, text: string): Promise<void> => {
|
|
185
200
|
if (props.writeField === undefined) return
|
|
201
|
+
// A row whose staged text fails its own validation is never written: the row
|
|
202
|
+
// explains why, and the value already in the config keeps working.
|
|
203
|
+
if (isStagedInvalid(key, text)) {
|
|
204
|
+
setSaveState('idle')
|
|
205
|
+
return
|
|
206
|
+
}
|
|
186
207
|
// A focus/blur with no edit, or an edit reverted to the stored value, is
|
|
187
208
|
// not a write: skip it without touching the footer status.
|
|
188
209
|
if (savedValues.current.get(key) === text) return
|
|
@@ -229,22 +250,49 @@ function SettingsRows(props: {
|
|
|
229
250
|
markSaved()
|
|
230
251
|
}
|
|
231
252
|
|
|
253
|
+
/**
|
|
254
|
+
* The rows a reset of key also clears. provider and model are one pair:
|
|
255
|
+
* clearing the provider leaves a model its (now empty) provider can no longer
|
|
256
|
+
* offer, so the select falls back to drawing its first option ("follow
|
|
257
|
+
* session") while the staged value — and its reset chip — stay behind. The
|
|
258
|
+
* pair is reset together so the control and its chip report the same state.
|
|
259
|
+
*/
|
|
260
|
+
const resetTargets = (key: string): string[] => (key === 'provider' && viewOf(props.state, 'model').text !== '' ? ['provider', 'model'] : [key])
|
|
261
|
+
|
|
232
262
|
const resetAndSave = (key: string): void => {
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
263
|
+
const targets = resetTargets(key)
|
|
264
|
+
for (const target of targets) {
|
|
265
|
+
props.resetField(target)
|
|
266
|
+
savedValues.current.set(target, defaultTextOf(target))
|
|
267
|
+
}
|
|
268
|
+
// Sequential: runReset takes a sequence ticket per call, and awaiting keeps
|
|
269
|
+
// the provider write from being superseded by the model write.
|
|
270
|
+
void (async () => {
|
|
271
|
+
for (const target of targets) await runReset(target, defaultTextOf(target))
|
|
272
|
+
})()
|
|
237
273
|
}
|
|
238
274
|
|
|
239
275
|
const manualSave = async (): Promise<void> => {
|
|
240
276
|
if (props.writeField === undefined) {
|
|
241
|
-
// Hosts without per-field writes keep the original whole-form action
|
|
277
|
+
// Hosts without per-field writes keep the original whole-form action — but
|
|
278
|
+
// an invalid row must not ride along, so the save is refused until it is
|
|
279
|
+
// fixed or cleared.
|
|
280
|
+
if (hasStagedInvalid()) {
|
|
281
|
+
setSaveState('idle')
|
|
282
|
+
return
|
|
283
|
+
}
|
|
242
284
|
props.save?.()
|
|
243
285
|
markSaved()
|
|
244
286
|
return
|
|
245
287
|
}
|
|
246
|
-
const changed = ROWS.map((row) => ({ key: row.key, text: viewOf(props.state, row.key).text })).filter(
|
|
288
|
+
const changed = ROWS.map((row) => ({ key: row.key, text: viewOf(props.state, row.key).text })).filter(
|
|
289
|
+
(item) => savedValues.current.get(item.key) !== item.text && !isStagedInvalid(item.key, item.text),
|
|
290
|
+
)
|
|
247
291
|
if (changed.length === 0) {
|
|
292
|
+
if (hasStagedInvalid()) {
|
|
293
|
+
setSaveState('idle')
|
|
294
|
+
return
|
|
295
|
+
}
|
|
248
296
|
markSaved()
|
|
249
297
|
return
|
|
250
298
|
}
|
|
@@ -279,10 +327,20 @@ function SettingsRows(props: {
|
|
|
279
327
|
timers.current.set(key, timer)
|
|
280
328
|
}
|
|
281
329
|
|
|
282
|
-
const onEdit = (key: string, text: string): void => {
|
|
330
|
+
const onEdit = (key: string, text: string, options?: { deferred?: boolean }): void => {
|
|
331
|
+
const previousProvider = key === 'provider' ? viewOf(props.state, 'provider').text : ''
|
|
283
332
|
props.edit(key, text)
|
|
333
|
+
// provider and model are one unit: a hand-typed model id belongs to the
|
|
334
|
+
// provider it was typed for, so switching providers clears it instead of
|
|
335
|
+
// leaving a value the new provider cannot serve (and a stale reset chip).
|
|
336
|
+
if (key === 'provider' && text !== previousProvider && viewOf(props.state, 'model').text !== '') {
|
|
337
|
+
props.resetField('model')
|
|
338
|
+
savedValues.current.set('model', '')
|
|
339
|
+
void runReset('model', '')
|
|
340
|
+
}
|
|
284
341
|
const row = ROWS.find((item) => item.key === key)
|
|
285
|
-
const
|
|
342
|
+
const typing = row !== undefined && (row.kind === 'text' || row.kind === 'number')
|
|
343
|
+
const debounced = options?.deferred === true || typing
|
|
286
344
|
scheduleSave(key, text, !debounced)
|
|
287
345
|
}
|
|
288
346
|
|
|
@@ -330,7 +388,7 @@ function SettingsRows(props: {
|
|
|
330
388
|
reasoningPair={{ provider, model }}
|
|
331
389
|
routing={routing}
|
|
332
390
|
providerValue={provider}
|
|
333
|
-
onEdit={(text: string) => onEdit(row.key, text)}
|
|
391
|
+
onEdit={(text: string, options?: { deferred?: boolean }) => onEdit(row.key, text, options)}
|
|
334
392
|
onReset={() => resetAndSave(row.key)}
|
|
335
393
|
onCommit={() => flushField(row.key, viewOf(props.state, row.key).text)}
|
|
336
394
|
/>
|