llmz 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/{common-BnvrDnIT.cjs → common-DJkSpeqw.cjs} +1 -1
  2. package/dist/{common-BlRFtdf2.js → common-DuEhn6u3.js} +1 -1
  3. package/dist/compiler/plugins/variable-extraction.d.ts +1 -7
  4. package/dist/{compiler-C-OI9sim.cjs → compiler-BJJUmNS9.cjs} +34 -68
  5. package/dist/{compiler-CW1VjQsn.js → compiler-BPl-5CXh.js} +34 -68
  6. package/dist/{component-C6Agl2ns.cjs → component-CPKXe6Ca.cjs} +2 -2
  7. package/dist/{custom-client-DAsGRnYc.cjs → custom-client-B_o56CB4.cjs} +6 -6
  8. package/dist/{custom-client-ChuZ63zp.js → custom-client-C-nDKG37.js} +3 -3
  9. package/dist/{dual-modes-DPXiuvNe.cjs → dual-modes-BNHlj2qM.cjs} +15 -14
  10. package/dist/{dual-modes-DDkoCp3R.js → dual-modes-BNIiNLrR.js} +13 -12
  11. package/dist/{execute-DM2-7y86.cjs → execute-0bvqakr7.cjs} +31 -18
  12. package/dist/{execute-BWcdv9so.js → execute-CWFIL5ny.js} +30 -17
  13. package/dist/{exit-DUM96DN1.cjs → exit-CGLXI0BH.cjs} +2 -2
  14. package/dist/index.cjs +21 -21
  15. package/dist/index.js +12 -12
  16. package/dist/index.workerd.js +217 -195
  17. package/dist/{jsx-owqxrquU.cjs → jsx-BJ6GWXI2.cjs} +1 -1
  18. package/dist/runtime/generate.test.d.ts +1 -0
  19. package/dist/{tool-Bv8N4IPj.js → tool-B6Pmuk6K.js} +35 -49
  20. package/dist/{tool-Dy6AJpJH.cjs → tool-BLTrA-sL.cjs} +38 -52
  21. package/dist/tool.d.ts +5 -3
  22. package/dist/{truncator-DZqEqnpD.js → truncator-CD7QtE84.js} +11 -6
  23. package/dist/{truncator-CLkouTCO.cjs → truncator-DmCu9M4m.cjs} +13 -8
  24. package/dist/{typings-3lsqCbkn.cjs → typings-DXJMu59O.cjs} +2 -2
  25. package/dist/{utils-3ESwP3yg.cjs → utils-DGQ4sRke.cjs} +1 -1
  26. package/dist/{vm-BLsHw1da.js → vm-Cn3jvZ00.js} +109 -53
  27. package/dist/{vm-D6s1zF6M.cjs → vm-X0uTj5Aa.cjs} +109 -53
  28. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- const require_compiler = require("./compiler-C-OI9sim.cjs");
1
+ const require_compiler = require("./compiler-BJJUmNS9.cjs");
2
2
  let json5 = require("json5");
3
3
  json5 = require_compiler.__toESM(json5, 1);
4
4
  let jsonrepair = require("jsonrepair");
@@ -1,5 +1,5 @@
1
1
  import { n as __exportAll } from "./rolldown-runtime-EAsCxrDo.js";
2
- import { r as hasTopLevelReturn } from "./compiler-CW1VjQsn.js";
2
+ import { r as hasTopLevelReturn } from "./compiler-BPl-5CXh.js";
3
3
  import JSON5 from "json5";
4
4
  import { jsonrepair } from "jsonrepair";
5
5
  //#region src/message-stream/types.ts
@@ -1,10 +1,4 @@
1
1
  import { type Ctx } from '../ast.js';
2
2
  export declare const VariableTrackingFnIdentifier = "__var__";
3
- /**
4
- * Tracks user variables so the VM can read their values between iterations:
5
- * - after each variable declaration: `__var__("a", () => eval("a"));`
6
- * - at the top of function bodies, for their parameters
7
- *
8
- * The `eval` indirection captures the variable lazily in its own scope.
9
- */
3
+ /** Retain getters only for bindings visible between iterations, never local shadows. */
10
4
  export declare function applyVariableTracking(ctx: Ctx, variables: Set<string>): void;
@@ -349,77 +349,43 @@ function applyToolCallTracking(ctx, calls) {
349
349
  //#endregion
350
350
  //#region src/compiler/plugins/variable-extraction.ts
351
351
  const VariableTrackingFnIdentifier = "__var__";
352
- /**
353
- * Tracks user variables so the VM can read their values between iterations:
354
- * - after each variable declaration: `__var__("a", () => eval("a"));`
355
- * - at the top of function bodies, for their parameters
356
- *
357
- * The `eval` indirection captures the variable lazily in its own scope.
358
- */
352
+ const FUNCTION_TYPES$1 = /* @__PURE__ */ new Set([
353
+ "FunctionDeclaration",
354
+ "FunctionExpression",
355
+ "ArrowFunctionExpression"
356
+ ]);
357
+ function declaredNames(id) {
358
+ if (!id) return [];
359
+ if (id.type === "Identifier") return [id.name];
360
+ if (id.type === "RestElement") return declaredNames(id.argument);
361
+ if (id.type === "AssignmentPattern") return declaredNames(id.left);
362
+ if (id.type === "ArrayPattern") return id.elements.flatMap(declaredNames);
363
+ if (id.type === "ObjectPattern") return id.properties.flatMap((prop) => declaredNames(prop.type === "RestElement" ? prop.argument : prop.value));
364
+ return [];
365
+ }
366
+ /** Retain getters only for bindings visible between iterations, never local shadows. */
359
367
  function applyVariableTracking(ctx, variables) {
360
- const trackerFor = (name) => {
361
- if (name.startsWith("__")) return null;
362
- variables.add(name);
363
- return `${VariableTrackingFnIdentifier}(${JSON.stringify(name)}, () => eval(${JSON.stringify(name)}));`;
364
- };
365
- const track = (names) => names.map(trackerFor).filter((t) => !!t).join("");
366
- const declaredNames = (id) => {
367
- if (id.type === "Identifier") return [id.name];
368
- if (id.type === "ObjectPattern") {
369
- const names = [];
370
- for (const prop of id.properties) {
371
- if (prop.type !== "Property") continue;
372
- if (prop.value.type === "Identifier") names.push(prop.value.name);
373
- else if (prop.value.type === "ObjectPattern") names.push(...declaredNames(prop.value));
374
- else if (prop.value.type === "AssignmentPattern" && prop.value.left.type === "Identifier") names.push(prop.value.left.name);
375
- }
376
- return names;
377
- }
378
- if (id.type === "ArrayPattern") {
379
- const names = [];
380
- for (const element of id.elements) {
381
- if (!element) continue;
382
- if (element.type === "Identifier") names.push(element.name);
383
- else if (element.type === "RestElement" && element.argument.type === "Identifier") names.push(element.argument.name);
384
- else if (element.type === "AssignmentPattern" && element.left.type === "Identifier") names.push(element.left.name);
385
- }
386
- return names;
387
- }
388
- return [];
389
- };
390
- const paramNames = (params) => {
391
- const names = [];
392
- for (const param of params) if (param.type === "Identifier") names.push(param.name);
393
- else if (param.type === "AssignmentPattern" && param.left.type === "Identifier") names.push(param.left.name);
394
- else if (param.type === "ObjectPattern") {
395
- for (const prop of param.properties) if (prop.type === "Property" && prop.value.type === "Identifier") names.push(prop.value.name);
396
- } else if (param.type === "ArrayPattern") {
397
- for (const element of param.elements) if ((element === null || element === void 0 ? void 0 : element.type) === "Identifier") names.push(element.name);
398
- }
399
- return names;
400
- };
401
- walk(ctx.ast, (node, parent) => {
402
- if (node.type === "VariableDeclaration") {
403
- if (parent && (parent.type === "ForStatement" || parent.type === "ForInStatement" || parent.type === "ForOfStatement")) return;
404
- const trackers = track(node.declarations.flatMap((d) => declaredNames(d.id)));
405
- if (trackers) {
406
- const semi = ctx.code[node.end - 1] === ";" ? "" : ";";
407
- ctx.ms.appendRight(node.end, `${semi}${trackers}`);
408
- }
409
- return;
410
- }
411
- if (node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") {
412
- const trackers = track(paramNames(node.params));
413
- if (!trackers) return;
414
- const body = node.body;
415
- if (body.type === "BlockStatement") ctx.ms.appendRight(body.start + 1, trackers);
416
- else {
417
- const expressions = trackers.slice(0, -1).replaceAll(";", ",");
418
- ctx.ms.prependLeft(body.start, `(${expressions}, (`);
419
- ctx.ms.appendRight(body.end, "))");
420
- }
368
+ const wrapper = ctx.ast.body.find((node) => {
369
+ var _node$id;
370
+ return node.type === "FunctionDeclaration" && ((_node$id = node.id) === null || _node$id === void 0 ? void 0 : _node$id.name) === "__fn__";
371
+ });
372
+ const root = (wrapper === null || wrapper === void 0 ? void 0 : wrapper.body) ?? ctx.ast;
373
+ const varBindings = /* @__PURE__ */ new Set();
374
+ const track = (names) => names.map((name) => `${VariableTrackingFnIdentifier}(${JSON.stringify(name)}, () => eval(${JSON.stringify(name)}));`).join("");
375
+ walk(root, (node, parent, ancestors) => {
376
+ if (node.type !== "VariableDeclaration" || ancestors.some((ancestor) => FUNCTION_TYPES$1.has(ancestor.type) || ancestor.type === "StaticBlock")) return;
377
+ if (node.kind !== "var" && parent !== root) return;
378
+ const names = node.declarations.flatMap((declaration) => declaredNames(declaration.id)).filter((name) => !name.startsWith("__"));
379
+ for (const name of names) variables.add(name);
380
+ if (node.kind === "var" && parent !== root) for (const name of names) varBindings.add(name);
381
+ else if (node.declarations.length > 1) ctx.ms.appendLeft(node.start, track(names));
382
+ else {
383
+ const semi = ctx.code[node.end - 1] === ";" ? "" : ";";
384
+ ctx.ms.appendRight(node.end, semi + track(names));
421
385
  }
422
386
  });
387
+ const entry = root.body.find((node) => !node.directive);
388
+ if (entry && varBindings.size) ctx.ms.appendLeft(entry.start, track([...varBindings]));
423
389
  }
424
390
  //#endregion
425
391
  //#region src/compiler/compiler.ts
@@ -316,77 +316,43 @@ function applyToolCallTracking(ctx, calls) {
316
316
  //#endregion
317
317
  //#region src/compiler/plugins/variable-extraction.ts
318
318
  const VariableTrackingFnIdentifier = "__var__";
319
- /**
320
- * Tracks user variables so the VM can read their values between iterations:
321
- * - after each variable declaration: `__var__("a", () => eval("a"));`
322
- * - at the top of function bodies, for their parameters
323
- *
324
- * The `eval` indirection captures the variable lazily in its own scope.
325
- */
319
+ const FUNCTION_TYPES$1 = /* @__PURE__ */ new Set([
320
+ "FunctionDeclaration",
321
+ "FunctionExpression",
322
+ "ArrowFunctionExpression"
323
+ ]);
324
+ function declaredNames(id) {
325
+ if (!id) return [];
326
+ if (id.type === "Identifier") return [id.name];
327
+ if (id.type === "RestElement") return declaredNames(id.argument);
328
+ if (id.type === "AssignmentPattern") return declaredNames(id.left);
329
+ if (id.type === "ArrayPattern") return id.elements.flatMap(declaredNames);
330
+ if (id.type === "ObjectPattern") return id.properties.flatMap((prop) => declaredNames(prop.type === "RestElement" ? prop.argument : prop.value));
331
+ return [];
332
+ }
333
+ /** Retain getters only for bindings visible between iterations, never local shadows. */
326
334
  function applyVariableTracking(ctx, variables) {
327
- const trackerFor = (name) => {
328
- if (name.startsWith("__")) return null;
329
- variables.add(name);
330
- return `${VariableTrackingFnIdentifier}(${JSON.stringify(name)}, () => eval(${JSON.stringify(name)}));`;
331
- };
332
- const track = (names) => names.map(trackerFor).filter((t) => !!t).join("");
333
- const declaredNames = (id) => {
334
- if (id.type === "Identifier") return [id.name];
335
- if (id.type === "ObjectPattern") {
336
- const names = [];
337
- for (const prop of id.properties) {
338
- if (prop.type !== "Property") continue;
339
- if (prop.value.type === "Identifier") names.push(prop.value.name);
340
- else if (prop.value.type === "ObjectPattern") names.push(...declaredNames(prop.value));
341
- else if (prop.value.type === "AssignmentPattern" && prop.value.left.type === "Identifier") names.push(prop.value.left.name);
342
- }
343
- return names;
344
- }
345
- if (id.type === "ArrayPattern") {
346
- const names = [];
347
- for (const element of id.elements) {
348
- if (!element) continue;
349
- if (element.type === "Identifier") names.push(element.name);
350
- else if (element.type === "RestElement" && element.argument.type === "Identifier") names.push(element.argument.name);
351
- else if (element.type === "AssignmentPattern" && element.left.type === "Identifier") names.push(element.left.name);
352
- }
353
- return names;
354
- }
355
- return [];
356
- };
357
- const paramNames = (params) => {
358
- const names = [];
359
- for (const param of params) if (param.type === "Identifier") names.push(param.name);
360
- else if (param.type === "AssignmentPattern" && param.left.type === "Identifier") names.push(param.left.name);
361
- else if (param.type === "ObjectPattern") {
362
- for (const prop of param.properties) if (prop.type === "Property" && prop.value.type === "Identifier") names.push(prop.value.name);
363
- } else if (param.type === "ArrayPattern") {
364
- for (const element of param.elements) if ((element === null || element === void 0 ? void 0 : element.type) === "Identifier") names.push(element.name);
365
- }
366
- return names;
367
- };
368
- walk(ctx.ast, (node, parent) => {
369
- if (node.type === "VariableDeclaration") {
370
- if (parent && (parent.type === "ForStatement" || parent.type === "ForInStatement" || parent.type === "ForOfStatement")) return;
371
- const trackers = track(node.declarations.flatMap((d) => declaredNames(d.id)));
372
- if (trackers) {
373
- const semi = ctx.code[node.end - 1] === ";" ? "" : ";";
374
- ctx.ms.appendRight(node.end, `${semi}${trackers}`);
375
- }
376
- return;
377
- }
378
- if (node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") {
379
- const trackers = track(paramNames(node.params));
380
- if (!trackers) return;
381
- const body = node.body;
382
- if (body.type === "BlockStatement") ctx.ms.appendRight(body.start + 1, trackers);
383
- else {
384
- const expressions = trackers.slice(0, -1).replaceAll(";", ",");
385
- ctx.ms.prependLeft(body.start, `(${expressions}, (`);
386
- ctx.ms.appendRight(body.end, "))");
387
- }
335
+ const wrapper = ctx.ast.body.find((node) => {
336
+ var _node$id;
337
+ return node.type === "FunctionDeclaration" && ((_node$id = node.id) === null || _node$id === void 0 ? void 0 : _node$id.name) === "__fn__";
338
+ });
339
+ const root = (wrapper === null || wrapper === void 0 ? void 0 : wrapper.body) ?? ctx.ast;
340
+ const varBindings = /* @__PURE__ */ new Set();
341
+ const track = (names) => names.map((name) => `${VariableTrackingFnIdentifier}(${JSON.stringify(name)}, () => eval(${JSON.stringify(name)}));`).join("");
342
+ walk(root, (node, parent, ancestors) => {
343
+ if (node.type !== "VariableDeclaration" || ancestors.some((ancestor) => FUNCTION_TYPES$1.has(ancestor.type) || ancestor.type === "StaticBlock")) return;
344
+ if (node.kind !== "var" && parent !== root) return;
345
+ const names = node.declarations.flatMap((declaration) => declaredNames(declaration.id)).filter((name) => !name.startsWith("__"));
346
+ for (const name of names) variables.add(name);
347
+ if (node.kind === "var" && parent !== root) for (const name of names) varBindings.add(name);
348
+ else if (node.declarations.length > 1) ctx.ms.appendLeft(node.start, track(names));
349
+ else {
350
+ const semi = ctx.code[node.end - 1] === ";" ? "" : ";";
351
+ ctx.ms.appendRight(node.end, semi + track(names));
388
352
  }
389
353
  });
354
+ const entry = root.body.find((node) => !node.directive);
355
+ if (entry && varBindings.size) ctx.ms.appendLeft(entry.start, track([...varBindings]));
390
356
  }
391
357
  //#endregion
392
358
  //#region src/compiler/compiler.ts
@@ -1,5 +1,5 @@
1
- const require_compiler = require("./compiler-C-OI9sim.cjs");
2
- const require_jsx = require("./jsx-owqxrquU.cjs");
1
+ const require_compiler = require("./compiler-BJJUmNS9.cjs");
2
+ const require_jsx = require("./jsx-BJ6GWXI2.cjs");
3
3
  //#region src/component.ts
4
4
  var component_exports = /* @__PURE__ */ require_compiler.__exportAll({
5
5
  Component: () => Component,
@@ -1,14 +1,14 @@
1
- const require_dual_modes = require("./dual-modes-DPXiuvNe.cjs");
1
+ const require_dual_modes = require("./dual-modes-BNHlj2qM.cjs");
2
2
  const require__overArg = require("./_overArg-C5Hy7oCi.cjs");
3
3
  const require__baseIteratee = require("./_baseIteratee-CF4qP2a8.cjs");
4
- const require_utils = require("./utils-3ESwP3yg.cjs");
4
+ const require_utils = require("./utils-DGQ4sRke.cjs");
5
5
  const require__getPrototype = require("./_getPrototype-DQDlNVVM.cjs");
6
6
  const require_isPlainObject = require("./isPlainObject-CSxXVKCk.cjs");
7
- const require_tool = require("./tool-Dy6AJpJH.cjs");
7
+ const require_tool = require("./tool-BLTrA-sL.cjs");
8
8
  const require_errors = require("./errors-C962uJdS.cjs");
9
- const require_exit = require("./exit-DUM96DN1.cjs");
10
- const require_component = require("./component-C6Agl2ns.cjs");
11
- const require_truncator = require("./truncator-CLkouTCO.cjs");
9
+ const require_exit = require("./exit-CGLXI0BH.cjs");
10
+ const require_component = require("./component-CPKXe6Ca.cjs");
11
+ const require_truncator = require("./truncator-DmCu9M4m.cjs");
12
12
  let _bpinternal_zui = require("@bpinternal/zui");
13
13
  let ulid = require("ulid");
14
14
  //#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayEach.js
@@ -1,14 +1,14 @@
1
- import { c as baseCreate, i as inspect, o as flatRest, r as extractType, s as copyArray, t as DualModePrompt } from "./dual-modes-DDkoCp3R.js";
1
+ import { c as baseCreate, i as inspect, o as flatRest, r as extractType, s as copyArray, t as DualModePrompt } from "./dual-modes-BNIiNLrR.js";
2
2
  import { a as Symbol, n as isArray, o as root, r as isObjectLike } from "./_overArg-CRYbj1NH.js";
3
3
  import { D as isBuffer, E as baseUnary, M as baseAssignValue, R as isObject, T as nodeUtil, _ as baseGet, c as _getTag_default, f as getSymbols, h as Stack, k as isPrototype, s as Uint8Array, u as getAllKeys, v as toKey, x as keys, y as castPath, z as arrayMap } from "./_baseIteratee-P_firB7b.js";
4
4
  import { _ as getSymbolsIn, b as keysIn, g as getAllKeysIn, i as getErrorMessage, o as getTokenizer, x as assignValue, y as baseSlice } from "./utils-UBeAFeEI.js";
5
5
  import { t as getPrototype } from "./_getPrototype-CG7Dxrrz.js";
6
6
  import { t as isPlainObject } from "./isPlainObject-D39AzPO2.js";
7
- import { t as Tool } from "./tool-Bv8N4IPj.js";
7
+ import { t as Tool } from "./tool-B6Pmuk6K.js";
8
8
  import { l as ThinkSignal, o as LoopExceededError } from "./errors-Cg1G0Awu.js";
9
9
  import { t as Exit } from "./exit-CDdxDBRT.js";
10
10
  import { n as assertValidComponent } from "./component-DGG7d_Mz.js";
11
- import { i as wrapContent, t as stripTruncationTags } from "./truncator-DZqEqnpD.js";
11
+ import { i as wrapContent, t as stripTruncationTags } from "./truncator-CD7QtE84.js";
12
12
  import { z } from "@bpinternal/zui";
13
13
  import { ulid } from "ulid";
14
14
  //#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayEach.js
@@ -1,14 +1,14 @@
1
- const require_compiler = require("./compiler-C-OI9sim.cjs");
2
- const require_common = require("./common-BnvrDnIT.cjs");
1
+ const require_compiler = require("./compiler-BJJUmNS9.cjs");
2
+ const require_common = require("./common-DJkSpeqw.cjs");
3
3
  const require__overArg = require("./_overArg-C5Hy7oCi.cjs");
4
4
  const require__baseIteratee = require("./_baseIteratee-CF4qP2a8.cjs");
5
5
  const require_uniq = require("./uniq-G872RWmE.cjs");
6
- const require_utils = require("./utils-3ESwP3yg.cjs");
6
+ const require_utils = require("./utils-DGQ4sRke.cjs");
7
7
  const require_isPlainObject = require("./isPlainObject-CSxXVKCk.cjs");
8
8
  const require__baseForOwn = require("./_baseForOwn-BfWDTL8L.cjs");
9
9
  const require_isEmpty = require("./isEmpty-LY533Wmh.cjs");
10
10
  const require_stack_traces = require("./stack-traces-ntw_qhoy.cjs");
11
- const require_truncator = require("./truncator-CLkouTCO.cjs");
11
+ const require_truncator = require("./truncator-DmCu9M4m.cjs");
12
12
  let acorn = require("acorn");
13
13
  let _bpinternal_zui = require("@bpinternal/zui");
14
14
  let bytes = require("bytes");
@@ -755,7 +755,7 @@ const renderExamples = async (examples, components, exits) => {
755
755
  if (!examples.length) return "";
756
756
  const registry = new ComponentRegistry(components.map(componentToProtocolDefinition));
757
757
  const exitDefinitions = exits.map(exitToProtocolDefinition);
758
- const { parseAssistantResponse } = await Promise.resolve().then(() => require("./common-BnvrDnIT.cjs")).then((n) => n.common_exports);
758
+ const { parseAssistantResponse } = await Promise.resolve().then(() => require("./common-DJkSpeqw.cjs")).then((n) => n.common_exports);
759
759
  const render = (output) => {
760
760
  var _response$diagnostics;
761
761
  const response = parseAssistantResponse(`■start\n${output}\n■end`);
@@ -2114,6 +2114,7 @@ const SECTION_SEP = "\n";
2114
2114
  const NUMBER_LOCALE = new Intl.NumberFormat("en-US");
2115
2115
  const LONG_TEXT_LENGTH = 4096;
2116
2116
  const DEFAULT_OPTIONS = { tokens: 1e5 };
2117
+ const stringify = (value) => JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() + "n" : item);
2117
2118
  function printLimitedJson(obj, maxDepth, maxLength, maxKeys) {
2118
2119
  const indent = 2;
2119
2120
  let currentLength = 0;
@@ -2132,7 +2133,7 @@ function printLimitedJson(obj, maxDepth, maxLength, maxKeys) {
2132
2133
  }
2133
2134
  }
2134
2135
  if (typeof currentObj !== "object" || currentObj === null) {
2135
- const value = JSON.stringify(currentObj);
2136
+ const value = stringify(currentObj);
2136
2137
  currentLength += require_utils.getTokenizer().count(value);
2137
2138
  return value;
2138
2139
  }
@@ -2204,10 +2205,10 @@ function previewValue(value, length = LONG_TEXT_LENGTH) {
2204
2205
  };
2205
2206
  const previewObj = (obj) => {
2206
2207
  const mapped = mapKeys(obj, (_value, key) => previewStr(key));
2207
- return JSON.stringify(mapped);
2208
+ return stringify(mapped);
2208
2209
  };
2209
2210
  if (typeof value === "string") return "<string> " + previewStr(value);
2210
- if (typeof value === "object" && Array.isArray(value)) return "<array> " + previewStr(JSON.stringify(value));
2211
+ if (typeof value === "object" && Array.isArray(value)) return "<array> " + previewStr(stringify(value));
2211
2212
  if (typeof value === "object" && value instanceof Date) return "<date> " + value.toISOString();
2212
2213
  if (typeof value === "object" && value instanceof RegExp) return "<regexp> " + value.toString();
2213
2214
  if (typeof value === "object") return "<object> " + previewObj(value);
@@ -2247,15 +2248,15 @@ function previewArray(arr, maxStringLength = LONG_TEXT_LENGTH) {
2247
2248
  lines.push("// Analysis Summary");
2248
2249
  lines.push(SUBTITLE_LN);
2249
2250
  const typesCount = countBy(arr, (item) => extractType(item, false));
2250
- const ordered = orderBy(arr.filter((item) => !isNil(item) && JSON.stringify(item).length < 100), (item) => JSON.stringify(item), "asc");
2251
+ const ordered = orderBy(arr.filter((item) => !isNil(item) && stringify(item).length < 100), (item) => stringify(item), "asc");
2251
2252
  const minValues = ordered.slice(0, 3).map((item) => previewValue(item, 10));
2252
2253
  const maxValues = ordered.slice(-3).map((item) => previewValue(item, 10));
2253
2254
  const uniqueItems = uniqWith(arr, isEqual);
2254
2255
  const nullValues = filter(arr, isNil).length;
2255
- const memoryUsage = (0, bytes.default)(JSON.stringify(arr).length);
2256
+ const memoryUsage = (0, bytes.default)(stringify(arr).length);
2256
2257
  lines.push(`Total Items: ${arr.length}`);
2257
2258
  lines.push(`Unique Items: ${uniqueItems.length}`);
2258
- lines.push(`Types: ${JSON.stringify(typesCount)}`);
2259
+ lines.push(`Types: ${stringify(typesCount)}`);
2259
2260
  lines.push(`Minimum Values: [${minValues.join(", ")}]`);
2260
2261
  lines.push(`Maximum Values: [${maxValues.join(", ")}]`);
2261
2262
  lines.push(`Memory Usage: ${memoryUsage}`);
@@ -2278,7 +2279,7 @@ function previewObject(obj, options) {
2278
2279
  const keys = Object.keys(obj);
2279
2280
  const uniqueEntries = require_uniq.uniq(Object.values(obj));
2280
2281
  const nilValues = filter(entries, ([, value]) => isNil(value)).length;
2281
- const memoryUsage = (0, bytes.default)(JSON.stringify(obj).length);
2282
+ const memoryUsage = (0, bytes.default)(stringify(obj).length);
2282
2283
  lines.push(`Total Entries: ${NUMBER_LOCALE.format(entries.length)}`);
2283
2284
  lines.push(`Keys: ${previewValue(keys)}`);
2284
2285
  lines.push(`Popular Types: ${previewValue(typesCount)}`);
@@ -2336,7 +2337,7 @@ const inspect = (value, name, options = DEFAULT_OPTIONS) => {
2336
2337
  let header = "";
2337
2338
  if (name) header = `// const ${name}: ${genericType}\n`;
2338
2339
  if (genericType === "Array") return header + previewArray(value, options.maxStringLength);
2339
- else if (genericType === "error") return header + previewError(value);
2340
+ else if (genericType === "error") return require_utils.getTokenizer().truncate(header + previewError(value), options.tokens);
2340
2341
  else if (genericType === "object") return header + previewObject(value, options);
2341
2342
  else if (genericType === "boolean") return header + previewValue(value);
2342
2343
  else if (typeof value === "string") {
@@ -2345,7 +2346,7 @@ const inspect = (value, name, options = DEFAULT_OPTIONS) => {
2345
2346
  }
2346
2347
  return header + previewValue(value);
2347
2348
  } catch (err) {
2348
- return `Error: ${(err === null || err === void 0 ? void 0 : err.message) ?? "Unknown Error"}`;
2349
+ return require_utils.getTokenizer().truncate(`Error: ${(err === null || err === void 0 ? void 0 : err.message) ?? "Unknown Error"}`, options.tokens);
2349
2350
  }
2350
2351
  };
2351
2352
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { n as __exportAll } from "./rolldown-runtime-EAsCxrDo.js";
2
- import { l as NAME_REGEX, n as parseAssistantResponse, r as replacePlaceholders } from "./common-BlRFtdf2.js";
2
+ import { l as NAME_REGEX, n as parseAssistantResponse, r as replacePlaceholders } from "./common-DuEhn6u3.js";
3
3
  import { a as Symbol, n as isArray, r as isObjectLike } from "./_overArg-CRYbj1NH.js";
4
4
  import { A as isArrayLike, B as isSymbol, E as baseUnary, F as WeakMap, L as identity, M as baseAssignValue, O as isArguments, P as defineProperty, R as isObject, _ as baseGet, c as _getTag_default, g as arrayPush, i as mapToArray, m as arrayFilter, n as baseIsEqual, t as baseIteratee, x as keys, z as arrayMap } from "./_baseIteratee-P_firB7b.js";
5
5
  import { n as baseUniq, r as noop, t as uniq } from "./uniq-BYQ7GWwb.js";
@@ -8,7 +8,7 @@ import { t as isPlainObject } from "./isPlainObject-D39AzPO2.js";
8
8
  import { t as baseForOwn } from "./_baseForOwn-CFhWe_W6.js";
9
9
  import { t as isEmpty } from "./isEmpty-BhJRCqIF.js";
10
10
  import { t as cleanStackTrace } from "./stack-traces-BIE_5Xwf.js";
11
- import { i as wrapContent } from "./truncator-DZqEqnpD.js";
11
+ import { i as wrapContent } from "./truncator-CD7QtE84.js";
12
12
  import { parse } from "acorn";
13
13
  import { transforms } from "@bpinternal/zui";
14
14
  import bytes from "bytes";
@@ -754,7 +754,7 @@ const renderExamples = async (examples, components, exits) => {
754
754
  if (!examples.length) return "";
755
755
  const registry = new ComponentRegistry(components.map(componentToProtocolDefinition));
756
756
  const exitDefinitions = exits.map(exitToProtocolDefinition);
757
- const { parseAssistantResponse } = await import("./common-BlRFtdf2.js").then((n) => n.t);
757
+ const { parseAssistantResponse } = await import("./common-DuEhn6u3.js").then((n) => n.t);
758
758
  const render = (output) => {
759
759
  var _response$diagnostics;
760
760
  const response = parseAssistantResponse(`■start\n${output}\n■end`);
@@ -2113,6 +2113,7 @@ const SECTION_SEP = "\n";
2113
2113
  const NUMBER_LOCALE = new Intl.NumberFormat("en-US");
2114
2114
  const LONG_TEXT_LENGTH = 4096;
2115
2115
  const DEFAULT_OPTIONS = { tokens: 1e5 };
2116
+ const stringify = (value) => JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() + "n" : item);
2116
2117
  function printLimitedJson(obj, maxDepth, maxLength, maxKeys) {
2117
2118
  const indent = 2;
2118
2119
  let currentLength = 0;
@@ -2131,7 +2132,7 @@ function printLimitedJson(obj, maxDepth, maxLength, maxKeys) {
2131
2132
  }
2132
2133
  }
2133
2134
  if (typeof currentObj !== "object" || currentObj === null) {
2134
- const value = JSON.stringify(currentObj);
2135
+ const value = stringify(currentObj);
2135
2136
  currentLength += getTokenizer().count(value);
2136
2137
  return value;
2137
2138
  }
@@ -2203,10 +2204,10 @@ function previewValue(value, length = LONG_TEXT_LENGTH) {
2203
2204
  };
2204
2205
  const previewObj = (obj) => {
2205
2206
  const mapped = mapKeys(obj, (_value, key) => previewStr(key));
2206
- return JSON.stringify(mapped);
2207
+ return stringify(mapped);
2207
2208
  };
2208
2209
  if (typeof value === "string") return "<string> " + previewStr(value);
2209
- if (typeof value === "object" && Array.isArray(value)) return "<array> " + previewStr(JSON.stringify(value));
2210
+ if (typeof value === "object" && Array.isArray(value)) return "<array> " + previewStr(stringify(value));
2210
2211
  if (typeof value === "object" && value instanceof Date) return "<date> " + value.toISOString();
2211
2212
  if (typeof value === "object" && value instanceof RegExp) return "<regexp> " + value.toString();
2212
2213
  if (typeof value === "object") return "<object> " + previewObj(value);
@@ -2246,15 +2247,15 @@ function previewArray(arr, maxStringLength = LONG_TEXT_LENGTH) {
2246
2247
  lines.push("// Analysis Summary");
2247
2248
  lines.push(SUBTITLE_LN);
2248
2249
  const typesCount = countBy(arr, (item) => extractType(item, false));
2249
- const ordered = orderBy(arr.filter((item) => !isNil(item) && JSON.stringify(item).length < 100), (item) => JSON.stringify(item), "asc");
2250
+ const ordered = orderBy(arr.filter((item) => !isNil(item) && stringify(item).length < 100), (item) => stringify(item), "asc");
2250
2251
  const minValues = ordered.slice(0, 3).map((item) => previewValue(item, 10));
2251
2252
  const maxValues = ordered.slice(-3).map((item) => previewValue(item, 10));
2252
2253
  const uniqueItems = uniqWith(arr, isEqual);
2253
2254
  const nullValues = filter(arr, isNil).length;
2254
- const memoryUsage = bytes(JSON.stringify(arr).length);
2255
+ const memoryUsage = bytes(stringify(arr).length);
2255
2256
  lines.push(`Total Items: ${arr.length}`);
2256
2257
  lines.push(`Unique Items: ${uniqueItems.length}`);
2257
- lines.push(`Types: ${JSON.stringify(typesCount)}`);
2258
+ lines.push(`Types: ${stringify(typesCount)}`);
2258
2259
  lines.push(`Minimum Values: [${minValues.join(", ")}]`);
2259
2260
  lines.push(`Maximum Values: [${maxValues.join(", ")}]`);
2260
2261
  lines.push(`Memory Usage: ${memoryUsage}`);
@@ -2277,7 +2278,7 @@ function previewObject(obj, options) {
2277
2278
  const keys = Object.keys(obj);
2278
2279
  const uniqueEntries = uniq(Object.values(obj));
2279
2280
  const nilValues = filter(entries, ([, value]) => isNil(value)).length;
2280
- const memoryUsage = bytes(JSON.stringify(obj).length);
2281
+ const memoryUsage = bytes(stringify(obj).length);
2281
2282
  lines.push(`Total Entries: ${NUMBER_LOCALE.format(entries.length)}`);
2282
2283
  lines.push(`Keys: ${previewValue(keys)}`);
2283
2284
  lines.push(`Popular Types: ${previewValue(typesCount)}`);
@@ -2335,7 +2336,7 @@ const inspect = (value, name, options = DEFAULT_OPTIONS) => {
2335
2336
  let header = "";
2336
2337
  if (name) header = `// const ${name}: ${genericType}\n`;
2337
2338
  if (genericType === "Array") return header + previewArray(value, options.maxStringLength);
2338
- else if (genericType === "error") return header + previewError(value);
2339
+ else if (genericType === "error") return getTokenizer().truncate(header + previewError(value), options.tokens);
2339
2340
  else if (genericType === "object") return header + previewObject(value, options);
2340
2341
  else if (genericType === "boolean") return header + previewValue(value);
2341
2342
  else if (typeof value === "string") {
@@ -2344,7 +2345,7 @@ const inspect = (value, name, options = DEFAULT_OPTIONS) => {
2344
2345
  }
2345
2346
  return header + previewValue(value);
2346
2347
  } catch (err) {
2347
- return `Error: ${(err === null || err === void 0 ? void 0 : err.message) ?? "Unknown Error"}`;
2348
+ return getTokenizer().truncate(`Error: ${(err === null || err === void 0 ? void 0 : err.message) ?? "Unknown Error"}`, options.tokens);
2348
2349
  }
2349
2350
  };
2350
2351
  //#endregion
@@ -1,13 +1,13 @@
1
- const require_compiler = require("./compiler-C-OI9sim.cjs");
2
- const require_dual_modes = require("./dual-modes-DPXiuvNe.cjs");
3
- const require_common = require("./common-BnvrDnIT.cjs");
4
- const require_custom_client = require("./custom-client-DAsGRnYc.cjs");
5
- const require_utils = require("./utils-3ESwP3yg.cjs");
6
- const require_jsx = require("./jsx-owqxrquU.cjs");
1
+ const require_compiler = require("./compiler-BJJUmNS9.cjs");
2
+ const require_dual_modes = require("./dual-modes-BNHlj2qM.cjs");
3
+ const require_common = require("./common-DJkSpeqw.cjs");
4
+ const require_custom_client = require("./custom-client-B_o56CB4.cjs");
5
+ const require_utils = require("./utils-DGQ4sRke.cjs");
6
+ const require_jsx = require("./jsx-BJ6GWXI2.cjs");
7
7
  const require_stack_traces = require("./stack-traces-ntw_qhoy.cjs");
8
8
  const require_errors = require("./errors-C962uJdS.cjs");
9
- const require_truncator = require("./truncator-CLkouTCO.cjs");
10
- const require_vm = require("./vm-D6s1zF6M.cjs");
9
+ const require_truncator = require("./truncator-DmCu9M4m.cjs");
10
+ const require_vm = require("./vm-X0uTj5Aa.cjs");
11
11
  let _bpinternal_zui = require("@bpinternal/zui");
12
12
  let ulid = require("ulid");
13
13
  let _botpress_client = require("@botpress/client");
@@ -126,19 +126,21 @@ const STREAM_INACTIVITY_TIMEOUT = 18e4;
126
126
  /** A syntactically valid prefix must not execute when generation did not finish successfully. */
127
127
  const assertSuccessfulGeneration = (metadata) => {
128
128
  if (metadata.provider === "unknown") throw new require_errors.CognitiveError("LLM generation failed: received error metadata with unknown provider");
129
- if (metadata.stopReason === "max_tokens" || metadata.stopReason === "content_filter") throw new require_errors.CognitiveError(`LLM generation did not complete: stopReason=${metadata.stopReason}`);
129
+ if (metadata.stopReason === "max_tokens" || metadata.stopReason === "content_filter" || metadata.stopReason === "other") throw new require_errors.CognitiveError(`LLM generation did not complete: stopReason=${metadata.stopReason}`);
130
130
  };
131
131
  const getModelOutputLimit = (inputLength) => clamp(RESPONSE_LENGTH_BUFFER.PERCENTAGE * inputLength, RESPONSE_LENGTH_BUFFER.MIN_TOKENS, RESPONSE_LENGTH_BUFFER.MAX_TOKENS);
132
132
  const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, onSend, onSendDelta, onRunStart }) => {
133
133
  const startedAt = Date.now();
134
134
  const traces = iteration.traces;
135
- const modelRef = Array.isArray(iteration.model) ? iteration.model[0] : iteration.model;
136
- const model = await cognitive.getModelDetails(modelRef).catch((thrown) => {
135
+ controller.signal.throwIfAborted();
136
+ const modelRefs = Array.isArray(iteration.model) ? iteration.model : [iteration.model];
137
+ const models = await Promise.all(modelRefs.map((modelRef) => cognitive.getModelDetails(modelRef).catch((thrown) => {
137
138
  throw new require_errors.CognitiveError(`Failed to fetch model details for model "${modelRef}": ${require_utils.getErrorMessage(thrown)}`);
138
- });
139
- let modelLimit = Math.max(model.input.maxTokens, 8e3);
140
- if (ctx.maxTokens) modelLimit = Math.min(ctx.maxTokens, modelLimit);
141
- const responseLengthBuffer = getModelOutputLimit(modelLimit);
139
+ })));
140
+ controller.signal.throwIfAborted();
141
+ const model = models[0];
142
+ const modelLimit = Math.min(...models.map((model) => model.input.maxTokens), ctx.maxTokens ?? Infinity);
143
+ const responseLengthBuffer = Math.min(getModelOutputLimit(modelLimit), Math.floor(modelLimit / 2));
142
144
  if (iteration.tokens) iteration.tokens.limit = modelLimit;
143
145
  let messages;
144
146
  try {
@@ -358,6 +360,7 @@ const generateCode = async ({ iteration, ctx, cognitive, controller, metadata, o
358
360
  const response = await cognitive.generateText(input, { signal: controller.signal }).catch((thrown) => {
359
361
  throw new require_errors.CognitiveError(`LLM generation failed: ${require_utils.getErrorMessage(thrown)}`);
360
362
  });
363
+ controller.signal.throwIfAborted();
361
364
  if (response.error) throw new require_errors.CognitiveError(`LLM generation failed: ${response.error}`);
362
365
  if (!response.output) throw new require_errors.CognitiveError("LLM did not return any text output");
363
366
  responseMetadata = response.metadata;
@@ -568,8 +571,10 @@ const finalizeIteration = async ({ iteration, status, controller, onIterationEnd
568
571
  //#region src/runtime/tool-wrapper.ts
569
572
  const SLOW_TOOL_WARNING = (0, ms.default)("15s");
570
573
  function wrapTool({ chat, tool, traces, object, iteration, beforeHook, afterHook, controller }) {
571
- const getToolInput = (input) => tool.zInput.safeParse(input).data ?? input;
574
+ const traceSchema = tool.input ? require_utils.fromJSONSchemaCompat(tool.input) : void 0;
575
+ const getToolInput = (input) => (traceSchema === null || traceSchema === void 0 ? void 0 : traceSchema.safeParse(input).data) ?? input;
572
576
  return async function(input) {
577
+ controller.signal.throwIfAborted();
573
578
  const toolCallId = `tcall_${(0, ulid.ulid)()}`;
574
579
  const originalInput = input;
575
580
  let effectiveInput = input;
@@ -645,6 +650,7 @@ function wrapTool({ chat, tool, traces, object, iteration, beforeHook, afterHook
645
650
  object,
646
651
  toolCallId
647
652
  }));
653
+ controller.signal.throwIfAborted();
648
654
  if (typeof (beforeRes === null || beforeRes === void 0 ? void 0 : beforeRes.input) !== "undefined") effectiveInput = beforeRes.input;
649
655
  output = await tool.execute(effectiveInput, {
650
656
  callId: toolCallId,
@@ -661,9 +667,16 @@ function wrapTool({ chat, tool, traces, object, iteration, beforeHook, afterHook
661
667
  }));
662
668
  if (typeof (afterRes === null || afterRes === void 0 ? void 0 : afterRes.output) !== "undefined") output = afterRes.output;
663
669
  } catch (err) {
664
- if (!await handleSignals(err)) {
670
+ try {
671
+ if (!await handleSignals(err)) {
672
+ success = false;
673
+ error = err;
674
+ output = void 0;
675
+ }
676
+ } catch (hookError) {
665
677
  success = false;
666
- error = err;
678
+ error = hookError;
679
+ output = void 0;
667
680
  }
668
681
  } finally {
669
682
  clearTimeout(alertSlowTool);