llmz 0.0.22 → 0.0.24

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.
@@ -2616,8 +2616,7 @@ var _a;
2616
2616
  var IS_CI = typeof process !== "undefined" && !!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.CI);
2617
2617
  var _a2;
2618
2618
  var VM_DRIVER = _nullishCoalesce((typeof process !== "undefined" && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.VM_DRIVER)), () => ( (IS_CI ? "node" : "isolated-vm")));
2619
- var USE_ISOLATED_VM = IS_NODE && VM_DRIVER === "isolated-vm";
2620
- var LINE_OFFSET = USE_ISOLATED_VM ? 3 : 1;
2619
+ var CAN_USE_ISOLATED_VM = IS_NODE && VM_DRIVER === "isolated-vm";
2621
2620
  var MAX_VM_EXECUTION_TIME = 6e4;
2622
2621
  var requireEsm = async (id) => {
2623
2622
  if (typeof globalThis.window === "undefined" && typeof globalThis.require !== "undefined") {
@@ -2723,7 +2722,16 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
2723
2722
  traces.push({ type: "yield", value, started_at: startedAt, ended_at: Date.now() });
2724
2723
  }
2725
2724
  };
2726
- if (!USE_ISOLATED_VM) {
2725
+ let DRIVER = CAN_USE_ISOLATED_VM ? "isolated-vm" : "node";
2726
+ let isolatedVm;
2727
+ if (DRIVER === "isolated-vm") {
2728
+ try {
2729
+ isolatedVm = await getIsolatedVm();
2730
+ } catch (e3) {
2731
+ DRIVER = "node";
2732
+ }
2733
+ }
2734
+ if (DRIVER === "node") {
2727
2735
  const AsyncFunction = async function* () {
2728
2736
  }.constructor;
2729
2737
  return await (async () => {
@@ -2758,16 +2766,18 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
2758
2766
  lines_executed: Array.from(lines_executed),
2759
2767
  return_value: res
2760
2768
  };
2761
- }).catch((err) => handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall)).catch((err) => handleCatch(err, traces, variables, lines_executed));
2769
+ }).catch((err) => handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall, DRIVER)).catch((err) => handleCatch(err, traces, variables, lines_executed));
2770
+ }
2771
+ if (!isolatedVm) {
2772
+ throw new Error("isolated-vm is not available");
2762
2773
  }
2763
- const isolatedVm = await getIsolatedVm();
2764
2774
  const isolate = new isolatedVm.Isolate({ memoryLimit: 128 });
2765
2775
  const isolatedContext = await isolate.createContext();
2766
2776
  const jail = isolatedContext.global;
2767
2777
  const trackedProperties = /* @__PURE__ */ new Set();
2768
2778
  const referenceProperties = /* @__PURE__ */ new Set();
2769
2779
  const abort = () => {
2770
- if (USE_ISOLATED_VM) {
2780
+ if (DRIVER === "isolated-vm") {
2771
2781
  isolate.dispose();
2772
2782
  isolatedContext.release();
2773
2783
  }
@@ -3012,7 +3022,7 @@ do {
3012
3022
  };
3013
3023
  },
3014
3024
  (err) => {
3015
- return handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall);
3025
+ return handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall, DRIVER);
3016
3026
  }
3017
3027
  ).catch((err) => {
3018
3028
  if (signal == null ? void 0 : signal.aborted) {
@@ -3025,21 +3035,22 @@ do {
3025
3035
  signal == null ? void 0 : signal.removeEventListener("abort", abort);
3026
3036
  try {
3027
3037
  isolate.dispose();
3028
- } catch (e3) {
3038
+ } catch (e4) {
3029
3039
  }
3030
3040
  try {
3031
3041
  isolatedContext.release();
3032
- } catch (e4) {
3042
+ } catch (e5) {
3033
3043
  }
3034
3044
  return final;
3035
3045
  }
3036
- var handleError = (err, code, consumer, traces, variables, lines_executed, currentToolCall) => {
3046
+ var handleError = (err, code, consumer, traces, variables, lines_executed, currentToolCall, driver = "isolated-vm") => {
3037
3047
  var _a3, _b, _c;
3038
3048
  err = _chunkJDABP4SDcjs.Signals.maybeDeserializeError(err);
3039
3049
  const lines = code.split("\n");
3040
3050
  const stackTrace = err.stack || "";
3051
+ const LINE_OFFSET = driver === "isolated-vm" ? 3 : 1;
3041
3052
  let regex = /\(<isolated-vm>:(\d+):(\d+)/g;
3042
- if (!USE_ISOLATED_VM) {
3053
+ if (driver === "node") {
3043
3054
  regex = /<anonymous>:(\d+):(\d+)/g;
3044
3055
  }
3045
3056
  const matches = [...stackTrace.matchAll(regex)].map((x) => {
@@ -3067,8 +3078,8 @@ var handleError = (err, code, consumer, traces, variables, lines_executed, curre
3067
3078
  }
3068
3079
  };
3069
3080
  for (let i = 0; i < lines.length; i++) {
3070
- const VM_OFFSET = USE_ISOLATED_VM ? 2 : 2;
3071
- const DISPLAY_OFFSET = USE_ISOLATED_VM ? 2 : 0;
3081
+ const VM_OFFSET = driver === "isolated-vm" ? 2 : 2;
3082
+ const DISPLAY_OFFSET = driver === "isolated-vm" ? 2 : 0;
3072
3083
  const line = lines[i];
3073
3084
  const correctedStackLineIndex = i + LINE_OFFSET + VM_OFFSET;
3074
3085
  const match = matches.find((x) => x.line + VM_OFFSET === correctedStackLineIndex);
@@ -3120,4 +3131,4 @@ var handleCatch = (err, traces, variables, lines_executed) => {
3120
3131
 
3121
3132
 
3122
3133
 
3123
- exports.USE_ISOLATED_VM = USE_ISOLATED_VM; exports.runAsyncFunction = runAsyncFunction;
3134
+ exports.CAN_USE_ISOLATED_VM = CAN_USE_ISOLATED_VM; exports.runAsyncFunction = runAsyncFunction;
@@ -2616,8 +2616,7 @@ var _a;
2616
2616
  var IS_CI = typeof process !== "undefined" && !!((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.CI);
2617
2617
  var _a2;
2618
2618
  var VM_DRIVER = (typeof process !== "undefined" && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.VM_DRIVER)) ?? (IS_CI ? "node" : "isolated-vm");
2619
- var USE_ISOLATED_VM = IS_NODE && VM_DRIVER === "isolated-vm";
2620
- var LINE_OFFSET = USE_ISOLATED_VM ? 3 : 1;
2619
+ var CAN_USE_ISOLATED_VM = IS_NODE && VM_DRIVER === "isolated-vm";
2621
2620
  var MAX_VM_EXECUTION_TIME = 6e4;
2622
2621
  var requireEsm = async (id) => {
2623
2622
  if (typeof globalThis.window === "undefined" && typeof globalThis.require !== "undefined") {
@@ -2723,7 +2722,16 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
2723
2722
  traces.push({ type: "yield", value, started_at: startedAt, ended_at: Date.now() });
2724
2723
  }
2725
2724
  };
2726
- if (!USE_ISOLATED_VM) {
2725
+ let DRIVER = CAN_USE_ISOLATED_VM ? "isolated-vm" : "node";
2726
+ let isolatedVm;
2727
+ if (DRIVER === "isolated-vm") {
2728
+ try {
2729
+ isolatedVm = await getIsolatedVm();
2730
+ } catch {
2731
+ DRIVER = "node";
2732
+ }
2733
+ }
2734
+ if (DRIVER === "node") {
2727
2735
  const AsyncFunction = async function* () {
2728
2736
  }.constructor;
2729
2737
  return await (async () => {
@@ -2758,16 +2766,18 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
2758
2766
  lines_executed: Array.from(lines_executed),
2759
2767
  return_value: res
2760
2768
  };
2761
- }).catch((err) => handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall)).catch((err) => handleCatch(err, traces, variables, lines_executed));
2769
+ }).catch((err) => handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall, DRIVER)).catch((err) => handleCatch(err, traces, variables, lines_executed));
2770
+ }
2771
+ if (!isolatedVm) {
2772
+ throw new Error("isolated-vm is not available");
2762
2773
  }
2763
- const isolatedVm = await getIsolatedVm();
2764
2774
  const isolate = new isolatedVm.Isolate({ memoryLimit: 128 });
2765
2775
  const isolatedContext = await isolate.createContext();
2766
2776
  const jail = isolatedContext.global;
2767
2777
  const trackedProperties = /* @__PURE__ */ new Set();
2768
2778
  const referenceProperties = /* @__PURE__ */ new Set();
2769
2779
  const abort = () => {
2770
- if (USE_ISOLATED_VM) {
2780
+ if (DRIVER === "isolated-vm") {
2771
2781
  isolate.dispose();
2772
2782
  isolatedContext.release();
2773
2783
  }
@@ -3012,7 +3022,7 @@ do {
3012
3022
  };
3013
3023
  },
3014
3024
  (err) => {
3015
- return handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall);
3025
+ return handleError(err, code, consumer, traces, variables, lines_executed, currentToolCall, DRIVER);
3016
3026
  }
3017
3027
  ).catch((err) => {
3018
3028
  if (signal == null ? void 0 : signal.aborted) {
@@ -3033,13 +3043,14 @@ do {
3033
3043
  }
3034
3044
  return final;
3035
3045
  }
3036
- var handleError = (err, code, consumer, traces, variables, lines_executed, currentToolCall) => {
3046
+ var handleError = (err, code, consumer, traces, variables, lines_executed, currentToolCall, driver = "isolated-vm") => {
3037
3047
  var _a3, _b, _c;
3038
3048
  err = Signals.maybeDeserializeError(err);
3039
3049
  const lines = code.split("\n");
3040
3050
  const stackTrace = err.stack || "";
3051
+ const LINE_OFFSET = driver === "isolated-vm" ? 3 : 1;
3041
3052
  let regex = /\(<isolated-vm>:(\d+):(\d+)/g;
3042
- if (!USE_ISOLATED_VM) {
3053
+ if (driver === "node") {
3043
3054
  regex = /<anonymous>:(\d+):(\d+)/g;
3044
3055
  }
3045
3056
  const matches = [...stackTrace.matchAll(regex)].map((x) => {
@@ -3067,8 +3078,8 @@ var handleError = (err, code, consumer, traces, variables, lines_executed, curre
3067
3078
  }
3068
3079
  };
3069
3080
  for (let i = 0; i < lines.length; i++) {
3070
- const VM_OFFSET = USE_ISOLATED_VM ? 2 : 2;
3071
- const DISPLAY_OFFSET = USE_ISOLATED_VM ? 2 : 0;
3081
+ const VM_OFFSET = driver === "isolated-vm" ? 2 : 2;
3082
+ const DISPLAY_OFFSET = driver === "isolated-vm" ? 2 : 0;
3072
3083
  const line = lines[i];
3073
3084
  const correctedStackLineIndex = i + LINE_OFFSET + VM_OFFSET;
3074
3085
  const match = matches.find((x) => x.line + VM_OFFSET === correctedStackLineIndex);
@@ -3118,6 +3129,6 @@ var handleCatch = (err, traces, variables, lines_executed) => {
3118
3129
  };
3119
3130
 
3120
3131
  export {
3121
- USE_ISOLATED_VM,
3132
+ CAN_USE_ISOLATED_VM,
3122
3133
  runAsyncFunction
3123
3134
  };
package/dist/index.cjs CHANGED
@@ -1103,16 +1103,16 @@ var utils = {
1103
1103
  truncateWrappedContent: _chunkGZPN7RGHcjs.truncateWrappedContent
1104
1104
  };
1105
1105
  var execute = async (props) => {
1106
- const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-GIUS3TQ2.cjs")));
1106
+ const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-UUZTBIF3.cjs")));
1107
1107
  return executeContext(props);
1108
1108
  };
1109
1109
  var init = async () => {
1110
- await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-GIUS3TQ2.cjs")));
1110
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-UUZTBIF3.cjs")));
1111
1111
  await Promise.resolve().then(() => _interopRequireWildcard(require("./component-R4WTW6DZ.cjs")));
1112
1112
  await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-O4SFRIE4.cjs")));
1113
1113
  await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-XAYKJ6TR.cjs")));
1114
1114
  await Promise.resolve().then(() => _interopRequireWildcard(require("./jsx-AJAXBWFE.cjs")));
1115
- await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-AW2BASES.cjs")));
1115
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-PRZ5GEM2.cjs")));
1116
1116
  await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-L5QAQXV2.cjs")));
1117
1117
  await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-W3NXBLYJ.cjs")));
1118
1118
  await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-Y45GMPZT.cjs")));
package/dist/index.js CHANGED
@@ -1103,16 +1103,16 @@ var utils = {
1103
1103
  truncateWrappedContent
1104
1104
  };
1105
1105
  var execute = async (props) => {
1106
- const { executeContext } = await import("./llmz-O27EUBHG.js");
1106
+ const { executeContext } = await import("./llmz-IUGXC4SH.js");
1107
1107
  return executeContext(props);
1108
1108
  };
1109
1109
  var init = async () => {
1110
- await import("./llmz-O27EUBHG.js");
1110
+ await import("./llmz-IUGXC4SH.js");
1111
1111
  await import("./component-WFVDVSDK.js");
1112
1112
  await import("./tool-PCOYOCRH.js");
1113
1113
  await import("./exit-YLO7BY7Z.js");
1114
1114
  await import("./jsx-AEHVFB3L.js");
1115
- await import("./vm-IUUM5RIZ.js");
1115
+ await import("./vm-CYC5RLKU.js");
1116
1116
  await import("./utils-RQHQ2KOG.js");
1117
1117
  await import("./truncator-BSP6PQPC.js");
1118
1118
  await import("./typings-WYHEFCYB.js");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runAsyncFunction
3
- } from "./chunk-ROGRW6ZK.js";
3
+ } from "./chunk-LUX4X7XO.js";
4
4
  import {
5
5
  Context,
6
6
  ErrorExecutionResult,
@@ -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 _chunkX2SBZ4BQcjs = require('./chunk-X2SBZ4BQ.cjs');
3
+ var _chunkBNDY7RGXcjs = require('./chunk-BNDY7RGX.cjs');
4
4
 
5
5
 
6
6
 
@@ -361,7 +361,7 @@ var executeIteration = async ({
361
361
  });
362
362
  }
363
363
  startedAt = Date.now();
364
- const result = await _chunkX2SBZ4BQcjs.runAsyncFunction.call(void 0,
364
+ const result = await _chunkBNDY7RGXcjs.runAsyncFunction.call(void 0,
365
365
  vmContext,
366
366
  iteration.code,
367
367
  traces,
@@ -1,12 +1,12 @@
1
1
  import {
2
- USE_ISOLATED_VM,
2
+ CAN_USE_ISOLATED_VM,
3
3
  runAsyncFunction
4
- } from "./chunk-ROGRW6ZK.js";
4
+ } from "./chunk-LUX4X7XO.js";
5
5
  import "./chunk-JKVVQN2P.js";
6
6
  import "./chunk-JQBT7UWN.js";
7
7
  import "./chunk-ORQP26SZ.js";
8
8
  import "./chunk-7WRN4E42.js";
9
9
  export {
10
- USE_ISOLATED_VM,
10
+ CAN_USE_ISOLATED_VM,
11
11
  runAsyncFunction
12
12
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkX2SBZ4BQcjs = require('./chunk-X2SBZ4BQ.cjs');
4
+ var _chunkBNDY7RGXcjs = require('./chunk-BNDY7RGX.cjs');
5
5
  require('./chunk-JDABP4SD.cjs');
6
6
  require('./chunk-IKSIOIIP.cjs');
7
7
  require('./chunk-KMZDFWYZ.cjs');
@@ -9,4 +9,4 @@ require('./chunk-UQOBUJIQ.cjs');
9
9
 
10
10
 
11
11
 
12
- exports.USE_ISOLATED_VM = _chunkX2SBZ4BQcjs.USE_ISOLATED_VM; exports.runAsyncFunction = _chunkX2SBZ4BQcjs.runAsyncFunction;
12
+ exports.CAN_USE_ISOLATED_VM = _chunkBNDY7RGXcjs.CAN_USE_ISOLATED_VM; exports.runAsyncFunction = _chunkBNDY7RGXcjs.runAsyncFunction;
package/dist/vm.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Trace, VMExecutionResult } from './types.js';
2
- export declare const USE_ISOLATED_VM: boolean;
2
+ export declare const CAN_USE_ISOLATED_VM: boolean;
3
3
  export declare function runAsyncFunction(context: any, code: string, traces?: Trace[], signal?: AbortSignal | null, timeout?: number): Promise<VMExecutionResult>;
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.22",
5
+ "version": "0.0.24",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "@babel/standalone": "^7.26.4",
35
35
  "@babel/traverse": "^7.26.4",
36
36
  "@babel/types": "^7.26.3",
37
- "@botpress/client": "1.24.2",
37
+ "@botpress/client": "1.25.0",
38
38
  "bytes": "^3.1.2",
39
39
  "exponential-backoff": "^3.1.1",
40
40
  "handlebars": "^4.7.8",
@@ -59,7 +59,7 @@
59
59
  "chalk": "^4.1.2",
60
60
  "diff": "^8.0.1",
61
61
  "dotenv": "^16.4.4",
62
- "esbuild": "^0.16.12",
62
+ "esbuild": "^0.25.10",
63
63
  "glob": "^9.3.4",
64
64
  "source-map-js": "1.2.1",
65
65
  "ts-node": "^10.9.2",
@@ -67,7 +67,7 @@
67
67
  "tsx": "^4.19.2"
68
68
  },
69
69
  "peerDependencies": {
70
- "@botpress/cognitive": "0.1.36",
70
+ "@botpress/cognitive": "0.1.41",
71
71
  "@bpinternal/thicktoken": "^1.0.5",
72
72
  "@bpinternal/zui": "^1.0.1"
73
73
  },