llmz 0.0.5 → 0.0.6
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/README.md +4 -0
- package/dist/chat.d.ts +1 -1
- package/dist/{chunk-5NVNEEYW.cjs → chunk-BEPRLBPK.cjs} +60 -16
- package/dist/{chunk-MU4LFVY7.cjs → chunk-CH5T6SPC.cjs} +88 -2
- package/dist/{chunk-4EWY34YA.js → chunk-D3ESDRLH.js} +60 -16
- package/dist/{chunk-3U57H7GT.js → chunk-XJNRORSK.js} +87 -1
- package/dist/context.d.ts +7 -0
- package/dist/index.cjs +17 -5
- package/dist/index.d.ts +5 -4
- package/dist/index.js +16 -4
- package/dist/{llmz-VDA4M42R.cjs → llmz-CPMVYIOJ.cjs} +21 -44
- package/dist/{llmz-YE5N54IU.js → llmz-LAN4WDFW.js} +20 -43
- package/dist/llmz.d.ts +2 -1
- package/dist/result.d.ts +33 -0
- package/dist/types.d.ts +1 -35
- package/dist/{vm-GJ5R72AP.cjs → vm-2DLG7V4G.cjs} +2 -2
- package/dist/{vm-ZUQOSRRM.js → vm-FLBMZUA2.js} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/chat.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Component, RenderedComponent } from './component.js';
|
|
2
2
|
import { Context } from './context.js';
|
|
3
3
|
import { ValueOrGetter } from './getter.js';
|
|
4
|
+
import { ExecutionResult } from './result.js';
|
|
4
5
|
import { TranscriptArray, TranscriptMessage } from './transcript.js';
|
|
5
|
-
import { ExecutionResult } from './types.js';
|
|
6
6
|
export type MessageHandler = (input: RenderedComponent) => Promise<void> | void;
|
|
7
7
|
export declare class Chat {
|
|
8
8
|
readonly handler: MessageHandler;
|
|
@@ -2649,6 +2649,7 @@ function getCompiledCode(code, traces = []) {
|
|
|
2649
2649
|
}
|
|
2650
2650
|
}
|
|
2651
2651
|
async function runAsyncFunction(context, code, traces = [], signal = null, timeout = MAX_VM_EXECUTION_TIME) {
|
|
2652
|
+
var _a3;
|
|
2652
2653
|
const transformed = getCompiledCode(code, traces);
|
|
2653
2654
|
const lines_executed = /* @__PURE__ */ new Map();
|
|
2654
2655
|
const variables = {};
|
|
@@ -2692,12 +2693,12 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2692
2693
|
};
|
|
2693
2694
|
let currentToolCall;
|
|
2694
2695
|
context[Identifiers.ToolCallTrackerFnIdentifier] = (callId, type, outputOrError) => {
|
|
2695
|
-
var
|
|
2696
|
+
var _a4;
|
|
2696
2697
|
const temp = _chunkJDABP4SDcjs.Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
|
|
2697
2698
|
if (type === "end" && temp instanceof _chunkJDABP4SDcjs.SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
|
|
2698
2699
|
currentToolCall = {
|
|
2699
2700
|
...temp.toolCall,
|
|
2700
|
-
assignment: (
|
|
2701
|
+
assignment: (_a4 = transformed.toolCalls.get(callId)) == null ? void 0 : _a4.assignment
|
|
2701
2702
|
};
|
|
2702
2703
|
}
|
|
2703
2704
|
};
|
|
@@ -2726,15 +2727,19 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2726
2727
|
const AsyncFunction = async function* () {
|
|
2727
2728
|
}.constructor;
|
|
2728
2729
|
return await (async () => {
|
|
2729
|
-
const
|
|
2730
|
-
|
|
2730
|
+
const descriptors = Object.getOwnPropertyDescriptors(context);
|
|
2731
|
+
const topLevelProperties = Object.keys(descriptors).filter(
|
|
2732
|
+
(x) => !NO_TRACKING.includes(x) && descriptors[x] && typeof descriptors[x].value !== "function" && typeof descriptors[x].value !== "object"
|
|
2731
2733
|
);
|
|
2732
2734
|
const __report = (name, value) => {
|
|
2733
|
-
context[name]
|
|
2735
|
+
if (context[name] !== void 0 && context[name] !== value) {
|
|
2736
|
+
context[name] = value;
|
|
2737
|
+
}
|
|
2734
2738
|
};
|
|
2735
2739
|
context.__report = __report;
|
|
2736
2740
|
const reportAll = topLevelProperties.map((x) => `__report("${x}", ${x})`).join(";");
|
|
2737
|
-
const
|
|
2741
|
+
const assigner = `let __${Identifiers.LineTrackingFnIdentifier} = ${Identifiers.LineTrackingFnIdentifier}; ${Identifiers.LineTrackingFnIdentifier} = function(line) { ${reportAll}; __${Identifiers.LineTrackingFnIdentifier}(line);}`;
|
|
2742
|
+
const wrapper = `"use strict"; try { ${assigner};${transformed.code} } finally { ${reportAll} };`;
|
|
2738
2743
|
const fn = AsyncFunction(...Object.keys(context), wrapper);
|
|
2739
2744
|
const res = fn(...Object.values(context));
|
|
2740
2745
|
do {
|
|
@@ -2760,6 +2765,7 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2760
2765
|
const isolatedContext = await isolate.createContext();
|
|
2761
2766
|
const jail = isolatedContext.global;
|
|
2762
2767
|
const trackedProperties = /* @__PURE__ */ new Set();
|
|
2768
|
+
const referenceProperties = /* @__PURE__ */ new Set();
|
|
2763
2769
|
const abort = () => {
|
|
2764
2770
|
if (USE_ISOLATED_VM) {
|
|
2765
2771
|
isolate.dispose();
|
|
@@ -2779,7 +2785,7 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2779
2785
|
arguments: { reference: true }
|
|
2780
2786
|
}
|
|
2781
2787
|
);
|
|
2782
|
-
} else if (typeof context[key] === "object") {
|
|
2788
|
+
} else if (typeof context[key] === "object" && !((_a3 = Object.getOwnPropertyDescriptor(context, key)) == null ? void 0 : _a3.get)) {
|
|
2783
2789
|
try {
|
|
2784
2790
|
trackedProperties.add(key);
|
|
2785
2791
|
const initial = Array.isArray(context[key]) ? new Array(context[key].length) : {};
|
|
@@ -2796,9 +2802,28 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2796
2802
|
}
|
|
2797
2803
|
);
|
|
2798
2804
|
} else {
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2805
|
+
const descriptor = Object.getOwnPropertyDescriptor(context[key], prop);
|
|
2806
|
+
if (descriptor && (descriptor.get || descriptor.set)) {
|
|
2807
|
+
referenceProperties.add(`${key}.${prop}`);
|
|
2808
|
+
await isolatedContext.evalClosure(
|
|
2809
|
+
`Object.defineProperty(global['${key}'], '${prop}', {
|
|
2810
|
+
get: () => $0.applySync(null, [], {arguments: {copy: true}}),
|
|
2811
|
+
set: (value) => $1.applySync(null, [value], {arguments: {copy: true}})
|
|
2812
|
+
});`,
|
|
2813
|
+
[
|
|
2814
|
+
() => context[key][prop],
|
|
2815
|
+
(value) => {
|
|
2816
|
+
context[key][prop] = value;
|
|
2817
|
+
return value;
|
|
2818
|
+
}
|
|
2819
|
+
],
|
|
2820
|
+
{ arguments: { reference: true } }
|
|
2821
|
+
);
|
|
2822
|
+
} else {
|
|
2823
|
+
await isolatedContext.evalClosure(`global['${key}']['${prop}'] = $0;`, [context[key][prop]], {
|
|
2824
|
+
arguments: { copy: true }
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2802
2827
|
}
|
|
2803
2828
|
} catch (err) {
|
|
2804
2829
|
console.error(`Could not copy "${key}.${prop}" (typeof = ${typeof context[key][prop]}) to the sandbox`, err);
|
|
@@ -2809,7 +2834,26 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2809
2834
|
}
|
|
2810
2835
|
} else {
|
|
2811
2836
|
try {
|
|
2812
|
-
|
|
2837
|
+
const descriptor = Object.getOwnPropertyDescriptor(context, key);
|
|
2838
|
+
if (descriptor && (descriptor.get || descriptor.set)) {
|
|
2839
|
+
referenceProperties.add(key);
|
|
2840
|
+
await isolatedContext.evalClosure(
|
|
2841
|
+
`Object.defineProperty(global, '${key}', {
|
|
2842
|
+
get: () => $0.applySync(null, [], {arguments: {copy: true}}),
|
|
2843
|
+
set: (value) => $1.applySync(null, [value], {arguments: {copy: true}})
|
|
2844
|
+
});`,
|
|
2845
|
+
[
|
|
2846
|
+
() => context[key],
|
|
2847
|
+
(value) => {
|
|
2848
|
+
context[key] = value;
|
|
2849
|
+
return value;
|
|
2850
|
+
}
|
|
2851
|
+
],
|
|
2852
|
+
{ arguments: { reference: true } }
|
|
2853
|
+
);
|
|
2854
|
+
} else {
|
|
2855
|
+
await jail.set(key, context[key], { copy: true });
|
|
2856
|
+
}
|
|
2813
2857
|
trackedProperties.add(key);
|
|
2814
2858
|
} catch (err) {
|
|
2815
2859
|
console.error(`Could not copy "${key}" to the sandbox (typeof = ${typeof context[key]})`, err);
|
|
@@ -2875,7 +2919,7 @@ do {
|
|
|
2875
2919
|
}
|
|
2876
2920
|
copied = true;
|
|
2877
2921
|
for (const key of trackedProperties) {
|
|
2878
|
-
if (typeof context[key] === "object") {
|
|
2922
|
+
if (typeof context[key] === "object" && !referenceProperties.has(key)) {
|
|
2879
2923
|
try {
|
|
2880
2924
|
let properties = [];
|
|
2881
2925
|
try {
|
|
@@ -2890,7 +2934,7 @@ do {
|
|
|
2890
2934
|
delete context[key][prop];
|
|
2891
2935
|
}
|
|
2892
2936
|
for (const prop of properties) {
|
|
2893
|
-
if (typeof context[key][prop] === "function") {
|
|
2937
|
+
if (typeof context[key][prop] === "function" || referenceProperties.has(`${key}.${prop}`)) {
|
|
2894
2938
|
continue;
|
|
2895
2939
|
}
|
|
2896
2940
|
try {
|
|
@@ -2921,6 +2965,9 @@ do {
|
|
|
2921
2965
|
}
|
|
2922
2966
|
} else {
|
|
2923
2967
|
try {
|
|
2968
|
+
if (referenceProperties.has(key)) {
|
|
2969
|
+
continue;
|
|
2970
|
+
}
|
|
2924
2971
|
const value = jail.getSync(key, { copy: true });
|
|
2925
2972
|
try {
|
|
2926
2973
|
Object.assign(context, { [key]: value });
|
|
@@ -2944,9 +2991,6 @@ do {
|
|
|
2944
2991
|
}
|
|
2945
2992
|
};
|
|
2946
2993
|
const final = await script.run(isolatedContext, {
|
|
2947
|
-
// TODO: fix getRemainingTimeInMillis ...
|
|
2948
|
-
// TODO: probably expose a "timeout" option instead
|
|
2949
|
-
// timeout: clamp(Runtime.getRemainingTimeInMillis() - 10_000, 5_000, MAX_VM_EXECUTION_TIME),
|
|
2950
2994
|
timeout,
|
|
2951
2995
|
copy: true,
|
|
2952
2996
|
promise: true
|
|
@@ -107,6 +107,72 @@ var Snapshot = class _Snapshot {
|
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
+
// src/result.ts
|
|
111
|
+
var ExecutionResult = class {
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
constructor(status, context) {
|
|
115
|
+
this.status = status;
|
|
116
|
+
this.context = context;
|
|
117
|
+
}
|
|
118
|
+
isSuccess() {
|
|
119
|
+
return this.status === "success" && this instanceof SuccessExecutionResult;
|
|
120
|
+
}
|
|
121
|
+
isError() {
|
|
122
|
+
return this.status === "error" && this instanceof ErrorExecutionResult;
|
|
123
|
+
}
|
|
124
|
+
isInterrupted() {
|
|
125
|
+
return this.status === "interrupted" && this instanceof PartialExecutionResult;
|
|
126
|
+
}
|
|
127
|
+
is(exit) {
|
|
128
|
+
return this.status === "success" && this instanceof SuccessExecutionResult && this.result.exit === exit;
|
|
129
|
+
}
|
|
130
|
+
get output() {
|
|
131
|
+
return this.isSuccess() ? this.result.result : null;
|
|
132
|
+
}
|
|
133
|
+
get iteration() {
|
|
134
|
+
return this.context.iterations.at(-1) || null;
|
|
135
|
+
}
|
|
136
|
+
get iterations() {
|
|
137
|
+
return _nullishCoalesce(this.context.iterations, () => ( []));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var SuccessExecutionResult = class extends ExecutionResult {
|
|
141
|
+
|
|
142
|
+
constructor(context, result) {
|
|
143
|
+
super("success", context);
|
|
144
|
+
this.result = result;
|
|
145
|
+
}
|
|
146
|
+
get output() {
|
|
147
|
+
return this.result.result;
|
|
148
|
+
}
|
|
149
|
+
get iteration() {
|
|
150
|
+
return this.context.iterations.at(-1);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var ErrorExecutionResult = class extends ExecutionResult {
|
|
154
|
+
|
|
155
|
+
constructor(context, error) {
|
|
156
|
+
super("error", context);
|
|
157
|
+
this.error = error;
|
|
158
|
+
}
|
|
159
|
+
get output() {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var PartialExecutionResult = class extends ExecutionResult {
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
constructor(context, signal, snapshot) {
|
|
167
|
+
super("interrupted", context);
|
|
168
|
+
this.signal = signal;
|
|
169
|
+
this.snapshot = snapshot;
|
|
170
|
+
}
|
|
171
|
+
get output() {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
110
176
|
// src/getter.ts
|
|
111
177
|
var getValue = async (valueOrGetter, ctx) => {
|
|
112
178
|
if (typeof valueOrGetter === "function") {
|
|
@@ -121,6 +187,7 @@ var getValue = async (valueOrGetter, ctx) => {
|
|
|
121
187
|
};
|
|
122
188
|
|
|
123
189
|
// src/context.ts
|
|
190
|
+
var _zui = require('@bpinternal/zui');
|
|
124
191
|
|
|
125
192
|
|
|
126
193
|
// src/handlers.ts
|
|
@@ -206,6 +273,20 @@ var ListenExit = new (0, _chunk4I7UPBLNcjs.Exit)({
|
|
|
206
273
|
name: "listen",
|
|
207
274
|
description: "Listen to the user and provide a response"
|
|
208
275
|
});
|
|
276
|
+
var DefaultExit = new (0, _chunk4I7UPBLNcjs.Exit)({
|
|
277
|
+
name: "done",
|
|
278
|
+
description: "When the execution is sucessfully completed or when error recovery is not possible",
|
|
279
|
+
schema: _zui.z.discriminatedUnion("success", [
|
|
280
|
+
_zui.z.object({
|
|
281
|
+
success: _zui.z.literal(true),
|
|
282
|
+
result: _zui.z.any().describe("The result of the execution")
|
|
283
|
+
}),
|
|
284
|
+
_zui.z.object({
|
|
285
|
+
success: _zui.z.literal(false),
|
|
286
|
+
error: _zui.z.string().describe("The error message if the execution failed")
|
|
287
|
+
})
|
|
288
|
+
])
|
|
289
|
+
});
|
|
209
290
|
var Iteration = class {
|
|
210
291
|
|
|
211
292
|
|
|
@@ -565,7 +646,7 @@ var Context = (_class2 = class {
|
|
|
565
646
|
throw new Error("Too many transcript messages. Expected at most 250 messages.");
|
|
566
647
|
}
|
|
567
648
|
if (!components.length && !exits.length) {
|
|
568
|
-
|
|
649
|
+
exits.push(DefaultExit);
|
|
569
650
|
}
|
|
570
651
|
return {
|
|
571
652
|
transcript,
|
|
@@ -605,4 +686,9 @@ var Context = (_class2 = class {
|
|
|
605
686
|
|
|
606
687
|
|
|
607
688
|
|
|
608
|
-
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
exports.Snapshot = Snapshot; exports.ExecutionResult = ExecutionResult; exports.SuccessExecutionResult = SuccessExecutionResult; exports.ErrorExecutionResult = ErrorExecutionResult; exports.PartialExecutionResult = PartialExecutionResult; exports.getValue = getValue; exports.ThinkExit = ThinkExit; exports.ListenExit = ListenExit; exports.DefaultExit = DefaultExit; exports.Context = Context;
|
|
@@ -2649,6 +2649,7 @@ function getCompiledCode(code, traces = []) {
|
|
|
2649
2649
|
}
|
|
2650
2650
|
}
|
|
2651
2651
|
async function runAsyncFunction(context, code, traces = [], signal = null, timeout = MAX_VM_EXECUTION_TIME) {
|
|
2652
|
+
var _a3;
|
|
2652
2653
|
const transformed = getCompiledCode(code, traces);
|
|
2653
2654
|
const lines_executed = /* @__PURE__ */ new Map();
|
|
2654
2655
|
const variables = {};
|
|
@@ -2692,12 +2693,12 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2692
2693
|
};
|
|
2693
2694
|
let currentToolCall;
|
|
2694
2695
|
context[Identifiers.ToolCallTrackerFnIdentifier] = (callId, type, outputOrError) => {
|
|
2695
|
-
var
|
|
2696
|
+
var _a4;
|
|
2696
2697
|
const temp = Signals.maybeDeserializeError(outputOrError == null ? void 0 : outputOrError.message);
|
|
2697
2698
|
if (type === "end" && temp instanceof SnapshotSignal && (temp == null ? void 0 : temp.toolCall)) {
|
|
2698
2699
|
currentToolCall = {
|
|
2699
2700
|
...temp.toolCall,
|
|
2700
|
-
assignment: (
|
|
2701
|
+
assignment: (_a4 = transformed.toolCalls.get(callId)) == null ? void 0 : _a4.assignment
|
|
2701
2702
|
};
|
|
2702
2703
|
}
|
|
2703
2704
|
};
|
|
@@ -2726,15 +2727,19 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2726
2727
|
const AsyncFunction = async function* () {
|
|
2727
2728
|
}.constructor;
|
|
2728
2729
|
return await (async () => {
|
|
2729
|
-
const
|
|
2730
|
-
|
|
2730
|
+
const descriptors = Object.getOwnPropertyDescriptors(context);
|
|
2731
|
+
const topLevelProperties = Object.keys(descriptors).filter(
|
|
2732
|
+
(x) => !NO_TRACKING.includes(x) && descriptors[x] && typeof descriptors[x].value !== "function" && typeof descriptors[x].value !== "object"
|
|
2731
2733
|
);
|
|
2732
2734
|
const __report = (name, value) => {
|
|
2733
|
-
context[name]
|
|
2735
|
+
if (context[name] !== void 0 && context[name] !== value) {
|
|
2736
|
+
context[name] = value;
|
|
2737
|
+
}
|
|
2734
2738
|
};
|
|
2735
2739
|
context.__report = __report;
|
|
2736
2740
|
const reportAll = topLevelProperties.map((x) => `__report("${x}", ${x})`).join(";");
|
|
2737
|
-
const
|
|
2741
|
+
const assigner = `let __${Identifiers.LineTrackingFnIdentifier} = ${Identifiers.LineTrackingFnIdentifier}; ${Identifiers.LineTrackingFnIdentifier} = function(line) { ${reportAll}; __${Identifiers.LineTrackingFnIdentifier}(line);}`;
|
|
2742
|
+
const wrapper = `"use strict"; try { ${assigner};${transformed.code} } finally { ${reportAll} };`;
|
|
2738
2743
|
const fn = AsyncFunction(...Object.keys(context), wrapper);
|
|
2739
2744
|
const res = fn(...Object.values(context));
|
|
2740
2745
|
do {
|
|
@@ -2760,6 +2765,7 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2760
2765
|
const isolatedContext = await isolate.createContext();
|
|
2761
2766
|
const jail = isolatedContext.global;
|
|
2762
2767
|
const trackedProperties = /* @__PURE__ */ new Set();
|
|
2768
|
+
const referenceProperties = /* @__PURE__ */ new Set();
|
|
2763
2769
|
const abort = () => {
|
|
2764
2770
|
if (USE_ISOLATED_VM) {
|
|
2765
2771
|
isolate.dispose();
|
|
@@ -2779,7 +2785,7 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2779
2785
|
arguments: { reference: true }
|
|
2780
2786
|
}
|
|
2781
2787
|
);
|
|
2782
|
-
} else if (typeof context[key] === "object") {
|
|
2788
|
+
} else if (typeof context[key] === "object" && !((_a3 = Object.getOwnPropertyDescriptor(context, key)) == null ? void 0 : _a3.get)) {
|
|
2783
2789
|
try {
|
|
2784
2790
|
trackedProperties.add(key);
|
|
2785
2791
|
const initial = Array.isArray(context[key]) ? new Array(context[key].length) : {};
|
|
@@ -2796,9 +2802,28 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2796
2802
|
}
|
|
2797
2803
|
);
|
|
2798
2804
|
} else {
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2805
|
+
const descriptor = Object.getOwnPropertyDescriptor(context[key], prop);
|
|
2806
|
+
if (descriptor && (descriptor.get || descriptor.set)) {
|
|
2807
|
+
referenceProperties.add(`${key}.${prop}`);
|
|
2808
|
+
await isolatedContext.evalClosure(
|
|
2809
|
+
`Object.defineProperty(global['${key}'], '${prop}', {
|
|
2810
|
+
get: () => $0.applySync(null, [], {arguments: {copy: true}}),
|
|
2811
|
+
set: (value) => $1.applySync(null, [value], {arguments: {copy: true}})
|
|
2812
|
+
});`,
|
|
2813
|
+
[
|
|
2814
|
+
() => context[key][prop],
|
|
2815
|
+
(value) => {
|
|
2816
|
+
context[key][prop] = value;
|
|
2817
|
+
return value;
|
|
2818
|
+
}
|
|
2819
|
+
],
|
|
2820
|
+
{ arguments: { reference: true } }
|
|
2821
|
+
);
|
|
2822
|
+
} else {
|
|
2823
|
+
await isolatedContext.evalClosure(`global['${key}']['${prop}'] = $0;`, [context[key][prop]], {
|
|
2824
|
+
arguments: { copy: true }
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2802
2827
|
}
|
|
2803
2828
|
} catch (err) {
|
|
2804
2829
|
console.error(`Could not copy "${key}.${prop}" (typeof = ${typeof context[key][prop]}) to the sandbox`, err);
|
|
@@ -2809,7 +2834,26 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
|
|
|
2809
2834
|
}
|
|
2810
2835
|
} else {
|
|
2811
2836
|
try {
|
|
2812
|
-
|
|
2837
|
+
const descriptor = Object.getOwnPropertyDescriptor(context, key);
|
|
2838
|
+
if (descriptor && (descriptor.get || descriptor.set)) {
|
|
2839
|
+
referenceProperties.add(key);
|
|
2840
|
+
await isolatedContext.evalClosure(
|
|
2841
|
+
`Object.defineProperty(global, '${key}', {
|
|
2842
|
+
get: () => $0.applySync(null, [], {arguments: {copy: true}}),
|
|
2843
|
+
set: (value) => $1.applySync(null, [value], {arguments: {copy: true}})
|
|
2844
|
+
});`,
|
|
2845
|
+
[
|
|
2846
|
+
() => context[key],
|
|
2847
|
+
(value) => {
|
|
2848
|
+
context[key] = value;
|
|
2849
|
+
return value;
|
|
2850
|
+
}
|
|
2851
|
+
],
|
|
2852
|
+
{ arguments: { reference: true } }
|
|
2853
|
+
);
|
|
2854
|
+
} else {
|
|
2855
|
+
await jail.set(key, context[key], { copy: true });
|
|
2856
|
+
}
|
|
2813
2857
|
trackedProperties.add(key);
|
|
2814
2858
|
} catch (err) {
|
|
2815
2859
|
console.error(`Could not copy "${key}" to the sandbox (typeof = ${typeof context[key]})`, err);
|
|
@@ -2875,7 +2919,7 @@ do {
|
|
|
2875
2919
|
}
|
|
2876
2920
|
copied = true;
|
|
2877
2921
|
for (const key of trackedProperties) {
|
|
2878
|
-
if (typeof context[key] === "object") {
|
|
2922
|
+
if (typeof context[key] === "object" && !referenceProperties.has(key)) {
|
|
2879
2923
|
try {
|
|
2880
2924
|
let properties = [];
|
|
2881
2925
|
try {
|
|
@@ -2890,7 +2934,7 @@ do {
|
|
|
2890
2934
|
delete context[key][prop];
|
|
2891
2935
|
}
|
|
2892
2936
|
for (const prop of properties) {
|
|
2893
|
-
if (typeof context[key][prop] === "function") {
|
|
2937
|
+
if (typeof context[key][prop] === "function" || referenceProperties.has(`${key}.${prop}`)) {
|
|
2894
2938
|
continue;
|
|
2895
2939
|
}
|
|
2896
2940
|
try {
|
|
@@ -2921,6 +2965,9 @@ do {
|
|
|
2921
2965
|
}
|
|
2922
2966
|
} else {
|
|
2923
2967
|
try {
|
|
2968
|
+
if (referenceProperties.has(key)) {
|
|
2969
|
+
continue;
|
|
2970
|
+
}
|
|
2924
2971
|
const value = jail.getSync(key, { copy: true });
|
|
2925
2972
|
try {
|
|
2926
2973
|
Object.assign(context, { [key]: value });
|
|
@@ -2944,9 +2991,6 @@ do {
|
|
|
2944
2991
|
}
|
|
2945
2992
|
};
|
|
2946
2993
|
const final = await script.run(isolatedContext, {
|
|
2947
|
-
// TODO: fix getRemainingTimeInMillis ...
|
|
2948
|
-
// TODO: probably expose a "timeout" option instead
|
|
2949
|
-
// timeout: clamp(Runtime.getRemainingTimeInMillis() - 10_000, 5_000, MAX_VM_EXECUTION_TIME),
|
|
2950
2994
|
timeout,
|
|
2951
2995
|
copy: true,
|
|
2952
2996
|
promise: true
|
|
@@ -107,6 +107,72 @@ var Snapshot = class _Snapshot {
|
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
+
// src/result.ts
|
|
111
|
+
var ExecutionResult = class {
|
|
112
|
+
status;
|
|
113
|
+
context;
|
|
114
|
+
constructor(status, context) {
|
|
115
|
+
this.status = status;
|
|
116
|
+
this.context = context;
|
|
117
|
+
}
|
|
118
|
+
isSuccess() {
|
|
119
|
+
return this.status === "success" && this instanceof SuccessExecutionResult;
|
|
120
|
+
}
|
|
121
|
+
isError() {
|
|
122
|
+
return this.status === "error" && this instanceof ErrorExecutionResult;
|
|
123
|
+
}
|
|
124
|
+
isInterrupted() {
|
|
125
|
+
return this.status === "interrupted" && this instanceof PartialExecutionResult;
|
|
126
|
+
}
|
|
127
|
+
is(exit) {
|
|
128
|
+
return this.status === "success" && this instanceof SuccessExecutionResult && this.result.exit === exit;
|
|
129
|
+
}
|
|
130
|
+
get output() {
|
|
131
|
+
return this.isSuccess() ? this.result.result : null;
|
|
132
|
+
}
|
|
133
|
+
get iteration() {
|
|
134
|
+
return this.context.iterations.at(-1) || null;
|
|
135
|
+
}
|
|
136
|
+
get iterations() {
|
|
137
|
+
return this.context.iterations ?? [];
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var SuccessExecutionResult = class extends ExecutionResult {
|
|
141
|
+
result;
|
|
142
|
+
constructor(context, result) {
|
|
143
|
+
super("success", context);
|
|
144
|
+
this.result = result;
|
|
145
|
+
}
|
|
146
|
+
get output() {
|
|
147
|
+
return this.result.result;
|
|
148
|
+
}
|
|
149
|
+
get iteration() {
|
|
150
|
+
return this.context.iterations.at(-1);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var ErrorExecutionResult = class extends ExecutionResult {
|
|
154
|
+
error;
|
|
155
|
+
constructor(context, error) {
|
|
156
|
+
super("error", context);
|
|
157
|
+
this.error = error;
|
|
158
|
+
}
|
|
159
|
+
get output() {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var PartialExecutionResult = class extends ExecutionResult {
|
|
164
|
+
signal;
|
|
165
|
+
snapshot;
|
|
166
|
+
constructor(context, signal, snapshot) {
|
|
167
|
+
super("interrupted", context);
|
|
168
|
+
this.signal = signal;
|
|
169
|
+
this.snapshot = snapshot;
|
|
170
|
+
}
|
|
171
|
+
get output() {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
110
176
|
// src/getter.ts
|
|
111
177
|
var getValue = async (valueOrGetter, ctx) => {
|
|
112
178
|
if (typeof valueOrGetter === "function") {
|
|
@@ -121,6 +187,7 @@ var getValue = async (valueOrGetter, ctx) => {
|
|
|
121
187
|
};
|
|
122
188
|
|
|
123
189
|
// src/context.ts
|
|
190
|
+
import { z } from "@bpinternal/zui";
|
|
124
191
|
import { ulid as ulid2 } from "ulid";
|
|
125
192
|
|
|
126
193
|
// src/handlers.ts
|
|
@@ -206,6 +273,20 @@ var ListenExit = new Exit({
|
|
|
206
273
|
name: "listen",
|
|
207
274
|
description: "Listen to the user and provide a response"
|
|
208
275
|
});
|
|
276
|
+
var DefaultExit = new Exit({
|
|
277
|
+
name: "done",
|
|
278
|
+
description: "When the execution is sucessfully completed or when error recovery is not possible",
|
|
279
|
+
schema: z.discriminatedUnion("success", [
|
|
280
|
+
z.object({
|
|
281
|
+
success: z.literal(true),
|
|
282
|
+
result: z.any().describe("The result of the execution")
|
|
283
|
+
}),
|
|
284
|
+
z.object({
|
|
285
|
+
success: z.literal(false),
|
|
286
|
+
error: z.string().describe("The error message if the execution failed")
|
|
287
|
+
})
|
|
288
|
+
])
|
|
289
|
+
});
|
|
209
290
|
var Iteration = class {
|
|
210
291
|
id;
|
|
211
292
|
messages;
|
|
@@ -565,7 +646,7 @@ var Context = class {
|
|
|
565
646
|
throw new Error("Too many transcript messages. Expected at most 250 messages.");
|
|
566
647
|
}
|
|
567
648
|
if (!components.length && !exits.length) {
|
|
568
|
-
|
|
649
|
+
exits.push(DefaultExit);
|
|
569
650
|
}
|
|
570
651
|
return {
|
|
571
652
|
transcript,
|
|
@@ -601,8 +682,13 @@ var Context = class {
|
|
|
601
682
|
|
|
602
683
|
export {
|
|
603
684
|
Snapshot,
|
|
685
|
+
ExecutionResult,
|
|
686
|
+
SuccessExecutionResult,
|
|
687
|
+
ErrorExecutionResult,
|
|
688
|
+
PartialExecutionResult,
|
|
604
689
|
getValue,
|
|
605
690
|
ThinkExit,
|
|
606
691
|
ListenExit,
|
|
692
|
+
DefaultExit,
|
|
607
693
|
Context
|
|
608
694
|
};
|
package/dist/context.d.ts
CHANGED
|
@@ -82,6 +82,13 @@ export declare namespace IterationStatuses {
|
|
|
82
82
|
}
|
|
83
83
|
export declare const ThinkExit: Exit<unknown>;
|
|
84
84
|
export declare const ListenExit: Exit<unknown>;
|
|
85
|
+
export declare const DefaultExit: Exit<{
|
|
86
|
+
success: true;
|
|
87
|
+
result?: any;
|
|
88
|
+
} | {
|
|
89
|
+
error: string;
|
|
90
|
+
success: false;
|
|
91
|
+
}>;
|
|
85
92
|
export declare class Iteration {
|
|
86
93
|
id: string;
|
|
87
94
|
messages: OAI.Message[];
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkCH5T6SPCcjs = require('./chunk-CH5T6SPC.cjs');
|
|
7
12
|
require('./chunk-6WT5VZBG.cjs');
|
|
8
13
|
|
|
9
14
|
|
|
@@ -16,6 +21,7 @@ var _chunkHYVKY3W6cjs = require('./chunk-HYVKY3W6.cjs');
|
|
|
16
21
|
|
|
17
22
|
|
|
18
23
|
|
|
24
|
+
|
|
19
25
|
var _chunkJDABP4SDcjs = require('./chunk-JDABP4SD.cjs');
|
|
20
26
|
require('./chunk-IKSIOIIP.cjs');
|
|
21
27
|
|
|
@@ -870,16 +876,16 @@ var Chat = class {
|
|
|
870
876
|
|
|
871
877
|
// src/index.ts
|
|
872
878
|
var execute = async (props) => {
|
|
873
|
-
const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-
|
|
879
|
+
const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-CPMVYIOJ.cjs")));
|
|
874
880
|
return executeContext(props);
|
|
875
881
|
};
|
|
876
882
|
var init = async () => {
|
|
877
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-
|
|
883
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./llmz-CPMVYIOJ.cjs")));
|
|
878
884
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./component-TSNW3SC7.cjs")));
|
|
879
885
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-SWJYOR2Z.cjs")));
|
|
880
886
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-KJ4COC5N.cjs")));
|
|
881
887
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./jsx-AJAXBWFE.cjs")));
|
|
882
|
-
await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-
|
|
888
|
+
await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-2DLG7V4G.cjs")));
|
|
883
889
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-QC4I2L6R.cjs")));
|
|
884
890
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-NYN7BGKJ.cjs")));
|
|
885
891
|
await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-XR6CYHW4.cjs")));
|
|
@@ -904,4 +910,10 @@ var init = async () => {
|
|
|
904
910
|
|
|
905
911
|
|
|
906
912
|
|
|
907
|
-
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkEJRCDWBAcjs.Component; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunkCH5T6SPCcjs.DefaultExit; exports.ErrorExecutionResult = _chunkCH5T6SPCcjs.ErrorExecutionResult; exports.ExecutionResult = _chunkCH5T6SPCcjs.ExecutionResult; exports.Exit = _chunk4I7UPBLNcjs.Exit; exports.ListenExit = _chunkCH5T6SPCcjs.ListenExit; exports.LoopExceededError = _chunkJDABP4SDcjs.LoopExceededError; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunkCH5T6SPCcjs.PartialExecutionResult; exports.Snapshot = _chunkCH5T6SPCcjs.Snapshot; exports.SnapshotSignal = _chunkJDABP4SDcjs.SnapshotSignal; exports.SuccessExecutionResult = _chunkCH5T6SPCcjs.SuccessExecutionResult; exports.ThinkExit = _chunkCH5T6SPCcjs.ThinkExit; exports.ThinkSignal = _chunkJDABP4SDcjs.ThinkSignal; exports.Tool = _chunk4QTK5ALHcjs.Tool; exports.assertValidComponent = _chunkEJRCDWBAcjs.assertValidComponent; exports.execute = execute; exports.getValue = _chunkCH5T6SPCcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkEJRCDWBAcjs.isAnyComponent; exports.isComponent = _chunkEJRCDWBAcjs.isComponent;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
export { Tool } from './tool.js';
|
|
2
2
|
export { Exit, ExitResult } from './exit.js';
|
|
3
3
|
export { ObjectInstance } from './objects.js';
|
|
4
|
-
export { SnapshotSignal, ThinkSignal } from './errors.js';
|
|
4
|
+
export { SnapshotSignal, ThinkSignal, LoopExceededError } from './errors.js';
|
|
5
5
|
export { Component, RenderedComponent, LeafComponentDefinition, ContainerComponentDefinition, DefaultComponentDefinition, ComponentDefinition, assertValidComponent, isComponent, isAnyComponent, } from './component.js';
|
|
6
6
|
export { Citation, CitationsManager } from './citations.js';
|
|
7
7
|
export { DefaultComponents } from './component.default.js';
|
|
8
8
|
export { Snapshot } from './snapshots.js';
|
|
9
9
|
export { Chat, type MessageHandler } from './chat.js';
|
|
10
10
|
import { type ExecutionProps } from './llmz.js';
|
|
11
|
-
import {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
11
|
+
import { ExecutionResult } from './result.js';
|
|
12
|
+
export { ErrorExecutionResult, ExecutionResult, PartialExecutionResult, SuccessExecutionResult } from './result.js';
|
|
13
|
+
export { Trace } from './types.js';
|
|
14
|
+
export { type Iteration, ListenExit, ThinkExit, DefaultExit, IterationStatuses, IterationStatus } from './context.js';
|
|
14
15
|
export { type ValueOrGetter, getValue } from './getter.js';
|
|
15
16
|
export declare const execute: (props: ExecutionProps) => Promise<ExecutionResult>;
|
|
16
17
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DefaultExit,
|
|
3
|
+
ErrorExecutionResult,
|
|
4
|
+
ExecutionResult,
|
|
2
5
|
ListenExit,
|
|
6
|
+
PartialExecutionResult,
|
|
3
7
|
Snapshot,
|
|
8
|
+
SuccessExecutionResult,
|
|
4
9
|
ThinkExit,
|
|
5
10
|
getValue
|
|
6
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-XJNRORSK.js";
|
|
7
12
|
import "./chunk-WLUVY5QU.js";
|
|
8
13
|
import {
|
|
9
14
|
Tool
|
|
@@ -14,6 +19,7 @@ import {
|
|
|
14
19
|
} from "./chunk-UNMKB2DA.js";
|
|
15
20
|
import {
|
|
16
21
|
CodeFormattingError,
|
|
22
|
+
LoopExceededError,
|
|
17
23
|
SnapshotSignal,
|
|
18
24
|
ThinkSignal
|
|
19
25
|
} from "./chunk-JKVVQN2P.js";
|
|
@@ -870,16 +876,16 @@ var Chat = class {
|
|
|
870
876
|
|
|
871
877
|
// src/index.ts
|
|
872
878
|
var execute = async (props) => {
|
|
873
|
-
const { executeContext } = await import("./llmz-
|
|
879
|
+
const { executeContext } = await import("./llmz-LAN4WDFW.js");
|
|
874
880
|
return executeContext(props);
|
|
875
881
|
};
|
|
876
882
|
var init = async () => {
|
|
877
|
-
await import("./llmz-
|
|
883
|
+
await import("./llmz-LAN4WDFW.js");
|
|
878
884
|
await import("./component-R2Y74VUI.js");
|
|
879
885
|
await import("./tool-LY77IWV2.js");
|
|
880
886
|
await import("./exit-OIYZLBVJ.js");
|
|
881
887
|
await import("./jsx-AEHVFB3L.js");
|
|
882
|
-
await import("./vm-
|
|
888
|
+
await import("./vm-FLBMZUA2.js");
|
|
883
889
|
await import("./utils-L5GLCS3C.js");
|
|
884
890
|
await import("./truncator-WAL2GCUY.js");
|
|
885
891
|
await import("./typings-AIV2OASX.js");
|
|
@@ -890,11 +896,17 @@ export {
|
|
|
890
896
|
CitationsManager,
|
|
891
897
|
Component,
|
|
892
898
|
DefaultComponents,
|
|
899
|
+
DefaultExit,
|
|
900
|
+
ErrorExecutionResult,
|
|
901
|
+
ExecutionResult,
|
|
893
902
|
Exit,
|
|
894
903
|
ListenExit,
|
|
904
|
+
LoopExceededError,
|
|
895
905
|
ObjectInstance,
|
|
906
|
+
PartialExecutionResult,
|
|
896
907
|
Snapshot,
|
|
897
908
|
SnapshotSignal,
|
|
909
|
+
SuccessExecutionResult,
|
|
898
910
|
ThinkExit,
|
|
899
911
|
ThinkSignal,
|
|
900
912
|
Tool,
|
|
@@ -1,10 +1,13 @@
|
|
|
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
|
|
3
|
+
var _chunkBEPRLBPKcjs = require('./chunk-BEPRLBPK.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkCH5T6SPCcjs = require('./chunk-CH5T6SPC.cjs');
|
|
8
11
|
require('./chunk-6WT5VZBG.cjs');
|
|
9
12
|
require('./chunk-4QTK5ALH.cjs');
|
|
10
13
|
require('./chunk-HYVKY3W6.cjs');
|
|
@@ -16,6 +19,7 @@ require('./chunk-HYVKY3W6.cjs');
|
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
|
|
22
|
+
|
|
19
23
|
var _chunkJDABP4SDcjs = require('./chunk-JDABP4SD.cjs');
|
|
20
24
|
|
|
21
25
|
|
|
@@ -69,7 +73,7 @@ var _executeContext = async (props) => {
|
|
|
69
73
|
const { signal, onIterationEnd, onTrace, onExit, onBeforeExecution } = props;
|
|
70
74
|
const cognitive = props.client instanceof _cognitive.Cognitive ? props.client : new (0, _cognitive.Cognitive)({ client: props.client });
|
|
71
75
|
const cleanups = [];
|
|
72
|
-
const ctx = new (0,
|
|
76
|
+
const ctx = new (0, _chunkCH5T6SPCcjs.Context)({
|
|
73
77
|
chat: props.chat,
|
|
74
78
|
instructions: props.instructions,
|
|
75
79
|
objects: props.objects,
|
|
@@ -84,12 +88,7 @@ var _executeContext = async (props) => {
|
|
|
84
88
|
try {
|
|
85
89
|
while (true) {
|
|
86
90
|
if (ctx.iterations.length >= ctx.loop) {
|
|
87
|
-
return
|
|
88
|
-
status: "error",
|
|
89
|
-
context: ctx,
|
|
90
|
-
error: `Loop limit exceeded. Maximum allowed loops: ${ctx.loop}`,
|
|
91
|
-
iterations: ctx.iterations
|
|
92
|
-
};
|
|
91
|
+
return new (0, _chunkCH5T6SPCcjs.ErrorExecutionResult)(ctx, new (0, _chunkJDABP4SDcjs.LoopExceededError)());
|
|
93
92
|
}
|
|
94
93
|
const iteration = await ctx.nextIteration();
|
|
95
94
|
if (signal == null ? void 0 : signal.aborted) {
|
|
@@ -99,12 +98,7 @@ var _executeContext = async (props) => {
|
|
|
99
98
|
reason: _nullishCoalesce(signal.reason, () => ( "The operation was aborted"))
|
|
100
99
|
}
|
|
101
100
|
});
|
|
102
|
-
return
|
|
103
|
-
status: "error",
|
|
104
|
-
error: _nullishCoalesce(signal.reason, () => ( "The operation was aborted")),
|
|
105
|
-
context: ctx,
|
|
106
|
-
iterations: ctx.iterations
|
|
107
|
-
};
|
|
101
|
+
return new (0, _chunkCH5T6SPCcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(signal.reason, () => ( "The operation was aborted")));
|
|
108
102
|
}
|
|
109
103
|
cleanups.push(
|
|
110
104
|
iteration.traces.onPush((traces) => {
|
|
@@ -138,42 +132,25 @@ var _executeContext = async (props) => {
|
|
|
138
132
|
}
|
|
139
133
|
if (iteration.status.type === "exit_success") {
|
|
140
134
|
const exitName = iteration.status.exit_success.exit_name;
|
|
141
|
-
return {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
result: {
|
|
146
|
-
exit: iteration.exits.find((x) => x.name === exitName),
|
|
147
|
-
result: iteration.status.exit_success.return_value
|
|
148
|
-
}
|
|
149
|
-
};
|
|
135
|
+
return new (0, _chunkCH5T6SPCcjs.SuccessExecutionResult)(ctx, {
|
|
136
|
+
exit: iteration.exits.find((x) => x.name === exitName),
|
|
137
|
+
result: iteration.status.exit_success.return_value
|
|
138
|
+
});
|
|
150
139
|
}
|
|
151
140
|
if (iteration.status.type === "callback_requested") {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
snapshot: _chunkMU4LFVY7cjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
|
|
158
|
-
};
|
|
141
|
+
return new (0, _chunkCH5T6SPCcjs.PartialExecutionResult)(
|
|
142
|
+
ctx,
|
|
143
|
+
iteration.status.callback_requested.signal,
|
|
144
|
+
_chunkCH5T6SPCcjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
|
|
145
|
+
);
|
|
159
146
|
}
|
|
160
147
|
if (iteration.status.type === "thinking_requested" || iteration.status.type === "exit_error" || iteration.status.type === "execution_error" || iteration.status.type === "invalid_code_error") {
|
|
161
148
|
continue;
|
|
162
149
|
}
|
|
163
|
-
return {
|
|
164
|
-
context: ctx,
|
|
165
|
-
error: _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)),
|
|
166
|
-
status: "error",
|
|
167
|
-
iterations: ctx.iterations
|
|
168
|
-
};
|
|
150
|
+
return new (0, _chunkCH5T6SPCcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)));
|
|
169
151
|
}
|
|
170
152
|
} catch (error) {
|
|
171
|
-
return
|
|
172
|
-
status: "error",
|
|
173
|
-
iterations: ctx.iterations,
|
|
174
|
-
context: ctx,
|
|
175
|
-
error: error instanceof Error ? error.message : _nullishCoalesce((error == null ? void 0 : error.toString()), () => ( "Unknown error"))
|
|
176
|
-
};
|
|
153
|
+
return new (0, _chunkCH5T6SPCcjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
|
|
177
154
|
} finally {
|
|
178
155
|
for (const cleanup of cleanups) {
|
|
179
156
|
try {
|
|
@@ -342,7 +319,7 @@ var executeIteration = async ({
|
|
|
342
319
|
});
|
|
343
320
|
}
|
|
344
321
|
startedAt = Date.now();
|
|
345
|
-
const result = await
|
|
322
|
+
const result = await _chunkBEPRLBPKcjs.runAsyncFunction.call(void 0, vmContext, iteration.code, traces, abortSignal, ctx.timeout).catch(
|
|
346
323
|
(err) => {
|
|
347
324
|
return {
|
|
348
325
|
success: false,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runAsyncFunction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-D3ESDRLH.js";
|
|
4
4
|
import {
|
|
5
5
|
Context,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ErrorExecutionResult,
|
|
7
|
+
PartialExecutionResult,
|
|
8
|
+
Snapshot,
|
|
9
|
+
SuccessExecutionResult
|
|
10
|
+
} from "./chunk-XJNRORSK.js";
|
|
8
11
|
import "./chunk-WLUVY5QU.js";
|
|
9
12
|
import "./chunk-QBXIE6EY.js";
|
|
10
13
|
import "./chunk-UNMKB2DA.js";
|
|
@@ -12,6 +15,7 @@ import {
|
|
|
12
15
|
AssignmentError,
|
|
13
16
|
CodeExecutionError,
|
|
14
17
|
InvalidCodeError,
|
|
18
|
+
LoopExceededError,
|
|
15
19
|
Signals,
|
|
16
20
|
SnapshotSignal,
|
|
17
21
|
ThinkSignal,
|
|
@@ -84,12 +88,7 @@ var _executeContext = async (props) => {
|
|
|
84
88
|
try {
|
|
85
89
|
while (true) {
|
|
86
90
|
if (ctx.iterations.length >= ctx.loop) {
|
|
87
|
-
return
|
|
88
|
-
status: "error",
|
|
89
|
-
context: ctx,
|
|
90
|
-
error: `Loop limit exceeded. Maximum allowed loops: ${ctx.loop}`,
|
|
91
|
-
iterations: ctx.iterations
|
|
92
|
-
};
|
|
91
|
+
return new ErrorExecutionResult(ctx, new LoopExceededError());
|
|
93
92
|
}
|
|
94
93
|
const iteration = await ctx.nextIteration();
|
|
95
94
|
if (signal == null ? void 0 : signal.aborted) {
|
|
@@ -99,12 +98,7 @@ var _executeContext = async (props) => {
|
|
|
99
98
|
reason: signal.reason ?? "The operation was aborted"
|
|
100
99
|
}
|
|
101
100
|
});
|
|
102
|
-
return
|
|
103
|
-
status: "error",
|
|
104
|
-
error: signal.reason ?? "The operation was aborted",
|
|
105
|
-
context: ctx,
|
|
106
|
-
iterations: ctx.iterations
|
|
107
|
-
};
|
|
101
|
+
return new ErrorExecutionResult(ctx, signal.reason ?? "The operation was aborted");
|
|
108
102
|
}
|
|
109
103
|
cleanups.push(
|
|
110
104
|
iteration.traces.onPush((traces) => {
|
|
@@ -138,42 +132,25 @@ var _executeContext = async (props) => {
|
|
|
138
132
|
}
|
|
139
133
|
if (iteration.status.type === "exit_success") {
|
|
140
134
|
const exitName = iteration.status.exit_success.exit_name;
|
|
141
|
-
return {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
result: {
|
|
146
|
-
exit: iteration.exits.find((x) => x.name === exitName),
|
|
147
|
-
result: iteration.status.exit_success.return_value
|
|
148
|
-
}
|
|
149
|
-
};
|
|
135
|
+
return new SuccessExecutionResult(ctx, {
|
|
136
|
+
exit: iteration.exits.find((x) => x.name === exitName),
|
|
137
|
+
result: iteration.status.exit_success.return_value
|
|
138
|
+
});
|
|
150
139
|
}
|
|
151
140
|
if (iteration.status.type === "callback_requested") {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
snapshot: Snapshot.fromSignal(iteration.status.callback_requested.signal)
|
|
158
|
-
};
|
|
141
|
+
return new PartialExecutionResult(
|
|
142
|
+
ctx,
|
|
143
|
+
iteration.status.callback_requested.signal,
|
|
144
|
+
Snapshot.fromSignal(iteration.status.callback_requested.signal)
|
|
145
|
+
);
|
|
159
146
|
}
|
|
160
147
|
if (iteration.status.type === "thinking_requested" || iteration.status.type === "exit_error" || iteration.status.type === "execution_error" || iteration.status.type === "invalid_code_error") {
|
|
161
148
|
continue;
|
|
162
149
|
}
|
|
163
|
-
return {
|
|
164
|
-
context: ctx,
|
|
165
|
-
error: iteration.error ?? `Unknown error. Status: ${iteration.status.type}`,
|
|
166
|
-
status: "error",
|
|
167
|
-
iterations: ctx.iterations
|
|
168
|
-
};
|
|
150
|
+
return new ErrorExecutionResult(ctx, iteration.error ?? `Unknown error. Status: ${iteration.status.type}`);
|
|
169
151
|
}
|
|
170
152
|
} catch (error) {
|
|
171
|
-
return
|
|
172
|
-
status: "error",
|
|
173
|
-
iterations: ctx.iterations,
|
|
174
|
-
context: ctx,
|
|
175
|
-
error: error instanceof Error ? error.message : (error == null ? void 0 : error.toString()) ?? "Unknown error"
|
|
176
|
-
};
|
|
153
|
+
return new ErrorExecutionResult(ctx, error ?? "Unknown error");
|
|
177
154
|
} finally {
|
|
178
155
|
for (const cleanup of cleanups) {
|
|
179
156
|
try {
|
package/dist/llmz.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { ValueOrGetter } from './getter.js';
|
|
|
6
6
|
import { type ObjectInstance } from './objects.js';
|
|
7
7
|
import { Snapshot } from './snapshots.js';
|
|
8
8
|
import { type Tool } from './tool.js';
|
|
9
|
-
import {
|
|
9
|
+
import { Trace } from './types.js';
|
|
10
|
+
import { ExecutionResult } from './result.js';
|
|
10
11
|
export type ExecutionHooks = {
|
|
11
12
|
/**
|
|
12
13
|
* Called after each iteration ends
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Context, Iteration } from './context.js';
|
|
2
|
+
import { SnapshotSignal } from './errors.js';
|
|
3
|
+
import { Exit, ExitResult } from './exit.js';
|
|
4
|
+
import { Snapshot } from './snapshots.js';
|
|
5
|
+
export declare abstract class ExecutionResult {
|
|
6
|
+
readonly status: 'success' | 'error' | 'interrupted';
|
|
7
|
+
readonly context: Context;
|
|
8
|
+
protected constructor(status: 'success' | 'error' | 'interrupted', context: Context);
|
|
9
|
+
isSuccess(): this is SuccessExecutionResult;
|
|
10
|
+
isError(): this is ErrorExecutionResult;
|
|
11
|
+
isInterrupted(): this is PartialExecutionResult;
|
|
12
|
+
is<T>(exit: Exit<T>): this is SuccessExecutionResult<T>;
|
|
13
|
+
get output(): unknown | null;
|
|
14
|
+
get iteration(): Iteration | null;
|
|
15
|
+
get iterations(): Iteration[];
|
|
16
|
+
}
|
|
17
|
+
export declare class SuccessExecutionResult<TOutput = unknown> extends ExecutionResult {
|
|
18
|
+
readonly result: ExitResult<TOutput>;
|
|
19
|
+
constructor(context: Context, result: ExitResult<TOutput>);
|
|
20
|
+
get output(): TOutput;
|
|
21
|
+
get iteration(): Iteration;
|
|
22
|
+
}
|
|
23
|
+
export declare class ErrorExecutionResult extends ExecutionResult {
|
|
24
|
+
readonly error: unknown;
|
|
25
|
+
constructor(context: Context, error: unknown);
|
|
26
|
+
get output(): null;
|
|
27
|
+
}
|
|
28
|
+
export declare class PartialExecutionResult extends ExecutionResult {
|
|
29
|
+
readonly signal: SnapshotSignal;
|
|
30
|
+
readonly snapshot: Snapshot;
|
|
31
|
+
constructor(context: Context, signal: SnapshotSignal, snapshot: Snapshot);
|
|
32
|
+
get output(): null;
|
|
33
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type SnapshotSignal, type VMSignal } from './errors.js';
|
|
3
|
-
import { ExitResult } from './exit.js';
|
|
4
|
-
import { type Snapshot } from './snapshots.js';
|
|
1
|
+
import { type VMSignal } from './errors.js';
|
|
5
2
|
export declare namespace Traces {
|
|
6
3
|
type Comment = TraceTemplate<'comment', {
|
|
7
4
|
comment: string;
|
|
@@ -101,37 +98,6 @@ export type ObjectMutation = {
|
|
|
101
98
|
before: any;
|
|
102
99
|
after: any;
|
|
103
100
|
};
|
|
104
|
-
export type SuccessExecutionResult = {
|
|
105
|
-
status: 'success';
|
|
106
|
-
iterations: Iteration[];
|
|
107
|
-
context: Context;
|
|
108
|
-
result: ExitResult;
|
|
109
|
-
};
|
|
110
|
-
export type PartialExecutionResult = {
|
|
111
|
-
status: 'interrupted';
|
|
112
|
-
iterations: Iteration[];
|
|
113
|
-
context: Context;
|
|
114
|
-
signal: SnapshotSignal;
|
|
115
|
-
snapshot: Snapshot;
|
|
116
|
-
};
|
|
117
|
-
export type ErrorExecutionResult = {
|
|
118
|
-
status: 'error';
|
|
119
|
-
iterations: Iteration[];
|
|
120
|
-
context: Context;
|
|
121
|
-
error: string;
|
|
122
|
-
};
|
|
123
|
-
export type ExecutionResult = SuccessExecutionResult | PartialExecutionResult | ErrorExecutionResult;
|
|
124
|
-
export declare function expectStatus<T extends ExecutionResult['status']>(execution: ExecutionResult, status: T): asserts execution is Extract<ExecutionResult, {
|
|
125
|
-
status: T;
|
|
126
|
-
}>;
|
|
127
|
-
export type Tool = {
|
|
128
|
-
name: string;
|
|
129
|
-
aliases?: string[];
|
|
130
|
-
description?: string;
|
|
131
|
-
input?: unknown;
|
|
132
|
-
output?: unknown;
|
|
133
|
-
metadata?: Record<string, any>;
|
|
134
|
-
};
|
|
135
101
|
export type ZuiType<Output = any, Input = Output> = {
|
|
136
102
|
readonly __type__: 'ZuiType';
|
|
137
103
|
readonly _output: Output;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkBEPRLBPKcjs = require('./chunk-BEPRLBPK.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 =
|
|
12
|
+
exports.USE_ISOLATED_VM = _chunkBEPRLBPKcjs.USE_ISOLATED_VM; exports.runAsyncFunction = _chunkBEPRLBPKcjs.runAsyncFunction;
|