@surfishs/dsh-prompt-enhance 0.0.7 → 0.0.9
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.en.md +24 -18
- package/README.md +24 -18
- package/cordis.patch.yml +1 -1
- package/icon.svg +14 -0
- package/lib/client.js +343 -383
- package/lib/index.js +67 -56
- package/lib/index.js.map +3 -3
- package/package.json +26 -16
- package/src/client/ActionIcons.tsx +4 -17
- package/src/client/EnhanceButton.tsx +52 -48
- package/src/client/ResultDock.tsx +22 -9
- package/src/client/ResultPanel.tsx +83 -52
- package/src/client/SparkleFishIcon.tsx +25 -20
- package/src/client/UndoBar.tsx +11 -6
- package/src/client/enhance-client.ts +44 -40
- package/src/client/index.tsx +3 -12
- package/src/client/llm-catalog.ts +14 -16
- package/src/client/locales.ts +18 -4
- package/src/client/reasoning-options.ts +7 -15
- package/src/client/settings-page-controls.tsx +449 -0
- package/src/client/settings-page-copy.ts +112 -0
- package/src/client/settings-page-spec.ts +330 -0
- package/src/client/settings-page-styles.ts +161 -0
- package/src/client/settings-page.tsx +113 -1110
- package/src/client/settings-source.ts +41 -31
- package/src/client/settings.ts +17 -12
- package/src/client/shortcut.ts +7 -6
- package/src/client/useDockAlignment.ts +5 -15
- package/src/config.ts +84 -27
- package/src/context.ts +1 -5
- package/src/enhance-routes.ts +8 -8
- package/src/enhancer.ts +43 -34
- package/src/orchestrate.ts +19 -23
- package/src/prompts.ts +4 -4
- package/src/provider-catalog.ts +1 -1
- package/src/reasoning-cache.ts +4 -4
- package/src/reasoning-efforts.ts +4 -9
- package/src/settings-source.ts +37 -23
- package/src/shared/limits.ts +38 -0
- package/src/shared/normalize.ts +4 -1
- package/src/shared/protocol.ts +27 -23
- package/src/shared/reasoning.ts +1 -7
- package/src/shared/stream-text.ts +0 -6
- package/src/shared/validate.ts +3 -9
- package/docs/code-review-2026-09.md +0 -211
- package/docs/handoff-settings-page.md +0 -195
- package/docs/release-0.2.3.md +0 -47
- package/docs/release-0.2.4.md +0 -20
- package/docs/release-0.2.5.md +0 -28
- package/docs/release-0.2.6.md +0 -33
- package/docs/release-0.2.7.md +0 -22
- package/docs/release-0.3.0.md +0 -36
- package/docs/release-0.3.1.md +0 -50
- package/docs/release-0.3.2.md +0 -41
- package/docs/release-0.3.3.md +0 -53
- package/docs/release-0.3.4.md +0 -43
- package/src/client/SparkleIcon.tsx +0 -33
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The row controls: one component per row kind, plus the chip, select and text
|
|
3
|
+
* primitives they build on.
|
|
4
|
+
* @module dsh-prompt-enhance/client/settings-page-controls
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useEffect, useRef, useState, type ReactElement, type ReactNode } from 'react'
|
|
8
|
+
import { SegmentedControl, Switch } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
9
|
+
import type { ReasoningCapabilities } from '../shared/reasoning'
|
|
10
|
+
import { fetchReasoningCapabilities } from './reasoning-options'
|
|
11
|
+
import type { LlmRoutingState } from './llm-catalog'
|
|
12
|
+
import type { RowProps } from './settings-page-spec'
|
|
13
|
+
import type { RowCopy } from './settings-page-copy'
|
|
14
|
+
import { HEAD_STYLE, HINT_STYLE, INPUT_STYLE, INVALID_STYLE, LABEL_STYLE, REFRESH_STYLE, RESET_STYLE, ROW_STYLE, SELECT_STYLE, STATUS_STYLE, WARN_STYLE } from './settings-page-styles'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The "overridden" badge and its reset button, as the text rows draw them.
|
|
18
|
+
* @param props - the frame copy, whether writes are refused, and the reset handler.
|
|
19
|
+
* @returns the badge pair.
|
|
20
|
+
*/
|
|
21
|
+
export function OverrideActions(props: { copy: RowCopy; disabled: boolean; onReset: () => void }): ReactElement {
|
|
22
|
+
return (
|
|
23
|
+
<button type="button" className="dsh-pe-chip-reset" style={{ ...RESET_STYLE, ...(props.disabled ? { opacity: 0.5, cursor: 'default' } : {}) }} disabled={props.disabled} onClick={props.onReset}>
|
|
24
|
+
{props.copy.labels.reset}
|
|
25
|
+
</button>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A boolean row: the title and the shell's switch on one line, the hint below.
|
|
31
|
+
* @param props - the row, its copy, its state, and its actions.
|
|
32
|
+
* @returns the row element.
|
|
33
|
+
*/
|
|
34
|
+
export function BooleanRow(props: RowProps): ReactElement {
|
|
35
|
+
return (
|
|
36
|
+
<div style={ROW_STYLE}>
|
|
37
|
+
<div style={HEAD_STYLE}>
|
|
38
|
+
<span style={LABEL_STYLE}>{props.label}</span>
|
|
39
|
+
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
40
|
+
<Switch checked={props.view.text === 'true'} disabled={props.disabled} label={props.label} onChange={(next: boolean) => props.onEdit(next ? 'true' : 'false')} />
|
|
41
|
+
</div>
|
|
42
|
+
<p style={HINT_STYLE}>{props.hint}</p>
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A fixed-choice row: the shell's segmented control under the title.
|
|
49
|
+
* @param props - the row, its choices, its state, and its actions.
|
|
50
|
+
* @returns the row element.
|
|
51
|
+
*/
|
|
52
|
+
export function ChoiceRow(props: RowProps & { options: readonly { value: string; label: string; title?: string }[] }): ReactElement {
|
|
53
|
+
return (
|
|
54
|
+
<div style={ROW_STYLE}>
|
|
55
|
+
<div style={HEAD_STYLE}>
|
|
56
|
+
<span style={LABEL_STYLE}>{props.label}</span>
|
|
57
|
+
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
58
|
+
</div>
|
|
59
|
+
<SegmentedControl
|
|
60
|
+
id={props.id}
|
|
61
|
+
className="dsh-pe-segmented-labels"
|
|
62
|
+
value={props.view.text}
|
|
63
|
+
options={props.options.map((option) => ({ ...option, title: option.title ?? option.label }))}
|
|
64
|
+
disabled={props.disabled}
|
|
65
|
+
label={props.label}
|
|
66
|
+
onChange={(next: string) => props.onEdit(next)}
|
|
67
|
+
/>
|
|
68
|
+
<p style={HINT_STYLE}>{props.hint}</p>
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The reasoning row: choices come from what the configured route declares.
|
|
75
|
+
*
|
|
76
|
+
* - Both provider/model empty → follow the default model; the host answers from
|
|
77
|
+
* its static DeepSeek catalog, or reports unavailable when the default is not
|
|
78
|
+
* DeepSeek. This path is not cached (the page cannot observe the default).
|
|
79
|
+
* - A pinned pair → the answer is cached in `localStorage` with no TTL; it is
|
|
80
|
+
* replaced only when the pair changes or the user presses refresh.
|
|
81
|
+
*
|
|
82
|
+
* While the answer is pending, or when it is unavailable, the control offers
|
|
83
|
+
* only "follow provider default" instead of guessing a tier list.
|
|
84
|
+
* @param props - the row, its copy, state, actions, and the pinned pair.
|
|
85
|
+
* @returns the row element.
|
|
86
|
+
*/
|
|
87
|
+
export function ReasoningRow(props: RowProps & { provider: string; model: string }): ReactElement {
|
|
88
|
+
const pair = props.provider !== '' && props.model !== '' ? `${props.provider}/${props.model}` : ''
|
|
89
|
+
const [phase, setPhase] = useState<'loading' | 'ready'>('loading')
|
|
90
|
+
const [capabilities, setCapabilities] = useState<ReasoningCapabilities | undefined>(undefined)
|
|
91
|
+
const [refreshToken, setRefreshToken] = useState(0)
|
|
92
|
+
const [feedback, setFeedback] = useState<'idle' | 'refreshing' | 'ok' | 'failed'>('idle')
|
|
93
|
+
const forceRef = useRef(false)
|
|
94
|
+
const feedbackTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const controller = new AbortController()
|
|
98
|
+
const force = forceRef.current
|
|
99
|
+
forceRef.current = false
|
|
100
|
+
setPhase('loading')
|
|
101
|
+
setCapabilities(undefined)
|
|
102
|
+
setFeedback(force ? 'refreshing' : 'idle')
|
|
103
|
+
if (feedbackTimer.current !== undefined) {
|
|
104
|
+
clearTimeout(feedbackTimer.current)
|
|
105
|
+
feedbackTimer.current = undefined
|
|
106
|
+
}
|
|
107
|
+
/** Settle the manual-refresh feedback; initial loads show no outcome. */
|
|
108
|
+
const settle = (result: 'ok' | 'failed'): void => {
|
|
109
|
+
if (!force) return
|
|
110
|
+
setFeedback(result)
|
|
111
|
+
feedbackTimer.current = setTimeout(() => {
|
|
112
|
+
setFeedback('idle')
|
|
113
|
+
feedbackTimer.current = undefined
|
|
114
|
+
}, 3000)
|
|
115
|
+
}
|
|
116
|
+
fetchReasoningCapabilities(props.provider === '' ? undefined : props.provider, props.model === '' ? undefined : props.model, { refresh: force, signal: controller.signal })
|
|
117
|
+
.then((answer) => {
|
|
118
|
+
if (controller.signal.aborted) return
|
|
119
|
+
setCapabilities(answer)
|
|
120
|
+
setPhase('ready')
|
|
121
|
+
settle(answer.source === 'unavailable' ? 'failed' : 'ok')
|
|
122
|
+
})
|
|
123
|
+
.catch(() => {
|
|
124
|
+
if (controller.signal.aborted) return
|
|
125
|
+
setCapabilities({ efforts: [], source: 'unavailable', reason: 'resolve-failed' })
|
|
126
|
+
setPhase('ready')
|
|
127
|
+
settle('failed')
|
|
128
|
+
})
|
|
129
|
+
return () => {
|
|
130
|
+
controller.abort()
|
|
131
|
+
if (feedbackTimer.current !== undefined) {
|
|
132
|
+
clearTimeout(feedbackTimer.current)
|
|
133
|
+
feedbackTimer.current = undefined
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// `pair` covers both ids; the default path reuses the empty string.
|
|
137
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
+
}, [pair, refreshToken])
|
|
139
|
+
|
|
140
|
+
// Every provider — DeepSeek included — shows the adapter's own tier names;
|
|
141
|
+
// only the "follow provider default" sentinel is plugin copy.
|
|
142
|
+
const current = props.view.text
|
|
143
|
+
const realTierKnown = phase === 'ready' && capabilities !== undefined && capabilities.source !== 'unavailable' && capabilities.efforts.some((effort) => effort.id === current)
|
|
144
|
+
const noTiers = phase === 'ready' && capabilities !== undefined && capabilities.source === 'unavailable' && capabilities.reason === 'no-efforts'
|
|
145
|
+
const options: { value: string; label: string; title?: string }[] = []
|
|
146
|
+
// A value the route does not declare (stale config, or while the list is
|
|
147
|
+
// still loading) is kept as a visible synthetic choice. Without it the
|
|
148
|
+
// segmented control's indicator has no matching option and slides off the
|
|
149
|
+
// left edge.
|
|
150
|
+
if (!noTiers && current !== '' && current !== 'inherit' && !realTierKnown) {
|
|
151
|
+
options.push({
|
|
152
|
+
value: current,
|
|
153
|
+
label: props.copy.interpolate('settings.reasoning.current', { value: current }),
|
|
154
|
+
title: props.copy.choice('settings.reasoning.currentTitle'),
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
if (phase === 'ready' && capabilities !== undefined && capabilities.source !== 'unavailable') {
|
|
158
|
+
for (const effort of capabilities.efforts) {
|
|
159
|
+
options.push({
|
|
160
|
+
value: effort.id,
|
|
161
|
+
label: effort.name,
|
|
162
|
+
title: effort.description === undefined ? effort.name : `${effort.name} — ${effort.description}`,
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
options.push({
|
|
167
|
+
value: 'inherit',
|
|
168
|
+
label: props.copy.choice('settings.reasoning.inherit'),
|
|
169
|
+
title: props.copy.choice('settings.reasoning.inherit'),
|
|
170
|
+
})
|
|
171
|
+
const unsupported = !noTiers && phase === 'ready' && capabilities?.source !== 'unavailable' && current !== '' && current !== 'inherit' && !realTierKnown
|
|
172
|
+
const refreshing = feedback === 'refreshing'
|
|
173
|
+
const refresh = (): void => {
|
|
174
|
+
forceRef.current = true
|
|
175
|
+
setRefreshToken((token) => token + 1)
|
|
176
|
+
}
|
|
177
|
+
return (
|
|
178
|
+
<div style={ROW_STYLE}>
|
|
179
|
+
<div style={HEAD_STYLE}>
|
|
180
|
+
<span style={LABEL_STYLE}>{props.label}</span>
|
|
181
|
+
{phase === 'ready' || refreshing ? (
|
|
182
|
+
<button type="button" className="dsh-pe-chip-refresh" style={{ ...REFRESH_STYLE, opacity: props.disabled || refreshing ? 0.5 : 1 }} disabled={props.disabled || refreshing} onClick={refresh}>
|
|
183
|
+
{props.copy.choice(refreshing ? 'settings.reasoning.refreshing' : 'settings.reasoning.refresh')}
|
|
184
|
+
</button>
|
|
185
|
+
) : null}
|
|
186
|
+
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
187
|
+
</div>
|
|
188
|
+
<SegmentedControl
|
|
189
|
+
id={props.id}
|
|
190
|
+
className="dsh-pe-segmented-labels"
|
|
191
|
+
// A route that declares no tiers is presented as "follow provider
|
|
192
|
+
// default"; the stored tier stays in the config and the host omits it
|
|
193
|
+
// on the call, so the displayed state matches what actually happens.
|
|
194
|
+
value={noTiers ? 'inherit' : props.view.text}
|
|
195
|
+
options={options}
|
|
196
|
+
// "Follow provider default" stays selectable while the tier list is
|
|
197
|
+
// still loading; the tier choices themselves only appear once known.
|
|
198
|
+
disabled={props.disabled}
|
|
199
|
+
label={props.label}
|
|
200
|
+
onChange={(next: string) => props.onEdit(next)}
|
|
201
|
+
/>
|
|
202
|
+
<p style={HINT_STYLE}>{props.hint}</p>
|
|
203
|
+
{phase === 'loading' ? <p style={STATUS_STYLE}>{props.copy.choice('settings.reasoning.loading')}</p> : null}
|
|
204
|
+
{phase === 'ready' && capabilities?.source === 'unavailable' ? <p style={STATUS_STYLE}>{props.copy.choice(noTiers ? 'settings.reasoning.noTiers' : 'settings.reasoning.unavailable')}</p> : null}
|
|
205
|
+
{unsupported ? <p style={STATUS_STYLE}>{props.copy.interpolate('settings.reasoning.unsupported', { effort: props.view.text })}</p> : null}
|
|
206
|
+
{feedback === 'ok' ? (
|
|
207
|
+
<p style={STATUS_STYLE} aria-live="polite">
|
|
208
|
+
{props.copy.choice('settings.reasoning.refreshOk')}
|
|
209
|
+
</p>
|
|
210
|
+
) : null}
|
|
211
|
+
{feedback === 'failed' ? (
|
|
212
|
+
<p style={STATUS_STYLE} aria-live="polite">
|
|
213
|
+
{props.copy.choice('settings.reasoning.refreshFailed')}
|
|
214
|
+
</p>
|
|
215
|
+
) : null}
|
|
216
|
+
</div>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The shared select control: a 1px resting border (a hairline can vanish at
|
|
222
|
+
* some scale factors) and a business-colour border while focused, so the
|
|
223
|
+
* control's outline never depends on the browser's focus ring.
|
|
224
|
+
*/
|
|
225
|
+
export function SelectControl(props: { id: string; value: string; disabled?: boolean; onChange: (value: string) => void; children: ReactNode }): ReactElement {
|
|
226
|
+
const [focused, setFocused] = useState(false)
|
|
227
|
+
return (
|
|
228
|
+
<select
|
|
229
|
+
id={props.id}
|
|
230
|
+
style={{ ...SELECT_STYLE, ...(focused ? { borderColor: 'var(--dsw-alias-state-business-primary, #4f8cff)' } : {}) }}
|
|
231
|
+
value={props.value}
|
|
232
|
+
disabled={props.disabled}
|
|
233
|
+
onFocus={() => setFocused(true)}
|
|
234
|
+
onBlur={() => setFocused(false)}
|
|
235
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
236
|
+
>
|
|
237
|
+
{props.children}
|
|
238
|
+
</select>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The provider select: registered providers plus dormant ones rendered
|
|
244
|
+
* disabled, and a synthetic entry for a stored value outside the registry.
|
|
245
|
+
* @param props - the row, its state, and the catalog reads.
|
|
246
|
+
* @returns the row element.
|
|
247
|
+
*/
|
|
248
|
+
export function ProviderRow(props: RowProps & { routing: LlmRoutingState }): ReactElement {
|
|
249
|
+
const current = props.view.text
|
|
250
|
+
const known = props.routing.providers.entries.find((entry) => entry.id === current)
|
|
251
|
+
const missing = current !== '' && known === undefined
|
|
252
|
+
const unconfigured = known !== undefined && !known.registered
|
|
253
|
+
return (
|
|
254
|
+
<div style={ROW_STYLE}>
|
|
255
|
+
<div style={HEAD_STYLE}>
|
|
256
|
+
<label htmlFor={props.id} style={LABEL_STYLE}>
|
|
257
|
+
{props.label}
|
|
258
|
+
</label>
|
|
259
|
+
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
260
|
+
</div>
|
|
261
|
+
<SelectControl id={props.id} value={current} disabled={props.disabled} onChange={(value) => props.onEdit(value)}>
|
|
262
|
+
<option value="">{props.copy.choice('settings.routing.followSession')}</option>
|
|
263
|
+
{missing ? (
|
|
264
|
+
<option value={current} title={current}>
|
|
265
|
+
{props.copy.interpolate('settings.routing.currentProvider', { value: current })}
|
|
266
|
+
</option>
|
|
267
|
+
) : null}
|
|
268
|
+
<optgroup label={props.copy.choice('settings.routing.groupRegistered')}>
|
|
269
|
+
{props.routing.providers.entries
|
|
270
|
+
.filter((entry) => entry.registered)
|
|
271
|
+
.map((entry) => (
|
|
272
|
+
<option key={entry.id} value={entry.id} title={entry.id}>
|
|
273
|
+
{entry.name}
|
|
274
|
+
</option>
|
|
275
|
+
))}
|
|
276
|
+
</optgroup>
|
|
277
|
+
{props.routing.providers.entries.some((entry) => !entry.registered) ? (
|
|
278
|
+
<optgroup label={props.copy.choice('settings.routing.groupDormant')}>
|
|
279
|
+
{props.routing.providers.entries
|
|
280
|
+
.filter((entry) => !entry.registered)
|
|
281
|
+
.map((entry) => (
|
|
282
|
+
<option key={entry.id} value={entry.id} disabled title={props.copy.choice('settings.routing.unconfiguredTitle')}>
|
|
283
|
+
{entry.name}
|
|
284
|
+
{props.copy.choice('settings.routing.unconfiguredSuffix')}
|
|
285
|
+
</option>
|
|
286
|
+
))}
|
|
287
|
+
</optgroup>
|
|
288
|
+
) : null}
|
|
289
|
+
</SelectControl>
|
|
290
|
+
<p style={HINT_STYLE}>{props.hint}</p>
|
|
291
|
+
{props.routing.providers.loading ? <p style={STATUS_STYLE}>{props.copy.choice('settings.routing.providersLoading')}</p> : null}
|
|
292
|
+
{props.routing.providers.failed ? <p style={STATUS_STYLE}>{props.copy.choice('settings.routing.providersFailed')}</p> : null}
|
|
293
|
+
{props.routing.providers.failed ? (
|
|
294
|
+
<button type="button" style={REFRESH_STYLE} onClick={props.routing.providers.reload}>
|
|
295
|
+
{props.copy.choice('settings.routing.retry')}
|
|
296
|
+
</button>
|
|
297
|
+
) : null}
|
|
298
|
+
{missing ? <p style={WARN_STYLE}>{props.copy.interpolate('settings.routing.providerMissing', { value: current })}</p> : null}
|
|
299
|
+
{unconfigured ? <p style={WARN_STYLE}>{props.copy.interpolate('settings.routing.providerUnconfigured', { name: known.name })}</p> : null}
|
|
300
|
+
</div>
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* The model select: the provider's advertised models, a "custom…" entry that
|
|
306
|
+
* reveals a free-text input, and warnings (incomplete pair / unresolvable
|
|
307
|
+
* route) that never block saving.
|
|
308
|
+
* @param props - the row, its state, the catalog reads, and the provider value.
|
|
309
|
+
* @returns the row element.
|
|
310
|
+
*/
|
|
311
|
+
export function ModelRow(props: RowProps & { routing: LlmRoutingState; providerValue: string }): ReactElement {
|
|
312
|
+
const current = props.view.text
|
|
313
|
+
const provider = props.providerValue
|
|
314
|
+
const [customMode, setCustomMode] = useState(false)
|
|
315
|
+
const known = props.routing.models.entries.some((entry) => entry.id === current)
|
|
316
|
+
// A stored model outside the advertised catalog is still editable, so the
|
|
317
|
+
// custom input opens automatically for it instead of hiding the value.
|
|
318
|
+
const showCustom = provider !== '' && (customMode || (current !== '' && !known))
|
|
319
|
+
const pairIncomplete = provider !== '' && current === ''
|
|
320
|
+
const routeUnavailable = provider !== '' && current !== '' && props.routing.route.available === false
|
|
321
|
+
return (
|
|
322
|
+
<div style={ROW_STYLE}>
|
|
323
|
+
<div style={HEAD_STYLE}>
|
|
324
|
+
<label htmlFor={props.id} style={LABEL_STYLE}>
|
|
325
|
+
{props.label}
|
|
326
|
+
</label>
|
|
327
|
+
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
328
|
+
</div>
|
|
329
|
+
<SelectControl
|
|
330
|
+
id={props.id}
|
|
331
|
+
value={showCustom ? '__custom__' : current}
|
|
332
|
+
disabled={props.disabled || provider === ''}
|
|
333
|
+
onChange={(value) => {
|
|
334
|
+
if (value === '__custom__') {
|
|
335
|
+
setCustomMode(true)
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
setCustomMode(false)
|
|
339
|
+
props.onEdit(value)
|
|
340
|
+
}}
|
|
341
|
+
>
|
|
342
|
+
<option value="">{provider === '' ? props.copy.choice('settings.routing.followSession') : props.copy.choice('settings.routing.selectModel')}</option>
|
|
343
|
+
{props.routing.models.entries.map((entry) => (
|
|
344
|
+
<option key={entry.id} value={entry.id} title={entry.id}>
|
|
345
|
+
{entry.name}
|
|
346
|
+
</option>
|
|
347
|
+
))}
|
|
348
|
+
{provider !== '' && current !== '' && !known ? (
|
|
349
|
+
<option value={current} title={current}>
|
|
350
|
+
{props.copy.interpolate('settings.routing.currentModel', { value: current })}
|
|
351
|
+
</option>
|
|
352
|
+
) : null}
|
|
353
|
+
{provider !== '' ? <option value="__custom__">{props.copy.choice('settings.routing.custom')}</option> : null}
|
|
354
|
+
</SelectControl>
|
|
355
|
+
{showCustom ? <TextControl value={current} placeholder={props.copy.choice('settings.routing.customPlaceholder')} disabled={props.disabled} onChange={props.onEdit} /> : null}
|
|
356
|
+
<p style={HINT_STYLE}>{props.hint}</p>
|
|
357
|
+
{props.routing.models.loading ? <p style={STATUS_STYLE}>{props.copy.choice('settings.routing.modelsLoading')}</p> : null}
|
|
358
|
+
{props.routing.models.failed && !showCustom ? <p style={STATUS_STYLE}>{props.copy.choice('settings.routing.modelsFailed')}</p> : null}
|
|
359
|
+
{pairIncomplete ? <p style={WARN_STYLE}>{props.copy.choice('settings.routing.pairIncomplete')}</p> : null}
|
|
360
|
+
{routeUnavailable ? <p style={WARN_STYLE}>{props.copy.choice('settings.routing.routeUnavailable')}</p> : null}
|
|
361
|
+
</div>
|
|
362
|
+
)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* A text/number row: the title and the reset chip on one line, a native input,
|
|
367
|
+
* then the hint. The host's `SettingsValueField` draws its own badge and reset
|
|
368
|
+
* link, which would diverge from the chip the other rows use, so value rows
|
|
369
|
+
* share this control instead.
|
|
370
|
+
* @param props - the row, its copy, state, and whether it is numeric.
|
|
371
|
+
* @returns the row element.
|
|
372
|
+
*/
|
|
373
|
+
/**
|
|
374
|
+
* The shared text/number control: the same 1px border as the selects, turning
|
|
375
|
+
* the same business colour while focused (the invalid state wins over focus).
|
|
376
|
+
*/
|
|
377
|
+
export function TextControl(props: {
|
|
378
|
+
id?: string
|
|
379
|
+
value: string
|
|
380
|
+
placeholder?: string
|
|
381
|
+
numeric?: boolean
|
|
382
|
+
invalid?: boolean
|
|
383
|
+
disabled?: boolean
|
|
384
|
+
onChange: (value: string) => void
|
|
385
|
+
onCommit?: () => void
|
|
386
|
+
}): ReactElement {
|
|
387
|
+
const [focused, setFocused] = useState(false)
|
|
388
|
+
const [revealedInvalid, setRevealedInvalid] = useState(false)
|
|
389
|
+
useEffect(() => {
|
|
390
|
+
if (props.invalid !== true) setRevealedInvalid(false)
|
|
391
|
+
}, [props.invalid])
|
|
392
|
+
const showInvalid = props.invalid === true && revealedInvalid
|
|
393
|
+
const borderColor = showInvalid ? 'var(--dsw-alias-state-error-primary, #f85149)' : focused ? 'var(--dsw-alias-state-business-primary, #4f8cff)' : undefined
|
|
394
|
+
return (
|
|
395
|
+
<input
|
|
396
|
+
id={props.id}
|
|
397
|
+
type="text"
|
|
398
|
+
inputMode={props.numeric === true ? 'numeric' : undefined}
|
|
399
|
+
aria-invalid={showInvalid || undefined}
|
|
400
|
+
disabled={props.disabled}
|
|
401
|
+
placeholder={props.placeholder}
|
|
402
|
+
value={props.value}
|
|
403
|
+
style={{
|
|
404
|
+
...INPUT_STYLE,
|
|
405
|
+
...(props.disabled === true ? { color: 'var(--dsw-alias-label-tertiary, inherit)', cursor: 'default' } : {}),
|
|
406
|
+
...(borderColor === undefined ? {} : { borderColor }),
|
|
407
|
+
}}
|
|
408
|
+
onFocus={() => setFocused(true)}
|
|
409
|
+
onBlur={() => {
|
|
410
|
+
setFocused(false)
|
|
411
|
+
if (props.invalid === true) setRevealedInvalid(true)
|
|
412
|
+
props.onCommit?.()
|
|
413
|
+
}}
|
|
414
|
+
onKeyDown={(event) => {
|
|
415
|
+
if (event.key !== 'Enter') return
|
|
416
|
+
event.preventDefault()
|
|
417
|
+
if (props.invalid === true) setRevealedInvalid(true)
|
|
418
|
+
props.onCommit?.()
|
|
419
|
+
}}
|
|
420
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
421
|
+
/>
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string }): ReactElement {
|
|
426
|
+
const invalid = props.view.invalid
|
|
427
|
+
return (
|
|
428
|
+
<div style={ROW_STYLE}>
|
|
429
|
+
<div style={HEAD_STYLE}>
|
|
430
|
+
<label htmlFor={props.id} style={LABEL_STYLE}>
|
|
431
|
+
{props.label}
|
|
432
|
+
</label>
|
|
433
|
+
{props.view.overridden ? <OverrideActions copy={props.copy} disabled={props.disabled} onReset={props.onReset} /> : null}
|
|
434
|
+
</div>
|
|
435
|
+
<TextControl
|
|
436
|
+
id={props.id}
|
|
437
|
+
value={props.view.text}
|
|
438
|
+
placeholder={props.placeholder}
|
|
439
|
+
numeric={props.numeric}
|
|
440
|
+
invalid={invalid}
|
|
441
|
+
disabled={props.disabled}
|
|
442
|
+
onChange={props.onEdit}
|
|
443
|
+
onCommit={props.onCommit}
|
|
444
|
+
/>
|
|
445
|
+
<p style={HINT_STYLE}>{props.hint}</p>
|
|
446
|
+
{invalid ? <p style={INVALID_STYLE}>{props.copy.labels.invalidNumber}</p> : null}
|
|
447
|
+
</div>
|
|
448
|
+
)
|
|
449
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The copy both configuration surfaces render: row titles, hints, labels and
|
|
3
|
+
* the two page descriptions, in the host language when a translate seat exists
|
|
4
|
+
* and in the shipped Chinese dictionary otherwise.
|
|
5
|
+
* @module dsh-prompt-enhance/client/settings-page-copy
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
9
|
+
import { NS as LOCALE_NS, zh } from './locales'
|
|
10
|
+
import type { PromptEnhanceKey } from './locales'
|
|
11
|
+
import type { Row } from './settings-page-spec'
|
|
12
|
+
|
|
13
|
+
/** The translate seat the slot framework injects for the declared namespace. */
|
|
14
|
+
export type Translate = TranslateNS<typeof LOCALE_NS>
|
|
15
|
+
|
|
16
|
+
/** The shipped Chinese dictionary, used when a host projects no `t` seat. */
|
|
17
|
+
export const ZH_COPY: Readonly<Record<string, string>> = zh
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the Plugins-page copy reader: the injected `t` when present, the
|
|
21
|
+
* shipped Chinese dictionary otherwise. Falling back keeps an older host (or a
|
|
22
|
+
* test) from rendering dictionary keys instead of copy.
|
|
23
|
+
* @param t - the injected translate seat, if any.
|
|
24
|
+
* @returns a reader for this page's keys.
|
|
25
|
+
*/
|
|
26
|
+
export function translator(t: Translate | undefined): Translate {
|
|
27
|
+
if (typeof t === 'function') return t
|
|
28
|
+
// The fallback dictionary must interpolate `{name}` placeholders too, or a
|
|
29
|
+
// parameterized line would render its raw template.
|
|
30
|
+
return ((key: string, params?: Readonly<Record<string, unknown>>) => {
|
|
31
|
+
let text = ZH_COPY[key] ?? key
|
|
32
|
+
for (const [name, value] of Object.entries(params ?? {})) {
|
|
33
|
+
text = text.split(`{${name}}`).join(String(value))
|
|
34
|
+
}
|
|
35
|
+
return text
|
|
36
|
+
}) as unknown as Translate
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How one surface titles and explains the rows. */
|
|
40
|
+
export interface RowCopy {
|
|
41
|
+
/** Copy of the shared form frame, plus the labels the custom rows draw. */
|
|
42
|
+
readonly labels: Readonly<Record<string, string>>
|
|
43
|
+
/** The row's title. */
|
|
44
|
+
readonly title: (row: Row) => string
|
|
45
|
+
/** The hint under the row. */
|
|
46
|
+
readonly hint: (row: Row) => string
|
|
47
|
+
/** An example shown greyed out while the input is empty, when the row has one. */
|
|
48
|
+
readonly placeholder: (row: Row) => string | undefined
|
|
49
|
+
/** One choice label of a segmented control. */
|
|
50
|
+
readonly choice: (key: PromptEnhanceKey) => string
|
|
51
|
+
/** One parameterized status line (dynamic reasoning tiers). */
|
|
52
|
+
readonly interpolate: (key: PromptEnhanceKey, params: Record<string, string>) => string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The settings dialog's copy: the raw config key first, then the localized
|
|
57
|
+
* name in parentheses while the client is Chinese, and one single-language
|
|
58
|
+
* hint. English mode drops the parenthesized Chinese name entirely — the key
|
|
59
|
+
* alone is the title there.
|
|
60
|
+
* @param t - the locale-bound translate seat.
|
|
61
|
+
* @param chinese - whether the active locale is Chinese.
|
|
62
|
+
* @returns the row copy for that language.
|
|
63
|
+
*/
|
|
64
|
+
export function sectionCopy(t: Translate, chinese: boolean): RowCopy {
|
|
65
|
+
return {
|
|
66
|
+
labels: {
|
|
67
|
+
unavailable: t('settings.unavailable'),
|
|
68
|
+
readOnly: t('settings.readOnly'),
|
|
69
|
+
saveFailed: t('settings.saveFailed'),
|
|
70
|
+
saveFailedShort: t('settings.saveFailedShort'),
|
|
71
|
+
save: t('settings.save'),
|
|
72
|
+
saving: t('settings.saving'),
|
|
73
|
+
saved: t('settings.saved'),
|
|
74
|
+
advanced: t('settings.advanced'),
|
|
75
|
+
reset: t('settings.reset'),
|
|
76
|
+
invalidNumber: t('settings.invalidNumber'),
|
|
77
|
+
},
|
|
78
|
+
title: (row) => (chinese ? `${row.key}(${t(row.label)})` : row.key),
|
|
79
|
+
hint: (row) => t(row.hint),
|
|
80
|
+
placeholder: (row) => (row.placeholder === undefined ? undefined : t(row.placeholder)),
|
|
81
|
+
choice: (key) => t(key),
|
|
82
|
+
interpolate: (key, params) => t(key, params),
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The Plugins page's copy: the active locale's title and single-sentence hint,
|
|
88
|
+
* as the host's own configuration pages read.
|
|
89
|
+
* @param t - the injected translate seat.
|
|
90
|
+
* @returns the row copy for that locale.
|
|
91
|
+
*/
|
|
92
|
+
export function pageCopy(t: Translate): RowCopy {
|
|
93
|
+
return {
|
|
94
|
+
labels: {
|
|
95
|
+
unavailable: t('settings.unavailable'),
|
|
96
|
+
readOnly: t('settings.readOnly'),
|
|
97
|
+
saveFailed: t('settings.saveFailed'),
|
|
98
|
+
saveFailedShort: t('settings.saveFailedShort'),
|
|
99
|
+
save: t('settings.save'),
|
|
100
|
+
saving: t('settings.saving'),
|
|
101
|
+
saved: t('settings.saved'),
|
|
102
|
+
advanced: t('settings.advanced'),
|
|
103
|
+
reset: t('settings.reset'),
|
|
104
|
+
invalidNumber: t('settings.invalidNumber'),
|
|
105
|
+
},
|
|
106
|
+
title: (row) => t(row.label),
|
|
107
|
+
hint: (row) => t(row.hint),
|
|
108
|
+
placeholder: (row) => (row.placeholder === undefined ? undefined : t(row.placeholder)),
|
|
109
|
+
choice: (key) => t(key),
|
|
110
|
+
interpolate: (key, params) => t(key, params),
|
|
111
|
+
}
|
|
112
|
+
}
|