llmz 0.0.31 → 0.0.33

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTypings
3
- } from "./chunk-IUE5BW56.js";
3
+ } from "./chunk-U4HWJLF2.js";
4
4
  import {
5
5
  convertObjectToZuiLiterals,
6
6
  isJsonSchema,
@@ -5,10 +5,10 @@ import {
5
5
  } from "./chunk-AAHUDKBY.js";
6
6
  import {
7
7
  Tool
8
- } from "./chunk-RC6YO5UW.js";
8
+ } from "./chunk-23SY6IDW.js";
9
9
  import {
10
10
  LoopExceededError
11
- } from "./chunk-MYLTD5WT.js";
11
+ } from "./chunk-WSVDMGMR.js";
12
12
  import {
13
13
  Exit
14
14
  } from "./chunk-VPTFUOIK.js";
@@ -972,6 +972,9 @@ var Iteration = class {
972
972
  get model() {
973
973
  return this._parameters.model;
974
974
  }
975
+ set model(value) {
976
+ this._parameters.model = value;
977
+ }
975
978
  get temperature() {
976
979
  return this._parameters.temperature;
977
980
  }
@@ -5,10 +5,10 @@
5
5
  var _chunk5BEKU5MZcjs = require('./chunk-5BEKU5MZ.cjs');
6
6
 
7
7
 
8
- var _chunkJ57224PDcjs = require('./chunk-J57224PD.cjs');
8
+ var _chunkSOEKWFU2cjs = require('./chunk-SOEKWFU2.cjs');
9
9
 
10
10
 
11
- var _chunkT63Y6GTWcjs = require('./chunk-T63Y6GTW.cjs');
11
+ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
12
12
 
13
13
 
14
14
  var _chunk3G3BS5IAcjs = require('./chunk-3G3BS5IA.cjs');
@@ -972,6 +972,9 @@ var Iteration = class {
972
972
  get model() {
973
973
  return this._parameters.model;
974
974
  }
975
+ set model(value) {
976
+ this._parameters.model = value;
977
+ }
975
978
  get temperature() {
976
979
  return this._parameters.temperature;
977
980
  }
@@ -1093,7 +1096,7 @@ var Context = (_class2 = class {
1093
1096
 
1094
1097
  async nextIteration() {
1095
1098
  if (this.iterations.length >= this.loop) {
1096
- throw new (0, _chunkT63Y6GTWcjs.LoopExceededError)();
1099
+ throw new (0, _chunkPK72FAKDcjs.LoopExceededError)();
1097
1100
  }
1098
1101
  if (this.snapshot && this.snapshot.status.type === "pending") {
1099
1102
  throw new Error(
@@ -1251,7 +1254,7 @@ var Context = (_class2 = class {
1251
1254
  var _a, _b;
1252
1255
  const instructions = await getValue(this.instructions, this);
1253
1256
  const transcript = new TranscriptArray(await getValue(_nullishCoalesce(((_a = this.chat) == null ? void 0 : _a.transcript), () => ( [])), this));
1254
- const tools = _chunkJ57224PDcjs.Tool.withUniqueNames(await _asyncNullishCoalesce(await getValue(this.tools, this), async () => ( [])));
1257
+ const tools = _chunkSOEKWFU2cjs.Tool.withUniqueNames(await _asyncNullishCoalesce(await getValue(this.tools, this), async () => ( [])));
1255
1258
  const objects = await _asyncNullishCoalesce(await getValue(this.objects, this), async () => ( []));
1256
1259
  const exits = await _asyncNullishCoalesce(await getValue(this.exits, this), async () => ( []));
1257
1260
  const components = await getValue(_nullishCoalesce(((_b = this.chat) == null ? void 0 : _b.components), () => ( [])), this);
@@ -1283,7 +1286,7 @@ var Context = (_class2 = class {
1283
1286
  "boolean",
1284
1287
  "array"
1285
1288
  ];
1286
- const MessageTool = this.chat && components.length ? new (0, _chunkJ57224PDcjs.Tool)({
1289
+ const MessageTool = this.chat && components.length ? new (0, _chunkSOEKWFU2cjs.Tool)({
1287
1290
  name: "Message",
1288
1291
  description: "Send a message to the user",
1289
1292
  aliases: Array.from(
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkT63Y6GTWcjs = require('./chunk-T63Y6GTW.cjs');
7
+ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
8
8
 
9
9
 
10
10
  var _chunkKIN7Y247cjs = require('./chunk-KIN7Y247.cjs');
@@ -2960,7 +2960,7 @@ function getCompiledCode(code, traces = []) {
2960
2960
  code,
2961
2961
  started_at: Date.now()
2962
2962
  });
2963
- throw new (0, _chunkT63Y6GTWcjs.InvalidCodeError)(err.message, code);
2963
+ throw new (0, _chunkPK72FAKDcjs.InvalidCodeError)(err.message, code);
2964
2964
  }
2965
2965
  }
2966
2966
  async function runAsyncFunction(context, code, traces = [], signal = null, timeout = MAX_VM_EXECUTION_TIME) {
@@ -3036,8 +3036,8 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
3036
3036
  let currentToolCall;
3037
3037
  context[Identifiers.ToolCallTrackerFnIdentifier] = (callId, type, outputOrError) => {
3038
3038
  var _a2;
3039
- const temp = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
3040
- if (type === "end" && temp instanceof _chunkT63Y6GTWcjs.SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
3039
+ const temp = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
3040
+ if (type === "end" && temp instanceof _chunkPK72FAKDcjs.SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
3041
3041
  currentToolCall = {
3042
3042
  ...temp.toolCall,
3043
3043
  assignment: (_a2 = transformed.toolCalls.get(callId)) == null ? void 0 : _a2.assignment
@@ -3535,8 +3535,8 @@ ${transformed.code}
3535
3535
  const errorStackResult = vm.evalCode("globalThis.__llmz_error_stack");
3536
3536
  const errorStack = vm.dump(errorStackResult.unwrap()) || "";
3537
3537
  errorStackResult.unwrap().dispose();
3538
- const deserializedError = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(errorValue);
3539
- if (deserializedError instanceof _chunkT63Y6GTWcjs.VMSignal) {
3538
+ const deserializedError = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(errorValue);
3539
+ if (deserializedError instanceof _chunkPK72FAKDcjs.VMSignal) {
3540
3540
  deserializedError.stack = errorStack;
3541
3541
  throw deserializedError;
3542
3542
  }
@@ -3554,11 +3554,11 @@ ${transformed.code}
3554
3554
  returnValue = vm.dump(resultResult.unwrap());
3555
3555
  resultResult.unwrap().dispose();
3556
3556
  }
3557
- returnValue = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(returnValue);
3557
+ returnValue = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(returnValue);
3558
3558
  return {
3559
3559
  success: true,
3560
3560
  variables: _chunkUQOBUJIQcjs.mapValues_default.call(void 0, variables, (getter) => _chunkUQOBUJIQcjs.isFunction_default.call(void 0, getter) ? getter() : getter),
3561
- signal: returnValue instanceof _chunkT63Y6GTWcjs.VMSignal ? returnValue : void 0,
3561
+ signal: returnValue instanceof _chunkPK72FAKDcjs.VMSignal ? returnValue : void 0,
3562
3562
  lines_executed: Array.from(lines_executed),
3563
3563
  return_value: returnValue
3564
3564
  };
@@ -3657,8 +3657,8 @@ ${transformed.code}
3657
3657
  let currentToolCall;
3658
3658
  context[Identifiers.ToolCallTrackerFnIdentifier] = (callId, type, outputOrError) => {
3659
3659
  var _a2;
3660
- const temp = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
3661
- if (type === "end" && temp instanceof _chunkT63Y6GTWcjs.SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
3660
+ const temp = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
3661
+ if (type === "end" && temp instanceof _chunkPK72FAKDcjs.SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
3662
3662
  currentToolCall = {
3663
3663
  ...temp.toolCall,
3664
3664
  assignment: (_a2 = transformed.toolCalls.get(callId)) == null ? void 0 : _a2.assignment
@@ -3712,11 +3712,11 @@ ${transformed.code}
3712
3712
  await context[Identifiers.AsyncIterYieldFnIdentifier](value);
3713
3713
  } while (true);
3714
3714
  })().then((res) => {
3715
- res = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(res);
3715
+ res = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(res);
3716
3716
  return {
3717
3717
  success: true,
3718
3718
  variables: _chunkUQOBUJIQcjs.mapValues_default.call(void 0, variables, (getter) => _chunkUQOBUJIQcjs.isFunction_default.call(void 0, getter) ? getter() : getter),
3719
- signal: res instanceof _chunkT63Y6GTWcjs.VMSignal ? res : void 0,
3719
+ signal: res instanceof _chunkPK72FAKDcjs.VMSignal ? res : void 0,
3720
3720
  lines_executed: Array.from(lines_executed),
3721
3721
  return_value: res
3722
3722
  };
@@ -3726,7 +3726,7 @@ ${transformed.code}
3726
3726
  }
3727
3727
  var handleErrorQuickJS = (err, code, _consumer, traces, variables, lines_executed, userCodeStartLine, currentToolCall) => {
3728
3728
  var _a, _b, _c;
3729
- err = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(err);
3729
+ err = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(err);
3730
3730
  const lines = code.split("\n");
3731
3731
  const stackTrace = err.stack || "";
3732
3732
  const LINE_OFFSET = 1;
@@ -3785,7 +3785,7 @@ var handleErrorQuickJS = (err, code, _consumer, traces, variables, lines_execute
3785
3785
  }
3786
3786
  debugUserCode = _chunkKIN7Y247cjs.cleanStackTrace.call(void 0, debugUserCode).trim();
3787
3787
  truncatedCode = _chunkKIN7Y247cjs.cleanStackTrace.call(void 0, truncatedCode).trim();
3788
- if (err instanceof _chunkT63Y6GTWcjs.VMSignal) {
3788
+ if (err instanceof _chunkPK72FAKDcjs.VMSignal) {
3789
3789
  const signalError = err;
3790
3790
  signalError.stack = debugUserCode;
3791
3791
  signalError.truncatedCode = truncatedCode;
@@ -3805,8 +3805,8 @@ var handleErrorQuickJS = (err, code, _consumer, traces, variables, lines_execute
3805
3805
  stackTrace: debugUserCode,
3806
3806
  started_at: Date.now()
3807
3807
  });
3808
- const codeError = new (0, _chunkT63Y6GTWcjs.CodeExecutionError)(err.message, code, debugUserCode);
3809
- const deserializedError = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(codeError);
3808
+ const codeError = new (0, _chunkPK72FAKDcjs.CodeExecutionError)(err.message, code, debugUserCode);
3809
+ const deserializedError = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(codeError);
3810
3810
  return {
3811
3811
  success: false,
3812
3812
  variables: _chunkUQOBUJIQcjs.mapValues_default.call(void 0, variables, (getter) => _chunkUQOBUJIQcjs.isFunction_default.call(void 0, getter) ? getter() : getter),
@@ -3818,7 +3818,7 @@ var handleErrorQuickJS = (err, code, _consumer, traces, variables, lines_execute
3818
3818
  };
3819
3819
  var handleErrorNode = (err, code, consumer, traces, variables, _lines_executed, currentToolCall) => {
3820
3820
  var _a, _b, _c;
3821
- err = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(err);
3821
+ err = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(err);
3822
3822
  const lines = code.split("\n");
3823
3823
  const stackTrace = err.stack || "";
3824
3824
  const LINE_OFFSET = 1;
@@ -3869,7 +3869,7 @@ var handleErrorNode = (err, code, consumer, traces, variables, _lines_executed,
3869
3869
  }
3870
3870
  debugUserCode = _chunkKIN7Y247cjs.cleanStackTrace.call(void 0, debugUserCode).trim();
3871
3871
  truncatedCode = _chunkKIN7Y247cjs.cleanStackTrace.call(void 0, truncatedCode).trim();
3872
- if (err instanceof _chunkT63Y6GTWcjs.VMSignal) {
3872
+ if (err instanceof _chunkPK72FAKDcjs.VMSignal) {
3873
3873
  err.stack = debugUserCode;
3874
3874
  err.truncatedCode = truncatedCode;
3875
3875
  err.variables = _chunkUQOBUJIQcjs.mapValues_default.call(void 0, variables, (getter) => _chunkUQOBUJIQcjs.isFunction_default.call(void 0, getter) ? getter() : getter);
@@ -3883,16 +3883,16 @@ var handleErrorNode = (err, code, consumer, traces, variables, _lines_executed,
3883
3883
  stackTrace: debugUserCode,
3884
3884
  started_at: Date.now()
3885
3885
  });
3886
- throw new (0, _chunkT63Y6GTWcjs.CodeExecutionError)(err.message, code, debugUserCode);
3886
+ throw new (0, _chunkPK72FAKDcjs.CodeExecutionError)(err.message, code, debugUserCode);
3887
3887
  }
3888
3888
  };
3889
3889
  var handleCatch = (err, traces, variables, lines_executed) => {
3890
- err = _chunkT63Y6GTWcjs.Signals.maybeDeserializeError(err);
3890
+ err = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(err);
3891
3891
  return {
3892
- success: err instanceof _chunkT63Y6GTWcjs.VMSignal ? true : false,
3892
+ success: err instanceof _chunkPK72FAKDcjs.VMSignal ? true : false,
3893
3893
  variables: _chunkUQOBUJIQcjs.mapValues_default.call(void 0, variables, (getter) => _chunkUQOBUJIQcjs.isFunction_default.call(void 0, getter) ? getter() : getter),
3894
3894
  error: err,
3895
- signal: err instanceof _chunkT63Y6GTWcjs.VMSignal ? err : void 0,
3895
+ signal: err instanceof _chunkPK72FAKDcjs.VMSignal ? err : void 0,
3896
3896
  traces,
3897
3897
  lines_executed: Array.from(lines_executed)
3898
3898
  };
@@ -4,7 +4,7 @@ import {
4
4
  Signals,
5
5
  SnapshotSignal,
6
6
  VMSignal
7
- } from "./chunk-MYLTD5WT.js";
7
+ } from "./chunk-WSVDMGMR.js";
8
8
  import {
9
9
  cleanStackTrace
10
10
  } from "./chunk-YEAWWJSJ.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkT63Y6GTWcjs = require('./chunk-T63Y6GTW.cjs');
3
+ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
4
4
 
5
5
 
6
6
 
@@ -38,7 +38,7 @@ async function formatTypings(typings, options) {
38
38
  return result;
39
39
  } catch (err) {
40
40
  if (options == null ? void 0 : options.throwOnError) {
41
- throw new (0, _chunkT63Y6GTWcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
41
+ throw new (0, _chunkPK72FAKDcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
42
42
  }
43
43
  return typings;
44
44
  }
@@ -96,10 +96,11 @@ var VMLoopSignal = class extends VMSignal {
96
96
  }
97
97
  };
98
98
  var ThinkSignal = class extends VMLoopSignal {
99
- constructor(reason, context) {
99
+ constructor(reason, context, metadata) {
100
100
  super("Think signal received: " + reason);
101
101
  this.reason = reason;
102
102
  this.context = context;
103
+ this.metadata = metadata;
103
104
  this.message = Signals.serializeError(this);
104
105
  this.stack = "";
105
106
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
2
 
3
- var _chunkRLOPQZTQcjs = require('./chunk-RLOPQZTQ.cjs');
3
+ var _chunkINDOGCAQcjs = require('./chunk-INDOGCAQ.cjs');
4
4
 
5
5
 
6
6
 
@@ -476,7 +476,7 @@ var Tool = (_class = class _Tool {
476
476
  input = _chunkWHNOR4ZUcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
477
477
  }
478
478
  const fnType = _zui.z.function(input, _zui.z.promise(output)).title(this.name).describe(_nullishCoalesce(this.description, () => ( "")));
479
- return _chunkRLOPQZTQcjs.getTypings.call(void 0, fnType, {
479
+ return _chunkINDOGCAQcjs.getTypings.call(void 0, fnType, {
480
480
  declaration: true
481
481
  });
482
482
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CodeFormattingError
3
- } from "./chunk-MYLTD5WT.js";
3
+ } from "./chunk-WSVDMGMR.js";
4
4
  import {
5
5
  escapeString,
6
6
  getMultilineComment,
@@ -96,10 +96,11 @@ var VMLoopSignal = class extends VMSignal {
96
96
  }
97
97
  };
98
98
  var ThinkSignal = class extends VMLoopSignal {
99
- constructor(reason, context) {
99
+ constructor(reason, context, metadata) {
100
100
  super("Think signal received: " + reason);
101
101
  this.reason = reason;
102
102
  this.context = context;
103
+ this.metadata = metadata;
103
104
  this.message = Signals.serializeError(this);
104
105
  this.stack = "";
105
106
  }
package/dist/context.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare namespace IterationStatuses {
50
50
  thinking_requested: {
51
51
  reason?: string;
52
52
  variables: Record<string, unknown>;
53
+ metadata?: Record<string, unknown>;
53
54
  };
54
55
  };
55
56
  type Callback = {
@@ -351,6 +352,7 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
351
352
  get tools(): Tool<import("./types.js").ZuiType, import("./types.js").ZuiType>[];
352
353
  get objects(): ObjectInstance[];
353
354
  get model(): Models | Models[];
355
+ set model(value: Models | Models[]);
354
356
  get temperature(): number;
355
357
  get exits(): Exit<unknown>[];
356
358
  get instructions(): string | undefined;
@@ -363,6 +365,12 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
363
365
  spend: number;
364
366
  output: string;
365
367
  model: string;
368
+ usage: {
369
+ inputCost: number;
370
+ outputCost: number;
371
+ inputTokens: number;
372
+ outputTokens: number;
373
+ };
366
374
  };
367
375
  hasExited(this: this): this is this & {
368
376
  status: IterationStatuses.ExitSuccess;
@@ -407,6 +415,12 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
407
415
  spend: number;
408
416
  output: string;
409
417
  model: string;
418
+ usage: {
419
+ inputCost: number;
420
+ outputCost: number;
421
+ inputTokens: number;
422
+ outputTokens: number;
423
+ };
410
424
  } | undefined;
411
425
  transcript: Transcript.Message[];
412
426
  tools: {
@@ -517,6 +531,12 @@ export declare class Context implements Serializable<Context.JSON> {
517
531
  spend: number;
518
532
  output: string;
519
533
  model: string;
534
+ usage: {
535
+ inputCost: number;
536
+ outputCost: number;
537
+ inputTokens: number;
538
+ outputTokens: number;
539
+ };
520
540
  } | undefined;
521
541
  transcript: Transcript.Message[];
522
542
  tools: {
package/dist/errors.d.ts CHANGED
@@ -40,7 +40,8 @@ export declare class VMLoopSignal extends VMSignal {
40
40
  export declare class ThinkSignal extends VMLoopSignal {
41
41
  reason: string;
42
42
  context?: any;
43
- constructor(reason: string, context?: any);
43
+ metadata?: Record<string, unknown> | undefined;
44
+ constructor(reason: string, context?: any, metadata?: Record<string, unknown> | undefined);
44
45
  toString(): string;
45
46
  }
46
47
  export declare class CodeExecutionError extends Error {
package/dist/index.cjs CHANGED
@@ -9,21 +9,21 @@
9
9
 
10
10
 
11
11
 
12
- var _chunk66NCLCNTcjs = require('./chunk-66NCLCNT.cjs');
12
+ var _chunk4XIOQWVZcjs = require('./chunk-4XIOQWVZ.cjs');
13
13
  require('./chunk-5BEKU5MZ.cjs');
14
14
 
15
15
 
16
- var _chunkJ57224PDcjs = require('./chunk-J57224PD.cjs');
16
+ var _chunkSOEKWFU2cjs = require('./chunk-SOEKWFU2.cjs');
17
17
 
18
18
 
19
19
 
20
- var _chunkRLOPQZTQcjs = require('./chunk-RLOPQZTQ.cjs');
20
+ var _chunkINDOGCAQcjs = require('./chunk-INDOGCAQ.cjs');
21
21
 
22
22
 
23
23
 
24
24
 
25
25
 
26
- var _chunkT63Y6GTWcjs = require('./chunk-T63Y6GTW.cjs');
26
+ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
27
27
  require('./chunk-KIN7Y247.cjs');
28
28
 
29
29
 
@@ -297,12 +297,12 @@ async function hoistTypings(code, formatOptions) {
297
297
  } catch (err) {
298
298
  console.error(err);
299
299
  if (formatOptions.throwOnError) {
300
- throw new (0, _chunkT63Y6GTWcjs.CodeFormattingError)(err instanceof Error ? err.message : String(_nullishCoalesce(err, () => ( "Unknown Error"))), code);
300
+ throw new (0, _chunkPK72FAKDcjs.CodeFormattingError)(err instanceof Error ? err.message : String(_nullishCoalesce(err, () => ( "Unknown Error"))), code);
301
301
  }
302
302
  break;
303
303
  }
304
304
  }
305
- return _chunkRLOPQZTQcjs.formatTypings.call(void 0, code, formatOptions);
305
+ return _chunkINDOGCAQcjs.formatTypings.call(void 0, code, formatOptions);
306
306
  }
307
307
 
308
308
  // src/objects.ts
@@ -428,7 +428,7 @@ var ObjectInstance = class {
428
428
  this.description = props.description;
429
429
  this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
430
430
  this.properties = props.properties;
431
- this.tools = _chunkJ57224PDcjs.Tool.withUniqueNames(_nullishCoalesce(props.tools, () => ( [])));
431
+ this.tools = _chunkSOEKWFU2cjs.Tool.withUniqueNames(_nullishCoalesce(props.tools, () => ( [])));
432
432
  }
433
433
  /**
434
434
  * Generates TypeScript namespace declarations for this object.
@@ -509,7 +509,7 @@ function getObjectTypings(obj) {
509
509
  }
510
510
  let type = "unknown";
511
511
  if (prop.type) {
512
- type = await _chunkRLOPQZTQcjs.getTypings.call(void 0, prop.type, {});
512
+ type = await _chunkINDOGCAQcjs.getTypings.call(void 0, prop.type, {});
513
513
  } else if (prop.value !== void 0) {
514
514
  type = typeof prop.value;
515
515
  }
@@ -529,7 +529,7 @@ function getObjectTypings(obj) {
529
529
  typings.push("");
530
530
  for (const tool of obj.tools) {
531
531
  const fnType = _zui.z.function(tool.zInput, tool.zOutput).title(tool.name).describe(_nullishCoalesce(tool.description, () => ( "")));
532
- let temp = await _chunkRLOPQZTQcjs.getTypings.call(void 0, fnType, {
532
+ let temp = await _chunkINDOGCAQcjs.getTypings.call(void 0, fnType, {
533
533
  declaration: true
534
534
  });
535
535
  temp = temp.replace("declare function ", "function ");
@@ -552,7 +552,7 @@ function getObjectTypings(obj) {
552
552
  if ((_a = obj.description) == null ? void 0 : _a.trim().length) {
553
553
  header = _chunkWHNOR4ZUcjs.getMultilineComment.call(void 0, obj.description);
554
554
  }
555
- return _chunkRLOPQZTQcjs.formatTypings.call(void 0,
555
+ return _chunkINDOGCAQcjs.formatTypings.call(void 0,
556
556
  `${header}
557
557
  export namespace ${obj.name} {
558
558
  ${body}
@@ -1104,19 +1104,19 @@ var utils = {
1104
1104
  truncateWrappedContent: _chunkGZPN7RGHcjs.truncateWrappedContent
1105
1105
  };
1106
1106
  var execute = async (props) => {
1107
- const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-NB4CQ5PW.cjs")));
1107
+ const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-HGUVAYIN.cjs")));
1108
1108
  return executeContext(props);
1109
1109
  };
1110
1110
  var init = async () => {
1111
- await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-NB4CQ5PW.cjs")));
1111
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-HGUVAYIN.cjs")));
1112
1112
  await Promise.resolve().then(() => _interopRequireWildcard(require("./component-R4WTW6DZ.cjs")));
1113
- await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-YCYYKKB3.cjs")));
1113
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-JVLOALQN.cjs")));
1114
1114
  await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-XAYKJ6TR.cjs")));
1115
1115
  await Promise.resolve().then(() => _interopRequireWildcard(require("./jsx-AJAXBWFE.cjs")));
1116
- await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-2LG42J6U.cjs")));
1116
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-VFORKC54.cjs")));
1117
1117
  await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-L5QAQXV2.cjs")));
1118
1118
  await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-W3NXBLYJ.cjs")));
1119
- await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-2RAAZ2YP.cjs")));
1119
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-OLI56LGT.cjs")));
1120
1120
  await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-UBHAMQW4.cjs")));
1121
1121
  };
1122
1122
 
@@ -1147,4 +1147,4 @@ var init = async () => {
1147
1147
 
1148
1148
 
1149
1149
 
1150
- exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkZRCU35UVcjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunk66NCLCNTcjs.DefaultExit; exports.ErrorExecutionResult = _chunk66NCLCNTcjs.ErrorExecutionResult; exports.ExecutionResult = _chunk66NCLCNTcjs.ExecutionResult; exports.Exit = _chunk3G3BS5IAcjs.Exit; exports.ListenExit = _chunk66NCLCNTcjs.ListenExit; exports.LoopExceededError = _chunkT63Y6GTWcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunk66NCLCNTcjs.PartialExecutionResult; exports.Snapshot = _chunk66NCLCNTcjs.Snapshot; exports.SnapshotSignal = _chunkT63Y6GTWcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunk66NCLCNTcjs.SuccessExecutionResult; exports.ThinkExit = _chunk66NCLCNTcjs.ThinkExit; exports.ThinkSignal = _chunkT63Y6GTWcjs.ThinkSignal; exports.Tool = _chunkJ57224PDcjs.Tool; exports.assertValidComponent = _chunkZRCU35UVcjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunk66NCLCNTcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkZRCU35UVcjs.isAnyComponent; exports.isComponent = _chunkZRCU35UVcjs.isComponent; exports.parseExit = _chunk66NCLCNTcjs.parseExit; exports.renderToTsx = _chunkZRCU35UVcjs.renderToTsx; exports.utils = utils;
1150
+ exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkZRCU35UVcjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunk4XIOQWVZcjs.DefaultExit; exports.ErrorExecutionResult = _chunk4XIOQWVZcjs.ErrorExecutionResult; exports.ExecutionResult = _chunk4XIOQWVZcjs.ExecutionResult; exports.Exit = _chunk3G3BS5IAcjs.Exit; exports.ListenExit = _chunk4XIOQWVZcjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunk4XIOQWVZcjs.PartialExecutionResult; exports.Snapshot = _chunk4XIOQWVZcjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunk4XIOQWVZcjs.SuccessExecutionResult; exports.ThinkExit = _chunk4XIOQWVZcjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkSOEKWFU2cjs.Tool; exports.assertValidComponent = _chunkZRCU35UVcjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunk4XIOQWVZcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkZRCU35UVcjs.isAnyComponent; exports.isComponent = _chunkZRCU35UVcjs.isComponent; exports.parseExit = _chunk4XIOQWVZcjs.parseExit; exports.renderToTsx = _chunkZRCU35UVcjs.renderToTsx; exports.utils = utils;
package/dist/index.js CHANGED
@@ -9,21 +9,21 @@ import {
9
9
  ThinkExit,
10
10
  getValue,
11
11
  parseExit
12
- } from "./chunk-WYFTNO2Y.js";
12
+ } from "./chunk-4JN4PPGP.js";
13
13
  import "./chunk-AAHUDKBY.js";
14
14
  import {
15
15
  Tool
16
- } from "./chunk-RC6YO5UW.js";
16
+ } from "./chunk-23SY6IDW.js";
17
17
  import {
18
18
  formatTypings,
19
19
  getTypings
20
- } from "./chunk-IUE5BW56.js";
20
+ } from "./chunk-U4HWJLF2.js";
21
21
  import {
22
22
  CodeFormattingError,
23
23
  LoopExceededError,
24
24
  SnapshotSignal,
25
25
  ThinkSignal
26
- } from "./chunk-MYLTD5WT.js";
26
+ } from "./chunk-WSVDMGMR.js";
27
27
  import "./chunk-YEAWWJSJ.js";
28
28
  import {
29
29
  Exit
@@ -1104,19 +1104,19 @@ var utils = {
1104
1104
  truncateWrappedContent
1105
1105
  };
1106
1106
  var execute = async (props) => {
1107
- const { executeContext } = await import("./llmz-VOXE65UW.js");
1107
+ const { executeContext } = await import("./llmz-3E2JM3HM.js");
1108
1108
  return executeContext(props);
1109
1109
  };
1110
1110
  var init = async () => {
1111
- await import("./llmz-VOXE65UW.js");
1111
+ await import("./llmz-3E2JM3HM.js");
1112
1112
  await import("./component-WFVDVSDK.js");
1113
- await import("./tool-U6SV6BZ6.js");
1113
+ await import("./tool-7QXH6A24.js");
1114
1114
  await import("./exit-YLO7BY7Z.js");
1115
1115
  await import("./jsx-AEHVFB3L.js");
1116
- await import("./vm-FVQBX2XV.js");
1116
+ await import("./vm-Y3WY2627.js");
1117
1117
  await import("./utils-RQHQ2KOG.js");
1118
1118
  await import("./truncator-BSP6PQPC.js");
1119
- await import("./typings-3VYUEACY.js");
1119
+ await import("./typings-ALZEKGV6.js");
1120
1120
  await import("./dual-modes-LEAHGCOF.js");
1121
1121
  };
1122
1122
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runAsyncFunction
3
- } from "./chunk-IAYPKHFV.js";
3
+ } from "./chunk-G3LSBWJT.js";
4
4
  import {
5
5
  Context,
6
6
  ErrorExecutionResult,
@@ -8,10 +8,10 @@ import {
8
8
  Snapshot,
9
9
  SuccessExecutionResult,
10
10
  parseExit
11
- } from "./chunk-WYFTNO2Y.js";
11
+ } from "./chunk-4JN4PPGP.js";
12
12
  import "./chunk-AAHUDKBY.js";
13
- import "./chunk-RC6YO5UW.js";
14
- import "./chunk-IUE5BW56.js";
13
+ import "./chunk-23SY6IDW.js";
14
+ import "./chunk-U4HWJLF2.js";
15
15
  import {
16
16
  AssignmentError,
17
17
  CodeExecutionError,
@@ -22,7 +22,7 @@ import {
22
22
  SnapshotSignal,
23
23
  ThinkSignal,
24
24
  VMSignal
25
- } from "./chunk-MYLTD5WT.js";
25
+ } from "./chunk-WSVDMGMR.js";
26
26
  import {
27
27
  cleanStackTrace
28
28
  } from "./chunk-YEAWWJSJ.js";
@@ -104,7 +104,7 @@ var executeContext = async (props) => {
104
104
  var _executeContext = async (props) => {
105
105
  var _a, _b;
106
106
  const controller = createJoinedAbortController([props.signal]);
107
- const { onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
107
+ const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
108
108
  const cognitive = Cognitive.isCognitiveClient(props.client) ? props.client : new Cognitive({ client: props.client });
109
109
  const cleanups = [];
110
110
  const ctx = new Context({
@@ -125,6 +125,19 @@ var _executeContext = async (props) => {
125
125
  return new ErrorExecutionResult(ctx, new LoopExceededError());
126
126
  }
127
127
  const iteration = await ctx.nextIteration();
128
+ try {
129
+ await executeOnIterationStartHook({
130
+ iteration,
131
+ ctx,
132
+ onIterationStart,
133
+ controller,
134
+ onIterationEnd
135
+ });
136
+ } catch (err) {
137
+ if (err instanceof ThinkSignal) {
138
+ continue;
139
+ }
140
+ }
128
141
  if (controller.signal.aborted) {
129
142
  iteration.end({
130
143
  type: "aborted",
@@ -277,7 +290,8 @@ var executeIteration = async ({
277
290
  tokens: output.meta.tokens.input + output.meta.tokens.output,
278
291
  spend: output.meta.cost.input + output.meta.cost.output,
279
292
  output: assistantResponse.raw,
280
- model: `${output.meta.model.integration}:${output.meta.model.model}`
293
+ model: `${output.meta.model.integration}:${output.meta.model.model}`,
294
+ usage: output.output.usage
281
295
  };
282
296
  traces.push({
283
297
  type: "llm_call_success",
@@ -423,7 +437,8 @@ var executeIteration = async ({
423
437
  type: "thinking_requested",
424
438
  thinking_requested: {
425
439
  variables: result.signal.context,
426
- reason: result.signal.reason
440
+ reason: result.signal.reason,
441
+ metadata: result.signal.metadata
427
442
  }
428
443
  });
429
444
  }
@@ -435,7 +450,6 @@ var executeIteration = async ({
435
450
  }
436
451
  });
437
452
  }
438
- const _validActions = [...iteration.exits.map((x) => x.name.toLowerCase()), "think"];
439
453
  let returnValue = result.success && result.return_value ? result.return_value : null;
440
454
  const returnAction = returnValue == null ? void 0 : returnValue.action;
441
455
  if (returnAction === "think") {
@@ -546,7 +560,9 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
546
560
  iteration,
547
561
  tool,
548
562
  input: input2,
549
- controller
563
+ controller,
564
+ object,
565
+ toolCallId
550
566
  }));
551
567
  if (typeof (beforeRes == null ? void 0 : beforeRes.input) !== "undefined") {
552
568
  input2 = beforeRes.input;
@@ -559,7 +575,9 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
559
575
  tool,
560
576
  input: input2,
561
577
  output: output2,
562
- controller
578
+ controller,
579
+ object,
580
+ toolCallId
563
581
  }));
564
582
  if (typeof (afterRes == null ? void 0 : afterRes.output) !== "undefined") {
565
583
  output2 = afterRes.output;
@@ -572,10 +590,23 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
572
590
  output = res;
573
591
  success = true;
574
592
  return res;
575
- }).catch((err) => {
593
+ }).catch(async (err) => {
576
594
  if (!handleSignals(err)) {
577
595
  success = false;
578
596
  error = err;
597
+ } else {
598
+ const afterRes = await (afterHook == null ? void 0 : afterHook({
599
+ iteration,
600
+ tool,
601
+ input,
602
+ output,
603
+ controller,
604
+ object,
605
+ toolCallId
606
+ }));
607
+ if (typeof (afterRes == null ? void 0 : afterRes.output) !== "undefined") {
608
+ output = afterRes.output;
609
+ }
579
610
  }
580
611
  throw err;
581
612
  }).finally(() => {
@@ -624,6 +655,39 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
624
655
  return output;
625
656
  };
626
657
  }
658
+ var executeOnIterationStartHook = async (props) => {
659
+ const { iteration, ctx, onIterationStart, controller, onIterationEnd } = props;
660
+ try {
661
+ const hookRes = await (onIterationStart == null ? void 0 : onIterationStart(iteration, controller, ctx));
662
+ if (hookRes) {
663
+ Object.assign(iteration, hookRes);
664
+ }
665
+ } catch (err) {
666
+ if (err instanceof ThinkSignal) {
667
+ iteration.end({
668
+ type: "thinking_requested",
669
+ thinking_requested: {
670
+ variables: err.context,
671
+ reason: err.reason
672
+ }
673
+ });
674
+ try {
675
+ await (onIterationEnd == null ? void 0 : onIterationEnd(iteration, controller));
676
+ } catch (err2) {
677
+ console.error(err2);
678
+ }
679
+ } else {
680
+ iteration.end({
681
+ type: "execution_error",
682
+ execution_error: {
683
+ message: `Error in onIterationStart hook: ${getErrorMessage(err)}`,
684
+ stack: cleanStackTrace(err.stack ?? "No stack trace available")
685
+ }
686
+ });
687
+ }
688
+ throw err;
689
+ }
690
+ };
627
691
  export {
628
692
  _executeContext,
629
693
  executeContext
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkCA7FRCZTcjs = require('./chunk-CA7FRCZT.cjs');
3
+ var _chunk5FWOHMO4cjs = require('./chunk-5FWOHMO4.cjs');
4
4
 
5
5
 
6
6
 
@@ -8,10 +8,10 @@ var _chunkCA7FRCZTcjs = require('./chunk-CA7FRCZT.cjs');
8
8
 
9
9
 
10
10
 
11
- var _chunk66NCLCNTcjs = require('./chunk-66NCLCNT.cjs');
11
+ var _chunk4XIOQWVZcjs = require('./chunk-4XIOQWVZ.cjs');
12
12
  require('./chunk-5BEKU5MZ.cjs');
13
- require('./chunk-J57224PD.cjs');
14
- require('./chunk-RLOPQZTQ.cjs');
13
+ require('./chunk-SOEKWFU2.cjs');
14
+ require('./chunk-INDOGCAQ.cjs');
15
15
 
16
16
 
17
17
 
@@ -22,7 +22,7 @@ require('./chunk-RLOPQZTQ.cjs');
22
22
 
23
23
 
24
24
 
25
- var _chunkT63Y6GTWcjs = require('./chunk-T63Y6GTW.cjs');
25
+ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
26
26
 
27
27
 
28
28
  var _chunkKIN7Y247cjs = require('./chunk-KIN7Y247.cjs');
@@ -104,10 +104,10 @@ var executeContext = async (props) => {
104
104
  var _executeContext = async (props) => {
105
105
  var _a, _b;
106
106
  const controller = createJoinedAbortController([props.signal]);
107
- const { onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
107
+ const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
108
108
  const cognitive = _cognitive.Cognitive.isCognitiveClient(props.client) ? props.client : new (0, _cognitive.Cognitive)({ client: props.client });
109
109
  const cleanups = [];
110
- const ctx = new (0, _chunk66NCLCNTcjs.Context)({
110
+ const ctx = new (0, _chunk4XIOQWVZcjs.Context)({
111
111
  chat: props.chat,
112
112
  instructions: props.instructions,
113
113
  objects: props.objects,
@@ -122,9 +122,22 @@ var _executeContext = async (props) => {
122
122
  try {
123
123
  while (true) {
124
124
  if (ctx.iterations.length >= ctx.loop) {
125
- return new (0, _chunk66NCLCNTcjs.ErrorExecutionResult)(ctx, new (0, _chunkT63Y6GTWcjs.LoopExceededError)());
125
+ return new (0, _chunk4XIOQWVZcjs.ErrorExecutionResult)(ctx, new (0, _chunkPK72FAKDcjs.LoopExceededError)());
126
126
  }
127
127
  const iteration = await ctx.nextIteration();
128
+ try {
129
+ await executeOnIterationStartHook({
130
+ iteration,
131
+ ctx,
132
+ onIterationStart,
133
+ controller,
134
+ onIterationEnd
135
+ });
136
+ } catch (err) {
137
+ if (err instanceof _chunkPK72FAKDcjs.ThinkSignal) {
138
+ continue;
139
+ }
140
+ }
128
141
  if (controller.signal.aborted) {
129
142
  iteration.end({
130
143
  type: "aborted",
@@ -132,7 +145,7 @@ var _executeContext = async (props) => {
132
145
  reason: _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted"))
133
146
  }
134
147
  });
135
- return new (0, _chunk66NCLCNTcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")));
148
+ return new (0, _chunk4XIOQWVZcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")));
136
149
  }
137
150
  cleanups.push(
138
151
  iteration.traces.onPush((traces) => {
@@ -168,25 +181,25 @@ var _executeContext = async (props) => {
168
181
  }
169
182
  if (iteration.status.type === "exit_success") {
170
183
  const exitName = iteration.status.exit_success.exit_name;
171
- return new (0, _chunk66NCLCNTcjs.SuccessExecutionResult)(ctx, {
184
+ return new (0, _chunk4XIOQWVZcjs.SuccessExecutionResult)(ctx, {
172
185
  exit: iteration.exits.find((x) => x.name === exitName),
173
186
  result: iteration.status.exit_success.return_value
174
187
  });
175
188
  }
176
189
  if (iteration.status.type === "callback_requested") {
177
- return new (0, _chunk66NCLCNTcjs.PartialExecutionResult)(
190
+ return new (0, _chunk4XIOQWVZcjs.PartialExecutionResult)(
178
191
  ctx,
179
192
  iteration.status.callback_requested.signal,
180
- _chunk66NCLCNTcjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
193
+ _chunk4XIOQWVZcjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
181
194
  );
182
195
  }
183
196
  if (iteration.status.type === "thinking_requested" || iteration.status.type === "exit_error" || iteration.status.type === "execution_error" || iteration.status.type === "invalid_code_error") {
184
197
  continue;
185
198
  }
186
- return new (0, _chunk66NCLCNTcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)));
199
+ return new (0, _chunk4XIOQWVZcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)));
187
200
  }
188
201
  } catch (error) {
189
- return new (0, _chunk66NCLCNTcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
202
+ return new (0, _chunk4XIOQWVZcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
190
203
  } finally {
191
204
  for (const cleanup of cleanups) {
192
205
  try {
@@ -240,7 +253,7 @@ var executeIteration = async ({
240
253
  });
241
254
  const out = ((_c = (_b = output.output.choices) == null ? void 0 : _b[0]) == null ? void 0 : _c.type) === "text" && typeof ((_d = output.output.choices) == null ? void 0 : _d[0].content) === "string" ? output.output.choices[0].content : null;
242
255
  if (!out) {
243
- throw new (0, _chunkT63Y6GTWcjs.CognitiveError)("LLM did not return any text output");
256
+ throw new (0, _chunkPK72FAKDcjs.CognitiveError)("LLM did not return any text output");
244
257
  }
245
258
  const assistantResponse = ctx.version.parseAssistantResponse(out);
246
259
  iteration.code = assistantResponse.code.trim();
@@ -251,7 +264,7 @@ var executeIteration = async ({
251
264
  iteration.code = hookRes.code.trim();
252
265
  }
253
266
  } catch (err) {
254
- if (err instanceof _chunkT63Y6GTWcjs.ThinkSignal) {
267
+ if (err instanceof _chunkPK72FAKDcjs.ThinkSignal) {
255
268
  return iteration.end({
256
269
  type: "thinking_requested",
257
270
  thinking_requested: {
@@ -277,7 +290,8 @@ var executeIteration = async ({
277
290
  tokens: output.meta.tokens.input + output.meta.tokens.output,
278
291
  spend: output.meta.cost.input + output.meta.cost.output,
279
292
  output: assistantResponse.raw,
280
- model: `${output.meta.model.integration}:${output.meta.model.model}`
293
+ model: `${output.meta.model.integration}:${output.meta.model.model}`,
294
+ usage: output.output.usage
281
295
  };
282
296
  traces.push({
283
297
  type: "llm_call_success",
@@ -305,14 +319,14 @@ var executeIteration = async ({
305
319
  return;
306
320
  }
307
321
  if (!writable) {
308
- throw new (0, _chunkT63Y6GTWcjs.AssignmentError)(`Property ${obj.name}.${name} is read-only and cannot be modified`);
322
+ throw new (0, _chunkPK72FAKDcjs.AssignmentError)(`Property ${obj.name}.${name} is read-only and cannot be modified`);
309
323
  }
310
324
  if (value2 === internalValues[name]) {
311
325
  return;
312
326
  }
313
327
  const parsed = schema.safeParse(value2);
314
328
  if (!parsed.success) {
315
- throw new (0, _chunkT63Y6GTWcjs.AssignmentError)(
329
+ throw new (0, _chunkPK72FAKDcjs.AssignmentError)(
316
330
  `Invalid value for Object property ${obj.name}.${name}: ${getErrorMessage(parsed.error)}`
317
331
  );
318
332
  }
@@ -363,7 +377,7 @@ var executeIteration = async ({
363
377
  });
364
378
  }
365
379
  startedAt = Date.now();
366
- const result = await _chunkCA7FRCZTcjs.runAsyncFunction.call(void 0,
380
+ const result = await _chunk5FWOHMO4cjs.runAsyncFunction.call(void 0,
367
381
  vmContext,
368
382
  iteration.code,
369
383
  traces,
@@ -378,7 +392,7 @@ var executeIteration = async ({
378
392
  variables: {}
379
393
  };
380
394
  });
381
- if (result.error && result.error instanceof _chunkT63Y6GTWcjs.InvalidCodeError) {
395
+ if (result.error && result.error instanceof _chunkPK72FAKDcjs.InvalidCodeError) {
382
396
  return iteration.end({
383
397
  type: "invalid_code_error",
384
398
  invalid_code_error: {
@@ -400,7 +414,7 @@ var executeIteration = async ({
400
414
  }
401
415
  });
402
416
  }
403
- if (result.error && result.error instanceof _chunkT63Y6GTWcjs.CodeExecutionError) {
417
+ if (result.error && result.error instanceof _chunkPK72FAKDcjs.CodeExecutionError) {
404
418
  return iteration.end({
405
419
  type: "execution_error",
406
420
  execution_error: {
@@ -418,16 +432,17 @@ var executeIteration = async ({
418
432
  }
419
433
  });
420
434
  }
421
- if (result.signal instanceof _chunkT63Y6GTWcjs.ThinkSignal) {
435
+ if (result.signal instanceof _chunkPK72FAKDcjs.ThinkSignal) {
422
436
  return iteration.end({
423
437
  type: "thinking_requested",
424
438
  thinking_requested: {
425
439
  variables: result.signal.context,
426
- reason: result.signal.reason
440
+ reason: result.signal.reason,
441
+ metadata: result.signal.metadata
427
442
  }
428
443
  });
429
444
  }
430
- if (result.signal instanceof _chunkT63Y6GTWcjs.SnapshotSignal) {
445
+ if (result.signal instanceof _chunkPK72FAKDcjs.SnapshotSignal) {
431
446
  return iteration.end({
432
447
  type: "callback_requested",
433
448
  callback_requested: {
@@ -435,7 +450,6 @@ var executeIteration = async ({
435
450
  }
436
451
  });
437
452
  }
438
- const _validActions = [...iteration.exits.map((x) => x.name.toLowerCase()), "think"];
439
453
  let returnValue = result.success && result.return_value ? result.return_value : null;
440
454
  const returnAction = returnValue == null ? void 0 : returnValue.action;
441
455
  if (returnAction === "think") {
@@ -457,7 +471,7 @@ var executeIteration = async ({
457
471
  }
458
472
  });
459
473
  }
460
- const parsedExit = _chunk66NCLCNTcjs.parseExit.call(void 0, returnValue, iteration.exits);
474
+ const parsedExit = _chunk4XIOQWVZcjs.parseExit.call(void 0, returnValue, iteration.exits);
461
475
  if (!parsedExit.success) {
462
476
  return iteration.end({
463
477
  type: "exit_error",
@@ -518,16 +532,16 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
518
532
  if (output === error2) {
519
533
  return true;
520
534
  }
521
- if (error2 instanceof _chunkT63Y6GTWcjs.SnapshotSignal) {
535
+ if (error2 instanceof _chunkPK72FAKDcjs.SnapshotSignal) {
522
536
  error2.toolCall = {
523
537
  name: tool.name,
524
538
  inputSchema: tool.input,
525
539
  outputSchema: tool.output,
526
540
  input
527
541
  };
528
- error2.message = _chunkT63Y6GTWcjs.Signals.serializeError(error2);
542
+ error2.message = _chunkPK72FAKDcjs.Signals.serializeError(error2);
529
543
  }
530
- if (error2 instanceof _chunkT63Y6GTWcjs.ThinkSignal) {
544
+ if (error2 instanceof _chunkPK72FAKDcjs.ThinkSignal) {
531
545
  traces.push({
532
546
  type: "think_signal",
533
547
  started_at: Date.now(),
@@ -546,7 +560,9 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
546
560
  iteration,
547
561
  tool,
548
562
  input: input2,
549
- controller
563
+ controller,
564
+ object,
565
+ toolCallId
550
566
  }));
551
567
  if (typeof (beforeRes == null ? void 0 : beforeRes.input) !== "undefined") {
552
568
  input2 = beforeRes.input;
@@ -559,7 +575,9 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
559
575
  tool,
560
576
  input: input2,
561
577
  output: output2,
562
- controller
578
+ controller,
579
+ object,
580
+ toolCallId
563
581
  }));
564
582
  if (typeof (afterRes == null ? void 0 : afterRes.output) !== "undefined") {
565
583
  output2 = afterRes.output;
@@ -572,10 +590,23 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
572
590
  output = res;
573
591
  success = true;
574
592
  return res;
575
- }).catch((err) => {
593
+ }).catch(async (err) => {
576
594
  if (!handleSignals(err)) {
577
595
  success = false;
578
596
  error = err;
597
+ } else {
598
+ const afterRes = await (afterHook == null ? void 0 : afterHook({
599
+ iteration,
600
+ tool,
601
+ input,
602
+ output,
603
+ controller,
604
+ object,
605
+ toolCallId
606
+ }));
607
+ if (typeof (afterRes == null ? void 0 : afterRes.output) !== "undefined") {
608
+ output = afterRes.output;
609
+ }
579
610
  }
580
611
  throw err;
581
612
  }).finally(() => {
@@ -618,12 +649,45 @@ function wrapTool({ tool, traces, object, iteration, beforeHook, afterHook, cont
618
649
  if (!success) {
619
650
  throw error;
620
651
  }
621
- if (output instanceof _chunkT63Y6GTWcjs.VMSignal) {
652
+ if (output instanceof _chunkPK72FAKDcjs.VMSignal) {
622
653
  throw output;
623
654
  }
624
655
  return output;
625
656
  };
626
657
  }
658
+ var executeOnIterationStartHook = async (props) => {
659
+ const { iteration, ctx, onIterationStart, controller, onIterationEnd } = props;
660
+ try {
661
+ const hookRes = await (onIterationStart == null ? void 0 : onIterationStart(iteration, controller, ctx));
662
+ if (hookRes) {
663
+ Object.assign(iteration, hookRes);
664
+ }
665
+ } catch (err) {
666
+ if (err instanceof _chunkPK72FAKDcjs.ThinkSignal) {
667
+ iteration.end({
668
+ type: "thinking_requested",
669
+ thinking_requested: {
670
+ variables: err.context,
671
+ reason: err.reason
672
+ }
673
+ });
674
+ try {
675
+ await (onIterationEnd == null ? void 0 : onIterationEnd(iteration, controller));
676
+ } catch (err2) {
677
+ console.error(err2);
678
+ }
679
+ } else {
680
+ iteration.end({
681
+ type: "execution_error",
682
+ execution_error: {
683
+ message: `Error in onIterationStart hook: ${getErrorMessage(err)}`,
684
+ stack: _chunkKIN7Y247cjs.cleanStackTrace.call(void 0, _nullishCoalesce(err.stack, () => ( "No stack trace available")))
685
+ }
686
+ });
687
+ }
688
+ throw err;
689
+ }
690
+ };
627
691
 
628
692
 
629
693
 
package/dist/llmz.d.ts CHANGED
@@ -22,6 +22,14 @@ export type ExecutionHooks = {
22
22
  trace: Trace;
23
23
  iteration: number;
24
24
  }) => void;
25
+ /**
26
+ * BLOCKING HOOK
27
+ * This hook will block the execution of the iteration until it resolves.
28
+ *
29
+ * This hook will be called before each iteration starts, regardless of the status.
30
+ * This is useful for logging or dynamically change model arguments
31
+ */
32
+ onIterationStart?: (iteration: Iteration, controller: AbortController, context: Context) => Promise<void | Partial<Iteration>> | void | Partial<Iteration>;
25
33
  /**
26
34
  * BLOCKING HOOK
27
35
  * This hook will block the execution of the iteration until it resolves.
@@ -70,6 +78,8 @@ export type ExecutionHooks = {
70
78
  tool: Tool;
71
79
  input: any;
72
80
  controller: AbortController;
81
+ toolCallId: string;
82
+ object?: string;
73
83
  }) => Promise<{
74
84
  input?: any;
75
85
  } | void>;
@@ -88,6 +98,8 @@ export type ExecutionHooks = {
88
98
  input: any;
89
99
  output: any;
90
100
  controller: AbortController;
101
+ toolCallId: string;
102
+ object?: string;
91
103
  }) => Promise<{
92
104
  output?: any;
93
105
  } | void>;
package/dist/objects.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { z } from '@bpinternal/zui';
2
1
  import { Tool } from './tool.js';
3
- import { Serializable } from './types.js';
2
+ import { Serializable, ZuiType } from './types.js';
4
3
  /**
5
4
  * Defines a property within an ObjectInstance.
6
5
  *
@@ -25,7 +24,7 @@ export type ObjectProperty = {
25
24
  /** The current value of the property */
26
25
  value: any;
27
26
  /** Optional Zod schema for validation when the property is modified */
28
- type?: z.Schema;
27
+ type?: ZuiType;
29
28
  /** Optional human-readable description of the property */
30
29
  description?: string;
31
30
  /** Whether the LLM can modify this property (default: false) */
package/dist/result.d.ts CHANGED
@@ -405,6 +405,12 @@ export declare class SuccessExecutionResult<TOutput = unknown> extends Execution
405
405
  spend: number;
406
406
  output: string;
407
407
  model: string;
408
+ usage: {
409
+ inputCost: number;
410
+ outputCost: number;
411
+ inputTokens: number;
412
+ outputTokens: number;
413
+ };
408
414
  } | undefined;
409
415
  transcript: import("./transcript.js").Transcript.Message[];
410
416
  tools: {
@@ -560,6 +566,12 @@ export declare class ErrorExecutionResult extends ExecutionResult implements Ser
560
566
  spend: number;
561
567
  output: string;
562
568
  model: string;
569
+ usage: {
570
+ inputCost: number;
571
+ outputCost: number;
572
+ inputTokens: number;
573
+ outputTokens: number;
574
+ };
563
575
  } | undefined;
564
576
  transcript: import("./transcript.js").Transcript.Message[];
565
577
  tools: {
@@ -735,6 +747,12 @@ export declare class PartialExecutionResult extends ExecutionResult implements S
735
747
  spend: number;
736
748
  output: string;
737
749
  model: string;
750
+ usage: {
751
+ inputCost: number;
752
+ outputCost: number;
753
+ inputTokens: number;
754
+ outputTokens: number;
755
+ };
738
756
  } | undefined;
739
757
  transcript: import("./transcript.js").Transcript.Message[];
740
758
  tools: {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Tool
3
- } from "./chunk-RC6YO5UW.js";
4
- import "./chunk-IUE5BW56.js";
5
- import "./chunk-MYLTD5WT.js";
3
+ } from "./chunk-23SY6IDW.js";
4
+ import "./chunk-U4HWJLF2.js";
5
+ import "./chunk-WSVDMGMR.js";
6
6
  import "./chunk-YEAWWJSJ.js";
7
7
  import "./chunk-ZORRILUV.js";
8
8
  import "./chunk-7WRN4E42.js";
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkJ57224PDcjs = require('./chunk-J57224PD.cjs');
4
- require('./chunk-RLOPQZTQ.cjs');
5
- require('./chunk-T63Y6GTW.cjs');
3
+ var _chunkSOEKWFU2cjs = require('./chunk-SOEKWFU2.cjs');
4
+ require('./chunk-INDOGCAQ.cjs');
5
+ require('./chunk-PK72FAKD.cjs');
6
6
  require('./chunk-KIN7Y247.cjs');
7
7
  require('./chunk-WHNOR4ZU.cjs');
8
8
  require('./chunk-UQOBUJIQ.cjs');
9
9
 
10
10
 
11
- exports.Tool = _chunkJ57224PDcjs.Tool;
11
+ exports.Tool = _chunkSOEKWFU2cjs.Tool;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getTypings
3
- } from "./chunk-IUE5BW56.js";
4
- import "./chunk-MYLTD5WT.js";
3
+ } from "./chunk-U4HWJLF2.js";
4
+ import "./chunk-WSVDMGMR.js";
5
5
  import "./chunk-YEAWWJSJ.js";
6
6
  import "./chunk-ZORRILUV.js";
7
7
  import "./chunk-7WRN4E42.js";
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkRLOPQZTQcjs = require('./chunk-RLOPQZTQ.cjs');
4
- require('./chunk-T63Y6GTW.cjs');
3
+ var _chunkINDOGCAQcjs = require('./chunk-INDOGCAQ.cjs');
4
+ require('./chunk-PK72FAKD.cjs');
5
5
  require('./chunk-KIN7Y247.cjs');
6
6
  require('./chunk-WHNOR4ZU.cjs');
7
7
  require('./chunk-UQOBUJIQ.cjs');
8
8
 
9
9
 
10
- exports.getTypings = _chunkRLOPQZTQcjs.getTypings;
10
+ exports.getTypings = _chunkINDOGCAQcjs.getTypings;
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkCA7FRCZTcjs = require('./chunk-CA7FRCZT.cjs');
4
- require('./chunk-T63Y6GTW.cjs');
3
+ var _chunk5FWOHMO4cjs = require('./chunk-5FWOHMO4.cjs');
4
+ require('./chunk-PK72FAKD.cjs');
5
5
  require('./chunk-KIN7Y247.cjs');
6
6
  require('./chunk-KMZDFWYZ.cjs');
7
7
  require('./chunk-UQOBUJIQ.cjs');
8
8
 
9
9
 
10
- exports.runAsyncFunction = _chunkCA7FRCZTcjs.runAsyncFunction;
10
+ exports.runAsyncFunction = _chunk5FWOHMO4cjs.runAsyncFunction;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  runAsyncFunction
3
- } from "./chunk-IAYPKHFV.js";
4
- import "./chunk-MYLTD5WT.js";
3
+ } from "./chunk-G3LSBWJT.js";
4
+ import "./chunk-WSVDMGMR.js";
5
5
  import "./chunk-YEAWWJSJ.js";
6
6
  import "./chunk-ORQP26SZ.js";
7
7
  import "./chunk-7WRN4E42.js";
package/package.json CHANGED
@@ -2,7 +2,7 @@
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.31",
5
+ "version": "0.0.33",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -70,8 +70,8 @@
70
70
  "tsx": "^4.19.2"
71
71
  },
72
72
  "peerDependencies": {
73
- "@botpress/client": "1.27.1",
74
- "@botpress/cognitive": "0.2.1",
73
+ "@botpress/client": "1.27.2",
74
+ "@botpress/cognitive": "0.3.1",
75
75
  "@bpinternal/thicktoken": "^1.0.5",
76
76
  "@bpinternal/zui": "1.2.1"
77
77
  },