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.
Files changed (52) hide show
  1. package/CLAUDE.md +363 -0
  2. package/README.md +61 -34
  3. package/dist/abort-signal.d.ts +40 -0
  4. package/dist/chat.d.ts +325 -0
  5. package/dist/{chunk-KH6JQYQA.js → chunk-2D2DE7CD.js} +2 -2
  6. package/dist/chunk-3G3BS5IA.cjs +256 -0
  7. package/dist/{chunk-SNDVQU5A.js → chunk-3JYCCI4S.js} +1 -1
  8. package/dist/chunk-A7QHWVD7.js +493 -0
  9. package/dist/{chunk-IH2WQFO5.js → chunk-EE6NVDID.js} +1 -1
  10. package/dist/{chunk-4L6D2A6O.cjs → chunk-FZJHYLM2.cjs} +14 -14
  11. package/dist/{chunk-JGVAZO4X.cjs → chunk-GZPN7RGH.cjs} +2 -2
  12. package/dist/{chunk-SHJDRZF5.cjs → chunk-PIDLNYIP.cjs} +25 -25
  13. package/dist/{chunk-PRVFVXT4.js → chunk-RBRTK37G.js} +383 -4
  14. package/dist/{chunk-HJKOSEH2.cjs → chunk-TCRRSS44.cjs} +397 -18
  15. package/dist/chunk-VPTFUOIK.js +256 -0
  16. package/dist/{chunk-276Q6EWP.cjs → chunk-WHNOR4ZU.cjs} +3 -0
  17. package/dist/chunk-XGJOEQMW.cjs +493 -0
  18. package/dist/{chunk-4MNIJGK6.js → chunk-ZORRILUV.js} +3 -0
  19. package/dist/context.d.ts +412 -4
  20. package/dist/{dual-modes-T53P72CH.js → dual-modes-7FI4T35O.js} +3 -3
  21. package/dist/{dual-modes-VLIGPIHX.cjs → dual-modes-OFHV2C3X.cjs} +4 -4
  22. package/dist/exit-XAYKJ6TR.cjs +8 -0
  23. package/dist/{exit-YORW76T3.js → exit-YLO7BY7Z.js} +2 -2
  24. package/dist/exit.d.ts +369 -2
  25. package/dist/index.cjs +253 -28
  26. package/dist/index.d.ts +71 -1
  27. package/dist/index.js +242 -17
  28. package/dist/{llmz-ROOX7RYI.js → llmz-67EZPJ4E.js} +113 -39
  29. package/dist/{llmz-QLZBDG2Z.cjs → llmz-WVNKAMCP.cjs} +123 -49
  30. package/dist/llmz.d.ts +142 -5
  31. package/dist/objects.d.ts +350 -1
  32. package/dist/result.d.ts +809 -6
  33. package/dist/snapshots.d.ts +181 -1
  34. package/dist/{tool-QP4MVRWI.cjs → tool-O4SFRIE4.cjs} +4 -4
  35. package/dist/{tool-N6ODRRGH.js → tool-PCOYOCRH.js} +3 -3
  36. package/dist/tool.d.ts +470 -2
  37. package/dist/{truncator-IY2MXOMC.js → truncator-BSP6PQPC.js} +2 -2
  38. package/dist/truncator-W3NXBLYJ.cjs +10 -0
  39. package/dist/types.d.ts +3 -0
  40. package/dist/{typings-GDMY6VY2.js → typings-WYHEFCYB.js} +2 -2
  41. package/dist/{typings-2CPHOFDN.cjs → typings-Y45GMPZT.cjs} +3 -3
  42. package/dist/utils-L5QAQXV2.cjs +39 -0
  43. package/dist/{utils-N24IHDFA.js → utils-RQHQ2KOG.js} +1 -1
  44. package/docs/TODO.md +919 -0
  45. package/package.json +3 -3
  46. package/dist/chunk-C6WNNTEV.cjs +0 -212
  47. package/dist/chunk-GWFYZDUR.cjs +0 -105
  48. package/dist/chunk-JAGB2AOU.js +0 -212
  49. package/dist/chunk-JMSZKB4T.js +0 -105
  50. package/dist/exit-TRXEU4OU.cjs +0 -8
  51. package/dist/truncator-DUMWEGQO.cjs +0 -10
  52. package/dist/utils-A7WNEFTA.cjs +0 -39
package/dist/result.d.ts CHANGED
@@ -2,32 +2,835 @@ import { Context, Iteration } from './context.js';
2
2
  import { SnapshotSignal } from './errors.js';
3
3
  import { Exit, ExitResult } from './exit.js';
4
4
  import { Snapshot } from './snapshots.js';
5
- export declare abstract class ExecutionResult {
6
- readonly status: 'success' | 'error' | 'interrupted';
5
+ import { Serializable } from './types.js';
6
+ type ExecutionStatus = 'success' | 'error' | 'interrupted';
7
+ export declare namespace ExecutionResult {
8
+ type JSON = SuccessExecutionResult.JSON | ErrorExecutionResult.JSON | PartialExecutionResult.JSON;
9
+ }
10
+ /**
11
+ * Base class for all execution results returned by the `execute()` function.
12
+ *
13
+ * ExecutionResult provides a type-safe way to handle the different outcomes of LLMz
14
+ * agent execution. All results contain the execution context and provide methods
15
+ * to check the final status and access relevant data.
16
+ *
17
+ * ## Result Types
18
+ *
19
+ * LLMz execution can result in three different outcomes:
20
+ * - **Success**: Agent completed with an Exit (SuccessExecutionResult)
21
+ * - **Error**: Execution failed with an unrecoverable error (ErrorExecutionResult)
22
+ * - **Interrupted**: Execution was paused for snapshots or cancellation (PartialExecutionResult)
23
+ *
24
+ * ## Usage Patterns
25
+ *
26
+ * ### Basic Status Checking
27
+ * ```typescript
28
+ * const result = await execute({
29
+ * instructions: 'Calculate the sum of numbers 1 to 100',
30
+ * client,
31
+ * })
32
+ *
33
+ * if (result.isSuccess()) {
34
+ * console.log('Success:', result.output)
35
+ * } else if (result.isError()) {
36
+ * console.error('Error:', result.error)
37
+ * } else if (result.isInterrupted()) {
38
+ * console.log('Interrupted - snapshot available:', !!result.snapshot)
39
+ * }
40
+ * ```
41
+ *
42
+ * ### Type-Safe Exit Checking
43
+ * ```typescript
44
+ * const dataExit = new Exit({
45
+ * name: 'dataProcessed',
46
+ * schema: z.object({
47
+ * recordCount: z.number(),
48
+ * processingTime: z.number(),
49
+ * }),
50
+ * })
51
+ *
52
+ * const result = await execute({
53
+ * instructions: 'Process the data',
54
+ * exits: [dataExit],
55
+ * client,
56
+ * })
57
+ *
58
+ * // Type-safe exit checking with typed output access
59
+ * if (result.is(dataExit)) {
60
+ * console.log(`Processed ${result.output.recordCount} records`)
61
+ * console.log(`Processing took ${result.output.processingTime}ms`)
62
+ * }
63
+ * ```
64
+ *
65
+ * ### Accessing Execution Details
66
+ * ```typescript
67
+ * if (result.isSuccess()) {
68
+ * // Access the generated code from the final iteration
69
+ * console.log('Generated code:', result.iteration.code)
70
+ *
71
+ * // Access all iterations to see the full execution flow
72
+ * result.iterations.forEach((iteration, index) => {
73
+ * console.log(`Iteration ${index + 1}:`, iteration.status.type)
74
+ * })
75
+ *
76
+ * // Access execution context
77
+ * console.log('Original instructions:', result.context.instructions)
78
+ * }
79
+ * ```
80
+ *
81
+ * ### Snapshot Handling
82
+ * ```typescript
83
+ * if (result.isInterrupted()) {
84
+ * // Serialize snapshot for persistence
85
+ * const serialized = result.snapshot.toJSON()
86
+ * await database.saveSnapshot(serialized)
87
+ *
88
+ * // Later, resume from snapshot
89
+ * const snapshot = Snapshot.fromJSON(serialized)
90
+ * snapshot.resolve({ data: 'resolved data' })
91
+ *
92
+ * const continuation = await execute({
93
+ * snapshot,
94
+ * instructions: result.context.instructions,
95
+ * tools: result.context.tools,
96
+ * exits: result.context.exits,
97
+ * client,
98
+ * })
99
+ * }
100
+ * ```
101
+ *
102
+ * @see {@link SuccessExecutionResult} For successful execution results
103
+ * @see {@link ErrorExecutionResult} For failed execution results
104
+ * @see {@link PartialExecutionResult} For interrupted execution results
105
+ */
106
+ export declare abstract class ExecutionResult implements Serializable<ExecutionResult.JSON> {
107
+ readonly status: ExecutionStatus;
7
108
  readonly context: Context;
8
- protected constructor(status: 'success' | 'error' | 'interrupted', context: Context);
109
+ protected constructor(status: ExecutionStatus, context: Context);
110
+ /**
111
+ * Type guard to check if the execution completed successfully.
112
+ *
113
+ * @returns True if the execution completed with an Exit, false otherwise
114
+ * @example
115
+ * ```typescript
116
+ * const result = await execute({ ... })
117
+ *
118
+ * if (result.isSuccess()) {
119
+ * // TypeScript knows this is SuccessExecutionResult
120
+ * console.log('Output:', result.output)
121
+ * console.log('Exit name:', result.result.exit.name)
122
+ * }
123
+ * ```
124
+ */
9
125
  isSuccess(): this is SuccessExecutionResult;
126
+ /**
127
+ * Type guard to check if the execution failed with an error.
128
+ *
129
+ * @returns True if the execution failed with an unrecoverable error, false otherwise
130
+ * @example
131
+ * ```typescript
132
+ * const result = await execute({ ... })
133
+ *
134
+ * if (result.isError()) {
135
+ * // TypeScript knows this is ErrorExecutionResult
136
+ * console.error('Execution failed:', result.error)
137
+ *
138
+ * // Access error details from the last iteration
139
+ * const lastIteration = result.iteration
140
+ * if (lastIteration?.status.type === 'execution_error') {
141
+ * console.error('Stack trace:', lastIteration.status.execution_error.stack)
142
+ * }
143
+ * }
144
+ * ```
145
+ */
10
146
  isError(): this is ErrorExecutionResult;
147
+ /**
148
+ * Type guard to check if the execution was interrupted.
149
+ * Interrupted means there's a snapshot available and the execution was paused and needs resuming.
150
+ *
151
+ * @returns True if the execution was interrupted, false otherwise
152
+ * @example
153
+ * ```typescript
154
+ * const result = await execute({ ... })
155
+ *
156
+ * if (result.isInterrupted()) {
157
+ * // TypeScript knows this is PartialExecutionResult
158
+ * console.log('Execution paused:', result.signal.message)
159
+ *
160
+ * // Access snapshot for later resumption
161
+ * const snapshot = result.snapshot
162
+ * const serialized = snapshot.toJSON()
163
+ * await storage.save('execution-state', serialized)
164
+ * }
165
+ * ```
166
+ */
11
167
  isInterrupted(): this is PartialExecutionResult;
168
+ /**
169
+ * Type guard to check if the execution completed with a specific exit.
170
+ *
171
+ * This method provides type-safe access to the output data based on the exit's schema.
172
+ * It's the recommended way to handle different exit types in complex agents.
173
+ *
174
+ * @param exit - The Exit instance to check against
175
+ * @returns True if the execution completed with the specified exit, false otherwise
176
+ * @template T - The output type of the exit
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // Define typed exits
181
+ * const successExit = new Exit({
182
+ * name: 'success',
183
+ * schema: z.object({
184
+ * message: z.string(),
185
+ * count: z.number(),
186
+ * }),
187
+ * })
188
+ *
189
+ * const errorExit = new Exit({
190
+ * name: 'error',
191
+ * schema: z.object({
192
+ * errorCode: z.string(),
193
+ * details: z.string(),
194
+ * }),
195
+ * })
196
+ *
197
+ * const result = await execute({
198
+ * instructions: 'Process the data',
199
+ * exits: [successExit, errorExit],
200
+ * client,
201
+ * })
202
+ *
203
+ * // Type-safe exit handling
204
+ * if (result.is(successExit)) {
205
+ * // TypeScript knows result.output has { message: string, count: number }
206
+ * console.log(`Success: ${result.output.message}`)
207
+ * console.log(`Processed ${result.output.count} items`)
208
+ * } else if (result.is(errorExit)) {
209
+ * // TypeScript knows result.output has { errorCode: string, details: string }
210
+ * console.error(`Error ${result.output.errorCode}: ${result.output.details}`)
211
+ * }
212
+ * ```
213
+ */
12
214
  is<T>(exit: Exit<T>): this is SuccessExecutionResult<T>;
215
+ /**
216
+ * Gets the output data from the last successful iteration.
217
+ *
218
+ * For successful executions, returns the data produced by the exit.
219
+ * For failed or interrupted executions, returns null.
220
+ *
221
+ * @returns The output data for successful executions, null otherwise
222
+ * @example
223
+ * ```typescript
224
+ * const result = await execute({ ... })
225
+ *
226
+ * // Generic output access
227
+ * if (result.isSuccess()) {
228
+ * console.log('Output:', result.output)
229
+ * }
230
+ *
231
+ * // Type-safe output access with specific exits
232
+ * if (result.is(myExit)) {
233
+ * // result.output is now typed based on myExit's schema
234
+ * console.log(result.output.specificField)
235
+ * }
236
+ * ```
237
+ */
13
238
  get output(): unknown | null;
239
+ /**
240
+ * Gets the most recent (last) iteration from the execution.
241
+ *
242
+ * Iterations represent individual steps in the execution loop where the LLM
243
+ * generates code, executes it, and processes the results. The last iteration
244
+ * contains the final generated code and execution status.
245
+ *
246
+ * @returns The last iteration, or null if no iterations were completed
247
+ * @example
248
+ * ```typescript
249
+ * const result = await execute({ ... })
250
+ *
251
+ * const lastIteration = result.iteration
252
+ * if (lastIteration) {
253
+ * console.log('Generated code:', lastIteration.code)
254
+ * console.log('Status:', lastIteration.status.type)
255
+ * console.log('Variables:', lastIteration.variables)
256
+ * console.log('Tool calls:', lastIteration.toolCalls)
257
+ * }
258
+ * ```
259
+ */
14
260
  get iteration(): Iteration | null;
261
+ /**
262
+ * Gets all iterations from the execution.
263
+ *
264
+ * This provides access to the complete execution history, showing how the agent
265
+ * progressed through multiple iterations to reach the final result. Useful for
266
+ * debugging, logging, or understanding the agent's reasoning process.
267
+ *
268
+ * @returns Array of all iterations in execution order
269
+ * @example
270
+ * ```typescript
271
+ * const result = await execute({ ... })
272
+ *
273
+ * // Analyze the full execution flow
274
+ * result.iterations.forEach((iteration, index) => {
275
+ * console.log(`Iteration ${index + 1}:`)
276
+ * console.log(' Status:', iteration.status.type)
277
+ * console.log(' Code length:', iteration.code?.length || 0)
278
+ * console.log(' Tool calls:', iteration.toolCalls.length)
279
+ * console.log(' Variables:', Object.keys(iteration.variables).length)
280
+ * })
281
+ *
282
+ * // Find iterations with specific characteristics
283
+ * const iterationsWithErrors = result.iterations.filter(
284
+ * iter => iter.status.type === 'execution_error'
285
+ * )
286
+ *
287
+ * // Calculate total execution time
288
+ * const totalTime = result.iterations.reduce(
289
+ * (sum, iter) => sum + (iter.duration || 0), 0
290
+ * )
291
+ * ```
292
+ */
15
293
  get iterations(): Iteration[];
294
+ abstract toJSON(): ExecutionResult.JSON;
295
+ }
296
+ export declare namespace SuccessExecutionResult {
297
+ type JSON = {
298
+ status: 'success';
299
+ context: Context.JSON;
300
+ result: {
301
+ exit: Exit.JSON;
302
+ result: unknown;
303
+ };
304
+ };
16
305
  }
17
- export declare class SuccessExecutionResult<TOutput = unknown> extends ExecutionResult {
306
+ /**
307
+ * Result for successful executions that completed with an Exit.
308
+ *
309
+ * SuccessExecutionResult indicates that the agent successfully completed its task
310
+ * and returned structured data through one of the provided exits. This is the
311
+ * most common positive outcome for LLMz executions.
312
+ *
313
+ * In *Worker Mode* (ie. no `chat` provided), if no exits were provided, the "DefaultExit" will be used.
314
+ * If *Chat Mode* is enabled, most likely the "ListenExit" will be used if no exits were provided.
315
+ *
316
+ * You can check for a specific exit using the `is()` method, which provides type-safe access to the output data of the exit.
317
+ * You can import "ListenExit" and "DefaultExit" from `llmz`.
318
+ *
319
+ * @template TOutput - The type of the output data based on the exit schema
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * import { execute, Exit, DefaultExit, ListenExit } from 'llmz'
324
+ *
325
+ * const exit = new Exit({
326
+ * name: 'dataProcessed',
327
+ * schema: z.object({
328
+ * recordCount: z.number(),
329
+ * summary: z.string(),
330
+ * }),
331
+ * })
332
+ *
333
+ * const result = await execute({
334
+ * instructions: 'Process the user data',
335
+ * exits: [exit],
336
+ * client,
337
+ * })
338
+ *
339
+ * if (result.isSuccess() && result.is(exit)) {
340
+ * // Access the exit information
341
+ * console.log('Exit name:', result.result.exit.name)
342
+ *
343
+ * // Access typed output data
344
+ * console.log('Records processed:', result.output.recordCount)
345
+ * console.log('Summary:', result.output.summary)
346
+ *
347
+ * // Access the final iteration (guaranteed to exist)
348
+ * console.log('Generated code:', result.iteration.code)
349
+ * }
350
+ * ```
351
+ */
352
+ export declare class SuccessExecutionResult<TOutput = unknown> extends ExecutionResult implements Serializable<SuccessExecutionResult.JSON> {
18
353
  readonly result: ExitResult<TOutput>;
19
354
  constructor(context: Context, result: ExitResult<TOutput>);
355
+ /**
356
+ * Gets the typed output data from the successful execution.
357
+ *
358
+ * This overrides the base class output property to provide proper typing
359
+ * based on the exit schema. The output is guaranteed to match the schema
360
+ * of the exit that was triggered.
361
+ *
362
+ * @returns The typed output data
363
+ */
20
364
  get output(): TOutput;
365
+ /**
366
+ * Gets the final iteration from the successful execution.
367
+ *
368
+ * For successful executions, there is always at least one iteration,
369
+ * so this method returns the guaranteed non-null final iteration.
370
+ *
371
+ * @returns The final iteration (guaranteed to exist)
372
+ */
21
373
  get iteration(): Iteration;
374
+ /**
375
+ * Serializes the execution result to JSON.
376
+ *
377
+ * This method converts the execution result into a JSON format that includes
378
+ * the execution status, context, and exit information. It is used for serialization
379
+ * and transmission of the execution result.
380
+ *
381
+ * @returns The JSON representation of the execution result.
382
+ */
383
+ toJSON(): {
384
+ status: "success";
385
+ context: {
386
+ id: string;
387
+ iterations: {
388
+ id: string;
389
+ messages: import("./index.js").LLMzPrompts.Message[];
390
+ code: string | undefined;
391
+ traces: import("./types.js").Traces.Trace[];
392
+ variables: Record<string, any>;
393
+ started_ts: number;
394
+ ended_ts: number | undefined;
395
+ status: import("./context.js").IterationStatus;
396
+ mutations: import("./types.js").ObjectMutation[];
397
+ llm: {
398
+ started_at: number;
399
+ ended_at: number;
400
+ status: "success" | "error";
401
+ cached: boolean;
402
+ tokens: number;
403
+ spend: number;
404
+ output: string;
405
+ model: string;
406
+ } | undefined;
407
+ transcript: import("./transcript.js").Transcript.Message[];
408
+ tools: {
409
+ name: string;
410
+ aliases: string[];
411
+ description: string | undefined;
412
+ metadata: Record<string, unknown>;
413
+ input: import("json-schema").JSONSchema7 | undefined;
414
+ output: import("json-schema").JSONSchema7 | undefined;
415
+ staticInputValues: unknown;
416
+ maxRetries: number;
417
+ }[];
418
+ objects: {
419
+ name: string;
420
+ description: string | undefined;
421
+ properties: import("./objects.js").ObjectProperty[] | undefined;
422
+ tools: {
423
+ name: string;
424
+ aliases: string[];
425
+ description: string | undefined;
426
+ metadata: Record<string, unknown>;
427
+ input: import("json-schema").JSONSchema7 | undefined;
428
+ output: import("json-schema").JSONSchema7 | undefined;
429
+ staticInputValues: unknown;
430
+ maxRetries: number;
431
+ }[];
432
+ metadata: Record<string, unknown> | undefined;
433
+ }[];
434
+ exits: {
435
+ name: string;
436
+ aliases: string[];
437
+ description: string;
438
+ metadata: {
439
+ [x: string]: unknown;
440
+ };
441
+ schema: import("json-schema").JSONSchema7 | undefined;
442
+ }[];
443
+ instructions: string | undefined;
444
+ duration: string;
445
+ error: string | null;
446
+ isChatEnabled: boolean;
447
+ }[];
448
+ iteration: number;
449
+ timeout: number;
450
+ loop: number;
451
+ temperature: number;
452
+ model: "best" | "fast" | `${string}:${string}` | undefined;
453
+ metadata: Record<string, any>;
454
+ snapshot: {
455
+ id: string;
456
+ reason: string | undefined;
457
+ stack: string;
458
+ variables: ({
459
+ name: string;
460
+ type: string;
461
+ bytes: number;
462
+ preview?: string;
463
+ value?: unknown;
464
+ truncated: boolean;
465
+ } & ({
466
+ truncated: true;
467
+ preview: string;
468
+ } | {
469
+ truncated: false;
470
+ value: unknown;
471
+ }))[];
472
+ toolCall: import("./errors.js").ToolCall | undefined;
473
+ status: import("./snapshots.js").SnapshotStatus;
474
+ } | undefined;
475
+ };
476
+ result: {
477
+ exit: {
478
+ name: string;
479
+ aliases: string[];
480
+ description: string;
481
+ metadata: {
482
+ [x: string]: unknown;
483
+ };
484
+ schema: import("json-schema").JSONSchema7 | undefined;
485
+ };
486
+ result: TOutput;
487
+ };
488
+ };
22
489
  }
23
- export declare class ErrorExecutionResult extends ExecutionResult {
490
+ export declare namespace ErrorExecutionResult {
491
+ type JSON = {
492
+ status: 'error';
493
+ context: Context.JSON;
494
+ error: unknown;
495
+ };
496
+ }
497
+ /**
498
+ * Result for executions that failed with an unrecoverable error.
499
+ *
500
+ * ErrorExecutionResult indicates that the execution encountered an error that could not be recovered from, such as:
501
+ * - Execution has been aborted by the user (eg. via the `signal` AbortSignal parameter)
502
+ * - Iterations exceeded the maximum allowed limit
503
+ *
504
+ * Upon iteration failure, the execution will continue until the maximum iteration limit is reached or an exit is triggered.
505
+ *
506
+ * @example
507
+ * ```typescript
508
+ * const result = await execute({
509
+ * instructions: 'Call a non-existent function',
510
+ * client,
511
+ * })
512
+ *
513
+ * if (result.isError()) {
514
+ * console.error('Execution failed:', result.error)
515
+ *
516
+ * // Access error details from the last iteration
517
+ * const lastIteration = result.iteration
518
+ * if (lastIteration?.status.type === 'execution_error') {
519
+ * console.error('Error type:', lastIteration.status.execution_error.type)
520
+ * console.error('Stack trace:', lastIteration.status.execution_error.stack)
521
+ * console.error('Generated code:', lastIteration.code)
522
+ * }
523
+ *
524
+ * // Access all iterations to understand the failure progression
525
+ * console.log('Total iterations before failure:', result.iterations.length)
526
+ * }
527
+ * ```
528
+ */
529
+ export declare class ErrorExecutionResult extends ExecutionResult implements Serializable<ErrorExecutionResult.JSON> {
24
530
  readonly error: unknown;
25
531
  constructor(context: Context, error: unknown);
532
+ /**
533
+ * Gets the output data (always null for error results).
534
+ *
535
+ * @returns Always null since error executions don't produce output
536
+ */
26
537
  get output(): null;
538
+ toJSON(): {
539
+ status: "error";
540
+ context: {
541
+ id: string;
542
+ iterations: {
543
+ id: string;
544
+ messages: import("./index.js").LLMzPrompts.Message[];
545
+ code: string | undefined;
546
+ traces: import("./types.js").Traces.Trace[];
547
+ variables: Record<string, any>;
548
+ started_ts: number;
549
+ ended_ts: number | undefined;
550
+ status: import("./context.js").IterationStatus;
551
+ mutations: import("./types.js").ObjectMutation[];
552
+ llm: {
553
+ started_at: number;
554
+ ended_at: number;
555
+ status: "success" | "error";
556
+ cached: boolean;
557
+ tokens: number;
558
+ spend: number;
559
+ output: string;
560
+ model: string;
561
+ } | undefined;
562
+ transcript: import("./transcript.js").Transcript.Message[];
563
+ tools: {
564
+ name: string;
565
+ aliases: string[];
566
+ description: string | undefined;
567
+ metadata: Record<string, unknown>;
568
+ input: import("json-schema").JSONSchema7 | undefined;
569
+ output: import("json-schema").JSONSchema7 | undefined;
570
+ staticInputValues: unknown;
571
+ maxRetries: number;
572
+ }[];
573
+ objects: {
574
+ name: string;
575
+ description: string | undefined;
576
+ properties: import("./objects.js").ObjectProperty[] | undefined;
577
+ tools: {
578
+ name: string;
579
+ aliases: string[];
580
+ description: string | undefined;
581
+ metadata: Record<string, unknown>;
582
+ input: import("json-schema").JSONSchema7 | undefined;
583
+ output: import("json-schema").JSONSchema7 | undefined;
584
+ staticInputValues: unknown;
585
+ maxRetries: number;
586
+ }[];
587
+ metadata: Record<string, unknown> | undefined;
588
+ }[];
589
+ exits: {
590
+ name: string;
591
+ aliases: string[];
592
+ description: string;
593
+ metadata: {
594
+ [x: string]: unknown;
595
+ };
596
+ schema: import("json-schema").JSONSchema7 | undefined;
597
+ }[];
598
+ instructions: string | undefined;
599
+ duration: string;
600
+ error: string | null;
601
+ isChatEnabled: boolean;
602
+ }[];
603
+ iteration: number;
604
+ timeout: number;
605
+ loop: number;
606
+ temperature: number;
607
+ model: "best" | "fast" | `${string}:${string}` | undefined;
608
+ metadata: Record<string, any>;
609
+ snapshot: {
610
+ id: string;
611
+ reason: string | undefined;
612
+ stack: string;
613
+ variables: ({
614
+ name: string;
615
+ type: string;
616
+ bytes: number;
617
+ preview?: string;
618
+ value?: unknown;
619
+ truncated: boolean;
620
+ } & ({
621
+ truncated: true;
622
+ preview: string;
623
+ } | {
624
+ truncated: false;
625
+ value: unknown;
626
+ }))[];
627
+ toolCall: import("./errors.js").ToolCall | undefined;
628
+ status: import("./snapshots.js").SnapshotStatus;
629
+ } | undefined;
630
+ };
631
+ error: unknown;
632
+ };
633
+ }
634
+ export declare namespace PartialExecutionResult {
635
+ type JSON = {
636
+ status: 'interrupted';
637
+ context: Context.JSON;
638
+ snapshot: Snapshot.JSON;
639
+ signal: {
640
+ message: string;
641
+ truncatedCode?: string;
642
+ variables: Record<string, any>;
643
+ };
644
+ };
27
645
  }
28
- export declare class PartialExecutionResult extends ExecutionResult {
646
+ /**
647
+ * Result for executions that were interrupted before completion.
648
+ *
649
+ * PartialExecutionResult indicates that a snapshot was created during the execution.
650
+ * Interrupted executions can be resumed using the provided snapshot.
651
+ *
652
+ * @example
653
+ * ```typescript
654
+ * // Tool that throws SnapshotSignal for long-running operations
655
+ * const longRunningTool = new Tool({
656
+ * name: 'processLargeDataset',
657
+ * async handler({ datasetId }) {
658
+ * // Start background processing
659
+ * const jobId = await startBackgroundJob(datasetId)
660
+ *
661
+ * // Pause execution until job completes
662
+ * throw new SnapshotSignal('Processing dataset', 'Waiting for background job completion', {
663
+ * jobId,
664
+ * datasetId,
665
+ * startTime: Date.now(),
666
+ * })
667
+ * },
668
+ * })
669
+ *
670
+ * const result = await execute({
671
+ * instructions: 'Process the large dataset',
672
+ * tools: [longRunningTool],
673
+ * client,
674
+ * })
675
+ *
676
+ * if (result.isInterrupted()) {
677
+ * console.log('Execution paused:', result.signal.message)
678
+ * console.log('Reason:', result.signal.longMessage)
679
+ *
680
+ * // Serialize snapshot for later resumption
681
+ * const serialized = result.snapshot.toJSON()
682
+ * await database.saveSnapshot('job-123', serialized)
683
+ *
684
+ * // Later, when the background job completes...
685
+ * const snapshot = Snapshot.fromJSON(serialized)
686
+ * snapshot.resolve({ jobResult: 'Processing completed successfully' })
687
+ *
688
+ * const continuation = await execute({
689
+ * snapshot,
690
+ * instructions: result.context.instructions,
691
+ * tools: result.context.tools,
692
+ * exits: result.context.exits,
693
+ * client,
694
+ * })
695
+ * }
696
+ * ```
697
+ */
698
+ export declare class PartialExecutionResult extends ExecutionResult implements Serializable<PartialExecutionResult.JSON> {
29
699
  readonly signal: SnapshotSignal;
30
700
  readonly snapshot: Snapshot;
31
701
  constructor(context: Context, signal: SnapshotSignal, snapshot: Snapshot);
702
+ /**
703
+ * Gets the output data (always null for interrupted results).
704
+ *
705
+ * @returns Always null since interrupted executions don't produce final output
706
+ */
32
707
  get output(): null;
708
+ /**
709
+ * Serializes the execution result to JSON.
710
+ *
711
+ * @returns The JSON representation of the execution result.
712
+ */
713
+ toJSON(): {
714
+ status: "interrupted";
715
+ context: {
716
+ id: string;
717
+ iterations: {
718
+ id: string;
719
+ messages: import("./index.js").LLMzPrompts.Message[];
720
+ code: string | undefined;
721
+ traces: import("./types.js").Traces.Trace[];
722
+ variables: Record<string, any>;
723
+ started_ts: number;
724
+ ended_ts: number | undefined;
725
+ status: import("./context.js").IterationStatus;
726
+ mutations: import("./types.js").ObjectMutation[];
727
+ llm: {
728
+ started_at: number;
729
+ ended_at: number;
730
+ status: "success" | "error";
731
+ cached: boolean;
732
+ tokens: number;
733
+ spend: number;
734
+ output: string;
735
+ model: string;
736
+ } | undefined;
737
+ transcript: import("./transcript.js").Transcript.Message[];
738
+ tools: {
739
+ name: string;
740
+ aliases: string[];
741
+ description: string | undefined;
742
+ metadata: Record<string, unknown>;
743
+ input: import("json-schema").JSONSchema7 | undefined;
744
+ output: import("json-schema").JSONSchema7 | undefined;
745
+ staticInputValues: unknown;
746
+ maxRetries: number;
747
+ }[];
748
+ objects: {
749
+ name: string;
750
+ description: string | undefined;
751
+ properties: import("./objects.js").ObjectProperty[] | undefined;
752
+ tools: {
753
+ name: string;
754
+ aliases: string[];
755
+ description: string | undefined;
756
+ metadata: Record<string, unknown>;
757
+ input: import("json-schema").JSONSchema7 | undefined;
758
+ output: import("json-schema").JSONSchema7 | undefined;
759
+ staticInputValues: unknown;
760
+ maxRetries: number;
761
+ }[];
762
+ metadata: Record<string, unknown> | undefined;
763
+ }[];
764
+ exits: {
765
+ name: string;
766
+ aliases: string[];
767
+ description: string;
768
+ metadata: {
769
+ [x: string]: unknown;
770
+ };
771
+ schema: import("json-schema").JSONSchema7 | undefined;
772
+ }[];
773
+ instructions: string | undefined;
774
+ duration: string;
775
+ error: string | null;
776
+ isChatEnabled: boolean;
777
+ }[];
778
+ iteration: number;
779
+ timeout: number;
780
+ loop: number;
781
+ temperature: number;
782
+ model: "best" | "fast" | `${string}:${string}` | undefined;
783
+ metadata: Record<string, any>;
784
+ snapshot: {
785
+ id: string;
786
+ reason: string | undefined;
787
+ stack: string;
788
+ variables: ({
789
+ name: string;
790
+ type: string;
791
+ bytes: number;
792
+ preview?: string;
793
+ value?: unknown;
794
+ truncated: boolean;
795
+ } & ({
796
+ truncated: true;
797
+ preview: string;
798
+ } | {
799
+ truncated: false;
800
+ value: unknown;
801
+ }))[];
802
+ toolCall: import("./errors.js").ToolCall | undefined;
803
+ status: import("./snapshots.js").SnapshotStatus;
804
+ } | undefined;
805
+ };
806
+ snapshot: {
807
+ id: string;
808
+ reason: string | undefined;
809
+ stack: string;
810
+ variables: ({
811
+ name: string;
812
+ type: string;
813
+ bytes: number;
814
+ preview?: string;
815
+ value?: unknown;
816
+ truncated: boolean;
817
+ } & ({
818
+ truncated: true;
819
+ preview: string;
820
+ } | {
821
+ truncated: false;
822
+ value: unknown;
823
+ }))[];
824
+ toolCall: import("./errors.js").ToolCall | undefined;
825
+ status: import("./snapshots.js").SnapshotStatus;
826
+ };
827
+ signal: {
828
+ message: string;
829
+ truncatedCode: string;
830
+ variables: {
831
+ [key: string]: any;
832
+ };
833
+ };
834
+ };
33
835
  }
836
+ export {};