agentgui 1.0.685 → 1.0.686
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/package.json +1 -1
- package/static/js/codec.js +1 -46
package/package.json
CHANGED
package/static/js/codec.js
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side codec — mirrors lib/codec.js exactly.
|
|
3
|
-
* msgpackr (global from msgpackr.min.js) + GPT tokenizer BPE compression.
|
|
4
|
-
*/
|
|
5
|
-
import { encode as tokEncode, decode as tokDecode } from 'https://esm.sh/gpt-tokenizer';
|
|
6
|
-
|
|
7
|
-
const THRESHOLD = 200;
|
|
8
|
-
const COMPRESSIBLE = new Set(['content', 'text', 'output', 'response', 'prompt', 'input', 'data']);
|
|
9
|
-
|
|
10
|
-
function compressText(str) {
|
|
11
|
-
return { __tok: true, d: tokEncode(str) };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function decompressText(val) {
|
|
15
|
-
return tokDecode(val.d);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function encodeObj(obj) {
|
|
19
|
-
if (!obj || typeof obj !== 'object') return obj;
|
|
20
|
-
if (Array.isArray(obj)) return obj.map(encodeObj);
|
|
21
|
-
const out = {};
|
|
22
|
-
for (const k of Object.keys(obj)) {
|
|
23
|
-
const v = obj[k];
|
|
24
|
-
if (COMPRESSIBLE.has(k) && typeof v === 'string' && v.length > THRESHOLD) {
|
|
25
|
-
out[k] = compressText(v);
|
|
26
|
-
} else if (v && typeof v === 'object' && !(v instanceof ArrayBuffer) && !ArrayBuffer.isView(v)) {
|
|
27
|
-
out[k] = encodeObj(v);
|
|
28
|
-
} else {
|
|
29
|
-
out[k] = v;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return out;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function decodeObj(obj) {
|
|
36
|
-
if (!obj || typeof obj !== 'object') return obj;
|
|
37
|
-
if (Array.isArray(obj)) return obj.map(decodeObj);
|
|
38
|
-
if (obj.__tok && obj.d) return decompressText(obj);
|
|
39
|
-
const out = {};
|
|
40
|
-
for (const k of Object.keys(obj)) {
|
|
41
|
-
out[k] = decodeObj(obj[k]);
|
|
42
|
-
}
|
|
43
|
-
return out;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
1
|
export function encode(obj) { return msgpackr.pack(obj); }
|
|
47
|
-
export function decode(buf) { return
|
|
2
|
+
export function decode(buf) { return msgpackr.unpack(new Uint8Array(buf instanceof ArrayBuffer ? buf : buf)); }
|