llmz 0.0.11 → 0.0.12
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/dist/chat.d.ts +17 -0
- package/dist/chunk-276Q6EWP.cjs +224 -0
- package/dist/chunk-4L6D2A6O.cjs +283 -0
- package/dist/chunk-4MNIJGK6.js +224 -0
- package/dist/chunk-7WRN4E42.js +3087 -0
- package/dist/chunk-BEPRLBPK.cjs +3123 -0
- package/dist/chunk-C6WNNTEV.cjs +212 -0
- package/dist/chunk-D3ESDRLH.js +3123 -0
- package/dist/chunk-GGWM6X2K.js +184 -0
- package/dist/chunk-GWFYZDUR.cjs +105 -0
- package/dist/chunk-HJKOSEH2.cjs +722 -0
- package/dist/chunk-IH2WQFO5.js +283 -0
- package/dist/chunk-IKSIOIIP.cjs +28 -0
- package/dist/chunk-JAGB2AOU.js +212 -0
- package/dist/chunk-JDABP4SD.cjs +161 -0
- package/dist/chunk-JGVAZO4X.cjs +152 -0
- package/dist/chunk-JKVVQN2P.js +161 -0
- package/dist/chunk-JMSZKB4T.js +105 -0
- package/dist/chunk-JQBT7UWN.js +28 -0
- package/dist/chunk-KH6JQYQA.js +796 -0
- package/dist/chunk-KMZDFWYZ.cjs +33 -0
- package/dist/chunk-ORQP26SZ.js +33 -0
- package/dist/chunk-PRVFVXT4.js +722 -0
- package/dist/chunk-SHJDRZF5.cjs +796 -0
- package/dist/chunk-SNDVQU5A.js +152 -0
- package/dist/chunk-UQOBUJIQ.cjs +3087 -0
- package/dist/chunk-ZRCU35UV.cjs +184 -0
- package/dist/citations.d.ts +63 -0
- package/dist/compiler/compiler.d.ts +28 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/plugins/async-iterator.d.ts +4 -0
- package/dist/compiler/plugins/braces-tsx.d.ts +3 -0
- package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +5 -0
- package/dist/compiler/plugins/line-tracking.d.ts +5 -0
- package/dist/compiler/plugins/replace-comment.d.ts +5 -0
- package/dist/compiler/plugins/return-async.d.ts +4 -0
- package/dist/compiler/plugins/track-tool-calls.d.ts +16 -0
- package/dist/compiler/plugins/variable-extraction.d.ts +5 -0
- package/dist/component-R4WTW6DZ.cjs +18 -0
- package/dist/component-WFVDVSDK.js +18 -0
- package/dist/component.d.ts +66 -0
- package/dist/component.default.d.ts +316 -0
- package/dist/context.d.ts +176 -0
- package/dist/dual-modes-T53P72CH.js +12 -0
- package/dist/dual-modes-VLIGPIHX.cjs +12 -0
- package/dist/errors.d.ts +64 -0
- package/dist/exit-TRXEU4OU.cjs +8 -0
- package/dist/exit-YORW76T3.js +8 -0
- package/dist/exit.d.ts +26 -0
- package/dist/formatting.d.ts +5 -0
- package/dist/getter.d.ts +2 -0
- package/dist/handlers.d.ts +10 -0
- package/dist/hoist.d.ts +2 -0
- package/dist/index.cjs +921 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +921 -0
- package/dist/inspect.d.ts +6 -0
- package/dist/jsx-AEHVFB3L.js +13 -0
- package/dist/jsx-AJAXBWFE.cjs +13 -0
- package/dist/jsx.d.ts +11 -0
- package/dist/llmz-QLZBDG2Z.cjs +576 -0
- package/dist/llmz-ROOX7RYI.js +576 -0
- package/dist/llmz.d.ts +40 -0
- package/dist/objects.d.ts +24 -0
- package/dist/prompts/chat-mode/system.md.d.ts +2 -0
- package/dist/prompts/chat-mode/user.md.d.ts +2 -0
- package/dist/prompts/common.d.ts +6 -0
- package/dist/prompts/dual-modes.d.ts +2 -0
- package/dist/prompts/prompt.d.ts +55 -0
- package/dist/prompts/worker-mode/system.md.d.ts +2 -0
- package/dist/prompts/worker-mode/user.md.d.ts +2 -0
- package/dist/result.d.ts +33 -0
- package/dist/snapshots.d.ts +69 -0
- package/dist/stack-traces.d.ts +1 -0
- package/dist/tool-N6ODRRGH.js +11 -0
- package/dist/tool-QP4MVRWI.cjs +11 -0
- package/dist/tool.d.ts +56 -0
- package/dist/transcript.d.ts +36 -0
- package/dist/truncator-DUMWEGQO.cjs +10 -0
- package/dist/truncator-IY2MXOMC.js +10 -0
- package/dist/truncator.d.ts +20 -0
- package/dist/types.d.ts +105 -0
- package/dist/typings-2CPHOFDN.cjs +10 -0
- package/dist/typings-GDMY6VY2.js +10 -0
- package/dist/typings.d.ts +5 -0
- package/dist/utils-A7WNEFTA.cjs +39 -0
- package/dist/utils-N24IHDFA.js +39 -0
- package/dist/utils.d.ts +23 -0
- package/dist/vm-2DLG7V4G.cjs +12 -0
- package/dist/vm-FLBMZUA2.js +12 -0
- package/dist/vm.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTokenizer
|
|
3
|
+
} from "./chunk-4MNIJGK6.js";
|
|
4
|
+
|
|
5
|
+
// src/truncator.ts
|
|
6
|
+
var DEFAULT_REMOVE_CHUNK = 250;
|
|
7
|
+
var WRAP_OPEN_TAG_1 = "\u3010TRUNCATE";
|
|
8
|
+
var WRAP_OPEN_TAG_2 = "\u3011";
|
|
9
|
+
var WRAP_CLOSE_TAG = "\u3010/TRUNCATE\u3011";
|
|
10
|
+
var getRegex = () => new RegExp(`(${WRAP_OPEN_TAG_1}(?:\\s+[\\w:]+)*\\s*${WRAP_OPEN_TAG_2})([\\s\\S]*?)(${WRAP_CLOSE_TAG})`, "g");
|
|
11
|
+
var DEFAULT_TRUNCATE_OPTIONS = {
|
|
12
|
+
preserve: "top",
|
|
13
|
+
flex: 1,
|
|
14
|
+
minTokens: 0
|
|
15
|
+
};
|
|
16
|
+
function wrapContent(content, options) {
|
|
17
|
+
const preserve = (options == null ? void 0 : options.preserve) ?? DEFAULT_TRUNCATE_OPTIONS.preserve;
|
|
18
|
+
const flex = (options == null ? void 0 : options.flex) ?? DEFAULT_TRUNCATE_OPTIONS.flex;
|
|
19
|
+
const minTokens = (options == null ? void 0 : options.minTokens) ?? DEFAULT_TRUNCATE_OPTIONS.minTokens;
|
|
20
|
+
return `${WRAP_OPEN_TAG_1} preserve:${preserve} flex:${flex} min:${minTokens} ${WRAP_OPEN_TAG_2}${content}${WRAP_CLOSE_TAG}`;
|
|
21
|
+
}
|
|
22
|
+
function truncateWrappedContent({
|
|
23
|
+
messages,
|
|
24
|
+
tokenLimit,
|
|
25
|
+
throwOnFailure = true
|
|
26
|
+
}) {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
const tokenizer = getTokenizer();
|
|
29
|
+
const parts = [];
|
|
30
|
+
for (const msg of messages) {
|
|
31
|
+
const current = [];
|
|
32
|
+
const content = typeof msg.content === "string" ? msg.content : "";
|
|
33
|
+
let match;
|
|
34
|
+
const regex = getRegex();
|
|
35
|
+
let lastIndex = 0;
|
|
36
|
+
while ((match = regex.exec(content)) !== null) {
|
|
37
|
+
const attributes = match[1].split(/\s+/).slice(1).filter((x) => x !== WRAP_OPEN_TAG_2).map((x) => x.split(":")).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
38
|
+
if (match.index > lastIndex) {
|
|
39
|
+
const nonTruncatableContent = content.slice(lastIndex, match.index);
|
|
40
|
+
current.push({
|
|
41
|
+
content: nonTruncatableContent,
|
|
42
|
+
tokens: tokenizer.count(nonTruncatableContent),
|
|
43
|
+
truncatable: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const wrappedContent = match[2];
|
|
47
|
+
current.push({
|
|
48
|
+
content: wrappedContent,
|
|
49
|
+
tokens: tokenizer.count(wrappedContent),
|
|
50
|
+
truncatable: true,
|
|
51
|
+
attributes: {
|
|
52
|
+
preserve: attributes.preserve,
|
|
53
|
+
flex: Number(attributes.flex) || DEFAULT_TRUNCATE_OPTIONS.flex,
|
|
54
|
+
minTokens: Number(attributes.min) || DEFAULT_TRUNCATE_OPTIONS.minTokens
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
lastIndex = regex.lastIndex;
|
|
58
|
+
}
|
|
59
|
+
if (lastIndex < content.length) {
|
|
60
|
+
const remainingContent = content.slice(lastIndex);
|
|
61
|
+
current.push({
|
|
62
|
+
content: remainingContent,
|
|
63
|
+
tokens: tokenizer.count(remainingContent),
|
|
64
|
+
truncatable: false
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
parts.push(current);
|
|
68
|
+
}
|
|
69
|
+
const getCount = () => parts.reduce((acc, x) => acc + x.reduce((acc2, y) => acc2 + y.tokens, 0), 0);
|
|
70
|
+
const getTwoBiggestTruncatables = () => {
|
|
71
|
+
var _a2, _b2;
|
|
72
|
+
let biggest = null;
|
|
73
|
+
let secondBiggest = null;
|
|
74
|
+
for (const part of parts.flat()) {
|
|
75
|
+
if (part.truncatable) {
|
|
76
|
+
const flex = ((_a2 = part.attributes) == null ? void 0 : _a2.flex) ?? DEFAULT_TRUNCATE_OPTIONS.flex;
|
|
77
|
+
const tokens = part.tokens * flex;
|
|
78
|
+
if (part.tokens <= (((_b2 = part.attributes) == null ? void 0 : _b2.minTokens) ?? 0)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!biggest || tokens > biggest.tokens) {
|
|
82
|
+
secondBiggest = biggest;
|
|
83
|
+
biggest = part;
|
|
84
|
+
} else if (!secondBiggest || tokens > secondBiggest.tokens) {
|
|
85
|
+
secondBiggest = part;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { biggest, secondBiggest };
|
|
90
|
+
};
|
|
91
|
+
let currentCount = getCount();
|
|
92
|
+
while (currentCount > tokenLimit) {
|
|
93
|
+
const { biggest, secondBiggest } = getTwoBiggestTruncatables();
|
|
94
|
+
if (!biggest || !biggest.truncatable || biggest.tokens <= 0) {
|
|
95
|
+
if (throwOnFailure) {
|
|
96
|
+
throw new Error(`Cannot truncate further, current count: ${getCount()}`);
|
|
97
|
+
} else {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const delta = Math.max(biggest.tokens - ((secondBiggest == null ? void 0 : secondBiggest.tokens) ?? 0), DEFAULT_REMOVE_CHUNK);
|
|
102
|
+
const room = Math.min(delta, biggest.tokens);
|
|
103
|
+
let toRemove = Math.min(room, currentCount - tokenLimit);
|
|
104
|
+
if (toRemove <= 0) {
|
|
105
|
+
if (throwOnFailure) {
|
|
106
|
+
throw new Error(`Cannot truncate further, current count: ${getCount()}`);
|
|
107
|
+
} else {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (biggest.tokens - toRemove < (((_a = biggest.attributes) == null ? void 0 : _a.minTokens) ?? 0)) {
|
|
112
|
+
toRemove = biggest.tokens - (((_b = biggest.attributes) == null ? void 0 : _b.minTokens) ?? 0);
|
|
113
|
+
}
|
|
114
|
+
const preserve = ((_c = biggest.attributes) == null ? void 0 : _c.preserve) ?? DEFAULT_TRUNCATE_OPTIONS.preserve;
|
|
115
|
+
const split = tokenizer.split(biggest.content);
|
|
116
|
+
if (preserve === "bottom") {
|
|
117
|
+
biggest.content = split.slice(toRemove).join("");
|
|
118
|
+
} else if (preserve === "top") {
|
|
119
|
+
biggest.content = split.slice(0, -toRemove).join("");
|
|
120
|
+
} else {
|
|
121
|
+
const anchor = Math.ceil(split.length / 2);
|
|
122
|
+
const radius = Math.ceil(toRemove / 2);
|
|
123
|
+
const left = anchor - radius;
|
|
124
|
+
const right = anchor + radius;
|
|
125
|
+
biggest.content = split.slice(0, left).join("") + split.slice(right).join("");
|
|
126
|
+
}
|
|
127
|
+
biggest.tokens -= toRemove;
|
|
128
|
+
currentCount -= toRemove;
|
|
129
|
+
}
|
|
130
|
+
const removeRedundantWrappers = (content) => {
|
|
131
|
+
return content.replace(getRegex(), "$2");
|
|
132
|
+
};
|
|
133
|
+
return messages.map((msg, i) => {
|
|
134
|
+
const p = parts[i];
|
|
135
|
+
return {
|
|
136
|
+
...msg,
|
|
137
|
+
content: typeof msg.content === "string" ? removeRedundantWrappers(
|
|
138
|
+
p.map((part) => {
|
|
139
|
+
if (part.truncatable) {
|
|
140
|
+
return part.content;
|
|
141
|
+
}
|
|
142
|
+
return part.content;
|
|
143
|
+
}).join("")
|
|
144
|
+
) : msg.content
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export {
|
|
150
|
+
wrapContent,
|
|
151
|
+
truncateWrappedContent
|
|
152
|
+
};
|