@surfishs/dsh-prompt-enhance 0.1.0 → 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.
@@ -14,10 +14,19 @@ import { ResultPanel } from './ResultPanel'
14
14
  import * as ui from './ui-state'
15
15
  import { useSessionKey } from './session-key'
16
16
  import { useDockAlignment } from './useDockAlignment'
17
+ import { getClientSettings, subscribeClientSettings } from './settings'
17
18
 
18
19
  /** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
19
20
  export type ResultDockProps = PropsRuntime<'conversation.input.dock'> & PropsLocale<'dsh-prompt-enhance'>
20
21
 
22
+ /**
23
+ * How long the regenerate button keeps the "regenerated" label.
24
+ *
25
+ * Matches the copy confirmation's window (`ResultPanel`'s copy handler uses the
26
+ * same 2500ms) so both transient confirmations feel like one system.
27
+ */
28
+ const REGENERATED_NOTICE_MS = 2500
29
+
21
30
  /** One session's enhancement card, docked above its composer. */
22
31
  export function ResultDock(props: ResultDockProps): ReactNode {
23
32
  const { t, sessionId, useInput, inputActions } = props
@@ -25,11 +34,8 @@ export function ResultDock(props: ResultDockProps): ReactNode {
25
34
  // host id for UI keying when present, else a stable per-mount fallback.
26
35
  const uiKey = useSessionKey(sessionId, inputActions)
27
36
  const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
37
+ const settings = useSyncExternalStore(subscribeClientSettings, getClientSettings)
28
38
  const rootRef = useDockAlignment(panel !== undefined && panel.sessionId === uiKey, uiKey)
29
- const [undone, setUndone] = useState(false)
30
- const [regenerated, setRegenerated] = useState(false)
31
- const [pendingRegenerate, setPendingRegenerate] = useState(false)
32
- const previousResultRef = useRef<unknown>(undefined)
33
39
  const draft = useInput((state) => {
34
40
  const value = (state as { draft?: unknown }).draft
35
41
  return typeof value === 'string' ? value : ''
@@ -63,12 +69,22 @@ export function ResultDock(props: ResultDockProps): ReactNode {
63
69
  : // eslint-disable-next-line react-hooks/rules-of-hooks
64
70
  Number(useSession((state) => (state as { queue?: unknown[] }).queue?.length ?? 0))
65
71
 
66
- // The applied chip is derived from the undo stack: it is true exactly while
72
+ // The applied state is derived from the undo stack: it is true exactly while
67
73
  // the composer still holds the applied text, and drops itself when the user
68
- // edits (the UndoBar drops the stale entry in the same situation).
74
+ // edits (the UndoBar drops the stale entry in the same situation). It drives
75
+ // the footer button (fill vs undo); the header shows no status chip.
69
76
  const entry = ui.peekUndo(uiKey)
70
77
  const applied = entry !== undefined && entry.applied === draft
71
78
 
79
+ // The regenerate button is HIDDEN while the next round streams, so its
80
+ // confirmation has to be a completion signal: it turns on only after a result
81
+ // that differs from the one the click captured arrives, and clears itself
82
+ // after REGENERATED_NOTICE_MS. A failure or a closed panel only drops the
83
+ // pending flag — there is no button to relabel in those states.
84
+ const [regeneratedNotice, setRegeneratedNotice] = useState(false)
85
+ const pendingRegenerate = useRef(false)
86
+ const previousResultRef = useRef<unknown>(undefined)
87
+
72
88
  // Sending the draft dismisses the card; the undo row can still take over.
73
89
  // The phase is checked where the host provides it; the session transition
74
90
  // (running false→true, or a new queued turn) is the fallback for hosts that
@@ -95,45 +111,27 @@ export function ResultDock(props: ResultDockProps): ReactNode {
95
111
  return () => document.removeEventListener('keydown', onKeyDown)
96
112
  }, [panel, uiKey])
97
113
 
98
- // The "undone" chip is transient: it confirms the undo for a moment, then
99
- // clears without needing another state change.
114
+ // Turn the completion signal into the transient label, and clear it on time.
115
+ // The two effects are separate on purpose: the first only watches the panel
116
+ // settling, the second only owns the timer, so a re-render of the panel cannot
117
+ // restart the countdown.
100
118
  useEffect(() => {
101
- if (!undone) return
102
- const timer = setTimeout(() => setUndone(false), 2500)
103
- return () => clearTimeout(timer)
104
- }, [undone])
105
-
106
- // "Regenerated" is a completion signal, not a click signal: wait until the
107
- // panel settles with a different result object, then show the chip briefly.
108
- useEffect(() => {
109
- if (!pendingRegenerate) return
110
- if (panel === undefined || panel.sessionId !== uiKey) {
111
- setPendingRegenerate(false)
112
- return
113
- }
114
- if (panel.phase === 'error') {
115
- setPendingRegenerate(false)
119
+ if (!pendingRegenerate.current) return
120
+ if (panel === undefined || panel.sessionId !== uiKey || panel.phase === 'error') {
121
+ pendingRegenerate.current = false
116
122
  return
117
123
  }
118
124
  if (panel.phase === 'result' && panel.result !== previousResultRef.current) {
119
- setPendingRegenerate(false)
120
- setRegenerated(true)
125
+ pendingRegenerate.current = false
126
+ setRegeneratedNotice(true)
121
127
  }
122
- }, [panel, pendingRegenerate, uiKey])
123
-
124
- useEffect(() => {
125
- if (!regenerated) return
126
- const timer = setTimeout(() => setRegenerated(false), 2500)
127
- return () => clearTimeout(timer)
128
- }, [regenerated])
128
+ }, [panel, uiKey])
129
129
 
130
- // A regenerate click on an empty draft is a no-op; do not leave the pending
131
- // flag stuck forever in that case.
132
130
  useEffect(() => {
133
- if (!pendingRegenerate) return
134
- const timer = setTimeout(() => setPendingRegenerate(false), 15000)
131
+ if (!regeneratedNotice) return
132
+ const timer = setTimeout(() => setRegeneratedNotice(false), REGENERATED_NOTICE_MS)
135
133
  return () => clearTimeout(timer)
136
- }, [pendingRegenerate])
134
+ }, [regeneratedNotice])
137
135
 
138
136
  if (panel === undefined || panel.sessionId !== uiKey) return null
139
137
 
@@ -145,23 +143,31 @@ export function ResultDock(props: ResultDockProps): ReactNode {
145
143
  // closing it falls back to the standalone undo row.
146
144
  ui.pushUndo(uiKey, { original: draft, applied: panel.result.text })
147
145
  inputActions.setDraft(panel.result.text)
148
- setUndone(false)
149
- setRegenerated(false)
146
+ // Fill first, fold second: the applied text is already in the composer, so
147
+ // the card can fold out of the way without hiding anything the user needs.
148
+ // Both steps honour the auto-fold setting (on by default) and setCollapsed
149
+ // is a no-op when the card is already in the requested state.
150
+ if (settings.autoFold) ui.setCollapsed(uiKey, true)
150
151
  }
151
152
 
152
153
  const undo = (): void => {
153
154
  if (entry === undefined) return
154
155
  inputActions.setDraft(entry.original)
155
156
  ui.popUndo(uiKey)
156
- setUndone(true)
157
- setRegenerated(false)
157
+ // Undo is the mirror of apply: the draft goes back to the user's text, so
158
+ // the card re-opens to show the result it belongs to. Expanding an already
159
+ // open card is a no-op, and the auto-fold setting governs this too.
160
+ if (settings.autoFold) ui.setCollapsed(uiKey, false)
158
161
  }
159
162
 
160
163
  const regenerate = (): void => {
161
164
  if (panel.phase !== 'result') return
165
+ // A click during the notice window starts a fresh round: drop the label now
166
+ // so the button shows its normal text before it disappears, and remember
167
+ // which result this round has to replace.
168
+ setRegeneratedNotice(false)
162
169
  previousResultRef.current = panel.result
163
- setRegenerated(false)
164
- setPendingRegenerate(true)
170
+ pendingRegenerate.current = true
165
171
  ui.runSession(uiKey)
166
172
  }
167
173
 
@@ -171,8 +177,10 @@ export function ResultDock(props: ResultDockProps): ReactNode {
171
177
  state={panel}
172
178
  t={t}
173
179
  applied={applied}
174
- undone={undone}
175
- regenerated={regenerated}
180
+ regenerated={regeneratedNotice}
181
+ collapsed={panel.collapsed === true}
182
+ onToggleCollapsed={() => ui.setCollapsed(uiKey, panel.collapsed !== true)}
183
+ foldAnimation={settings.foldAnimation}
176
184
  onApply={apply}
177
185
  onUndo={undo}
178
186
  onRegenerate={regenerate}
@@ -6,12 +6,12 @@
6
6
  * @module dsh-prompt-enhance/client/ResultPanel
7
7
  */
8
8
 
9
- import { useCallback, useState, type ReactNode } from 'react'
9
+ import { useCallback, useRef, useState, type ReactNode } from 'react'
10
10
  import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
11
11
  import type { EnhanceError, EnhanceUsage, ClientFailureReason } from '../shared/protocol'
12
12
  import type { PromptEnhanceKey } from './locales'
13
13
  import type { PanelState } from './ui-state'
14
- import { CopyIcon, FillIcon, RegenerateIcon, UndoIcon } from './ActionIcons'
14
+ import { ChevronIcon, CopyIcon, FillIcon, RegenerateIcon, UndoIcon, XIcon } from './ActionIcons'
15
15
  import { SparkleFishIcon } from './SparkleFishIcon'
16
16
 
17
17
  /** Props of the result card. */
@@ -30,14 +30,18 @@ export interface ResultPanelProps {
30
30
  onUndo?: () => void
31
31
  /** Run the same source prompt through the model again. */
32
32
  onRegenerate?: () => void
33
- /** Show the transient 'undone' chip after an undo. */
34
- undone?: boolean
35
- /** Show the transient 'regenerated' chip after a regenerate request settles. */
33
+ /** Show the transient "regenerated" label on that button instead of its normal text. */
36
34
  regenerated?: boolean
35
+ /** Hide the body, keeping the header and the footer rows (and their actions). */
36
+ collapsed?: boolean
37
+ /** Toggle {@link collapsed}. */
38
+ onToggleCollapsed?: () => void
39
+ /** Play the fold transition; false switches instantly (a setting). */
40
+ foldAnimation?: boolean
37
41
  }
38
42
 
39
- /** Whether one error phase is worth retrying (model/transport failures). */
40
- const retryable = (code: string | undefined): boolean => code === 'upstream' || code === 'timeout' || code === 'internal'
43
+ /** Whether one error phase is worth retrying: model/transport failures, but never a call the user cancelled. */
44
+ const retryable = (error: EnhanceError | undefined): boolean => error?.code === 'upstream' || error?.code === 'timeout' || (error?.code === 'internal' && error.params?.reason !== 'cancelled')
41
45
 
42
46
  /**
43
47
  * Wire `reason` (`UpstreamReason`, kebab-case as the host sends it) → the
@@ -154,6 +158,16 @@ function formatTokens(tokens: number): string {
154
158
  return tokens.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
155
159
  }
156
160
 
161
+ /**
162
+ * Title-case an adapter-owned effort id for the badge ("off" → "Off"). Ids are
163
+ * opaque strings, so only a leading ASCII letter is changed.
164
+ * @param value - the effort id the host reported.
165
+ * @returns the label shown in the badge.
166
+ */
167
+ function capitalizeEffort(value: string): string {
168
+ return value.charAt(0).toUpperCase() + value.slice(1)
169
+ }
170
+
157
171
  /**
158
172
  * The call's billed total: the provider's own number when it reported one,
159
173
  * otherwise the disjoint counters added up (uncached input + output + cache
@@ -165,15 +179,21 @@ function totalTokensOf(usage: EnhanceUsage): number {
165
179
 
166
180
  /** One enhancement result card. */
167
181
  export function ResultPanel(props: ResultPanelProps): ReactNode {
168
- const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, undone = false, regenerated = false } = props
182
+ const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, regenerated = false, collapsed = false, onToggleCollapsed, foldAnimation = true } = props
169
183
  const [copied, setCopied] = useState<'idle' | 'ok' | 'failed'>('idle')
184
+ /** Pending reset of the copy label; one timer only, so a second copy cannot be cut short by the first. */
185
+ const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
170
186
 
171
187
  const copy = useCallback((): void => {
172
188
  if (state.result === undefined) return
173
189
  const text = state.result.text
174
190
  const done = (ok: boolean): void => {
175
191
  setCopied(ok ? 'ok' : 'failed')
176
- if (ok) setTimeout(() => setCopied('idle'), 2500)
192
+ // Both outcomes are transient. A failure used to stay on the button until
193
+ // the next click, which reads as a stuck control rather than an error; the
194
+ // label now clears the same way a success does.
195
+ if (copyTimer.current !== undefined) clearTimeout(copyTimer.current)
196
+ copyTimer.current = setTimeout(() => setCopied('idle'), 2500)
177
197
  }
178
198
  // navigator.clipboard only exists in secure contexts (https / localhost);
179
199
  // guard the dereference and fall back for plain-http LAN access.
@@ -205,8 +225,26 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
205
225
  return parts.join(' · ')
206
226
  }
207
227
 
228
+ /**
229
+ * One label of a swap group.
230
+ *
231
+ * Every label of the group sits in the same `.dsh-pe-swap` grid cell, so the
232
+ * widest label of the active language defines the button width and swapping
233
+ * the visible one cannot resize the button or shift the footer. Only the
234
+ * active label is painted; `aria-hidden` keeps the inert ones out of the
235
+ * accessibility tree even before the stylesheet applies.
236
+ * @param active - whether this label is the one currently shown.
237
+ * @param text - the label text.
238
+ * @returns the label element.
239
+ */
240
+ const swapLabel = (active: boolean, text: string): ReactNode => (
241
+ <span className={active ? 'on' : undefined} aria-hidden={active ? undefined : true}>
242
+ {text}
243
+ </span>
244
+ )
245
+
208
246
  return (
209
- <section className="dsh-pe-panel" role="region" aria-label={t('panel.title')}>
247
+ <section className={`dsh-pe-panel${collapsed ? ' is-collapsed' : ''}${foldAnimation ? '' : ' is-static'}`} role="region" aria-label={t('panel.title')}>
210
248
  <header className="dsh-pe-head">
211
249
  <span className="dsh-pe-title">
212
250
  <SparkleFishIcon size={15} />
@@ -215,7 +253,15 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
215
253
  <div className="dsh-pe-head-actions">
216
254
  {state.phase === 'result' && state.result !== undefined && (
217
255
  <span className="dsh-pe-badge">
218
- {t('panel.model', { provider: state.result.provider, model: state.result.model })} · {t('panel.elapsed', { ms: formatMs(state.result.elapsedMs) })}
256
+ {t('panel.model', { provider: state.result.provider, model: state.result.model })}
257
+ {state.result.reasoningEffort === undefined ? null : (
258
+ <>
259
+ {' · '}
260
+ {state.result.reasoningEffort === 'inherit' ? t('panel.effortDefault') : capitalizeEffort(state.result.reasoningEffort)}
261
+ </>
262
+ )}
263
+ {' · '}
264
+ {t('panel.elapsed', { ms: formatMs(state.result.elapsedMs) })}
219
265
  {state.result.usage === undefined ? null : (
220
266
  <>
221
267
  {' · '}
@@ -224,101 +270,125 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
224
270
  )}
225
271
  </span>
226
272
  )}
227
- {copied === 'ok' ? (
228
- <span className="dsh-pe-applied">{t('panel.copiedShort')}</span>
229
- ) : regenerated ? (
230
- <span className="dsh-pe-applied">{t('panel.regeneratedShort')}</span>
231
- ) : applied ? (
232
- <span className="dsh-pe-applied">{t('panel.appliedShort')}</span>
233
- ) : undone ? (
234
- <span className="dsh-pe-applied">{t('panel.undoneShort')}</span>
273
+ {/* Collapsed, the body — and with it the warnings — is hidden, so the
274
+ header carries a marker instead of silently swallowing one. */}
275
+ {collapsed && (state.stale === true || state.result?.truncated === true) ? (
276
+ <span className="dsh-pe-warn-dot" title={state.stale === true ? t('panel.stale.warn') : t('panel.truncated')} aria-hidden="true">
277
+ ⚠
278
+ </span>
235
279
  ) : null}
280
+ <button type="button" className="dsh-pe-collapse" aria-label={collapsed ? t('panel.expand') : t('panel.collapse')} aria-expanded={!collapsed} onClick={onToggleCollapsed}>
281
+ <ChevronIcon open={!collapsed} />
282
+ </button>
236
283
  <button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>
237
- ✕
284
+ <XIcon />
238
285
  </button>
239
286
  </div>
240
287
  </header>
241
288
 
242
- {state.phase === 'loading' && (
243
- <div className="dsh-pe-loading">
244
- {state.streaming === undefined || state.streaming === '' ? (
245
- <>
246
- <div className="dsh-pe-spin" aria-hidden />
247
- <div>{t('panel.loading')}</div>
248
- <div className="dsh-pe-hint">{t('panel.loading.hint')}</div>
249
- </>
250
- ) : (
251
- <div className="dsh-pe-stream">
252
- <div className="dsh-pe-col-title">
253
- <span className="dsh-pe-spin small" aria-hidden />
254
- {t('panel.streaming')}
255
- </div>
256
- <pre className="dsh-pe-result-text">{state.streaming}</pre>
289
+ {/* The body keeps the header above and the footer below; only it folds.
290
+ It stays mounted so the fold can animate (grid track 1fr ↔ 0fr) and the
291
+ result's scroll position survives a fold. Collapsed, the CSS hides it
292
+ from painting, selection and assistive tech. */}
293
+ <div className="dsh-pe-body" aria-hidden={collapsed || undefined}>
294
+ <div className="dsh-pe-body-inner">
295
+ {state.phase === 'loading' && (
296
+ <div className="dsh-pe-loading">
297
+ {state.streaming === undefined || state.streaming === '' ? (
298
+ <>
299
+ <div className="dsh-pe-spin" aria-hidden />
300
+ <div>{t('panel.loading')}</div>
301
+ <div className="dsh-pe-hint">{t('panel.loading.hint')}</div>
302
+ </>
303
+ ) : (
304
+ <div className="dsh-pe-stream">
305
+ <div className="dsh-pe-col-title">
306
+ <span className="dsh-pe-spin small" aria-hidden />
307
+ {t('panel.streaming')}
308
+ </div>
309
+ <pre className="dsh-pe-result-text">{state.streaming}</pre>
310
+ </div>
311
+ )}
257
312
  </div>
258
313
  )}
259
- </div>
260
- )}
261
314
 
262
- {state.phase === 'error' && state.error !== undefined && (
263
- <div className="dsh-pe-error">
264
- {state.error.localized !== undefined ? (
265
- <div>{state.error.localized}</div>
266
- ) : (
267
- <>
268
- <div>{localizedErrorMessage(t, state.error.code, state.error.params)}</div>
269
- {state.error.message !== undefined && state.error.message !== '' && <div className="dsh-pe-error-detail">{state.error.message}</div>}
270
- </>
315
+ {state.phase === 'error' && state.error !== undefined && (
316
+ <div className="dsh-pe-error">
317
+ {state.error.localized !== undefined ? (
318
+ <div>{state.error.localized}</div>
319
+ ) : (
320
+ <>
321
+ <div>{localizedErrorMessage(t, state.error.code, state.error.params)}</div>
322
+ {state.error.message !== undefined && state.error.message !== '' && <div className="dsh-pe-error-detail">{state.error.message}</div>}
323
+ </>
324
+ )}
325
+ </div>
271
326
  )}
272
- </div>
273
- )}
274
327
 
275
- {state.phase === 'result' && state.result !== undefined && (
276
- <div className="dsh-pe-result">
277
- <pre className="dsh-pe-result-text">{state.result.text}</pre>
278
- </div>
279
- )}
328
+ {state.phase === 'result' && state.result !== undefined && (
329
+ <div className="dsh-pe-result">
330
+ <pre className="dsh-pe-result-text">{state.result.text}</pre>
331
+ </div>
332
+ )}
280
333
 
281
- {state.phase === 'result' && state.result?.truncated === true && <div className="dsh-pe-stale">⚠ {t('panel.truncated')}</div>}
334
+ {state.phase === 'result' && state.result?.truncated === true && <div className="dsh-pe-stale">⚠ {t('panel.truncated')}</div>}
282
335
 
283
- {state.phase === 'result' && state.stale && <div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>}
336
+ {state.phase === 'result' && state.stale && <div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>}
337
+ </div>
338
+ </div>
284
339
 
285
340
  <footer className="dsh-pe-foot">
286
341
  <span className="dsh-pe-grow" />
287
342
  {state.phase === 'result' && (
288
- <button type="button" className="dsh-pe-btn-action plain" onClick={onRegenerate} disabled={onRegenerate === undefined}>
343
+ <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-floor" onClick={onRegenerate} disabled={onRegenerate === undefined}>
289
344
  <RegenerateIcon />
290
- {t('panel.regenerate')}
345
+ <span className="dsh-pe-swap">
346
+ {swapLabel(!regenerated, t('panel.regenerate'))}
347
+ {swapLabel(regenerated, t('panel.regenerated'))}
348
+ </span>
291
349
  </button>
292
350
  )}
293
351
  {state.phase === 'error' && (
294
352
  <>
295
- {retryable(state.error?.code) && onRetry !== undefined && (
296
- <button type="button" className="dsh-pe-btn-action plain" onClick={onRetry}>
353
+ {retryable(state.error) && onRetry !== undefined && (
354
+ <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-floor" onClick={onRetry}>
297
355
  {t('panel.retry')}
298
356
  </button>
299
357
  )}
300
358
  </>
301
359
  )}
302
360
  {state.phase === 'loading' && (
303
- <button type="button" className="dsh-pe-btn-action plain" onClick={onCancel}>
361
+ <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-floor" onClick={onCancel}>
304
362
  {t('panel.cancel')}
305
363
  </button>
306
364
  )}
307
365
  {state.phase === 'result' && (
308
366
  <>
309
- <button type="button" className="dsh-pe-btn-action plain dsh-pe-copy" onClick={copy}>
367
+ <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-floor" onClick={copy}>
310
368
  <CopyIcon />
311
- {copied === 'ok' ? t('panel.copied') : copied === 'failed' ? t('panel.copyFailed') : t('panel.copy')}
369
+ <span className="dsh-pe-swap">
370
+ {swapLabel(copied === 'idle', t('panel.copy'))}
371
+ {swapLabel(copied === 'ok', t('panel.copied'))}
372
+ {swapLabel(copied === 'failed', t('panel.copyFailed'))}
373
+ </span>
312
374
  </button>
313
375
  {applied ? (
314
- <button type="button" className="dsh-pe-btn-action primary" onClick={onUndo} disabled={onUndo === undefined}>
376
+ <button type="button" className="dsh-pe-btn-action primary dsh-pe-btn-floor" onClick={onUndo} disabled={onUndo === undefined}>
315
377
  <UndoIcon />
316
- {t('undo.undo')}
378
+ {/* The undo label reserves the width of the fill label it replaces,
379
+ so switching between the two does not resize the footer. */}
380
+ <span className="dsh-pe-swap">
381
+ {swapLabel(true, t('undo.undo'))}
382
+ {swapLabel(false, t('panel.apply'))}
383
+ </span>
317
384
  </button>
318
385
  ) : (
319
- <button type="button" className="dsh-pe-btn-action primary" onClick={onApply}>
386
+ <button type="button" className="dsh-pe-btn-action primary dsh-pe-btn-floor" onClick={onApply}>
320
387
  <FillIcon />
321
- {t('panel.apply')}
388
+ <span className="dsh-pe-swap">
389
+ {swapLabel(true, t('panel.apply'))}
390
+ {swapLabel(false, t('undo.undo'))}
391
+ </span>
322
392
  </button>
323
393
  )}
324
394
  </>
@@ -12,7 +12,7 @@ import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots
12
12
  import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
13
13
  import * as ui from './ui-state'
14
14
  import { useSessionKey } from './session-key'
15
- import { UndoIcon } from './ActionIcons'
15
+ import { CheckIcon, UndoIcon } from './ActionIcons'
16
16
  import { useDockAlignment } from './useDockAlignment'
17
17
 
18
18
  /** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
@@ -58,7 +58,7 @@ export function UndoBar(props: UndoBarProps): ReactNode {
58
58
  <div ref={rootRef} className="dsh-pe-dock">
59
59
  <div className="dsh-pe-undo">
60
60
  <span className="dsh-pe-undo-check" aria-hidden>
61
- ✓
61
+ <CheckIcon />
62
62
  </span>
63
63
  <span>{t('undo.applied')}</span>
64
64
  <button type="button" className="dsh-pe-undo-link" onClick={undo}>
@@ -109,6 +109,10 @@ function parseResult(value: unknown): EnhanceResult {
109
109
  // the UI never seeing it. Only `true` is ever normalized in, matching the
110
110
  // host, which sets the field solely on a capped finish.
111
111
  ...(record.truncated === true ? { truncated: true } : {}),
112
+ // Same trap as runcated above: rebuilding the object field by field
113
+ // drops anything not listed here, so a new result field has to be added
114
+ // in this exact place or the UI silently never sees it.
115
+ ...(typeof record.reasoningEffort === 'string' ? { reasoningEffort: record.reasoningEffort } : {}),
112
116
  }
113
117
  }
114
118
  throw new EnhanceClientError({ code: 'internal', params: { reason: 'malformed' } })
@@ -15,6 +15,7 @@
15
15
  * @module dsh-prompt-enhance/client
16
16
  */
17
17
 
18
+ import type { ReactNode } from 'react'
18
19
  import type { Context as ClientContext } from '@deepseek-ai/cordis'
19
20
  import type {} from '@deepseek-ai/dsh-client-ui-slots'
20
21
  import type {} from '@deepseek-ai/dsh-client-locale/client'
@@ -26,6 +27,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
26
27
  import type {} from '@deepseek-ai/dsh-client-ui-session/client'
27
28
  import type {} from '@deepseek-ai/dsh-client-store'
28
29
  import { EnhanceButton } from './EnhanceButton'
30
+ import type { EnhanceButtonProps } from './EnhanceButton'
29
31
  import { ResultDock } from './ResultDock'
30
32
  import { UndoBar } from './UndoBar'
31
33
  import * as ui from './ui-state'
@@ -129,7 +131,12 @@ export function apply(ctx: ClientContext): void {
129
131
  if (slots === undefined) return
130
132
  return slots.inject('conversation.input.right', () => {
131
133
  try {
132
- return slots.register({ name: 'conversation.input.right', id: 'dsh-prompt-enhance', order: 60, locale: NS }, EnhanceButton as unknown as never)
134
+ // The quick-settings menu needs the client context (model directories)
135
+ // but slot components only receive their standard props, so hand the
136
+ // context down through the closure — the same shape other composer
137
+ // plugins in this ecosystem use.
138
+ const Bound = (buttonProps: EnhanceButtonProps): ReactNode => <EnhanceButton {...buttonProps} __ctx={ctx as never} />
139
+ return slots.register({ name: 'conversation.input.right', id: 'dsh-prompt-enhance', order: 60, locale: NS }, Bound as unknown as never)
133
140
  } catch (error) {
134
141
  return report('composer enhance button slot', error)
135
142
  }
@@ -35,6 +35,31 @@ async function getJson<T>(url: URL, signal?: AbortSignal): Promise<T | undefined
35
35
  }
36
36
  }
37
37
 
38
+ /**
39
+ * How long one catalog answer stays usable. Provider/model names change only
40
+ * when the host registry does, so a short window is enough to make repeated
41
+ * card opens and page mounts free without showing stale names for long.
42
+ */
43
+ export const CATALOG_TTL_MS = 60_000
44
+
45
+ /** One memoized answer. */
46
+ interface Memo<T> {
47
+ value: T
48
+ at: number
49
+ }
50
+
51
+ let providersMemo: Memo<ProviderCatalogEntry[]> | undefined
52
+ const modelsMemo = new Map<string, Memo<ModelCatalog>>()
53
+
54
+ /**
55
+ * Drop every memoized catalog answer. The settings reload controls bypass the
56
+ * cache per call; tests and deployments that swap the registry call this.
57
+ */
58
+ export function clearCatalogCache(): void {
59
+ providersMemo = undefined
60
+ modelsMemo.clear()
61
+ }
62
+
38
63
  /** Resolve one endpoint against the current page origin. */
39
64
  function endpoint(path: string, params: Record<string, string> = {}): URL {
40
65
  const url = new URL(path, globalThis.location?.origin ?? 'http://127.0.0.1')
@@ -42,18 +67,38 @@ function endpoint(path: string, params: Record<string, string> = {}): URL {
42
67
  return url
43
68
  }
44
69
 
45
- /** Registered + dormant providers, or undefined when the read failed. */
46
- export async function fetchProviders(signal?: AbortSignal): Promise<ProviderCatalogEntry[] | undefined> {
70
+ /**
71
+ * Registered + dormant providers, or undefined when the read failed.
72
+ * @param signal - cancels the request.
73
+ * @param options - `refresh` bypasses the short-lived memo.
74
+ * @returns the provider entries, or undefined on failure (failures are not cached).
75
+ */
76
+ export async function fetchProviders(signal?: AbortSignal, options: { refresh?: boolean } = {}): Promise<ProviderCatalogEntry[] | undefined> {
77
+ const cached = providersMemo
78
+ if (options.refresh !== true && cached !== undefined && Date.now() - cached.at <= CATALOG_TTL_MS) return cached.value
47
79
  const value = await getJson<ProviderCatalog>(endpoint(LLM_PROVIDERS_ENDPOINT), signal)
48
80
  if (value === undefined || !Array.isArray(value.providers)) return undefined
49
- return value.providers.filter(
81
+ const providers = value.providers.filter(
50
82
  (entry): entry is ProviderCatalogEntry =>
51
83
  entry !== null && typeof entry === 'object' && typeof entry.id === 'string' && entry.id !== '' && typeof entry.name === 'string' && entry.name !== '' && typeof entry.registered === 'boolean',
52
84
  )
85
+ providersMemo = { value: providers, at: Date.now() }
86
+ return providers
53
87
  }
54
88
 
55
- /** Models of one provider, or undefined when the read failed. */
56
- export async function fetchModels(provider: string, signal?: AbortSignal): Promise<ModelCatalog | undefined> {
89
+ /**
90
+ * Models of one provider, or undefined when the read failed.
91
+ *
92
+ * An empty list is not memoized: it is what a transient adapter failure looks
93
+ * like, and caching it would keep the select empty for the whole window.
94
+ * @param provider - provider id.
95
+ * @param signal - cancels the request.
96
+ * @param options - `refresh` bypasses the short-lived memo.
97
+ * @returns the catalog, or undefined on failure.
98
+ */
99
+ export async function fetchModels(provider: string, signal?: AbortSignal, options: { refresh?: boolean } = {}): Promise<ModelCatalog | undefined> {
100
+ const cached = modelsMemo.get(provider)
101
+ if (options.refresh !== true && cached !== undefined && Date.now() - cached.at <= CATALOG_TTL_MS) return cached.value
57
102
  const value = await getJson<ModelCatalog>(endpoint(LLM_MODELS_ENDPOINT, { provider }), signal)
58
103
  if (value === undefined || !Array.isArray(value.models)) return undefined
59
104
  const models = value.models
@@ -65,7 +110,9 @@ export async function fetchModels(provider: string, signal?: AbortSignal): Promi
65
110
  name: entry.name,
66
111
  ...(typeof entry.description === 'string' && entry.description !== '' ? { description: entry.description } : {}),
67
112
  }))
68
- return { models, ...(typeof value.reason === 'string' ? { reason: value.reason as ModelCatalog['reason'] } : {}) }
113
+ const answer: ModelCatalog = { models, ...(typeof value.reason === 'string' ? { reason: value.reason as ModelCatalog['reason'] } : {}) }
114
+ if (models.length > 0) modelsMemo.set(provider, { value: answer, at: Date.now() })
115
+ return answer
69
116
  }
70
117
 
71
118
  /** Whether one exact route resolves; undefined when the check itself failed. */
@@ -110,7 +157,7 @@ export function useLlmRouting(provider: string, model: string): LlmRoutingState
110
157
  const controller = new AbortController()
111
158
  setProvidersLoading(true)
112
159
  setProvidersFailed(false)
113
- void fetchProviders(controller.signal).then((entries) => {
160
+ void fetchProviders(controller.signal, { refresh: providersToken > 0 }).then((entries) => {
114
161
  if (controller.signal.aborted) return
115
162
  setProvidersLoading(false)
116
163
  if (entries === undefined) {
@@ -134,7 +181,7 @@ export function useLlmRouting(provider: string, model: string): LlmRoutingState
134
181
  setModels([])
135
182
  setModelsLoading(true)
136
183
  setModelsFailed(false)
137
- void fetchModels(provider, controller.signal).then((answer) => {
184
+ void fetchModels(provider, controller.signal, { refresh: modelsToken > 0 }).then((answer) => {
138
185
  if (controller.signal.aborted) return
139
186
  setModelsLoading(false)
140
187
  if (answer === undefined) {