llmz 0.0.13 → 0.0.15
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/CLAUDE.md +363 -0
- package/README.md +61 -34
- package/dist/abort-signal.d.ts +40 -0
- package/dist/chat.d.ts +325 -0
- package/dist/{chunk-KH6JQYQA.js → chunk-2D2DE7CD.js} +2 -2
- package/dist/chunk-3G3BS5IA.cjs +256 -0
- package/dist/{chunk-SNDVQU5A.js → chunk-3JYCCI4S.js} +1 -1
- package/dist/chunk-A7QHWVD7.js +493 -0
- package/dist/{chunk-IH2WQFO5.js → chunk-EE6NVDID.js} +1 -1
- package/dist/{chunk-4L6D2A6O.cjs → chunk-FZJHYLM2.cjs} +14 -14
- package/dist/{chunk-JGVAZO4X.cjs → chunk-GZPN7RGH.cjs} +2 -2
- package/dist/{chunk-SHJDRZF5.cjs → chunk-PIDLNYIP.cjs} +25 -25
- package/dist/{chunk-PRVFVXT4.js → chunk-RBRTK37G.js} +383 -4
- package/dist/{chunk-HJKOSEH2.cjs → chunk-TCRRSS44.cjs} +397 -18
- package/dist/chunk-VPTFUOIK.js +256 -0
- package/dist/{chunk-276Q6EWP.cjs → chunk-WHNOR4ZU.cjs} +3 -0
- package/dist/chunk-XGJOEQMW.cjs +493 -0
- package/dist/{chunk-4MNIJGK6.js → chunk-ZORRILUV.js} +3 -0
- package/dist/context.d.ts +412 -4
- package/dist/{dual-modes-T53P72CH.js → dual-modes-7FI4T35O.js} +3 -3
- package/dist/{dual-modes-VLIGPIHX.cjs → dual-modes-OFHV2C3X.cjs} +4 -4
- package/dist/exit-XAYKJ6TR.cjs +8 -0
- package/dist/{exit-YORW76T3.js → exit-YLO7BY7Z.js} +2 -2
- package/dist/exit.d.ts +369 -2
- package/dist/index.cjs +253 -28
- package/dist/index.d.ts +71 -1
- package/dist/index.js +242 -17
- package/dist/{llmz-ROOX7RYI.js → llmz-67EZPJ4E.js} +113 -39
- package/dist/{llmz-QLZBDG2Z.cjs → llmz-WVNKAMCP.cjs} +123 -49
- package/dist/llmz.d.ts +142 -5
- package/dist/objects.d.ts +350 -1
- package/dist/result.d.ts +809 -6
- package/dist/snapshots.d.ts +181 -1
- package/dist/{tool-QP4MVRWI.cjs → tool-O4SFRIE4.cjs} +4 -4
- package/dist/{tool-N6ODRRGH.js → tool-PCOYOCRH.js} +3 -3
- package/dist/tool.d.ts +470 -2
- package/dist/{truncator-IY2MXOMC.js → truncator-BSP6PQPC.js} +2 -2
- package/dist/truncator-W3NXBLYJ.cjs +10 -0
- package/dist/types.d.ts +3 -0
- package/dist/{typings-GDMY6VY2.js → typings-WYHEFCYB.js} +2 -2
- package/dist/{typings-2CPHOFDN.cjs → typings-Y45GMPZT.cjs} +3 -3
- package/dist/utils-L5QAQXV2.cjs +39 -0
- package/dist/{utils-N24IHDFA.js → utils-RQHQ2KOG.js} +1 -1
- package/docs/TODO.md +919 -0
- package/package.json +3 -3
- package/dist/chunk-C6WNNTEV.cjs +0 -212
- package/dist/chunk-GWFYZDUR.cjs +0 -105
- package/dist/chunk-JAGB2AOU.js +0 -212
- package/dist/chunk-JMSZKB4T.js +0 -105
- package/dist/exit-TRXEU4OU.cjs +0 -8
- package/dist/truncator-DUMWEGQO.cjs +0 -10
- package/dist/utils-A7WNEFTA.cjs +0 -39
package/dist/snapshots.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ToolCall, SnapshotSignal } from './errors.js';
|
|
2
|
+
import { Serializable } from './types.js';
|
|
2
3
|
type Variable = {
|
|
3
4
|
name: string;
|
|
4
5
|
type: string;
|
|
@@ -27,13 +28,101 @@ export declare namespace SnapshotStatuses {
|
|
|
27
28
|
error: unknown;
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
export declare
|
|
31
|
+
export declare namespace Snapshot {
|
|
32
|
+
type JSON = {
|
|
33
|
+
id: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
stack: string;
|
|
36
|
+
variables: Variable[];
|
|
37
|
+
toolCall?: ToolCall;
|
|
38
|
+
status: SnapshotStatus;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Snapshot represents a captured execution state that can be persisted and restored later.
|
|
43
|
+
*
|
|
44
|
+
* Snapshots are created when a SnapshotSignal is thrown during execution, typically from
|
|
45
|
+
* within a tool handler to pause execution for long-running operations that need to be
|
|
46
|
+
* completed asynchronously (e.g., background jobs, external API calls, user input).
|
|
47
|
+
*
|
|
48
|
+
* ## Use Cases
|
|
49
|
+
* - **Long-running operations**: Pause execution while waiting for external processes
|
|
50
|
+
* - **User interaction**: Collect input from users before continuing execution
|
|
51
|
+
* - **Resource management**: Defer expensive operations to background workers
|
|
52
|
+
* - **Workflow persistence**: Save execution state across process restarts
|
|
53
|
+
*
|
|
54
|
+
* ## Basic Usage
|
|
55
|
+
*
|
|
56
|
+
* ### Creating a Snapshot
|
|
57
|
+
* From within a tool handler, throw a SnapshotSignal to create a snapshot:
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const tool = new Tool({
|
|
60
|
+
* handler: async ({ input }) => {
|
|
61
|
+
* // Start long-running operation
|
|
62
|
+
* throw new SnapshotSignal('Waiting for external API response')
|
|
63
|
+
* }
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* ### Handling Interrupted Execution
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const result = await execute({ tools: [tool], ... })
|
|
70
|
+
*
|
|
71
|
+
* if (result.isInterrupted()) {
|
|
72
|
+
* const snapshot = result.snapshot
|
|
73
|
+
*
|
|
74
|
+
* // Serialize for persistence
|
|
75
|
+
* const serialized = snapshot.toJSON()
|
|
76
|
+
* await database.saveSnapshot(serialized)
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* ### Resuming from Snapshot
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Restore from persistence
|
|
83
|
+
* const serialized = await database.getSnapshot(id)
|
|
84
|
+
* const snapshot = Snapshot.fromJSON(serialized)
|
|
85
|
+
*
|
|
86
|
+
* // Resolve with the result of the long-running operation
|
|
87
|
+
* snapshot.resolve({ result: 'Operation completed!' })
|
|
88
|
+
*
|
|
89
|
+
* // Continue execution
|
|
90
|
+
* const continuation = await execute({
|
|
91
|
+
* snapshot,
|
|
92
|
+
* instructions: originalInstructions,
|
|
93
|
+
* tools: originalTools,
|
|
94
|
+
* exits: originalExits,
|
|
95
|
+
* client
|
|
96
|
+
* })
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* ## Snapshot Lifecycle
|
|
100
|
+
* 1. **Created**: When SnapshotSignal is thrown (status: pending)
|
|
101
|
+
* 2. **Serialized**: Convert to JSON for persistence with toJSON()
|
|
102
|
+
* 3. **Restored**: Recreate from JSON with fromJSON()
|
|
103
|
+
* 4. **Resolved/Rejected**: Provide result data with resolve() or reject()
|
|
104
|
+
* 5. **Resumed**: Continue execution with the resolved snapshot
|
|
105
|
+
*
|
|
106
|
+
* ## What's Captured
|
|
107
|
+
* - **Execution stack**: Current code position and call stack
|
|
108
|
+
* - **Variables**: All local variables and their values (up to size limit)
|
|
109
|
+
* - **Tool context**: Information about the tool call that triggered the snapshot
|
|
110
|
+
* - **Reason**: Human-readable description of why the snapshot was created
|
|
111
|
+
*
|
|
112
|
+
* @see {@link https://github.com/botpress/botpress/blob/master/packages/llmz/examples/14_worker_snapshot/index.ts} Example usage
|
|
113
|
+
*/
|
|
114
|
+
export declare class Snapshot implements Serializable<Snapshot.JSON> {
|
|
31
115
|
#private;
|
|
32
116
|
readonly id: string;
|
|
33
117
|
readonly reason?: string;
|
|
34
118
|
readonly stack: string;
|
|
35
119
|
readonly variables: Variable[];
|
|
36
120
|
readonly toolCall?: ToolCall;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the current status of the snapshot.
|
|
123
|
+
*
|
|
124
|
+
* @returns The snapshot status (pending, resolved, or rejected)
|
|
125
|
+
*/
|
|
37
126
|
get status(): Readonly<{
|
|
38
127
|
type: "pending";
|
|
39
128
|
} | {
|
|
@@ -44,7 +133,32 @@ export declare class Snapshot {
|
|
|
44
133
|
error: unknown;
|
|
45
134
|
}>;
|
|
46
135
|
private constructor();
|
|
136
|
+
/**
|
|
137
|
+
* Creates a new Snapshot from a SnapshotSignal.
|
|
138
|
+
*
|
|
139
|
+
* This method is called internally by the LLMz execution engine when a SnapshotSignal
|
|
140
|
+
* is thrown during execution. It captures the current execution state including
|
|
141
|
+
* variables, stack trace, and tool context.
|
|
142
|
+
*
|
|
143
|
+
* @param signal The SnapshotSignal containing execution state
|
|
144
|
+
* @returns A new Snapshot instance in pending status
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
47
147
|
static fromSignal(signal: SnapshotSignal): Snapshot;
|
|
148
|
+
/**
|
|
149
|
+
* Serializes the snapshot to a JSON-compatible object for persistence.
|
|
150
|
+
*
|
|
151
|
+
* Use this method to save snapshots to databases, files, or other storage systems.
|
|
152
|
+
* The serialized snapshot can be restored later using fromJSON().
|
|
153
|
+
*
|
|
154
|
+
* @returns A JSON-serializable representation of the snapshot
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const snapshot = result.snapshot
|
|
158
|
+
* const serialized = snapshot.toJSON()
|
|
159
|
+
* await database.save('snapshots', snapshot.id, serialized)
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
48
162
|
toJSON(): {
|
|
49
163
|
id: string;
|
|
50
164
|
reason: string | undefined;
|
|
@@ -53,6 +167,20 @@ export declare class Snapshot {
|
|
|
53
167
|
toolCall: ToolCall | undefined;
|
|
54
168
|
status: SnapshotStatus;
|
|
55
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Restores a snapshot from its JSON representation.
|
|
172
|
+
*
|
|
173
|
+
* Use this method to recreate snapshots from persistent storage. The restored
|
|
174
|
+
* snapshot will maintain its original state and can be resolved/rejected as needed.
|
|
175
|
+
*
|
|
176
|
+
* @param json The serialized snapshot data from toJSON()
|
|
177
|
+
* @returns A restored Snapshot instance
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const serialized = await database.get('snapshots', snapshotId)
|
|
181
|
+
* const snapshot = Snapshot.fromJSON(serialized)
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
56
184
|
static fromJSON(json: {
|
|
57
185
|
id: string;
|
|
58
186
|
reason?: string;
|
|
@@ -61,9 +189,61 @@ export declare class Snapshot {
|
|
|
61
189
|
toolCall?: ToolCall;
|
|
62
190
|
status: SnapshotStatus;
|
|
63
191
|
}): Snapshot;
|
|
192
|
+
/**
|
|
193
|
+
* Creates a deep copy of the snapshot.
|
|
194
|
+
*
|
|
195
|
+
* @returns A new Snapshot instance with identical data
|
|
196
|
+
*/
|
|
64
197
|
clone(): Snapshot;
|
|
198
|
+
/**
|
|
199
|
+
* Resets the snapshot status back to pending.
|
|
200
|
+
*
|
|
201
|
+
* This allows a previously resolved or rejected snapshot to be resolved/rejected
|
|
202
|
+
* again with different data. Useful for retry scenarios.
|
|
203
|
+
*/
|
|
65
204
|
reset(): void;
|
|
205
|
+
/**
|
|
206
|
+
* Resolves the snapshot with a successful result value.
|
|
207
|
+
*
|
|
208
|
+
* Call this method when the long-running operation that caused the snapshot
|
|
209
|
+
* has completed successfully. The provided value will be returned as the
|
|
210
|
+
* result of the original tool call when execution resumes.
|
|
211
|
+
*
|
|
212
|
+
* @param value The result value from the completed operation
|
|
213
|
+
* @throws Error if the snapshot is not in pending status
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* // After a background job completes
|
|
217
|
+
* const result = await backgroundJob.getResult()
|
|
218
|
+
* snapshot.resolve(result)
|
|
219
|
+
*
|
|
220
|
+
* // Continue execution
|
|
221
|
+
* const continuation = await execute({ snapshot, ... })
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
66
224
|
resolve(value: any): void;
|
|
225
|
+
/**
|
|
226
|
+
* Rejects the snapshot with an error.
|
|
227
|
+
*
|
|
228
|
+
* Call this method when the long-running operation that caused the snapshot
|
|
229
|
+
* has failed or encountered an error. The provided error will be thrown
|
|
230
|
+
* when execution resumes, allowing the generated code to handle it.
|
|
231
|
+
*
|
|
232
|
+
* @param error The error that occurred during the operation
|
|
233
|
+
* @throws Error if the snapshot is not in pending status
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* try {
|
|
237
|
+
* const result = await externalAPI.call()
|
|
238
|
+
* snapshot.resolve(result)
|
|
239
|
+
* } catch (error) {
|
|
240
|
+
* snapshot.reject(error)
|
|
241
|
+
* }
|
|
242
|
+
*
|
|
243
|
+
* // Continue execution (will throw the error)
|
|
244
|
+
* const continuation = await execute({ snapshot, ... })
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
67
247
|
reject(error: any): void;
|
|
68
248
|
}
|
|
69
249
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var _chunkXGJOEQMWcjs = require('./chunk-XGJOEQMW.cjs');
|
|
4
|
+
require('./chunk-FZJHYLM2.cjs');
|
|
5
5
|
require('./chunk-JDABP4SD.cjs');
|
|
6
6
|
require('./chunk-IKSIOIIP.cjs');
|
|
7
|
-
require('./chunk-
|
|
7
|
+
require('./chunk-WHNOR4ZU.cjs');
|
|
8
8
|
require('./chunk-UQOBUJIQ.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.Tool =
|
|
11
|
+
exports.Tool = _chunkXGJOEQMWcjs.Tool;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Tool
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-A7QHWVD7.js";
|
|
4
|
+
import "./chunk-EE6NVDID.js";
|
|
5
5
|
import "./chunk-JKVVQN2P.js";
|
|
6
6
|
import "./chunk-JQBT7UWN.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-ZORRILUV.js";
|
|
8
8
|
import "./chunk-7WRN4E42.js";
|
|
9
9
|
export {
|
|
10
10
|
Tool
|