@lynn123411/dsh-chat-translate 3.6.0 → 3.8.0
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 +38 -7
- package/README.md +5 -4
- package/lib/client.js +59 -26
- package/lib/client.js.map +3 -3
- package/lib/index.js +33 -16
- package/lib/index.js.map +3 -3
- package/lib/types/client/chat/assistant-step.d.ts +14 -2
- package/lib/types/client/chat/conclusion.d.ts +56 -0
- package/lib/types/client/chat/row-plan.d.ts +16 -5
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/prompt.d.ts +19 -14
- package/lib/types/server/adapters/openai.d.ts +16 -9
- package/lib/types/server/prompt-revision.d.ts +5 -5
- package/lib/types/server/sampling.d.ts +12 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
|
@@ -37,7 +37,7 @@ interface PresentationLike {
|
|
|
37
37
|
readonly settledReasoningPreview: boolean;
|
|
38
38
|
}
|
|
39
39
|
interface NodeDataLike {
|
|
40
|
-
readonly status:
|
|
40
|
+
readonly status: 'running' | 'settled' | 'interrupted';
|
|
41
41
|
readonly turn: number;
|
|
42
42
|
readonly step: number;
|
|
43
43
|
readonly blocks: readonly AssistantBlockLike[];
|
|
@@ -48,8 +48,13 @@ interface NodeDataLike {
|
|
|
48
48
|
interface TurnProcessLike {
|
|
49
49
|
readonly foldable: boolean;
|
|
50
50
|
readonly open: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 宿主 `TurnProcessSpec` 的结构性镜像。`answerStep` 在宿主那里是可以为 null
|
|
53
|
+
* 的(本轮还没有落定的消息),镜像必须照实写,否则判据会在类型层面被当成
|
|
54
|
+
* 「永远有值」。
|
|
55
|
+
*/
|
|
51
56
|
readonly spec: {
|
|
52
|
-
readonly answerStep: number;
|
|
57
|
+
readonly answerStep: number | null;
|
|
53
58
|
readonly inlineReasoning: boolean;
|
|
54
59
|
};
|
|
55
60
|
readonly setOpen: (open: boolean) => void;
|
|
@@ -62,10 +67,17 @@ export interface AssistantStepProps {
|
|
|
62
67
|
readonly store?: RowTranslateStore;
|
|
63
68
|
readonly node: {
|
|
64
69
|
readonly data: NodeDataLike;
|
|
70
|
+
/**
|
|
71
|
+
* 宿主 `TurnLocation` 的结构性镜像:本轮各 step 的号只用来判「后面还有没有
|
|
72
|
+
* 一步」,所以这里只声明 `step` 一个字段,不声明每一步的数据。
|
|
73
|
+
*/
|
|
65
74
|
readonly location?: {
|
|
66
75
|
readonly kind?: string;
|
|
67
76
|
readonly turn?: {
|
|
68
77
|
readonly status?: string;
|
|
78
|
+
readonly steps?: readonly {
|
|
79
|
+
readonly step: number;
|
|
80
|
+
}[];
|
|
69
81
|
};
|
|
70
82
|
};
|
|
71
83
|
readonly anchorSeq?: number;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 结论步骤的判据:这一行正文要不要送译。
|
|
3
|
+
*
|
|
4
|
+
* 一轮回答里,前面几步在干活(读文件、跑命令),最后一步把结论交给读者。前者
|
|
5
|
+
* 的散文往往是英文,要翻;后者由模型直接写给读者,通常是已经写好的中文,再送
|
|
6
|
+
* 一遍模型只换来等待与改坏的风险。所以**结论步骤的正文一律不送译**:它按原文
|
|
7
|
+
* 呈现,左缘不出现任何东西(没有窄带、没有 ↻、不报「设置没配好」)——与总开关
|
|
8
|
+
* 关着时一样,是纯粹的「这里不翻译」,不是失败。
|
|
9
|
+
*
|
|
10
|
+
* 「哪一步是结论」的权威信号来自宿主。`TurnProcessSpec.answerStep`
|
|
11
|
+
* (`packages/client/ui-chat/src/client/conversation-nodes/turn-process.ts`)取本轮
|
|
12
|
+
* 最后一个 step,要求它带着 `finalNode`(消息已落定)、有正文、且**不含
|
|
13
|
+
* tool-call**。这个字段在流式期间是 null,插件因此要自己补上「还没落定」那一段
|
|
14
|
+
* 的判断——下面 3、4 两档复刻的就是宿主那三条条件,宿主改动时由
|
|
15
|
+
* `scripts/test-host-parity.mjs` 里钉 `latestAnswer()` 的那条断言报出来。判定按
|
|
16
|
+
* 从严到宽分档:
|
|
17
|
+
*
|
|
18
|
+
* 1. `answerStep` 有值:直接用,它是宿主的权威答案。
|
|
19
|
+
* 2. 没有轮次投影(`answerStep === undefined`):判不了就是判不了,一律照旧送译
|
|
20
|
+
* ——宁可多翻一段,也不能因为拿不到投影就把整段正文悄悄关掉。
|
|
21
|
+
* 3. `answerStep` 是 null(本轮还没有落定的消息):若已知本轮的 step 序列,而这
|
|
22
|
+
* 一行不是最后一个 step,就肯定不是结论——后面还有一步要走。
|
|
23
|
+
* 4. 剩下的就是「可能成为结论」。带 tool-call 的 step 按宿主判据永远成不了结论,
|
|
24
|
+
* 可以当场送译;还在写、又只有正文的行先按结论处理:先译再撤会让读者眼前的
|
|
25
|
+
* 中文闪回原文。
|
|
26
|
+
*
|
|
27
|
+
* 第四档是唯一的取舍:一个只有正文、没有 tool-call 的过程步骤(例如「我先看一眼
|
|
28
|
+
* 实现」)会等到下一步开始时才送译。这是为了让结论行从第一帧起就是原文。
|
|
29
|
+
*/
|
|
30
|
+
import type { AssistantBlockLike } from './row-plan.ts';
|
|
31
|
+
/** {@link isConclusionRow} 的输入。 */
|
|
32
|
+
export interface ConclusionInput {
|
|
33
|
+
/** 行状态:`running` 还在写,`settled` 已落定,`interrupted` 被中断。 */
|
|
34
|
+
status: 'running' | 'settled' | 'interrupted';
|
|
35
|
+
/** 这一行所属的 step 号。 */
|
|
36
|
+
step: number;
|
|
37
|
+
/** 行的块清单。 */
|
|
38
|
+
blocks: readonly AssistantBlockLike[];
|
|
39
|
+
/**
|
|
40
|
+
* 宿主算出的结论步骤号(`TurnProcessSpec.answerStep`);`null` = 本轮还没有
|
|
41
|
+
* 落定的消息,宿主暂时给不出这个答案;`undefined` = 这一行没拿到轮次投影。
|
|
42
|
+
*/
|
|
43
|
+
answerStep?: number | null | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* 本轮各 step 的号,升序;缺省 = 不知道本轮还有没有后面的 step。只需要号,
|
|
46
|
+
* 不读每一步的数据。
|
|
47
|
+
*/
|
|
48
|
+
turnSteps?: readonly number[] | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 这一行是不是本轮结论步骤的正文。
|
|
52
|
+
*
|
|
53
|
+
* @param input - 行状态、step、块清单,以及宿主的结论步骤号。
|
|
54
|
+
* @returns 是结论步骤则为 true(正文不送译)。
|
|
55
|
+
*/
|
|
56
|
+
export declare function isConclusionRow(input: ConclusionInput): boolean;
|
|
@@ -101,27 +101,38 @@ export interface RowPlanInput {
|
|
|
101
101
|
/** 用户点了「读原文」的正文块(按条目 key):成功块改回原文渲染,
|
|
102
102
|
* 触发它的是左缘窄带上的切换,不是点正文。 */
|
|
103
103
|
originalKeys?: ReadonlySet<number>;
|
|
104
|
+
/**
|
|
105
|
+
* 这一行是不是本轮结论步骤的正文(判据见 `conclusion.ts`)。是则整行正文按原文
|
|
106
|
+
* 呈现:不送译、不挂窄带、不挂 ↻、不报「设置没配好」——与总开关关着时一样,
|
|
107
|
+
* 是纯粹的「这里不翻译」,不是失败。
|
|
108
|
+
*/
|
|
109
|
+
conclusion?: boolean;
|
|
104
110
|
}
|
|
105
111
|
/**
|
|
106
112
|
* 送译清单:本分组真正会渲染出来的非空白 text 块。reasoning 分组不渲染任何正文,
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
113
|
+
* 也就不送译;结论步骤的正文按原文呈现,整行一块都不送——判据见
|
|
114
|
+
* `conclusion.ts` 的 `isConclusionRow()`。texts、textIndex、outcomes 三者始终同域
|
|
115
|
+
* 对齐。渲染层判「已经写定到第几块」用的是同一份清单({@link growingTailIndex}),
|
|
116
|
+
* 所以这里导出的既是一个读法,也是那条判据的唯一实现。
|
|
110
117
|
*
|
|
111
118
|
* @param blocks - 行的块清单。
|
|
112
119
|
* @param groupPart - flow 分组。
|
|
120
|
+
* @param conclusion - 这一行是不是本轮结论步骤:是则没有可送译的正文。
|
|
113
121
|
* @returns 按出现顺序排列的正文原文。
|
|
114
122
|
*/
|
|
115
|
-
export declare function proseTexts(blocks: readonly AssistantBlockLike[], groupPart?: string): string[];
|
|
123
|
+
export declare function proseTexts(blocks: readonly AssistantBlockLike[], groupPart?: string, conclusion?: boolean): string[];
|
|
116
124
|
/**
|
|
117
125
|
* 流式期间「已经写定」的块数:正文只往后追加,所以除了**正在长的最后一块**,
|
|
118
126
|
* 前面每一块的内容都不会再变。正在长的尾块一个字都不送,它写定的那一刻才轮到它。
|
|
119
127
|
*
|
|
120
128
|
* @param blocks - 行的块清单。
|
|
121
129
|
* @param groupPart - flow 分组;reasoning 分组一块都不送。
|
|
130
|
+
* @param options - `conclusion` 说这一行是结论步骤,送译清单为空。
|
|
122
131
|
* @returns 已经写定的正文块数。
|
|
123
132
|
*/
|
|
124
|
-
export declare function growingTailIndex(blocks: readonly AssistantBlockLike[], groupPart
|
|
133
|
+
export declare function growingTailIndex(blocks: readonly AssistantBlockLike[], groupPart: string | undefined, options?: {
|
|
134
|
+
conclusion?: boolean;
|
|
135
|
+
}): number;
|
|
125
136
|
/**
|
|
126
137
|
* 「设置没配好」时进悬停气泡与读屏标签的那一句:本地化的标签已经说清要去哪儿改,
|
|
127
138
|
* 这一句是同一件事的技术侧说明(没有向通道发过请求)。它同时替换掉实际上不会发生
|
|
@@ -38,7 +38,7 @@ export declare const zh: {
|
|
|
38
38
|
readonly saveProbeOk: "设置已保存,通道连接正常";
|
|
39
39
|
readonly saveProbeFail: "设置已保存,但通道探测失败:{error}";
|
|
40
40
|
readonly promptTitle: "翻译提示词";
|
|
41
|
-
readonly promptDesc: "
|
|
41
|
+
readonly promptDesc: "拼在待译正文前面的那段指令。点「编辑」可以改写,改完点下面的「保存」生效;留空等于用内置默认。";
|
|
42
42
|
readonly promptEdit: "编辑";
|
|
43
43
|
readonly promptDone: "完成";
|
|
44
44
|
readonly promptRestore: "恢复默认";
|
package/lib/types/prompt.d.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 发给翻译模型的请求前缀,以及「打包成多段」时追加的那一段说明。
|
|
3
3
|
*
|
|
4
4
|
* 这段文字是配置页上可改的一项:Host 的 Config 里 `prompt` 存用户改写过的
|
|
5
5
|
* 那一份,空着就用 {@link DEFAULT_PROMPT}。两半边都读本模块——宿主半边拿它
|
|
6
|
-
*
|
|
6
|
+
* 拼请求前缀,浏览器半边拿它填满提示词输入框、并在「恢复默认」时放回原样。
|
|
7
|
+
*
|
|
8
|
+
* 请求里只有一条 user 消息:前缀在前,待译正文在后(见 `server/adapters/openai.ts`)。
|
|
7
9
|
*
|
|
8
10
|
* 内置默认的写法有几条是承载行为的,改文案时别把它们删掉:
|
|
9
11
|
*
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* -
|
|
12
|
+
* - 两个短例排在最前,写成「输入/输出」的对话样式。示例决定模型把中文当
|
|
13
|
+
* 待译内容还是当抄写对象;排到规则后面、或写成「原文/译文」,模型会把示例
|
|
14
|
+
* 连同规则一起搬进译文。
|
|
15
|
+
* - 首句的动词是「原样抄写」,不是「翻译」或「整理」。写成后者时模型回到
|
|
16
|
+
* 改写模式,已经通顺的中文会被换一套说法。
|
|
17
|
+
* - 送来的每一段都交给模型(判据见 `client/chat/conclusion.ts`),所以
|
|
18
|
+
* 抄写后面必须留「只有句子读不通时才改那几句」:那是它唯一被允许改动
|
|
19
|
+
* 中文的入口。
|
|
20
|
+
* - 「保持 Markdown 记号」是必要提醒。宿主会按行签名把结构修回去
|
|
21
|
+
* (`pipeline/segments.ts`),提示词只管让模型少制造要修的地方,不逐条
|
|
22
|
+
* 规定行数、链接括号这些细节——那些由代码兜底。
|
|
19
23
|
*
|
|
20
24
|
* 代码围栏在送模型之前就被切掉了(`pipeline/segments.ts`),所以这里不提
|
|
21
|
-
*
|
|
25
|
+
* 围栏本身,只按括号形状描述打包标记:点名具体字符会让模型把整段约定当成
|
|
26
|
+
* 待译内容。
|
|
22
27
|
*/
|
|
23
28
|
export declare const DEFAULT_PROMPT: string;
|
|
24
29
|
/**
|
|
@@ -26,11 +31,11 @@ export declare const DEFAULT_PROMPT: string;
|
|
|
26
31
|
* 许合并。它是请求形状的约定,不是译文风格,所以跟着拼请求时自动追加,配置
|
|
27
32
|
* 页上只让人改上面那段正文指令。
|
|
28
33
|
*/
|
|
29
|
-
export declare const BATCH_PROMPT_CLAUSE = "
|
|
34
|
+
export declare const BATCH_PROMPT_CLAUSE = "\u4E0B\u9762\u6BCF\u6BB5\u90FD\u4EE5\u5355\u72EC\u4E00\u884C\u6807\u8BB0\u5F00\u5934\uFF0C\u6807\u8BB0\u7531\u4E24\u4E2A\u62EC\u53F7\u5939\u7740\u4E00\u4E2A\u7F16\u53F7\u3002\u6BCF\u6BB5\u5148\u539F\u6837\u8F93\u51FA\u90A3\u4E00\u884C\u6807\u8BB0\uFF0C\u518D\u5728\u4E0B\u4E00\u884C\u5199\u8FD9\u6BB5\u7684\u8BD1\u6587\uFF0C\u987A\u5E8F\u4E0D\u53D8\uFF0C\u6BB5\u4E0E\u6BB5\u4E0D\u8981\u5408\u5E76\u3002";
|
|
30
35
|
/**
|
|
31
36
|
* 当前生效的指令正文:用户改写过的优先,空白视为没写过。
|
|
32
37
|
* @param prompt - Config 里 `prompt` 的值,可能是空串。
|
|
33
|
-
* @returns
|
|
38
|
+
* @returns 拼在待译正文前面的那段文字。
|
|
34
39
|
*/
|
|
35
40
|
export declare function resolvePrompt(prompt: string | undefined): string;
|
|
36
41
|
/**
|
|
@@ -7,22 +7,29 @@ import type { KeyReader } from '../credentials.ts';
|
|
|
7
7
|
* ~/.dsh/.credentials.yaml (refs.TRANSLATE_API_KEY). Works with OpenAI,
|
|
8
8
|
* DeepSeek, Qwen, Ollama and any other service exposing the standard endpoint.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* 请求里只有一条 user 消息:指令在前、待译正文在后,与 Hy-MT 系列的训练分布
|
|
11
|
+
* 一致。指令正文连同它的写作要点住在 `src/prompt.ts`。
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* multi-part marker clause when the request packs several parts.
|
|
14
|
+
* 一条请求的前缀:配置页上那段指令,打包多段时再接上标记约定。
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* request.
|
|
16
|
+
* 导出是因为它就是模型在正文之前原样收到的那段文字——回归测试直接断言它,
|
|
17
|
+
* 而不是绕一圈发一个请求。
|
|
20
18
|
*
|
|
21
19
|
* @param mode - `plain` for one fragment, `blocks` for a packed multi-part request.
|
|
22
20
|
* @param prompt - the prompt as configured; blank means the built-in default.
|
|
23
|
-
* @returns the complete
|
|
21
|
+
* @returns the complete request prefix.
|
|
24
22
|
*/
|
|
25
|
-
export declare function
|
|
23
|
+
export declare function buildRequestPrefix(mode: 'plain' | 'blocks', prompt?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* 一条请求的 user 消息:前缀在前,待译正文在后,中间空一行。
|
|
26
|
+
*
|
|
27
|
+
* @param mode - `plain` for one fragment, `blocks` for a packed multi-part request.
|
|
28
|
+
* @param text - the text to translate, markers included when packed.
|
|
29
|
+
* @param prompt - the prompt as configured; blank means the built-in default.
|
|
30
|
+
* @returns the user message content.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildUserMessage(mode: 'plain' | 'blocks', text: string, prompt?: string): string;
|
|
26
33
|
export declare class OpenAiCompatibleAdapter implements ITranslationAdapter {
|
|
27
34
|
readonly id = "openai";
|
|
28
35
|
readonly name = "OpenAI \u517C\u5BB9 (Chat Completions)";
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Bump it — and only here — whenever the built-in prompt in `src/prompt.ts`
|
|
3
3
|
* changes what the model is asked to do. Copy-only edits may ride.
|
|
4
4
|
*/
|
|
5
|
-
export declare const PROMPT_REVISION = "
|
|
5
|
+
export declare const PROMPT_REVISION = "r6";
|
|
6
6
|
/**
|
|
7
7
|
* Cache generation for the prompt currently in force.
|
|
8
8
|
*
|
|
9
|
-
* The digest
|
|
10
|
-
* one, the built-in default otherwise —
|
|
11
|
-
*
|
|
12
|
-
* and
|
|
9
|
+
* The digest covers the effective prompt — the reader's text when they wrote
|
|
10
|
+
* one, the built-in default otherwise — and the sampling parameters the request
|
|
11
|
+
* goes out with, so editing either one retires every translation the previous
|
|
12
|
+
* settings produced, and landing on the same settings again reuses the pool.
|
|
13
13
|
*
|
|
14
14
|
* @param prompt - the configured prompt; blank means the built-in default.
|
|
15
15
|
* @returns the generation string a cache document is written and matched under.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 采样参数:Hy-MT2-1.8B 的官方推荐值。
|
|
3
|
+
*
|
|
4
|
+
* 只发标准参数。官方推荐里还有 `top_k 20` 与 `repetition_penalty 1.05`,
|
|
5
|
+
* 它们是 vLLM 系服务的扩展,严格的 OpenAI 兼容端点收到会直接 400,所以不随
|
|
6
|
+
* 请求发出;用自建服务的人可以照这两个值在自己的服务上配。
|
|
7
|
+
*
|
|
8
|
+
* 同一段原文今天翻两次可能不一样,但同一段只翻一次(译文池按原文内容命中),
|
|
9
|
+
* 所以差异只出现在不同段落之间。
|
|
10
|
+
*/
|
|
11
|
+
export declare const SAMPLING_TEMPERATURE = 0.7;
|
|
12
|
+
export declare const SAMPLING_TOP_P = 0.6;
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Chat translate",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "Translates foreign prose in assistant replies into Simplified Chinese and keeps passages already in Chinese as they are; code blocks and thinking chains are untouched."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED