@surfishs/dsh-prompt-enhance 0.0.2 → 0.0.3
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 +672 -445
- package/lib/index.js +9 -2
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
- package/src/client/ActionIcons.tsx +61 -0
- package/src/client/EnhanceButton.tsx +24 -56
- package/src/client/ResultDock.tsx +261 -0
- package/src/client/ResultPanel.tsx +149 -177
- package/src/client/SparkleFishIcon.tsx +41 -0
- package/src/client/SparkleIcon.tsx +33 -0
- package/src/client/UndoBar.tsx +4 -0
- package/src/client/index.tsx +16 -0
- package/src/client/locales.ts +18 -4
- package/src/client/styles.ts +75 -48
- package/src/client/ui-state.ts +7 -2
- package/src/enhancer.ts +11 -2
- package/src/shared/protocol.ts +2 -0
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The enhancement card: header with model/usage meta, the enhanced body (or
|
|
3
|
+
* the streamed text / error), and the apply/undo/copy/close actions. It is a
|
|
4
|
+
* plain non-modal region rendered inside the composer dock, not a dialog:
|
|
5
|
+
* the dock wrapper owns session ownership, keyboard handling and auto-close.
|
|
6
6
|
* @module dsh-prompt-enhance/client/ResultPanel
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { useCallback,
|
|
9
|
+
import { useCallback, useState, type ReactNode } from 'react'
|
|
10
10
|
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
11
11
|
import type { EnhanceError, EnhanceUsage } 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'
|
|
15
|
+
import { SparkleFishIcon } from './SparkleFishIcon'
|
|
14
16
|
|
|
15
|
-
/** Props of the
|
|
17
|
+
/** Props of the result card. */
|
|
16
18
|
export interface ResultPanelProps {
|
|
17
19
|
state: PanelState
|
|
18
20
|
t: TranslateNS<'dsh-prompt-enhance'>
|
|
19
|
-
/** Fill the enhanced text back into the composer
|
|
21
|
+
/** Fill the enhanced text back into the composer; the card stays visible. */
|
|
20
22
|
onApply: () => void
|
|
21
23
|
/** Close without touching the composer (also aborts an in-flight call). */
|
|
22
24
|
onCancel: () => void
|
|
23
25
|
/** Retry after a retryable error; undefined in non-error phases. */
|
|
24
26
|
onRetry?: () => void
|
|
27
|
+
/** True once the enhanced text is the composer's current draft. */
|
|
28
|
+
applied?: boolean
|
|
29
|
+
/** Restore the pre-apply draft; only meaningful while `applied`. */
|
|
30
|
+
onUndo?: () => void
|
|
31
|
+
/** Run the same source prompt through the model again. */
|
|
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. */
|
|
36
|
+
regenerated?: boolean
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/** Whether one error phase is worth retrying (model/transport failures). */
|
|
@@ -105,79 +117,32 @@ function fallbackCopy(text: string): boolean {
|
|
|
105
117
|
}
|
|
106
118
|
}
|
|
107
119
|
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const panelRef = useRef<HTMLElement | null>(null)
|
|
113
|
-
|
|
114
|
-
// Keyboard handling: Escape closes (cancels) the panel — except during IME
|
|
115
|
-
// composition, where Esc cancels candidate input — and Tab cycles inside
|
|
116
|
-
// the dialog so focus cannot escape to the page beneath.
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
const onKeyDown = (event: KeyboardEvent): void => {
|
|
119
|
-
if (event.isComposing) return
|
|
120
|
-
if (event.key === 'Escape' && !event.defaultPrevented) {
|
|
121
|
-
event.preventDefault()
|
|
122
|
-
onCancel()
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
if (event.key === 'Tab') {
|
|
126
|
-
const panel = panelRef.current
|
|
127
|
-
if (panel === null) return
|
|
128
|
-
const focusables = panel.querySelectorAll<HTMLElement>('button:not([disabled]), [href], input, [tabindex]:not([tabindex="-1"])')
|
|
129
|
-
const first = focusables[0]
|
|
130
|
-
const last = focusables[focusables.length - 1]
|
|
131
|
-
if (first === undefined || last === undefined) return
|
|
132
|
-
const active = document.activeElement
|
|
133
|
-
// The panel takes focus on open, and its root is deliberately
|
|
134
|
-
// `tabIndex={-1}` — so it is neither `first` nor `last`. Testing only
|
|
135
|
-
// for the endpoints let Shift+Tab walk out of the dialog from that
|
|
136
|
-
// starting position (the forward direction happened to be covered by
|
|
137
|
-
// the `[tabindex="-1"]` filter). Treat the root as "before first", so
|
|
138
|
-
// both directions wrap from wherever focus actually starts.
|
|
139
|
-
const atRoot = active === panel
|
|
140
|
-
if (event.shiftKey && (active === first || atRoot)) {
|
|
141
|
-
event.preventDefault()
|
|
142
|
-
last.focus()
|
|
143
|
-
} else if (!event.shiftKey && active === last) {
|
|
144
|
-
event.preventDefault()
|
|
145
|
-
first.focus()
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
document.addEventListener('keydown', onKeyDown)
|
|
150
|
-
return () => document.removeEventListener('keydown', onKeyDown)
|
|
151
|
-
}, [onCancel])
|
|
120
|
+
/** Group thousands so a five-digit token count stays readable. */
|
|
121
|
+
function formatTokens(tokens: number): string {
|
|
122
|
+
return tokens.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
123
|
+
}
|
|
152
124
|
|
|
153
|
-
|
|
154
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The call's billed total: the provider's own number when it reported one,
|
|
127
|
+
* otherwise the disjoint counters added up (uncached input + output + cache
|
|
128
|
+
* reads/writes).
|
|
129
|
+
*/
|
|
130
|
+
function totalTokensOf(usage: EnhanceUsage): number {
|
|
131
|
+
return usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0)
|
|
132
|
+
}
|
|
155
133
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// itself and hand focus straight back out, neutering the Tab trap and the
|
|
161
|
-
// Escape handler below.
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
openerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null
|
|
164
|
-
panelRef.current?.focus()
|
|
165
|
-
return () => {
|
|
166
|
-
const opener = openerRef.current
|
|
167
|
-
openerRef.current = null
|
|
168
|
-
// Hand focus back to the opener, but never steal it from wherever the
|
|
169
|
-
// user has since moved it (the document body means focus was dropped,
|
|
170
|
-
// not moved on purpose).
|
|
171
|
-
if (opener === null || !opener.isConnected) return
|
|
172
|
-
const active = document.activeElement
|
|
173
|
-
if (active === null || active === document.body) opener.focus()
|
|
174
|
-
}
|
|
175
|
-
}, [])
|
|
134
|
+
/** One enhancement result card. */
|
|
135
|
+
export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
136
|
+
const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, undone = false, regenerated = false } = props
|
|
137
|
+
const [copied, setCopied] = useState<'idle' | 'ok' | 'failed'>('idle')
|
|
176
138
|
|
|
177
139
|
const copy = useCallback((): void => {
|
|
178
140
|
if (state.result === undefined) return
|
|
179
141
|
const text = state.result.text
|
|
180
|
-
const done = (ok: boolean): void =>
|
|
142
|
+
const done = (ok: boolean): void => {
|
|
143
|
+
setCopied(ok ? 'ok' : 'failed')
|
|
144
|
+
if (ok) setTimeout(() => setCopied('idle'), 2500)
|
|
145
|
+
}
|
|
181
146
|
// navigator.clipboard only exists in secure contexts (https / localhost);
|
|
182
147
|
// guard the dereference and fall back for plain-http LAN access.
|
|
183
148
|
if (navigator.clipboard !== undefined) {
|
|
@@ -188,15 +153,6 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
188
153
|
}, [state.result])
|
|
189
154
|
|
|
190
155
|
const formatMs = (ms: number): string => (ms < 1000 ? `${ms}ms` : `${(ms / 1000).toFixed(1)}s`)
|
|
191
|
-
/** Group thousands so a five-digit token count stays readable. */
|
|
192
|
-
const formatTokens = (tokens: number): string => tokens.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
193
|
-
/**
|
|
194
|
-
* The call's billed total: the provider's own number when it reported one,
|
|
195
|
-
* otherwise the disjoint counters added up (uncached input + output +
|
|
196
|
-
* cache reads/writes).
|
|
197
|
-
*/
|
|
198
|
-
const totalTokensOf = (usage: EnhanceUsage): number =>
|
|
199
|
-
usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0)
|
|
200
156
|
|
|
201
157
|
/**
|
|
202
158
|
* The tooltip under the token total. Input and output always appear; a cache
|
|
@@ -218,107 +174,123 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
218
174
|
}
|
|
219
175
|
|
|
220
176
|
return (
|
|
221
|
-
<
|
|
222
|
-
<
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
{' · '}
|
|
240
|
-
<span
|
|
241
|
-
title={tokenDetail(state.result.usage)}
|
|
242
|
-
>
|
|
243
|
-
{t('panel.tokens', { total: formatTokens(totalTokensOf(state.result.usage)) })}
|
|
244
|
-
</span>
|
|
245
|
-
</>
|
|
246
|
-
)}
|
|
247
|
-
</span>
|
|
248
|
-
)}
|
|
249
|
-
<button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>✕</button>
|
|
250
|
-
</header>
|
|
251
|
-
{state.phase === 'loading' && (
|
|
252
|
-
<div className="dsh-pe-loading">
|
|
253
|
-
{state.streaming === undefined || state.streaming === '' ? (
|
|
254
|
-
<>
|
|
255
|
-
<div className="dsh-pe-spin" aria-hidden />
|
|
256
|
-
<div>{t('panel.loading')}</div>
|
|
257
|
-
<div className="dsh-pe-hint">{t('panel.loading.hint')}</div>
|
|
258
|
-
</>
|
|
259
|
-
) : (
|
|
260
|
-
// Incremental view: the text already generated, replaced by the
|
|
261
|
-
// normalized full body the moment the call settles.
|
|
262
|
-
<div className="dsh-pe-stream">
|
|
263
|
-
<div className="dsh-pe-col-title">
|
|
264
|
-
<span className="dsh-pe-spin small" aria-hidden />
|
|
265
|
-
{t('panel.streaming')}
|
|
266
|
-
</div>
|
|
267
|
-
<pre className="dsh-pe-col-text">{state.streaming}</pre>
|
|
268
|
-
</div>
|
|
269
|
-
)}
|
|
270
|
-
</div>
|
|
271
|
-
)}
|
|
272
|
-
{state.phase === 'error' && state.error !== undefined && (
|
|
273
|
-
<div className="dsh-pe-error">
|
|
274
|
-
{state.error.localized !== undefined ? (
|
|
275
|
-
// Client-side guard failures carry their own pre-localized copy.
|
|
276
|
-
<div>{state.error.localized}</div>
|
|
277
|
-
) : (
|
|
278
|
-
<>
|
|
279
|
-
<div>{localizedErrorMessage(t, state.error.code, state.error.params)}</div>
|
|
280
|
-
{state.error.message !== undefined && state.error.message !== '' && (
|
|
281
|
-
<div className="dsh-pe-error-detail">{state.error.message}</div>
|
|
177
|
+
<section className="dsh-pe-panel" role="region" aria-label={t('panel.title')}>
|
|
178
|
+
<header className="dsh-pe-head">
|
|
179
|
+
<span className="dsh-pe-title">
|
|
180
|
+
<SparkleFishIcon size={15} />
|
|
181
|
+
{t('panel.title')}
|
|
182
|
+
</span>
|
|
183
|
+
{state.phase === 'result' && state.result !== undefined && (
|
|
184
|
+
<span className="dsh-pe-badge">
|
|
185
|
+
{t('panel.model', { provider: state.result.provider, model: state.result.model })} · {t('panel.elapsed', { ms: formatMs(state.result.elapsedMs) })}
|
|
186
|
+
{state.result.usage === undefined
|
|
187
|
+
? null
|
|
188
|
+
: (
|
|
189
|
+
<>
|
|
190
|
+
{' · '}
|
|
191
|
+
<span title={tokenDetail(state.result.usage)}>
|
|
192
|
+
{t('panel.tokens', { total: formatTokens(totalTokensOf(state.result.usage)) })}
|
|
193
|
+
</span>
|
|
194
|
+
</>
|
|
282
195
|
)}
|
|
283
|
-
|
|
284
|
-
)}
|
|
285
|
-
</div>
|
|
196
|
+
</span>
|
|
286
197
|
)}
|
|
287
|
-
{
|
|
288
|
-
<
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
198
|
+
{copied === 'ok'
|
|
199
|
+
? <span className="dsh-pe-applied">{t('panel.copiedShort')}</span>
|
|
200
|
+
: regenerated
|
|
201
|
+
? <span className="dsh-pe-applied">{t('panel.regeneratedShort')}</span>
|
|
202
|
+
: applied
|
|
203
|
+
? <span className="dsh-pe-applied">{t('panel.appliedShort')}</span>
|
|
204
|
+
: undone
|
|
205
|
+
? <span className="dsh-pe-applied">{t('panel.undoneShort')}</span>
|
|
206
|
+
: null}
|
|
207
|
+
<button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>✕</button>
|
|
208
|
+
</header>
|
|
209
|
+
|
|
210
|
+
{state.phase === 'loading' && (
|
|
211
|
+
<div className="dsh-pe-loading">
|
|
212
|
+
{state.streaming === undefined || state.streaming === '' ? (
|
|
213
|
+
<>
|
|
214
|
+
<div className="dsh-pe-spin" aria-hidden />
|
|
215
|
+
<div>{t('panel.loading')}</div>
|
|
216
|
+
<div className="dsh-pe-hint">{t('panel.loading.hint')}</div>
|
|
217
|
+
</>
|
|
218
|
+
) : (
|
|
219
|
+
<div className="dsh-pe-stream">
|
|
220
|
+
<div className="dsh-pe-col-title">
|
|
221
|
+
<span className="dsh-pe-spin small" aria-hidden />
|
|
222
|
+
{t('panel.streaming')}
|
|
223
|
+
</div>
|
|
224
|
+
<pre className="dsh-pe-result-text">{state.streaming}</pre>
|
|
296
225
|
</div>
|
|
297
|
-
</div>
|
|
298
|
-
)}
|
|
299
|
-
{state.phase === 'result' && state.stale && (
|
|
300
|
-
<div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>
|
|
301
|
-
)}
|
|
302
|
-
<footer className="dsh-pe-foot">
|
|
303
|
-
<span className="dsh-pe-grow" />
|
|
304
|
-
{state.phase === 'error' && retryable(state.error?.code) && onRetry !== undefined && (
|
|
305
|
-
<button type="button" className="dsh-pe-btn-action plain" onClick={onRetry}>{t('panel.retry')}</button>
|
|
306
226
|
)}
|
|
307
|
-
|
|
227
|
+
</div>
|
|
228
|
+
)}
|
|
229
|
+
|
|
230
|
+
{state.phase === 'error' && state.error !== undefined && (
|
|
231
|
+
<div className="dsh-pe-error">
|
|
232
|
+
{state.error.localized !== undefined ? (
|
|
233
|
+
<div>{state.error.localized}</div>
|
|
234
|
+
) : (
|
|
308
235
|
<>
|
|
309
|
-
<
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
236
|
+
<div>{localizedErrorMessage(t, state.error.code, state.error.params)}</div>
|
|
237
|
+
{state.error.message !== undefined && state.error.message !== '' && (
|
|
238
|
+
<div className="dsh-pe-error-detail">{state.error.message}</div>
|
|
239
|
+
)}
|
|
313
240
|
</>
|
|
314
241
|
)}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
242
|
+
</div>
|
|
243
|
+
)}
|
|
244
|
+
|
|
245
|
+
{state.phase === 'result' && state.result !== undefined && (
|
|
246
|
+
<div className="dsh-pe-result">
|
|
247
|
+
<pre className="dsh-pe-result-text">{state.result.text}</pre>
|
|
248
|
+
</div>
|
|
249
|
+
)}
|
|
250
|
+
|
|
251
|
+
{state.phase === 'result' && state.result?.truncated === true && (
|
|
252
|
+
<div className="dsh-pe-stale">⚠ {t('panel.truncated')}</div>
|
|
253
|
+
)}
|
|
254
|
+
|
|
255
|
+
{state.phase === 'result' && state.stale && (
|
|
256
|
+
<div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>
|
|
257
|
+
)}
|
|
258
|
+
|
|
259
|
+
<footer className="dsh-pe-foot">
|
|
260
|
+
<span className="dsh-pe-grow" />
|
|
261
|
+
{state.phase === 'result' && (
|
|
262
|
+
<button type="button" className="dsh-pe-btn-action plain" onClick={onRegenerate} disabled={onRegenerate === undefined}>
|
|
263
|
+
<RegenerateIcon />
|
|
264
|
+
{t('panel.regenerate')}
|
|
265
|
+
</button>
|
|
266
|
+
)}
|
|
267
|
+
{state.phase === 'error' && (
|
|
268
|
+
<>
|
|
269
|
+
{retryable(state.error?.code) && onRetry !== undefined && (
|
|
270
|
+
<button type="button" className="dsh-pe-btn-action plain" onClick={onRetry}>{t('panel.retry')}</button>
|
|
271
|
+
)}
|
|
272
|
+
</>
|
|
273
|
+
)}
|
|
274
|
+
{state.phase === 'loading' && (
|
|
275
|
+
<button type="button" className="dsh-pe-btn-action plain" onClick={onCancel}>{t('panel.cancel')}</button>
|
|
276
|
+
)}
|
|
277
|
+
{state.phase === 'result' && (
|
|
278
|
+
<>
|
|
279
|
+
<button type="button" className="dsh-pe-btn-action plain dsh-pe-copy" onClick={copy}>
|
|
280
|
+
<CopyIcon />
|
|
281
|
+
{copied === 'ok' ? t('panel.copied') : copied === 'failed' ? t('panel.copyFailed') : t('panel.copy')}
|
|
318
282
|
</button>
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
283
|
+
{applied ? (
|
|
284
|
+
<button type="button" className="dsh-pe-btn-action primary" onClick={onUndo} disabled={onUndo === undefined}>
|
|
285
|
+
<UndoIcon />
|
|
286
|
+
{t('undo.undo')}
|
|
287
|
+
</button>
|
|
288
|
+
) : (
|
|
289
|
+
<button type="button" className="dsh-pe-btn-action primary" onClick={onApply}><FillIcon />{t('panel.apply')}</button>
|
|
290
|
+
)}
|
|
291
|
+
</>
|
|
292
|
+
)}
|
|
293
|
+
</footer>
|
|
294
|
+
</section>
|
|
323
295
|
)
|
|
324
296
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composer mark: the DeepSeek fish with the two-star sparkle tucked into
|
|
3
|
+
* its upper-left corner. The fish is the brand path used by the Harness
|
|
4
|
+
* bundles; the star is the NovelAI-style enhance mark. Both are painted with
|
|
5
|
+
* currentColor so the icon follows the button's label color, and the busy
|
|
6
|
+
* state pulses the whole mark instead of swapping glyphs.
|
|
7
|
+
* @module dsh-prompt-enhance/client/SparkleFishIcon
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ReactElement } from 'react'
|
|
11
|
+
|
|
12
|
+
/** Height in viewBox units; the fish keeps its 23.16:17.04 aspect. */
|
|
13
|
+
const FISH_PATH =
|
|
14
|
+
'M22.9168 1.43018C22.6713 1.31018 22.5658 1.53918 22.4223 1.65519C22.3733 1.69269 22.3318 1.74169 22.2903 1.78669C21.9317 2.1697 21.5127 2.42121 20.9657 2.39121C20.1657 2.34621 19.4827 2.59771 18.8787 3.20973C18.7502 2.45521 18.3236 2.0047 17.6746 1.71569C17.3351 1.56568 16.9916 1.41518 16.7536 1.08867C16.5876 0.856163 16.5421 0.597155 16.4591 0.341647C16.4061 0.187643 16.3536 0.0301382 16.1761 0.00363739C15.9836 -0.0263635 15.9081 0.135141 15.8326 0.270145C15.5306 0.822162 15.4136 1.43018 15.4251 2.0462C15.4516 3.43174 16.0366 4.53527 17.1991 5.3203C17.3311 5.4103 17.3651 5.5003 17.3236 5.63181C17.2441 5.90231 17.1501 6.16482 17.0671 6.43533C17.0141 6.60784 16.9351 6.64584 16.7501 6.57033C16.1121 6.30383 15.5611 5.90931 15.074 5.4328C14.2475 4.63328 13.5 3.75075 12.568 3.05973C12.349 2.89822 12.13 2.74822 11.9034 2.60522C10.9524 1.68169 12.028 0.923165 12.277 0.833162C12.5375 0.739159 12.3675 0.41615 11.5259 0.42015C10.6844 0.42365 9.91439 0.705658 8.93286 1.08117C8.78935 1.13767 8.63835 1.17867 8.48384 1.21267C7.59332 1.04367 6.66829 1.00617 5.70226 1.11517C3.88321 1.31768 2.43016 2.1777 1.36213 3.64575C0.0790928 5.4103 -0.222916 7.41536 0.146595 9.50642C0.535106 11.7105 1.66014 13.535 3.38869 14.9616C5.18125 16.4406 7.24581 17.1657 9.60138 17.0266C11.0319 16.9441 12.6245 16.7526 14.421 15.2321C14.874 15.4576 15.3496 15.5476 16.1381 15.6151C16.7456 15.6716 17.3306 15.5851 17.7836 15.4911C18.4931 15.3411 18.4441 14.6841 18.1876 14.5636C16.1081 13.595 16.5646 13.9891 16.1496 13.67C17.2061 12.42 18.8202 10.1979 19.3182 7.17235C19.3672 6.83834 19.4297 6.36783 19.4222 6.09732C19.4182 5.93231 19.4562 5.86831 19.6447 5.84931C20.1657 5.78931 20.6712 5.64681 21.1357 5.3913C22.4833 4.65528 23.0268 3.44624 23.1548 1.9972C23.1738 1.77569 23.1508 1.54668 22.9168 1.43018ZM11.1749 14.4736C9.15936 12.889 8.18184 12.3675 7.77832 12.39C7.40081 12.4125 7.46881 12.8445 7.55182 13.126C7.63882 13.404 7.75182 13.5955 7.91033 13.8396C8.01983 14.0011 8.09533 14.2411 7.80083 14.4216C7.15181 14.8231 6.02327 14.2866 5.97027 14.2601C4.65673 13.4865 3.5587 12.4655 2.78467 11.069C2.03715 9.72493 1.60314 8.28289 1.53164 6.74384C1.51264 6.37233 1.62214 6.24082 1.99215 6.17332C2.47916 6.08332 2.98118 6.06432 3.46769 6.13582C5.52476 6.43633 7.27581 7.35586 8.74385 8.8129C9.58188 9.64243 10.2159 10.634 10.8689 11.6025C11.5634 12.631 12.3105 13.611 13.262 14.4146C13.598 14.6961 13.866 14.9101 14.1225 15.0681C13.349 15.1546 12.058 15.1731 11.1749 14.4746L11.1749 14.4736ZM12.141 8.25988C12.141 8.09488 12.273 7.96338 12.439 7.96338C12.4765 7.96338 12.5105 7.97088 12.541 7.98188C12.5825 7.99688 12.6205 8.01938 12.6505 8.05338C12.7035 8.10588 12.7335 8.18088 12.7335 8.25988C12.7335 8.42489 12.6015 8.55639 12.4355 8.55639C12.2695 8.55639 12.141 8.42489 12.141 8.25988ZM15.1415 9.79893C14.949 9.87793 14.7565 9.94544 14.5715 9.95294C14.2845 9.96794 13.9715 9.85143 13.8015 9.70893C13.5375 9.48742 13.3485 9.36342 13.2695 8.97691C13.2355 8.8119 13.2545 8.55639 13.2845 8.40989C13.3525 8.09438 13.277 7.89187 13.0545 7.70787C12.8735 7.55786 12.643 7.51636 12.39 7.51636C12.2955 7.51636 12.209 7.47486 12.1445 7.44136C12.039 7.38886 11.9519 7.25735 12.035 7.09585C12.0615 7.04335 12.19 6.91584 12.22 6.89334C12.5635 6.69784 12.9595 6.76184 13.326 6.90834C13.6655 7.04735 13.9225 7.30236 14.292 7.66287C14.6695 8.09838 14.7375 8.21838 14.9525 8.54539C15.1225 8.8009 15.277 9.06341 15.3831 9.36392C15.4471 9.55142 15.3641 9.70493 15.1415 9.79893Z'
|
|
15
|
+
|
|
16
|
+
/** A four-point star, used at the fish's upper-left corner. */
|
|
17
|
+
const STAR_PATH = 'M5.715 0 L7.2 4.2 L11.43 5.715 L7.2 7.2 L5.715 11.43 L4.2 7.2 L0 5.715 L4.2 4.2 Z'
|
|
18
|
+
|
|
19
|
+
/** A fish-plus-sparkle mark sized to its container. */
|
|
20
|
+
export function SparkleFishIcon(props: { size?: number; spinning?: boolean }): ReactElement {
|
|
21
|
+
const size = props.size ?? 15
|
|
22
|
+
return (
|
|
23
|
+
<svg
|
|
24
|
+
width={size * 1.3}
|
|
25
|
+
height={size}
|
|
26
|
+
viewBox="0 0 26 20"
|
|
27
|
+
fill="none"
|
|
28
|
+
aria-hidden="true"
|
|
29
|
+
focusable="false"
|
|
30
|
+
style={{ display: 'block', flexShrink: 0 }}
|
|
31
|
+
>
|
|
32
|
+
<g transform="translate(5,3) scale(0.85)">
|
|
33
|
+
<path d={FISH_PATH} fill="currentColor" />
|
|
34
|
+
</g>
|
|
35
|
+
<path d={STAR_PATH} transform="translate(1.2,0.8) scale(0.55)" fill="currentColor" />
|
|
36
|
+
{props.spinning === true
|
|
37
|
+
? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" />
|
|
38
|
+
: null}
|
|
39
|
+
</svg>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two-star sparkle used for the enhance action: one large four-point star
|
|
3
|
+
* at the upper left and a smaller companion at the lower right. The path is
|
|
4
|
+
* taken from the icon the user supplied from sharednai5.pro, which matches the
|
|
5
|
+
* mark NovelAI's image toolbar uses for its enhance action.
|
|
6
|
+
* @module dsh-prompt-enhance/client/SparkleIcon
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ReactElement } from 'react'
|
|
10
|
+
|
|
11
|
+
/** A sparkle sized to its container, painted with the current text color. */
|
|
12
|
+
export function SparkleIcon(props: { size?: number; spinning?: boolean }): ReactElement {
|
|
13
|
+
const size = props.size ?? 15
|
|
14
|
+
return (
|
|
15
|
+
<svg
|
|
16
|
+
width={size}
|
|
17
|
+
height={size}
|
|
18
|
+
viewBox="0 0 16 16"
|
|
19
|
+
fill="none"
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
focusable="false"
|
|
22
|
+
style={{ display: 'block', flexShrink: 0 }}
|
|
23
|
+
>
|
|
24
|
+
<path
|
|
25
|
+
d="M5.02692 11.2125C5.22842 11.3544 5.46898 11.4303 5.71542 11.4297C5.96186 11.429 6.20204 11.352 6.40284 11.2091C6.60626 11.0605 6.76053 10.8547 6.8451 10.617L7.35593 9.0477C7.4867 8.65418 7.70731 8.29654 8.00029 8.00312C8.29327 7.7097 8.65056 7.48856 9.04383 7.35724L10.6335 6.8429C10.8685 6.7578 11.0709 6.60108 11.2121 6.39484C11.3534 6.1886 11.4264 5.94323 11.4208 5.6933C11.4153 5.44337 11.3315 5.20148 11.1812 5.00172C11.0309 4.80196 10.8217 4.65439 10.5832 4.57981L9.01183 4.06776C8.61813 3.9372 8.26027 3.71665 7.96668 3.4236C7.67308 3.13056 7.45184 2.77309 7.3205 2.37959L6.80396 0.793139C6.72078 0.559416 6.56684 0.357433 6.36355 0.215288C6.16025 0.0731435 5.91772 -0.0020932 5.66968 4.43152e-05C5.42164 0.00218183 5.18044 0.0815873 4.97962 0.227214C4.77881 0.372841 4.62837 0.577448 4.54923 0.81257L4.02697 2.41273C3.89617 2.79564 3.68006 3.1438 3.39497 3.43091C3.10989 3.71803 2.76329 3.93657 2.38135 4.07005L0.792873 4.58096C0.559281 4.66432 0.357437 4.81836 0.215361 5.02168C0.0732858 5.225 -0.00197096 5.46752 3.92466e-05 5.71557C0.00204945 5.96362 0.0812268 6.20489 0.226579 6.40588C0.371931 6.60687 0.576246 6.75762 0.811157 6.83719L2.38135 7.34581C2.77671 7.47731 3.13575 7.69966 3.42967 7.99502C3.72359 8.29038 3.94421 8.65052 4.07383 9.04656L4.59037 10.6364C4.67265 10.8696 4.82579 11.0708 5.02692 11.2125ZM12.0402 15.8324C12.1571 15.9146 12.2915 15.9685 12.4328 15.9897C12.5742 16.011 12.7185 15.9991 12.8544 15.955C12.9903 15.9109 13.1141 15.8357 13.2159 15.7355C13.3178 15.6352 13.395 15.5127 13.4413 15.3775L13.7247 14.5065C13.7857 14.3259 13.8874 14.1617 14.0218 14.0265C14.1567 13.8893 14.3212 13.7888 14.5018 13.7293L15.384 13.4413C15.5661 13.3784 15.7237 13.2597 15.8342 13.102C15.9448 12.9443 16.0028 12.7557 16.0099 12.5631C15.997 12.3705 15.9333 12.1838 15.818 12.0295C15.7027 11.8752 15.5416 11.7613 15.3578 11.704L14.4847 11.4182C14.3039 11.3581 14.1397 11.2569 14.0048 11.1224C13.8699 10.9879 13.7682 10.8239 13.7076 10.6433L13.4196 9.75977C13.3577 9.57805 13.2403 9.42041 13.0839 9.30918C12.9275 9.19795 12.74 9.13877 12.5481 9.14003C12.3562 9.1413 12.1695 9.20294 12.0146 9.31622C11.8596 9.42951 11.7443 9.58869 11.6848 9.7712L11.4026 10.6421C11.3444 10.8214 11.2455 10.9847 11.1136 11.1194C10.9818 11.254 10.8206 11.3563 10.6426 11.4182L9.75922 11.7063C9.57745 11.7679 9.41968 11.8851 9.30827 12.0414C9.19685 12.1977 9.13744 12.3851 9.13845 12.5771C9.13946 12.769 9.20085 12.9558 9.3139 13.1109C9.42696 13.266 9.58596 13.3816 9.76836 13.4413L10.6403 13.7236C10.8232 13.7853 10.9877 13.8871 11.1226 14.0219C11.2586 14.1579 11.3591 14.3225 11.4174 14.5043L11.7065 15.3889C11.7691 15.5678 11.8857 15.7227 12.0402 15.8324Z"
|
|
26
|
+
fill="currentColor"
|
|
27
|
+
/>
|
|
28
|
+
{props.spinning === true
|
|
29
|
+
? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" />
|
|
30
|
+
: null}
|
|
31
|
+
</svg>
|
|
32
|
+
)
|
|
33
|
+
}
|
package/src/client/UndoBar.tsx
CHANGED
|
@@ -37,6 +37,10 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
37
37
|
if (entry !== undefined && entry.applied !== draft) ui.popUndo(uiKey)
|
|
38
38
|
}, [draft, entry, uiKey])
|
|
39
39
|
|
|
40
|
+
// The result card owns the undo affordance while it is open; the standalone
|
|
41
|
+
// row takes over only after the card is closed.
|
|
42
|
+
const panel = ui.getPanel()
|
|
43
|
+
if (panel !== undefined && panel.sessionId === uiKey) return null
|
|
40
44
|
if (entry === undefined || entry.applied !== draft) return null
|
|
41
45
|
|
|
42
46
|
const undo = (): void => {
|
package/src/client/index.tsx
CHANGED
|
@@ -26,6 +26,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
|
26
26
|
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
|
|
27
27
|
import type {} from '@deepseek-ai/dsh-client-store'
|
|
28
28
|
import { EnhanceButton } from './EnhanceButton'
|
|
29
|
+
import { ResultDock } from './ResultDock'
|
|
29
30
|
import { UndoBar } from './UndoBar'
|
|
30
31
|
import * as ui from './ui-state'
|
|
31
32
|
import { dictionaries, NS } from './locales'
|
|
@@ -138,6 +139,21 @@ export function apply(ctx: ClientContext): void {
|
|
|
138
139
|
})
|
|
139
140
|
})
|
|
140
141
|
|
|
142
|
+
ctx.inject(['slots'], (slotsCtx: ClientContext) => {
|
|
143
|
+
const slots = (slotsCtx as unknown as { slots?: SlotsFace }).slots
|
|
144
|
+
if (slots === undefined) return
|
|
145
|
+
return slots.inject('conversation.input.dock', () => {
|
|
146
|
+
try {
|
|
147
|
+
return slots.register(
|
|
148
|
+
{ name: 'conversation.input.dock', id: 'dsh-prompt-enhance-result', order: 30, locale: NS },
|
|
149
|
+
ResultDock as unknown as never,
|
|
150
|
+
)
|
|
151
|
+
} catch (error) {
|
|
152
|
+
return report('result dock slot', error)
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
141
157
|
ctx.inject(['slots'], (slotsCtx: ClientContext) => {
|
|
142
158
|
const slots = (slotsCtx as unknown as { slots?: SlotsFace }).slots
|
|
143
159
|
if (slots === undefined) return
|
package/src/client/locales.ts
CHANGED
|
@@ -9,20 +9,27 @@ export const zh = {
|
|
|
9
9
|
'button.title': '提示词增强',
|
|
10
10
|
'button.busy': '正在增强…',
|
|
11
11
|
'button.otherBusy': '另一个会话正在增强中;请等它完成或先关闭其结果面板。',
|
|
12
|
+
'button.emptyTitle': '提示词增强(当前输入区为空,请先输入文字)',
|
|
12
13
|
'panel.title': '提示词增强',
|
|
13
14
|
'panel.loading': '正在增强,稍候…',
|
|
14
|
-
'panel.streaming': '
|
|
15
|
+
'panel.streaming': '正在生成…',
|
|
15
16
|
'panel.loading.hint': '原文保留在输入框中,不会被动修改。',
|
|
16
17
|
'panel.cancel': '取消',
|
|
17
18
|
'panel.original': '原始提示词',
|
|
18
19
|
'panel.enhanced': '增强结果',
|
|
19
20
|
'panel.apply': '回填到输入框',
|
|
21
|
+
'panel.regenerate': '重新生成',
|
|
22
|
+
'panel.appliedShort': '已替换 ✓',
|
|
23
|
+
'panel.undoneShort': '已撤销 ✓',
|
|
24
|
+
'panel.regeneratedShort': '已重新生成 ✓',
|
|
25
|
+
'panel.copiedShort': '已复制 ✓',
|
|
20
26
|
'panel.copy': '复制结果',
|
|
21
27
|
'panel.copied': '已复制',
|
|
22
28
|
'panel.copyFailed': '复制失败',
|
|
23
29
|
'panel.close': '关闭',
|
|
24
30
|
'panel.retry': '重试',
|
|
25
|
-
'panel.stale.warn': '
|
|
31
|
+
'panel.stale.warn': '草稿已改动,当前结果基于改动前的文本;回填会覆盖当前输入(可撤销)。',
|
|
32
|
+
'panel.truncated': '输出达到 Token 上限,结果可能不完整。可在设置中调高「最大输出 Token」。',
|
|
26
33
|
'panel.model': '模型:{provider} / {model}',
|
|
27
34
|
'panel.elapsed': '耗时 {ms}',
|
|
28
35
|
'panel.tokens': '{total} tokens',
|
|
@@ -145,20 +152,27 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
145
152
|
'button.title': 'Enhance prompt',
|
|
146
153
|
'button.busy': 'Enhancing…',
|
|
147
154
|
'button.otherBusy': 'Another session is enhancing right now — wait for it, or close its result panel first.',
|
|
155
|
+
'button.emptyTitle': 'Enhance prompt (the input is empty — type something first)',
|
|
148
156
|
'panel.title': 'Prompt Enhance',
|
|
149
157
|
'panel.loading': 'Enhancing, please wait…',
|
|
150
|
-
'panel.streaming': 'Generating
|
|
158
|
+
'panel.streaming': 'Generating…',
|
|
151
159
|
'panel.loading.hint': 'Your draft stays untouched until you apply the result.',
|
|
152
160
|
'panel.cancel': 'Cancel',
|
|
153
161
|
'panel.original': 'Original prompt',
|
|
154
162
|
'panel.enhanced': 'Enhanced result',
|
|
155
163
|
'panel.apply': 'Fill into input box',
|
|
164
|
+
'panel.regenerate': 'Regenerate',
|
|
165
|
+
'panel.appliedShort': 'Replaced ✓',
|
|
166
|
+
'panel.undoneShort': 'Undone ✓',
|
|
167
|
+
'panel.regeneratedShort': 'Regenerated ✓',
|
|
168
|
+
'panel.copiedShort': 'Copied ✓',
|
|
156
169
|
'panel.copy': 'Copy result',
|
|
157
170
|
'panel.copied': 'Copied',
|
|
158
171
|
'panel.copyFailed': 'Copy failed',
|
|
159
172
|
'panel.close': 'Close',
|
|
160
173
|
'panel.retry': 'Retry',
|
|
161
|
-
'panel.stale.warn': '
|
|
174
|
+
'panel.stale.warn': 'Draft changed — this result uses the earlier text; Apply overwrites the current input (undoable).',
|
|
175
|
+
'panel.truncated': 'Output hit the token cap and may be incomplete. Raise "Max output tokens" in the settings.',
|
|
162
176
|
'panel.model': 'Model: {provider} / {model}',
|
|
163
177
|
'panel.elapsed': '{ms} elapsed',
|
|
164
178
|
'panel.tokens': '{total} tokens',
|