@surfishs/dsh-prompt-enhance 0.1.3 → 0.1.4
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/NOTICE +2 -0
- package/README.en.md +71 -36
- package/README.md +70 -35
- package/docs/images/panel-en.png +0 -0
- package/docs/images/panel.png +0 -0
- package/lib/client.js +216 -100
- package/lib/index.js +65 -19
- package/lib/index.js.map +2 -2
- package/package.json +2 -1
- package/src/client/EnhanceButton.tsx +30 -4
- package/src/client/ResultDock.tsx +7 -0
- package/src/client/ResultPanel.tsx +18 -8
- package/src/client/locales.ts +86 -68
- package/src/client/settings-page-copy.ts +18 -2
- package/src/client/settings-page-spec.ts +34 -8
- package/src/client/settings-page.tsx +33 -2
- package/src/client/styles.ts +17 -0
- package/src/client/ui-state.ts +12 -1
- package/src/config.ts +11 -4
- package/src/enhance-routes.ts +30 -2
- package/src/enhancer.ts +3 -1
- package/src/orchestrate.ts +15 -4
- package/src/prompts.ts +76 -5
- package/src/shared/protocol.ts +6 -0
- package/src/shared/validate.ts +7 -5
- package/docs/images/panel-en-915.png +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surfishs/dsh-prompt-enhance",
|
|
3
3
|
"description": "Prompt enhancement for the dsh web GUI: rewrite the composer draft into a well-structured prompt through the harness LLM service, preview the before/after, then fill back, copy, or undo. Original draft is always preserved.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
"locale/*.json",
|
|
89
89
|
"icon.svg",
|
|
90
90
|
"docs/images/**",
|
|
91
|
+
"NOTICE",
|
|
91
92
|
"README.md",
|
|
92
93
|
"README.en.md"
|
|
93
94
|
],
|
|
@@ -63,6 +63,17 @@ function occurrenceCountOf(value: unknown): number {
|
|
|
63
63
|
return Array.isArray(value) ? value.length : OCCURRENCES_UNKNOWN
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Read the composer's attachment count. Only the count is forwarded into the
|
|
68
|
+
* prompt — the contents are never sent — and a host without the field counts
|
|
69
|
+
* as zero, the same defensive shape as the other optional input fields.
|
|
70
|
+
* @param value - the untrusted field.
|
|
71
|
+
* @returns the array length, or 0 when absent/not an array.
|
|
72
|
+
*/
|
|
73
|
+
function attachmentCountOf(value: unknown): number {
|
|
74
|
+
return Array.isArray(value) ? value.length : 0
|
|
75
|
+
}
|
|
76
|
+
|
|
66
77
|
/**
|
|
67
78
|
* Read a field that downstream code requires to be a string. `draft` drives
|
|
68
79
|
* `checkInputText`, which iterates the text — an absent field would throw on
|
|
@@ -85,6 +96,7 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
|
|
|
85
96
|
const draft = useInput((state: InputState) => stringOf((state as { draft?: unknown }).draft))
|
|
86
97
|
const phase = useInput((state: InputState) => (state as { phase?: unknown }).phase)
|
|
87
98
|
const occurrenceCount = useInput((state: InputState) => occurrenceCountOf((state as { occurrences?: unknown }).occurrences))
|
|
99
|
+
const attachmentCount = useInput((state: InputState) => attachmentCountOf((state as { attachmentIds?: unknown }).attachmentIds))
|
|
88
100
|
const settings = useSyncExternalStore(subscribeClientSettings, getClientSettings)
|
|
89
101
|
const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
|
|
90
102
|
const rootRef = useRef<HTMLButtonElement | null>(null)
|
|
@@ -345,13 +357,27 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
|
|
|
345
357
|
ui.openError(uiKey, source, { code: 'rejected', localized: occurrences })
|
|
346
358
|
return
|
|
347
359
|
}
|
|
360
|
+
// `claimed` is a command chip waiting for its arguments (`/plan ` in
|
|
361
|
+
// front of the body), not a submission in flight: the editor is still
|
|
362
|
+
// editable and the phase persists until the command runs. The busy copy
|
|
363
|
+
// named the wrong state and hid what the user had to do, so a
|
|
364
|
+
// command-led draft gets its own message. The genuinely busy phases
|
|
365
|
+
// (adjudicating / submitting / sending) keep the busy copy below.
|
|
366
|
+
if (phase === 'claimed') {
|
|
367
|
+
const command = t('error.command')
|
|
368
|
+
ui.openError(uiKey, source, { code: 'rejected', localized: command })
|
|
369
|
+
return
|
|
370
|
+
}
|
|
348
371
|
if (phase !== 'plain') {
|
|
349
372
|
const busyPhase = t('error.phase')
|
|
350
373
|
ui.openError(uiKey, source, { code: 'rejected', localized: busyPhase })
|
|
351
374
|
return
|
|
352
375
|
}
|
|
353
376
|
const controller = new AbortController()
|
|
354
|
-
|
|
377
|
+
// Snapshot the count at request time: the result card reports what the
|
|
378
|
+
// call announced, not what the composer holds later.
|
|
379
|
+
const attachments = attachmentCount > 0 ? { attachments: { count: attachmentCount } } : {}
|
|
380
|
+
ui.openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort(), ...attachments })
|
|
355
381
|
const settle = (result: Parameters<typeof ui.settleResult>[1]): void => ui.settleResult(uiKey, result)
|
|
356
382
|
const fail = (error: unknown): void => {
|
|
357
383
|
const detail: EnhanceError = error instanceof EnhanceClientError ? error.detail : { code: 'internal', message: error instanceof Error ? error.message : String(error) }
|
|
@@ -362,7 +388,7 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
|
|
|
362
388
|
// the transport cannot stream.
|
|
363
389
|
if (settings.streaming) {
|
|
364
390
|
requestEnhanceStream(
|
|
365
|
-
{ sessionId: wireId, text: source },
|
|
391
|
+
{ sessionId: wireId, text: source, ...attachments },
|
|
366
392
|
{
|
|
367
393
|
signal: controller.signal,
|
|
368
394
|
onDelta: (delta: string): void => ui.appendDelta(uiKey, delta),
|
|
@@ -370,9 +396,9 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
|
|
|
370
396
|
).then(settle, fail)
|
|
371
397
|
return
|
|
372
398
|
}
|
|
373
|
-
requestEnhance({ sessionId: wireId, text: source }, controller.signal).then(settle, fail)
|
|
399
|
+
requestEnhance({ sessionId: wireId, text: source, ...attachments }, controller.signal).then(settle, fail)
|
|
374
400
|
},
|
|
375
|
-
[anyBusy, draft, occurrenceCount, phase, settings, uiKey, wireId, t],
|
|
401
|
+
[anyBusy, draft, occurrenceCount, attachmentCount, phase, settings, uiKey, wireId, t],
|
|
376
402
|
)
|
|
377
403
|
|
|
378
404
|
// The session registry holds a stable identity; run always dispatches to
|
|
@@ -40,6 +40,9 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
40
40
|
const value = (state as { draft?: unknown }).draft
|
|
41
41
|
return typeof value === 'string' ? value : ''
|
|
42
42
|
})
|
|
43
|
+
// Same emptiness rule as the composer button: an attachment-only draft has
|
|
44
|
+
// no text to re-run, so regenerate is unavailable (the card explains why).
|
|
45
|
+
const draftEmpty = draft.trim() === ''
|
|
43
46
|
const phase = useInput((state) => {
|
|
44
47
|
const value = (state as { phase?: unknown }).phase
|
|
45
48
|
return typeof value === 'string' ? value : ''
|
|
@@ -162,6 +165,9 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
162
165
|
|
|
163
166
|
const regenerate = (): void => {
|
|
164
167
|
if (panel.phase !== 'result') return
|
|
168
|
+
// An empty draft cannot be re-run; the disabled card already says so, and
|
|
169
|
+
// clicking must not leave a pending label behind.
|
|
170
|
+
if (draftEmpty) return
|
|
165
171
|
// A click during the notice window starts a fresh round: drop the label now
|
|
166
172
|
// so the button shows its normal text before it disappears, and remember
|
|
167
173
|
// which result this round has to replace.
|
|
@@ -178,6 +184,7 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
178
184
|
t={t}
|
|
179
185
|
applied={applied}
|
|
180
186
|
regenerated={regeneratedNotice}
|
|
187
|
+
draftEmpty={draftEmpty}
|
|
181
188
|
collapsed={panel.collapsed === true}
|
|
182
189
|
onToggleCollapsed={() => ui.setCollapsed(uiKey, panel.collapsed !== true)}
|
|
183
190
|
foldAnimation={settings.foldAnimation}
|
|
@@ -30,6 +30,8 @@ export interface ResultPanelProps {
|
|
|
30
30
|
onUndo?: () => void
|
|
31
31
|
/** Run the same source prompt through the model again. */
|
|
32
32
|
onRegenerate?: () => void
|
|
33
|
+
/** The composer draft is empty: regenerate cannot run, so the button reports why. */
|
|
34
|
+
draftEmpty?: boolean
|
|
33
35
|
/** Show the transient "regenerated" label on that button instead of its normal text. */
|
|
34
36
|
regenerated?: boolean
|
|
35
37
|
/** Hide the body, keeping the header and the footer rows (and their actions). */
|
|
@@ -184,8 +186,8 @@ function totalTokensOf(usage: EnhanceUsage): number {
|
|
|
184
186
|
* @param props - the usage numbers and the locale seat.
|
|
185
187
|
* @returns the info button and its tooltip.
|
|
186
188
|
*/
|
|
187
|
-
function ContextUsageInfo(props: { usage?: ContextUsage; t: TranslateNS<'dsh-prompt-enhance'> }): ReactNode {
|
|
188
|
-
const { usage, t } = props
|
|
189
|
+
function ContextUsageInfo(props: { usage?: ContextUsage; attachments?: { count: number }; t: TranslateNS<'dsh-prompt-enhance'> }): ReactNode {
|
|
190
|
+
const { usage, attachments, t } = props
|
|
189
191
|
const [open, setOpen] = useState(false)
|
|
190
192
|
// Reaching the turn cap is the normal shape of the window, not a warning;
|
|
191
193
|
// only a character squeeze or a cut turn needs the amber treatment.
|
|
@@ -227,6 +229,7 @@ function ContextUsageInfo(props: { usage?: ContextUsage; t: TranslateNS<'dsh-pro
|
|
|
227
229
|
<span role="tooltip" className="dsh-pe-context-tip">
|
|
228
230
|
<span className="dsh-pe-context-stats">{stats}</span>
|
|
229
231
|
{reason !== '' && <span className="dsh-pe-context-reason">{reason}</span>}
|
|
232
|
+
{attachments !== undefined && attachments.count > 0 && <span className="dsh-pe-context-attachments">{t('panel.attachmentsCount', { count: attachments.count })}</span>}
|
|
230
233
|
</span>
|
|
231
234
|
)}
|
|
232
235
|
</span>
|
|
@@ -235,7 +238,7 @@ function ContextUsageInfo(props: { usage?: ContextUsage; t: TranslateNS<'dsh-pro
|
|
|
235
238
|
|
|
236
239
|
/** One enhancement result card. */
|
|
237
240
|
export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
238
|
-
const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, regenerated = false, collapsed = false, onToggleCollapsed, foldAnimation = true } = props
|
|
241
|
+
const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, draftEmpty = false, regenerated = false, collapsed = false, onToggleCollapsed, foldAnimation = true } = props
|
|
239
242
|
const [copied, setCopied] = useState<'idle' | 'ok' | 'failed'>('idle')
|
|
240
243
|
/** Pending reset of the copy label; one timer only, so a second copy cannot be cut short by the first. */
|
|
241
244
|
const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
@@ -329,7 +332,7 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
329
332
|
{/* Collapsed, the body — and with it the warnings — is hidden, so the
|
|
330
333
|
header carries a marker instead of silently swallowing one. */}
|
|
331
334
|
{collapsed && (state.stale === true || state.result?.truncated === true) ? (
|
|
332
|
-
<span className=
|
|
335
|
+
<span className={`dsh-pe-warn-dot${state.stale === true ? '' : ' is-danger'}`} title={state.stale === true ? t('panel.stale.dot') : t('panel.truncated.dot')} aria-hidden="true">
|
|
333
336
|
⚠
|
|
334
337
|
</span>
|
|
335
338
|
) : null}
|
|
@@ -387,17 +390,24 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
387
390
|
</div>
|
|
388
391
|
)}
|
|
389
392
|
|
|
390
|
-
{state.phase === 'result' && state.result?.truncated === true && <div className="dsh-pe-stale">⚠ {t('panel.truncated')}</div>}
|
|
393
|
+
{state.phase === 'result' && state.result?.truncated === true && !state.stale && <div className="dsh-pe-stale dsh-pe-truncated">⚠ {t('panel.truncated')}</div>}
|
|
391
394
|
|
|
392
|
-
{state.phase === 'result' && state.stale && <div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>}
|
|
395
|
+
{state.phase === 'result' && state.stale && <div className="dsh-pe-stale">⚠ {t(draftEmpty ? 'panel.stale.empty' : 'panel.stale.warn')}</div>}
|
|
393
396
|
</div>
|
|
394
397
|
</div>
|
|
395
398
|
|
|
396
399
|
<footer className="dsh-pe-foot">
|
|
397
|
-
{state.phase === 'result' && <ContextUsageInfo usage={state.result?.context} t={t} />}
|
|
400
|
+
{state.phase === 'result' && <ContextUsageInfo usage={state.result?.context} attachments={state.attachments} t={t} />}
|
|
398
401
|
<span className="dsh-pe-grow" />
|
|
399
402
|
{state.phase === 'result' && (
|
|
400
|
-
<button
|
|
403
|
+
<button
|
|
404
|
+
type="button"
|
|
405
|
+
className="dsh-pe-btn-action plain dsh-pe-btn-floor"
|
|
406
|
+
onClick={onRegenerate}
|
|
407
|
+
disabled={onRegenerate === undefined}
|
|
408
|
+
aria-disabled={draftEmpty || undefined}
|
|
409
|
+
title={draftEmpty ? t('panel.regenerate.empty') : undefined}
|
|
410
|
+
>
|
|
401
411
|
<RegenerateIcon />
|
|
402
412
|
<span className="dsh-pe-swap">
|
|
403
413
|
{swapLabel(!regenerated, t('panel.regenerate'))}
|
package/src/client/locales.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const zh = {
|
|
|
32
32
|
'panel.enhanced': '增强结果',
|
|
33
33
|
'panel.apply': '回填到输入框',
|
|
34
34
|
'panel.regenerate': '重新生成',
|
|
35
|
+
'panel.regenerate.empty': '请先输入文字后再重新生成',
|
|
35
36
|
'panel.regenerated': '已重新生成',
|
|
36
37
|
'panel.copy': '复制结果',
|
|
37
38
|
'panel.copied': '已复制',
|
|
@@ -40,13 +41,17 @@ export const zh = {
|
|
|
40
41
|
'panel.collapse': '折叠',
|
|
41
42
|
'panel.expand': '展开',
|
|
42
43
|
'panel.retry': '重试',
|
|
43
|
-
'panel.stale.warn': '
|
|
44
|
-
'panel.
|
|
44
|
+
'panel.stale.warn': '草稿已改动:当前结果基于旧文本。「重新生成」会按当前文本重跑;回填会覆盖你后来的修改(可撤销)。',
|
|
45
|
+
'panel.stale.empty': '草稿已改动:当前为空。「重新生成」不可用,请先输入文字;回填会覆盖你后来的修改(可撤销)。',
|
|
46
|
+
'panel.stale.dot': '草稿已改动',
|
|
47
|
+
'panel.truncated': '输出已达到「输出 token 上限」,结果可能不完整。请在设置里调高该上限后再重新生成。',
|
|
48
|
+
'panel.truncated.dot': '输出被截断',
|
|
45
49
|
'panel.contextUsage': '上下文用量',
|
|
46
50
|
'panel.contextStats': '上下文 {turns}/{maxTurns} 条 · {chars}/{maxChars} 字({percent}%)',
|
|
47
51
|
'panel.contextCharsLimited': '已达字数上限,较早内容未发送',
|
|
48
52
|
'panel.contextCut': '已达字数上限,最新一条仅发送了开头',
|
|
49
53
|
'panel.contextUnused': '本次未使用上下文',
|
|
54
|
+
'panel.attachmentsCount': '附件:{count} 个',
|
|
50
55
|
'panel.model': '模型:{provider} / {model}',
|
|
51
56
|
'panel.elapsed': '耗时 {ms}',
|
|
52
57
|
'panel.tokens': '{total} tokens',
|
|
@@ -58,34 +63,35 @@ export const zh = {
|
|
|
58
63
|
'undo.applied': '已替换原提示词',
|
|
59
64
|
'undo.undo': '撤销',
|
|
60
65
|
'undo.dismiss': '关闭提示',
|
|
61
|
-
'error.empty': '
|
|
62
|
-
'error.tooLong': '
|
|
63
|
-
'error.occurrences': '
|
|
64
|
-
'error.chipsUnknown': '
|
|
65
|
-
'error.phase': '
|
|
66
|
-
'error.
|
|
67
|
-
'error.
|
|
68
|
-
'error.
|
|
69
|
-
'error.
|
|
70
|
-
'error.
|
|
71
|
-
'error.
|
|
72
|
-
'error.
|
|
73
|
-
'error.
|
|
74
|
-
'error.client.
|
|
75
|
-
'error.client.
|
|
76
|
-
'error.client.
|
|
77
|
-
'error.client.
|
|
78
|
-
'error.
|
|
79
|
-
'error.
|
|
80
|
-
'error.
|
|
81
|
-
'error.
|
|
82
|
-
'error.upstream.
|
|
83
|
-
'error.upstream.
|
|
84
|
-
'error.upstream.
|
|
85
|
-
'error.upstream.
|
|
86
|
-
'error.upstream.
|
|
87
|
-
'error.upstream.
|
|
88
|
-
'error.upstream.
|
|
66
|
+
'error.empty': '输入框是空的,请先输入要增强的文字。',
|
|
67
|
+
'error.tooLong': '草稿共 {count} 字,超过 {max} 字上限(按字符计,不是 token)。不会自动截断,请精简后再试。',
|
|
68
|
+
'error.occurrences': '草稿里有文件或会话引用,暂不支持增强;请先移除引用,增强后再手动插回。',
|
|
69
|
+
'error.chipsUnknown': '读不到输入框里的引用状态。为避免回填时覆盖你的命令或文件引用,本次没有执行;请改成纯文本后再试。',
|
|
70
|
+
'error.phase': '输入框正在提交或校验中,请等它结束后再试。',
|
|
71
|
+
'error.command': '草稿以命令块开头(如 /计划),暂不支持增强;请先移除命令块,再单独增强正文。',
|
|
72
|
+
'error.disabled': '提示词增强已在插件设置中关闭;请在设置里重新开启后再试。',
|
|
73
|
+
'error.rejected': '这次增强被拒绝了。请稍后再试;如果一直如此,请检查插件设置。',
|
|
74
|
+
'error.timeout': '等了 {seconds} 秒仍没有结果,本次已取消。可以重试,或到设置里调大「超时(毫秒)」;你的输入没有被改动。',
|
|
75
|
+
'error.unconfigured': '还没确定用哪个模型:请在插件设置里填好 provider 和 model(两项都要填),或先在当前会话发一条消息,让增强跟随会话模型。',
|
|
76
|
+
'error.effortUnsupported': '当前模型不支持所选推理档位「{effort}」;请换一个档位,或改用「模型默认」。',
|
|
77
|
+
'error.upstream': '模型服务返回了错误。下方有详情时按详情处理,否则可以直接重试;你的输入没有被改动。',
|
|
78
|
+
'error.internal': '增强失败。请重试;如果反复失败,请查看 DSH 运行日志。你的输入没有被改动。',
|
|
79
|
+
'error.client.unreachable': '连不上 DSH 服务:请确认 DSH 正在运行,然后重试。',
|
|
80
|
+
'error.client.malformed': 'DSH 返回了无法解析的数据。请重试;你的输入没有被改动。',
|
|
81
|
+
'error.client.refused': 'DSH 拒绝了这次请求(HTTP {status})。请稍后重试。',
|
|
82
|
+
'error.client.streamClosed': '结果返回前连接断开了。请重试;你的输入没有被改动。',
|
|
83
|
+
'error.client.cancelled': '已取消增强,你的输入没有被改动。',
|
|
84
|
+
'error.rateLimit': '操作太频繁:每分钟最多 {limit} 次增强。请等 {retryAfterSeconds} 秒再试。',
|
|
85
|
+
'error.concurrencyLimit': '同时最多 {max} 个增强在进行中,请等其中一个完成后再试。',
|
|
86
|
+
'error.cooldown': '连续 {failures} 次增强失败,已暂停 {retryAfterSeconds} 秒,避免继续请求模型服务。可以先检查模型配置,稍后再试。',
|
|
87
|
+
'error.upstream.auth': '模型服务鉴权失败:请检查该 provider 的 API Key。',
|
|
88
|
+
'error.upstream.invalidCredential': '模型服务鉴权失败:保存的 API Key 不可用,请更新后重试。',
|
|
89
|
+
'error.upstream.rateLimit': '模型服务正在限流,请稍后重试。',
|
|
90
|
+
'error.upstream.quota': '模型服务余额或配额不足,请检查账户。',
|
|
91
|
+
'error.upstream.empty': '模型返回了空结果,请重试。',
|
|
92
|
+
'error.upstream.contextWindow': '内容超出模型的上下文窗口,请精简原文或换一个模型。',
|
|
93
|
+
'error.upstream.toolCall': '模型尝试调用工具,而提示词增强只需要纯文本;请换一个模型后重试。',
|
|
94
|
+
'error.upstream.maxTokens': '结果达到了「输出 token 上限」。请调高该设置,或精简原文后重试。',
|
|
89
95
|
'settings.summary': '模型、上下文与资源限制',
|
|
90
96
|
'settings.title': '提示词增强',
|
|
91
97
|
'settings.description': '把输入框草稿改写为结构化提示词:角色与目标、可执行步骤、输出格式、验收标准、边界条件。原文保留,失败不改草稿;保存后下一次调用即生效。',
|
|
@@ -108,7 +114,7 @@ export const zh = {
|
|
|
108
114
|
'settings.row.enabled.label': '总开关',
|
|
109
115
|
'settings.row.enabled.hint': '关闭后隐藏输入框的增强按钮,命令与快捷键一并停用。',
|
|
110
116
|
'settings.row.contextAware.label': '上下文感知',
|
|
111
|
-
'settings.row.contextAware.hint': '
|
|
117
|
+
'settings.row.contextAware.hint': '读取当前会话最近几条消息来消解指代、补全省略;无历史时回退为单条增强。',
|
|
112
118
|
'settings.row.streaming.label': '增量展示',
|
|
113
119
|
'settings.row.streaming.hint': '模型边写边在面板显示;仅影响显示节奏,最终写入的文本不变。',
|
|
114
120
|
'settings.row.foldAnimation.label': '卡片折叠动画',
|
|
@@ -144,6 +150,9 @@ export const zh = {
|
|
|
144
150
|
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。「模型默认」表示不发送该字段,由提供方使用默认档。',
|
|
145
151
|
'settings.row.maxOutputTokens.label': '输出 token 上限',
|
|
146
152
|
'settings.row.maxOutputTokens.hint': '单次增强的输出预算;默认 8192。',
|
|
153
|
+
'settings.row.invalidInteger': '请输入 {min}–{max} 之间的整数',
|
|
154
|
+
'settings.row.invalidNumber': '请输入 {min}–{max} 之间的数字',
|
|
155
|
+
'settings.row.blankDefault': '留空 = 使用默认值 {value}',
|
|
147
156
|
'settings.row.maxInputChars.label': '输入字符上限',
|
|
148
157
|
'settings.row.maxInputChars.hint': '超出直接拒绝、不截断;默认 12000。',
|
|
149
158
|
'settings.row.timeoutMs.label': '超时(毫秒)',
|
|
@@ -154,7 +163,7 @@ export const zh = {
|
|
|
154
163
|
'settings.row.systemPrompt.hint': '留空使用内置增强策略。',
|
|
155
164
|
'settings.row.systemPrompt.placeholder': '例:把用户的中文输入翻译成英文。',
|
|
156
165
|
'settings.row.contextMaxMessages.label': '上下文消息条数',
|
|
157
|
-
'settings.row.contextMaxMessages.hint': '
|
|
166
|
+
'settings.row.contextMaxMessages.hint': '最多参考最近多少条消息;0 表示不参考;默认 8。',
|
|
158
167
|
'settings.row.contextMaxChars.label': '上下文字符上限',
|
|
159
168
|
'settings.row.contextMaxChars.hint': '历史片段的字符预算;0 表示不参考;默认 4000。',
|
|
160
169
|
'settings.row.maxConcurrent.label': '并发上限',
|
|
@@ -210,6 +219,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
210
219
|
'panel.enhanced': 'Enhanced result',
|
|
211
220
|
'panel.apply': 'Fill into input box',
|
|
212
221
|
'panel.regenerate': 'Regenerate',
|
|
222
|
+
'panel.regenerate.empty': 'Type some text before regenerating',
|
|
213
223
|
'panel.regenerated': 'Regenerated',
|
|
214
224
|
'panel.copy': 'Copy result',
|
|
215
225
|
'panel.copied': 'Copied',
|
|
@@ -218,13 +228,17 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
218
228
|
'panel.collapse': 'Collapse',
|
|
219
229
|
'panel.expand': 'Expand',
|
|
220
230
|
'panel.retry': 'Retry',
|
|
221
|
-
'panel.stale.warn': 'Draft changed
|
|
222
|
-
'panel.
|
|
231
|
+
'panel.stale.warn': 'Draft changed: this result uses the earlier text. Regenerate re-runs on the current draft; filling into the input box overwrites your later edits (undoable).',
|
|
232
|
+
'panel.stale.empty': 'Draft changed: it is now empty. Regenerate is unavailable — type some text first; filling into the input box overwrites your later edits (undoable).',
|
|
233
|
+
'panel.stale.dot': 'Draft changed',
|
|
234
|
+
'panel.truncated': 'The output hit the "Output token budget" limit, so the result may be incomplete. Raise that limit in the settings, then regenerate.',
|
|
235
|
+
'panel.truncated.dot': 'Output truncated',
|
|
223
236
|
'panel.contextUsage': 'Context usage',
|
|
224
|
-
'panel.contextStats': 'Context {turns}/{maxTurns}
|
|
225
|
-
'panel.contextCharsLimited': 'Character cap reached; earlier
|
|
226
|
-
'panel.contextCut': 'Character limit reached; only the opening of the latest
|
|
237
|
+
'panel.contextStats': 'Context {turns}/{maxTurns} messages · {chars}/{maxChars} chars ({percent}%)',
|
|
238
|
+
'panel.contextCharsLimited': 'Character cap reached; earlier messages were not sent',
|
|
239
|
+
'panel.contextCut': 'Character limit reached; only the opening of the latest message was sent',
|
|
227
240
|
'panel.contextUnused': 'No conversation context was used for this call',
|
|
241
|
+
'panel.attachmentsCount': 'Attachments: {count}',
|
|
228
242
|
'panel.model': 'Model: {provider} / {model}',
|
|
229
243
|
'panel.elapsed': '{ms} elapsed',
|
|
230
244
|
'panel.tokens': '{total} tokens',
|
|
@@ -236,35 +250,36 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
236
250
|
'undo.applied': 'Original draft replaced',
|
|
237
251
|
'undo.undo': 'Undo',
|
|
238
252
|
'undo.dismiss': 'Dismiss',
|
|
239
|
-
'error.empty': 'The input box is empty — type
|
|
240
|
-
'error.tooLong': 'The draft is {count} characters, over the {max} limit (characters, not tokens)
|
|
241
|
-
'error.occurrences': 'The draft contains
|
|
242
|
-
'error.chipsUnknown': 'The composer reference state could not be read
|
|
243
|
-
'error.phase': 'The input box is busy
|
|
244
|
-
'error.
|
|
245
|
-
'error.
|
|
246
|
-
'error.
|
|
253
|
+
'error.empty': 'The input box is empty — type the text you want enhanced first.',
|
|
254
|
+
'error.tooLong': 'The draft is {count} characters, over the {max}-character limit (characters, not tokens). It is never truncated automatically — shorten it and try again.',
|
|
255
|
+
'error.occurrences': 'The draft contains file or session references, which are not supported yet — remove them first, then re-insert them after enhancing.',
|
|
256
|
+
'error.chipsUnknown': 'The composer reference state could not be read. To avoid overwriting your command or file reference on fill-back, nothing was run — use plain text and try again.',
|
|
257
|
+
'error.phase': 'The input box is busy submitting or checking — wait for it to finish, then try again.',
|
|
258
|
+
'error.command': 'The draft starts with a command chip (for example /plan), which is not supported yet — remove the command first, then enhance the body on its own.',
|
|
259
|
+
'error.disabled': 'Prompt enhance is turned off in the plugin settings — re-enable it there and try again.',
|
|
260
|
+
'error.rejected': 'This enhancement was refused. Retry later; if it keeps happening, check the plugin settings.',
|
|
261
|
+
'error.timeout': 'No result after {seconds}s, so this call was cancelled. Retry, or raise "Timeout (ms)" in the settings; your input was not changed.',
|
|
247
262
|
'error.unconfigured':
|
|
248
|
-
'No model is configured
|
|
249
|
-
'error.effortUnsupported': '
|
|
250
|
-
'error.upstream': 'The model provider returned an error. If there is detail below, act on it; otherwise retry. Your
|
|
251
|
-
'error.internal': 'Enhancement failed. Retry; if it keeps failing, check the
|
|
252
|
-
'error.client.unreachable': 'Cannot reach the
|
|
253
|
-
'error.client.malformed': '
|
|
254
|
-
'error.client.refused': '
|
|
255
|
-
'error.client.streamClosed': 'The
|
|
256
|
-
'error.client.cancelled': '
|
|
257
|
-
'error.rateLimit': 'Too many requests
|
|
258
|
-
'error.concurrencyLimit': '{max} enhancements
|
|
259
|
-
'error.cooldown': '{failures} enhancements failed in a row
|
|
260
|
-
'error.upstream.auth':
|
|
261
|
-
'error.upstream.invalidCredential': '
|
|
262
|
-
'error.upstream.rateLimit': 'The model
|
|
263
|
-
'error.upstream.quota': 'The model
|
|
264
|
-
'error.upstream.empty': 'The model returned an empty
|
|
265
|
-
'error.upstream.contextWindow':
|
|
266
|
-
'error.upstream.toolCall': 'The model
|
|
267
|
-
'error.upstream.maxTokens': 'The
|
|
263
|
+
'No model is configured yet: fill in both provider and model in the plugin settings, or send a message in the current session first so the enhancement follows the session model.',
|
|
264
|
+
'error.effortUnsupported': 'The current model does not support the selected reasoning effort "{effort}" — choose another tier, or use "Model default".',
|
|
265
|
+
'error.upstream': 'The model provider returned an error. If there is detail below, act on it; otherwise retry. Your input was not changed.',
|
|
266
|
+
'error.internal': 'Enhancement failed. Retry; if it keeps failing, check the DSH logs. Your input was not changed.',
|
|
267
|
+
'error.client.unreachable': 'Cannot reach the DSH service — make sure DSH is running, then retry.',
|
|
268
|
+
'error.client.malformed': 'DSH returned data that could not be parsed. Retry; your input was not changed.',
|
|
269
|
+
'error.client.refused': 'DSH refused the request (HTTP {status}). Retry later.',
|
|
270
|
+
'error.client.streamClosed': 'The connection closed before the result arrived. Retry; your input was not changed.',
|
|
271
|
+
'error.client.cancelled': 'Enhancement cancelled; your input was not changed.',
|
|
272
|
+
'error.rateLimit': 'Too many requests: at most {limit} enhancements per minute. Try again in {retryAfterSeconds}s.',
|
|
273
|
+
'error.concurrencyLimit': 'At most {max} enhancements can run at once — wait for one to finish, then try again.',
|
|
274
|
+
'error.cooldown': '{failures} enhancements failed in a row, so calls are paused for {retryAfterSeconds}s to avoid hammering the model service. Check the model settings, then retry.',
|
|
275
|
+
'error.upstream.auth': "Model service authentication failed: check this provider's API key.",
|
|
276
|
+
'error.upstream.invalidCredential': 'Model service authentication failed: the stored API key is not usable — update it and retry.',
|
|
277
|
+
'error.upstream.rateLimit': 'The model service is rate-limiting requests. Retry later.',
|
|
278
|
+
'error.upstream.quota': 'The model service is out of quota or balance — check the account.',
|
|
279
|
+
'error.upstream.empty': 'The model returned an empty result — retry.',
|
|
280
|
+
'error.upstream.contextWindow': "The content exceeds the model's context window — shorten the draft or switch models.",
|
|
281
|
+
'error.upstream.toolCall': 'The model tried to call a tool, but prompt enhancement only sends plain text — switch models and retry.',
|
|
282
|
+
'error.upstream.maxTokens': 'The result hit the "Output token budget" limit. Raise that setting, or shorten the draft and retry.',
|
|
268
283
|
'settings.summary': 'Model, context, and resource limits',
|
|
269
284
|
'settings.title': 'Prompt enhance',
|
|
270
285
|
'settings.description':
|
|
@@ -288,7 +303,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
288
303
|
'settings.row.enabled.label': 'Master switch',
|
|
289
304
|
'settings.row.enabled.hint': 'Off hides the composer button and disables the command and the shortcut.',
|
|
290
305
|
'settings.row.contextAware.label': 'Context aware',
|
|
291
|
-
'settings.row.contextAware.hint': 'Reads the recent
|
|
306
|
+
'settings.row.contextAware.hint': 'Reads the recent messages of the current conversation; falls back to a single-prompt rewrite when there is no history.',
|
|
292
307
|
'settings.row.streaming.label': 'Streaming display',
|
|
293
308
|
'settings.row.streaming.hint': 'Shows the rewrite while it is being written. Display only: the applied text is unchanged.',
|
|
294
309
|
'settings.row.foldAnimation.label': 'Card fold animation',
|
|
@@ -326,6 +341,9 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
326
341
|
'Tier choices come from what the configured provider/model declares; custom models are read on demand. "Model default" means the field is omitted and the provider applies its default.',
|
|
327
342
|
'settings.row.maxOutputTokens.label': 'Output token budget',
|
|
328
343
|
'settings.row.maxOutputTokens.hint': 'Output budget for one enhancement call. Default 8192.',
|
|
344
|
+
'settings.row.invalidInteger': 'Enter an integer between {min} and {max}',
|
|
345
|
+
'settings.row.invalidNumber': 'Enter a number between {min} and {max}',
|
|
346
|
+
'settings.row.blankDefault': 'Leave blank to use the default: {value}',
|
|
329
347
|
'settings.row.maxInputChars.label': 'Input character cap',
|
|
330
348
|
'settings.row.maxInputChars.hint': 'Over-limit drafts are rejected, never truncated. Default 12000.',
|
|
331
349
|
'settings.row.timeoutMs.label': 'Timeout (ms)',
|
|
@@ -336,8 +354,8 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
336
354
|
'settings.row.systemPrompt.label': 'Custom system prompt',
|
|
337
355
|
'settings.row.systemPrompt.hint': 'Leave empty to use the built-in enhancement strategy.',
|
|
338
356
|
'settings.row.systemPrompt.placeholder': 'e.g. translate the user text from Chinese into English.',
|
|
339
|
-
'settings.row.contextMaxMessages.label': 'Context
|
|
340
|
-
'settings.row.contextMaxMessages.hint': 'How many recent
|
|
357
|
+
'settings.row.contextMaxMessages.label': 'Context messages',
|
|
358
|
+
'settings.row.contextMaxMessages.hint': 'How many recent messages may ground the rewrite; 0 disables context. Default 8.',
|
|
341
359
|
'settings.row.contextMaxChars.label': 'Context characters',
|
|
342
360
|
'settings.row.contextMaxChars.hint': 'Character budget for the context snippet; 0 disables it. Default 4000.',
|
|
343
361
|
'settings.row.maxConcurrent.label': 'Concurrency cap',
|
|
@@ -16,6 +16,22 @@ export type Translate = TranslateNS<typeof LOCALE_NS>
|
|
|
16
16
|
/** The shipped Chinese dictionary, used when a host projects no `t` seat. */
|
|
17
17
|
export const ZH_COPY: Readonly<Record<string, string>> = zh
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Fill `{name}` placeholders from `params`, then hand the result to the seat.
|
|
21
|
+
* The seat's own parameter support is host-dependent; doing the substitution
|
|
22
|
+
* locally keeps a parameterized row message working on every host (and in the
|
|
23
|
+
* test double, whose `t` takes the key only).
|
|
24
|
+
* @param t - the locale-bound translate seat.
|
|
25
|
+
* @param key - the dictionary key.
|
|
26
|
+
* @param params - placeholder values.
|
|
27
|
+
* @returns the interpolated copy.
|
|
28
|
+
*/
|
|
29
|
+
function interpolate(t: Translate, key: PromptEnhanceKey, params: Record<string, string>): string {
|
|
30
|
+
let text = t(key)
|
|
31
|
+
for (const [name, value] of Object.entries(params)) text = text.split(`{${name}}`).join(value)
|
|
32
|
+
return text
|
|
33
|
+
}
|
|
34
|
+
|
|
19
35
|
/**
|
|
20
36
|
* Resolve the Plugins-page copy reader: the injected `t` when present, the
|
|
21
37
|
* shipped Chinese dictionary otherwise. Falling back keeps an older host (or a
|
|
@@ -84,7 +100,7 @@ export function sectionCopy(t: Translate, chinese: boolean): RowCopy {
|
|
|
84
100
|
hint: (row) => t(row.hint),
|
|
85
101
|
placeholder: (row) => (row.placeholder === undefined ? undefined : t(row.placeholder)),
|
|
86
102
|
choice: (key) => t(key),
|
|
87
|
-
interpolate: (key, params) => t
|
|
103
|
+
interpolate: (key, params) => interpolate(t, key, params),
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
106
|
|
|
@@ -117,6 +133,6 @@ export function pageCopy(t: Translate): RowCopy {
|
|
|
117
133
|
hint: (row) => t(row.hint),
|
|
118
134
|
placeholder: (row) => (row.placeholder === undefined ? undefined : t(row.placeholder)),
|
|
119
135
|
choice: (key) => t(key),
|
|
120
|
-
interpolate: (key, params) => t
|
|
136
|
+
interpolate: (key, params) => interpolate(t, key, params),
|
|
121
137
|
}
|
|
122
138
|
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { SettingsFormModel, settingsNumberField, settingsTextField } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
13
13
|
import type { SettingsFieldDescriptor } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
14
14
|
import { DEFAULT_VALUES } from '../shared/defaults'
|
|
15
|
+
import { FIELD_LIMITS, TEMPERATURE, type NumericRange } from '../shared/limits'
|
|
15
16
|
import { parseShortcut } from './shortcut'
|
|
16
17
|
import type { PromptEnhanceKey } from './locales'
|
|
17
18
|
import type { RowCopy, Translate } from './settings-page-copy'
|
|
@@ -130,10 +131,35 @@ export interface Row {
|
|
|
130
131
|
* Absent means "anything the descriptor stages is writable".
|
|
131
132
|
*/
|
|
132
133
|
readonly validate?: (text: string) => boolean
|
|
134
|
+
/** Inclusive bounds a number row enforces; `integer` defaults to true. */
|
|
135
|
+
readonly range?: NumericRange & { readonly integer?: boolean }
|
|
133
136
|
/** Offer the press-a-combination recorder next to the input (the shortcut row). */
|
|
134
137
|
readonly recordable?: boolean
|
|
135
138
|
}
|
|
136
139
|
|
|
140
|
+
/** Whether one staged numeric text is writable: empty clears, otherwise an in-range number. */
|
|
141
|
+
function validateNumber(text: string, range: NumericRange, integer: boolean): boolean {
|
|
142
|
+
const trimmed = text.trim()
|
|
143
|
+
// Empty means "clear" in the form model, so it is valid for every row.
|
|
144
|
+
if (trimmed === '') return true
|
|
145
|
+
const value = Number(trimmed)
|
|
146
|
+
if (!Number.isFinite(value)) return false
|
|
147
|
+
if (integer && !Number.isInteger(value)) return false
|
|
148
|
+
return value >= range.min && value <= range.max
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** One numeric row: its real bounds plus the staged-text validation the red-box path reads. */
|
|
152
|
+
function numberRow(key: string, label: PromptEnhanceKey, hint: PromptEnhanceKey, range: NumericRange, integer = true): Row {
|
|
153
|
+
return {
|
|
154
|
+
key,
|
|
155
|
+
kind: 'number',
|
|
156
|
+
label,
|
|
157
|
+
hint,
|
|
158
|
+
range: { ...range, integer },
|
|
159
|
+
validate: (text: string) => validateNumber(text, range, integer),
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
137
163
|
/**
|
|
138
164
|
* Every row both pages edit, in display order: the master switch and the two
|
|
139
165
|
* display/context switches first, then routing and generation, then the
|
|
@@ -144,7 +170,7 @@ export const BASIC_ROWS: readonly Row[] = [
|
|
|
144
170
|
{ key: 'provider', kind: 'provider', label: 'settings.row.provider.label', hint: 'settings.row.provider.hint' },
|
|
145
171
|
{ key: 'model', kind: 'model', label: 'settings.row.model.label', hint: 'settings.row.model.hint' },
|
|
146
172
|
{ key: 'reasoningEffort', kind: 'reasoning', label: 'settings.row.reasoningEffort.label', hint: 'settings.row.reasoningEffort.hint' },
|
|
147
|
-
|
|
173
|
+
numberRow('temperature', 'settings.row.temperature.label', 'settings.row.temperature.hint', TEMPERATURE, false),
|
|
148
174
|
{ key: 'contextAware', kind: 'boolean', label: 'settings.row.contextAware.label', hint: 'settings.row.contextAware.hint' },
|
|
149
175
|
{ key: 'streaming', kind: 'boolean', label: 'settings.row.streaming.label', hint: 'settings.row.streaming.hint' },
|
|
150
176
|
{ key: 'systemPrompt', kind: 'text', label: 'settings.row.systemPrompt.label', hint: 'settings.row.systemPrompt.hint', placeholder: 'settings.row.systemPrompt.placeholder' },
|
|
@@ -165,13 +191,13 @@ export const ADVANCED_ROWS: readonly Row[] = [
|
|
|
165
191
|
{ key: 'foldAnimation', kind: 'boolean', label: 'settings.row.foldAnimation.label', hint: 'settings.row.foldAnimation.hint' },
|
|
166
192
|
{ key: 'autoFold', kind: 'boolean', label: 'settings.row.autoFold.label', hint: 'settings.row.autoFold.hint' },
|
|
167
193
|
{ key: 'strategyMode', kind: 'strategy', label: 'settings.row.strategyMode.label', hint: 'settings.row.strategyMode.hint' },
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
194
|
+
numberRow('maxInputChars', 'settings.row.maxInputChars.label', 'settings.row.maxInputChars.hint', FIELD_LIMITS.maxInputChars),
|
|
195
|
+
numberRow('maxOutputTokens', 'settings.row.maxOutputTokens.label', 'settings.row.maxOutputTokens.hint', FIELD_LIMITS.maxOutputTokens),
|
|
196
|
+
numberRow('timeoutMs', 'settings.row.timeoutMs.label', 'settings.row.timeoutMs.hint', FIELD_LIMITS.timeoutMs),
|
|
197
|
+
numberRow('contextMaxMessages', 'settings.row.contextMaxMessages.label', 'settings.row.contextMaxMessages.hint', FIELD_LIMITS.contextMaxMessages),
|
|
198
|
+
numberRow('contextMaxChars', 'settings.row.contextMaxChars.label', 'settings.row.contextMaxChars.hint', FIELD_LIMITS.contextMaxChars),
|
|
199
|
+
numberRow('maxConcurrent', 'settings.row.maxConcurrent.label', 'settings.row.maxConcurrent.hint', FIELD_LIMITS.maxConcurrent),
|
|
200
|
+
numberRow('rateLimitPerMinute', 'settings.row.rateLimitPerMinute.label', 'settings.row.rateLimitPerMinute.hint', FIELD_LIMITS.rateLimitPerMinute),
|
|
175
201
|
]
|
|
176
202
|
|
|
177
203
|
/** Every row both pages edit; the renderer splits it at the Advanced boundary. */
|