@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.
@@ -3,19 +3,33 @@
3
3
  *
4
4
  * 宿主把这一策略派生自 `ui-chat` 配置条目的 `transcriptView` 字段;本插件接管
5
5
  * 助手行渲染后,经 `ctx.configForms.get('ui-chat')` 读同一个字段。渲染层只用到
6
- * 其中一个能力:落定的思考行要不要在 Think 标题旁预览首行
7
- * ({@link ChatPresentationPolicy.settledReasoningPreview}),所以这里只镜像那一个
8
- * 字段,而不是把宿主的整张策略表搬过来。快照对象按取值常驻(同一取值恒等返回
9
- * 同一实例),选择器订阅看到的是稳定引用。
6
+ * 其中两个能力:落定的思考行要不要在 Think 标题旁预览首行
7
+ * ({@link ChatPresentationPolicy.settledReasoningPreview}),以及折叠时保留哪些
8
+ * 助手回复({@link ChatPresentationPolicy.foldedReplies})。只镜像本插件真正读到的
9
+ * 这两个字段,而不是把宿主的整张策略表搬过来。快照对象按取值常驻(同一取值恒等
10
+ * 返回同一实例),选择器订阅看到的是稳定引用。
10
11
  */
11
- /** 与宿主 ChatPresentationPolicy 同形的结构性镜像(只保留本插件读取的那个能力)。 */
12
+ /** 折叠回复时保留哪些助手回复:全部,还是只有最后一条结论。 */
13
+ export type FoldedReplies = 'all' | 'final';
14
+ /** 与宿主 ChatPresentationPolicy 同形的结构性镜像(只保留本插件读取的两个能力)。 */
12
15
  export interface ChatPresentationPolicy {
13
16
  readonly settledReasoningPreview: boolean;
17
+ readonly foldedReplies: FoldedReplies;
14
18
  }
15
19
  /** 宿主在用户没有显式选择时使用的模式。 */
16
20
  export declare const DEFAULT_MODE = "standard";
21
+ /** 宿主在没有保存折叠回复偏好时保留全部回复。 */
22
+ export declare const DEFAULT_FOLDED_REPLIES: FoldedReplies;
17
23
  /**
18
- * 存储值 → 策略快照。
24
+ * 两个存储值 → 策略快照。
25
+ *
26
+ * @param mode - `transcriptView` 的原样字符串。
27
+ * @param foldedReplies - `foldedReplies` 的原样字符串;未识别按保留全部。
28
+ * @returns 该组合的常驻快照。
29
+ */
30
+ export declare function policyFor(mode: string, foldedReplies: string): ChatPresentationPolicy;
31
+ /**
32
+ * 存储值 → 策略快照(只按工作细节模式,折叠回复取宿主默认)。
19
33
  *
20
34
  * @param mode - `transcriptView` 的原样字符串。
21
35
  * @returns 该模式的常驻快照。
@@ -15,12 +15,10 @@ export declare const zh: {
15
15
  readonly badgeConfigured: "已配置";
16
16
  readonly badgeUnconfigured: "未配置";
17
17
  readonly apiKeyTitle: "API Key";
18
- readonly apiKeyDesc: "保存至 {home} 的 {ref},保存后立即生效;留空保存 = 清除";
18
+ readonly apiKeyDesc: "保存至 {home} 的 {ref},离开输入框即保存生效;留空离开 = 清除";
19
19
  readonly apiKeyPlaceholderConfigured: "已配置(如需更换请直接输入)";
20
- readonly save: "保存";
21
20
  readonly saving: "保存中…";
22
- readonly keySaved: "已保存到 {home},立即生效";
23
- readonly keyCleared: "已清除 API Key(未配置时正文保持原文,不会翻译)";
21
+ readonly autoSaveHint: "改动在离开输入框时自动保存";
24
22
  readonly saveFailed: "保存失败:{error}";
25
23
  readonly unknownError: "未知错误";
26
24
  readonly baseUrlTitle: "Base URL";
@@ -33,12 +31,9 @@ export declare const zh: {
33
31
  readonly testing: "测试中…";
34
32
  readonly testOk: "连接正常,延迟 {latency}ms";
35
33
  readonly testFail: "失败:{error}";
36
- readonly unsavedHint: "改动保存后才生效";
37
34
  readonly invalidTimeout: "超时填写不合法:请填 500 到 900000 之间的毫秒数";
38
- readonly saveProbeOk: "设置已保存,通道连接正常";
39
- readonly saveProbeFail: "设置已保存,但通道探测失败:{error}";
40
35
  readonly promptTitle: "翻译提示词";
41
- readonly promptDesc: "拼在待译正文前面的那段指令。点「编辑」可以改写,改完点下面的「保存」生效;留空等于用内置默认。";
36
+ readonly promptDesc: "拼在待译正文前面的那段指令。点「编辑」可以改写,离开输入框或点「完成」后立即生效;留空等于用内置默认。";
42
37
  readonly promptEdit: "编辑";
43
38
  readonly promptDone: "完成";
44
39
  readonly promptRestore: "恢复默认";
@@ -1,22 +1,21 @@
1
1
  /**
2
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.
3
+ * has staged on the page, and what a commit would write.
4
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.
5
+ * Every control stages its edit in a draft, and a draft is written as soon as
6
+ * the reader leaves that control: there is no save button. Leaving a control
7
+ * that holds an invalid value (an out-of-range timeout) writes nothing, so a
8
+ * bad number never reaches the Host; the page shows why and keeps the draft for
9
+ * correction.
11
10
  *
12
11
  * 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
12
+ * Remote on the same commit, so the key and the rest of the settings land as
14
13
  * one gesture.
15
14
  *
16
15
  * The prompt is staged like any text control, with one twist: the control shows
17
16
  * the *effective* instruction, so an untouched plugin displays the built-in
18
- * default in full. Saving that exact text clears the field again, which keeps
19
- * "empty means the built-in default" true in the stored document.
17
+ * default in full. Committing that exact text clears the field again, which
18
+ * keeps "empty means the built-in default" true in the stored document.
20
19
  */
21
20
  /** Resolved config as the Host serves it, plus the derived readiness flag. */
22
21
  export interface CommittedConfig {
@@ -38,12 +37,6 @@ export interface DraftField {
38
37
  /** Whether the draft is not a value this field accepts (blocks saving). */
39
38
  invalid: boolean;
40
39
  }
41
- /** The channel probe run by one save: what the settings page reports. */
42
- export interface ProbeState {
43
- running: boolean;
44
- ok?: boolean;
45
- message?: string;
46
- }
47
40
  /** Everything the page renders. */
48
41
  export interface SettingsPageState {
49
42
  /** False while the Host does not serve this plugin's config entry. */
@@ -76,10 +69,8 @@ export interface SettingsPageState {
76
69
  /** Whether any draft is invalid, which blocks the save. */
77
70
  invalid: boolean;
78
71
  saving: boolean;
79
- /** The last save did not land: drafts stay for correction. */
72
+ /** The last commit did not land: drafts stay for correction. */
80
73
  saveFailed: boolean;
81
- /** Probe from the last save; undefined until a save ran. */
82
- probe?: ProbeState;
83
74
  }
84
75
  /** Profile entry id (== settings namespace) + credentials ref. */
85
76
  export declare const SETTINGS_NAMESPACE = "dsh-chat-translate";
@@ -151,11 +142,11 @@ export interface CredentialsRemoteLike {
151
142
  export declare function parseTimeout(text: string): number | null | undefined;
152
143
  /**
153
144
  * The configuration page's own store: committed reads for the whole client,
154
- * plus the drafts and the save that this page alone owns.
145
+ * plus the drafts and the commit this page alone owns.
155
146
  *
156
147
  * `update` is the surface for controls outside the page — the composer dock
157
148
  * toggle writes the master switch straight through, which is the one place a
158
- * click takes effect without a save.
149
+ * click takes effect without leaving a control.
159
150
  */
160
151
  declare class SettingsStore {
161
152
  private state;
@@ -170,6 +161,8 @@ declare class SettingsStore {
170
161
  * 输入框下方的「译」胶囊)不该把没保存的草稿冲掉。
171
162
  */
172
163
  private seeded;
164
+ /** One in-flight commit shared by every control that leaves at once. */
165
+ private inflight;
173
166
  /**
174
167
  * Bind the DSH services. Called once from the settings UI setup; re-binding
175
168
  * (e.g. after a reconnect) detaches the previous subscription first.
@@ -192,22 +185,23 @@ declare class SettingsStore {
192
185
  /** Fold dirty/invalid from every draft into the page-level flags. */
193
186
  private recomputeGate;
194
187
  /**
195
- * Stage one text control. The draft is local: nothing leaves this page until
196
- * a save, so a half-typed Base URL never reaches the translation path.
188
+ * Stage one text control. The draft is local: nothing leaves this page while
189
+ * the reader types, so a half-typed Base URL never reaches the translation
190
+ * path. The control's blur commits it (see {@link save}).
197
191
  */
198
192
  draft(field: 'baseUrl' | 'model' | 'aiTimeoutMs' | 'prompt' | 'apiKey', text: string): void;
199
193
  /**
200
194
  * Put the built-in instruction back into the draft.
201
195
  *
202
- * Restoring is intentionally a draft edit like typing: nothing is written
203
- * until the reader saves, so the button beside the field behaves exactly like
204
- * the field itself.
196
+ * Restoring is intentionally a draft edit like typing: it becomes committed
197
+ * when the reader leaves the field, so the button beside the field behaves
198
+ * exactly like the field itself.
205
199
  */
206
200
  restoreDefaultPrompt(): void;
207
201
  /**
208
202
  * The master switch, written straight through: the composer dock pill and the
209
- * page's own switch are two entries into one state, and the pill has no save
210
- * button to press.
203
+ * page's own switch are two entries into one state, and the pill has no field
204
+ * to leave.
211
205
  */
212
206
  setEnabled(enabled: boolean): Promise<void>;
213
207
  /**
@@ -217,20 +211,23 @@ declare class SettingsStore {
217
211
  * staged no change — the effective prompt is still the default. Leaving the
218
212
  * box blank in that state would contradict what the card promises (the box
219
213
  * always shows what the model receives), so it is filled in again. Called when
220
- * a save lands and when the reader leaves the editing state.
214
+ * a commit lands and when the reader leaves the editing state.
221
215
  */
222
216
  settlePromptDraft(): void;
223
217
  /**
224
- * Write every staged edit as one revision-fenced batch, then probe the
225
- * channel and report what the probe found.
218
+ * Write every staged edit as one revision-fenced batch.
219
+ *
220
+ * Called when the reader leaves a control. An invalid draft writes nothing at
221
+ * all, so the page keeps it for correction instead of storing a value it never
222
+ * showed. A refused write keeps every draft for the same reason.
226
223
  *
227
- * The probe runs after the save lands, never before it: a probe against
228
- * values the Host has not accepted would report on a configuration nobody
229
- * has. A refused write keeps every draft so the reader can correct it.
224
+ * Concurrent callers (a field blur racing the prompt's **完成** button) share
225
+ * one in-flight commit instead of starting a second one.
230
226
  *
231
227
  * @returns nothing; the outcome is published through {@link getState}.
232
228
  */
233
229
  save(): Promise<void>;
230
+ private runSave;
234
231
  /** Pull the key's status-only view and re-derive readiness. */
235
232
  refreshKeyStatus(): Promise<void>;
236
233
  /**
@@ -4,10 +4,10 @@ import { NS } from '../locales.ts';
4
4
  /**
5
5
  * Chat-translate's own configuration page inside the DSH **Plugins** page.
6
6
  *
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.
7
+ * Every control stages its edit and leaves no save button; leaving that control
8
+ * writes the whole batch as one revision-fenced document mutation. Nothing here
9
+ * is written while the reader types, so a half-finished Base URL can never reach
10
+ * the translation path.
11
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynn123411/dsh-chat-translate",
3
- "version": "3.8.1",
3
+ "version": "3.9.3",
4
4
  "description": "Assistant reply-body translation for the DeepSeek Harness Web UI (OpenAI-compatible channel)",
5
5
  "license": "MIT",
6
6
  "author": "lynn123411",
@@ -72,18 +72,18 @@
72
72
  },
73
73
  "engines": {
74
74
  "node": "^22.19 || >=24",
75
- "dsh": ">=0.2.1-rc.2"
75
+ "dsh": ">=0.2.2-rc.1"
76
76
  },
77
77
  "devDependencies": {
78
- "@deepseek-ai/cordis": "^4.0.5",
79
- "@deepseek-ai/dsh-client-connection": ">=0.2.1-rc.2",
80
- "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-rc.2",
81
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-rc.2",
82
- "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-rc.2",
83
- "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-rc.2",
84
- "@deepseek-ai/dsh-client-ui-slots": ">=0.2.1-rc.2",
85
- "@deepseek-ai/dsh-home-paths": ">=0.2.1-rc.2",
86
- "@deepseek-ai/schemastery": "^3.18.5",
78
+ "@deepseek-ai/cordis": "^4.1.0",
79
+ "@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.1",
80
+ "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.2-rc.1",
81
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.1",
82
+ "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.2-rc.1",
83
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.2.2-rc.1",
84
+ "@deepseek-ai/dsh-client-ui-slots": ">=0.2.2-rc.1",
85
+ "@deepseek-ai/dsh-home-paths": ">=0.2.2-rc.1",
86
+ "@deepseek-ai/schemastery": "^3.19.0",
87
87
  "@types/node": "^22.19.0",
88
88
  "@types/react": "^19.2.18",
89
89
  "@types/react-dom": "^19.3.0",
@@ -94,8 +94,8 @@
94
94
  "typescript": "^6.0.0"
95
95
  },
96
96
  "peerDependencies": {
97
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-rc.2",
98
- "@deepseek-ai/dsh-home-paths": ">=0.2.1-rc.2"
97
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.1",
98
+ "@deepseek-ai/dsh-home-paths": ">=0.2.2-rc.1"
99
99
  },
100
100
  "peerDependenciesMeta": {
101
101
  "@deepseek-ai/dsh-client-ui-primitives": {