@lynn123411/dsh-chat-translate 3.4.0 → 3.5.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.md +11 -9
- package/docs//351/205/215/347/275/256.md +9 -9
- package/lib/client.js +644 -277
- package/lib/client.js.map +3 -3
- package/lib/index.js +71 -19
- package/lib/index.js.map +3 -3
- package/lib/types/client/chat/assistant-step.d.ts +13 -3
- package/lib/types/client/chat/hint-bubble.d.ts +52 -0
- package/lib/types/client/chat/row-plan.d.ts +53 -6
- package/lib/types/client/chat/styles.d.ts +20 -6
- package/lib/types/client/chat/translate-store.d.ts +87 -19
- package/lib/types/client/locales.d.ts +18 -5
- package/lib/types/client/settings/store.d.ts +136 -42
- package/lib/types/client/settings/ui.d.ts +5 -5
- package/lib/types/server/config.d.ts +10 -0
- package/lib/types/server/dispatcher.d.ts +3 -3
- package/lib/types/server/types.d.ts +23 -4
- package/package.json +16 -15
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
* (包括模型认为原样最好的块)换成中文渲染,失败的块保持原文。
|
|
11
11
|
*
|
|
12
12
|
* 正文左缘不画任何东西,正文排版与宿主默认逐字一致。可点的只有左缘之外的两样:
|
|
13
|
-
* 成功块的译文/原文切换归一条
|
|
14
|
-
* 归一个真的 ↻
|
|
15
|
-
*
|
|
13
|
+
* 成功块的译文/原文切换归一条 10px 透明窄带(正文一个像素都不占),失败块的补跑
|
|
14
|
+
* 归一个真的 ↻ 按钮(浮在正文左侧的空隙里)。鼠标停在窄带上时,**光标右边**出
|
|
15
|
+
* 一条气泡报出此刻能做的动作(读译文时「查看原文」,反之亦然),气泡跟着光标在
|
|
16
|
+
* 带子上移动,鼠标离开带子就收起。正文整块不是点击目标,所以单击落字、拖选复制
|
|
17
|
+
* 都不会误触。补跑在途时 ↻ 原位转圈、暂不可重复点。
|
|
16
18
|
*
|
|
17
19
|
* 除正文外的行内容与宿主逐分支等价:reasoning 行走折叠(含 Turn-process
|
|
18
20
|
* 隐藏与 beforematch 揭示)、连续 image 组交回 owner 的 renderMessageImages、
|
|
@@ -25,6 +27,7 @@ import * as React from 'react';
|
|
|
25
27
|
import type { ReactElement, ReactNode } from 'react';
|
|
26
28
|
import type { MarkdownFileMentions } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
27
29
|
import type { AssistantBlockLike } from './row-plan.ts';
|
|
30
|
+
import type { ChatTranslateStore } from './translate-store.ts';
|
|
28
31
|
interface DisclosureState {
|
|
29
32
|
readonly expanded: boolean;
|
|
30
33
|
readonly setExpanded: (open: boolean) => void;
|
|
@@ -52,6 +55,11 @@ interface TurnProcessLike {
|
|
|
52
55
|
readonly setOpen: (open: boolean) => void;
|
|
53
56
|
}
|
|
54
57
|
export interface AssistantStepProps {
|
|
58
|
+
/**
|
|
59
|
+
* 这一行用的翻译池。缺省是客户端半边那一个单例;测试按座次注入自己的池,
|
|
60
|
+
* 好把一行渲染成某个指定的结果态,而不必先让单例池产出那个结果。
|
|
61
|
+
*/
|
|
62
|
+
readonly store?: RowTranslateStore;
|
|
55
63
|
readonly node: {
|
|
56
64
|
readonly data: NodeDataLike;
|
|
57
65
|
readonly location?: {
|
|
@@ -79,5 +87,7 @@ export interface AssistantStepProps {
|
|
|
79
87
|
readonly usePresentation: <R>(select: (policy: PresentationLike) => R) => R;
|
|
80
88
|
readonly t: (key: string, params?: Record<string, unknown>) => string;
|
|
81
89
|
}
|
|
90
|
+
/** 行的翻译池:默认是客户端半边那一个单例,测试可以按座次注入自己的池。 */
|
|
91
|
+
export type RowTranslateStore = Pick<ChatTranslateStore, 'ensure' | 'getState' | 'getVersion' | 'subscribe'>;
|
|
82
92
|
export declare const AssistantStepView: React.MemoExoticComponent<(props: AssistantStepProps) => ReactElement | null>;
|
|
83
93
|
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 左缘透明带上的悬停气泡:一条贴在鼠标右边的提示,报出此刻能做的那个动作。
|
|
3
|
+
*
|
|
4
|
+
* 位置是纯几何计算:默认落在光标右侧 {@link HINT_GAP} 像素、与光标同一高度;
|
|
5
|
+
* 右边放不下时翻到光标左边,上下贴边时把气泡收回视口内。气泡由渲染层常挂、
|
|
6
|
+
* 随鼠标移动改写内联样式——不经过 React 状态,鼠标划过一段正文不会重渲染 markdown。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不用宿主的 `Tooltip`:它把气泡钉在锚点元素的矩形上,而且只在悬停开始那一刻
|
|
9
|
+
* 量一次那个矩形(`show()` 里一次 `getBoundingClientRect`),所以它既到不了光标处、
|
|
10
|
+
* 也不会跟着光标走。这里要的是「跟着光标」,气泡因此自己画;样式取宿主 Tooltip 的
|
|
11
|
+
* 同款令牌与尺寸(见 styles.ts 的 `.dsh-ct-hint`)。
|
|
12
|
+
*/
|
|
13
|
+
/** 光标位置:视口坐标,即鼠标事件的 clientX / clientY。 */
|
|
14
|
+
export interface HintPointer {
|
|
15
|
+
readonly clientX: number;
|
|
16
|
+
readonly clientY: number;
|
|
17
|
+
}
|
|
18
|
+
/** 视口尺寸。 */
|
|
19
|
+
export interface HintViewport {
|
|
20
|
+
readonly width: number;
|
|
21
|
+
readonly height: number;
|
|
22
|
+
}
|
|
23
|
+
/** 气泡与光标之间的间隙。 */
|
|
24
|
+
export declare const HINT_GAP = 12;
|
|
25
|
+
/**
|
|
26
|
+
* 算出气泡该落在哪儿。
|
|
27
|
+
*
|
|
28
|
+
* @param pointer - 光标位置(视口坐标)。
|
|
29
|
+
* @param size - 气泡自己的尺寸(由调用方从元素上量出来)。
|
|
30
|
+
* @param viewport - 视口尺寸。
|
|
31
|
+
* @returns left / top 是给 `position: fixed` 用的视口坐标;side 说气泡落在光标的
|
|
32
|
+
* 哪一侧——`right` 时左边缘贴 left,`left` 时右边缘贴 left(由样式层翻成位移)。
|
|
33
|
+
*/
|
|
34
|
+
export declare function hintPlacement(pointer: HintPointer, size: {
|
|
35
|
+
readonly width: number;
|
|
36
|
+
readonly height: number;
|
|
37
|
+
}, viewport: HintViewport): {
|
|
38
|
+
readonly left: number;
|
|
39
|
+
readonly top: number;
|
|
40
|
+
readonly side: 'left' | 'right';
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* 把气泡挪到光标旁边并显形。尺寸每次现量:气泡宽度由文案决定,而文案会随
|
|
44
|
+
* 译文/原文的切换改变。
|
|
45
|
+
*
|
|
46
|
+
* @param bubble - 气泡元素(`position: fixed`,见 `.dsh-ct-hint`)。
|
|
47
|
+
* @param pointer - 光标位置(视口坐标)。
|
|
48
|
+
* @param viewport - 视口尺寸。
|
|
49
|
+
*/
|
|
50
|
+
export declare function placeHintBubble(bubble: HTMLElement, pointer: HintPointer, viewport: HintViewport): void;
|
|
51
|
+
/** 收起气泡:只摘掉显形标记,元素留在原地(下次悬停不必重挂载)。 */
|
|
52
|
+
export declare function hideHintBubble(bubble: HTMLElement | null): void;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* 渲染层(assistant-step.tsx)只消费 mark 与两个附加位;改动这里的等价分支必须
|
|
19
19
|
* 同时对照宿主实现。
|
|
20
20
|
*/
|
|
21
|
-
import type { BlockOutcome } from './translate-store.ts';
|
|
21
|
+
import type { BlockOutcome, BlockFailKind } from './translate-store.ts';
|
|
22
22
|
import type { ProseMark } from './styles.ts';
|
|
23
23
|
/** 助手行块数据的结构性镜像(值边不跨包,type-only 世界)。 */
|
|
24
24
|
export interface AssistantBlockLike {
|
|
@@ -39,7 +39,10 @@ export type RowPlanEntry =
|
|
|
39
39
|
* 正文块:mark 即左缘标记状态(类名与左缘动作全由它决定);translated 仅在
|
|
40
40
|
* 成功时非 null;showingOriginal 是同一份成功结果上的显示源选择(成功块的
|
|
41
41
|
* 译文/原文切换);fail 仅在 mark==='failed' 时非 null——服务端的技术一句,
|
|
42
|
-
* 供悬停报因;
|
|
42
|
+
* 供悬停报因;failKind 是同一失败的分类(悬停与读屏据此报哪一类原因);
|
|
43
|
+
* retryBusy 仅在这一块被手点补跑时为 true——↻ 原地转圈、暂不可重复点;
|
|
44
|
+
* frozen = 这一块的内容已经写完(流式中只有正在长的尾块为 false,它不带
|
|
45
|
+
* 任何左缘动作,也没有任何结果位)。
|
|
43
46
|
*/
|
|
44
47
|
| {
|
|
45
48
|
type: 'prose';
|
|
@@ -49,7 +52,9 @@ export type RowPlanEntry =
|
|
|
49
52
|
mark: ProseMark;
|
|
50
53
|
showingOriginal: boolean;
|
|
51
54
|
fail: string | null;
|
|
55
|
+
failKind: BlockFailKind | null;
|
|
52
56
|
retryBusy: boolean;
|
|
57
|
+
frozen: boolean;
|
|
53
58
|
} | {
|
|
54
59
|
type: 'images';
|
|
55
60
|
key: number;
|
|
@@ -76,20 +81,62 @@ export interface RowPlanInput {
|
|
|
76
81
|
interrupted: boolean;
|
|
77
82
|
/** flow 分组:'reasoning' 只要思考块,'response' 排除思考块,缺省全要。 */
|
|
78
83
|
groupPart?: string;
|
|
79
|
-
/**
|
|
80
|
-
|
|
84
|
+
/**
|
|
85
|
+
* 通道此刻的状态,决定正文左缘出现什么:'ready' 正常送译、'unconfigured'
|
|
86
|
+
* 不送请求但如实报「设置没配好」、'off' 一律按原文且不挂任何标记。
|
|
87
|
+
*/
|
|
88
|
+
channel: ChannelState;
|
|
81
89
|
/**
|
|
82
90
|
* 该行正文块的翻译结果,与 texts 同下标;null = 该批尚未落定。
|
|
83
91
|
* 未登记或换代时整个缺省。
|
|
84
92
|
*/
|
|
85
93
|
outcomes?: readonly (BlockOutcome | null)[];
|
|
86
94
|
/**
|
|
87
|
-
*
|
|
95
|
+
* 前多少个正文块已经写完(内容冻结)。省略 = 全部写完。流式期间调用方传
|
|
96
|
+
* 当前冻结数:正在长的尾块(下标 >= frozen)保持原文,也不带任何左缘动作。
|
|
97
|
+
*/
|
|
98
|
+
frozen?: number;
|
|
99
|
+
/**
|
|
100
|
+
* 这一轮在途是用户点 ↻ 发起的补跑所涉及的下标:只有它们让失败块的 ↻ 转圈。
|
|
88
101
|
* 首跑在途(还有批没回)不转——用户没点过它。
|
|
89
102
|
*/
|
|
90
|
-
|
|
103
|
+
retrying?: readonly number[];
|
|
91
104
|
/** 用户点了「读原文」的正文块(按条目 key):成功块改回原文渲染,
|
|
92
105
|
* 触发它的是左缘窄带上的切换,不是点正文。 */
|
|
93
106
|
originalKeys?: ReadonlySet<number>;
|
|
94
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* 送译清单:本分组真正会渲染出来的非空白 text 块。reasoning 分组不渲染任何正文,
|
|
110
|
+
* 也就不送译——texts、textIndex、outcomes 三者始终同域对齐。渲染层判「已经写定
|
|
111
|
+
* 到第几块」用的是同一份清单({@link growingTailIndex}),所以这里导出的既是一
|
|
112
|
+
* 个读法,也是那条判据的唯一实现。
|
|
113
|
+
*
|
|
114
|
+
* @param blocks - 行的块清单。
|
|
115
|
+
* @param groupPart - flow 分组。
|
|
116
|
+
* @returns 按出现顺序排列的正文原文。
|
|
117
|
+
*/
|
|
118
|
+
export declare function proseTexts(blocks: readonly AssistantBlockLike[], groupPart?: string): string[];
|
|
119
|
+
/**
|
|
120
|
+
* 流式期间「已经写定」的块数:正文只往后追加,所以除了**正在长的最后一块**,
|
|
121
|
+
* 前面每一块的内容都不会再变。正在长的尾块一个字都不送,它写定的那一刻才轮到它。
|
|
122
|
+
*
|
|
123
|
+
* @param blocks - 行的块清单。
|
|
124
|
+
* @param groupPart - flow 分组;reasoning 分组一块都不送。
|
|
125
|
+
* @returns 已经写定的正文块数。
|
|
126
|
+
*/
|
|
127
|
+
export declare function growingTailIndex(blocks: readonly AssistantBlockLike[], groupPart?: string): number;
|
|
128
|
+
/**
|
|
129
|
+
* 「设置没配好」时进悬停气泡与读屏标签的那一句:本地化的标签已经说清要去哪儿改,
|
|
130
|
+
* 这一句是同一件事的技术侧说明(没有向通道发过请求)。它同时替换掉实际上不会发生
|
|
131
|
+
* 的服务端回执——客户端在这条路上一个字都不发。
|
|
132
|
+
*/
|
|
133
|
+
export declare const NOT_CONFIGURED_DETAIL = "no translation request was sent: the channel is not configured";
|
|
134
|
+
/** 正文块的翻译通道此刻是什么状态,决定正文左缘出现什么。 */
|
|
135
|
+
export type ChannelState =
|
|
136
|
+
/** 开关开着、通道也配齐了:正常送译。 */
|
|
137
|
+
'ready'
|
|
138
|
+
/** 开关开着但通道没配齐(缺 Key / Base URL / 模型):不送请求,但如实标记。 */
|
|
139
|
+
| 'unconfigured'
|
|
140
|
+
/** 总开关关着:纯粹不要翻译,正文保持原文,不挂任何标记。 */
|
|
141
|
+
| 'off';
|
|
95
142
|
export declare function planAssistantRow(input: RowPlanInput): RowPlan;
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
* 默认完全一致。标记只剩两种语义类,且都只是状态钩子、不带任何绘制规则:
|
|
7
7
|
* `dsh-ct-prose-translated`(有译文)与 `dsh-ct-prose-failed`(失败)。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* 1. 成功块的可点面是 `dsh-ct-hotspot
|
|
11
|
-
*
|
|
9
|
+
* 交互压到两个东西上,都落在正文之外:
|
|
10
|
+
* 1. 成功块的可点面是 `dsh-ct-hotspot`——正文左缘外侧那条透明窄带。它整条落在
|
|
11
|
+
* 正文之外(不占正文一个像素),切换译文与原文都由它承载;鼠标停在它上面时
|
|
12
|
+
* 出气泡(`dsh-ct-hint`),报出此刻能做的那个动作(读译文时「查看原文」,
|
|
13
|
+
* 反之亦然)。气泡贴在光标的右边、跟着光标走,位置由渲染层算(hint-bubble.ts)。
|
|
12
14
|
* 2. 失败块的可点面是 `dsh-ct-retry`——一个真的 button(小 ↻),浮在正文左缘
|
|
13
15
|
* 外侧更远一点的位置;补跑在途时它原位转圈(`data-busy`),不重挂载。
|
|
14
16
|
*
|
|
15
|
-
*
|
|
17
|
+
* 两样都不给可见的焦点框:键盘可以聚焦,但界面不加任何标记——这是明说的取舍。
|
|
16
18
|
* 悬停也不改任何视觉,只有指针变手型。动画声明尊重 `prefers-reduced-motion`。
|
|
17
19
|
* 样式随 bundle 注入一次(`<style data-plugin-css>`),类名用固定前缀,不依赖
|
|
18
20
|
* 宿主哈希类名。
|
|
@@ -36,12 +38,24 @@ export declare function proseAction(mark: ProseMark): ProseAction;
|
|
|
36
38
|
* 切换归左缘窄带、补跑归 ↻({@link HOTSPOT_CLASS} / {@link RETRY_CLASS})。
|
|
37
39
|
*/
|
|
38
40
|
export declare function proseClassNames(mark: ProseMark): string | undefined;
|
|
39
|
-
/**
|
|
41
|
+
/** 成功块的可点窄带类名:左缘外一条透明带子,切换译文/原文。 */
|
|
40
42
|
export declare const HOTSPOT_CLASS = "dsh-ct-hotspot";
|
|
41
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* 悬停气泡的类名:一条贴在光标右边的提示,报出窄带此刻能做的动作。位置由渲染层
|
|
45
|
+
* 算(hint-bubble.ts),收起只摘 `data-visible`。它是纯装饰,读屏忽略它——
|
|
46
|
+
* 窄带自己的 aria-label 就是读屏唯一的通道。
|
|
47
|
+
*/
|
|
48
|
+
export declare const HINT_BUBBLE_CLASS = "dsh-ct-hint";
|
|
49
|
+
/** 失败块的 ↻ 类名:一个真的 button,点它只重发这一块。 */
|
|
42
50
|
export declare const RETRY_CLASS = "dsh-ct-retry";
|
|
43
51
|
/** 补跑在途态:挂在 ↻ 自己身上(同一个节点,只换属性,不重挂载)。 */
|
|
44
52
|
export declare const RETRY_BUSY_ATTR = "data-busy";
|
|
53
|
+
/**
|
|
54
|
+
* 「设置还没配好」类失败:同一个 ↻ 位置上的按钮降到次要色(错误红是「通道伤了」
|
|
55
|
+
* 的颜色,设置问题不是通道伤)。位置、可点性、读屏标签都不变——第一题选了 C,
|
|
56
|
+
* 按钮不改成跳转,只是把它报的原因说清楚。
|
|
57
|
+
*/
|
|
58
|
+
export declare const RETRY_UNCONFIGURED_ATTR = "data-unconfigured";
|
|
45
59
|
/** ↻ 的转圈图标类名(转的是图标本身,按钮位置不动)。 */
|
|
46
60
|
export declare const RETRY_SPIN_CLASS = "dsh-ct-retry-spin";
|
|
47
61
|
/** 注入接管样式;重复调用是空操作。 */
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ReplyBlockResult } from '../../server/types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* 一块翻译失败的类别:`channel` = 通道伤(超时、断流、空返回),重试有意义;
|
|
4
|
+
* `not-configured` = 通道还没配齐或设置不对,重试不会变,得先去改设置。
|
|
5
|
+
*/
|
|
6
|
+
export type BlockFailKind = 'channel' | 'not-configured';
|
|
2
7
|
/** 一行正文的按块翻译结果,与请求的 texts 数组按下标对齐。 */
|
|
3
8
|
export interface BlockOutcome {
|
|
4
9
|
/** 模型产出的中文(Markdown 源文本);失败时等于原文。 */
|
|
@@ -7,23 +12,44 @@ export interface BlockOutcome {
|
|
|
7
12
|
ok: boolean;
|
|
8
13
|
/** 仅 ok=false 时可能出现:服务端给出的技术细节,拼在标签后进悬停文案。 */
|
|
9
14
|
detail?: string;
|
|
15
|
+
/** 仅 ok=false 时可能出现:失败类别,决定悬停与读屏报哪一类原因。 */
|
|
16
|
+
reason?: BlockFailKind;
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
|
-
* 一行正文的翻译状态。outcomes 与 texts 同下标,null =
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
19
|
+
* 一行正文的翻译状态。outcomes 与 texts 同下标,null = 该块还没有任何结果:
|
|
20
|
+
* 它还没写定(流式期间正在长,判据见 {@link ChatTranslateStore.ensure} 的
|
|
21
|
+
* `frozen`),或者本代还没有轮到它。每批返回就地填入并通知,长回答按阅读顺序
|
|
22
|
+
* 逐段出中文,不憋到最后一批。
|
|
23
|
+
*
|
|
24
|
+
* settledThrough = 前多少个下标已经写定(正文只往后追加,写定的块内容再也
|
|
25
|
+
* 不会变)。已经落定的块不会因为后面又有新块写定而重发——**失败块是唯一的
|
|
26
|
+
* 例外**,它由用户手点 ↻ 重发(`retries`),池里没有任何自动补跑。
|
|
18
27
|
*/
|
|
19
28
|
export interface RowState {
|
|
20
29
|
status: 'pending' | 'settled';
|
|
21
30
|
texts: readonly string[];
|
|
22
31
|
outcomes: readonly (BlockOutcome | null)[];
|
|
23
|
-
|
|
32
|
+
/** 已经写定的块数:这些下标的内容不会再变。 */
|
|
33
|
+
settledThrough: number;
|
|
34
|
+
/** 这一轮在途是用户手点的补跑所涉及的下标;补跑期间这些块的 ↻ 转圈。 */
|
|
35
|
+
retrying: readonly number[];
|
|
24
36
|
}
|
|
25
37
|
/** 送译一行正文的取数面:默认走宿主路由,测试注入假实现。 */
|
|
26
38
|
export type ReplyFetcher = (texts: string[]) => Promise<ReplyBlockResult[]>;
|
|
39
|
+
/** {@link ChatTranslateStore.ensure} 的调用面。 */
|
|
40
|
+
export interface EnsureOptions {
|
|
41
|
+
/**
|
|
42
|
+
* 前多少个块已经写定(内容冻结、可以送译)。省略 = 全部写定,也就是落定行
|
|
43
|
+
* 的整行送译。流式期间调用方传当前冻结数:正文只往后追加,所以这个数只增
|
|
44
|
+
* 不减;正在长的尾块(下标 >= frozen)一个字都不发。
|
|
45
|
+
*/
|
|
46
|
+
frozen?: number;
|
|
47
|
+
/**
|
|
48
|
+
* 用户点 ↻ 发起的补跑:只重发这些下标里**当前没有成功译文**的块,其余块
|
|
49
|
+
* (成功的、内容已经命中的)原地不动。省略 = 自动首跑,不重发任何已落定的块。
|
|
50
|
+
*/
|
|
51
|
+
retries?: readonly number[];
|
|
52
|
+
}
|
|
27
53
|
/** 同时在池的行数上限:LRU 淘汰最久未读的整行;行文本本身仍归宿主会话持有。 */
|
|
28
54
|
export declare const MAX_TRANSLATED_ROWS = 200;
|
|
29
55
|
/**
|
|
@@ -34,16 +60,27 @@ export declare const MAX_TRANSLATED_ROWS = 200;
|
|
|
34
60
|
export declare const REQUEST_TOKEN_BUDGET = 4096;
|
|
35
61
|
/** 按出现顺序把整行文本切成不超预算的批;单块超预算时独自成批。 */
|
|
36
62
|
export declare function chunkTexts(texts: readonly string[]): string[][];
|
|
63
|
+
/** 文本清单是否同代(逐位相等):池的幂等判据,渲染层拿它核对登记行属于当前文本。 */
|
|
64
|
+
export declare function sameTexts(a: readonly string[], b: readonly string[]): boolean;
|
|
65
|
+
/** 前缀关系:`next` 是不是由 `prev` 往后追加而来(正文流式的正常形态)。 */
|
|
66
|
+
export declare function isAppendOnly(prev: readonly string[], next: readonly string[]): boolean;
|
|
37
67
|
/**
|
|
38
|
-
*
|
|
68
|
+
* 助手行的翻译池:按行键登记「该行正文块的翻译结果」,并按原文内容查已送达的译文。
|
|
69
|
+
*
|
|
70
|
+
* 行键由渲染层给出(会话内锚点序号),文本数组参与一致性判断。判定分两件:
|
|
71
|
+
*
|
|
72
|
+
* - **换代 = 整行重新登记**:文本清单与前一代不是「逐位相等」也不是「往后追加」
|
|
73
|
+
* (正文被整份重写,例如上游模型重试),旧结果整份作废。
|
|
74
|
+
* - **写定的块不回炉**:流式期间调用方逐次给出已经写定的块数,池只对「本次新
|
|
75
|
+
* 写定、而且内容还没有命中」的块发请求。正文只往后追加,先写定的块内容再
|
|
76
|
+
* 也不会变,重发它只是白烧一次通道。
|
|
39
77
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* 单点判定)。在途期间换代,迟到的旧代结果直接丢弃。
|
|
78
|
+
* **内容寻址**:同一段原文在别处出现过(同一行的另一块、另一行、另一个会话),
|
|
79
|
+
* 直接取已送达的译文,不再打通道。手动补跑(`retries`)同样只重发没有成功
|
|
80
|
+
* 译文的块,所以点一次 ↻ 不会把整行重新翻译一遍。
|
|
81
|
+
*
|
|
82
|
+
* **落定即终态**:池里没有任何自动补跑——滚动、重挂载、后面又有新块写定都不会
|
|
83
|
+
* 重发已经落定的块;救活只由 `retries` 发起,无限次、不设额度。
|
|
47
84
|
*
|
|
48
85
|
* 本模块不依赖 React:渲染层用 useSyncExternalStore 订阅版本,再读 getState。
|
|
49
86
|
*/
|
|
@@ -52,24 +89,55 @@ export declare class ChatTranslateStore {
|
|
|
52
89
|
private listeners;
|
|
53
90
|
private version;
|
|
54
91
|
private fetch;
|
|
92
|
+
/** 已送达的译文,按原文内容寻址:跨行、跨代复用同一段文本的结果。 */
|
|
93
|
+
private translated;
|
|
94
|
+
/** 每行写定到哪个下标为止;null(缺席)= 还没有登记过。 */
|
|
95
|
+
private settled;
|
|
96
|
+
/**
|
|
97
|
+
* 每行在途的那一轮请求,登记的是**这一轮认领的那份文本数组**。登记换代时旧
|
|
98
|
+
* 一轮的写入按它丢弃:`live.texts` 与它不再同一个数组就说明行已经换代。
|
|
99
|
+
*/
|
|
100
|
+
private active;
|
|
101
|
+
/**
|
|
102
|
+
* 每行**在飞的块**:下标 → 那一轮请求认领的原文。流式期间新代接手它们的结果位
|
|
103
|
+
* 而不重发,等结果回来按当时登记的原文落账(文本没变才算同一块)。
|
|
104
|
+
*/
|
|
105
|
+
private pending;
|
|
55
106
|
constructor(fetcher: ReplyFetcher);
|
|
56
107
|
/** 单调版本号:任何状态变化(含单批落定)都前进一位,供渲染层判等重渲。 */
|
|
57
108
|
getVersion(): number;
|
|
58
109
|
subscribe: (listener: () => void) => (() => void);
|
|
59
110
|
/** 读一行状态,并把该行刷成最近使用。 */
|
|
60
111
|
getState(rowKey: string): RowState | undefined;
|
|
112
|
+
/** 按原文内容查已送达的译文;null = 还没有结果。 */
|
|
113
|
+
lookup(text: string): string | null;
|
|
61
114
|
/**
|
|
62
115
|
* 确保该行按当前文本被翻译。
|
|
63
|
-
* @param
|
|
116
|
+
* @param rowKey - 行键(会话内锚点)。
|
|
117
|
+
* @param texts - 该行正文的原文清单,与渲染用的下标对齐。
|
|
118
|
+
* @param options - `frozen`(写定到第几块)与 `retries`(手点补跑哪些块)。
|
|
64
119
|
* @returns 是否发出了新的请求。
|
|
65
120
|
*/
|
|
66
|
-
ensure(rowKey: string, texts: readonly string[],
|
|
121
|
+
ensure(rowKey: string, texts: readonly string[], options?: EnsureOptions): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* 建本轮的取数计划:哪些下标要送、送什么文本、结果位怎么排。
|
|
124
|
+
*
|
|
125
|
+
* 只对**已经写定、而且内容还没命中**的块发请求。自动首跑里先前写定的下标一律
|
|
126
|
+
* 跳过(它们要么已经成功,要么在等手点补跑);`retries` 只对点名的块解禁一次。
|
|
127
|
+
*/
|
|
128
|
+
private planFor;
|
|
67
129
|
private run;
|
|
130
|
+
/**
|
|
131
|
+
* 把这一次请求已经拿到的结果写回行。
|
|
132
|
+
*
|
|
133
|
+
* 落账的判据是**在飞账本**而不是文本数组的身份:这一块还在飞、而且行的原文与
|
|
134
|
+
* 那时登记的一字不差,结果才算数。行被换代(旧结果整份作废)、被 LRU 淘汰、
|
|
135
|
+
* 或者那一块已经被手动补跑重新认领时,结果一律丢弃。
|
|
136
|
+
*/
|
|
137
|
+
private commit;
|
|
68
138
|
private prune;
|
|
69
139
|
private bump;
|
|
70
140
|
}
|
|
71
|
-
/** 文本清单是否同代(逐位相等):池的幂等判据,渲染层拿它核对登记行属于当前文本。 */
|
|
72
|
-
export declare function sameTexts(a: readonly string[], b: readonly string[]): boolean;
|
|
73
141
|
/** 供测试注入取数面创建独立池。 */
|
|
74
142
|
export declare function createTranslateStore(fetcher: ReplyFetcher): ChatTranslateStore;
|
|
75
143
|
/** 正文翻译池:客户端半边唯一的按行译文登记处。 */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Locale bundles for the chat-translate card on the DSH Plugins page. */
|
|
2
|
+
import type { BlockFailKind } from './chat/translate-store.ts';
|
|
2
3
|
/** Dictionary namespace owned by this plugin's settings card. */
|
|
3
4
|
export declare const NS = "settings.chatTranslate";
|
|
4
5
|
/**
|
|
@@ -33,16 +34,25 @@ export declare const zh: {
|
|
|
33
34
|
readonly testing: "测试中…";
|
|
34
35
|
readonly testOk: "连接正常,延迟 {latency}ms";
|
|
35
36
|
readonly testFail: "失败:{error}";
|
|
37
|
+
readonly unsavedHint: "改动保存后才生效";
|
|
38
|
+
readonly invalidTimeout: "超时填写不合法:请填 500 到 900000 之间的毫秒数";
|
|
39
|
+
readonly saveProbeOk: "设置已保存,通道连接正常";
|
|
40
|
+
readonly saveProbeFail: "设置已保存,但通道探测失败:{error}";
|
|
36
41
|
readonly behaviorTitle: "翻译范围";
|
|
37
42
|
readonly behaviorRule: "助手回答正文一律翻译,包括最终汇总与整段中文的块:中文块同样交给模型改写成自然中文,意义、术语与数字不变;空白块不送译、左缘不出现任何标记。思考链正文、工具调用标题与折叠摘要不翻译,代码块及其内部原样保留。";
|
|
38
43
|
readonly dockLabel: "译";
|
|
39
44
|
readonly dockOn: "正文翻译已开启,点击关闭";
|
|
40
45
|
readonly dockOff: "正文翻译已关闭,点击开启";
|
|
41
46
|
readonly failTitle: "翻译失败";
|
|
42
|
-
readonly
|
|
47
|
+
readonly failTitleUnconfigured: "翻译通道还没配好";
|
|
48
|
+
readonly retryAria: "翻译失败,点这个按钮重新翻译这一块";
|
|
43
49
|
readonly retryBusyAria: "正在重新翻译,请等待";
|
|
50
|
+
readonly retryAriaUnconfigured: "翻译通道还没配好:先去「插件」页把 API Key、Base URL 与模型填齐,再回来点这个按钮重试";
|
|
51
|
+
readonly retryBusyAriaUnconfigured: "正在重试,请等待";
|
|
44
52
|
readonly toggleToOriginalAria: "查看原文";
|
|
45
53
|
readonly toggleToTranslatedAria: "查看译文";
|
|
54
|
+
readonly hotspotShowOriginal: "查看原文";
|
|
55
|
+
readonly hotspotShowTranslation: "查看译文";
|
|
46
56
|
};
|
|
47
57
|
/** Locale keys this plugin renders. */
|
|
48
58
|
export type ChatTranslateLocaleKey = keyof typeof zh;
|
|
@@ -62,12 +72,15 @@ export declare function rowCopy(): {
|
|
|
62
72
|
* `aria-describedby`,所以败因必须进标签本身——读屏用户不悬停,这是他们
|
|
63
73
|
* 唯一能听到「超时 / 断流 / 空返回」的通道。
|
|
64
74
|
*/
|
|
65
|
-
retryAria: (detail?: string | null) => string;
|
|
75
|
+
retryAria: (detail?: string | null, kind?: BlockFailKind | null) => string;
|
|
66
76
|
/** 补跑在途时 ↻ 的读屏标签:说清此刻按下去没有动作,同样带上败因。 */
|
|
67
|
-
retryBusyAria: (detail?: string | null) => string;
|
|
77
|
+
retryBusyAria: (detail?: string | null, kind?: BlockFailKind | null) => string;
|
|
68
78
|
/** 窄带的读屏标签:读译文时提示可切回原文,反之亦然。 */
|
|
69
79
|
toggleToOriginalAria: string;
|
|
70
80
|
toggleToTranslatedAria: string;
|
|
71
|
-
/**
|
|
72
|
-
|
|
81
|
+
/** 左缘窄带悬停时气泡里的文案:当前能做的那个动作。 */
|
|
82
|
+
hotspotShowOriginal: string;
|
|
83
|
+
hotspotShowTranslation: string;
|
|
84
|
+
/** 失败块悬停文案:本地化标签(按失败类别)+ 服务端带来的技术一句。 */
|
|
85
|
+
failTitle: (kind?: BlockFailKind | null, detail?: string | null) => string;
|
|
73
86
|
};
|