@lynn123411/dsh-chat-translate 3.8.0 → 3.9.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 +23 -7
- package/README.md +3 -2
- package/assets/icon.svg +5 -5
- package/lib/client.js +97 -109
- package/lib/client.js.map +3 -3
- package/lib/index.js +35 -8
- package/lib/index.js.map +2 -2
- package/lib/types/client/locales.d.ts +3 -8
- package/lib/types/client/settings/store.d.ts +31 -34
- package/lib/types/client/settings/ui.d.ts +4 -4
- package/lib/types/prompt.d.ts +25 -0
- package/lib/types/server/adapters/openai.d.ts +4 -2
- package/lib/types/server/dispatcher.d.ts +3 -0
- package/lib/types/server/pipeline/segments.d.ts +10 -2
- package/lib/types/server/prompt-revision.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
3
|
+
* has staged on the page, and what a commit would write.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
196
|
-
*
|
|
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:
|
|
203
|
-
*
|
|
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
|
|
210
|
-
*
|
|
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
|
|
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
|
|
225
|
-
*
|
|
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
|
-
*
|
|
228
|
-
*
|
|
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
|
|
8
|
-
* revision-fenced document mutation
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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/lib/types/prompt.d.ts
CHANGED
|
@@ -21,11 +21,24 @@
|
|
|
21
21
|
* (`pipeline/segments.ts`),提示词只管让模型少制造要修的地方,不逐条
|
|
22
22
|
* 规定行数、链接括号这些细节——那些由代码兜底。
|
|
23
23
|
*
|
|
24
|
+
* 「原文分几段的,译文也分几段,一段都不要少」不在默认里,由
|
|
25
|
+
* {@link promptFor} 按待译正文**追加**:小模型会把开头那段当整段交差、后面
|
|
26
|
+
* 几段整段不写,这一句能把丢段压到零;但它同时会让本来就只有一段的中文被
|
|
27
|
+
* 多改一遍(实测同样的五条单段样本,改动率从约 2% 升到约 10%)。所以它只在
|
|
28
|
+
* 正文自己分了段时才出现——那一刻丢段才是真正的风险。
|
|
29
|
+
*
|
|
24
30
|
* 代码围栏在送模型之前就被切掉了(`pipeline/segments.ts`),所以这里不提
|
|
25
31
|
* 围栏本身,只按括号形状描述打包标记:点名具体字符会让模型把整段约定当成
|
|
26
32
|
* 待译内容。
|
|
27
33
|
*/
|
|
28
34
|
export declare const DEFAULT_PROMPT: string;
|
|
35
|
+
/**
|
|
36
|
+
* 多段正文追加的一句:原文分几段,译文就分几段,一段都不许少。
|
|
37
|
+
*
|
|
38
|
+
* 它单独成句、接在默认指令之后,不并进上面那句话:并进去会失效。待译正文
|
|
39
|
+
* 只有一段时它不出现——那时它没有要保的东西,只会让中文被多改一遍。
|
|
40
|
+
*/
|
|
41
|
+
export declare const PARAGRAPH_KEEP_CLAUSE = "\u539F\u6587\u5206\u51E0\u6BB5\u7684\uFF0C\u8BD1\u6587\u4E5F\u5206\u51E0\u6BB5\uFF0C\u4E00\u6BB5\u90FD\u4E0D\u8981\u5C11\u3002";
|
|
29
42
|
/**
|
|
30
43
|
* 打包成多段时追加的一段:说清每段自带一行标记、标记要原样带出、段与段不
|
|
31
44
|
* 许合并。它是请求形状的约定,不是译文风格,所以跟着拼请求时自动追加,配置
|
|
@@ -38,6 +51,18 @@ export declare const BATCH_PROMPT_CLAUSE = "\u4E0B\u9762\u6BCF\u6BB5\u90FD\u4EE5
|
|
|
38
51
|
* @returns 拼在待译正文前面的那段文字。
|
|
39
52
|
*/
|
|
40
53
|
export declare function resolvePrompt(prompt: string | undefined): string;
|
|
54
|
+
/**
|
|
55
|
+
* 拼一条请求真正用的前缀:生效的指令,正文分了段时再接上
|
|
56
|
+
* {@link PARAGRAPH_KEEP_CLAUSE}。
|
|
57
|
+
*
|
|
58
|
+
* 追加的最后一句是给模型看的最后一条要求,所以它排在生效指令的末尾——生效
|
|
59
|
+
* 指令由读者改写时同样如此,成段保真不归读者维护。
|
|
60
|
+
*
|
|
61
|
+
* @param text - 这一次要送出去的待译正文(打包时带标记的整段负载)。
|
|
62
|
+
* @param prompt - the prompt as configured; blank means the built-in default.
|
|
63
|
+
* @returns 拼在待译正文前面的那段文字。
|
|
64
|
+
*/
|
|
65
|
+
export declare function promptFor(text: string, prompt?: string): string;
|
|
41
66
|
/**
|
|
42
67
|
* 这份草稿是不是就等于内置默认(空着、或一字不差地写着默认都算)。
|
|
43
68
|
*
|
|
@@ -11,16 +11,18 @@ import type { KeyReader } from '../credentials.ts';
|
|
|
11
11
|
* 一致。指令正文连同它的写作要点住在 `src/prompt.ts`。
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* 一条请求的前缀:配置页上那段指令,正文分了段时接上成段保真那一句,打包
|
|
15
|
+
* 多段时再接上标记约定。
|
|
15
16
|
*
|
|
16
17
|
* 导出是因为它就是模型在正文之前原样收到的那段文字——回归测试直接断言它,
|
|
17
18
|
* 而不是绕一圈发一个请求。
|
|
18
19
|
*
|
|
19
20
|
* @param mode - `plain` for one fragment, `blocks` for a packed multi-part request.
|
|
21
|
+
* @param text - 这一次要送出去的待译正文;分段与否决定要不要追加保真那一句。
|
|
20
22
|
* @param prompt - the prompt as configured; blank means the built-in default.
|
|
21
23
|
* @returns the complete request prefix.
|
|
22
24
|
*/
|
|
23
|
-
export declare function buildRequestPrefix(mode: 'plain' | 'blocks', prompt?: string): string;
|
|
25
|
+
export declare function buildRequestPrefix(mode: 'plain' | 'blocks', text: string, prompt?: string): string;
|
|
24
26
|
/**
|
|
25
27
|
* 一条请求的 user 消息:前缀在前,待译正文在后,中间空一行。
|
|
26
28
|
*
|
|
@@ -46,6 +46,9 @@ export declare class TranslationDispatcher {
|
|
|
46
46
|
/**
|
|
47
47
|
* 发出一次正文请求,返回逐片段的裸答案(打包标记已剥除、首尾已 trim)。
|
|
48
48
|
* 空返回与打包拆不回都按通道失败抛出——形状对不对在这里不算败因。
|
|
49
|
+
*
|
|
50
|
+
* @param packed - 单个片段也走带标记的打包形状。缺段之后的重问用它:标记把
|
|
51
|
+
* 这一段框成「一整段待译内容」,模型不再把开头那段当整段交差。
|
|
49
52
|
*/
|
|
50
53
|
private fetchReplyAnswers;
|
|
51
54
|
/** 串行执行器:同时最多一个在途请求。 */
|
|
@@ -36,11 +36,19 @@ export interface ShapeRepair {
|
|
|
36
36
|
text: string | null;
|
|
37
37
|
/** 修不了时的一句理由,直接进悬停文案。 */
|
|
38
38
|
error: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* 修不了的原因是不是**正文没写全**:整段少写了才算,记号、竖线、链接这些
|
|
41
|
+
* 骨架漂移不算。内容少了没有「照收」这条退路——收下就等于把原文那几段
|
|
42
|
+
* 永久丢掉,所以调用方据此换一种救法。
|
|
43
|
+
*/
|
|
44
|
+
missingContent?: boolean;
|
|
39
45
|
}
|
|
40
46
|
/**
|
|
41
47
|
* 形状修复:核对与修形一次过,能修的绝不成败因。骨架按**段落块**对齐——
|
|
42
|
-
* 1.
|
|
43
|
-
*
|
|
48
|
+
* 1. 块数可以因为空行漂移不等(模型吞空行、多空行都由重排消化),但**非空行
|
|
49
|
+
* 一条都不能少**:少了就是正文被吞了一段(弱模型会把开头那段当整段交差,
|
|
50
|
+
* 后面几段一个字都不写),带 missingContent 交回调用方重掷。多出来的行
|
|
51
|
+
* 按非空行签名 1:1 对齐后重排。
|
|
44
52
|
* 2. 块内**结构行**逐一对齐(记号类别、表格竖线数、链接个数、缩进代码的
|
|
45
53
|
* 缩进),行首前缀修回原文同款:`##`→`###`、`-`→`*`、序号、引用深度、
|
|
46
54
|
* 列表缩进的漂移就此消失。
|
|
@@ -2,7 +2,7 @@
|
|
|
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 = "r7";
|
|
6
6
|
/**
|
|
7
7
|
* Cache generation for the prompt currently in force.
|
|
8
8
|
*
|
package/package.json
CHANGED