@lynn123411/dsh-chat-translate 1.3.0 → 1.3.2
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 +2 -2
- package/lib/client.js +18 -0
- package/lib/client.js.map +3 -3
- package/lib/index.js +146 -52
- package/lib/index.js.map +4 -4
- package/lib/types/server/pipeline/mask-tokens.d.ts +76 -0
- package/lib/types/server/pipeline/masking.d.ts +20 -0
- package/package.json +2 -3
- package/LICENSE +0 -21
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mask placeholder tokens — single source of truth for the wire format, the
|
|
3
|
+
* tolerant matcher and the leftover detector.
|
|
4
|
+
*
|
|
5
|
+
* Wire format: `__DSHMASKx<letters>_<index>__` (e.g. `__DSHMASKxkbdt_3__`).
|
|
6
|
+
*
|
|
7
|
+
* Design constraints, each one a measured failure of the previous
|
|
8
|
+
* `__DSH_MASK_<index>__` format against real MT engines:
|
|
9
|
+
*
|
|
10
|
+
* - No underscore between `DSH` and `MASK`. Small models routinely drop that
|
|
11
|
+
* one separator (`__DSH_MASK_1__` -> `__DSHMASK_1__`), which defeated the
|
|
12
|
+
* old strict unmask regex and leaked the raw token into the UI.
|
|
13
|
+
* - A random letter run (`x<letters>`) makes the token collision-free against
|
|
14
|
+
* the source text and unambiguous to parse: the index is the digit run after
|
|
15
|
+
* the last `_`, so no lookbehind is needed.
|
|
16
|
+
* - The leading/trailing `__` stay: they survive MT and mark the token as
|
|
17
|
+
* emphasis to the model.
|
|
18
|
+
*
|
|
19
|
+
* `matchMaskToken` stays tolerant of the *legacy* format and of the spacing /
|
|
20
|
+
* casing / separator damage observed in the wild, because poisoned translations
|
|
21
|
+
* already sit in the on-disk and browser caches.
|
|
22
|
+
*/
|
|
23
|
+
export declare function randomTokenId(): string;
|
|
24
|
+
export interface MaskTokenFormat {
|
|
25
|
+
/** Unique per `mask()` call; embedded in every token of that call. */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Build the placeholder written into the text sent to the translator. */
|
|
28
|
+
token: (index: number) => string;
|
|
29
|
+
}
|
|
30
|
+
export declare function createMaskTokenFormat(): MaskTokenFormat;
|
|
31
|
+
/**
|
|
32
|
+
* Loose matcher covering every observed engine rewrite:
|
|
33
|
+
*
|
|
34
|
+
* __DSHMASKxkbdt_3__ exact
|
|
35
|
+
* __DSHMASKXKBDT_3__ case folded
|
|
36
|
+
* __DSH MASK xkbdt _ 3__ spaces inserted around the structural underscores
|
|
37
|
+
* __DSHMASKkbdt_3__ the `x` id separator eaten
|
|
38
|
+
* _DSHMASKxkbdt_3_ one boundary underscore dropped
|
|
39
|
+
* __DSH_MASK_3__ / __dsh_mask_3__ legacy format (no random id)
|
|
40
|
+
*
|
|
41
|
+
* Both boundaries and the internal separators are optional, and the `x` id
|
|
42
|
+
* separator may be replaced by whitespace/dot/hyphen. The two index branches
|
|
43
|
+
* stay unambiguous: an id is always a letter run, the index always digits.
|
|
44
|
+
* Capture groups: `[1] = legacy index` (undefined for the current format),
|
|
45
|
+
* `[2] = token id` (undefined for the legacy format), `[3] = current index`.
|
|
46
|
+
*/
|
|
47
|
+
export declare const MASK_TOKEN_PATTERN_SOURCE = "_*\\s*DSH\\s*_*\\s*MASK\\s*(?:_?\\s*(\\d+)|_*[xX]?[\\s._-]*([a-z]{2,8})\\s*_+\\s*(\\d+))(?:_{0,2}(?=[^\\w]|$))?";
|
|
48
|
+
export interface MaskTokenMatch {
|
|
49
|
+
index: number;
|
|
50
|
+
/** false when the token carried an id from a different `mask()` call. */
|
|
51
|
+
acceptsId: boolean;
|
|
52
|
+
/** Length of the matched token in characters. */
|
|
53
|
+
length: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Match a single mask token at `start` in `text`.
|
|
57
|
+
*
|
|
58
|
+
* `acceptsId` is false when the token's random id belongs to another masking
|
|
59
|
+
* pass — the caller must then leave the token untouched, because its index
|
|
60
|
+
* would resolve to unrelated content.
|
|
61
|
+
*/
|
|
62
|
+
export declare function matchMaskToken(text: string, start: number, id: string): MaskTokenMatch | null;
|
|
63
|
+
/** True when translated text still carries a mask token of any format. */
|
|
64
|
+
export declare function hasMaskResidue(text: string): boolean;
|
|
65
|
+
/** Every mask-token-looking fragment in `text`, verbatim. */
|
|
66
|
+
export declare function maskResidues(text: string): string[];
|
|
67
|
+
/**
|
|
68
|
+
* True when `translatedText` exposes a mask token that was NOT already part of
|
|
69
|
+
* `originalText`.
|
|
70
|
+
*
|
|
71
|
+
* A placeholder surviving the round trip is a leak; but a source text that
|
|
72
|
+
* legitimately talks *about* placeholders (this plugin's own documentation,
|
|
73
|
+
* say) must survive translation, so tokens the source already carried are not
|
|
74
|
+
* treated as residue.
|
|
75
|
+
*/
|
|
76
|
+
export declare function hasNewMaskResidue(originalText: string, translatedText: string): boolean;
|
|
@@ -5,3 +5,23 @@ export interface MaskResult {
|
|
|
5
5
|
export declare class ContentMaskingPipeline {
|
|
6
6
|
mask(text: string): MaskResult;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolve every in-range mask token in `text` through `resolve`.
|
|
10
|
+
*
|
|
11
|
+
* A token whose random id belongs to another masking pass, an out-of-range
|
|
12
|
+
* index and any unmatched text are all kept verbatim; `hasMaskResidue()` on the
|
|
13
|
+
* result is what flags a leaked token.
|
|
14
|
+
*/
|
|
15
|
+
export declare function replaceMaskTokens(text: string, id: string, resolve: (index: number) => string | undefined): string;
|
|
16
|
+
/**
|
|
17
|
+
* True when a translated string would still show a mask token to the user.
|
|
18
|
+
* Callers use it to discard a poisoned translation (and to evict poisoned
|
|
19
|
+
* cache entries written by earlier releases).
|
|
20
|
+
*/
|
|
21
|
+
export declare function isMaskLeak(translatedText: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Same as `isMaskLeak`, but a token the source text already contained is not a
|
|
24
|
+
* leak: text that talks about placeholders (this plugin's docs, a bug report)
|
|
25
|
+
* must round-trip untouched.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isMaskLeakAgainst(originalText: string, translatedText: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynn123411/dsh-chat-translate",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Tool-call & think-summary translation with dual AI (OpenAI-compatible) + Bing channels for the DeepSeek Harness Web UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "lynn123411",
|
|
@@ -54,8 +54,7 @@
|
|
|
54
54
|
"lib",
|
|
55
55
|
"docs",
|
|
56
56
|
"cordis.patch.yml",
|
|
57
|
-
"README.md"
|
|
58
|
-
"LICENSE"
|
|
57
|
+
"README.md"
|
|
59
58
|
],
|
|
60
59
|
"scripts": {
|
|
61
60
|
"build": "node build.mjs",
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 ChuanTianML
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|