@openviking/openclaw-plugin 2026.5.26 → 2026.6.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/INSTALL-AGENT.md +355 -355
- package/INSTALL-ZH.md +345 -345
- package/INSTALL.md +362 -362
- package/README.md +354 -338
- package/auto-recall.ts +287 -257
- package/client.ts +939 -939
- package/commands/setup.ts +1002 -1002
- package/config.ts +476 -476
- package/context-engine.ts +1739 -1737
- package/dist/auto-recall.js +27 -7
- package/dist/client.js +2 -2
- package/dist/context-engine.js +4 -8
- package/dist/index.js +21 -2
- package/dist/process-manager.js +5 -17
- package/dist/token-estimator.js +51 -0
- package/index.ts +2010 -1985
- package/install-manifest.json +48 -47
- package/memory-ranking.ts +267 -267
- package/openclaw.plugin.json +335 -335
- package/package.json +76 -76
- package/process-manager.ts +41 -45
- package/runtime-utils.ts +5 -5
- package/session-transcript-repair.ts +530 -530
- package/skills/install-openviking-memory/SKILL.md +679 -665
- package/text-utils.ts +507 -507
- package/token-estimator.ts +65 -0
- package/tool-call-id.ts +331 -331
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
type TokenCountableAgentMessage = {
|
|
2
|
+
role?: string;
|
|
3
|
+
content?: unknown;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
function isCjkCodePoint(codePoint: number): boolean {
|
|
7
|
+
return (
|
|
8
|
+
(codePoint >= 0x3400 && codePoint <= 0x4dbf) ||
|
|
9
|
+
(codePoint >= 0x4e00 && codePoint <= 0x9fff) ||
|
|
10
|
+
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
11
|
+
(codePoint >= 0x20000 && codePoint <= 0x2ebef) ||
|
|
12
|
+
(codePoint >= 0x3040 && codePoint <= 0x30ff) ||
|
|
13
|
+
(codePoint >= 0x31f0 && codePoint <= 0x31ff) ||
|
|
14
|
+
(codePoint >= 0xac00 && codePoint <= 0xd7af) ||
|
|
15
|
+
(codePoint >= 0x1100 && codePoint <= 0x11ff) ||
|
|
16
|
+
(codePoint >= 0x3130 && codePoint <= 0x318f) ||
|
|
17
|
+
(codePoint >= 0xff00 && codePoint <= 0xffef) ||
|
|
18
|
+
(codePoint >= 0x3000 && codePoint <= 0x303f)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function codePointWeight(codePoint: number): number {
|
|
23
|
+
if (isCjkCodePoint(codePoint)) {
|
|
24
|
+
return 1.5;
|
|
25
|
+
}
|
|
26
|
+
if (codePoint > 0xffff) {
|
|
27
|
+
return 2;
|
|
28
|
+
}
|
|
29
|
+
return 0.25;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function estimateTextTokens(text: string | null | undefined): number {
|
|
33
|
+
if (!text) {
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let weightedTokens = 0;
|
|
38
|
+
for (const char of text) {
|
|
39
|
+
weightedTokens += codePointWeight(char.codePointAt(0) ?? 0);
|
|
40
|
+
}
|
|
41
|
+
return Math.ceil(weightedTokens);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function estimateSerializedTokens(value: unknown): number {
|
|
45
|
+
if (value === null || value === undefined) {
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === "string") {
|
|
49
|
+
return estimateTextTokens(value);
|
|
50
|
+
}
|
|
51
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
52
|
+
return estimateTextTokens(String(value));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const serialized = JSON.stringify(value);
|
|
56
|
+
return estimateTextTokens(serialized ?? "");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function estimateAgentMessageTokens(message: TokenCountableAgentMessage): number {
|
|
60
|
+
return estimateSerializedTokens(message);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function estimateAgentMessagesTokens(messages: TokenCountableAgentMessage[]): number {
|
|
64
|
+
return estimateSerializedTokens(messages);
|
|
65
|
+
}
|