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.
- package/dist/{common-BnvrDnIT.cjs → common-DJkSpeqw.cjs} +1 -1
- package/dist/{common-BlRFtdf2.js → common-DuEhn6u3.js} +1 -1
- package/dist/compiler/plugins/variable-extraction.d.ts +1 -7
- package/dist/{compiler-C-OI9sim.cjs → compiler-BJJUmNS9.cjs} +34 -68
- package/dist/{compiler-CW1VjQsn.js → compiler-BPl-5CXh.js} +34 -68
- package/dist/{component-C6Agl2ns.cjs → component-CPKXe6Ca.cjs} +2 -2
- package/dist/{custom-client-DAsGRnYc.cjs → custom-client-B_o56CB4.cjs} +6 -6
- package/dist/{custom-client-ChuZ63zp.js → custom-client-C-nDKG37.js} +3 -3
- package/dist/{dual-modes-DPXiuvNe.cjs → dual-modes-BNHlj2qM.cjs} +15 -14
- package/dist/{dual-modes-DDkoCp3R.js → dual-modes-BNIiNLrR.js} +13 -12
- package/dist/{execute-DM2-7y86.cjs → execute-0bvqakr7.cjs} +31 -18
- package/dist/{execute-BWcdv9so.js → execute-CWFIL5ny.js} +30 -17
- package/dist/{exit-DUM96DN1.cjs → exit-CGLXI0BH.cjs} +2 -2
- package/dist/index.cjs +21 -21
- package/dist/index.js +12 -12
- package/dist/index.workerd.js +217 -195
- package/dist/{jsx-owqxrquU.cjs → jsx-BJ6GWXI2.cjs} +1 -1
- package/dist/runtime/generate.test.d.ts +1 -0
- package/dist/{tool-Bv8N4IPj.js → tool-B6Pmuk6K.js} +35 -49
- package/dist/{tool-Dy6AJpJH.cjs → tool-BLTrA-sL.cjs} +38 -52
- package/dist/tool.d.ts +5 -3
- package/dist/{truncator-DZqEqnpD.js → truncator-CD7QtE84.js} +11 -6
- package/dist/{truncator-CLkouTCO.cjs → truncator-DmCu9M4m.cjs} +13 -8
- package/dist/{typings-3lsqCbkn.cjs → typings-DXJMu59O.cjs} +2 -2
- package/dist/{utils-3ESwP3yg.cjs → utils-DGQ4sRke.cjs} +1 -1
- package/dist/{vm-BLsHw1da.js → vm-Cn3jvZ00.js} +109 -53
- package/dist/{vm-D6s1zF6M.cjs → vm-X0uTj5Aa.cjs} +109 -53
- package/package.json +2 -2
|
@@ -3,7 +3,7 @@ import { B as isSymbol, I as isFunction, M as baseAssignValue, t as baseIteratee
|
|
|
3
3
|
import { t as baseForOwn } from "./_baseForOwn-CFhWe_W6.js";
|
|
4
4
|
import { t as cleanStackTrace } from "./stack-traces-BIE_5Xwf.js";
|
|
5
5
|
import { a as InvalidCodeError, c as SnapshotSignal, n as CodeExecutionError, s as Signals, u as VMSignal } from "./errors-Cg1G0Awu.js";
|
|
6
|
-
import { n as compile, t as Identifiers } from "./compiler-
|
|
6
|
+
import { n as compile, t as Identifiers } from "./compiler-BPl-5CXh.js";
|
|
7
7
|
import { n as getQuickJSVariant } from "./quickjs-variant-BYhMBpwU.js";
|
|
8
8
|
import { newQuickJSWASMModuleFromVariant, shouldInterruptAfterDeadline } from "quickjs-emscripten-core";
|
|
9
9
|
//#region ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGt.js
|
|
@@ -2481,6 +2481,22 @@ var QuickJSDriver = class {
|
|
|
2481
2481
|
const trackedProperties = /* @__PURE__ */ new Set();
|
|
2482
2482
|
const referenceProperties = /* @__PURE__ */ new Set();
|
|
2483
2483
|
const pendingPromises = [];
|
|
2484
|
+
const variableGetters = /* @__PURE__ */ new Map();
|
|
2485
|
+
const objectConstructor = vm.getProp(vm.global, "Object");
|
|
2486
|
+
const freezeFunction = vm.getProp(objectConstructor, "freeze");
|
|
2487
|
+
objectConstructor.dispose();
|
|
2488
|
+
const preserveFreeze = (value, handle) => {
|
|
2489
|
+
if (Object.isFrozen(value)) {
|
|
2490
|
+
const frozen = vm.callFunction(freezeFunction, vm.undefined, handle);
|
|
2491
|
+
try {
|
|
2492
|
+
frozen.unwrap().dispose();
|
|
2493
|
+
} catch (error) {
|
|
2494
|
+
handle.dispose();
|
|
2495
|
+
throw error;
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
return handle;
|
|
2499
|
+
};
|
|
2484
2500
|
const toVmValue = (value) => {
|
|
2485
2501
|
if (typeof value === "string") return vm.newString(value);
|
|
2486
2502
|
else if (typeof value === "number") return vm.newNumber(value);
|
|
@@ -2488,21 +2504,13 @@ var QuickJSDriver = class {
|
|
|
2488
2504
|
else if (value === null) return vm.null;
|
|
2489
2505
|
else if (value === void 0) return vm.undefined;
|
|
2490
2506
|
else if (Array.isArray(value)) {
|
|
2491
|
-
const
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
else if (typeof item === "object") return JSON.stringify(item);
|
|
2497
|
-
return "undefined";
|
|
2507
|
+
const array = vm.newArray();
|
|
2508
|
+
value.forEach((item, index) => {
|
|
2509
|
+
const handle = toVmValue(item);
|
|
2510
|
+
vm.setProp(array, index, handle);
|
|
2511
|
+
disposeIfNeeded(handle);
|
|
2498
2512
|
});
|
|
2499
|
-
|
|
2500
|
-
if ("error" in result) {
|
|
2501
|
-
var _result$error;
|
|
2502
|
-
(_result$error = result.error) === null || _result$error === void 0 || _result$error.dispose();
|
|
2503
|
-
return vm.undefined;
|
|
2504
|
-
}
|
|
2505
|
-
return result.value;
|
|
2513
|
+
return preserveFreeze(value, array);
|
|
2506
2514
|
} else if (typeof value === "object") {
|
|
2507
2515
|
const obj = vm.newObject();
|
|
2508
2516
|
for (const [k, v] of Object.entries(value)) if (typeof v !== "function") {
|
|
@@ -2510,7 +2518,7 @@ var QuickJSDriver = class {
|
|
|
2510
2518
|
vm.setProp(obj, k, propHandle);
|
|
2511
2519
|
disposeIfNeeded(propHandle);
|
|
2512
2520
|
}
|
|
2513
|
-
return obj;
|
|
2521
|
+
return preserveFreeze(value, obj);
|
|
2514
2522
|
}
|
|
2515
2523
|
return vm.undefined;
|
|
2516
2524
|
};
|
|
@@ -2541,8 +2549,9 @@ var QuickJSDriver = class {
|
|
|
2541
2549
|
};
|
|
2542
2550
|
};
|
|
2543
2551
|
try {
|
|
2552
|
+
installValueReader(vm);
|
|
2544
2553
|
bridgeContextToVM(context, vm, trackedProperties, referenceProperties, toVmValue, disposeIfNeeded, bridgeFunction);
|
|
2545
|
-
setupVariableTrackingBridge(vm, variables);
|
|
2554
|
+
setupVariableTrackingBridge(vm, variables, variableGetters);
|
|
2546
2555
|
const scriptCode = buildScriptCode(transformed.code);
|
|
2547
2556
|
const copyBackContextFromVM = () => {
|
|
2548
2557
|
for (const key of trackedProperties) {
|
|
@@ -2599,7 +2608,7 @@ var QuickJSDriver = class {
|
|
|
2599
2608
|
let returnValue = void 0;
|
|
2600
2609
|
if (resultSet) {
|
|
2601
2610
|
const resultResult = vm.evalCode("globalThis.__llmz_result");
|
|
2602
|
-
returnValue = vm
|
|
2611
|
+
returnValue = readVmValue(vm, resultResult.unwrap());
|
|
2603
2612
|
resultResult.unwrap().dispose();
|
|
2604
2613
|
}
|
|
2605
2614
|
returnValue = Signals.maybeDeserializeError(returnValue);
|
|
@@ -2631,6 +2640,8 @@ var QuickJSDriver = class {
|
|
|
2631
2640
|
})).catch(() => {});
|
|
2632
2641
|
return handleErrorQuickJS(err, code, consumer, traces, variables, lines_executed, userCodeStartLine, ctx.currentToolCall ?? state.currentToolCall);
|
|
2633
2642
|
} finally {
|
|
2643
|
+
for (const getter of variableGetters.values()) getter.dispose();
|
|
2644
|
+
freezeFunction.dispose();
|
|
2634
2645
|
try {
|
|
2635
2646
|
vm.dispose();
|
|
2636
2647
|
} catch {}
|
|
@@ -2780,7 +2791,7 @@ function bridgeContextToVM(context, vm, trackedProperties, referenceProperties,
|
|
|
2780
2791
|
}
|
|
2781
2792
|
}
|
|
2782
2793
|
function bridgeGetterSetter(vm, key, prop, descriptor, context, toVmValue) {
|
|
2783
|
-
var _result$
|
|
2794
|
+
var _result$error;
|
|
2784
2795
|
const target = prop ? `${key}` : "globalThis";
|
|
2785
2796
|
const propName = prop ?? key;
|
|
2786
2797
|
const prefix = prop ? `${key}_${prop}` : key;
|
|
@@ -2802,7 +2813,7 @@ function bridgeGetterSetter(vm, key, prop, descriptor, context, toVmValue) {
|
|
|
2802
2813
|
if (descriptor.set) {
|
|
2803
2814
|
const setterBridge = vm.newFunction(`set_${propName}`, (valueHandle) => {
|
|
2804
2815
|
try {
|
|
2805
|
-
const jsValue = vm
|
|
2816
|
+
const jsValue = readVmValue(vm, valueHandle, true);
|
|
2806
2817
|
if (prop) context[key][prop] = jsValue;
|
|
2807
2818
|
else context[key] = jsValue;
|
|
2808
2819
|
return vm.undefined;
|
|
@@ -2824,31 +2835,88 @@ function bridgeGetterSetter(vm, key, prop, descriptor, context, toVmValue) {
|
|
|
2824
2835
|
});
|
|
2825
2836
|
`;
|
|
2826
2837
|
const result = vm.evalCode(definePropertyCode);
|
|
2827
|
-
if ("error" in result) (_result$
|
|
2838
|
+
if ("error" in result) (_result$error = result.error) === null || _result$error === void 0 || _result$error.dispose();
|
|
2828
2839
|
else result.value.dispose();
|
|
2829
2840
|
}
|
|
2830
|
-
function
|
|
2831
|
-
|
|
2841
|
+
function installValueReader(vm) {
|
|
2842
|
+
vm.evalCode(`
|
|
2843
|
+
globalThis.__llmz_read_value = function encode(value, strict, seen = new Set()) {
|
|
2844
|
+
if (value === undefined) return ['undefined'];
|
|
2845
|
+
if (typeof value === 'number') {
|
|
2846
|
+
if (strict && !Number.isFinite(value)) throw new Error('Non-finite numbers cannot be assigned to host properties');
|
|
2847
|
+
return ['number', Object.is(value, -0) ? '-0' : String(value)];
|
|
2848
|
+
}
|
|
2849
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') return ['value', value];
|
|
2850
|
+
if (typeof value !== 'object') throw new Error('Unsupported VM value: ' + typeof value);
|
|
2851
|
+
if (seen.has(value)) throw new Error('Cyclic VM values cannot be transferred');
|
|
2852
|
+
if (value instanceof Date) return ['value', value.toJSON()];
|
|
2853
|
+
seen.add(value);
|
|
2854
|
+
try {
|
|
2855
|
+
if (Array.isArray(value)) return ['array', Array.from(value, item => encode(item, strict, seen))];
|
|
2856
|
+
return ['object', Object.entries(value).map(([key, item]) => [key, encode(item, strict, seen)])];
|
|
2857
|
+
} finally {
|
|
2858
|
+
seen.delete(value);
|
|
2859
|
+
}
|
|
2860
|
+
};
|
|
2861
|
+
`).unwrap().dispose();
|
|
2862
|
+
}
|
|
2863
|
+
function readVmValue(vm, handle, strict = false) {
|
|
2864
|
+
const decode = ([type, value]) => {
|
|
2865
|
+
if (type === "undefined") return void 0;
|
|
2866
|
+
if (type === "number") return Number(value);
|
|
2867
|
+
if (type === "array") return value.map(decode);
|
|
2868
|
+
if (type === "object") return Object.fromEntries(value.map(([key, item]) => [key, decode(item)]));
|
|
2869
|
+
return value;
|
|
2870
|
+
};
|
|
2871
|
+
const encoder = vm.getProp(vm.global, "__llmz_read_value");
|
|
2872
|
+
try {
|
|
2873
|
+
const result = vm.callFunction(encoder, vm.undefined, handle, strict ? vm.true : vm.false);
|
|
2874
|
+
if (result.error) {
|
|
2875
|
+
const error = vm.dump(result.error);
|
|
2876
|
+
result.error.dispose();
|
|
2877
|
+
if (strict) throw new Error(error.message);
|
|
2878
|
+
const copy = handle.dup();
|
|
2879
|
+
try {
|
|
2880
|
+
return vm.dump(copy);
|
|
2881
|
+
} finally {
|
|
2882
|
+
if (copy.alive) copy.dispose();
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
try {
|
|
2886
|
+
return decode(vm.dump(result.value));
|
|
2887
|
+
} finally {
|
|
2888
|
+
result.value.dispose();
|
|
2889
|
+
}
|
|
2890
|
+
} finally {
|
|
2891
|
+
encoder.dispose();
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
function setupVariableTrackingBridge(vm, variables, getters) {
|
|
2895
|
+
const tracker = vm.newFunction(Identifiers.VariableTrackingFnIdentifier, (nameHandle, getterHandle) => {
|
|
2896
|
+
var _getters$get;
|
|
2832
2897
|
const name = vm.getString(nameHandle);
|
|
2833
2898
|
if (NO_TRACKING.includes(name)) return;
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2899
|
+
(_getters$get = getters.get(name)) === null || _getters$get === void 0 || _getters$get.dispose();
|
|
2900
|
+
const getter = getterHandle.dup();
|
|
2901
|
+
getters.set(name, getter);
|
|
2902
|
+
variables[name] = () => {
|
|
2903
|
+
const result = vm.callFunction(getter, vm.undefined);
|
|
2904
|
+
if (result.error) {
|
|
2905
|
+
result.error.dispose();
|
|
2906
|
+
return "[[non-primitive]]";
|
|
2841
2907
|
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2908
|
+
try {
|
|
2909
|
+
if (vm.typeof(result.value) === "function") return "[[non-primitive]]";
|
|
2910
|
+
return readVmValue(vm, result.value);
|
|
2911
|
+
} catch {
|
|
2912
|
+
return "[[non-primitive]]";
|
|
2913
|
+
} finally {
|
|
2914
|
+
result.value.dispose();
|
|
2915
|
+
}
|
|
2916
|
+
};
|
|
2849
2917
|
});
|
|
2850
|
-
vm.setProp(vm.global, Identifiers.VariableTrackingFnIdentifier,
|
|
2851
|
-
|
|
2918
|
+
vm.setProp(vm.global, Identifiers.VariableTrackingFnIdentifier, tracker);
|
|
2919
|
+
tracker.dispose();
|
|
2852
2920
|
}
|
|
2853
2921
|
function buildScriptCode(transformedCode) {
|
|
2854
2922
|
return `
|
|
@@ -2919,21 +2987,10 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2919
2987
|
});
|
|
2920
2988
|
context ??= {};
|
|
2921
2989
|
for (const name of Array.from(transformed.variables)) delete context[name];
|
|
2922
|
-
let driver;
|
|
2990
|
+
let driver = new NodeDriver();
|
|
2923
2991
|
if (useQuickJS()) try {
|
|
2992
|
+
await loadQuickJSModule();
|
|
2924
2993
|
driver = new QuickJSDriver();
|
|
2925
|
-
return await driver.execute({
|
|
2926
|
-
transformed,
|
|
2927
|
-
consumer,
|
|
2928
|
-
context,
|
|
2929
|
-
traces,
|
|
2930
|
-
signal,
|
|
2931
|
-
timeout,
|
|
2932
|
-
code,
|
|
2933
|
-
lines_executed,
|
|
2934
|
-
variables,
|
|
2935
|
-
currentToolCall: void 0
|
|
2936
|
-
});
|
|
2937
2994
|
} catch (quickjsError) {
|
|
2938
2995
|
const variant = getQuickJSVariant();
|
|
2939
2996
|
const debugInfo = {
|
|
@@ -2959,7 +3016,6 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2959
3016
|
console.warn("Error:", (quickjsError === null || quickjsError === void 0 ? void 0 : quickjsError.message) || quickjsError);
|
|
2960
3017
|
console.warn("Debug info:", JSON.stringify(debugInfo, null, 2));
|
|
2961
3018
|
}
|
|
2962
|
-
driver = new NodeDriver();
|
|
2963
3019
|
return await driver.execute({
|
|
2964
3020
|
transformed,
|
|
2965
3021
|
consumer,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_compiler = require("./compiler-
|
|
1
|
+
const require_compiler = require("./compiler-BJJUmNS9.cjs");
|
|
2
2
|
const require__baseIteratee = require("./_baseIteratee-CF4qP2a8.cjs");
|
|
3
3
|
const require__baseForOwn = require("./_baseForOwn-BfWDTL8L.cjs");
|
|
4
4
|
const require_stack_traces = require("./stack-traces-ntw_qhoy.cjs");
|
|
@@ -2480,6 +2480,22 @@ var QuickJSDriver = class {
|
|
|
2480
2480
|
const trackedProperties = /* @__PURE__ */ new Set();
|
|
2481
2481
|
const referenceProperties = /* @__PURE__ */ new Set();
|
|
2482
2482
|
const pendingPromises = [];
|
|
2483
|
+
const variableGetters = /* @__PURE__ */ new Map();
|
|
2484
|
+
const objectConstructor = vm.getProp(vm.global, "Object");
|
|
2485
|
+
const freezeFunction = vm.getProp(objectConstructor, "freeze");
|
|
2486
|
+
objectConstructor.dispose();
|
|
2487
|
+
const preserveFreeze = (value, handle) => {
|
|
2488
|
+
if (Object.isFrozen(value)) {
|
|
2489
|
+
const frozen = vm.callFunction(freezeFunction, vm.undefined, handle);
|
|
2490
|
+
try {
|
|
2491
|
+
frozen.unwrap().dispose();
|
|
2492
|
+
} catch (error) {
|
|
2493
|
+
handle.dispose();
|
|
2494
|
+
throw error;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
return handle;
|
|
2498
|
+
};
|
|
2483
2499
|
const toVmValue = (value) => {
|
|
2484
2500
|
if (typeof value === "string") return vm.newString(value);
|
|
2485
2501
|
else if (typeof value === "number") return vm.newNumber(value);
|
|
@@ -2487,21 +2503,13 @@ var QuickJSDriver = class {
|
|
|
2487
2503
|
else if (value === null) return vm.null;
|
|
2488
2504
|
else if (value === void 0) return vm.undefined;
|
|
2489
2505
|
else if (Array.isArray(value)) {
|
|
2490
|
-
const
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
else if (typeof item === "object") return JSON.stringify(item);
|
|
2496
|
-
return "undefined";
|
|
2506
|
+
const array = vm.newArray();
|
|
2507
|
+
value.forEach((item, index) => {
|
|
2508
|
+
const handle = toVmValue(item);
|
|
2509
|
+
vm.setProp(array, index, handle);
|
|
2510
|
+
disposeIfNeeded(handle);
|
|
2497
2511
|
});
|
|
2498
|
-
|
|
2499
|
-
if ("error" in result) {
|
|
2500
|
-
var _result$error;
|
|
2501
|
-
(_result$error = result.error) === null || _result$error === void 0 || _result$error.dispose();
|
|
2502
|
-
return vm.undefined;
|
|
2503
|
-
}
|
|
2504
|
-
return result.value;
|
|
2512
|
+
return preserveFreeze(value, array);
|
|
2505
2513
|
} else if (typeof value === "object") {
|
|
2506
2514
|
const obj = vm.newObject();
|
|
2507
2515
|
for (const [k, v] of Object.entries(value)) if (typeof v !== "function") {
|
|
@@ -2509,7 +2517,7 @@ var QuickJSDriver = class {
|
|
|
2509
2517
|
vm.setProp(obj, k, propHandle);
|
|
2510
2518
|
disposeIfNeeded(propHandle);
|
|
2511
2519
|
}
|
|
2512
|
-
return obj;
|
|
2520
|
+
return preserveFreeze(value, obj);
|
|
2513
2521
|
}
|
|
2514
2522
|
return vm.undefined;
|
|
2515
2523
|
};
|
|
@@ -2540,8 +2548,9 @@ var QuickJSDriver = class {
|
|
|
2540
2548
|
};
|
|
2541
2549
|
};
|
|
2542
2550
|
try {
|
|
2551
|
+
installValueReader(vm);
|
|
2543
2552
|
bridgeContextToVM(context, vm, trackedProperties, referenceProperties, toVmValue, disposeIfNeeded, bridgeFunction);
|
|
2544
|
-
setupVariableTrackingBridge(vm, variables);
|
|
2553
|
+
setupVariableTrackingBridge(vm, variables, variableGetters);
|
|
2545
2554
|
const scriptCode = buildScriptCode(transformed.code);
|
|
2546
2555
|
const copyBackContextFromVM = () => {
|
|
2547
2556
|
for (const key of trackedProperties) {
|
|
@@ -2598,7 +2607,7 @@ var QuickJSDriver = class {
|
|
|
2598
2607
|
let returnValue = void 0;
|
|
2599
2608
|
if (resultSet) {
|
|
2600
2609
|
const resultResult = vm.evalCode("globalThis.__llmz_result");
|
|
2601
|
-
returnValue = vm
|
|
2610
|
+
returnValue = readVmValue(vm, resultResult.unwrap());
|
|
2602
2611
|
resultResult.unwrap().dispose();
|
|
2603
2612
|
}
|
|
2604
2613
|
returnValue = require_errors.Signals.maybeDeserializeError(returnValue);
|
|
@@ -2630,6 +2639,8 @@ var QuickJSDriver = class {
|
|
|
2630
2639
|
})).catch(() => {});
|
|
2631
2640
|
return handleErrorQuickJS(err, code, consumer, traces, variables, lines_executed, userCodeStartLine, ctx.currentToolCall ?? state.currentToolCall);
|
|
2632
2641
|
} finally {
|
|
2642
|
+
for (const getter of variableGetters.values()) getter.dispose();
|
|
2643
|
+
freezeFunction.dispose();
|
|
2633
2644
|
try {
|
|
2634
2645
|
vm.dispose();
|
|
2635
2646
|
} catch {}
|
|
@@ -2779,7 +2790,7 @@ function bridgeContextToVM(context, vm, trackedProperties, referenceProperties,
|
|
|
2779
2790
|
}
|
|
2780
2791
|
}
|
|
2781
2792
|
function bridgeGetterSetter(vm, key, prop, descriptor, context, toVmValue) {
|
|
2782
|
-
var _result$
|
|
2793
|
+
var _result$error;
|
|
2783
2794
|
const target = prop ? `${key}` : "globalThis";
|
|
2784
2795
|
const propName = prop ?? key;
|
|
2785
2796
|
const prefix = prop ? `${key}_${prop}` : key;
|
|
@@ -2801,7 +2812,7 @@ function bridgeGetterSetter(vm, key, prop, descriptor, context, toVmValue) {
|
|
|
2801
2812
|
if (descriptor.set) {
|
|
2802
2813
|
const setterBridge = vm.newFunction(`set_${propName}`, (valueHandle) => {
|
|
2803
2814
|
try {
|
|
2804
|
-
const jsValue = vm
|
|
2815
|
+
const jsValue = readVmValue(vm, valueHandle, true);
|
|
2805
2816
|
if (prop) context[key][prop] = jsValue;
|
|
2806
2817
|
else context[key] = jsValue;
|
|
2807
2818
|
return vm.undefined;
|
|
@@ -2823,31 +2834,88 @@ function bridgeGetterSetter(vm, key, prop, descriptor, context, toVmValue) {
|
|
|
2823
2834
|
});
|
|
2824
2835
|
`;
|
|
2825
2836
|
const result = vm.evalCode(definePropertyCode);
|
|
2826
|
-
if ("error" in result) (_result$
|
|
2837
|
+
if ("error" in result) (_result$error = result.error) === null || _result$error === void 0 || _result$error.dispose();
|
|
2827
2838
|
else result.value.dispose();
|
|
2828
2839
|
}
|
|
2829
|
-
function
|
|
2830
|
-
|
|
2840
|
+
function installValueReader(vm) {
|
|
2841
|
+
vm.evalCode(`
|
|
2842
|
+
globalThis.__llmz_read_value = function encode(value, strict, seen = new Set()) {
|
|
2843
|
+
if (value === undefined) return ['undefined'];
|
|
2844
|
+
if (typeof value === 'number') {
|
|
2845
|
+
if (strict && !Number.isFinite(value)) throw new Error('Non-finite numbers cannot be assigned to host properties');
|
|
2846
|
+
return ['number', Object.is(value, -0) ? '-0' : String(value)];
|
|
2847
|
+
}
|
|
2848
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') return ['value', value];
|
|
2849
|
+
if (typeof value !== 'object') throw new Error('Unsupported VM value: ' + typeof value);
|
|
2850
|
+
if (seen.has(value)) throw new Error('Cyclic VM values cannot be transferred');
|
|
2851
|
+
if (value instanceof Date) return ['value', value.toJSON()];
|
|
2852
|
+
seen.add(value);
|
|
2853
|
+
try {
|
|
2854
|
+
if (Array.isArray(value)) return ['array', Array.from(value, item => encode(item, strict, seen))];
|
|
2855
|
+
return ['object', Object.entries(value).map(([key, item]) => [key, encode(item, strict, seen)])];
|
|
2856
|
+
} finally {
|
|
2857
|
+
seen.delete(value);
|
|
2858
|
+
}
|
|
2859
|
+
};
|
|
2860
|
+
`).unwrap().dispose();
|
|
2861
|
+
}
|
|
2862
|
+
function readVmValue(vm, handle, strict = false) {
|
|
2863
|
+
const decode = ([type, value]) => {
|
|
2864
|
+
if (type === "undefined") return void 0;
|
|
2865
|
+
if (type === "number") return Number(value);
|
|
2866
|
+
if (type === "array") return value.map(decode);
|
|
2867
|
+
if (type === "object") return Object.fromEntries(value.map(([key, item]) => [key, decode(item)]));
|
|
2868
|
+
return value;
|
|
2869
|
+
};
|
|
2870
|
+
const encoder = vm.getProp(vm.global, "__llmz_read_value");
|
|
2871
|
+
try {
|
|
2872
|
+
const result = vm.callFunction(encoder, vm.undefined, handle, strict ? vm.true : vm.false);
|
|
2873
|
+
if (result.error) {
|
|
2874
|
+
const error = vm.dump(result.error);
|
|
2875
|
+
result.error.dispose();
|
|
2876
|
+
if (strict) throw new Error(error.message);
|
|
2877
|
+
const copy = handle.dup();
|
|
2878
|
+
try {
|
|
2879
|
+
return vm.dump(copy);
|
|
2880
|
+
} finally {
|
|
2881
|
+
if (copy.alive) copy.dispose();
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
try {
|
|
2885
|
+
return decode(vm.dump(result.value));
|
|
2886
|
+
} finally {
|
|
2887
|
+
result.value.dispose();
|
|
2888
|
+
}
|
|
2889
|
+
} finally {
|
|
2890
|
+
encoder.dispose();
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
function setupVariableTrackingBridge(vm, variables, getters) {
|
|
2894
|
+
const tracker = vm.newFunction(require_compiler.Identifiers.VariableTrackingFnIdentifier, (nameHandle, getterHandle) => {
|
|
2895
|
+
var _getters$get;
|
|
2831
2896
|
const name = vm.getString(nameHandle);
|
|
2832
2897
|
if (NO_TRACKING.includes(name)) return;
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2898
|
+
(_getters$get = getters.get(name)) === null || _getters$get === void 0 || _getters$get.dispose();
|
|
2899
|
+
const getter = getterHandle.dup();
|
|
2900
|
+
getters.set(name, getter);
|
|
2901
|
+
variables[name] = () => {
|
|
2902
|
+
const result = vm.callFunction(getter, vm.undefined);
|
|
2903
|
+
if (result.error) {
|
|
2904
|
+
result.error.dispose();
|
|
2905
|
+
return "[[non-primitive]]";
|
|
2840
2906
|
}
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2907
|
+
try {
|
|
2908
|
+
if (vm.typeof(result.value) === "function") return "[[non-primitive]]";
|
|
2909
|
+
return readVmValue(vm, result.value);
|
|
2910
|
+
} catch {
|
|
2911
|
+
return "[[non-primitive]]";
|
|
2912
|
+
} finally {
|
|
2913
|
+
result.value.dispose();
|
|
2914
|
+
}
|
|
2915
|
+
};
|
|
2848
2916
|
});
|
|
2849
|
-
vm.setProp(vm.global, require_compiler.Identifiers.VariableTrackingFnIdentifier,
|
|
2850
|
-
|
|
2917
|
+
vm.setProp(vm.global, require_compiler.Identifiers.VariableTrackingFnIdentifier, tracker);
|
|
2918
|
+
tracker.dispose();
|
|
2851
2919
|
}
|
|
2852
2920
|
function buildScriptCode(transformedCode) {
|
|
2853
2921
|
return `
|
|
@@ -2918,21 +2986,10 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2918
2986
|
});
|
|
2919
2987
|
context ??= {};
|
|
2920
2988
|
for (const name of Array.from(transformed.variables)) delete context[name];
|
|
2921
|
-
let driver;
|
|
2989
|
+
let driver = new NodeDriver();
|
|
2922
2990
|
if (useQuickJS()) try {
|
|
2991
|
+
await loadQuickJSModule();
|
|
2923
2992
|
driver = new QuickJSDriver();
|
|
2924
|
-
return await driver.execute({
|
|
2925
|
-
transformed,
|
|
2926
|
-
consumer,
|
|
2927
|
-
context,
|
|
2928
|
-
traces,
|
|
2929
|
-
signal,
|
|
2930
|
-
timeout,
|
|
2931
|
-
code,
|
|
2932
|
-
lines_executed,
|
|
2933
|
-
variables,
|
|
2934
|
-
currentToolCall: void 0
|
|
2935
|
-
});
|
|
2936
2993
|
} catch (quickjsError) {
|
|
2937
2994
|
const variant = require_quickjs_variant.getQuickJSVariant();
|
|
2938
2995
|
const debugInfo = {
|
|
@@ -2958,7 +3015,6 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2958
3015
|
console.warn("Error:", (quickjsError === null || quickjsError === void 0 ? void 0 : quickjsError.message) || quickjsError);
|
|
2959
3016
|
console.warn("Debug info:", JSON.stringify(debugInfo, null, 2));
|
|
2960
3017
|
}
|
|
2961
|
-
driver = new NodeDriver();
|
|
2962
3018
|
return await driver.execute({
|
|
2963
3019
|
transformed,
|
|
2964
3020
|
consumer,
|
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.9.
|
|
5
|
+
"version": "0.9.2",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
8
8
|
"DOCS.md"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"tsx": "^4.19.2"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@botpress/client": "2.
|
|
71
|
+
"@botpress/client": "2.6.0",
|
|
72
72
|
"@botpress/cognitive": "1.2.2",
|
|
73
73
|
"@bpinternal/thicktoken": "^3.1.0",
|
|
74
74
|
"@bpinternal/zui": "^2.4.1"
|