llmz 0.0.29 → 0.0.31

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 (30) hide show
  1. package/README.md +25 -12
  2. package/dist/{chunk-WP4F6KMW.cjs → chunk-5BEKU5MZ.cjs} +2 -2
  3. package/dist/{chunk-VADA6DMR.cjs → chunk-66NCLCNT.cjs} +296 -10
  4. package/dist/{chunk-HCC76DDO.js → chunk-AAHUDKBY.js} +2 -2
  5. package/dist/{chunk-FMOTPO76.cjs → chunk-CA7FRCZT.cjs} +1130 -401
  6. package/dist/{chunk-ERK3MOZF.js → chunk-IAYPKHFV.js} +1129 -400
  7. package/dist/{chunk-273DEMEU.cjs → chunk-J57224PD.cjs} +62 -8
  8. package/dist/{chunk-7POUFE5M.js → chunk-RC6YO5UW.js} +62 -8
  9. package/dist/{chunk-KQPGB6GB.js → chunk-WYFTNO2Y.js} +289 -3
  10. package/dist/compiler/compiler.d.ts +1 -0
  11. package/dist/compiler/plugins/async-iterator.d.ts +2 -0
  12. package/dist/compiler/plugins/html-to-markdown.d.ts +21 -0
  13. package/dist/compiler/plugins/jsx-undefined-vars.d.ts +14 -0
  14. package/dist/{dual-modes-DW3KRXT2.js → dual-modes-LEAHGCOF.js} +1 -1
  15. package/dist/{dual-modes-F4UV5VAZ.cjs → dual-modes-UBHAMQW4.cjs} +2 -2
  16. package/dist/exit-parser.d.ts +37 -0
  17. package/dist/index.cjs +12 -10
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +11 -9
  20. package/dist/{llmz-RZUY2RT4.cjs → llmz-NB4CQ5PW.cjs} +29 -50
  21. package/dist/{llmz-QUBEO7EF.js → llmz-VOXE65UW.js} +21 -42
  22. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  23. package/dist/quickjs-variant.d.ts +2 -0
  24. package/dist/{tool-GEBXW6AQ.js → tool-U6SV6BZ6.js} +1 -1
  25. package/dist/{tool-GMYMVXUK.cjs → tool-YCYYKKB3.cjs} +2 -2
  26. package/dist/tool.d.ts +1 -1
  27. package/dist/{vm-5SJN3OJI.cjs → vm-2LG42J6U.cjs} +2 -4
  28. package/dist/{vm-SQHETBVH.js → vm-FVQBX2XV.js} +1 -3
  29. package/dist/vm.d.ts +7 -1
  30. package/package.json +3 -2
@@ -94,7 +94,16 @@ var Tool = (_class = class _Tool {
94
94
  * @internal
95
95
  */
96
96
  get zInput() {
97
- let input = this.input ? _zui.transforms.fromJSONSchemaLegacy(this.input) : _zui.z.any();
97
+ let input;
98
+ if (this.input) {
99
+ try {
100
+ input = _zui.transforms.fromJSONSchema(this.input);
101
+ } catch (e2) {
102
+ input = _zui.transforms.fromJSONSchemaLegacy(this.input);
103
+ }
104
+ } else {
105
+ input = _zui.z.any();
106
+ }
98
107
  if (!_chunkUQOBUJIQcjs.isEmpty_default.call(void 0, this._staticInputValues)) {
99
108
  const inputExtensions = _chunkWHNOR4ZUcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
100
109
  if (input instanceof _zui.z.ZodObject) {
@@ -114,7 +123,14 @@ var Tool = (_class = class _Tool {
114
123
  * @internal
115
124
  */
116
125
  get zOutput() {
117
- return this.output ? _zui.transforms.fromJSONSchemaLegacy(this.output) : _zui.z.void();
126
+ if (!this.output) {
127
+ return _zui.z.void();
128
+ }
129
+ try {
130
+ return _zui.transforms.fromJSONSchema(this.output);
131
+ } catch (e3) {
132
+ return _zui.transforms.fromJSONSchemaLegacy(this.output);
133
+ }
118
134
  }
119
135
  /**
120
136
  * Renames the tool and updates its aliases.
@@ -200,8 +216,22 @@ var Tool = (_class = class _Tool {
200
216
  clone(props = {}) {
201
217
  var _a, _b;
202
218
  try {
203
- const zInput = this.input ? _zui.transforms.fromJSONSchemaLegacy(this.input) : void 0;
204
- const zOutput = this.output ? _zui.transforms.fromJSONSchemaLegacy(this.output) : void 0;
219
+ let zInput;
220
+ if (this.input) {
221
+ try {
222
+ zInput = _zui.transforms.fromJSONSchema(this.input);
223
+ } catch (e4) {
224
+ zInput = _zui.transforms.fromJSONSchemaLegacy(this.input);
225
+ }
226
+ }
227
+ let zOutput;
228
+ if (this.output) {
229
+ try {
230
+ zOutput = _zui.transforms.fromJSONSchema(this.output);
231
+ } catch (e5) {
232
+ zOutput = _zui.transforms.fromJSONSchemaLegacy(this.output);
233
+ }
234
+ }
205
235
  return new _Tool({
206
236
  name: _nullishCoalesce(props.name, () => ( this.name)),
207
237
  aliases: _nullishCoalesce(props.aliases, () => ( [...this.aliases])),
@@ -324,7 +354,11 @@ var Tool = (_class = class _Tool {
324
354
  }
325
355
  if (typeof props.input !== "undefined") {
326
356
  if (_chunkWHNOR4ZUcjs.isZuiSchema.call(void 0, props.input)) {
327
- this.input = _zui.transforms.toJSONSchemaLegacy(props.input);
357
+ try {
358
+ this.input = _zui.transforms.toJSONSchema(props.input);
359
+ } catch (e6) {
360
+ this.input = _zui.transforms.toJSONSchemaLegacy(props.input);
361
+ }
328
362
  } else if (_chunkWHNOR4ZUcjs.isJsonSchema.call(void 0, props.input)) {
329
363
  this.input = props.input;
330
364
  } else {
@@ -335,7 +369,11 @@ var Tool = (_class = class _Tool {
335
369
  }
336
370
  if (typeof props.output !== "undefined") {
337
371
  if (_chunkWHNOR4ZUcjs.isZuiSchema.call(void 0, props.output)) {
338
- this.output = _zui.transforms.toJSONSchemaLegacy(props.output);
372
+ try {
373
+ this.output = _zui.transforms.toJSONSchema(props.output);
374
+ } catch (e7) {
375
+ this.output = _zui.transforms.toJSONSchemaLegacy(props.output);
376
+ }
339
377
  } else if (_chunkWHNOR4ZUcjs.isJsonSchema.call(void 0, props.output)) {
340
378
  this.output = props.output;
341
379
  } else {
@@ -413,8 +451,24 @@ var Tool = (_class = class _Tool {
413
451
  * @returns Promise resolving to TypeScript declaration string
414
452
  */
415
453
  async getTypings() {
416
- let input = this.input ? _zui.transforms.fromJSONSchemaLegacy(this.input) : void 0;
417
- const output = this.output ? _zui.transforms.fromJSONSchemaLegacy(this.output) : _zui.z.void();
454
+ let input;
455
+ if (this.input) {
456
+ try {
457
+ input = _zui.transforms.fromJSONSchema(this.input);
458
+ } catch (e8) {
459
+ input = _zui.transforms.fromJSONSchemaLegacy(this.input);
460
+ }
461
+ }
462
+ let output;
463
+ if (!this.output || Object.keys(this.output).length === 0) {
464
+ output = _zui.z.void();
465
+ } else {
466
+ try {
467
+ output = _zui.transforms.fromJSONSchema(this.output);
468
+ } catch (e9) {
469
+ output = _zui.transforms.fromJSONSchemaLegacy(this.output);
470
+ }
471
+ }
418
472
  if ((input == null ? void 0 : input.naked()) instanceof _zui.ZodObject && typeof this._staticInputValues === "object" && !_chunkUQOBUJIQcjs.isEmpty_default.call(void 0, this._staticInputValues)) {
419
473
  const inputExtensions = _chunkWHNOR4ZUcjs.convertObjectToZuiLiterals.call(void 0, this._staticInputValues);
420
474
  input = input.extend(inputExtensions);
@@ -94,7 +94,16 @@ var Tool = class _Tool {
94
94
  * @internal
95
95
  */
96
96
  get zInput() {
97
- let input = this.input ? transforms.fromJSONSchemaLegacy(this.input) : z.any();
97
+ let input;
98
+ if (this.input) {
99
+ try {
100
+ input = transforms.fromJSONSchema(this.input);
101
+ } catch {
102
+ input = transforms.fromJSONSchemaLegacy(this.input);
103
+ }
104
+ } else {
105
+ input = z.any();
106
+ }
98
107
  if (!isEmpty_default(this._staticInputValues)) {
99
108
  const inputExtensions = convertObjectToZuiLiterals(this._staticInputValues);
100
109
  if (input instanceof z.ZodObject) {
@@ -114,7 +123,14 @@ var Tool = class _Tool {
114
123
  * @internal
115
124
  */
116
125
  get zOutput() {
117
- return this.output ? transforms.fromJSONSchemaLegacy(this.output) : z.void();
126
+ if (!this.output) {
127
+ return z.void();
128
+ }
129
+ try {
130
+ return transforms.fromJSONSchema(this.output);
131
+ } catch {
132
+ return transforms.fromJSONSchemaLegacy(this.output);
133
+ }
118
134
  }
119
135
  /**
120
136
  * Renames the tool and updates its aliases.
@@ -200,8 +216,22 @@ var Tool = class _Tool {
200
216
  clone(props = {}) {
201
217
  var _a, _b;
202
218
  try {
203
- const zInput = this.input ? transforms.fromJSONSchemaLegacy(this.input) : void 0;
204
- const zOutput = this.output ? transforms.fromJSONSchemaLegacy(this.output) : void 0;
219
+ let zInput;
220
+ if (this.input) {
221
+ try {
222
+ zInput = transforms.fromJSONSchema(this.input);
223
+ } catch {
224
+ zInput = transforms.fromJSONSchemaLegacy(this.input);
225
+ }
226
+ }
227
+ let zOutput;
228
+ if (this.output) {
229
+ try {
230
+ zOutput = transforms.fromJSONSchema(this.output);
231
+ } catch {
232
+ zOutput = transforms.fromJSONSchemaLegacy(this.output);
233
+ }
234
+ }
205
235
  return new _Tool({
206
236
  name: props.name ?? this.name,
207
237
  aliases: props.aliases ?? [...this.aliases],
@@ -324,7 +354,11 @@ var Tool = class _Tool {
324
354
  }
325
355
  if (typeof props.input !== "undefined") {
326
356
  if (isZuiSchema(props.input)) {
327
- this.input = transforms.toJSONSchemaLegacy(props.input);
357
+ try {
358
+ this.input = transforms.toJSONSchema(props.input);
359
+ } catch {
360
+ this.input = transforms.toJSONSchemaLegacy(props.input);
361
+ }
328
362
  } else if (isJsonSchema(props.input)) {
329
363
  this.input = props.input;
330
364
  } else {
@@ -335,7 +369,11 @@ var Tool = class _Tool {
335
369
  }
336
370
  if (typeof props.output !== "undefined") {
337
371
  if (isZuiSchema(props.output)) {
338
- this.output = transforms.toJSONSchemaLegacy(props.output);
372
+ try {
373
+ this.output = transforms.toJSONSchema(props.output);
374
+ } catch {
375
+ this.output = transforms.toJSONSchemaLegacy(props.output);
376
+ }
339
377
  } else if (isJsonSchema(props.output)) {
340
378
  this.output = props.output;
341
379
  } else {
@@ -413,8 +451,24 @@ var Tool = class _Tool {
413
451
  * @returns Promise resolving to TypeScript declaration string
414
452
  */
415
453
  async getTypings() {
416
- let input = this.input ? transforms.fromJSONSchemaLegacy(this.input) : void 0;
417
- const output = this.output ? transforms.fromJSONSchemaLegacy(this.output) : z.void();
454
+ let input;
455
+ if (this.input) {
456
+ try {
457
+ input = transforms.fromJSONSchema(this.input);
458
+ } catch {
459
+ input = transforms.fromJSONSchemaLegacy(this.input);
460
+ }
461
+ }
462
+ let output;
463
+ if (!this.output || Object.keys(this.output).length === 0) {
464
+ output = z.void();
465
+ } else {
466
+ try {
467
+ output = transforms.fromJSONSchema(this.output);
468
+ } catch {
469
+ output = transforms.fromJSONSchemaLegacy(this.output);
470
+ }
471
+ }
418
472
  if ((input == null ? void 0 : input.naked()) instanceof ZodObject && typeof this._staticInputValues === "object" && !isEmpty_default(this._staticInputValues)) {
419
473
  const inputExtensions = convertObjectToZuiLiterals(this._staticInputValues);
420
474
  input = input.extend(inputExtensions);
@@ -2,10 +2,10 @@ import {
2
2
  DualModePrompt,
3
3
  extractType,
4
4
  inspect
5
- } from "./chunk-HCC76DDO.js";
5
+ } from "./chunk-AAHUDKBY.js";
6
6
  import {
7
7
  Tool
8
- } from "./chunk-7POUFE5M.js";
8
+ } from "./chunk-RC6YO5UW.js";
9
9
  import {
10
10
  LoopExceededError
11
11
  } from "./chunk-MYLTD5WT.js";
@@ -20,9 +20,294 @@ import {
20
20
  } from "./chunk-3JYCCI4S.js";
21
21
  import {
22
22
  cloneDeep_default,
23
- isPlainObject_default
23
+ isPlainObject_default,
24
+ omit_default
24
25
  } from "./chunk-7WRN4E42.js";
25
26
 
27
+ // src/exit-parser.ts
28
+ function isValuePrimitive(value) {
29
+ return value === null || value === void 0 || typeof value !== "object" || Array.isArray(value);
30
+ }
31
+ function generatePossibleWraps(value, shape, discriminator) {
32
+ const possibleWraps = [];
33
+ const commonNames = ["result", "value", "data", "message", "error", "output", "response"];
34
+ if (shape && typeof shape === "object") {
35
+ for (const key of Object.keys(shape)) {
36
+ if (key !== discriminator) {
37
+ const wrap = discriminator ? { [discriminator]: shape[discriminator]._def.value, [key]: value } : { [key]: value };
38
+ possibleWraps.push(wrap);
39
+ }
40
+ }
41
+ }
42
+ for (const name of commonNames) {
43
+ const hasName = possibleWraps.some((w) => Object.keys(w).includes(name));
44
+ if (!hasName) {
45
+ const wrap = discriminator && (shape == null ? void 0 : shape[discriminator]) ? { [discriminator]: shape[discriminator]._def.value, [name]: value } : { [name]: value };
46
+ possibleWraps.push(wrap);
47
+ }
48
+ }
49
+ return possibleWraps;
50
+ }
51
+ function tryObjectWrapping(schema, candidateValue) {
52
+ const possibleWraps = generatePossibleWraps(candidateValue, schema.shape);
53
+ for (const wrap of possibleWraps) {
54
+ const testParse = schema.safeParse(wrap);
55
+ if (testParse.success) {
56
+ return { success: true, valueToValidate: wrap, parsed: testParse };
57
+ }
58
+ }
59
+ return { success: false, valueToValidate: candidateValue, parsed: { success: false } };
60
+ }
61
+ function detectDiscriminator(options) {
62
+ if (options.length === 0 || options[0]._def.typeName !== "ZodObject") {
63
+ return void 0;
64
+ }
65
+ const firstShape = options[0].shape;
66
+ for (const key in firstShape) {
67
+ const firstFieldType = firstShape[key]._def.typeName;
68
+ if (firstFieldType === "ZodLiteral") {
69
+ const allHaveLiteral = options.every((opt) => {
70
+ var _a;
71
+ return ((_a = opt.shape[key]) == null ? void 0 : _a._def.typeName) === "ZodLiteral";
72
+ });
73
+ if (allHaveLiteral) {
74
+ return key;
75
+ }
76
+ }
77
+ }
78
+ return void 0;
79
+ }
80
+ function tryAddDiscriminator(schema, options, discriminator, valueToValidate) {
81
+ const matchingOptions = [];
82
+ for (const option of options) {
83
+ if (option._def.typeName === "ZodObject" && option.shape[discriminator]) {
84
+ const discriminatorValue = option.shape[discriminator]._def.value;
85
+ const wrappedValue = { [discriminator]: discriminatorValue, ...valueToValidate };
86
+ const testParse = schema.safeParse(wrappedValue);
87
+ if (testParse.success) {
88
+ matchingOptions.push({ wrappedValue });
89
+ }
90
+ }
91
+ }
92
+ if (matchingOptions.length === 1) {
93
+ const wrapped = matchingOptions[0].wrappedValue;
94
+ return { success: true, valueToValidate: wrapped, parsed: schema.safeParse(wrapped) };
95
+ }
96
+ return { success: false, valueToValidate, parsed: { success: false } };
97
+ }
98
+ function tryUnionPrimitiveWrapping(schema, options, discriminator, valueToValidate) {
99
+ const allSuccessfulWraps = [];
100
+ for (const option of options) {
101
+ if (option._def.typeName === "ZodObject" && option.shape[discriminator]) {
102
+ const discriminatorValue = option.shape[discriminator]._def.value;
103
+ const possibleWraps = generatePossibleWraps(valueToValidate, option.shape, discriminator);
104
+ for (const wrap of possibleWraps) {
105
+ const finalWrap = { [discriminator]: discriminatorValue, ...wrap };
106
+ const testParse = schema.safeParse(finalWrap);
107
+ if (testParse.success) {
108
+ allSuccessfulWraps.push({ wrap: finalWrap });
109
+ break;
110
+ }
111
+ }
112
+ }
113
+ }
114
+ if (allSuccessfulWraps.length === 1) {
115
+ const wrapped = allSuccessfulWraps[0].wrap;
116
+ return { success: true, valueToValidate: wrapped, parsed: schema.safeParse(wrapped) };
117
+ }
118
+ return { success: false, valueToValidate, parsed: { success: false } };
119
+ }
120
+ function tryUnionWrapping(schema, valueToValidate) {
121
+ const options = schema._def.options;
122
+ let discriminator = schema._def.discriminator;
123
+ if (!discriminator) {
124
+ discriminator = detectDiscriminator(options);
125
+ }
126
+ if (!discriminator) {
127
+ return { success: false, valueToValidate, parsed: { success: false } };
128
+ }
129
+ const isValueObject = valueToValidate !== null && typeof valueToValidate === "object" && !Array.isArray(valueToValidate);
130
+ const isPrimitive = isValuePrimitive(valueToValidate);
131
+ if (isValueObject && !(discriminator in valueToValidate)) {
132
+ const result = tryAddDiscriminator(schema, options, discriminator, valueToValidate);
133
+ if (result.success) {
134
+ return result;
135
+ }
136
+ }
137
+ if (isPrimitive) {
138
+ return tryUnionPrimitiveWrapping(schema, options, discriminator, valueToValidate);
139
+ }
140
+ return { success: false, valueToValidate, parsed: { success: false } };
141
+ }
142
+ function trySmartWrapping(schema, schemaType, valueToValidate, alternativeValue) {
143
+ const valuesToTry = [valueToValidate];
144
+ if (alternativeValue !== void 0 && alternativeValue !== valueToValidate) {
145
+ valuesToTry.push(alternativeValue);
146
+ }
147
+ for (const candidateValue of valuesToTry) {
148
+ const isPrimitive = isValuePrimitive(candidateValue);
149
+ if (schemaType === "ZodObject" && isPrimitive) {
150
+ const result = tryObjectWrapping(schema, candidateValue);
151
+ if (result.success) {
152
+ return result;
153
+ }
154
+ }
155
+ }
156
+ if (alternativeValue !== void 0 && alternativeValue !== valueToValidate) {
157
+ valueToValidate = alternativeValue;
158
+ }
159
+ if (schemaType === "ZodDiscriminatedUnion" || schemaType === "ZodUnion") {
160
+ const result = tryUnionWrapping(schema, valueToValidate);
161
+ if (result.success) {
162
+ return result;
163
+ }
164
+ }
165
+ return { valueToValidate, parsed: { success: false } };
166
+ }
167
+ function parseExit(returnValue, exits) {
168
+ if (!returnValue) {
169
+ return {
170
+ success: false,
171
+ error: "No return value provided",
172
+ returnValue
173
+ };
174
+ }
175
+ const returnAction = returnValue.action;
176
+ if (!returnAction) {
177
+ return {
178
+ success: false,
179
+ error: `Code did not return an action. Valid actions are: ${exits.map((x) => x.name).join(", ")}`,
180
+ returnValue
181
+ };
182
+ }
183
+ const returnExit = exits.find((x) => x.name.toLowerCase() === returnAction.toLowerCase()) ?? exits.find((x) => x.aliases.some((a) => a.toLowerCase() === returnAction.toLowerCase()));
184
+ if (!returnExit) {
185
+ return {
186
+ success: false,
187
+ error: `Exit "${returnAction}" not found. Valid actions are: ${exits.map((x) => x.name).join(", ")}`,
188
+ returnValue
189
+ };
190
+ }
191
+ if (!returnExit.zSchema) {
192
+ const otherProps = omit_default(returnValue, "action");
193
+ const value = Object.keys(otherProps).length === 1 ? Object.values(otherProps)[0] : otherProps;
194
+ return {
195
+ success: true,
196
+ exit: returnExit,
197
+ value
198
+ };
199
+ }
200
+ let valueToValidate = returnValue.value;
201
+ let alternativeValue = void 0;
202
+ if (valueToValidate === void 0) {
203
+ const otherProps = omit_default(returnValue, "action");
204
+ if (Object.keys(otherProps).length > 0) {
205
+ valueToValidate = otherProps;
206
+ if (Object.keys(otherProps).length === 1) {
207
+ alternativeValue = Object.values(otherProps)[0];
208
+ }
209
+ }
210
+ }
211
+ const schema = returnExit.zSchema;
212
+ const schemaType = schema._def.typeName;
213
+ let parsed = schema.safeParse(valueToValidate);
214
+ if (!parsed.success && alternativeValue !== void 0 && alternativeValue !== valueToValidate) {
215
+ const altParsed = schema.safeParse(alternativeValue);
216
+ if (altParsed.success) {
217
+ parsed = altParsed;
218
+ valueToValidate = alternativeValue;
219
+ }
220
+ }
221
+ if (!parsed.success) {
222
+ const result = trySmartWrapping(schema, schemaType, valueToValidate, alternativeValue);
223
+ valueToValidate = result.valueToValidate;
224
+ parsed = result.parsed;
225
+ }
226
+ if (!parsed.success) {
227
+ const getValueTypeDescription = (val) => {
228
+ if (val === null)
229
+ return "null";
230
+ if (val === void 0)
231
+ return "undefined";
232
+ if (Array.isArray(val))
233
+ return "array";
234
+ return typeof val;
235
+ };
236
+ const generatedType = getValueTypeDescription(valueToValidate);
237
+ let generatedStatement = `return { action: '${returnAction}'`;
238
+ if (returnValue.value !== void 0) {
239
+ generatedStatement += `, value: ${generatedType}`;
240
+ } else {
241
+ const otherProps = omit_default(returnValue, "action");
242
+ const propKeys = Object.keys(otherProps);
243
+ if (propKeys.length === 1) {
244
+ generatedStatement += `, ${propKeys[0]}: ${generatedType}`;
245
+ } else if (propKeys.length > 1) {
246
+ generatedStatement += `, ${propKeys.join(", ")}`;
247
+ }
248
+ }
249
+ generatedStatement += " }";
250
+ const expectedStatements = [];
251
+ for (const exit of exits) {
252
+ let statement = `return { action: '${exit.name}'`;
253
+ if (exit.zSchema) {
254
+ const schema2 = exit.zSchema;
255
+ const typeName = schema2._def.typeName;
256
+ if (typeName === "ZodObject") {
257
+ const shape = schema2.shape;
258
+ const properties = Object.keys(shape).map((key) => {
259
+ var _a;
260
+ const field = shape[key];
261
+ const fieldType = field._def.typeName || "unknown";
262
+ const isOptional = ((_a = field.isOptional) == null ? void 0 : _a.call(field)) || false;
263
+ return `${key}${isOptional ? "?" : ""}: ${fieldType.replace("Zod", "").toLowerCase()}`;
264
+ });
265
+ statement += `, value: { ${properties.join(", ")} }`;
266
+ } else if (typeName === "ZodUnion" || typeName === "ZodDiscriminatedUnion") {
267
+ const options = schema2._def.options || [];
268
+ const variants = options.map((opt) => {
269
+ if (opt._def.typeName === "ZodObject") {
270
+ const shape = opt.shape;
271
+ const properties = Object.keys(shape).map((key) => {
272
+ const field = shape[key];
273
+ const fieldType = field._def.typeName || "unknown";
274
+ return `${key}: ${fieldType.replace("Zod", "").toLowerCase()}`;
275
+ });
276
+ return `{ ${properties.join(", ")} }`;
277
+ }
278
+ return "unknown";
279
+ });
280
+ statement += `, value: ${variants.join(" | ")}`;
281
+ } else {
282
+ const schemaTypeName = (typeName == null ? void 0 : typeName.replace("Zod", "").toLowerCase()) || "unknown";
283
+ statement += `, value: ${schemaTypeName}`;
284
+ }
285
+ }
286
+ statement += " }";
287
+ expectedStatements.push(statement);
288
+ }
289
+ const errorMessage = [
290
+ `Invalid return value for exit "${returnExit.name}"`,
291
+ "",
292
+ "You generated:",
293
+ ` ${generatedStatement}`,
294
+ "",
295
+ "But expected one of:",
296
+ ...expectedStatements.map((s) => ` ${s}`)
297
+ ].join("\n");
298
+ return {
299
+ success: false,
300
+ error: errorMessage,
301
+ returnValue
302
+ };
303
+ }
304
+ return {
305
+ success: true,
306
+ exit: returnExit,
307
+ value: parsed.data
308
+ };
309
+ }
310
+
26
311
  // src/snapshots.ts
27
312
  import { ulid } from "ulid";
28
313
  var MAX_SNAPSHOT_SIZE_BYTES = 4e3;
@@ -1101,6 +1386,7 @@ var Context = class {
1101
1386
  };
1102
1387
 
1103
1388
  export {
1389
+ parseExit,
1104
1390
  Snapshot,
1105
1391
  ExecutionResult,
1106
1392
  SuccessExecutionResult,
@@ -14,6 +14,7 @@ export declare const Identifiers: {
14
14
  export type CompiledCode = ReturnType<typeof compile>;
15
15
  export declare function compile(code: string): {
16
16
  code: string;
17
+ codeWithMarkers: string;
17
18
  map: {
18
19
  version: number;
19
20
  sources: string[];
@@ -1,3 +1,5 @@
1
+ export declare const USER_CODE_START_MARKER = "/* __LLMZ_USER_CODE_START__ */";
2
+ export declare const USER_CODE_END_MARKER = "/* __LLMZ_USER_CODE_END__ */";
1
3
  export declare const AsyncIterator: {
2
4
  preProcessing: (code: string) => string;
3
5
  postProcessing: (code: string) => string;
@@ -0,0 +1,21 @@
1
+ import { type PluginObj } from '@babel/core';
2
+ /**
3
+ * This plugin converts simple HTML tags in JSX text to markdown equivalents.
4
+ * Only handles basic formatting tags without attributes (except href/src).
5
+ *
6
+ * Supported conversions:
7
+ * - <strong>text</strong> -> **text**
8
+ * - <b>text</b> -> **text**
9
+ * - <em>text</em> -> *text*
10
+ * - <i>text</i> -> *text*
11
+ * - <u>text</u> -> __text__
12
+ * - <a href="url">text</a> -> [text](url)
13
+ * - <ul><li>item</li></ul> -> - item
14
+ * - <ol><li>item</li></ol> -> 1. item
15
+ * - <br>, <br/>, <br /> -> \n
16
+ * - <p>text</p> -> text\n\n
17
+ *
18
+ * Only converts tags that have no attributes (except href for links).
19
+ * Preserves complex HTML that can't be represented in simple markdown.
20
+ */
21
+ export declare function htmlToMarkdownPlugin(): PluginObj;
@@ -0,0 +1,14 @@
1
+ import { type PluginObj } from '@babel/core';
2
+ /**
3
+ * This plugin transforms JSX expressions that reference undefined variables
4
+ * into safe fallbacks that display the variable name as a string.
5
+ *
6
+ * For example:
7
+ * <div>{content}</div>
8
+ * becomes:
9
+ * <div>{(() => { try { return content } catch { return 'content' } })()}</div>
10
+ *
11
+ * This prevents "variable is not defined" errors when the LLM generates JSX
12
+ * with variable references that don't exist in the actual execution scope.
13
+ */
14
+ export declare function jsxUndefinedVarsPlugin(): PluginObj;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DualModePrompt
3
- } from "./chunk-HCC76DDO.js";
3
+ } from "./chunk-AAHUDKBY.js";
4
4
  import "./chunk-YEAWWJSJ.js";
5
5
  import "./chunk-GGWM6X2K.js";
6
6
  import "./chunk-ORQP26SZ.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkWP4F6KMWcjs = require('./chunk-WP4F6KMW.cjs');
3
+ var _chunk5BEKU5MZcjs = require('./chunk-5BEKU5MZ.cjs');
4
4
  require('./chunk-KIN7Y247.cjs');
5
5
  require('./chunk-ZRCU35UV.cjs');
6
6
  require('./chunk-KMZDFWYZ.cjs');
@@ -9,4 +9,4 @@ require('./chunk-WHNOR4ZU.cjs');
9
9
  require('./chunk-UQOBUJIQ.cjs');
10
10
 
11
11
 
12
- exports.DualModePrompt = _chunkWP4F6KMWcjs.DualModePrompt;
12
+ exports.DualModePrompt = _chunk5BEKU5MZcjs.DualModePrompt;
@@ -0,0 +1,37 @@
1
+ import { Exit } from './exit.js';
2
+ /**
3
+ * Result of parsing an exit from return value
4
+ */
5
+ export type ParsedExit = {
6
+ success: true;
7
+ exit: Exit;
8
+ value: unknown;
9
+ } | {
10
+ success: false;
11
+ error: string;
12
+ returnValue: unknown;
13
+ };
14
+ /**
15
+ * Parses and validates a return value against a list of exits.
16
+ * Attempts to intelligently fit the data to the expected schema.
17
+ *
18
+ * @param returnValue - The raw return value from code execution
19
+ * @param exits - Available exits to match against
20
+ * @returns Parsed exit result with validated data or error
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const exits = [
25
+ * new Exit({ name: 'done', schema: z.object({ result: z.string() }) })
26
+ * ]
27
+ *
28
+ * // Returns primitive value - will be smart-wrapped
29
+ * const result = parseExit({ action: 'done', data: 'hello' }, exits)
30
+ * // result.success === true
31
+ * // result.value === { result: 'hello' }
32
+ * ```
33
+ */
34
+ export declare function parseExit(returnValue: {
35
+ action: string;
36
+ [key: string]: unknown;
37
+ } | null, exits: Exit[]): ParsedExit;