@surfishs/dsh-prompt-enhance 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +153 -44
- package/README.md +151 -42
- package/docs/images/panel-en-915.png +0 -0
- package/docs/images/panel.png +0 -0
- package/lib/client.js +1963 -647
- package/lib/index.js +57 -13
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
- package/src/client/ActionIcons.tsx +49 -0
- package/src/client/EnhanceButton.tsx +314 -5
- package/src/client/QuickSettingsMenu.tsx +163 -0
- package/src/client/ResultDock.tsx +14 -0
- package/src/client/ResultPanel.tsx +157 -52
- package/src/client/UndoBar.tsx +2 -2
- package/src/client/enhance-client.ts +42 -0
- package/src/client/index.tsx +8 -1
- package/src/client/llm-catalog.ts +55 -8
- package/src/client/locales.ts +101 -41
- package/src/client/quick-settings.ts +260 -0
- package/src/client/settings-page-controls.tsx +180 -48
- package/src/client/settings-page-copy.ts +10 -0
- package/src/client/settings-page-spec.ts +29 -3
- package/src/client/settings-page-styles.ts +59 -7
- package/src/client/settings-page.tsx +68 -10
- package/src/client/settings-source.ts +23 -0
- package/src/client/settings-writer.ts +51 -0
- package/src/client/settings.ts +24 -0
- package/src/client/shortcut.ts +45 -0
- package/src/client/styles.ts +476 -43
- package/src/client/ui-state.ts +16 -0
- package/src/config.ts +8 -0
- package/src/context.ts +87 -7
- package/src/enhancer.ts +3 -0
- package/src/orchestrate.ts +24 -5
- package/src/shared/defaults.ts +4 -0
- package/src/shared/protocol.ts +26 -0
package/src/client/locales.ts
CHANGED
|
@@ -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': '正在生成…',
|
|
@@ -24,12 +37,20 @@ export const zh = {
|
|
|
24
37
|
'panel.copied': '已复制',
|
|
25
38
|
'panel.copyFailed': '复制失败',
|
|
26
39
|
'panel.close': '关闭',
|
|
40
|
+
'panel.collapse': '折叠',
|
|
41
|
+
'panel.expand': '展开',
|
|
27
42
|
'panel.retry': '重试',
|
|
28
|
-
'panel.stale.warn': '
|
|
29
|
-
'panel.truncated': '
|
|
43
|
+
'panel.stale.warn': '草稿已改动,当前结果基于旧文本。「重新生成」会按当前文本重跑;回填仍会覆盖当前输入(可撤销)。',
|
|
44
|
+
'panel.truncated': '输出被截断(达到输出上限),结果可能不完整。可在设置里调高「输出 token 上限」后重新生成。',
|
|
45
|
+
'panel.contextUsage': '上下文用量',
|
|
46
|
+
'panel.contextStats': '上下文 {turns}/{maxTurns} 条 · {chars}/{maxChars} 字({percent}%)',
|
|
47
|
+
'panel.contextCharsLimited': '已达字数上限,较早内容未发送',
|
|
48
|
+
'panel.contextCut': '已达字数上限,最新一条仅发送了开头',
|
|
49
|
+
'panel.contextUnused': '本次未使用上下文',
|
|
30
50
|
'panel.model': '模型:{provider} / {model}',
|
|
31
51
|
'panel.elapsed': '耗时 {ms}',
|
|
32
52
|
'panel.tokens': '{total} tokens',
|
|
53
|
+
'panel.effortDefault': '模型默认',
|
|
33
54
|
'panel.tokens.input': '输入 {count}',
|
|
34
55
|
'panel.tokens.output': '输出 {count}',
|
|
35
56
|
'panel.tokens.cacheRead': '缓存读取 {count}',
|
|
@@ -38,17 +59,17 @@ export const zh = {
|
|
|
38
59
|
'undo.undo': '撤销',
|
|
39
60
|
'undo.dismiss': '关闭提示',
|
|
40
61
|
'error.empty': '输入框为空,请先输入要增强的提示词。',
|
|
41
|
-
'error.tooLong': '
|
|
62
|
+
'error.tooLong': '内容 {count} 字,超过 {max} 字上限(按字符计,非 token);不会自动截断,请精简后重试。',
|
|
42
63
|
'error.occurrences': '输入内容包含命令或文件引用,暂不支持增强;请先移除后再试。',
|
|
43
|
-
'error.chipsUnknown': '
|
|
64
|
+
'error.chipsUnknown': '无法读取输入框里的引用状态;为避免覆盖你的命令或文件引用,本次已阻止。请改为纯文本后重试。',
|
|
44
65
|
'error.phase': '当前输入正被占用(提交中),请稍后再试。',
|
|
45
|
-
'error.disabled': '
|
|
46
|
-
'error.rejected': '
|
|
47
|
-
'error.timeout': '增强超时({seconds}
|
|
48
|
-
'error.unconfigured': '
|
|
49
|
-
'error.effortUnsupported': '该模型不支持所选推理档位「{effort}
|
|
50
|
-
'error.upstream': '
|
|
51
|
-
'error.internal': '
|
|
66
|
+
'error.disabled': '提示词增强已在插件设置中关闭,可在设置里重新开启。',
|
|
67
|
+
'error.rejected': '增强请求被拒绝。请稍后重试;若持续出现,请检查插件设置。',
|
|
68
|
+
'error.timeout': '增强超时({seconds} 秒)。可直接重试,或到设置里调高「超时(毫秒)」;原输入未改动。',
|
|
69
|
+
'error.unconfigured': '还没确定用哪个模型:请在插件设置里填写 provider 和 model(两项都要填),或在当前会话先发一条消息以跟随会话模型。',
|
|
70
|
+
'error.effortUnsupported': '该模型不支持所选推理档位「{effort}」,请改选其它档位,或改用「模型默认」。',
|
|
71
|
+
'error.upstream': '模型服务返回错误;若下方有详情,请按详情处理,否则可直接重试。原输入未改动。',
|
|
72
|
+
'error.internal': '增强失败,请重试;若反复失败,请查看 dsh 运行日志。原输入未改动。',
|
|
52
73
|
'error.client.unreachable': '无法连接宿主服务,请确认 dsh web 正在运行后重试。',
|
|
53
74
|
'error.client.malformed': '宿主服务返回了无法解析的数据,请重试;原输入未改动。',
|
|
54
75
|
'error.client.refused': '宿主服务拒绝了请求(HTTP {status}),请稍后重试。',
|
|
@@ -56,7 +77,7 @@ export const zh = {
|
|
|
56
77
|
'error.client.cancelled': '已取消增强;原输入未改动。',
|
|
57
78
|
'error.rateLimit': '请求过于频繁:每分钟最多 {limit} 次增强,请在 {retryAfterSeconds} 秒后再试。',
|
|
58
79
|
'error.concurrencyLimit': '已有 {max} 个增强正在进行,请等其中一个完成后再试。',
|
|
59
|
-
'error.cooldown': '连续 {failures}
|
|
80
|
+
'error.cooldown': '连续 {failures} 次增强失败,已暂停 {retryAfterSeconds} 秒以免持续冲击模型服务;可稍后重试,或先检查模型配置。',
|
|
60
81
|
'error.upstream.auth': '鉴权失败:请检查该 provider 的 API Key 配置。',
|
|
61
82
|
'error.upstream.invalidCredential': '鉴权失败:存储的 API Key 不可用,请修正后重试。',
|
|
62
83
|
'error.upstream.rateLimit': '模型服务限流,请稍后重试。',
|
|
@@ -64,7 +85,7 @@ export const zh = {
|
|
|
64
85
|
'error.upstream.empty': '模型返回了空响应,请重试。',
|
|
65
86
|
'error.upstream.contextWindow': '输入超出模型上下文窗口,请精简原文或更换模型。',
|
|
66
87
|
'error.upstream.toolCall': '模型请求了工具调用,提示词增强只需要纯文本;请更换模型后重试。',
|
|
67
|
-
'error.upstream.maxTokens': '
|
|
88
|
+
'error.upstream.maxTokens': '重写结果达到「输出 token 上限」,请调高该设置或精简原文后重试。',
|
|
68
89
|
'settings.summary': '模型、上下文与资源限制',
|
|
69
90
|
'settings.title': '提示词增强',
|
|
70
91
|
'settings.description': '把输入框草稿改写为结构化提示词:角色与目标、可执行步骤、输出格式、验收标准、边界条件。原文保留,失败不改草稿;保存后下一次调用即生效。',
|
|
@@ -78,6 +99,11 @@ export const zh = {
|
|
|
78
99
|
'settings.unavailable': '该插件当前未加载,暂时无法配置。',
|
|
79
100
|
'settings.reset': '恢复默认',
|
|
80
101
|
'settings.invalidNumber': '请填数字;留空表示使用默认值。',
|
|
102
|
+
'settings.record': '录制',
|
|
103
|
+
'settings.recordStop': '取消录制',
|
|
104
|
+
'settings.recordPrompt': '请按下组合键(Esc 取消)',
|
|
105
|
+
'settings.recordNeedsModifier': '需要至少按住 ctrl / alt / meta 中的一个',
|
|
106
|
+
'settings.invalidShortcut': '写法无效,快捷键不会生效:需包含 ctrl / alt / meta 中至少一个,键放在最后,例如 ctrl+alt+e。',
|
|
81
107
|
'settings.disconnected': '表单没有接通:宿主没有向这个页面注入表单状态。插件仍按组合配置工作。',
|
|
82
108
|
'settings.row.enabled.label': '总开关',
|
|
83
109
|
'settings.row.enabled.hint': '关闭后隐藏输入框的增强按钮,命令与快捷键一并停用。',
|
|
@@ -85,6 +111,10 @@ export const zh = {
|
|
|
85
111
|
'settings.row.contextAware.hint': '读取当前会话最近几轮对话来消解指代、补全省略;无历史时回退为单条增强。',
|
|
86
112
|
'settings.row.streaming.label': '增量展示',
|
|
87
113
|
'settings.row.streaming.hint': '模型边写边在面板显示;仅影响显示节奏,最终写入的文本不变。',
|
|
114
|
+
'settings.row.foldAnimation.label': '卡片折叠动画',
|
|
115
|
+
'settings.row.foldAnimation.hint': '展开/收起时播放过渡;关闭后立即切换。系统「减少动态效果」偏好始终优先。',
|
|
116
|
+
'settings.row.autoFold.label': '自动收纳卡片',
|
|
117
|
+
'settings.row.autoFold.hint': '回填到输入框后自动收起卡片,撤销后自动展开;关闭后卡片保持当前状态。',
|
|
88
118
|
'settings.row.provider.label': '模型服务方',
|
|
89
119
|
'settings.row.provider.hint': '从 DSH 已注册的 LLM provider 中选择;留空跟随当前会话的模型。',
|
|
90
120
|
'settings.row.model.label': '模型 ID',
|
|
@@ -111,7 +141,7 @@ export const zh = {
|
|
|
111
141
|
'settings.row.temperature.label': '温度',
|
|
112
142
|
'settings.row.temperature.hint': '采样温度(0~1,步进 0.05),越低越忠实原文;默认 0.3。',
|
|
113
143
|
'settings.row.reasoningEffort.label': '推理预算',
|
|
114
|
-
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model
|
|
144
|
+
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。「模型默认」表示不发送该字段,由提供方使用默认档。',
|
|
115
145
|
'settings.row.maxOutputTokens.label': '输出 token 上限',
|
|
116
146
|
'settings.row.maxOutputTokens.hint': '单次增强的输出预算;默认 8192。',
|
|
117
147
|
'settings.row.maxInputChars.label': '输入字符上限',
|
|
@@ -136,14 +166,14 @@ export const zh = {
|
|
|
136
166
|
'settings.row.shortcut.placeholder': '例:ctrl+alt+shift+e',
|
|
137
167
|
'settings.strategy.replace': '替换内置策略',
|
|
138
168
|
'settings.strategy.extend': '追加在内置策略后',
|
|
139
|
-
'settings.reasoning.inherit': '
|
|
169
|
+
'settings.reasoning.inherit': '模型默认',
|
|
140
170
|
'settings.reasoning.loading': '正在读取该模型的档位…',
|
|
141
171
|
'settings.reasoning.unavailable': '无法读取该模型的档位列表;已保存的档位仍会照常发送。',
|
|
142
|
-
'settings.reasoning.noTiers': '
|
|
172
|
+
'settings.reasoning.noTiers': '该模型未声明推理档位;调用时不发送档位,由提供方决定。',
|
|
143
173
|
'settings.reasoning.unsupported': '当前值「{effort}」不在该模型支持的档位中。',
|
|
144
174
|
'settings.reasoning.current': '当前值:{value}',
|
|
145
175
|
'settings.reasoning.currentTitle': '该模型未声明此档位',
|
|
146
|
-
'settings.reasoning.refresh': '
|
|
176
|
+
'settings.reasoning.refresh': '刷新',
|
|
147
177
|
'settings.reasoning.refreshing': '正在获取档位信息…',
|
|
148
178
|
'settings.reasoning.refreshOk': '档位信息已更新',
|
|
149
179
|
'settings.reasoning.refreshFailed': '获取档位信息失败,请重试。',
|
|
@@ -154,10 +184,23 @@ export type PromptEnhanceKey = keyof typeof zh
|
|
|
154
184
|
|
|
155
185
|
/** English dictionary. */
|
|
156
186
|
export const en: Record<PromptEnhanceKey, string> = {
|
|
157
|
-
'button.title': 'Enhance prompt',
|
|
187
|
+
'button.title': 'Enhance prompt · rewrite the text in the input box',
|
|
158
188
|
'button.busy': 'Enhancing…',
|
|
159
|
-
'button.otherBusy': 'Another session is enhancing right now
|
|
160
|
-
'button.emptyTitle': 'Enhance prompt
|
|
189
|
+
'button.otherBusy': 'Another session is enhancing right now',
|
|
190
|
+
'button.emptyTitle': 'Enhance prompt · type the text to rewrite first',
|
|
191
|
+
'button.quickHint': ' (right-click to configure)',
|
|
192
|
+
'menu.title': 'Quick settings',
|
|
193
|
+
'menu.model': 'Model',
|
|
194
|
+
'menu.modelFollow': 'Follow session',
|
|
195
|
+
'menu.modelHint': 'Change it on the plugin settings page',
|
|
196
|
+
'menu.effortsNone': 'This model declares no reasoning tiers',
|
|
197
|
+
'menu.effortsFailed': 'Could not read this model tiers',
|
|
198
|
+
'menu.effort': 'Reasoning effort',
|
|
199
|
+
'menu.effortDefault': 'Model default',
|
|
200
|
+
'menu.context': 'Context awareness',
|
|
201
|
+
'menu.contextOn': 'on',
|
|
202
|
+
'menu.contextOff': 'off',
|
|
203
|
+
'menu.writeFailed': 'Could not save — try again.',
|
|
161
204
|
'panel.title': 'Prompt Enhance',
|
|
162
205
|
'panel.loading': 'Enhancing, please wait…',
|
|
163
206
|
'panel.streaming': 'Generating…',
|
|
@@ -172,12 +215,20 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
172
215
|
'panel.copied': 'Copied',
|
|
173
216
|
'panel.copyFailed': 'Copy failed',
|
|
174
217
|
'panel.close': 'Close',
|
|
218
|
+
'panel.collapse': 'Collapse',
|
|
219
|
+
'panel.expand': 'Expand',
|
|
175
220
|
'panel.retry': 'Retry',
|
|
176
|
-
'panel.stale.warn': 'Draft changed — this result uses the earlier text; Apply overwrites the
|
|
177
|
-
'panel.truncated': 'Output
|
|
221
|
+
'panel.stale.warn': 'Draft changed — this result uses the earlier text. Regenerate re-runs on the current draft; Apply still overwrites the input (undoable).',
|
|
222
|
+
'panel.truncated': 'Output was cut at the output limit, so the result may be incomplete. Raise "Output token budget" in the settings, then regenerate.',
|
|
223
|
+
'panel.contextUsage': 'Context usage',
|
|
224
|
+
'panel.contextStats': 'Context {turns}/{maxTurns} turns · {chars}/{maxChars} chars ({percent}%)',
|
|
225
|
+
'panel.contextCharsLimited': 'Character cap reached; earlier turns were not sent',
|
|
226
|
+
'panel.contextCut': 'Character limit reached; only the opening of the latest turn was sent',
|
|
227
|
+
'panel.contextUnused': 'No conversation context was used for this call',
|
|
178
228
|
'panel.model': 'Model: {provider} / {model}',
|
|
179
229
|
'panel.elapsed': '{ms} elapsed',
|
|
180
230
|
'panel.tokens': '{total} tokens',
|
|
231
|
+
'panel.effortDefault': 'Model default',
|
|
181
232
|
'panel.tokens.input': 'Input {count}',
|
|
182
233
|
'panel.tokens.output': 'Output {count}',
|
|
183
234
|
'panel.tokens.cacheRead': 'Cache read {count}',
|
|
@@ -186,19 +237,18 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
186
237
|
'undo.undo': 'Undo',
|
|
187
238
|
'undo.dismiss': 'Dismiss',
|
|
188
239
|
'error.empty': 'The input box is empty — type a prompt to enhance first.',
|
|
189
|
-
'error.tooLong': 'The draft is {count} characters,
|
|
240
|
+
'error.tooLong': 'The draft is {count} characters, over the {max} limit (characters, not tokens); it is never truncated automatically — please shorten it.',
|
|
190
241
|
'error.occurrences': 'The draft contains commands or file references, which are not supported yet — remove them first.',
|
|
191
|
-
'error.chipsUnknown':
|
|
192
|
-
'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.',
|
|
242
|
+
'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.',
|
|
193
243
|
'error.phase': 'The input box is busy (submitting) — try again in a moment.',
|
|
194
|
-
'error.disabled': 'Prompt enhance is disabled in the plugin settings.',
|
|
195
|
-
'error.rejected': 'The enhance request was rejected.',
|
|
196
|
-
'error.timeout': 'The enhancement timed out ({seconds}s). Retry; your draft is untouched.',
|
|
244
|
+
'error.disabled': 'Prompt enhance is disabled in the plugin settings; re-enable it there.',
|
|
245
|
+
'error.rejected': 'The enhance request was rejected. Retry later; if it persists, check the plugin settings.',
|
|
246
|
+
'error.timeout': 'The enhancement timed out ({seconds}s). Retry, or raise "Timeout (ms)" in the settings; your draft is untouched.',
|
|
197
247
|
'error.unconfigured':
|
|
198
|
-
'No model
|
|
199
|
-
'error.effortUnsupported': 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "
|
|
200
|
-
'error.upstream': 'The model provider returned an error.
|
|
201
|
-
'error.internal': 'Enhancement failed. Retry;
|
|
248
|
+
'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.',
|
|
249
|
+
'error.effortUnsupported': 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "Model default".',
|
|
250
|
+
'error.upstream': 'The model provider returned an error. If there is detail below, act on it; otherwise retry. Your draft is untouched.',
|
|
251
|
+
'error.internal': 'Enhancement failed. Retry; if it keeps failing, check the dsh logs. Your draft is untouched.',
|
|
202
252
|
'error.client.unreachable': 'Cannot reach the host service — make sure dsh web is running, then retry.',
|
|
203
253
|
'error.client.malformed': 'The host returned data that could not be parsed. Retry; your draft is untouched.',
|
|
204
254
|
'error.client.refused': 'The host refused the request (HTTP {status}). Retry later.',
|
|
@@ -206,7 +256,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
206
256
|
'error.client.cancelled': 'The enhancement was cancelled; your draft is untouched.',
|
|
207
257
|
'error.rateLimit': 'Too many requests — at most {limit} enhancements per minute; retry in {retryAfterSeconds} seconds.',
|
|
208
258
|
'error.concurrencyLimit': '{max} enhancements are already running — wait for one to finish, then retry.',
|
|
209
|
-
'error.cooldown': '{failures} enhancements failed in a row; calls are paused to stop hammering the model service. Retry
|
|
259
|
+
'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.',
|
|
210
260
|
'error.upstream.auth': 'Authentication failed — check the API key configured for this provider.',
|
|
211
261
|
'error.upstream.invalidCredential': 'Authentication failed — the stored API key is invalid; fix it and retry.',
|
|
212
262
|
'error.upstream.rateLimit': 'The model provider is rate-limiting; retry later.',
|
|
@@ -214,7 +264,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
214
264
|
'error.upstream.empty': 'The model returned an empty response; retry.',
|
|
215
265
|
'error.upstream.contextWindow': 'The input exceeds the model context window — shorten it or switch models.',
|
|
216
266
|
'error.upstream.toolCall': 'The model requested tool calls, but prompt enhance needs plain text — switch models and retry.',
|
|
217
|
-
'error.upstream.maxTokens': 'The rewrite hit the
|
|
267
|
+
'error.upstream.maxTokens': 'The rewrite hit the "Output token budget" limit — raise that setting or shorten the draft, then retry.',
|
|
218
268
|
'settings.summary': 'Model, context, and resource limits',
|
|
219
269
|
'settings.title': 'Prompt enhance',
|
|
220
270
|
'settings.description':
|
|
@@ -229,6 +279,11 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
229
279
|
'settings.unavailable': 'This plugin is not loaded, so it cannot be configured right now.',
|
|
230
280
|
'settings.reset': 'Reset to default',
|
|
231
281
|
'settings.invalidNumber': 'Enter a number, or leave blank to use the default.',
|
|
282
|
+
'settings.record': 'Record',
|
|
283
|
+
'settings.recordStop': 'Stop recording',
|
|
284
|
+
'settings.recordPrompt': 'Press the key combination (Esc to cancel)',
|
|
285
|
+
'settings.recordNeedsModifier': 'Hold at least one of ctrl / alt / meta',
|
|
286
|
+
'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.',
|
|
232
287
|
'settings.disconnected': 'This page has no form: the host did not project its form store. The plugin keeps working with its composition config.',
|
|
233
288
|
'settings.row.enabled.label': 'Master switch',
|
|
234
289
|
'settings.row.enabled.hint': 'Off hides the composer button and disables the command and the shortcut.',
|
|
@@ -236,6 +291,10 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
236
291
|
'settings.row.contextAware.hint': 'Reads the recent turns of the current conversation; falls back to a single-prompt rewrite when there is no history.',
|
|
237
292
|
'settings.row.streaming.label': 'Streaming display',
|
|
238
293
|
'settings.row.streaming.hint': 'Shows the rewrite while it is being written. Display only: the applied text is unchanged.',
|
|
294
|
+
'settings.row.foldAnimation.label': 'Card fold animation',
|
|
295
|
+
'settings.row.foldAnimation.hint': 'Plays the expand/collapse transition; off switches instantly. The system "reduce motion" preference always wins.',
|
|
296
|
+
'settings.row.autoFold.label': 'Fold the card automatically',
|
|
297
|
+
'settings.row.autoFold.hint': 'Folds the card after Apply and re-opens it after Undo; off leaves the card as it is.',
|
|
239
298
|
'settings.row.provider.label': 'Model provider',
|
|
240
299
|
'settings.row.provider.hint': 'Pick a registered DSH LLM provider; leave empty to follow the current session’s model.',
|
|
241
300
|
'settings.row.model.label': 'Model id',
|
|
@@ -263,7 +322,8 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
263
322
|
'settings.row.temperature.label': 'Temperature',
|
|
264
323
|
'settings.row.temperature.hint': 'Sampling temperature (0–1, step 0.05); lower stays closer to the original. Default 0.3.',
|
|
265
324
|
'settings.row.reasoningEffort.label': 'Reasoning effort',
|
|
266
|
-
'settings.row.reasoningEffort.hint':
|
|
325
|
+
'settings.row.reasoningEffort.hint':
|
|
326
|
+
'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.',
|
|
267
327
|
'settings.row.maxOutputTokens.label': 'Output token budget',
|
|
268
328
|
'settings.row.maxOutputTokens.hint': 'Output budget for one enhancement call. Default 8192.',
|
|
269
329
|
'settings.row.maxInputChars.label': 'Input character cap',
|
|
@@ -289,14 +349,14 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
289
349
|
'settings.row.shortcut.placeholder': 'e.g. ctrl+alt+shift+e',
|
|
290
350
|
'settings.strategy.replace': 'Replace the built-in strategy',
|
|
291
351
|
'settings.strategy.extend': 'Append after the built-in strategy',
|
|
292
|
-
'settings.reasoning.inherit': '
|
|
352
|
+
'settings.reasoning.inherit': 'Model default',
|
|
293
353
|
'settings.reasoning.loading': 'Reading this model’s tiers…',
|
|
294
354
|
'settings.reasoning.unavailable': 'Could not read this model’s tier list; your saved tier is still sent.',
|
|
295
|
-
'settings.reasoning.noTiers': 'This model declares no reasoning tiers; calls
|
|
355
|
+
'settings.reasoning.noTiers': 'This model declares no reasoning tiers; calls omit the field and let the provider decide.',
|
|
296
356
|
'settings.reasoning.unsupported': 'The current value “{effort}” is not one of this model’s tiers.',
|
|
297
357
|
'settings.reasoning.current': 'Current value: {value}',
|
|
298
358
|
'settings.reasoning.currentTitle': 'This model does not declare this tier',
|
|
299
|
-
'settings.reasoning.refresh': '
|
|
359
|
+
'settings.reasoning.refresh': 'Refresh',
|
|
300
360
|
'settings.reasoning.refreshing': 'Loading tier info…',
|
|
301
361
|
'settings.reasoning.refreshOk': 'Tier info updated',
|
|
302
362
|
'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
|
+
}
|