@surfishs/dsh-prompt-enhance 0.1.2 → 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/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.2",
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
- ui.openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort() })
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}
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { useCallback, useRef, useState, type ReactNode } from 'react'
10
10
  import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
11
- import type { EnhanceError, EnhanceUsage, ClientFailureReason } from '../shared/protocol'
11
+ import type { ContextUsage, EnhanceError, EnhanceUsage, ClientFailureReason } from '../shared/protocol'
12
12
  import type { PromptEnhanceKey } from './locales'
13
13
  import type { PanelState } from './ui-state'
14
14
  import { ChevronIcon, CopyIcon, FillIcon, RegenerateIcon, UndoIcon, XIcon } from './ActionIcons'
@@ -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). */
@@ -177,9 +179,66 @@ function totalTokensOf(usage: EnhanceUsage): number {
177
179
  return usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0)
178
180
  }
179
181
 
182
+ /**
183
+ * Footer info button: the call's context usage, on hover/focus (and a tap on
184
+ * touch devices, where there is no hover). The card has no room for this in
185
+ * its header, and the footer keeps the action row intact.
186
+ * @param props - the usage numbers and the locale seat.
187
+ * @returns the info button and its tooltip.
188
+ */
189
+ function ContextUsageInfo(props: { usage?: ContextUsage; attachments?: { count: number }; t: TranslateNS<'dsh-prompt-enhance'> }): ReactNode {
190
+ const { usage, attachments, t } = props
191
+ const [open, setOpen] = useState(false)
192
+ // Reaching the turn cap is the normal shape of the window, not a warning;
193
+ // only a character squeeze or a cut turn needs the amber treatment.
194
+ const limited = usage !== undefined && (usage.cutTurn || usage.limitedBy === 'chars')
195
+ const percent = usage !== undefined && usage.maxChars > 0 ? Math.round((usage.usedChars / usage.maxChars) * 100) : 0
196
+ const stats =
197
+ usage === undefined
198
+ ? t('panel.contextUnused')
199
+ : t('panel.contextStats', {
200
+ turns: usage.usedTurns,
201
+ maxTurns: usage.maxTurns,
202
+ chars: formatTokens(usage.usedChars),
203
+ maxChars: formatTokens(usage.maxChars),
204
+ percent,
205
+ })
206
+ const reason = usage === undefined ? '' : usage.cutTurn ? t('panel.contextCut') : usage.limitedBy === 'chars' ? t('panel.contextCharsLimited') : ''
207
+ return (
208
+ <span className="dsh-pe-context-wrap">
209
+ <button
210
+ type="button"
211
+ className={`dsh-pe-context${limited ? ' is-limited' : ''}`}
212
+ aria-label={t('panel.contextUsage')}
213
+ aria-expanded={open}
214
+ onMouseEnter={() => setOpen(true)}
215
+ onMouseLeave={() => setOpen(false)}
216
+ onFocus={() => setOpen(true)}
217
+ onBlur={() => setOpen(false)}
218
+ onClick={() => setOpen((value) => !value)}
219
+ onKeyDown={(event) => {
220
+ if (event.key === 'Escape') setOpen(false)
221
+ }}
222
+ >
223
+ <svg className="dsh-pe-context-icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
224
+ <rect x="2.2" y="3.4" width="11.6" height="9.2" rx="2.2" fill="none" stroke="currentColor" strokeWidth="1.2" />
225
+ <path d="M5.2 6.6h5.6M5.2 9.2h3.8" fill="none" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round" />
226
+ </svg>
227
+ </button>
228
+ {open && (
229
+ <span role="tooltip" className="dsh-pe-context-tip">
230
+ <span className="dsh-pe-context-stats">{stats}</span>
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>}
233
+ </span>
234
+ )}
235
+ </span>
236
+ )
237
+ }
238
+
180
239
  /** One enhancement result card. */
181
240
  export function ResultPanel(props: ResultPanelProps): ReactNode {
182
- 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
183
242
  const [copied, setCopied] = useState<'idle' | 'ok' | 'failed'>('idle')
184
243
  /** Pending reset of the copy label; one timer only, so a second copy cannot be cut short by the first. */
185
244
  const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
@@ -273,7 +332,7 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
273
332
  {/* Collapsed, the body — and with it the warnings — is hidden, so the
274
333
  header carries a marker instead of silently swallowing one. */}
275
334
  {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">
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">
277
336
  ⚠
278
337
  </span>
279
338
  ) : null}
@@ -331,16 +390,24 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
331
390
  </div>
332
391
  )}
333
392
 
334
- {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>}
335
394
 
336
- {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>}
337
396
  </div>
338
397
  </div>
339
398
 
340
399
  <footer className="dsh-pe-foot">
400
+ {state.phase === 'result' && <ContextUsageInfo usage={state.result?.context} attachments={state.attachments} t={t} />}
341
401
  <span className="dsh-pe-grow" />
342
402
  {state.phase === 'result' && (
343
- <button type="button" className="dsh-pe-btn-action plain dsh-pe-btn-floor" onClick={onRegenerate} disabled={onRegenerate === undefined}>
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
+ >
344
411
  <RegenerateIcon />
345
412
  <span className="dsh-pe-swap">
346
413
  {swapLabel(!regenerated, t('panel.regenerate'))}
@@ -11,6 +11,7 @@ import {
11
11
  type EnhanceError,
12
12
  type EnhanceErrorCode,
13
13
  type EnhanceRequestBody,
14
+ type ContextUsage,
14
15
  type EnhanceResult,
15
16
  type EnhanceStreamEvent,
16
17
  type EnhanceUsage,
@@ -82,6 +83,41 @@ function parseUsage(value: unknown): EnhanceUsage | undefined {
82
83
  }
83
84
 
84
85
  /** Strictly narrow one success value; anything malformed is a client-visible error. */
86
+ /**
87
+ * Validate the optional context-usage block the host sends with a result.
88
+ *
89
+ * The panel relies on the numbers being integers (malformed fractions would
90
+ * format oddly) and on `limitedBy` being one of the two caps; anything else
91
+ * is treated as "no usage" rather than surfacing a broken tooltip.
92
+ * @param value - the untrusted wire value.
93
+ * @returns the usage, or undefined when absent/malformed.
94
+ */
95
+ function parseContextUsage(value: unknown): ContextUsage | undefined {
96
+ const record = value as Partial<ContextUsage> | null
97
+ if (record === null || typeof record !== 'object') return undefined
98
+ const integer = (field: unknown): field is number => typeof field === 'number' && Number.isInteger(field) && field >= 0
99
+ if (
100
+ !integer(record.usedTurns) ||
101
+ !integer(record.maxTurns) ||
102
+ !integer(record.usedChars) ||
103
+ !integer(record.maxChars) ||
104
+ !integer(record.droppedTurns) ||
105
+ (record.limitedBy !== null && record.limitedBy !== 'turns' && record.limitedBy !== 'chars') ||
106
+ typeof record.cutTurn !== 'boolean'
107
+ ) {
108
+ return undefined
109
+ }
110
+ return {
111
+ usedTurns: record.usedTurns,
112
+ maxTurns: record.maxTurns,
113
+ usedChars: record.usedChars,
114
+ maxChars: record.maxChars,
115
+ droppedTurns: record.droppedTurns,
116
+ limitedBy: record.limitedBy,
117
+ cutTurn: record.cutTurn,
118
+ }
119
+ }
120
+
85
121
  function parseResult(value: unknown): EnhanceResult {
86
122
  const record = value as Partial<EnhanceResult> | null
87
123
  if (
@@ -97,6 +133,7 @@ function parseResult(value: unknown): EnhanceResult {
97
133
  Number.isFinite(record.elapsedMs)
98
134
  ) {
99
135
  const usage = parseUsage((record as { usage?: unknown }).usage)
136
+ const context = parseContextUsage((record as { context?: unknown }).context)
100
137
  return {
101
138
  text: record.text,
102
139
  provider: record.provider,
@@ -113,6 +150,7 @@ function parseResult(value: unknown): EnhanceResult {
113
150
  // drops anything not listed here, so a new result field has to be added
114
151
  // in this exact place or the UI silently never sees it.
115
152
  ...(typeof record.reasoningEffort === 'string' ? { reasoningEffort: record.reasoningEffort } : {}),
153
+ ...(context === undefined ? {} : { context }),
116
154
  }
117
155
  }
118
156
  throw new EnhanceClientError({ code: 'internal', params: { reason: 'malformed' } })
@@ -18,7 +18,7 @@ export const zh = {
18
18
  'menu.effortsNone': '该模型未声明推理档位',
19
19
  'menu.effortsFailed': '无法读取该模型的档位',
20
20
  'menu.effort': '推理等级',
21
- 'menu.effortDefault': '不指定',
21
+ 'menu.effortDefault': '模型默认',
22
22
  'menu.context': '上下文感知',
23
23
  'menu.contextOn': '开',
24
24
  'menu.contextOff': '关',
@@ -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,12 +41,21 @@ export const zh = {
40
41
  'panel.collapse': '折叠',
41
42
  'panel.expand': '展开',
42
43
  'panel.retry': '重试',
43
- 'panel.stale.warn': '草稿已改动,当前结果基于旧文本。「重新生成」会按当前文本重跑;回填仍会覆盖当前输入(可撤销)。',
44
- 'panel.truncated': '输出被截断(达到输出上限),结果可能不完整。可在设置里调高「输出 token 上限」后重新生成。',
44
+ 'panel.stale.warn': '草稿已改动:当前结果基于旧文本。「重新生成」会按当前文本重跑;回填会覆盖你后来的修改(可撤销)。',
45
+ 'panel.stale.empty': '草稿已改动:当前为空。「重新生成」不可用,请先输入文字;回填会覆盖你后来的修改(可撤销)。',
46
+ 'panel.stale.dot': '草稿已改动',
47
+ 'panel.truncated': '输出已达到「输出 token 上限」,结果可能不完整。请在设置里调高该上限后再重新生成。',
48
+ 'panel.truncated.dot': '输出被截断',
49
+ 'panel.contextUsage': '上下文用量',
50
+ 'panel.contextStats': '上下文 {turns}/{maxTurns} 条 · {chars}/{maxChars} 字({percent}%)',
51
+ 'panel.contextCharsLimited': '已达字数上限,较早内容未发送',
52
+ 'panel.contextCut': '已达字数上限,最新一条仅发送了开头',
53
+ 'panel.contextUnused': '本次未使用上下文',
54
+ 'panel.attachmentsCount': '附件:{count} 个',
45
55
  'panel.model': '模型:{provider} / {model}',
46
56
  'panel.elapsed': '耗时 {ms}',
47
57
  'panel.tokens': '{total} tokens',
48
- 'panel.effortDefault': '不指定',
58
+ 'panel.effortDefault': '模型默认',
49
59
  'panel.tokens.input': '输入 {count}',
50
60
  'panel.tokens.output': '输出 {count}',
51
61
  'panel.tokens.cacheRead': '缓存读取 {count}',
@@ -53,34 +63,35 @@ export const zh = {
53
63
  'undo.applied': '已替换原提示词',
54
64
  'undo.undo': '撤销',
55
65
  'undo.dismiss': '关闭提示',
56
- 'error.empty': '输入框为空,请先输入要增强的提示词。',
57
- 'error.tooLong': '内容 {count} 字,超过 {max} 字上限(按字符计,非 token);不会自动截断,请精简后重试。',
58
- 'error.occurrences': '输入内容包含命令或文件引用,暂不支持增强;请先移除后再试。',
59
- 'error.chipsUnknown': '无法读取输入框里的引用状态;为避免覆盖你的命令或文件引用,本次已阻止。请改为纯文本后重试。',
60
- 'error.phase': '当前输入正被占用(提交中),请稍后再试。',
61
- 'error.disabled': '提示词增强已在插件设置中关闭,可在设置里重新开启。',
62
- 'error.rejected': '增强请求被拒绝。请稍后重试;若持续出现,请检查插件设置。',
63
- 'error.timeout': '增强超时({seconds} 秒)。可直接重试,或到设置里调高「超时(毫秒)」;原输入未改动。',
64
- 'error.unconfigured': '还没确定用哪个模型:请在插件设置里填写 provider 和 model(两项都要填),或在当前会话先发一条消息以跟随会话模型。',
65
- 'error.effortUnsupported': '该模型不支持所选推理档位「{effort}」,请改选其它档位,或改用「不指定」。',
66
- 'error.upstream': '模型服务返回错误;若下方有详情,请按详情处理,否则可直接重试。原输入未改动。',
67
- 'error.internal': '增强失败,请重试;若反复失败,请查看 dsh 运行日志。原输入未改动。',
68
- 'error.client.unreachable': '无法连接宿主服务,请确认 dsh web 正在运行后重试。',
69
- 'error.client.malformed': '宿主服务返回了无法解析的数据,请重试;原输入未改动。',
70
- 'error.client.refused': '宿主服务拒绝了请求(HTTP {status}),请稍后重试。',
71
- 'error.client.streamClosed': '宿主服务提前关闭了增强流,请重试;原输入未改动。',
72
- 'error.client.cancelled': '已取消增强;原输入未改动。',
73
- 'error.rateLimit': '请求过于频繁:每分钟最多 {limit} 次增强,请在 {retryAfterSeconds} 秒后再试。',
74
- 'error.concurrencyLimit': '已有 {max} 个增强正在进行,请等其中一个完成后再试。',
75
- 'error.cooldown': '连续 {failures} 次增强失败,已暂停 {retryAfterSeconds} 秒以免持续冲击模型服务;可稍后重试,或先检查模型配置。',
76
- 'error.upstream.auth': '鉴权失败:请检查该 provider 的 API Key 配置。',
77
- 'error.upstream.invalidCredential': '鉴权失败:存储的 API Key 不可用,请修正后重试。',
78
- 'error.upstream.rateLimit': '模型服务限流,请稍后重试。',
79
- 'error.upstream.quota': '模型服务配额/余额不足,请检查账户。',
80
- 'error.upstream.empty': '模型返回了空响应,请重试。',
81
- 'error.upstream.contextWindow': '输入超出模型上下文窗口,请精简原文或更换模型。',
82
- 'error.upstream.toolCall': '模型请求了工具调用,提示词增强只需要纯文本;请更换模型后重试。',
83
- 'error.upstream.maxTokens': '重写结果达到「输出 token 上限」,请调高该设置或精简原文后重试。',
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 上限」。请调高该设置,或精简原文后重试。',
84
95
  'settings.summary': '模型、上下文与资源限制',
85
96
  'settings.title': '提示词增强',
86
97
  'settings.description': '把输入框草稿改写为结构化提示词:角色与目标、可执行步骤、输出格式、验收标准、边界条件。原文保留,失败不改草稿;保存后下一次调用即生效。',
@@ -103,7 +114,7 @@ export const zh = {
103
114
  'settings.row.enabled.label': '总开关',
104
115
  'settings.row.enabled.hint': '关闭后隐藏输入框的增强按钮,命令与快捷键一并停用。',
105
116
  'settings.row.contextAware.label': '上下文感知',
106
- 'settings.row.contextAware.hint': '读取当前会话最近几轮对话来消解指代、补全省略;无历史时回退为单条增强。',
117
+ 'settings.row.contextAware.hint': '读取当前会话最近几条消息来消解指代、补全省略;无历史时回退为单条增强。',
107
118
  'settings.row.streaming.label': '增量展示',
108
119
  'settings.row.streaming.hint': '模型边写边在面板显示;仅影响显示节奏,最终写入的文本不变。',
109
120
  'settings.row.foldAnimation.label': '卡片折叠动画',
@@ -136,9 +147,12 @@ export const zh = {
136
147
  'settings.row.temperature.label': '温度',
137
148
  'settings.row.temperature.hint': '采样温度(0~1,步进 0.05),越低越忠实原文;默认 0.3。',
138
149
  'settings.row.reasoningEffort.label': '推理预算',
139
- 'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。「不指定」表示不传该字段。',
150
+ 'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。「模型默认」表示不发送该字段,由提供方使用默认档。',
140
151
  'settings.row.maxOutputTokens.label': '输出 token 上限',
141
152
  'settings.row.maxOutputTokens.hint': '单次增强的输出预算;默认 8192。',
153
+ 'settings.row.invalidInteger': '请输入 {min}–{max} 之间的整数',
154
+ 'settings.row.invalidNumber': '请输入 {min}–{max} 之间的数字',
155
+ 'settings.row.blankDefault': '留空 = 使用默认值 {value}',
142
156
  'settings.row.maxInputChars.label': '输入字符上限',
143
157
  'settings.row.maxInputChars.hint': '超出直接拒绝、不截断;默认 12000。',
144
158
  'settings.row.timeoutMs.label': '超时(毫秒)',
@@ -149,7 +163,7 @@ export const zh = {
149
163
  'settings.row.systemPrompt.hint': '留空使用内置增强策略。',
150
164
  'settings.row.systemPrompt.placeholder': '例:把用户的中文输入翻译成英文。',
151
165
  'settings.row.contextMaxMessages.label': '上下文消息条数',
152
- 'settings.row.contextMaxMessages.hint': '最多参考最近多少轮对话;0 表示不参考;默认 8。',
166
+ 'settings.row.contextMaxMessages.hint': '最多参考最近多少条消息;0 表示不参考;默认 8。',
153
167
  'settings.row.contextMaxChars.label': '上下文字符上限',
154
168
  'settings.row.contextMaxChars.hint': '历史片段的字符预算;0 表示不参考;默认 4000。',
155
169
  'settings.row.maxConcurrent.label': '并发上限',
@@ -161,7 +175,7 @@ export const zh = {
161
175
  'settings.row.shortcut.placeholder': '例:ctrl+alt+shift+e',
162
176
  'settings.strategy.replace': '替换内置策略',
163
177
  'settings.strategy.extend': '追加在内置策略后',
164
- 'settings.reasoning.inherit': '不指定',
178
+ 'settings.reasoning.inherit': '模型默认',
165
179
  'settings.reasoning.loading': '正在读取该模型的档位…',
166
180
  'settings.reasoning.unavailable': '无法读取该模型的档位列表;已保存的档位仍会照常发送。',
167
181
  'settings.reasoning.noTiers': '该模型未声明推理档位;调用时不发送档位,由提供方决定。',
@@ -191,7 +205,7 @@ export const en: Record<PromptEnhanceKey, string> = {
191
205
  'menu.effortsNone': 'This model declares no reasoning tiers',
192
206
  'menu.effortsFailed': 'Could not read this model tiers',
193
207
  'menu.effort': 'Reasoning effort',
194
- 'menu.effortDefault': 'Not specified',
208
+ 'menu.effortDefault': 'Model default',
195
209
  'menu.context': 'Context awareness',
196
210
  'menu.contextOn': 'on',
197
211
  'menu.contextOff': 'off',
@@ -205,6 +219,7 @@ export const en: Record<PromptEnhanceKey, string> = {
205
219
  'panel.enhanced': 'Enhanced result',
206
220
  'panel.apply': 'Fill into input box',
207
221
  'panel.regenerate': 'Regenerate',
222
+ 'panel.regenerate.empty': 'Type some text before regenerating',
208
223
  'panel.regenerated': 'Regenerated',
209
224
  'panel.copy': 'Copy result',
210
225
  'panel.copied': 'Copied',
@@ -213,12 +228,21 @@ export const en: Record<PromptEnhanceKey, string> = {
213
228
  'panel.collapse': 'Collapse',
214
229
  'panel.expand': 'Expand',
215
230
  'panel.retry': 'Retry',
216
- 'panel.stale.warn': 'Draft changed — this result uses the earlier text. Regenerate re-runs on the current draft; Apply still overwrites the input (undoable).',
217
- 'panel.truncated': 'Output was cut at the output limit, so the result may be incomplete. Raise "Output token budget" in the settings, then regenerate.',
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',
236
+ 'panel.contextUsage': 'Context usage',
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',
240
+ 'panel.contextUnused': 'No conversation context was used for this call',
241
+ 'panel.attachmentsCount': 'Attachments: {count}',
218
242
  'panel.model': 'Model: {provider} / {model}',
219
243
  'panel.elapsed': '{ms} elapsed',
220
244
  'panel.tokens': '{total} tokens',
221
- 'panel.effortDefault': 'Not specified',
245
+ 'panel.effortDefault': 'Model default',
222
246
  'panel.tokens.input': 'Input {count}',
223
247
  'panel.tokens.output': 'Output {count}',
224
248
  'panel.tokens.cacheRead': 'Cache read {count}',
@@ -226,35 +250,36 @@ export const en: Record<PromptEnhanceKey, string> = {
226
250
  'undo.applied': 'Original draft replaced',
227
251
  'undo.undo': 'Undo',
228
252
  'undo.dismiss': 'Dismiss',
229
- 'error.empty': 'The input box is empty — type a prompt to enhance first.',
230
- 'error.tooLong': 'The draft is {count} characters, over the {max} limit (characters, not tokens); it is never truncated automatically — please shorten it.',
231
- 'error.occurrences': 'The draft contains commands or file references, which are not supported yet — remove them first.',
232
- 'error.chipsUnknown': 'The composer reference state could not be read, so the enhancement was blocked to avoid overwriting your command or file reference. Use plain text, then retry.',
233
- 'error.phase': 'The input box is busy (submitting) — try again in a moment.',
234
- 'error.disabled': 'Prompt enhance is disabled in the plugin settings; re-enable it there.',
235
- 'error.rejected': 'The enhance request was rejected. Retry later; if it persists, check the plugin settings.',
236
- 'error.timeout': 'The enhancement timed out ({seconds}s). Retry, or raise "Timeout (ms)" in the settings; your draft is untouched.',
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.',
237
262
  'error.unconfigured':
238
- 'No model is configured for the enhancement: fill in both provider and model in the plugin settings, or send a message in the current session first to follow the session model.',
239
- 'error.effortUnsupported': 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "Not specified".',
240
- 'error.upstream': 'The model provider returned an error. If there is detail below, act on it; otherwise retry. Your draft is untouched.',
241
- 'error.internal': 'Enhancement failed. Retry; if it keeps failing, check the dsh logs. Your draft is untouched.',
242
- 'error.client.unreachable': 'Cannot reach the host service — make sure dsh web is running, then retry.',
243
- 'error.client.malformed': 'The host returned data that could not be parsed. Retry; your draft is untouched.',
244
- 'error.client.refused': 'The host refused the request (HTTP {status}). Retry later.',
245
- 'error.client.streamClosed': 'The host closed the enhance stream early. Retry; your draft is untouched.',
246
- 'error.client.cancelled': 'The enhancement was cancelled; your draft is untouched.',
247
- 'error.rateLimit': 'Too many requests — at most {limit} enhancements per minute; retry in {retryAfterSeconds} seconds.',
248
- 'error.concurrencyLimit': '{max} enhancements are already running — wait for one to finish, then retry.',
249
- 'error.cooldown': '{failures} enhancements failed in a row; calls are paused for {retryAfterSeconds}s to stop hammering the model service. Retry later, or check the model settings first.',
250
- 'error.upstream.auth': 'Authentication failed — check the API key configured for this provider.',
251
- 'error.upstream.invalidCredential': 'Authentication failed — the stored API key is invalid; fix it and retry.',
252
- 'error.upstream.rateLimit': 'The model provider is rate-limiting; retry later.',
253
- 'error.upstream.quota': 'The model provider reports a quota/balance issue — check your account.',
254
- 'error.upstream.empty': 'The model returned an empty response; retry.',
255
- 'error.upstream.contextWindow': 'The input exceeds the model context window — shorten it or switch models.',
256
- 'error.upstream.toolCall': 'The model requested tool calls, but prompt enhance needs plain text — switch models and retry.',
257
- 'error.upstream.maxTokens': 'The rewrite hit the "Output token budget" limit — raise that setting or shorten the draft, then retry.',
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.',
258
283
  'settings.summary': 'Model, context, and resource limits',
259
284
  'settings.title': 'Prompt enhance',
260
285
  'settings.description':
@@ -278,7 +303,7 @@ export const en: Record<PromptEnhanceKey, string> = {
278
303
  'settings.row.enabled.label': 'Master switch',
279
304
  'settings.row.enabled.hint': 'Off hides the composer button and disables the command and the shortcut.',
280
305
  'settings.row.contextAware.label': 'Context aware',
281
- 'settings.row.contextAware.hint': 'Reads the recent turns of the current conversation; falls back to a single-prompt rewrite when there is no history.',
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.',
282
307
  'settings.row.streaming.label': 'Streaming display',
283
308
  'settings.row.streaming.hint': 'Shows the rewrite while it is being written. Display only: the applied text is unchanged.',
284
309
  'settings.row.foldAnimation.label': 'Card fold animation',
@@ -312,9 +337,13 @@ export const en: Record<PromptEnhanceKey, string> = {
312
337
  'settings.row.temperature.label': 'Temperature',
313
338
  'settings.row.temperature.hint': 'Sampling temperature (0–1, step 0.05); lower stays closer to the original. Default 0.3.',
314
339
  'settings.row.reasoningEffort.label': 'Reasoning effort',
315
- 'settings.row.reasoningEffort.hint': 'Tier choices come from what the configured provider/model declares; custom models are read on demand. "Not specified" omits the field.',
340
+ 'settings.row.reasoningEffort.hint':
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.',
316
342
  'settings.row.maxOutputTokens.label': 'Output token budget',
317
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}',
318
347
  'settings.row.maxInputChars.label': 'Input character cap',
319
348
  'settings.row.maxInputChars.hint': 'Over-limit drafts are rejected, never truncated. Default 12000.',
320
349
  'settings.row.timeoutMs.label': 'Timeout (ms)',
@@ -325,8 +354,8 @@ export const en: Record<PromptEnhanceKey, string> = {
325
354
  'settings.row.systemPrompt.label': 'Custom system prompt',
326
355
  'settings.row.systemPrompt.hint': 'Leave empty to use the built-in enhancement strategy.',
327
356
  'settings.row.systemPrompt.placeholder': 'e.g. translate the user text from Chinese into English.',
328
- 'settings.row.contextMaxMessages.label': 'Context turns',
329
- 'settings.row.contextMaxMessages.hint': 'How many recent turns may ground the rewrite; 0 disables context. Default 8.',
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.',
330
359
  'settings.row.contextMaxChars.label': 'Context characters',
331
360
  'settings.row.contextMaxChars.hint': 'Character budget for the context snippet; 0 disables it. Default 4000.',
332
361
  'settings.row.maxConcurrent.label': 'Concurrency cap',
@@ -338,7 +367,7 @@ export const en: Record<PromptEnhanceKey, string> = {
338
367
  'settings.row.shortcut.placeholder': 'e.g. ctrl+alt+shift+e',
339
368
  'settings.strategy.replace': 'Replace the built-in strategy',
340
369
  'settings.strategy.extend': 'Append after the built-in strategy',
341
- 'settings.reasoning.inherit': 'Not specified',
370
+ 'settings.reasoning.inherit': 'Model default',
342
371
  'settings.reasoning.loading': 'Reading this model’s tiers…',
343
372
  'settings.reasoning.unavailable': 'Could not read this model’s tier list; your saved tier is still sent.',
344
373
  'settings.reasoning.noTiers': 'This model declares no reasoning tiers; calls omit the field and let the provider decide.',