@lynn123411/dsh-chat-translate 3.4.1 → 3.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,82 @@
1
- export interface ClientSettingsState {
1
+ /**
2
+ * This plugin's configuration page state: what the Host serves, what the reader
3
+ * has staged on the page, and what a save would do.
4
+ *
5
+ * There is no optimistic write and no debounce. Every control stages its edit
6
+ * in a draft; the live configuration changes only when the reader presses
7
+ * **保存**, and the whole batch crosses the wire as one revision-fenced write.
8
+ * That is what keeps a half-typed Base URL from reaching the translation path
9
+ * mid-edit, and it is why the reply renderer reads only the committed values:
10
+ * a draft never changes what is already on screen.
11
+ *
12
+ * The API Key is staged the same way but written through the credentials
13
+ * Remote on the same save, so the key and the rest of the settings commit as
14
+ * one gesture.
15
+ */
16
+ /** Resolved config as the Host serves it, plus the derived readiness flag. */
17
+ export interface CommittedConfig {
2
18
  enabled: boolean;
3
19
  aiTimeoutMs: number;
4
20
  baseUrl: string;
5
21
  model: string;
6
- /** 派生值:Key / Base URL / 模型齐全,正文才会被翻译。 */
22
+ /** Derived: Key / Base URL / model all present, so prose would be translated. */
7
23
  aiConfigured: boolean;
8
24
  }
25
+ /** One staged text control. */
26
+ export interface DraftField {
27
+ /** What the control shows. */
28
+ text: string;
29
+ /** Whether the draft differs from the committed value. */
30
+ dirty: boolean;
31
+ /** Whether the draft is not a value this field accepts (blocks saving). */
32
+ invalid: boolean;
33
+ }
34
+ /** The channel probe run by one save: what the settings page reports. */
35
+ export interface ProbeState {
36
+ running: boolean;
37
+ ok?: boolean;
38
+ message?: string;
39
+ }
40
+ /** Everything the page renders. */
41
+ export interface SettingsPageState {
42
+ /** False while the Host does not serve this plugin's config entry. */
43
+ available: boolean;
44
+ /** Whether the Host document accepts writes. */
45
+ writable: boolean;
46
+ /** The committed configuration the translation path actually uses. */
47
+ committed: CommittedConfig;
48
+ baseUrl: DraftField;
49
+ model: DraftField;
50
+ aiTimeoutMs: DraftField;
51
+ /**
52
+ * Write-only control. Blank until typed; `dirty` records that the reader has
53
+ * typed into it, because a secret is never echoed back — an untouched blank
54
+ * draft means "leave the key alone", while a blank draft the reader produced
55
+ * means "clear it".
56
+ */
57
+ apiKey: {
58
+ text: string;
59
+ dirty: boolean;
60
+ };
61
+ /** Whether the drafts differ from what has been committed. */
62
+ dirty: boolean;
63
+ /** Whether any draft is invalid, which blocks the save. */
64
+ invalid: boolean;
65
+ saving: boolean;
66
+ /** The last save did not land: drafts stay for correction. */
67
+ saveFailed: boolean;
68
+ /** Probe from the last save; undefined until a save ran. */
69
+ probe?: ProbeState;
70
+ /** Localized one-liner for the last save ('' when nothing to say). */
71
+ message?: string;
72
+ }
73
+ /** Profile entry id (== settings namespace) + credentials ref. */
74
+ export declare const SETTINGS_NAMESPACE = "dsh-chat-translate";
75
+ export declare const TRANSLATE_API_KEY_REF = "TRANSLATE_API_KEY";
9
76
  /** 正文单次请求超时的取值范围,与宿主半边保持一致。 */
10
77
  export declare const AI_TIMEOUT_MIN = 500;
11
78
  export declare const AI_TIMEOUT_MAX = 900000;
12
- /** Profile entry id (== settings namespace) + credentials ref, mirroring the host constants. */
13
- export declare const SETTINGS_NAMESPACE = "dsh-chat-translate";
14
- export declare const TRANSLATE_API_KEY_REF = "TRANSLATE_API_KEY";
15
- /**
16
- * One path-addressed edit, matching the wire shape the shared configuration
17
- * form's `mutate` accepts.
18
- */
79
+ /** One path-addressed edit, matching the wire shape the form's `mutate` accepts. */
19
80
  export type SettingsPathOpLike = {
20
81
  op: 'set';
21
82
  path: string[];
@@ -26,11 +87,9 @@ export type SettingsPathOpLike = {
26
87
  };
27
88
  /**
28
89
  * Minimal structural shape of the DSH shared configuration form this store
29
- * rides on — `ConfigForm<T>` from @deepseek-ai/dsh-client-ui-settings, reached
30
- * as `ctx.configForms.get(<profile entry id>)`. Keeping it structural keeps
31
- * this bundle free of the settings package and lets tests inject fakes; the
32
- * real form is a structural superset (it also carries `base`, `user` and
33
- * `mode`).
90
+ * rides on — reached as `ctx.configForms.get(<profile entry id>)`. Keeping it
91
+ * structural keeps this bundle testable with fakes; the real form is a
92
+ * structural superset.
34
93
  */
35
94
  export interface ConfigFormLike {
36
95
  getSnapshot(): {
@@ -69,15 +128,23 @@ export interface CredentialsRemoteLike {
69
128
  unset(ref: string): Promise<RemoteResult<void>>;
70
129
  }
71
130
  /**
72
- * Client settings store backed by this plugin's own configuration form.
131
+ * Parse one timeout draft.
132
+ *
133
+ * @param text - the draft as typed.
134
+ * @returns the committed value, `null` when the draft is empty (which clears the
135
+ * field, so the resolved default takes over), or `undefined` when the draft is
136
+ * not a number this field accepts. An out-of-range value is refused rather than
137
+ * silently pulled into range: a save that quietly stores something other than
138
+ * what the page shows is worse than one that asks the reader to fix it.
139
+ */
140
+ export declare function parseTimeout(text: string): number | null | undefined;
141
+ /**
142
+ * The configuration page's own store: committed reads for the whole client,
143
+ * plus the drafts and the save that this page alone owns.
73
144
  *
74
- * There is no localStorage overlay and no custom config HTTP endpoint: the
75
- * store derives from the bound `ConfigForm`, which mirrors the profile entry's
76
- * config section (schema defaults → composition base → user layer) and folds
77
- * every accepted write back, and each debounced flush commits its touched
78
- * fields as one `mutate` batch — one revision fence, serialized and persisted
79
- * by DSH. Without a bound form (unit tests) it degrades to an in-memory store
80
- * with the same semantics.
145
+ * `update` is the surface for controls outside the page — the composer dock
146
+ * toggle writes the master switch straight through, which is the one place a
147
+ * click takes effect without a save.
81
148
  */
82
149
  declare class SettingsStore {
83
150
  private state;
@@ -86,44 +153,71 @@ declare class SettingsStore {
86
153
  private credentials;
87
154
  private unsubscribeForm;
88
155
  private keyConfigured;
89
- private writeTimer;
90
- private pendingFields;
156
+ private probeFn;
91
157
  /**
92
158
  * Bind the DSH services. Called once from the settings UI setup; re-binding
93
159
  * (e.g. after a reconnect) detaches the previous subscription first.
94
160
  */
95
161
  attach(form: ConfigFormLike | null, credentials: CredentialsRemoteLike | null): void;
96
- getState(): ClientSettingsState;
162
+ /** Inject the probe the settings page's save runs (the translate route). */
163
+ useProbe(fn: (() => Promise<{
164
+ ok: boolean;
165
+ latencyMs: number;
166
+ error?: string;
167
+ }>) | null): void;
168
+ getState(): SettingsPageState;
97
169
  subscribe(listener: () => void): () => void;
98
- /** Map the resolved section into client state and notify. */
99
- private derive;
100
- private applyState;
101
- private notify;
102
- /** Pull the key's status-only view and re-derive aiConfigured. */
103
- private refreshKeyStatus;
170
+ /** Map the Host's resolved section into committed state and notify. */
171
+ private deriveCommitted;
172
+ /** Seed every control from what the Host serves, once, and mark nothing dirty. */
173
+ private seedDrafts;
174
+ /** Rebuild every draft's dirty/invalid flags against the committed values. */
175
+ private deriveDrafts;
176
+ /** Fold dirty/invalid from every draft into the page-level flags. */
177
+ private recomputeGate;
104
178
  /**
105
- * Optimistically apply locally, then persist each touched field through the
106
- * configuration form. Writes are trailing-debounced (300ms) so typing in the
107
- * baseUrl/model inputs collapses into a single queued mutation instead of
108
- * one write per keystroke — which would otherwise flash stale mirror values
109
- * back into the inputs between commits. A failed write makes the form reload
110
- * its mirror, which re-derives this store from the Host document
111
- * (conflict-safe recovery).
179
+ * Stage one text control. The draft is local: nothing leaves this page until
180
+ * a save, so a half-typed Base URL never reaches the translation path.
112
181
  */
113
- update(partial: Partial<ClientSettingsState>): Promise<void>;
114
- private scheduleWrite;
115
- private flushWrite;
182
+ draft(field: 'baseUrl' | 'model' | 'aiTimeoutMs' | 'apiKey', text: string): void;
183
+ /**
184
+ * The master switch, written straight through: the composer dock pill and the
185
+ * page's own switch are two entries into one state, and the pill has no save
186
+ * button to press.
187
+ */
188
+ setEnabled(enabled: boolean): Promise<void>;
189
+ /**
190
+ * Write every staged edit as one revision-fenced batch, then probe the
191
+ * channel and report what the probe found.
192
+ *
193
+ * The probe runs after the save lands, never before it: a probe against
194
+ * values the Host has not accepted would report on a configuration nobody
195
+ * has. A refused write keeps every draft so the reader can correct it.
196
+ *
197
+ * @returns nothing; the outcome is published through {@link getState}.
198
+ */
199
+ save(): Promise<void>;
200
+ /** Pull the key's status-only view and re-derive readiness. */
201
+ refreshKeyStatus(): Promise<void>;
202
+ /** Probe the translation channel; the settings page's test button. */
116
203
  testChannel(channel: string): Promise<{
117
204
  ok: boolean;
118
205
  latencyMs: number;
119
206
  error?: string;
120
207
  }>;
121
- /** Write (or clear) the API key through the credentials Remote API. */
208
+ /**
209
+ * Write (or clear) the API key through the credentials Remote API.
210
+ *
211
+ * @param apiKey - the staged key; a blank value clears the ref, because the
212
+ * save only reaches here for a draft the reader actually produced.
213
+ * @returns whether the credentials surface accepted the write.
214
+ */
122
215
  saveApiKey(apiKey: string): Promise<{
123
216
  ok: boolean;
124
217
  error?: string;
125
218
  }>;
126
219
  dispose(): void;
220
+ private notify;
127
221
  }
128
222
  export declare const settingsStore: SettingsStore;
129
223
  export {};
@@ -4,11 +4,11 @@ import { NS } from '../locales.ts';
4
4
  /**
5
5
  * Chat-translate's own configuration page inside the DSH **Plugins** page.
6
6
  *
7
- * The host's Plugins page owns per-plugin configuration: it draws the icon, the
8
- * title and the crumb, and renders a `plugins.bundle.config` entry ON the
9
- * bundle's own page, under its description and above its rows. The card keeps
10
- * its own chrome — the switches, the credential form, the section order — so the
11
- * move from the Settings page changed where it is reached from, not what it does.
7
+ * Every control stages its edit; **保存** writes the whole batch as one
8
+ * revision-fenced document mutation and then probes the channel, reporting
9
+ * what it found. Nothing here is written while the reader types, so a
10
+ * half-finished Base URL can never reach the translation path.
11
+ *
12
12
  * @param props - renderer-bound seat of the `plugins.bundle.config` slot: the
13
13
  * `view` asked for plus the `t` seat its `locale: NS` registration injects.
14
14
  * @returns The card element.
@@ -72,5 +72,15 @@ export declare class ConfigManager {
72
72
  getConfig(): PluginConfig;
73
73
  /** Whether the AI channel has every required piece: baseUrl, model and key. */
74
74
  isAiConfigured(): boolean;
75
+ /**
76
+ * Name every missing piece of the AI channel, as the reply path reports a
77
+ * setup failure. This travels to the hover bubble and the screen reader, so
78
+ * it names fields rather than values and never echoes the key.
79
+ *
80
+ * @param config - the resolved config to inspect; defaults to the current one.
81
+ * @returns the unset pieces by name, or a generic phrase when all are set
82
+ * (the adapter may still refuse the configuration).
83
+ */
84
+ describeMissing(config?: PluginConfig): string;
75
85
  onConfigChange(listener: (config: PluginConfig) => void): () => void;
76
86
  }
@@ -20,12 +20,12 @@ export declare class TranslationDispatcher {
20
20
  *
21
21
  * **形状问题不否决内容**:修不好的片段自动重掷一次;再修不好就照收模型的
22
22
  * 译文(链接数不等时不回填,其余原样)——原文一键可回,可读的译文优先于
23
- * 形状完整。失败只剩通道伤一种:超时、断流、空返回,块保持原文并带一句
24
- * detail 供悬停报因,救活由用户的点击发起。
23
+ * 形状完整。失败只有两类:通道伤(超时、断流、空返回)与设置没配好;两者
24
+ * 都让块保持原文并带上类别与一句 detail,救活由用户的点击发起。
25
25
  *
26
26
  * 调用方传进来的每个块要么整块译出、要么整块保持原文:任一片段缺失都让该块
27
27
  * 作废,避免半中半英的段落;失败块带 `detail` 一句技术细节。每行只跑首跑
28
- * 一次,通道恢复后由点击救活。
28
+ * 一次(新的写定块由调用方逐次递进来,本方法对它们各自独立决定成败)。
29
29
  *
30
30
  * 客户端按与宿主同源的 4096 估算 token 切批,所以一个 markdown 块可能跨多次
31
31
  * 调用;每次调用都独立决定成败,不会出现「前一段已挂译文、后一段失败」的
@@ -17,13 +17,21 @@ export interface ITranslationAdapter {
17
17
  isAvailable(config: PluginConfig): boolean;
18
18
  translate(text: string, signal: AbortSignal, config: PluginConfig, options?: TranslateAdapterOptions): Promise<string>;
19
19
  }
20
+ /**
21
+ * Why one block failed, as the client's label needs it. `channel` is a hurt
22
+ * channel (timeout, HTTP error, broken stream, empty return) — retrying it
23
+ * may work. `not-configured` is a setup problem (missing key, base URL or
24
+ * model) — retrying the same request can never fix it, so the wording points
25
+ * at the configuration page instead.
26
+ */
27
+ export type TranslateFailureKind = 'channel' | 'not-configured';
20
28
  /**
21
29
  * One reply block's outcome, aligned by index with the request's block list.
22
30
  * Failure means the channel was hurt (timeout, HTTP error, broken stream,
23
- * empty return) — the answer's markdown shape is never a failure reason:
24
- * drift is repaired by construction, re-rolled once, or accepted as written
25
- * (the original stays one click away). `detail` carries the technical
26
- * one-liner for the hover text.
31
+ * empty return) or the channel is not configured — the answer's markdown shape
32
+ * is never a failure reason: drift is repaired by construction, re-rolled
33
+ * once, or accepted as written (the original stays one click away). `detail`
34
+ * carries the technical one-liner for the hover text.
27
35
  */
28
36
  export interface ReplyBlockResult {
29
37
  original: string;
@@ -37,4 +45,15 @@ export interface ReplyBlockResult {
37
45
  * no detail exists.
38
46
  */
39
47
  detail?: string;
48
+ /** Present only when `ok` is false: the failure class the label branches on. */
49
+ reason?: TranslateFailureKind;
50
+ }
51
+ /** A translation failure the reply path can classify for the client. */
52
+ export declare class TranslationFailure extends Error {
53
+ readonly reason: TranslateFailureKind;
54
+ /**
55
+ * @param reason - failure class the client's label branches on.
56
+ * @param message - technical one-liner safe to show in a hover bubble.
57
+ */
58
+ constructor(reason: TranslateFailureKind, message: string);
40
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynn123411/dsh-chat-translate",
3
- "version": "3.4.1",
3
+ "version": "3.5.4",
4
4
  "description": "Assistant reply-body translation for the DeepSeek Harness Web UI (OpenAI-compatible channel)",
5
5
  "license": "MIT",
6
6
  "author": "lynn123411",
@@ -57,16 +57,16 @@
57
57
  },
58
58
  "files": [
59
59
  "lib",
60
- "docs",
61
60
  "assets",
62
61
  "locale",
63
62
  "cordis.patch.yml",
64
- "README.md"
63
+ "README.md",
64
+ "DETAILS.md"
65
65
  ],
66
66
  "scripts": {
67
67
  "build": "node build.mjs",
68
68
  "typecheck": "tsc -p tsconfig.json --noEmit",
69
- "test": "node scripts/test-client-wiring.mjs && node scripts/test-render.mjs && node scripts/test-chat-translate.mjs && node scripts/test-regression-suite.mjs && node scripts/test-channel-logic.mjs && node scripts/test-store.mjs && node scripts/test-reply-pipeline.mjs",
69
+ "test": "node scripts/test-client-wiring.mjs && node scripts/test-render.mjs && node scripts/test-chat-translate.mjs && node scripts/test-regression-suite.mjs && node scripts/test-channel-logic.mjs && node scripts/test-store.mjs && node scripts/test-reply-pipeline.mjs && node scripts/test-host-parity.mjs",
70
70
  "assert:lib-untracked": "node scripts/assert-lib-untracked.mjs",
71
71
  "check": "pnpm typecheck && pnpm build && pnpm test && pnpm assert:lib-untracked"
72
72
  },
@@ -77,6 +77,7 @@
77
77
  "devDependencies": {
78
78
  "@deepseek-ai/cordis": "^4.0.5-alpha.2",
79
79
  "@deepseek-ai/dsh-client-connection": ">=0.2.1-alpha.3",
80
+ "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-alpha.3",
80
81
  "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-alpha.3",
81
82
  "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-alpha.3",
82
83
  "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-alpha.3",
@@ -86,12 +87,12 @@
86
87
  "@eslint/js": "^9.30.0",
87
88
  "@types/node": "^22.19.0",
88
89
  "@types/react": "^19.2.18",
90
+ "@types/react-dom": "^19.3.0",
89
91
  "esbuild": "^0.25.0",
90
92
  "jsdom": "^26.1.0",
91
93
  "react": "^18.3.1",
92
94
  "react-dom": "^18.3.1",
93
- "typescript": "^6.0.0",
94
- "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-alpha.3"
95
+ "typescript": "^6.0.0"
95
96
  },
96
97
  "peerDependencies": {
97
98
  "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-alpha.3",
@@ -1,38 +0,0 @@
1
- # 配置
2
-
3
- > 本文档为 [@lynn123411/dsh-chat-translate](../README.md) 的配置说明。
4
-
5
- 1. **API Key**:打开「插件」→ 本插件详情页(配置就在描述之下的 AI 翻译卡片里),直接填写 API Key 并保存(经 DSH 凭据服务写入 `~/.dsh/.credentials.yaml` 的 `TRANSLATE_API_KEY`,权限 0600,保存后立即生效;留空保存 = 清除该键)。也可以手动编辑该文件:
6
-
7
- ```yaml
8
- refs:
9
- TRANSLATE_API_KEY: sk-xxx
10
- ```
11
-
12
- > ⚠️ **注意**:DSH 的凭据加载器要求 refs 键值非空。手动编辑时要么填写真实 Key,要么**直接删除该行**——不要写成 `TRANSLATE_API_KEY: ""` 这类空值,否则 DSH 启动会失败。未配置时插件不翻译,正文保持原文,不会报错。
13
-
14
- 2. **Base URL 与模型等设置**:在本插件的配置页里填写 Base URL(如 `https://api.openai.com/v1` 或 `https://api.deepseek.com/v1`)与模型名(如 `gpt-4o-mini`、`deepseek-chat`),点击「测试 AI 通道」验证。所有设置(开关、超时、Base URL、模型)都是本插件在 profile 里的插件配置:写入当前 profile 的 patch(`~/.dsh/profiles/<profile>/cordis.patch.yml`)中 `dsh-chat-translate` 条目的 `config`。开关 `enabled` 有两个入口:本插件配置页的总开关,与聊天输入框下方那一行(composer dock)的「译」胶囊——两处读写同一个字段,状态同步;这一行只在会话形态渲染,新建会话的 Hero 形态没有它。字段都是可实时更新的,改完立即生效,可直接编辑该文件,不需重载:
15
-
16
- ```yaml
17
- - id: dsh-chat-translate
18
- name: '@lynn123411/dsh-chat-translate'
19
- config:
20
- enabled: true
21
- aiTimeoutMs: 600000
22
- baseUrl: https://api.deepseek.com/v1
23
- model: deepseek-chat
24
- ```
25
-
26
- 目标语言固定为简体中文,没有配置项。
27
-
28
- 3. **翻译范围与时机**:插件接管助手行的渲染(keyed slot `conversation.chat.node` / `assistant-step`,priority -1)。正文块不论源语言一律送模型改写成自然简体中文——「用时 XXX」大折叠块里每一步露出的正文与最终汇总那一步一视同仁;整段中文同样照送(意义、术语、数字不动,顺掉机器腔)。模型返回与原文一模一样的文字时同样算翻译过:照常显示、照常可切换。trim 后为空的块不送译、不占下标、永不标记;块内的代码围栏逐字保留、从不送模型。**正文左缘不画任何东西**:没有竖线、没有脉动、也没有缩进,正文字号、行距、列表与引用的缩进与宿主默认逐字一致。插件自己的两个可点物都落在正文左缘**之外**,详见下条。分组判据是座次传入的 `groupPart`(`response` 分组排除思考块,`reasoning` 分组只渲染思考块,不送译),流式判据是行数据的 `status === "running"`。流式期间整行按原文渲染;落定且该行进入视口(150px 缓冲)后,整行正文按估算 token 预算切批、逐批顺序请求,先回的段先出中文——这是每行的首跑,也是唯一自动发生的请求。首跑期间界面不显示任何提示,中文回来直接替换原文。
29
-
30
- - 不送译的内容:Think 卡的思考链正文、工具调用行、用户消息、代码块(`pre`)及其内部、空白块——这些与宿主渲染逐分支等价,接管渲染器抛错时按框架退位规则由宿主渲染器自动回位。
31
- - 译文用宿主基线组件 `MarkdownText` 重新渲染,表格、列表、加粗、行内代码的结构保持原样。
32
- - 失败只有一种(通道伤)、悬停报细节,重试归手点:块内任一片段通道失败(超时、断流、空返回)就整块按原文渲染、左缘留下一个 ↻ 按钮(`.dsh-ct-retry`);鼠标停在这个按钮上出 Tooltip,报服务端原样带回的技术一句(如展开后的 fetch 报错、`channel timed out after 20000ms`),读屏也读同一句。**译文的结构漂移不是失败理由**——它由形状修复消化(见下条),修不齐的自动重掷一次、仍不齐则照收,永不因格式留下失败标记。控制台各留一条通道失败警告。失败结果不进缓存,一批失败只败在这一批;通道失败**不自动重试**——滚动、重挂载都不会重发已落定的行,救活由点击发起:点失败块的 ↻ = 整行手动补跑,无限次不设额度,已成功的结果整体保留(宿主磁盘缓存让它们秒回、不花模型调用)。补跑在途时 ↻ **原地转圈**(同一个按钮元素,只换属性,不重挂载——键盘焦点不掉),且不能重复点。
33
- - 左缘之外有两个可点物,各自是所在段落的唯一入口:**成功块**是一条**宽 6px 的透明窄带**(`.dsh-ct-hotspot`,`left:-6px;width:6px`,随块高铺满),整条落在正文左缘之外、不占正文一个像素、不参与排版;点它时读译文切原文、读原文切译文(键盘聚焦后 Enter/Space 同样),块与块互不影响。**失败块**是一个真的 ↻ 按钮(`.dsh-ct-retry`,官方 `IconRefreshOutlineRegular`,`left:-18px` 浮在正文左侧的空隙里),失败段**不放窄带**——一段落只对应一个动作,两种点击目标不叠在同一小片地方。正文整块不响应点击——选中文字、拖选复制都不会误触;在窄带上按下、往右拖进正文再松手算选字,不触发切换。悬停不改任何视觉(鼠标移到窄带或 ↻ 上才变手型),键盘聚焦不给任何可见标记(明说的取舍:键盘能操作,但界面不加标记)。关闭总开关即全部回到原文,两个可点物一并消失。
34
- - **排版**:插件不给正文加任何 padding、margin 或 border——可翻译与不可翻译时排版完全相同。两个可点物都在正文左缘之外,宿主正文列左侧恒定有 32px(侧栏嵌入 24px)内边距,因此它们落在空白里、不压任何宿主元素。已知的小重叠:两位以上序号的有序列表(`10.`、`100.`)的序号会往左伸出正文左缘,与那条 6px 窄带重叠——点那几像素会切换译文而不是选中文字(刻意接受,优先保证排版原生)。
35
-
36
- 4. **请求方式**:按行请求——落定的助手行把它全部正文块一次送出。宿主先按 markdown 结构切段:代码围栏与纯空白段逐字保留、永不送模型;散文段超过输入上限(4096 估算 token)时按空行、单行、句末依次切开,相邻片段打包成一个请求(输出上限 8192 token),译回后按原结构拼回——片段头尾的空行由拆下的部分补回,`[文字](URL)` 的 URL 按出现序逐字拼回。每片段过**形状修复**(`repairShape`):按段落块对齐,块内结构行(记号类别、表格竖线数、链接个数、缩进代码缩进)逐一对齐并把行首前缀修回原文同款(标题层级、列表符号、序号、引用深度、列表缩进的漂移就此消失),散文行自由重排(软换行渲染无感、只查整块链接总数不丢),空行布局一律取原文。修不齐的片段自动重掷一次;仍不齐则照收模型的译文(链接数不等时不回填,其余原样)——形状问题永不否决内容,失败标记只留给通道伤。同时最多一个在途请求,超时由 `aiTimeoutMs` 控制(默认 600000 毫秒,范围 500–900000)——每行首跑与每次手点都等到真实结果,嫌等就调小超时。客户端只保留一个按行的内存翻译池(会话锚点为键,LRU 200 行);持久缓存只有宿主的磁盘池 `~/.dsh/dsh-chat-translate/cache.json`(1000 条、7 天 LRU),文档形态是 `{ rev, entries }`,其中 `rev` 登记写入它的提示词修订号——修订号(`src/server/prompt-revision.ts` 的 `PROMPT_REVISION`,单点登记)与实际加载的提示词不符时整池作废重来,换提示词不会让旧译文串代。
37
-
38
- 5. **通道行为**:只有一条通道——Key / Base URL / 模型三者齐备才翻译,缺任何一项都保持原文,不做降级兜底。