@lynn123411/dsh-chat-translate 3.5.6 → 3.5.9

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.
@@ -2,26 +2,25 @@
2
2
  * 助手行渲染所需的「工作细节」呈现策略。
3
3
  *
4
4
  * 宿主把这一策略派生自 `ui-chat` 配置条目的 `transcriptView` 字段;本插件接管
5
- * 助手行渲染后,经 `ctx.configForms.get('ui-chat')` 读同一个字段,映射到与宿主
6
- * 同形、同值的策略表。策略对象按模式常驻(同一模式恒等返回同一实例),
7
- * 选择器订阅看到的是稳定引用。
5
+ * 助手行渲染后,经 `ctx.configForms.get('ui-chat')` 读同一个字段。渲染层只用到
6
+ * 其中一个能力:落定的思考行要不要在 Think 标题旁预览首行
7
+ * ({@link ChatPresentationPolicy.settledReasoningPreview}),所以这里只镜像那一个
8
+ * 字段,而不是把宿主的整张策略表搬过来。快照对象按取值常驻(同一取值恒等返回
9
+ * 同一实例),选择器订阅看到的是稳定引用。
8
10
  */
9
- /** 与宿主 ChatPresentationPolicy 同形的结构性镜像。 */
11
+ /** 与宿主 ChatPresentationPolicy 同形的结构性镜像(只保留本插件读取的那个能力)。 */
10
12
  export interface ChatPresentationPolicy {
11
- readonly mode: string;
12
- readonly foldCompletedTurns: boolean;
13
- readonly stepGrouping: 'collapsed' | 'history' | 'none';
14
- readonly liveProcessDetail: boolean;
15
13
  readonly settledReasoningPreview: boolean;
16
14
  }
17
- /**
18
- * 模式 → 策略常量表,逐行对齐宿主 ui-chat 的实现(含两代 legacy 存储值:
19
- * `normal` 按 standard 读、`expanded` 按 detailed 读,从不写回)。
20
- * 渲染器只选择单个字段,不按 mode 分支。
21
- */
22
- export declare const POLICY_BY_MODE: Readonly<Record<string, ChatPresentationPolicy>>;
23
15
  /** 宿主在用户没有显式选择时使用的模式。 */
24
16
  export declare const DEFAULT_MODE = "standard";
17
+ /**
18
+ * 存储值 → 策略快照。
19
+ *
20
+ * @param mode - `transcriptView` 的原样字符串。
21
+ * @returns 该模式的常驻快照。
22
+ */
23
+ export declare function policyForMode(mode: string): ChatPresentationPolicy;
25
24
  /** 本模块只用到配置面的这一小片形状(结构性镜像,值边不跨包)。 */
26
25
  interface ModeFormLike {
27
26
  getSnapshot(): {
@@ -40,9 +40,7 @@ export type RowPlanEntry =
40
40
  * 成功时非 null;showingOriginal 是同一份成功结果上的显示源选择(成功块的
41
41
  * 译文/原文切换);fail 仅在 mark==='failed' 时非 null——服务端的技术一句,
42
42
  * 供悬停报因;failKind 是同一失败的分类(悬停与读屏据此报哪一类原因);
43
- * retryBusy 仅在这一块被手点补跑时为 true——↻ 原地转圈、暂不可重复点;
44
- * frozen = 这一块的内容已经写完(流式中只有正在长的尾块为 false,它不带
45
- * 任何左缘动作,也没有任何结果位)。
43
+ * retryBusy 仅在这一块被手点补跑时为 true——↻ 原地转圈、暂不可重复点。
46
44
  */
47
45
  | {
48
46
  type: 'prose';
@@ -54,7 +52,6 @@ export type RowPlanEntry =
54
52
  fail: string | null;
55
53
  failKind: BlockFailKind | null;
56
54
  retryBusy: boolean;
57
- frozen: boolean;
58
55
  } | {
59
56
  type: 'images';
60
57
  key: number;
@@ -91,13 +91,6 @@ export declare class ChatTranslateStore {
91
91
  private fetch;
92
92
  /** 已送达的译文,按原文内容寻址:跨行、跨代复用同一段文本的结果。 */
93
93
  private translated;
94
- /** 每行写定到哪个下标为止;null(缺席)= 还没有登记过。 */
95
- private settled;
96
- /**
97
- * 每行在途的那一轮请求,登记的是**这一轮认领的那份文本数组**。登记换代时旧
98
- * 一轮的写入按它丢弃:`live.texts` 与它不再同一个数组就说明行已经换代。
99
- */
100
- private active;
101
94
  /**
102
95
  * 每行**在飞的块**:下标 → 那一轮请求认领的原文。流式期间新代接手它们的结果位
103
96
  * 而不重发,等结果回来按当时登记的原文落账(文本没变才算同一块)。
@@ -109,8 +102,6 @@ export declare class ChatTranslateStore {
109
102
  subscribe: (listener: () => void) => (() => void);
110
103
  /** 读一行状态,并把该行刷成最近使用。 */
111
104
  getState(rowKey: string): RowState | undefined;
112
- /** 按原文内容查已送达的译文;null = 还没有结果。 */
113
- lookup(text: string): string | null;
114
105
  /**
115
106
  * 确保该行按当前文本被翻译。
116
107
  * @param rowKey - 行键(会话内锚点)。
@@ -4,8 +4,8 @@ import { NS } from '../locales.ts';
4
4
  /**
5
5
  * `t` 由注册项的 `locale: NS` 注入,类型走共享的 `PropsLocale`。owner props
6
6
  * (`PropsRuntime<'conversation.composer.dock'>`)的类型随
7
- * `@deepseek-ai/dsh-client-ui-conversation` 声明,本包不依赖它(与 dsh-a6api
8
- * 同法),组件也不读那些 prop。
7
+ * `@deepseek-ai/dsh-client-ui-conversation` 声明,本包不依赖它,组件也不读
8
+ * 那些 prop。
9
9
  */
10
10
  export type DockToggleProps = PropsLocale<typeof NS>;
11
11
  /**
@@ -37,7 +37,7 @@ export declare function apply(ctx: ClientContext): void;
37
37
  export { AssistantStepView } from './chat/assistant-step.tsx';
38
38
  export { planAssistantRow } from './chat/row-plan.ts';
39
39
  export { chatTranslate, createTranslateStore } from './chat/translate-store.ts';
40
- export { chatPresentation, createChatPresentation, POLICY_BY_MODE } from './chat/presentation.ts';
40
+ export { chatPresentation, createChatPresentation, policyForMode } from './chat/presentation.ts';
41
41
  export { ensureAssistantStyles } from './chat/styles.ts';
42
42
  export { setupSettingsUi } from './settings/ui.tsx';
43
43
  export { setupComposerToggle, ComposerTranslateToggle } from './composer/dock-toggle.tsx';
@@ -67,8 +67,6 @@ export interface SettingsPageState {
67
67
  saveFailed: boolean;
68
68
  /** Probe from the last save; undefined until a save ran. */
69
69
  probe?: ProbeState;
70
- /** Localized one-liner for the last save ('' when nothing to say). */
71
- message?: string;
72
70
  }
73
71
  /** Profile entry id (== settings namespace) + credentials ref. */
74
72
  export declare const SETTINGS_NAMESPACE = "dsh-chat-translate";
@@ -153,18 +151,11 @@ declare class SettingsStore {
153
151
  private credentials;
154
152
  private unsubscribeForm;
155
153
  private keyConfigured;
156
- private probeFn;
157
154
  /**
158
155
  * Bind the DSH services. Called once from the settings UI setup; re-binding
159
156
  * (e.g. after a reconnect) detaches the previous subscription first.
160
157
  */
161
158
  attach(form: ConfigFormLike | null, credentials: CredentialsRemoteLike | null): void;
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
159
  getState(): SettingsPageState;
169
160
  subscribe(listener: () => void): () => void;
170
161
  /** Map the Host's resolved section into committed state and notify. */
@@ -199,12 +190,6 @@ declare class SettingsStore {
199
190
  save(): Promise<void>;
200
191
  /** Pull the key's status-only view and re-derive readiness. */
201
192
  refreshKeyStatus(): Promise<void>;
202
- /** Probe the translation channel; the settings page's test button. */
203
- testChannel(channel: string): Promise<{
204
- ok: boolean;
205
- latencyMs: number;
206
- error?: string;
207
- }>;
208
193
  /**
209
194
  * Write (or clear) the API key through the credentials Remote API.
210
195
  *
@@ -40,17 +40,11 @@ interface HostContext {
40
40
  }, owner?: unknown): () => void;
41
41
  };
42
42
  credentials: {
43
+ /** The one face this plugin reads; writes go through the browser's Remote API. */
43
44
  resolve(ref: string): Promise<{
44
45
  value: string;
45
46
  source?: string;
46
47
  } | undefined>;
47
- describe(ref: string): Promise<{
48
- configured: boolean;
49
- source?: string;
50
- writable: boolean;
51
- }>;
52
- set(ref: string, value: string): Promise<void>;
53
- unset(ref: string): Promise<void>;
54
48
  };
55
49
  on(event: string, listener: (...args: any[]) => void): () => void;
56
50
  effect(factory: () => void | (() => void), label?: string): unknown;
@@ -1,5 +1,14 @@
1
- import type { ITranslationAdapter, PluginConfig, TranslateAdapterOptions } from './base.ts';
1
+ import type { ITranslationAdapter, PluginConfig, TranslateAdapterOptions } from '../types.ts';
2
2
  import type { KeyReader } from '../credentials.ts';
3
+ /**
4
+ * The translator instruction: the complete text the model receives as its
5
+ * system message. Exported because the clauses are a contract of their own —
6
+ * the regression suite asserts them directly rather than through a request.
7
+ *
8
+ * @param mode - `plain` for one fragment, `blocks` for a packed multi-part request.
9
+ * @returns the complete system prompt.
10
+ */
11
+ export declare function buildSystemPrompt(mode: 'plain' | 'blocks'): string;
3
12
  export declare class OpenAiCompatibleAdapter implements ITranslationAdapter {
4
13
  readonly id = "openai";
5
14
  readonly name = "OpenAI \u517C\u5BB9 (Chat Completions)";
@@ -70,8 +70,6 @@ export declare class ConfigManager {
70
70
  private credentials;
71
71
  constructor(source: ConfigSourceLike, credentials: CredentialsReader);
72
72
  getConfig(): PluginConfig;
73
- /** Whether the AI channel has every required piece: baseUrl, model and key. */
74
- isAiConfigured(): boolean;
75
73
  /**
76
74
  * Name every missing piece of the AI channel, as the reply path reports a
77
75
  * setup failure. This travels to the hover bubble and the screen reader, so
@@ -2,9 +2,9 @@
2
2
  * API-key access through the DSH `ctx.credentials` service.
3
3
  *
4
4
  * The service owns ~/.dsh/.credentials.yaml (refs section, 0600 perms, env
5
- * shadowing, cross-process locking): reads go through `resolve`, writes through
6
- * `set`/`unset`, and the host's `credentials/reference-updated` event keeps
7
- * the sync cache warm.
5
+ * shadowing, cross-process locking). This plugin only reads: writes go
6
+ * through the browser's `credentials` Remote API, and the host's
7
+ * `credentials/reference-updated` event keeps the sync cache warm.
8
8
  */
9
9
  /** Refs key that holds the translation API key. */
10
10
  export declare const TRANSLATE_API_KEY_REF = "TRANSLATE_API_KEY";
@@ -12,23 +12,13 @@ export declare const TRANSLATE_API_KEY_REF = "TRANSLATE_API_KEY";
12
12
  export interface KeyReader {
13
13
  getApiKey(): string;
14
14
  }
15
- /** Minimal structural shape of the DSH `ctx.credentials` service. */
15
+ /** Minimal structural shape of the DSH `ctx.credentials` service: the read face. */
16
16
  export interface CredentialsServiceLike {
17
17
  /** Resolve a ref to its stored/inherited value; undefined when absent. */
18
18
  resolve(ref: string): Promise<{
19
19
  value: string;
20
20
  source?: string;
21
21
  } | undefined>;
22
- /** Status-only view — never returns the plaintext value. */
23
- describe(ref: string): Promise<{
24
- configured: boolean;
25
- source?: string;
26
- writable: boolean;
27
- }>;
28
- /** Store a non-empty value under the ref. */
29
- set(ref: string, value: string): Promise<void>;
30
- /** Remove the ref from the document. */
31
- unset(ref: string): Promise<void>;
32
22
  }
33
23
  export declare class CredentialsReader implements KeyReader {
34
24
  private service;
@@ -45,17 +35,4 @@ export declare class CredentialsReader implements KeyReader {
45
35
  refresh(): Promise<void>;
46
36
  /** Synchronous cached read — the hot translation path stays sync. */
47
37
  getApiKey(): string;
48
- /**
49
- * Status-only view of the ref (plaintext never crosses the wire).
50
- *
51
- * @internal Test-only. The settings UI reads key status through the
52
- * `credentials` Remote API with its own client-side shape, so nothing in
53
- * `src/` calls this host-side method; only `scripts/test-*.mjs` do.
54
- */
55
- describe(): Promise<{
56
- configured: boolean;
57
- writable: boolean;
58
- }>;
59
- /** Write (or clear) the ref through the DSH credentials service. */
60
- setApiKey(apiKey: string): Promise<void>;
61
38
  }
@@ -32,8 +32,6 @@ export declare class TranslationDispatcher {
32
32
  * 半截结果。
33
33
  */
34
34
  translateReplyBlocks(blocks: string[]): Promise<ReplyBlockResult[]>;
35
- /** 通道可用之后的正文执行段:切段、打包、请求、拼装。 */
36
- private serveReplyBlocks;
37
35
  /**
38
36
  * 一整批一次请求;批内修不好的片段与整批的失败都退回逐片段单发。单发仍
39
37
  * 修不好的**照收**(见 {@link translateReplyBlocks})——只有通道伤才让片段
@@ -3,7 +3,7 @@
3
3
  * 回来后**按原结构拼回**——「翻译后 markdown 语法没问题」由构造与形状核对保证:
4
4
  * 模型从来见不到占位符,也就谈不上带不带回。
5
5
  *
6
- * 三件事:
6
+ * 四件事:
7
7
  * 1. `splitMarkdownSegments`:把块切成 code / prose 段的有序清单,拼接恒等于原文。
8
8
  * code 段(``` 或 ~~~ 围栏,含未闭合的到块尾)永不送模型;4 空格缩进代码不
9
9
  * 单独识别(聊天正文里几乎不出现,无记号行的行首缩进由形状签名兜住,
@@ -31,8 +31,6 @@ export interface MarkdownSegment {
31
31
  * 头尾空白天然包含段间距,重装配逐字拼得回。
32
32
  */
33
33
  export declare function splitMarkdownSegments(text: string): MarkdownSegment[];
34
- /** 形状核对的只读错误视图:repairShape 的 error 侧。null = 可成立。 */
35
- export declare function shapeMismatch(original: string, translated: string): string | null;
36
34
  export interface ShapeRepair {
37
35
  /** 修好的文本:原文骨架(空行布局 + 行首前缀)+ 译文正文;null = 修不了。 */
38
36
  text: string | null;
@@ -61,8 +59,3 @@ export declare function restoreLinkTargets(original: string, translated: string)
61
59
  * 不等时回填会把原文 URL 串到错的链接上,宁可不回填。
62
60
  */
63
61
  export declare function linkCountsMatch(a: string, b: string): boolean;
64
- /**
65
- * 只修形不核对的旧口:转手 repairShape——行首前缀修回与空行重排都在那里。
66
- * 修不了时原样返回(调用方自己先看 repairShape 的 error)。
67
- */
68
- export declare function restoreLineShapes(original: string, translated: string): string;
@@ -4,11 +4,10 @@
4
4
  * The reply cache stores results keyed by source text; a cache document
5
5
  * written under a different prompt semantics would replay stale translations
6
6
  * into a new policy (the exact poisoning that makes "already-Chinese blocks
7
- * look untranslated" persist for a TTL after a prompt change). The document
8
- * therefore carries this revision, and a load whose revision differs starts
9
- * from an empty pool.
7
+ * look untranslated" outlive a prompt fix). The document therefore carries
8
+ * this revision, and a load whose revision differs starts from an empty pool.
10
9
  *
11
10
  * Bump it — and only here — whenever the prompt below `buildSystemPrompt`
12
11
  * changes what the model is asked to do. Copy-only edits may ride.
13
12
  */
14
- export declare const PROMPT_REVISION = "r2";
13
+ export declare const PROMPT_REVISION = "r4";
@@ -34,10 +34,8 @@ export type TranslateFailureKind = 'channel' | 'not-configured';
34
34
  * carries the technical one-liner for the hover text.
35
35
  */
36
36
  export interface ReplyBlockResult {
37
- original: string;
38
37
  translated: string;
39
38
  ok: boolean;
40
- cached: boolean;
41
39
  /**
42
40
  * Present only when `ok` is false: the technical one-liner behind the
43
41
  * localized label (e.g. `channel timed out after 20000ms` or the expanded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynn123411/dsh-chat-translate",
3
- "version": "3.5.6",
3
+ "version": "3.5.9",
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,19 +72,18 @@
72
72
  },
73
73
  "engines": {
74
74
  "node": "^22.19 || >=24",
75
- "dsh": ">=0.2.1-alpha.5"
75
+ "dsh": ">=0.2.1-rc.2"
76
76
  },
77
77
  "devDependencies": {
78
- "@deepseek-ai/cordis": "^4.0.5-alpha.2",
79
- "@deepseek-ai/dsh-client-connection": ">=0.2.1-alpha.5",
80
- "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-alpha.5",
81
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-alpha.5",
82
- "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-alpha.5",
83
- "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-alpha.5",
84
- "@deepseek-ai/dsh-client-ui-slots": ">=0.2.1-alpha.5",
85
- "@deepseek-ai/dsh-home-paths": ">=0.2.1-alpha.5",
86
- "@deepseek-ai/schemastery": "^3.18.5-alpha.2",
87
- "@eslint/js": "^9.30.0",
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",
88
87
  "@types/node": "^22.19.0",
89
88
  "@types/react": "^19.2.18",
90
89
  "@types/react-dom": "^19.3.0",
@@ -95,8 +94,8 @@
95
94
  "typescript": "^6.0.0"
96
95
  },
97
96
  "peerDependencies": {
98
- "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-alpha.5",
99
- "@deepseek-ai/dsh-home-paths": ">=0.2.1-alpha.5"
97
+ "@deepseek-ai/dsh-client-ui-primitives": ">=0.2.1-rc.2",
98
+ "@deepseek-ai/dsh-home-paths": ">=0.2.1-rc.2"
100
99
  },
101
100
  "peerDependenciesMeta": {
102
101
  "@deepseek-ai/dsh-client-ui-primitives": {
@@ -1 +0,0 @@
1
- export type { ITranslationAdapter, PluginConfig, TranslateAdapterOptions, } from '../types.ts';