llmz 0.0.15 → 0.0.17
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/{chunk-TCRRSS44.cjs → chunk-2NU62OI4.cjs} +1 -1
- package/dist/{chunk-RBRTK37G.js → chunk-QIZBF7A5.js} +1 -1
- package/dist/index.cjs +7 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -4
- package/dist/{llmz-WVNKAMCP.cjs → llmz-EUESEPB7.cjs} +9 -9
- package/dist/{llmz-67EZPJ4E.js → llmz-T4DEP7OD.js} +1 -1
- package/dist/truncator.d.ts +96 -0
- package/package.json +4 -2
|
@@ -228,7 +228,7 @@ var TranscriptArray = class extends Array {
|
|
|
228
228
|
items = Array.isArray(items) ? items : [];
|
|
229
229
|
super(...items);
|
|
230
230
|
items.forEach((item) => {
|
|
231
|
-
if (!["user", "assistant"].includes(item.role)) {
|
|
231
|
+
if (!["user", "assistant", "event", "summary"].includes(item.role)) {
|
|
232
232
|
throw new Error(`Invalid role "${item.role}" in transcript message`);
|
|
233
233
|
}
|
|
234
234
|
if ("name" in item && item.name && typeof item.name !== "string") {
|
|
@@ -228,7 +228,7 @@ var TranscriptArray = class extends Array {
|
|
|
228
228
|
items = Array.isArray(items) ? items : [];
|
|
229
229
|
super(...items);
|
|
230
230
|
items.forEach((item) => {
|
|
231
|
-
if (!["user", "assistant"].includes(item.role)) {
|
|
231
|
+
if (!["user", "assistant", "event", "summary"].includes(item.role)) {
|
|
232
232
|
throw new Error(`Invalid role "${item.role}" in transcript message`);
|
|
233
233
|
}
|
|
234
234
|
if ("name" in item && item.name && typeof item.name !== "string") {
|
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunk2NU62OI4cjs = require('./chunk-2NU62OI4.cjs');
|
|
12
12
|
require('./chunk-PIDLNYIP.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
@@ -37,6 +37,7 @@ var _chunkZRCU35UVcjs = require('./chunk-ZRCU35UV.cjs');
|
|
|
37
37
|
require('./chunk-KMZDFWYZ.cjs');
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
|
|
40
41
|
var _chunkGZPN7RGHcjs = require('./chunk-GZPN7RGH.cjs');
|
|
41
42
|
|
|
42
43
|
|
|
@@ -1098,14 +1099,15 @@ var Chat = class {
|
|
|
1098
1099
|
var utils = {
|
|
1099
1100
|
toValidObjectName: _chunkWHNOR4ZUcjs.toValidObjectName,
|
|
1100
1101
|
toValidFunctionName: _chunkWHNOR4ZUcjs.toValidFunctionName,
|
|
1101
|
-
wrapContent: _chunkGZPN7RGHcjs.wrapContent
|
|
1102
|
+
wrapContent: _chunkGZPN7RGHcjs.wrapContent,
|
|
1103
|
+
truncateWrappedContent: _chunkGZPN7RGHcjs.truncateWrappedContent
|
|
1102
1104
|
};
|
|
1103
1105
|
var execute = async (props) => {
|
|
1104
|
-
const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-
|
|
1106
|
+
const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-EUESEPB7.cjs")));
|
|
1105
1107
|
return executeContext(props);
|
|
1106
1108
|
};
|
|
1107
1109
|
var init = async () => {
|
|
1108
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-
|
|
1110
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-EUESEPB7.cjs")));
|
|
1109
1111
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./component-R4WTW6DZ.cjs")));
|
|
1110
1112
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-O4SFRIE4.cjs")));
|
|
1111
1113
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-XAYKJ6TR.cjs")));
|
|
@@ -1143,4 +1145,4 @@ var init = async () => {
|
|
|
1143
1145
|
|
|
1144
1146
|
|
|
1145
1147
|
|
|
1146
|
-
exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkZRCU35UVcjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit =
|
|
1148
|
+
exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkZRCU35UVcjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunk2NU62OI4cjs.DefaultExit; exports.ErrorExecutionResult = _chunk2NU62OI4cjs.ErrorExecutionResult; exports.ExecutionResult = _chunk2NU62OI4cjs.ExecutionResult; exports.Exit = _chunk3G3BS5IAcjs.Exit; exports.ListenExit = _chunk2NU62OI4cjs.ListenExit; exports.LoopExceededError = _chunkJDABP4SDcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunk2NU62OI4cjs.PartialExecutionResult; exports.Snapshot = _chunk2NU62OI4cjs.Snapshot; exports.SnapshotSignal = _chunkJDABP4SDcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunk2NU62OI4cjs.SuccessExecutionResult; exports.ThinkExit = _chunk2NU62OI4cjs.ThinkExit; exports.ThinkSignal = _chunkJDABP4SDcjs.ThinkSignal; exports.Tool = _chunkXGJOEQMWcjs.Tool; exports.assertValidComponent = _chunkZRCU35UVcjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunk2NU62OI4cjs.getValue; exports.init = init; exports.isAnyComponent = _chunkZRCU35UVcjs.isAnyComponent; exports.isComponent = _chunkZRCU35UVcjs.isComponent; exports.renderToTsx = _chunkZRCU35UVcjs.renderToTsx; exports.utils = utils;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { Snapshot } from './snapshots.js';
|
|
|
9
9
|
export { Chat, type MessageHandler } from './chat.js';
|
|
10
10
|
import { type ExecutionProps } from './llmz.js';
|
|
11
11
|
import { ExecutionResult } from './result.js';
|
|
12
|
-
import { wrapContent } from './truncator.js';
|
|
12
|
+
import { truncateWrappedContent, wrapContent } from './truncator.js';
|
|
13
13
|
export { Transcript } from './transcript.js';
|
|
14
14
|
export { ErrorExecutionResult, ExecutionResult, PartialExecutionResult, SuccessExecutionResult } from './result.js';
|
|
15
15
|
export { type Trace, type Traces } from './types.js';
|
|
@@ -21,6 +21,7 @@ export declare const utils: {
|
|
|
21
21
|
toValidObjectName: (str: string) => string;
|
|
22
22
|
toValidFunctionName: (str: string) => string;
|
|
23
23
|
wrapContent: typeof wrapContent;
|
|
24
|
+
truncateWrappedContent: typeof truncateWrappedContent;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
27
|
* Executes an LLMz agent in either Chat Mode or Worker Mode.
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
SuccessExecutionResult,
|
|
9
9
|
ThinkExit,
|
|
10
10
|
getValue
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QIZBF7A5.js";
|
|
12
12
|
import "./chunk-2D2DE7CD.js";
|
|
13
13
|
import {
|
|
14
14
|
Tool
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from "./chunk-GGWM6X2K.js";
|
|
37
37
|
import "./chunk-ORQP26SZ.js";
|
|
38
38
|
import {
|
|
39
|
+
truncateWrappedContent,
|
|
39
40
|
wrapContent
|
|
40
41
|
} from "./chunk-3JYCCI4S.js";
|
|
41
42
|
import {
|
|
@@ -1098,14 +1099,15 @@ var Chat = class {
|
|
|
1098
1099
|
var utils = {
|
|
1099
1100
|
toValidObjectName,
|
|
1100
1101
|
toValidFunctionName,
|
|
1101
|
-
wrapContent
|
|
1102
|
+
wrapContent,
|
|
1103
|
+
truncateWrappedContent
|
|
1102
1104
|
};
|
|
1103
1105
|
var execute = async (props) => {
|
|
1104
|
-
const { executeContext } = await import("./llmz-
|
|
1106
|
+
const { executeContext } = await import("./llmz-T4DEP7OD.js");
|
|
1105
1107
|
return executeContext(props);
|
|
1106
1108
|
};
|
|
1107
1109
|
var init = async () => {
|
|
1108
|
-
await import("./llmz-
|
|
1110
|
+
await import("./llmz-T4DEP7OD.js");
|
|
1109
1111
|
await import("./component-WFVDVSDK.js");
|
|
1110
1112
|
await import("./tool-PCOYOCRH.js");
|
|
1111
1113
|
await import("./exit-YLO7BY7Z.js");
|
|
@@ -7,7 +7,7 @@ var _chunkBEPRLBPKcjs = require('./chunk-BEPRLBPK.cjs');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunk2NU62OI4cjs = require('./chunk-2NU62OI4.cjs');
|
|
11
11
|
require('./chunk-PIDLNYIP.cjs');
|
|
12
12
|
require('./chunk-XGJOEQMW.cjs');
|
|
13
13
|
require('./chunk-FZJHYLM2.cjs');
|
|
@@ -105,7 +105,7 @@ var _executeContext = async (props) => {
|
|
|
105
105
|
const { onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
|
|
106
106
|
const cognitive = _cognitive.Cognitive.isCognitiveClient(props.client) ? props.client : new (0, _cognitive.Cognitive)({ client: props.client });
|
|
107
107
|
const cleanups = [];
|
|
108
|
-
const ctx = new (0,
|
|
108
|
+
const ctx = new (0, _chunk2NU62OI4cjs.Context)({
|
|
109
109
|
chat: props.chat,
|
|
110
110
|
instructions: props.instructions,
|
|
111
111
|
objects: props.objects,
|
|
@@ -120,7 +120,7 @@ var _executeContext = async (props) => {
|
|
|
120
120
|
try {
|
|
121
121
|
while (true) {
|
|
122
122
|
if (ctx.iterations.length >= ctx.loop) {
|
|
123
|
-
return new (0,
|
|
123
|
+
return new (0, _chunk2NU62OI4cjs.ErrorExecutionResult)(ctx, new (0, _chunkJDABP4SDcjs.LoopExceededError)());
|
|
124
124
|
}
|
|
125
125
|
const iteration = await ctx.nextIteration();
|
|
126
126
|
if (controller.signal.aborted) {
|
|
@@ -130,7 +130,7 @@ var _executeContext = async (props) => {
|
|
|
130
130
|
reason: _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted"))
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
|
-
return new (0,
|
|
133
|
+
return new (0, _chunk2NU62OI4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")));
|
|
134
134
|
}
|
|
135
135
|
cleanups.push(
|
|
136
136
|
iteration.traces.onPush((traces) => {
|
|
@@ -166,25 +166,25 @@ var _executeContext = async (props) => {
|
|
|
166
166
|
}
|
|
167
167
|
if (iteration.status.type === "exit_success") {
|
|
168
168
|
const exitName = iteration.status.exit_success.exit_name;
|
|
169
|
-
return new (0,
|
|
169
|
+
return new (0, _chunk2NU62OI4cjs.SuccessExecutionResult)(ctx, {
|
|
170
170
|
exit: iteration.exits.find((x) => x.name === exitName),
|
|
171
171
|
result: iteration.status.exit_success.return_value
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
if (iteration.status.type === "callback_requested") {
|
|
175
|
-
return new (0,
|
|
175
|
+
return new (0, _chunk2NU62OI4cjs.PartialExecutionResult)(
|
|
176
176
|
ctx,
|
|
177
177
|
iteration.status.callback_requested.signal,
|
|
178
|
-
|
|
178
|
+
_chunk2NU62OI4cjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
181
|
if (iteration.status.type === "thinking_requested" || iteration.status.type === "exit_error" || iteration.status.type === "execution_error" || iteration.status.type === "invalid_code_error") {
|
|
182
182
|
continue;
|
|
183
183
|
}
|
|
184
|
-
return new (0,
|
|
184
|
+
return new (0, _chunk2NU62OI4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)));
|
|
185
185
|
}
|
|
186
186
|
} catch (error) {
|
|
187
|
-
return new (0,
|
|
187
|
+
return new (0, _chunk2NU62OI4cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
|
|
188
188
|
} finally {
|
|
189
189
|
for (const cleanup of cleanups) {
|
|
190
190
|
try {
|
package/dist/truncator.d.ts
CHANGED
|
@@ -15,6 +15,102 @@ type TruncateOptions = {
|
|
|
15
15
|
/** If provided, the message will never truncate below that number */
|
|
16
16
|
minTokens: number;
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Wraps content with truncation tags to mark it as truncatable when using `truncateWrappedContent`.
|
|
20
|
+
*
|
|
21
|
+
* This function encases the provided content within special truncation tags that contain metadata
|
|
22
|
+
* about how the content should be truncated. The wrapped content becomes eligible for intelligent
|
|
23
|
+
* truncation while preserving non-wrapped content intact.
|
|
24
|
+
*
|
|
25
|
+
* @param content - The string content to wrap with truncation tags
|
|
26
|
+
* @param options - Optional truncation configuration
|
|
27
|
+
* @param options.preserve - Which part of the content to preserve when truncating:
|
|
28
|
+
* - 'top': Keep the beginning, remove from the end (default)
|
|
29
|
+
* - 'bottom': Keep the end, remove from the beginning
|
|
30
|
+
* - 'both': Keep both ends, remove from the middle
|
|
31
|
+
* @param options.flex - Priority factor for truncation (default: 1). Higher values make this
|
|
32
|
+
* content more likely to be truncated. A flex of 2 means this content can shrink twice as
|
|
33
|
+
* much as content with flex of 1.
|
|
34
|
+
* @param options.minTokens - Minimum number of tokens to preserve (default: 0). Content will
|
|
35
|
+
* never be truncated below this threshold.
|
|
36
|
+
*
|
|
37
|
+
* @returns The content wrapped with truncation tags and embedded metadata
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Basic usage - content will be truncated from the end if needed
|
|
42
|
+
* const wrapped = wrapContent("This is some long content that might need truncation")
|
|
43
|
+
*
|
|
44
|
+
* // Preserve the end of the content
|
|
45
|
+
* const bottomPreserved = wrapContent("Error log: ... important error details", {
|
|
46
|
+
* preserve: 'bottom'
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* // High priority for truncation with minimum preservation
|
|
50
|
+
* const flexible = wrapContent("Optional context information", {
|
|
51
|
+
* flex: 3,
|
|
52
|
+
* minTokens: 50
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
18
56
|
export declare function wrapContent(content: string, options?: Partial<TruncateOptions>): string;
|
|
57
|
+
/**
|
|
58
|
+
* Intelligently truncates message content to fit within a token limit while preserving important parts.
|
|
59
|
+
*
|
|
60
|
+
* This function processes an array of messages and reduces their total token count to fit within the
|
|
61
|
+
* specified limit. It only truncates content that has been wrapped with `wrapContent()`, leaving
|
|
62
|
+
* unwrapped content completely intact. The truncation algorithm prioritizes content based on flex
|
|
63
|
+
* values and respects preservation preferences and minimum token requirements.
|
|
64
|
+
*
|
|
65
|
+
* ## How it works:
|
|
66
|
+
* 1. **Parsing**: Scans each message for wrapped content sections and unwrapped sections
|
|
67
|
+
* 2. **Token counting**: Calculates tokens for each section using the configured tokenizer
|
|
68
|
+
* 3. **Prioritization**: Identifies the largest truncatable sections based on flex values
|
|
69
|
+
* 4. **Intelligent truncation**: Removes content according to preservation preferences
|
|
70
|
+
* 5. **Reconstruction**: Rebuilds messages with truncated content and removes wrapper tags
|
|
71
|
+
*
|
|
72
|
+
* ## Truncation strategy:
|
|
73
|
+
* - **Priority**: Higher flex values = higher truncation priority
|
|
74
|
+
* - **Minimum tokens**: Content is never truncated below its `minTokens` threshold
|
|
75
|
+
* - **Preservation modes**:
|
|
76
|
+
* - `'top'`: Removes from the end, keeps the beginning
|
|
77
|
+
* - `'bottom'`: Removes from the beginning, keeps the end
|
|
78
|
+
* - `'both'`: Removes from the middle, keeps both ends
|
|
79
|
+
*
|
|
80
|
+
* @template T - Type extending MessageLike (must have a content property)
|
|
81
|
+
* @param options - Configuration object
|
|
82
|
+
* @param options.messages - Array of messages to truncate
|
|
83
|
+
* @param options.tokenLimit - Maximum total tokens allowed across all messages
|
|
84
|
+
* @param options.throwOnFailure - Whether to throw an error if truncation fails (default: true).
|
|
85
|
+
* If false, returns the best effort result even if over the token limit.
|
|
86
|
+
*
|
|
87
|
+
* @returns Array of messages with content truncated to fit the token limit
|
|
88
|
+
*
|
|
89
|
+
* @throws Error if unable to truncate enough content to meet the token limit (when throwOnFailure is true)
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const messages = [
|
|
94
|
+
* {
|
|
95
|
+
* role: 'system',
|
|
96
|
+
* content: 'You are a helpful assistant. ' + wrapContent('Here is some background info...', { flex: 2 })
|
|
97
|
+
* },
|
|
98
|
+
* {
|
|
99
|
+
* role: 'user',
|
|
100
|
+
* content: 'Please help me with: ' + wrapContent('detailed context and examples', { preserve: 'both' })
|
|
101
|
+
* }
|
|
102
|
+
* ]
|
|
103
|
+
*
|
|
104
|
+
* // Truncate to fit within 1000 tokens
|
|
105
|
+
* const truncated = truncateWrappedContent({
|
|
106
|
+
* messages,
|
|
107
|
+
* tokenLimit: 1000,
|
|
108
|
+
* throwOnFailure: false
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* // The system message background info will be truncated first (higher flex),
|
|
112
|
+
* // and user context will be truncated from the middle if needed (preserve: 'both')
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
19
115
|
export declare function truncateWrappedContent<T extends MessageLike>({ messages, tokenLimit, throwOnFailure, }: Options<T>): T[];
|
|
20
116
|
export {};
|
package/package.json
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
"name": "llmz",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "LLMz – An LLM-native Typescript VM built on top of Zui",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.17",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
7
9
|
"exports": {
|
|
8
10
|
".": {
|
|
9
11
|
"import": "./dist/index.js",
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
"@babel/standalone": "^7.26.4",
|
|
33
35
|
"@babel/traverse": "^7.26.4",
|
|
34
36
|
"@babel/types": "^7.26.3",
|
|
35
|
-
"@botpress/client": "1.
|
|
37
|
+
"@botpress/client": "1.21.0",
|
|
36
38
|
"bytes": "^3.1.2",
|
|
37
39
|
"exponential-backoff": "^3.1.1",
|
|
38
40
|
"handlebars": "^4.7.8",
|