@lynn123411/dsh-chat-translate 3.8.1 → 3.9.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/DETAILS.md +6 -6
- package/README.md +2 -2
- package/lib/client.js +150 -123
- package/lib/client.js.map +3 -3
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/types/client/chat/assistant-step.d.ts +16 -8
- package/lib/types/client/chat/presentation.d.ts +20 -6
- package/lib/types/client/locales.d.ts +3 -8
- package/lib/types/client/settings/store.d.ts +31 -34
- package/lib/types/client/settings/ui.d.ts +4 -4
- package/package.json +13 -13
package/DETAILS.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
### 1. API Key
|
|
8
8
|
|
|
9
|
-
打开「插件」→ 本插件详情页(配置就在描述之下的 AI 翻译卡片里),直接填写 API Key
|
|
9
|
+
打开「插件」→ 本插件详情页(配置就在描述之下的 AI 翻译卡片里),直接填写 API Key(离开输入框即自动保存,经 DSH 凭据服务写入 `~/.dsh/.credentials.yaml` 的 `TRANSLATE_API_KEY`,权限 0600,保存后立即生效;留空离开 = 清除该键)。也可以手动编辑该文件:
|
|
10
10
|
|
|
11
11
|
```yaml
|
|
12
12
|
refs:
|
|
@@ -17,7 +17,7 @@ refs:
|
|
|
17
17
|
|
|
18
18
|
### 2. Base URL、模型、超时与提示词
|
|
19
19
|
|
|
20
|
-
在本插件的配置页里填写 Base URL(如 `https://api.openai.com/v1` 或 `https://api.deepseek.com/v1`)与模型名(如 `gpt-4o-mini`、`deepseek-chat
|
|
20
|
+
在本插件的配置页里填写 Base URL(如 `https://api.openai.com/v1` 或 `https://api.deepseek.com/v1`)与模型名(如 `gpt-4o-mini`、`deepseek-chat`),离开输入框即自动保存。**改动先停在页面上**:打字期间一个字都不写盘,离开那个输入框才提交;卡片上没有保存按钮。想验一次通道,点「测试 AI 通道」。
|
|
21
21
|
|
|
22
22
|
所有设置都是本插件在 profile 里的插件配置:写入当前 profile 的 patch(`~/.dsh/profiles/<profile>/cordis.patch.yml`)中 `dsh-chat-translate` 条目的 `config`:
|
|
23
23
|
|
|
@@ -34,17 +34,17 @@ refs:
|
|
|
34
34
|
|
|
35
35
|
| 键 | 默认值 | 含义 |
|
|
36
36
|
| --- | --- | --- |
|
|
37
|
-
| `enabled` | `true` |
|
|
37
|
+
| `enabled` | `true` | 总开关。与输入框下方那一行的「译」胶囊读写同一个字段,两处状态同步;拨一下就写,不用等离开输入框。这一行只在会话形态渲染,新建会话的 Hero 形态没有它。 |
|
|
38
38
|
| `aiTimeoutMs` | `600000` | 单次请求超时(毫秒),范围 500–900000。每行首跑与每次手点都等到真实结果,嫌等就调小。 |
|
|
39
39
|
| `baseUrl` | 空 | OpenAI 兼容服务的接入地址。 |
|
|
40
40
|
| `model` | 空 | 翻译用的模型名。 |
|
|
41
41
|
| `prompt` | 空 | 拼在待译正文前面的那段指令。空着 = 用内置默认(`src/prompt.ts` 的 `DEFAULT_PROMPT`),配置页上看到的就是这份;写了就整段以配置页那段为准。多段打包时追加的标记约定由插件自己接在后面,不占这一项。请求里只有一条 user 消息:这一段在前,待译正文在后。 |
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
目标语言固定为简体中文,没有配置项。空着离开等于清除该项(`unset`,回落到默认值);超时草稿填了非数字时不写盘,页面报出原因、草稿留在页面上供改正。提示词与内置默认一字不差时同样存成空值:配置页的输入框始终显示「生效的那份」,读者不会看到一个空框却不知道模型收到什么。
|
|
44
44
|
|
|
45
45
|
### 2.1 提示词
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
提示词是配置页上单独的一张卡片,平时**只读**:一进页面看得到模型实际收到的那整段指令,改不动;点标题右侧「编辑」才进改写态,焦点直接落进输入框,同排多出「恢复默认」与「完成」。点「完成」(或直接离开输入框)收起改写态并把改动写盘;把框清空再点「完成」时,框里填回生效中的指令——只读态永远显示模型实际收到的那一份,不会停在一个空框上。只读态不摆「恢复默认」,免得看着像能直接改。
|
|
48
48
|
|
|
49
49
|
内置默认那一段的写法有几条承载行为,改文案时别删掉(`src/prompt.ts` 的注释里逐条写了理由):开头先用两个短例立住行为,示例必须排在规则**前面**且写成「输入/输出」的对话样式(放到后面或写成「原文/译文」,模型会把示例连同规则一起复读进译文);首句说「原样抄写」而不是「翻译」或「整理」(这两类写法让模型回到改写模式,已通顺的中文会被换一套说法);中文说的是「原样抄写,只有句子读不通时才改那几句」,那是它唯一被允许改动中文的入口;Markdown 记号只提醒一句,逐行对齐与链接回填由代码兜底。
|
|
50
50
|
|
|
@@ -174,4 +174,4 @@ cd <my-dsh 绝对路径>/plugins/dsh-chat-translate && pnpm install && pnpm buil
|
|
|
174
174
|
cd plugins/dsh-chat-translate && pnpm check
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
`check` 串起类型检查、构建、九份测试与产物门禁(`lib/` 不被索引跟踪)。测试覆盖:行渲染计划与宿主 `AssistantMarkdown` 的分支等价、翻译呈现单点(成功与失败两种标记、失败类别与就地补跑在途)、翻译池(流式增量送译、内容寻址复用、同代幂等、换代作废、换提示词时整池丢弃、按块补跑、逐批落定、LRU
|
|
177
|
+
`check` 串起类型检查、构建、九份测试与产物门禁(`lib/` 不被索引跟踪)。测试覆盖:行渲染计划与宿主 `AssistantMarkdown` 的分支等价、翻译呈现单点(成功与失败两种标记、失败类别与就地补跑在途)、翻译池(流式增量送译、内容寻址复用、同代幂等、换代作废、换提示词时整池丢弃、按块补跑、逐批落定、LRU)、配置面策略跟随与**离开输入框即保存**(打字期间不写盘、离开即整批提交、被拒后留草稿、并发提交共享一批写、提示词按默认/自写两态存取、清空提示词框后回到只读态会填回生效指令、拨「译」胶囊不冲掉提示词草稿),以及真 react + jsdom 的渲染自检——窄带切换、拖选与点正文不误触、悬停气泡贴在光标右边并跟着走、失败段 ↻ 是唯一可点物、补跑在途原地转圈且不重挂载、两类失败各自的读屏文案,配置卡片上提示词那一格默认只读(点「编辑」才改得动、焦点跟着进框、点「完成」收起并写盘)、没有保存按钮、打字期间停在草稿、离开输入框即写盘、恢复默认只填回草稿。服务端半边另有结构重装配、缓存、通道契约与「设置没配好逐块如实回报」的回归;`test-host-parity.mjs` 额外盯住宿主渲染器的漂移(宿主多出一种块、或改了分组与守卫规则时当场失败,找不到 DSH 源码则明确跳过)。
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助
|
|
|
11
11
|
- **失败保持原文、只手点重试**:失败分两类——**通道伤**(超时、断流、空返回)与**设置没配好**(缺 Key / Base URL / 模型)。失败块保持原文,左缘留下一个 ↻ 按钮,悬停报出哪一类失败与原因;点它只重发这一块,已成功的块原地不动。失败不自动重试,一块失败不连坐。
|
|
12
12
|
- **设置没配好不再无声**:缺 Key / Base URL / 模型时如实报出「设置没配好」,气泡与读屏都指向配置页;总开关关着则是纯粹的「不要翻译」,不挂任何标记。
|
|
13
13
|
- **开关两个入口**:输入框下方那一行的「译」胶囊与本插件配置页的总开关,读写同一个 `enabled`,状态同步、拨一下即时生效。
|
|
14
|
-
- **配置页挂在「插件」页**:注册进 `plugins.bundle.config`(key 为包名),路径是「插件」→ 本插件详情页;卡片提供总开关、API Key、Base URL
|
|
14
|
+
- **配置页挂在「插件」页**:注册进 `plugins.bundle.config`(key 为包名),路径是「插件」→ 本插件详情页;卡片提供总开关、API Key、Base URL、模型、单次请求超时、**提示词**与「测试 AI 通道」,改动在离开输入框时自动保存。配置项、安装与校验见 [DETAILS.md](./DETAILS.md)。
|
|
15
15
|
|
|
16
16
|
## 特性
|
|
17
17
|
|
|
@@ -28,7 +28,7 @@ DeepSeek Harness Web 界面的**助手回答正文翻译**插件。它接管助
|
|
|
28
28
|
- **缓存按提示词世代整体作废**:磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(1000 条 LRU)在文档里登记 `rev`,世代跟着此刻生效的提示词与采样参数走——改了提示词或换了参数,旧产出整池作废(浏览器这一侧的译文池同时丢掉);同一代里命中即复用。
|
|
29
29
|
- **跟随宿主显示设置**:Think 行的折叠摘要预览跟随「工作细节」模式(读 `ui-chat` 配置的 `transcriptView`,含旧取值映射),设置缺席时按 standard。
|
|
30
30
|
- **DSH 原生配置接入**:配置就是本插件在 profile 里的插件配置——配置页经 `ctx.configForms` 读写 `dsh-chat-translate` 条目的 `config`,用户层落在当前 profile 的 patch;无任何自研配置文件,译文从不写回会话上下文。
|
|
31
|
-
-
|
|
31
|
+
- **离开输入框即自动保存**:Base URL、模型、超时、提示词与 API Key 都是草稿——打字期间一个字都不写盘,离开那个输入框时提交上去,没有保存按钮。空着离开等于清除该项,超时草稿不合法时不写盘、页面报出原因。想验通道就点「测试 AI 通道」。总开关拨一下即时生效。
|
|
32
32
|
|
|
33
33
|
## 安装
|
|
34
34
|
|
package/lib/client.js
CHANGED
|
@@ -98,45 +98,6 @@ function describeError(err) {
|
|
|
98
98
|
return parts.join(" \u2190 ");
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
// src/client/translate/api.ts
|
|
102
|
-
async function requestTranslateReply(blocks) {
|
|
103
|
-
const fallback = () => blocks.map((block) => ({ translated: block, ok: false }));
|
|
104
|
-
if (!Array.isArray(blocks) || blocks.length === 0) return [];
|
|
105
|
-
try {
|
|
106
|
-
const res = await fetch("/api/dsh-chat-translate/translate-reply", {
|
|
107
|
-
method: "POST",
|
|
108
|
-
headers: { "Content-Type": "application/json" },
|
|
109
|
-
body: JSON.stringify({ blocks })
|
|
110
|
-
});
|
|
111
|
-
if (res.ok) {
|
|
112
|
-
const data = await res.json();
|
|
113
|
-
if (data.ok && Array.isArray(data.results) && data.results.length === blocks.length) {
|
|
114
|
-
return data.results;
|
|
115
|
-
}
|
|
116
|
-
if (data.error) {
|
|
117
|
-
console.warn(`[dsh-chat-translate] \u6B63\u6587\u7FFB\u8BD1\u63A5\u53E3\u9519\u8BEF: ${data.error}`);
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
console.warn(`[dsh-chat-translate] \u6B63\u6587\u7FFB\u8BD1\u8BF7\u6C42\u5931\u8D25 (HTTP ${res.status})`);
|
|
121
|
-
}
|
|
122
|
-
} catch (err) {
|
|
123
|
-
console.warn(`[dsh-chat-translate] \u6B63\u6587\u7FFB\u8BD1\u8BF7\u6C42\u5F02\u5E38: ${describeError(err)}`);
|
|
124
|
-
}
|
|
125
|
-
return fallback();
|
|
126
|
-
}
|
|
127
|
-
async function testServerChannel(channel) {
|
|
128
|
-
try {
|
|
129
|
-
const res = await fetch("/api/dsh-chat-translate/test-channel", {
|
|
130
|
-
method: "POST",
|
|
131
|
-
headers: { "Content-Type": "application/json" },
|
|
132
|
-
body: JSON.stringify({ channel })
|
|
133
|
-
});
|
|
134
|
-
return await res.json();
|
|
135
|
-
} catch (err) {
|
|
136
|
-
return { ok: false, latencyMs: 0, error: describeError(err) };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
101
|
// src/client/settings/store.ts
|
|
141
102
|
var SETTINGS_NAMESPACE = "dsh-chat-translate";
|
|
142
103
|
var TRANSLATE_API_KEY_REF = "TRANSLATE_API_KEY";
|
|
@@ -184,6 +145,8 @@ var SettingsStore = class {
|
|
|
184
145
|
* 输入框下方的「译」胶囊)不该把没保存的草稿冲掉。
|
|
185
146
|
*/
|
|
186
147
|
seeded = null;
|
|
148
|
+
/** One in-flight commit shared by every control that leaves at once. */
|
|
149
|
+
inflight = null;
|
|
187
150
|
/**
|
|
188
151
|
* Bind the DSH services. Called once from the settings UI setup; re-binding
|
|
189
152
|
* (e.g. after a reconnect) detaches the previous subscription first.
|
|
@@ -302,8 +265,9 @@ var SettingsStore = class {
|
|
|
302
265
|
this.notify();
|
|
303
266
|
}
|
|
304
267
|
/**
|
|
305
|
-
* Stage one text control. The draft is local: nothing leaves this page
|
|
306
|
-
*
|
|
268
|
+
* Stage one text control. The draft is local: nothing leaves this page while
|
|
269
|
+
* the reader types, so a half-typed Base URL never reaches the translation
|
|
270
|
+
* path. The control's blur commits it (see {@link save}).
|
|
307
271
|
*/
|
|
308
272
|
draft(field, text) {
|
|
309
273
|
this.state = {
|
|
@@ -316,17 +280,17 @@ var SettingsStore = class {
|
|
|
316
280
|
/**
|
|
317
281
|
* Put the built-in instruction back into the draft.
|
|
318
282
|
*
|
|
319
|
-
* Restoring is intentionally a draft edit like typing:
|
|
320
|
-
*
|
|
321
|
-
* the field itself.
|
|
283
|
+
* Restoring is intentionally a draft edit like typing: it becomes committed
|
|
284
|
+
* when the reader leaves the field, so the button beside the field behaves
|
|
285
|
+
* exactly like the field itself.
|
|
322
286
|
*/
|
|
323
287
|
restoreDefaultPrompt() {
|
|
324
288
|
this.draft("prompt", DEFAULT_PROMPT);
|
|
325
289
|
}
|
|
326
290
|
/**
|
|
327
291
|
* The master switch, written straight through: the composer dock pill and the
|
|
328
|
-
* page's own switch are two entries into one state, and the pill has no
|
|
329
|
-
*
|
|
292
|
+
* page's own switch are two entries into one state, and the pill has no field
|
|
293
|
+
* to leave.
|
|
330
294
|
*/
|
|
331
295
|
async setEnabled(enabled) {
|
|
332
296
|
this.state = { ...this.state, committed: { ...this.state.committed, enabled } };
|
|
@@ -343,7 +307,7 @@ var SettingsStore = class {
|
|
|
343
307
|
* staged no change — the effective prompt is still the default. Leaving the
|
|
344
308
|
* box blank in that state would contradict what the card promises (the box
|
|
345
309
|
* always shows what the model receives), so it is filled in again. Called when
|
|
346
|
-
* a
|
|
310
|
+
* a commit lands and when the reader leaves the editing state.
|
|
347
311
|
*/
|
|
348
312
|
settlePromptDraft() {
|
|
349
313
|
if (!isDefaultPrompt(this.state.prompt.text)) return;
|
|
@@ -354,16 +318,25 @@ var SettingsStore = class {
|
|
|
354
318
|
this.recomputeGate();
|
|
355
319
|
}
|
|
356
320
|
/**
|
|
357
|
-
* Write every staged edit as one revision-fenced batch
|
|
358
|
-
* channel and report what the probe found.
|
|
321
|
+
* Write every staged edit as one revision-fenced batch.
|
|
359
322
|
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
323
|
+
* Called when the reader leaves a control. An invalid draft writes nothing at
|
|
324
|
+
* all, so the page keeps it for correction instead of storing a value it never
|
|
325
|
+
* showed. A refused write keeps every draft for the same reason.
|
|
326
|
+
*
|
|
327
|
+
* Concurrent callers (a field blur racing the prompt's **完成** button) share
|
|
328
|
+
* one in-flight commit instead of starting a second one.
|
|
363
329
|
*
|
|
364
330
|
* @returns nothing; the outcome is published through {@link getState}.
|
|
365
331
|
*/
|
|
366
|
-
|
|
332
|
+
save() {
|
|
333
|
+
if (this.inflight) return this.inflight;
|
|
334
|
+
this.inflight = this.runSave().finally(() => {
|
|
335
|
+
this.inflight = null;
|
|
336
|
+
});
|
|
337
|
+
return this.inflight;
|
|
338
|
+
}
|
|
339
|
+
async runSave() {
|
|
367
340
|
if (this.state.saving) return;
|
|
368
341
|
if (this.state.invalid) return;
|
|
369
342
|
const form = this.form;
|
|
@@ -395,7 +368,7 @@ var SettingsStore = class {
|
|
|
395
368
|
} else if (prompt !== committedPrompt) {
|
|
396
369
|
ops.push({ op: "set", path: ["prompt"], value: prompt });
|
|
397
370
|
}
|
|
398
|
-
this.state = { ...this.state, saving: true, saveFailed: false
|
|
371
|
+
this.state = { ...this.state, saving: true, saveFailed: false };
|
|
399
372
|
this.notify();
|
|
400
373
|
let landed = true;
|
|
401
374
|
if (ops.length > 0 && form) {
|
|
@@ -413,16 +386,10 @@ var SettingsStore = class {
|
|
|
413
386
|
...this.state,
|
|
414
387
|
saving: false,
|
|
415
388
|
saveFailed: false,
|
|
416
|
-
apiKey: { text: "", dirty: false }
|
|
417
|
-
probe: { running: true }
|
|
389
|
+
apiKey: { text: "", dirty: false }
|
|
418
390
|
};
|
|
419
391
|
this.settlePromptDraft();
|
|
420
392
|
this.notify();
|
|
421
|
-
const probe = await testServerChannel("openai");
|
|
422
|
-
this.state = {
|
|
423
|
-
...this.state,
|
|
424
|
-
probe: { running: false, ok: probe.ok, message: probe.error }
|
|
425
|
-
};
|
|
426
393
|
this.deriveDrafts();
|
|
427
394
|
}
|
|
428
395
|
/** Pull the key's status-only view and re-derive readiness. */
|
|
@@ -626,14 +593,8 @@ var SETTINGS_CSS = String.raw`
|
|
|
626
593
|
color: var(--dsw-alias-state-error-primary);
|
|
627
594
|
}
|
|
628
595
|
|
|
629
|
-
/*
|
|
630
|
-
|
|
631
|
-
.dsh-tidy-actions {
|
|
632
|
-
justify-content: flex-start;
|
|
633
|
-
gap: 10px;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
.dsh-tidy-hint {
|
|
596
|
+
/* 自动保存状态:一行安静的小字,只说明此刻在写盘还是已经写好。 */
|
|
597
|
+
.dsh-tidy-autosave {
|
|
637
598
|
color: var(--dsw-alias-label-tertiary);
|
|
638
599
|
font: var(--dsw-font-xxxs-11);
|
|
639
600
|
}
|
|
@@ -650,12 +611,10 @@ var zh = {
|
|
|
650
611
|
badgeConfigured: "\u5DF2\u914D\u7F6E",
|
|
651
612
|
badgeUnconfigured: "\u672A\u914D\u7F6E",
|
|
652
613
|
apiKeyTitle: "API Key",
|
|
653
|
-
apiKeyDesc: "\u4FDD\u5B58\u81F3 {home} \u7684 {ref}\uFF0C\
|
|
614
|
+
apiKeyDesc: "\u4FDD\u5B58\u81F3 {home} \u7684 {ref}\uFF0C\u79BB\u5F00\u8F93\u5165\u6846\u5373\u4FDD\u5B58\u751F\u6548\uFF1B\u7559\u7A7A\u79BB\u5F00 = \u6E05\u9664",
|
|
654
615
|
apiKeyPlaceholderConfigured: "\u5DF2\u914D\u7F6E\uFF08\u5982\u9700\u66F4\u6362\u8BF7\u76F4\u63A5\u8F93\u5165\uFF09",
|
|
655
|
-
save: "\u4FDD\u5B58",
|
|
656
616
|
saving: "\u4FDD\u5B58\u4E2D\u2026",
|
|
657
|
-
|
|
658
|
-
keyCleared: "\u5DF2\u6E05\u9664 API Key\uFF08\u672A\u914D\u7F6E\u65F6\u6B63\u6587\u4FDD\u6301\u539F\u6587\uFF0C\u4E0D\u4F1A\u7FFB\u8BD1\uFF09",
|
|
617
|
+
autoSaveHint: "\u6539\u52A8\u5728\u79BB\u5F00\u8F93\u5165\u6846\u65F6\u81EA\u52A8\u4FDD\u5B58",
|
|
659
618
|
saveFailed: "\u4FDD\u5B58\u5931\u8D25\uFF1A{error}",
|
|
660
619
|
unknownError: "\u672A\u77E5\u9519\u8BEF",
|
|
661
620
|
baseUrlTitle: "Base URL",
|
|
@@ -668,12 +627,9 @@ var zh = {
|
|
|
668
627
|
testing: "\u6D4B\u8BD5\u4E2D\u2026",
|
|
669
628
|
testOk: "\u8FDE\u63A5\u6B63\u5E38\uFF0C\u5EF6\u8FDF {latency}ms",
|
|
670
629
|
testFail: "\u5931\u8D25\uFF1A{error}",
|
|
671
|
-
unsavedHint: "\u6539\u52A8\u4FDD\u5B58\u540E\u624D\u751F\u6548",
|
|
672
630
|
invalidTimeout: "\u8D85\u65F6\u586B\u5199\u4E0D\u5408\u6CD5\uFF1A\u8BF7\u586B 500 \u5230 900000 \u4E4B\u95F4\u7684\u6BEB\u79D2\u6570",
|
|
673
|
-
saveProbeOk: "\u8BBE\u7F6E\u5DF2\u4FDD\u5B58\uFF0C\u901A\u9053\u8FDE\u63A5\u6B63\u5E38",
|
|
674
|
-
saveProbeFail: "\u8BBE\u7F6E\u5DF2\u4FDD\u5B58\uFF0C\u4F46\u901A\u9053\u63A2\u6D4B\u5931\u8D25\uFF1A{error}",
|
|
675
631
|
promptTitle: "\u7FFB\u8BD1\u63D0\u793A\u8BCD",
|
|
676
|
-
promptDesc: "\u62FC\u5728\u5F85\u8BD1\u6B63\u6587\u524D\u9762\u7684\u90A3\u6BB5\u6307\u4EE4\u3002\u70B9\u300C\u7F16\u8F91\u300D\u53EF\u4EE5\u6539\u5199\uFF0C\
|
|
632
|
+
promptDesc: "\u62FC\u5728\u5F85\u8BD1\u6B63\u6587\u524D\u9762\u7684\u90A3\u6BB5\u6307\u4EE4\u3002\u70B9\u300C\u7F16\u8F91\u300D\u53EF\u4EE5\u6539\u5199\uFF0C\u79BB\u5F00\u8F93\u5165\u6846\u6216\u70B9\u300C\u5B8C\u6210\u300D\u540E\u7ACB\u5373\u751F\u6548\uFF1B\u7559\u7A7A\u7B49\u4E8E\u7528\u5185\u7F6E\u9ED8\u8BA4\u3002",
|
|
677
633
|
promptEdit: "\u7F16\u8F91",
|
|
678
634
|
promptDone: "\u5B8C\u6210",
|
|
679
635
|
promptRestore: "\u6062\u590D\u9ED8\u8BA4",
|
|
@@ -699,12 +655,10 @@ var en = {
|
|
|
699
655
|
badgeConfigured: "Configured",
|
|
700
656
|
badgeUnconfigured: "Not configured",
|
|
701
657
|
apiKeyTitle: "API Key",
|
|
702
|
-
apiKeyDesc: "Saved as {ref} in {home}; takes effect immediately.
|
|
658
|
+
apiKeyDesc: "Saved as {ref} in {home}; leaving the field saves it and it takes effect immediately. Leaving it empty clears it.",
|
|
703
659
|
apiKeyPlaceholderConfigured: "Configured (type a new value to replace it)",
|
|
704
|
-
save: "Save",
|
|
705
660
|
saving: "Saving\u2026",
|
|
706
|
-
|
|
707
|
-
keyCleared: "API Key cleared (with nothing configured, replies stay in their original language)",
|
|
661
|
+
autoSaveHint: "Changes are saved when you leave a field",
|
|
708
662
|
saveFailed: "Save failed: {error}",
|
|
709
663
|
unknownError: "Unknown error",
|
|
710
664
|
baseUrlTitle: "Base URL",
|
|
@@ -717,12 +671,9 @@ var en = {
|
|
|
717
671
|
testing: "Testing\u2026",
|
|
718
672
|
testOk: "Connected, {latency}ms latency",
|
|
719
673
|
testFail: "Failed: {error}",
|
|
720
|
-
unsavedHint: "Changes take effect after you save",
|
|
721
674
|
invalidTimeout: "Invalid timeout: enter a number of milliseconds between 500 and 900000",
|
|
722
|
-
saveProbeOk: "Settings saved; the channel answered",
|
|
723
|
-
saveProbeFail: "Settings saved, but the channel probe failed: {error}",
|
|
724
675
|
promptTitle: "Translation prompt",
|
|
725
|
-
promptDesc: "The instruction placed ahead of the text to translate. Press Edit to rewrite it
|
|
676
|
+
promptDesc: "The instruction placed ahead of the text to translate. Press Edit to rewrite it; it applies when you leave the field or press Done. An empty field means the built-in default.",
|
|
726
677
|
promptEdit: "Edit",
|
|
727
678
|
promptDone: "Done",
|
|
728
679
|
promptRestore: "Restore default",
|
|
@@ -771,6 +722,45 @@ function setupPluginPage(slots, register) {
|
|
|
771
722
|
return slots.inject(BUNDLE_CONFIG_SLOT, register);
|
|
772
723
|
}
|
|
773
724
|
|
|
725
|
+
// src/client/translate/api.ts
|
|
726
|
+
async function requestTranslateReply(blocks) {
|
|
727
|
+
const fallback = () => blocks.map((block) => ({ translated: block, ok: false }));
|
|
728
|
+
if (!Array.isArray(blocks) || blocks.length === 0) return [];
|
|
729
|
+
try {
|
|
730
|
+
const res = await fetch("/api/dsh-chat-translate/translate-reply", {
|
|
731
|
+
method: "POST",
|
|
732
|
+
headers: { "Content-Type": "application/json" },
|
|
733
|
+
body: JSON.stringify({ blocks })
|
|
734
|
+
});
|
|
735
|
+
if (res.ok) {
|
|
736
|
+
const data = await res.json();
|
|
737
|
+
if (data.ok && Array.isArray(data.results) && data.results.length === blocks.length) {
|
|
738
|
+
return data.results;
|
|
739
|
+
}
|
|
740
|
+
if (data.error) {
|
|
741
|
+
console.warn(`[dsh-chat-translate] \u6B63\u6587\u7FFB\u8BD1\u63A5\u53E3\u9519\u8BEF: ${data.error}`);
|
|
742
|
+
}
|
|
743
|
+
} else {
|
|
744
|
+
console.warn(`[dsh-chat-translate] \u6B63\u6587\u7FFB\u8BD1\u8BF7\u6C42\u5931\u8D25 (HTTP ${res.status})`);
|
|
745
|
+
}
|
|
746
|
+
} catch (err) {
|
|
747
|
+
console.warn(`[dsh-chat-translate] \u6B63\u6587\u7FFB\u8BD1\u8BF7\u6C42\u5F02\u5E38: ${describeError(err)}`);
|
|
748
|
+
}
|
|
749
|
+
return fallback();
|
|
750
|
+
}
|
|
751
|
+
async function testServerChannel(channel) {
|
|
752
|
+
try {
|
|
753
|
+
const res = await fetch("/api/dsh-chat-translate/test-channel", {
|
|
754
|
+
method: "POST",
|
|
755
|
+
headers: { "Content-Type": "application/json" },
|
|
756
|
+
body: JSON.stringify({ channel })
|
|
757
|
+
});
|
|
758
|
+
return await res.json();
|
|
759
|
+
} catch (err) {
|
|
760
|
+
return { ok: false, latencyMs: 0, error: describeError(err) };
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
774
764
|
// src/client/settings/ui.tsx
|
|
775
765
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
776
766
|
var stylesInjected = false;
|
|
@@ -820,7 +810,6 @@ function TidySettingsPanel(props) {
|
|
|
820
810
|
message: res.ok ? t("testOk").replace("{latency}", String(res.latencyMs)) : res.error || t("unknownError")
|
|
821
811
|
});
|
|
822
812
|
};
|
|
823
|
-
const saveDisabled = state.saving || state.invalid || !state.dirty || !state.writable && state.apiKey.text.trim() === "";
|
|
824
813
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-tidy-settings", children: [
|
|
825
814
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-tidy-card", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-tidy-title", children: [
|
|
826
815
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("masterTitle") }),
|
|
@@ -857,6 +846,9 @@ function TidySettingsPanel(props) {
|
|
|
857
846
|
placeholder: state.committed.aiConfigured ? t("apiKeyPlaceholderConfigured") : "sk-...",
|
|
858
847
|
value: state.apiKey.text,
|
|
859
848
|
onChange: (e) => settingsStore.draft("apiKey", e.target.value),
|
|
849
|
+
onBlur: () => {
|
|
850
|
+
void settingsStore.save();
|
|
851
|
+
},
|
|
860
852
|
"aria-label": t("apiKeyTitle")
|
|
861
853
|
}
|
|
862
854
|
)
|
|
@@ -877,6 +869,9 @@ function TidySettingsPanel(props) {
|
|
|
877
869
|
placeholder: "https://api.openai.com/v1",
|
|
878
870
|
value: state.baseUrl.text,
|
|
879
871
|
onChange: (e) => settingsStore.draft("baseUrl", e.target.value),
|
|
872
|
+
onBlur: () => {
|
|
873
|
+
void settingsStore.save();
|
|
874
|
+
},
|
|
880
875
|
"aria-label": t("baseUrlTitle")
|
|
881
876
|
}
|
|
882
877
|
)
|
|
@@ -894,6 +889,9 @@ function TidySettingsPanel(props) {
|
|
|
894
889
|
placeholder: "gpt-4o-mini",
|
|
895
890
|
value: state.model.text,
|
|
896
891
|
onChange: (e) => settingsStore.draft("model", e.target.value),
|
|
892
|
+
onBlur: () => {
|
|
893
|
+
void settingsStore.save();
|
|
894
|
+
},
|
|
897
895
|
"aria-label": t("modelTitle")
|
|
898
896
|
}
|
|
899
897
|
)
|
|
@@ -913,10 +911,14 @@ function TidySettingsPanel(props) {
|
|
|
913
911
|
step: 1e3,
|
|
914
912
|
value: state.aiTimeoutMs.text,
|
|
915
913
|
onChange: (e) => settingsStore.draft("aiTimeoutMs", e.target.value),
|
|
914
|
+
onBlur: () => {
|
|
915
|
+
void settingsStore.save();
|
|
916
|
+
},
|
|
916
917
|
"aria-label": t("timeoutTitle")
|
|
917
918
|
}
|
|
918
919
|
)
|
|
919
920
|
] }),
|
|
921
|
+
state.invalid && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-tidy-test-result fail", role: "status", children: t("invalidTimeout") }),
|
|
920
922
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-tidy-row", children: [
|
|
921
923
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { variant: "outline", size: "sm", disabled: testing?.running, onClick: runTest, children: testing?.running ? t("testing") : t("test") }),
|
|
922
924
|
testing !== null && !testing.running && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `dsh-tidy-test-result ${testing.ok ? "ok" : "fail"}`, children: testing.message })
|
|
@@ -942,8 +944,10 @@ function TidySettingsPanel(props) {
|
|
|
942
944
|
variant: "ghost",
|
|
943
945
|
size: "sm",
|
|
944
946
|
onClick: () => {
|
|
945
|
-
settingsStore.
|
|
946
|
-
|
|
947
|
+
void settingsStore.save().then(() => {
|
|
948
|
+
settingsStore.settlePromptDraft();
|
|
949
|
+
setEditingPrompt(false);
|
|
950
|
+
});
|
|
947
951
|
},
|
|
948
952
|
children: t("promptDone")
|
|
949
953
|
}
|
|
@@ -963,31 +967,15 @@ function TidySettingsPanel(props) {
|
|
|
963
967
|
onChange: (e) => {
|
|
964
968
|
if (!editingPrompt) return;
|
|
965
969
|
settingsStore.draft("prompt", e.target.value);
|
|
970
|
+
},
|
|
971
|
+
onBlur: () => {
|
|
972
|
+
if (!editingPrompt) return;
|
|
973
|
+
void settingsStore.save();
|
|
966
974
|
}
|
|
967
975
|
}
|
|
968
976
|
)
|
|
969
977
|
] }),
|
|
970
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
971
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-tidy-row dsh-tidy-actions", children: [
|
|
972
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
973
|
-
import_dsh_client_ui_primitives.Button,
|
|
974
|
-
{
|
|
975
|
-
variant: "primary",
|
|
976
|
-
size: "sm",
|
|
977
|
-
className: "dsh-tidy-save",
|
|
978
|
-
disabled: saveDisabled,
|
|
979
|
-
onClick: () => {
|
|
980
|
-
void settingsStore.save();
|
|
981
|
-
},
|
|
982
|
-
children: state.saving ? t("saving") : t("save")
|
|
983
|
-
}
|
|
984
|
-
),
|
|
985
|
-
state.dirty && !state.saving && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-tidy-hint", children: t("unsavedHint") })
|
|
986
|
-
] }),
|
|
987
|
-
state.invalid && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-tidy-test-result fail", role: "status", children: t("invalidTimeout") }),
|
|
988
|
-
state.saveFailed && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-tidy-test-result fail", role: "status", children: t("saveFailed").replace("{error}", t("unknownError")) }),
|
|
989
|
-
state.probe !== void 0 && !state.probe.running && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `dsh-tidy-test-result ${state.probe.ok ? "ok" : "fail"}`, role: "status", children: state.probe.ok ? t("saveProbeOk") : t("saveProbeFail").replace("{error}", state.probe.message || t("unknownError")) })
|
|
990
|
-
] })
|
|
978
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-tidy-autosave", role: "status", children: state.saving ? t("saving") : state.saveFailed ? t("saveFailed").replace("{error}", t("unknownError")) : t("autoSaveHint") })
|
|
991
979
|
] });
|
|
992
980
|
}
|
|
993
981
|
function setupSettingsUi(ctx) {
|
|
@@ -1721,6 +1709,9 @@ function useSearchableHidden(hidden, reveal) {
|
|
|
1721
1709
|
}, [reveal]);
|
|
1722
1710
|
return ref;
|
|
1723
1711
|
}
|
|
1712
|
+
function useFallbackGroupAction(hidden, reveal) {
|
|
1713
|
+
return useSearchableHidden(hidden, reveal);
|
|
1714
|
+
}
|
|
1724
1715
|
var subscribeSettings = (listener) => settingsStore.subscribe(listener);
|
|
1725
1716
|
function useSettledInView(ref, armed) {
|
|
1726
1717
|
const noObserver = typeof IntersectionObserver === "undefined";
|
|
@@ -1819,7 +1810,8 @@ function ProseBlock({
|
|
|
1819
1810
|
streaming,
|
|
1820
1811
|
labels,
|
|
1821
1812
|
mentions,
|
|
1822
|
-
pathImages
|
|
1813
|
+
pathImages,
|
|
1814
|
+
textInteractionSource
|
|
1823
1815
|
}) {
|
|
1824
1816
|
const action = proseAction(mark);
|
|
1825
1817
|
const source = mark === "translated" && !showingOriginal ? translated : text;
|
|
@@ -1913,13 +1905,15 @@ function ProseBlock({
|
|
|
1913
1905
|
streaming,
|
|
1914
1906
|
labels,
|
|
1915
1907
|
fileMentions: mentions,
|
|
1916
|
-
pathImages
|
|
1908
|
+
pathImages,
|
|
1909
|
+
textInteractionSource
|
|
1917
1910
|
})
|
|
1918
1911
|
);
|
|
1919
1912
|
}
|
|
1920
1913
|
var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(props) {
|
|
1921
1914
|
ensureAssistantStyles();
|
|
1922
|
-
const { store, node, groupPart, useDisclosure, useTurnData, turnProcess, openFile,
|
|
1915
|
+
const { store, node, groupPart, useDisclosure, useTurnData, turnProcess, openFile, renderFactorySlot, loadImage, fileMentions, usePresentation, useGroupAction, t } = props;
|
|
1916
|
+
const groupAction = typeof useGroupAction === "function" ? useGroupAction : useFallbackGroupAction;
|
|
1923
1917
|
const data = node.data;
|
|
1924
1918
|
const streaming = data.status === "running";
|
|
1925
1919
|
const interrupted = data.status === "interrupted";
|
|
@@ -1948,7 +1942,10 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
1948
1942
|
if (tail?.closing?.finalNode?.seq !== data.finalNode.seq) return void 0;
|
|
1949
1943
|
return { turn, seq: data.finalNode.seq, openFile };
|
|
1950
1944
|
}, [data.finalNode, openFile, tail, turn]);
|
|
1951
|
-
const mentions = (0, import_react3.useMemo)(
|
|
1945
|
+
const mentions = (0, import_react3.useMemo)(
|
|
1946
|
+
() => owner === void 0 || typeof fileMentions !== "function" ? void 0 : fileMentions(owner),
|
|
1947
|
+
[fileMentions, owner]
|
|
1948
|
+
);
|
|
1952
1949
|
const blocks = (0, import_react3.useMemo)(() => data.blocks ?? [], [data.blocks]);
|
|
1953
1950
|
const turnSteps = turn?.steps?.map((entry) => entry.step);
|
|
1954
1951
|
const conclusion = isConclusionRow({
|
|
@@ -1999,7 +1996,8 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
1999
1996
|
}),
|
|
2000
1997
|
[blocks, streaming, interrupted, groupPart, channel, rowState, frozenCount, originalKeys, conclusion]
|
|
2001
1998
|
);
|
|
2002
|
-
const
|
|
1999
|
+
const keepReplies = usePresentation((policy) => policy.foldedReplies === "all");
|
|
2000
|
+
const reasoningHidden = turnProcess !== void 0 && turnProcess.foldable && (keepReplies ? groupPart !== "reasoning" : turnProcess.spec.answerStep === data.step && turnProcess.spec.inlineReasoning) && !turnProcess.open;
|
|
2003
2001
|
const revealProcess = (0, import_react3.useCallback)(() => {
|
|
2004
2002
|
turnProcess?.setOpen(true);
|
|
2005
2003
|
}, [turnProcess]);
|
|
@@ -2024,6 +2022,7 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
2024
2022
|
}, [frozenCount, plan, rowKey, rowState, translate]);
|
|
2025
2023
|
if (displayed.entries === null) return null;
|
|
2026
2024
|
const last = blocks.length - 1;
|
|
2025
|
+
const textInteractionSource = data.status === "settled" && data.finalNode?.messageId !== void 0;
|
|
2027
2026
|
const rendered = [];
|
|
2028
2027
|
for (const entry of displayed.entries) {
|
|
2029
2028
|
switch (entry.type) {
|
|
@@ -2043,7 +2042,8 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
2043
2042
|
streaming,
|
|
2044
2043
|
labels,
|
|
2045
2044
|
mentions,
|
|
2046
|
-
pathImages
|
|
2045
|
+
pathImages,
|
|
2046
|
+
textInteractionSource
|
|
2047
2047
|
})
|
|
2048
2048
|
);
|
|
2049
2049
|
break;
|
|
@@ -2055,6 +2055,7 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
2055
2055
|
key: entry.key,
|
|
2056
2056
|
hidden: reasoningHidden,
|
|
2057
2057
|
reveal: revealProcess,
|
|
2058
|
+
useGroupAction: groupAction,
|
|
2058
2059
|
children: React.createElement(ReasoningRow, {
|
|
2059
2060
|
text: entry.text,
|
|
2060
2061
|
running: streaming && entry.blockIndex === last,
|
|
@@ -2070,7 +2071,11 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
2070
2071
|
rendered.push(
|
|
2071
2072
|
React.createElement(React.Fragment, {
|
|
2072
2073
|
key: entry.key
|
|
2073
|
-
},
|
|
2074
|
+
}, renderFactorySlot === void 0 ? null : renderFactorySlot("conversation.images.content", {
|
|
2075
|
+
images: entry.attachments.map((attachment) => ({ attachment })),
|
|
2076
|
+
loadImage,
|
|
2077
|
+
align: "start"
|
|
2078
|
+
}))
|
|
2074
2079
|
);
|
|
2075
2080
|
break;
|
|
2076
2081
|
case "unknown":
|
|
@@ -2095,7 +2100,7 @@ var AssistantStepView = (0, import_react3.memo)(function AssistantStepView2(prop
|
|
|
2095
2100
|
);
|
|
2096
2101
|
});
|
|
2097
2102
|
function ProcessReasoning(props) {
|
|
2098
|
-
const ref =
|
|
2103
|
+
const ref = props.useGroupAction(props.hidden, props.reveal);
|
|
2099
2104
|
return React.createElement(
|
|
2100
2105
|
"div",
|
|
2101
2106
|
{ ref, "data-turn-process-inline": props.hidden || void 0 },
|
|
@@ -2106,10 +2111,20 @@ function ProcessReasoning(props) {
|
|
|
2106
2111
|
// src/client/chat/presentation.ts
|
|
2107
2112
|
var NO_PREVIEW_MODE = "compact";
|
|
2108
2113
|
var DEFAULT_MODE = "standard";
|
|
2109
|
-
var
|
|
2110
|
-
var
|
|
2114
|
+
var DEFAULT_FOLDED_REPLIES = "all";
|
|
2115
|
+
var SNAPSHOTS = {
|
|
2116
|
+
"preview:all": Object.freeze({ settledReasoningPreview: true, foldedReplies: "all" }),
|
|
2117
|
+
"preview:final": Object.freeze({ settledReasoningPreview: true, foldedReplies: "final" }),
|
|
2118
|
+
"plain:all": Object.freeze({ settledReasoningPreview: false, foldedReplies: "all" }),
|
|
2119
|
+
"plain:final": Object.freeze({ settledReasoningPreview: false, foldedReplies: "final" })
|
|
2120
|
+
};
|
|
2121
|
+
function policyFor(mode, foldedReplies) {
|
|
2122
|
+
const preview = mode !== NO_PREVIEW_MODE ? "preview" : "plain";
|
|
2123
|
+
const folded = foldedReplies === "final" ? "final" : "all";
|
|
2124
|
+
return SNAPSHOTS[`${preview}:${folded}`];
|
|
2125
|
+
}
|
|
2111
2126
|
function policyForMode(mode) {
|
|
2112
|
-
return mode
|
|
2127
|
+
return policyFor(mode, DEFAULT_FOLDED_REPLIES);
|
|
2113
2128
|
}
|
|
2114
2129
|
var ChatPresentation = class {
|
|
2115
2130
|
policy = policyForMode(DEFAULT_MODE);
|
|
@@ -2149,7 +2164,8 @@ var ChatPresentation = class {
|
|
|
2149
2164
|
value = void 0;
|
|
2150
2165
|
}
|
|
2151
2166
|
const raw = typeof value?.transcriptView === "string" ? value.transcriptView : "";
|
|
2152
|
-
const
|
|
2167
|
+
const rawFolded = typeof value?.foldedReplies === "string" ? value.foldedReplies : "";
|
|
2168
|
+
const next = policyFor(raw, rawFolded);
|
|
2153
2169
|
if (next !== this.policy) {
|
|
2154
2170
|
this.policy = next;
|
|
2155
2171
|
for (const listener of [...this.listeners]) {
|
|
@@ -2185,8 +2201,19 @@ function apply(ctx) {
|
|
|
2185
2201
|
// 两侧渲染逐字一致;t 由座次按该命名空间合成。
|
|
2186
2202
|
locale: "chat",
|
|
2187
2203
|
priority: -1,
|
|
2188
|
-
// 思考行的 settledReasoningPreview
|
|
2189
|
-
|
|
2204
|
+
// 思考行的 settledReasoningPreview 与 foldedReplies 来自活的工作细节模式;
|
|
2205
|
+
// fileMentions 由这条注册项自己提供(0.2.2 起不再走 owner props)。
|
|
2206
|
+
inject: (sessionId) => ({
|
|
2207
|
+
hooks: { presentation: chatPresentation },
|
|
2208
|
+
fileMentions: (owner) => {
|
|
2209
|
+
try {
|
|
2210
|
+
const service = ctx.get?.("chatFileMentions");
|
|
2211
|
+
return service?.forClosing?.(owner, sessionId);
|
|
2212
|
+
} catch {
|
|
2213
|
+
return void 0;
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
})
|
|
2190
2217
|
},
|
|
2191
2218
|
AssistantStepView
|
|
2192
2219
|
)
|