@surfishs/dsh-prompt-enhance 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,10 +6,23 @@
6
6
 
7
7
  /** Simplified Chinese dictionary (the key-set source of truth). */
8
8
  export const zh = {
9
- 'button.title': '提示词增强',
9
+ 'button.title': '提示词增强 · 优化输入框里的文字',
10
10
  'button.busy': '正在增强…',
11
- 'button.otherBusy': '另一个会话正在增强中;请等它完成或先关闭其结果面板。',
12
- 'button.emptyTitle': '提示词增强(当前输入区为空,请先输入文字)',
11
+ 'button.otherBusy': '另一个会话正在增强中',
12
+ 'button.emptyTitle': '提示词增强 · 请先输入要优化的文字',
13
+ 'button.quickHint': '(右键配置)',
14
+ 'menu.title': '快捷设置',
15
+ 'menu.model': '模型',
16
+ 'menu.modelFollow': '跟随会话',
17
+ 'menu.modelHint': '在插件设置页修改',
18
+ 'menu.effortsNone': '该模型未声明推理档位',
19
+ 'menu.effortsFailed': '无法读取该模型的档位',
20
+ 'menu.effort': '推理等级',
21
+ 'menu.effortDefault': '不指定',
22
+ 'menu.context': '上下文感知',
23
+ 'menu.contextOn': '开',
24
+ 'menu.contextOff': '关',
25
+ 'menu.writeFailed': '写入失败,请稍后再试。',
13
26
  'panel.title': '提示词增强',
14
27
  'panel.loading': '正在增强,稍候…',
15
28
  'panel.streaming': '正在生成…',
@@ -19,20 +32,20 @@ export const zh = {
19
32
  'panel.enhanced': '增强结果',
20
33
  'panel.apply': '回填到输入框',
21
34
  'panel.regenerate': '重新生成',
22
- 'panel.appliedShort': '已替换 ✓',
23
- 'panel.undoneShort': '已撤销 ✓',
24
- 'panel.regeneratedShort': '已重新生成 ✓',
25
- 'panel.copiedShort': '已复制 ✓',
35
+ 'panel.regenerated': '已重新生成',
26
36
  'panel.copy': '复制结果',
27
37
  'panel.copied': '已复制',
28
38
  'panel.copyFailed': '复制失败',
29
39
  'panel.close': '关闭',
40
+ 'panel.collapse': '折叠',
41
+ 'panel.expand': '展开',
30
42
  'panel.retry': '重试',
31
- 'panel.stale.warn': '草稿已改动,当前结果基于改动前的文本;回填会覆盖当前输入(可撤销)。',
32
- 'panel.truncated': '输出达到 Token 上限,结果可能不完整。可在设置中调高「最大输出 Token」。',
43
+ 'panel.stale.warn': '草稿已改动,当前结果基于旧文本。「重新生成」会按当前文本重跑;回填仍会覆盖当前输入(可撤销)。',
44
+ 'panel.truncated': '输出被截断(达到输出上限),结果可能不完整。可在设置里调高「输出 token 上限」后重新生成。',
33
45
  'panel.model': '模型:{provider} / {model}',
34
46
  'panel.elapsed': '耗时 {ms}',
35
47
  'panel.tokens': '{total} tokens',
48
+ 'panel.effortDefault': '不指定',
36
49
  'panel.tokens.input': '输入 {count}',
37
50
  'panel.tokens.output': '输出 {count}',
38
51
  'panel.tokens.cacheRead': '缓存读取 {count}',
@@ -41,17 +54,17 @@ export const zh = {
41
54
  'undo.undo': '撤销',
42
55
  'undo.dismiss': '关闭提示',
43
56
  'error.empty': '输入框为空,请先输入要增强的提示词。',
44
- 'error.tooLong': '内容共 {count} 个字符,超过 {max} 个字符上限(按 Unicode 字符数统计,不是 token 数)。为避免改变原意不会自动截断,请精简后再试。',
57
+ 'error.tooLong': '内容 {count} 字,超过 {max} 字上限(按字符计,非 token);不会自动截断,请精简后重试。',
45
58
  'error.occurrences': '输入内容包含命令或文件引用,暂不支持增强;请先移除后再试。',
46
- 'error.chipsUnknown': '无法读取输入框的引用状态(宿主未提供引用信息)。为避免覆盖已添加的命令或文件引用,本次增强已阻止;请清空输入框后输入纯文本草稿,或升级 DSH 后重试。',
59
+ 'error.chipsUnknown': '无法读取输入框里的引用状态;为避免覆盖你的命令或文件引用,本次已阻止。请改为纯文本后重试。',
47
60
  'error.phase': '当前输入正被占用(提交中),请稍后再试。',
48
- 'error.disabled': '提示词增强已在插件设置中关闭。',
49
- 'error.rejected': '增强请求被拒绝。',
50
- 'error.timeout': '增强超时({seconds} 秒),请重试;原输入未改动。',
51
- 'error.unconfigured': '尚未确定增强用的模型:请在插件设置中成对填写 provider/model,或先在当前会话发送一条消息(将跟随会话模型)。',
52
- 'error.effortUnsupported': '该模型不支持所选推理档位「{effort}」,请改选其它档位,或改用「跟随提供方默认」。',
53
- 'error.upstream': '模型服务返回错误,请重试;原输入未改动。',
54
- 'error.internal': '增强失败,请重试;原输入未改动。',
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 运行日志。原输入未改动。',
55
68
  'error.client.unreachable': '无法连接宿主服务,请确认 dsh web 正在运行后重试。',
56
69
  'error.client.malformed': '宿主服务返回了无法解析的数据,请重试;原输入未改动。',
57
70
  'error.client.refused': '宿主服务拒绝了请求(HTTP {status}),请稍后重试。',
@@ -59,7 +72,7 @@ export const zh = {
59
72
  'error.client.cancelled': '已取消增强;原输入未改动。',
60
73
  'error.rateLimit': '请求过于频繁:每分钟最多 {limit} 次增强,请在 {retryAfterSeconds} 秒后再试。',
61
74
  'error.concurrencyLimit': '已有 {max} 个增强正在进行,请等其中一个完成后再试。',
62
- 'error.cooldown': '连续 {failures} 次增强失败,已暂停调用以免持续冲击模型服务;请 {retryAfterSeconds} 秒后重试,或先检查设置里的模型配置。',
75
+ 'error.cooldown': '连续 {failures} 次增强失败,已暂停 {retryAfterSeconds} 秒以免持续冲击模型服务;可稍后重试,或先检查模型配置。',
63
76
  'error.upstream.auth': '鉴权失败:请检查该 provider 的 API Key 配置。',
64
77
  'error.upstream.invalidCredential': '鉴权失败:存储的 API Key 不可用,请修正后重试。',
65
78
  'error.upstream.rateLimit': '模型服务限流,请稍后重试。',
@@ -67,7 +80,7 @@ export const zh = {
67
80
  'error.upstream.empty': '模型返回了空响应,请重试。',
68
81
  'error.upstream.contextWindow': '输入超出模型上下文窗口,请精简原文或更换模型。',
69
82
  'error.upstream.toolCall': '模型请求了工具调用,提示词增强只需要纯文本;请更换模型后重试。',
70
- 'error.upstream.maxTokens': '重写结果达到输出上限(maxOutputTokens),请在设置中调大上限或精简原文后重试。',
83
+ 'error.upstream.maxTokens': '重写结果达到「输出 token 上限」,请调高该设置或精简原文后重试。',
71
84
  'settings.summary': '模型、上下文与资源限制',
72
85
  'settings.title': '提示词增强',
73
86
  'settings.description': '把输入框草稿改写为结构化提示词:角色与目标、可执行步骤、输出格式、验收标准、边界条件。原文保留,失败不改草稿;保存后下一次调用即生效。',
@@ -81,6 +94,11 @@ export const zh = {
81
94
  'settings.unavailable': '该插件当前未加载,暂时无法配置。',
82
95
  'settings.reset': '恢复默认',
83
96
  'settings.invalidNumber': '请填数字;留空表示使用默认值。',
97
+ 'settings.record': '录制',
98
+ 'settings.recordStop': '取消录制',
99
+ 'settings.recordPrompt': '请按下组合键(Esc 取消)',
100
+ 'settings.recordNeedsModifier': '需要至少按住 ctrl / alt / meta 中的一个',
101
+ 'settings.invalidShortcut': '写法无效,快捷键不会生效:需包含 ctrl / alt / meta 中至少一个,键放在最后,例如 ctrl+alt+e。',
84
102
  'settings.disconnected': '表单没有接通:宿主没有向这个页面注入表单状态。插件仍按组合配置工作。',
85
103
  'settings.row.enabled.label': '总开关',
86
104
  'settings.row.enabled.hint': '关闭后隐藏输入框的增强按钮,命令与快捷键一并停用。',
@@ -88,6 +106,10 @@ export const zh = {
88
106
  'settings.row.contextAware.hint': '读取当前会话最近几轮对话来消解指代、补全省略;无历史时回退为单条增强。',
89
107
  'settings.row.streaming.label': '增量展示',
90
108
  'settings.row.streaming.hint': '模型边写边在面板显示;仅影响显示节奏,最终写入的文本不变。',
109
+ 'settings.row.foldAnimation.label': '卡片折叠动画',
110
+ 'settings.row.foldAnimation.hint': '展开/收起时播放过渡;关闭后立即切换。系统「减少动态效果」偏好始终优先。',
111
+ 'settings.row.autoFold.label': '自动收纳卡片',
112
+ 'settings.row.autoFold.hint': '回填到输入框后自动收起卡片,撤销后自动展开;关闭后卡片保持当前状态。',
91
113
  'settings.row.provider.label': '模型服务方',
92
114
  'settings.row.provider.hint': '从 DSH 已注册的 LLM provider 中选择;留空跟随当前会话的模型。',
93
115
  'settings.row.model.label': '模型 ID',
@@ -114,7 +136,7 @@ export const zh = {
114
136
  'settings.row.temperature.label': '温度',
115
137
  'settings.row.temperature.hint': '采样温度(0~1,步进 0.05),越低越忠实原文;默认 0.3。',
116
138
  'settings.row.reasoningEffort.label': '推理预算',
117
- 'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。提供方默认表示不传该字段。',
139
+ 'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。「不指定」表示不传该字段。',
118
140
  'settings.row.maxOutputTokens.label': '输出 token 上限',
119
141
  'settings.row.maxOutputTokens.hint': '单次增强的输出预算;默认 8192。',
120
142
  'settings.row.maxInputChars.label': '输入字符上限',
@@ -139,14 +161,14 @@ export const zh = {
139
161
  'settings.row.shortcut.placeholder': '例:ctrl+alt+shift+e',
140
162
  'settings.strategy.replace': '替换内置策略',
141
163
  'settings.strategy.extend': '追加在内置策略后',
142
- 'settings.reasoning.inherit': '提供方默认',
164
+ 'settings.reasoning.inherit': '不指定',
143
165
  'settings.reasoning.loading': '正在读取该模型的档位…',
144
166
  'settings.reasoning.unavailable': '无法读取该模型的档位列表;已保存的档位仍会照常发送。',
145
- 'settings.reasoning.noTiers': '该模型未声明推理档位,调用时将跟随提供方默认。',
167
+ 'settings.reasoning.noTiers': '该模型未声明推理档位;调用时不发送档位,由提供方决定。',
146
168
  'settings.reasoning.unsupported': '当前值「{effort}」不在该模型支持的档位中。',
147
169
  'settings.reasoning.current': '当前值:{value}',
148
170
  'settings.reasoning.currentTitle': '该模型未声明此档位',
149
- 'settings.reasoning.refresh': '重新获取档位信息',
171
+ 'settings.reasoning.refresh': '刷新',
150
172
  'settings.reasoning.refreshing': '正在获取档位信息…',
151
173
  'settings.reasoning.refreshOk': '档位信息已更新',
152
174
  'settings.reasoning.refreshFailed': '获取档位信息失败,请重试。',
@@ -157,10 +179,23 @@ export type PromptEnhanceKey = keyof typeof zh
157
179
 
158
180
  /** English dictionary. */
159
181
  export const en: Record<PromptEnhanceKey, string> = {
160
- 'button.title': 'Enhance prompt',
182
+ 'button.title': 'Enhance prompt · rewrite the text in the input box',
161
183
  'button.busy': 'Enhancing…',
162
- 'button.otherBusy': 'Another session is enhancing right now — wait for it, or close its result panel first.',
163
- 'button.emptyTitle': 'Enhance prompt (the input is empty — type something first)',
184
+ 'button.otherBusy': 'Another session is enhancing right now',
185
+ 'button.emptyTitle': 'Enhance prompt · type the text to rewrite first',
186
+ 'button.quickHint': ' (right-click to configure)',
187
+ 'menu.title': 'Quick settings',
188
+ 'menu.model': 'Model',
189
+ 'menu.modelFollow': 'Follow session',
190
+ 'menu.modelHint': 'Change it on the plugin settings page',
191
+ 'menu.effortsNone': 'This model declares no reasoning tiers',
192
+ 'menu.effortsFailed': 'Could not read this model tiers',
193
+ 'menu.effort': 'Reasoning effort',
194
+ 'menu.effortDefault': 'Not specified',
195
+ 'menu.context': 'Context awareness',
196
+ 'menu.contextOn': 'on',
197
+ 'menu.contextOff': 'off',
198
+ 'menu.writeFailed': 'Could not save — try again.',
164
199
  'panel.title': 'Prompt Enhance',
165
200
  'panel.loading': 'Enhancing, please wait…',
166
201
  'panel.streaming': 'Generating…',
@@ -170,20 +205,20 @@ export const en: Record<PromptEnhanceKey, string> = {
170
205
  'panel.enhanced': 'Enhanced result',
171
206
  'panel.apply': 'Fill into input box',
172
207
  'panel.regenerate': 'Regenerate',
173
- 'panel.appliedShort': 'Replaced ✓',
174
- 'panel.undoneShort': 'Undone ✓',
175
- 'panel.regeneratedShort': 'Regenerated ✓',
176
- 'panel.copiedShort': 'Copied ✓',
208
+ 'panel.regenerated': 'Regenerated',
177
209
  'panel.copy': 'Copy result',
178
210
  'panel.copied': 'Copied',
179
211
  'panel.copyFailed': 'Copy failed',
180
212
  'panel.close': 'Close',
213
+ 'panel.collapse': 'Collapse',
214
+ 'panel.expand': 'Expand',
181
215
  'panel.retry': 'Retry',
182
- 'panel.stale.warn': 'Draft changed — this result uses the earlier text; Apply overwrites the current input (undoable).',
183
- 'panel.truncated': 'Output hit the token cap and may be incomplete. Raise "Max output tokens" in the settings.',
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.',
184
218
  'panel.model': 'Model: {provider} / {model}',
185
219
  'panel.elapsed': '{ms} elapsed',
186
220
  'panel.tokens': '{total} tokens',
221
+ 'panel.effortDefault': 'Not specified',
187
222
  'panel.tokens.input': 'Input {count}',
188
223
  'panel.tokens.output': 'Output {count}',
189
224
  'panel.tokens.cacheRead': 'Cache read {count}',
@@ -192,19 +227,18 @@ export const en: Record<PromptEnhanceKey, string> = {
192
227
  'undo.undo': 'Undo',
193
228
  'undo.dismiss': 'Dismiss',
194
229
  'error.empty': 'The input box is empty — type a prompt to enhance first.',
195
- 'error.tooLong': 'The draft is {count} characters, above the {max} cap (Unicode characters, not tokens). It is never auto-truncated (that would change your meaning) — please shorten it.',
230
+ 'error.tooLong': 'The draft is {count} characters, over the {max} limit (characters, not tokens); it is never truncated automatically — please shorten it.',
196
231
  'error.occurrences': 'The draft contains commands or file references, which are not supported yet — remove them first.',
197
- 'error.chipsUnknown':
198
- 'The composer reference state could not be read on this host, so the enhancement was blocked to avoid overwriting a command or file reference. Clear the input box and type plain text, or update DSH, then retry.',
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.',
199
233
  'error.phase': 'The input box is busy (submitting) — try again in a moment.',
200
- 'error.disabled': 'Prompt enhance is disabled in the plugin settings.',
201
- 'error.rejected': 'The enhance request was rejected.',
202
- 'error.timeout': 'The enhancement timed out ({seconds}s). Retry; your draft is untouched.',
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.',
203
237
  'error.unconfigured':
204
- 'No model resolved for the enhancement: pair provider/model in the plugin settings, or send a message in the current session first (the enhancement will follow the session model).',
205
- 'error.effortUnsupported': 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "follow provider default".',
206
- 'error.upstream': 'The model provider returned an error. Retry; your draft is untouched.',
207
- 'error.internal': 'Enhancement failed. Retry; your draft is untouched.',
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.',
208
242
  'error.client.unreachable': 'Cannot reach the host service — make sure dsh web is running, then retry.',
209
243
  'error.client.malformed': 'The host returned data that could not be parsed. Retry; your draft is untouched.',
210
244
  'error.client.refused': 'The host refused the request (HTTP {status}). Retry later.',
@@ -212,7 +246,7 @@ export const en: Record<PromptEnhanceKey, string> = {
212
246
  'error.client.cancelled': 'The enhancement was cancelled; your draft is untouched.',
213
247
  'error.rateLimit': 'Too many requests — at most {limit} enhancements per minute; retry in {retryAfterSeconds} seconds.',
214
248
  'error.concurrencyLimit': '{max} enhancements are already running — wait for one to finish, then retry.',
215
- 'error.cooldown': '{failures} enhancements failed in a row; calls are paused to stop hammering the model service. Retry in {retryAfterSeconds}s, or check the model settings first.',
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.',
216
250
  'error.upstream.auth': 'Authentication failed — check the API key configured for this provider.',
217
251
  'error.upstream.invalidCredential': 'Authentication failed — the stored API key is invalid; fix it and retry.',
218
252
  'error.upstream.rateLimit': 'The model provider is rate-limiting; retry later.',
@@ -220,7 +254,7 @@ export const en: Record<PromptEnhanceKey, string> = {
220
254
  'error.upstream.empty': 'The model returned an empty response; retry.',
221
255
  'error.upstream.contextWindow': 'The input exceeds the model context window — shorten it or switch models.',
222
256
  'error.upstream.toolCall': 'The model requested tool calls, but prompt enhance needs plain text — switch models and retry.',
223
- 'error.upstream.maxTokens': 'The rewrite hit the output cap (maxOutputTokens) — raise it in settings or shorten the draft.',
257
+ 'error.upstream.maxTokens': 'The rewrite hit the "Output token budget" limit — raise that setting or shorten the draft, then retry.',
224
258
  'settings.summary': 'Model, context, and resource limits',
225
259
  'settings.title': 'Prompt enhance',
226
260
  'settings.description':
@@ -235,6 +269,11 @@ export const en: Record<PromptEnhanceKey, string> = {
235
269
  'settings.unavailable': 'This plugin is not loaded, so it cannot be configured right now.',
236
270
  'settings.reset': 'Reset to default',
237
271
  'settings.invalidNumber': 'Enter a number, or leave blank to use the default.',
272
+ 'settings.record': 'Record',
273
+ 'settings.recordStop': 'Stop recording',
274
+ 'settings.recordPrompt': 'Press the key combination (Esc to cancel)',
275
+ 'settings.recordNeedsModifier': 'Hold at least one of ctrl / alt / meta',
276
+ 'settings.invalidShortcut': 'Invalid shortcut - it would never fire: use at least one of ctrl / alt / meta and put the key last, e.g. ctrl+alt+e.',
238
277
  'settings.disconnected': 'This page has no form: the host did not project its form store. The plugin keeps working with its composition config.',
239
278
  'settings.row.enabled.label': 'Master switch',
240
279
  'settings.row.enabled.hint': 'Off hides the composer button and disables the command and the shortcut.',
@@ -242,6 +281,10 @@ export const en: Record<PromptEnhanceKey, string> = {
242
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.',
243
282
  'settings.row.streaming.label': 'Streaming display',
244
283
  'settings.row.streaming.hint': 'Shows the rewrite while it is being written. Display only: the applied text is unchanged.',
284
+ 'settings.row.foldAnimation.label': 'Card fold animation',
285
+ 'settings.row.foldAnimation.hint': 'Plays the expand/collapse transition; off switches instantly. The system "reduce motion" preference always wins.',
286
+ 'settings.row.autoFold.label': 'Fold the card automatically',
287
+ 'settings.row.autoFold.hint': 'Folds the card after Apply and re-opens it after Undo; off leaves the card as it is.',
245
288
  'settings.row.provider.label': 'Model provider',
246
289
  'settings.row.provider.hint': 'Pick a registered DSH LLM provider; leave empty to follow the current session’s model.',
247
290
  'settings.row.model.label': 'Model id',
@@ -269,7 +312,7 @@ export const en: Record<PromptEnhanceKey, string> = {
269
312
  'settings.row.temperature.label': 'Temperature',
270
313
  'settings.row.temperature.hint': 'Sampling temperature (0–1, step 0.05); lower stays closer to the original. Default 0.3.',
271
314
  'settings.row.reasoningEffort.label': 'Reasoning effort',
272
- 'settings.row.reasoningEffort.hint': 'Tier choices come from what the configured provider/model declares; custom models are read on demand. Provider default omits the field.',
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.',
273
316
  'settings.row.maxOutputTokens.label': 'Output token budget',
274
317
  'settings.row.maxOutputTokens.hint': 'Output budget for one enhancement call. Default 8192.',
275
318
  'settings.row.maxInputChars.label': 'Input character cap',
@@ -295,14 +338,14 @@ export const en: Record<PromptEnhanceKey, string> = {
295
338
  'settings.row.shortcut.placeholder': 'e.g. ctrl+alt+shift+e',
296
339
  'settings.strategy.replace': 'Replace the built-in strategy',
297
340
  'settings.strategy.extend': 'Append after the built-in strategy',
298
- 'settings.reasoning.inherit': 'Provider default',
341
+ 'settings.reasoning.inherit': 'Not specified',
299
342
  'settings.reasoning.loading': 'Reading this model’s tiers…',
300
343
  'settings.reasoning.unavailable': 'Could not read this model’s tier list; your saved tier is still sent.',
301
- 'settings.reasoning.noTiers': 'This model declares no reasoning tiers; calls follow the provider default.',
344
+ 'settings.reasoning.noTiers': 'This model declares no reasoning tiers; calls omit the field and let the provider decide.',
302
345
  'settings.reasoning.unsupported': 'The current value “{effort}” is not one of this model’s tiers.',
303
346
  'settings.reasoning.current': 'Current value: {value}',
304
347
  'settings.reasoning.currentTitle': 'This model does not declare this tier',
305
- 'settings.reasoning.refresh': 'Reload tier info',
348
+ 'settings.reasoning.refresh': 'Refresh',
306
349
  'settings.reasoning.refreshing': 'Loading tier info…',
307
350
  'settings.reasoning.refreshOk': 'Tier info updated',
308
351
  'settings.reasoning.refreshFailed': 'Could not load tier info — please retry.',
@@ -0,0 +1,260 @@
1
+ /**
2
+ * The quick-settings model behind the composer button's menu: which reasoning
3
+ * tiers to offer, which one the config holds, and how to write either setting.
4
+ *
5
+ * Everything here is defensive. The tier list has three sources of decreasing
6
+ * confidence (an explicit provider/model override, the session's own model
7
+ * directory, the static DeepSeek catalog) and any of them may be missing on a
8
+ * given host — a failure must degrade the list, never break the button.
9
+ * @module dsh-prompt-enhance/client/quick-settings
10
+ */
11
+
12
+ import { DEEPSEEK_EFFORTS, isDeepSeekProvider, type ReasoningReason } from '../shared/reasoning'
13
+ import { fetchModels, fetchProviders } from './llm-catalog'
14
+ import { fetchReasoningCapabilities } from './reasoning-options'
15
+ import type { ClientSettings } from './settings'
16
+ import type { SettingsWriter } from './settings-writer'
17
+
18
+ /** One selectable tier. */
19
+ export interface QuickEffort {
20
+ readonly id: string
21
+ readonly name: string
22
+ }
23
+
24
+ /** The host services this menu reads (structural, so tests can pass stubs). */
25
+ export interface QuickContext {
26
+ modelDirectories?: {
27
+ directoryFor?: (sessionId: string | undefined) => unknown
28
+ }
29
+ }
30
+
31
+ /** One snapshot of what the menu should show. */
32
+ export interface QuickSettingsData {
33
+ /** Tiers offered by the resolved route (empty when nothing is known). */
34
+ readonly efforts: readonly QuickEffort[]
35
+ /** The effort the plugin config currently holds (may be `inherit`). */
36
+ readonly effort: string
37
+ /** The context switch the plugin config currently holds. */
38
+ readonly contextAware: boolean
39
+ /** The pinned provider override (empty follows the session). */
40
+ readonly provider: string
41
+ /** The pinned model override (empty follows the session). */
42
+ readonly model: string
43
+ /** Display name of the pinned provider (the raw id when the catalog is unavailable). */
44
+ readonly providerLabel: string
45
+ /** Display name of the pinned model (the raw id when the catalog is unavailable). */
46
+ readonly modelLabel: string
47
+ /** Where `efforts` came from — diagnostics only. */
48
+ readonly source: 'override' | 'session' | 'static'
49
+ /** Why the list is empty, when a source answered negatively. */
50
+ readonly effortReason?: ReasoningReason
51
+ }
52
+
53
+ /** Input of one menu open. */
54
+ export interface QuickSettingsInput {
55
+ readonly ctx?: QuickContext
56
+ readonly sessionId?: string
57
+ readonly settings: ClientSettings
58
+ }
59
+
60
+ /** The sentinel config value meaning "omit the field, let the provider decide". */
61
+ export const INHERIT_EFFORT = 'inherit'
62
+
63
+ /** Narrow one untrusted effort list. */
64
+ function effortsOf(value: unknown): QuickEffort[] {
65
+ if (!Array.isArray(value)) return []
66
+ const out: QuickEffort[] = []
67
+ for (const item of value) {
68
+ if (item === null || typeof item !== 'object') continue
69
+ const record = item as { id?: unknown; name?: unknown }
70
+ if (typeof record.id !== 'string' || record.id === '') continue
71
+ out.push({ id: record.id, name: typeof record.name === 'string' && record.name !== '' ? record.name : record.id })
72
+ }
73
+ return out
74
+ }
75
+
76
+ /** The static catalog as menu options. */
77
+ function staticEfforts(): QuickEffort[] {
78
+ return DEEPSEEK_EFFORTS.map((effort) => ({ id: effort.id, name: effort.name }))
79
+ }
80
+
81
+ /** The options a menu should draw: the tiers plus the stored value when it is unknown to them. */
82
+ export function menuOptionsOf(data: QuickSettingsData): QuickEffort[] {
83
+ const options = [...data.efforts]
84
+ if (data.effort !== '' && data.effort !== INHERIT_EFFORT && !options.some((option) => option.id === data.effort)) {
85
+ // The route gave no name for the stored tier; the shipped catalog still
86
+ // knows the display name of the standard ids (Off/Low/High/Max), so the
87
+ // folded cell never falls back to the raw lowercase id it stores.
88
+ const known = DEEPSEEK_EFFORTS.find((effort) => effort.id === data.effort)
89
+ options.push({ id: data.effort, name: known?.name ?? data.effort })
90
+ }
91
+ return options
92
+ }
93
+
94
+ /** The model directory bound to one session, when the host exposes it. */
95
+ export function modelDirectoryOf(ctx: QuickContext | undefined, sessionId: string | undefined): unknown {
96
+ try {
97
+ return ctx?.modelDirectories?.directoryFor?.(sessionId)
98
+ } catch {
99
+ return undefined
100
+ }
101
+ }
102
+
103
+ /** The store/load face the directory exposes, when it has one. */
104
+ export interface ModelDirectoryFace {
105
+ readonly store?: {
106
+ getSnapshot?: () => unknown
107
+ subscribe?: (listener: () => void) => () => void
108
+ }
109
+ load?: () => unknown
110
+ }
111
+
112
+ /** Narrow a directory object onto the face the menu can watch. */
113
+ export function directoryFaceOf(directory: unknown): ModelDirectoryFace | undefined {
114
+ if (directory === null || typeof directory !== 'object') return undefined
115
+ return directory as ModelDirectoryFace
116
+ }
117
+
118
+ /** Read one directory snapshot without trusting any of its fields. */
119
+ function readDirectory(directory: unknown): { efforts: QuickEffort[]; provider?: string; model?: string } | undefined {
120
+ const store = (directory as { store?: { getSnapshot?: () => unknown } } | undefined)?.store
121
+ let snapshot: unknown
122
+ try {
123
+ snapshot = store?.getSnapshot?.()
124
+ } catch {
125
+ return undefined
126
+ }
127
+ if (snapshot === null || typeof snapshot !== 'object') return undefined
128
+ const state = snapshot as { current?: { provider?: unknown; model?: unknown }; groups?: unknown }
129
+ const provider = typeof state.current?.provider === 'string' ? state.current.provider : undefined
130
+ const model = typeof state.current?.model === 'string' ? state.current.model : undefined
131
+ let efforts: QuickEffort[] = []
132
+ if (Array.isArray(state.groups) && provider !== undefined && model !== undefined) {
133
+ for (const group of state.groups) {
134
+ if (group === null || typeof group !== 'object') continue
135
+ const entry = group as { id?: unknown; models?: unknown }
136
+ if (entry.id !== provider || !Array.isArray(entry.models)) continue
137
+ for (const candidate of entry.models) {
138
+ if (candidate === null || typeof candidate !== 'object') continue
139
+ const record = candidate as { id?: unknown; reasoning?: { efforts?: unknown } }
140
+ if (record.id !== model) continue
141
+ efforts = effortsOf(record.reasoning?.efforts)
142
+ }
143
+ }
144
+ }
145
+ return { efforts, provider, model }
146
+ }
147
+
148
+ /** Ask the directory to load, without letting a slow or throwing host block the menu. */
149
+ async function kickLoad(directory: unknown): Promise<void> {
150
+ const load = (directory as { load?: () => unknown } | undefined)?.load
151
+ if (typeof load !== 'function') return
152
+ try {
153
+ await Promise.resolve(load.call(directory))
154
+ } catch {
155
+ // A directory that cannot load keeps whatever the static fallback offers.
156
+ }
157
+ }
158
+
159
+ /** Labels for a pinned route; both empty when the plugin follows the session. */
160
+ interface RouteLabels {
161
+ readonly providerLabel: string
162
+ readonly modelLabel: string
163
+ }
164
+
165
+ const FOLLOW_LABELS: RouteLabels = { providerLabel: '', modelLabel: '' }
166
+
167
+ /**
168
+ * Resolve the display names of a pinned provider/model from the host catalogs.
169
+ *
170
+ * The card names the route the enhancement will actually call, so an id the
171
+ * registry stopped advertising still shows as its id: a failed read must never
172
+ * leave the row blank.
173
+ * @param provider - pinned provider id.
174
+ * @param model - pinned model id ('' when only the provider is pinned).
175
+ * @returns the two labels, falling back to the ids.
176
+ */
177
+ async function routeLabelsOf(provider: string, model: string): Promise<RouteLabels> {
178
+ if (provider === '') return FOLLOW_LABELS
179
+ const [providers, models] = await Promise.all([fetchProviders(), model === '' ? Promise.resolve(undefined) : fetchModels(provider)])
180
+ return {
181
+ providerLabel: providers?.find((entry) => entry.id === provider)?.name ?? provider,
182
+ modelLabel: model === '' ? '' : (models?.models.find((entry) => entry.id === model)?.name ?? model),
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Resolve what the menu shows for one composer.
188
+ *
189
+ * Priority: an explicit provider/model override (the enhance call will use it)
190
+ * → the session's own directory → the static DeepSeek catalog. Any tier list
191
+ * that comes back empty falls through to the next source.
192
+ * @param input - the services, the session, and the current config.
193
+ * @returns the menu data.
194
+ */
195
+ export async function resolveQuickSettings(input: QuickSettingsInput): Promise<QuickSettingsData> {
196
+ const stored = typeof input.settings.reasoningEffort === 'string' ? input.settings.reasoningEffort.trim() : ''
197
+ const effort = stored === '' ? 'off' : stored
198
+ const contextAware = input.settings.contextAware === true
199
+ const provider = input.settings.provider?.trim() ?? ''
200
+ const model = input.settings.model?.trim() ?? ''
201
+ // Start the catalog read with the capability read so the card opens once, not
202
+ // twice in a row.
203
+ const labelsPromise = routeLabelsOf(provider, model)
204
+
205
+ if (provider !== '' && model !== '') {
206
+ const capabilities = await fetchReasoningCapabilities(provider, model)
207
+ const efforts = effortsOf(capabilities.efforts)
208
+ // A pinned route owns the list: when it declares no tiers (or the lookup
209
+ // fails) the menu must say so instead of borrowing the session's tiers or
210
+ // the shipped DeepSeek catalog, which would offer tiers this model rejects.
211
+ if (efforts.length > 0) return { efforts, effort, contextAware, provider, model, ...(await labelsPromise), source: 'override' }
212
+ return { efforts: [], effort, contextAware, provider, model, ...(await labelsPromise), source: 'override', effortReason: capabilities.reason ?? 'resolve-failed' }
213
+ }
214
+
215
+ const directory = modelDirectoryOf(input.ctx, input.sessionId)
216
+ if (directory !== undefined) {
217
+ const first = readDirectory(directory)
218
+ if (first !== undefined && first.efforts.length > 0) return { efforts: first.efforts, effort, contextAware, provider, model, ...(await labelsPromise), source: 'session' }
219
+ // A snapshot that has not loaded yet is normal on a cold composer; nudge it
220
+ // and read once more before settling for the static catalog.
221
+ await kickLoad(directory)
222
+ const second = readDirectory(directory)
223
+ if (second !== undefined && second.efforts.length > 0) return { efforts: second.efforts, effort, contextAware, provider, model, ...(await labelsPromise), source: 'session' }
224
+ if (second?.provider !== undefined && !isDeepSeekProvider(second.provider)) {
225
+ // A non-DeepSeek route declares its own tiers; guessing them would offer
226
+ // options the model rejects, so the menu shows the stored value only.
227
+ return { efforts: [], effort, contextAware, provider, model, ...(await labelsPromise), source: 'session', effortReason: 'no-efforts' }
228
+ }
229
+ }
230
+
231
+ return { efforts: staticEfforts(), effort, contextAware, provider, model, ...(await labelsPromise), source: 'static' }
232
+ }
233
+
234
+ /**
235
+ * Write the reasoning effort. The caller reports the failure in the menu.
236
+ * @param writer - the installed settings writer.
237
+ * @param id - tier id, or {@link INHERIT_EFFORT}.
238
+ * @returns true when the host accepted the write.
239
+ */
240
+ export async function writeQuickEffort(writer: SettingsWriter, id: string): Promise<boolean> {
241
+ try {
242
+ return await writer.set('reasoningEffort', id)
243
+ } catch {
244
+ return false
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Write the context switch.
250
+ * @param writer - the installed settings writer.
251
+ * @param next - the desired value.
252
+ * @returns true when the host accepted the write.
253
+ */
254
+ export async function writeQuickContext(writer: SettingsWriter, next: boolean): Promise<boolean> {
255
+ try {
256
+ return await writer.set('contextAware', next)
257
+ } catch {
258
+ return false
259
+ }
260
+ }