dsh-plugin-term-dictionary 0.0.0-stage → 1.1.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/CHANGELOG.md +189 -0
- package/LICENSE +21 -0
- package/README.md +776 -2
- package/cordis.patch.yml +14 -0
- package/icon.svg +13 -0
- package/lib/ROADMAP-lexicon.md +52 -0
- package/lib/client.js +13354 -0
- package/lib/core/api.js +278 -0
- package/lib/core/bus.js +98 -0
- package/lib/core/copy.js +614 -0
- package/lib/core/core.js +309 -0
- package/lib/core/dictionary.js +1187 -0
- package/lib/core/entries.js +454 -0
- package/lib/core/highlight.js +282 -0
- package/lib/core/hover.js +470 -0
- package/lib/core/hovercard.js +173 -0
- package/lib/core/interact.js +1802 -0
- package/lib/core/lexicon.en.js +872 -0
- package/lib/core/lexicon.zh.js +249 -0
- package/lib/core/overlay.js +239 -0
- package/lib/core/pack.js +372 -0
- package/lib/core/package.json +4 -0
- package/lib/core/selection.js +83 -0
- package/lib/core/settings.js +366 -0
- package/lib/core/shell.js +1003 -0
- package/lib/core/stopwords.js +147 -0
- package/lib/core/store.js +397 -0
- package/lib/core/styles.js +574 -0
- package/lib/core/terms.js +398 -0
- package/lib/core/transfer.js +382 -0
- package/lib/core/views.js +2428 -0
- package/lib/index.js +1110 -0
- package/lib/pack-code.js +84 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +71 -3
package/lib/pack-code.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Share codes: a pack as one pasteable string.
|
|
3
|
+
*
|
|
4
|
+
* Host side only, and deliberately so. Deflate and a hash need `node:zlib` and `node:crypto`; the page
|
|
5
|
+
* has neither, and a second implementation in the browser (`CompressionStream`) would be a second
|
|
6
|
+
* thing to keep in step with this one. The page therefore asks its own host to encode and decode, over
|
|
7
|
+
* routes that already exist for exactly this kind of request.
|
|
8
|
+
*
|
|
9
|
+
* The wire format is `dshpack1:<base64url of the raw-deflate of the pack's JSON>`, with the prefix
|
|
10
|
+
* defined in `core/pack.js` because the panel checks it before anything is sent and this module checks
|
|
11
|
+
* it before anything is decompressed.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
import { createRequire } from "node:module";
|
|
16
|
+
import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
17
|
+
|
|
18
|
+
const require = createRequire(import.meta.url);
|
|
19
|
+
const pack = require("./core/pack.js");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* How much a share code may decompress to.
|
|
23
|
+
*
|
|
24
|
+
* A cap, not a nicety: deflate turns a few kilobytes of zeroes into a few bytes, so without one a
|
|
25
|
+
* pasted string from a stranger is a memory exhaustion attack on the app that pastes it.
|
|
26
|
+
*/
|
|
27
|
+
const MAX_INFLATED_BYTES = 4 * 1024 * 1024;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The SHA-256 of some bytes, lowercase hex.
|
|
31
|
+
* @param bytes - a string or a buffer.
|
|
32
|
+
* @returns the digest.
|
|
33
|
+
*/
|
|
34
|
+
export function sha256Hex(bytes) {
|
|
35
|
+
return createHash("sha256").update(typeof bytes === "string" ? Buffer.from(bytes, "utf8") : bytes).digest("hex");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Turn a pack into a share code.
|
|
40
|
+
* @param value - a built or parsed pack.
|
|
41
|
+
* @returns the code.
|
|
42
|
+
*/
|
|
43
|
+
export function encodePackCode(value) {
|
|
44
|
+
const deflated = deflateRawSync(Buffer.from(pack.packBytes(value), "utf8"), { level: 9 });
|
|
45
|
+
return `${pack.PACK_CODE_PREFIX}${deflated.toString("base64url")}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Turn a share code back into a pack.
|
|
50
|
+
*
|
|
51
|
+
* Whitespace is stripped before anything else: a code is long, and every real path it travels — a chat
|
|
52
|
+
* message, a terminal, a text editor — eventually wraps it. The failures are told apart because they
|
|
53
|
+
* send the user to different places: `not-a-code` means this is not a share code at all, `corrupt`
|
|
54
|
+
* means the paste lost or mangled characters, `too-large` means the payload exceeded the cap.
|
|
55
|
+
*
|
|
56
|
+
* @param code - the pasted string.
|
|
57
|
+
* @returns `{ ok: true, pack }`, or `{ ok: false, error }`.
|
|
58
|
+
*/
|
|
59
|
+
export function decodePackCode(code) {
|
|
60
|
+
if (typeof code !== "string") return { ok: false, error: "not-a-code" };
|
|
61
|
+
const trimmed = code.replace(/\s+/g, "");
|
|
62
|
+
if (!trimmed.startsWith(pack.PACK_CODE_PREFIX)) return { ok: false, error: "not-a-code" };
|
|
63
|
+
const body = trimmed.slice(pack.PACK_CODE_PREFIX.length);
|
|
64
|
+
if (body === "") return { ok: false, error: "empty-code" };
|
|
65
|
+
let inflated;
|
|
66
|
+
try {
|
|
67
|
+
inflated = inflateRawSync(Buffer.from(body, "base64url"), { maxOutputLength: MAX_INFLATED_BYTES });
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const code = String(error?.code ?? "");
|
|
70
|
+
return { ok: false, error: code === "ERR_BUFFER_TOO_LARGE" || code.includes("maxOutputLength") ? "too-large" : "corrupt" };
|
|
71
|
+
}
|
|
72
|
+
let raw;
|
|
73
|
+
try {
|
|
74
|
+
raw = JSON.parse(inflated.toString("utf8"));
|
|
75
|
+
} catch (error) {
|
|
76
|
+
void error;
|
|
77
|
+
return { ok: false, error: "corrupt" };
|
|
78
|
+
}
|
|
79
|
+
// The pack's own validation, not a second one: a code and a fetched file must be judged by the same
|
|
80
|
+
// rules, or one of the two paths becomes the way around them.
|
|
81
|
+
return pack.parsePack(raw);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { MAX_INFLATED_BYTES };
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Term Dictionary",
|
|
4
|
+
"description": "Detects rare jargon in agent replies and keeps a dictionary of entries, with a panel in the left sidebar. Collected terms are marked in the transcript: hover for a brief explanation, click to open the entry, or select a phrase to add it."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-term-dictionary",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "术语词典:自动识别对话中的生僻术语并建立词条,左侧插件区提供词典面板。已收录的词在回复中被划出,鼠标靠近显示简短解释,点击进入词典对应词条;选中词句可一键添加词条。",
|
|
5
|
+
"icon": "./icon.svg",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"deepseek",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"dsh",
|
|
10
|
+
"dsh-plugin",
|
|
11
|
+
"dictionary",
|
|
12
|
+
"glossary",
|
|
13
|
+
"terminology",
|
|
14
|
+
"术语",
|
|
15
|
+
"词典"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"default": "./lib/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"default": "./lib/client.js"
|
|
25
|
+
},
|
|
26
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
27
|
+
"./locale/*.json": "./locale/*.json",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"lib/index.js",
|
|
32
|
+
"lib/client.js",
|
|
33
|
+
"lib/pack-code.js",
|
|
34
|
+
"lib/core/*.js",
|
|
35
|
+
"lib/core/package.json",
|
|
36
|
+
"lib/ROADMAP-lexicon.md",
|
|
37
|
+
"cordis.patch.yml",
|
|
38
|
+
"locale/*.json",
|
|
39
|
+
"icon.svg",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/lakerian/dsh-plugin-term-dictionary.git"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/lakerian/dsh-plugin-term-dictionary/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/lakerian/dsh-plugin-term-dictionary#readme",
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^22.19.0 || >=24.0.0",
|
|
55
|
+
"dsh": ">=0.2.0-rc.2"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"dsh": {
|
|
61
|
+
"bundle": {
|
|
62
|
+
"patch": "./cordis.patch.yml"
|
|
63
|
+
},
|
|
64
|
+
"client": {
|
|
65
|
+
"platform": "web",
|
|
66
|
+
"inject": [
|
|
67
|
+
"slots",
|
|
68
|
+
"locale",
|
|
69
|
+
"layout"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"scripts": {}
|
|
6
74
|
}
|