llmz 0.6.0 → 0.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/DOCS.md +1 -3
- package/dist/_baseForOwn-CFhWe_W6.js +48 -0
- package/dist/_baseForOwn-buOZDFbK.cjs +103 -0
- package/dist/_baseIteratee-CF4qP2a8.cjs +2377 -0
- package/dist/_baseIteratee-P_firB7b.js +2138 -0
- package/dist/_getPrototype-CG7Dxrrz.js +6 -0
- package/dist/_getPrototype-DQDlNVVM.cjs +10 -0
- package/dist/_overArg-C5Hy7oCi.cjs +196 -0
- package/dist/_overArg-CRYbj1NH.js +155 -0
- package/dist/citations.d.ts +11 -11
- package/dist/component-BwixNVH8.cjs +73 -0
- package/dist/component-DGG7d_Mz.js +44 -0
- package/dist/context.d.ts +8 -8
- package/dist/custom-client-BPmEoWKu.cjs +2618 -0
- package/dist/custom-client-NUoxrFQh.js +2547 -0
- package/dist/dual-modes-D_p-jedw.js +2750 -0
- package/dist/dual-modes-wAOAlaBS.cjs +2840 -0
- package/dist/errors-C962uJdS.cjs +220 -0
- package/dist/errors-Cg1G0Awu.js +161 -0
- package/dist/execute-BEaq3jkV.cjs +1003 -0
- package/dist/execute-DYvFRs54.js +1001 -0
- package/dist/exit-BGi0Kk0y.cjs +428 -0
- package/dist/exit-CDdxDBRT.js +417 -0
- package/dist/index.cjs +1786 -1489
- package/dist/index.d.ts +10 -9
- package/dist/index.js +1721 -1479
- package/dist/index.workerd.js +17534 -16875
- package/dist/isEmpty-BhJRCqIF.js +52 -0
- package/dist/isEmpty-LY533Wmh.cjs +57 -0
- package/dist/isPlainObject-CSxXVKCk.cjs +56 -0
- package/dist/isPlainObject-D39AzPO2.js +51 -0
- package/dist/jsx-BWvT6ukg.cjs +75 -0
- package/dist/jsx-CIgdGGVs.js +52 -0
- package/dist/jsx.d.ts +2 -2
- package/dist/prompts/chat-mode/system.md.d.ts +1 -1
- package/dist/prompts/chat-mode/user.md.d.ts +1 -1
- package/dist/prompts/worker-mode/system.md.d.ts +1 -1
- package/dist/prompts/worker-mode/user.md.d.ts +1 -1
- package/dist/quickjs-variant-BYhMBpwU.js +45 -0
- package/dist/quickjs-variant-CsIwTVFC.cjs +56 -0
- package/dist/quickjs-variant.workerd.d.ts +1 -1
- package/dist/result.d.ts +12 -12
- package/dist/rolldown-runtime-EAsCxrDo.js +14 -0
- package/dist/runtime/interpret-result.d.ts +1 -1
- package/dist/snapshots.d.ts +5 -5
- package/dist/stack-traces-BIE_5Xwf.js +21 -0
- package/dist/stack-traces-ntw_qhoy.cjs +26 -0
- package/dist/tool-CAo-BQHs.js +643 -0
- package/dist/tool-DdPZb0JW.cjs +654 -0
- package/dist/tool.d.ts +3 -3
- package/dist/truncator-B6aaJaN1.cjs +276 -0
- package/dist/truncator-DZqEqnpD.js +253 -0
- package/dist/typings-BwAz_TM9.cjs +784 -0
- package/dist/typings-CrBa7Tyy.js +743 -0
- package/dist/uniq-BYQ7GWwb.js +183 -0
- package/dist/uniq-G872RWmE.cjs +200 -0
- package/dist/utils-UBeAFeEI.js +950 -0
- package/dist/utils-ZpJm00ed.cjs +1075 -0
- package/dist/vm/errors.d.ts +2 -2
- package/dist/vm-BjkJqSQH.cjs +3438 -0
- package/dist/vm-C5vf1LH3.js +3436 -0
- package/package.json +7 -7
- package/dist/chunk-34GJUS6U.js +0 -3266
- package/dist/chunk-3UZKLXAD.cjs +0 -3249
- package/dist/chunk-4POZJQXN.js +0 -1530
- package/dist/chunk-5WBNTV42.cjs +0 -1530
- package/dist/chunk-5ZF6NTYI.cjs +0 -33
- package/dist/chunk-72ZWBNZV.js +0 -173
- package/dist/chunk-DDSJTR6Q.cjs +0 -257
- package/dist/chunk-GDJTKI7J.js +0 -792
- package/dist/chunk-GLXADNTR.js +0 -199
- package/dist/chunk-GOWPACSK.cjs +0 -199
- package/dist/chunk-HB2G32AK.js +0 -257
- package/dist/chunk-HC2QZTVT.cjs +0 -3266
- package/dist/chunk-HEAQAEFZ.cjs +0 -173
- package/dist/chunk-HMMM32RG.cjs +0 -792
- package/dist/chunk-I56MPOVG.cjs +0 -62
- package/dist/chunk-KIN7Y247.cjs +0 -32
- package/dist/chunk-KTDBAJBB.cjs +0 -1685
- package/dist/chunk-KWQTYXAT.js +0 -62
- package/dist/chunk-LOX7GOR6.js +0 -1685
- package/dist/chunk-PK72FAKD.cjs +0 -175
- package/dist/chunk-PZE6PIPG.cjs +0 -621
- package/dist/chunk-RGUG3UMF.cjs +0 -26
- package/dist/chunk-TDALRNGL.js +0 -621
- package/dist/chunk-UGHFNCPD.js +0 -26
- package/dist/chunk-WSVDMGMR.js +0 -175
- package/dist/chunk-XTEHT2TK.js +0 -33
- package/dist/chunk-YEAWWJSJ.js +0 -32
- package/dist/chunk-YRS7KRKP.js +0 -3249
- package/dist/component-2NYFY6CW.cjs +0 -14
- package/dist/component-ASNZHQUR.js +0 -14
- package/dist/dual-modes-S5TJ5JVJ.js +0 -10
- package/dist/dual-modes-TCMWBZIH.cjs +0 -10
- package/dist/execute-FF7D46TY.js +0 -1109
- package/dist/execute-IK6O4SU2.cjs +0 -1109
- package/dist/exit-MX56VN2C.cjs +0 -8
- package/dist/exit-UQ3EUX5D.js +0 -8
- package/dist/jsx-DDZ63UUF.js +0 -13
- package/dist/jsx-ULPWX5TW.cjs +0 -13
- package/dist/tool-KD7FL45V.js +0 -11
- package/dist/tool-VE2YHIY2.cjs +0 -11
- package/dist/truncator-73RCL52Y.js +0 -12
- package/dist/truncator-FZNLYSDL.cjs +0 -12
- package/dist/typings-E2RROCLT.js +0 -10
- package/dist/typings-LQOBZXSO.cjs +0 -10
- package/dist/utils-IATCUNKF.js +0 -43
- package/dist/utils-ITB4NEL7.cjs +0 -43
- package/dist/vm-6D3IIIU7.cjs +0 -12
- package/dist/vm-QO5FSGPN.js +0 -12
package/dist/chunk-HEAQAEFZ.cjs
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
|
-
|
|
3
|
-
var _chunkGOWPACSKcjs = require('./chunk-GOWPACSK.cjs');
|
|
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 REGEXP = `(${WRAP_OPEN_TAG_1}(?:\\s+[\\w:]+)*\\s*${WRAP_OPEN_TAG_2})([\\s\\S]*?)(${WRAP_CLOSE_TAG})`;
|
|
11
|
-
var DEFAULT_TRUNCATE_OPTIONS = {
|
|
12
|
-
preserve: "top",
|
|
13
|
-
flex: 1,
|
|
14
|
-
minTokens: 0
|
|
15
|
-
};
|
|
16
|
-
function wrapContent(content, options) {
|
|
17
|
-
const preserve = _nullishCoalesce((options == null ? void 0 : options.preserve), () => ( DEFAULT_TRUNCATE_OPTIONS.preserve));
|
|
18
|
-
const flex = _nullishCoalesce((options == null ? void 0 : options.flex), () => ( DEFAULT_TRUNCATE_OPTIONS.flex));
|
|
19
|
-
const minTokens = _nullishCoalesce((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 = _chunkGOWPACSKcjs.getTokenizer.call(void 0, );
|
|
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 parser = new _MessageContentParser();
|
|
35
|
-
while ((match = parser.parse(content)) !== null) {
|
|
36
|
-
const { attributes, nonTruncatableContent, wrappedContent } = match;
|
|
37
|
-
if (nonTruncatableContent) {
|
|
38
|
-
current.push({
|
|
39
|
-
content: nonTruncatableContent,
|
|
40
|
-
tokens: tokenizer.count(nonTruncatableContent),
|
|
41
|
-
truncatable: false
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
current.push({
|
|
45
|
-
content: wrappedContent,
|
|
46
|
-
tokens: tokenizer.count(wrappedContent),
|
|
47
|
-
truncatable: true,
|
|
48
|
-
attributes: {
|
|
49
|
-
preserve: attributes.preserve,
|
|
50
|
-
flex: Number(attributes.flex) || DEFAULT_TRUNCATE_OPTIONS.flex,
|
|
51
|
-
minTokens: Number(attributes.min) || DEFAULT_TRUNCATE_OPTIONS.minTokens
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
const remainingContent = parser.getRemainingContent(content);
|
|
56
|
-
if (remainingContent) {
|
|
57
|
-
current.push({
|
|
58
|
-
content: remainingContent,
|
|
59
|
-
tokens: tokenizer.count(remainingContent),
|
|
60
|
-
truncatable: false
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
parts.push(current);
|
|
64
|
-
}
|
|
65
|
-
let currentCount = _countTotalTokens(parts);
|
|
66
|
-
while (currentCount > tokenLimit) {
|
|
67
|
-
const { biggest, secondBiggest } = _getTwoBiggestTruncables(parts);
|
|
68
|
-
if (!biggest || !biggest.truncatable || biggest.tokens <= 0) {
|
|
69
|
-
if (throwOnFailure) {
|
|
70
|
-
throw new Error(`Cannot truncate further, current count: ${currentCount}`);
|
|
71
|
-
} else {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const delta = Math.max(biggest.tokens - (_nullishCoalesce((secondBiggest == null ? void 0 : secondBiggest.tokens), () => ( 0))), DEFAULT_REMOVE_CHUNK);
|
|
76
|
-
const room = Math.min(delta, biggest.tokens);
|
|
77
|
-
let toRemove = Math.min(room, currentCount - tokenLimit);
|
|
78
|
-
if (toRemove <= 0) {
|
|
79
|
-
if (throwOnFailure) {
|
|
80
|
-
throw new Error(`Cannot truncate further, current count: ${currentCount}`);
|
|
81
|
-
} else {
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (biggest.tokens - toRemove < (_nullishCoalesce(((_a = biggest.attributes) == null ? void 0 : _a.minTokens), () => ( 0)))) {
|
|
86
|
-
toRemove = biggest.tokens - (_nullishCoalesce(((_b = biggest.attributes) == null ? void 0 : _b.minTokens), () => ( 0)));
|
|
87
|
-
}
|
|
88
|
-
const preserve = _nullishCoalesce(((_c = biggest.attributes) == null ? void 0 : _c.preserve), () => ( DEFAULT_TRUNCATE_OPTIONS.preserve));
|
|
89
|
-
const split = tokenizer.splitAndSlice(biggest.content);
|
|
90
|
-
if (preserve === "bottom") {
|
|
91
|
-
biggest.content = split.slice(toRemove).join("");
|
|
92
|
-
} else if (preserve === "top") {
|
|
93
|
-
biggest.content = split.slice(0, -toRemove).join("");
|
|
94
|
-
} else {
|
|
95
|
-
const anchor = Math.ceil(split.length / 2);
|
|
96
|
-
const radius = Math.ceil(toRemove / 2);
|
|
97
|
-
const left = anchor - radius;
|
|
98
|
-
const right = anchor + radius;
|
|
99
|
-
biggest.content = split.slice(0, left).join("") + split.slice(right).join("");
|
|
100
|
-
}
|
|
101
|
-
biggest.tokens -= toRemove;
|
|
102
|
-
currentCount -= toRemove;
|
|
103
|
-
}
|
|
104
|
-
return messages.map((msg, i) => {
|
|
105
|
-
const p = parts[i];
|
|
106
|
-
return {
|
|
107
|
-
...msg,
|
|
108
|
-
content: typeof msg.content === "string" ? _renderRemainingWrappers(p.map((part) => part.content).join("")) : msg.content
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
var _MessageContentParser = (_class = class {
|
|
113
|
-
|
|
114
|
-
__init() {this._lastIndex = 0}
|
|
115
|
-
constructor() {;_class.prototype.__init.call(this);
|
|
116
|
-
this._regex = _createRegex();
|
|
117
|
-
}
|
|
118
|
-
parse(content) {
|
|
119
|
-
const match = this._regex.exec(content);
|
|
120
|
-
if (!match) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
const attributes = match[1].split(/\s+/).slice(1).filter((x) => x !== WRAP_OPEN_TAG_2).map((x) => x.split(":")).reduce(
|
|
124
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
125
|
-
{}
|
|
126
|
-
);
|
|
127
|
-
let nonTruncatableContent = void 0;
|
|
128
|
-
if (match.index > this._lastIndex) {
|
|
129
|
-
nonTruncatableContent = content.slice(this._lastIndex, match.index);
|
|
130
|
-
}
|
|
131
|
-
const wrappedContent = match[2];
|
|
132
|
-
this._lastIndex = this._regex.lastIndex;
|
|
133
|
-
return { attributes, nonTruncatableContent, wrappedContent };
|
|
134
|
-
}
|
|
135
|
-
getRemainingContent(content) {
|
|
136
|
-
if (this._lastIndex < content.length) {
|
|
137
|
-
const remainingContent = content.slice(this._lastIndex);
|
|
138
|
-
return remainingContent;
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
}, _class);
|
|
143
|
-
var _createRegex = () => new RegExp(REGEXP, "g");
|
|
144
|
-
var _renderRemainingWrappers = (content) => content.replace(_createRegex(), "$2");
|
|
145
|
-
var stripTruncationTags = (content) => _renderRemainingWrappers(content);
|
|
146
|
-
var _countTotalTokens = (parts) => parts.reduce((acc, x) => acc + x.reduce((acc2, y) => acc2 + y.tokens, 0), 0);
|
|
147
|
-
var _getTwoBiggestTruncables = (parts) => {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
let biggest = null;
|
|
150
|
-
let secondBiggest = null;
|
|
151
|
-
for (const part of parts.flat()) {
|
|
152
|
-
if (part.truncatable) {
|
|
153
|
-
if (part.tokens <= (_nullishCoalesce(((_a = part.attributes) == null ? void 0 : _a.minTokens), () => ( 0)))) {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
const flex = _nullishCoalesce(((_b = part.attributes) == null ? void 0 : _b.flex), () => ( DEFAULT_TRUNCATE_OPTIONS.flex));
|
|
157
|
-
const tokens = part.tokens * flex;
|
|
158
|
-
if (!biggest || tokens > biggest.tokens) {
|
|
159
|
-
secondBiggest = biggest;
|
|
160
|
-
biggest = part;
|
|
161
|
-
} else if (!secondBiggest || tokens > secondBiggest.tokens) {
|
|
162
|
-
secondBiggest = part;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return { biggest, secondBiggest };
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
exports.wrapContent = wrapContent; exports.truncateWrappedContent = truncateWrappedContent; exports.stripTruncationTags = stripTruncationTags;
|