llmz 0.0.30 → 0.0.32

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 (35) hide show
  1. package/dist/{chunk-7POUFE5M.js → chunk-23SY6IDW.js} +63 -9
  2. package/dist/{chunk-KQPGB6GB.js → chunk-4JN4PPGP.js} +293 -4
  3. package/dist/{chunk-VADA6DMR.cjs → chunk-4XIOQWVZ.cjs} +301 -12
  4. package/dist/{chunk-WP4F6KMW.cjs → chunk-5BEKU5MZ.cjs} +2 -2
  5. package/dist/{chunk-R3LXNE5N.cjs → chunk-5FWOHMO4.cjs} +325 -60
  6. package/dist/{chunk-HCC76DDO.js → chunk-AAHUDKBY.js} +2 -2
  7. package/dist/{chunk-DCYSCVQM.js → chunk-G3LSBWJT.js} +304 -39
  8. package/dist/{chunk-RLOPQZTQ.cjs → chunk-INDOGCAQ.cjs} +2 -2
  9. package/dist/{chunk-T63Y6GTW.cjs → chunk-PK72FAKD.cjs} +2 -1
  10. package/dist/{chunk-273DEMEU.cjs → chunk-SOEKWFU2.cjs} +64 -10
  11. package/dist/{chunk-IUE5BW56.js → chunk-U4HWJLF2.js} +1 -1
  12. package/dist/{chunk-MYLTD5WT.js → chunk-WSVDMGMR.js} +2 -1
  13. package/dist/compiler/plugins/html-to-markdown.d.ts +21 -0
  14. package/dist/compiler/plugins/jsx-undefined-vars.d.ts +14 -0
  15. package/dist/context.d.ts +20 -0
  16. package/dist/{dual-modes-DW3KRXT2.js → dual-modes-LEAHGCOF.js} +1 -1
  17. package/dist/{dual-modes-F4UV5VAZ.cjs → dual-modes-UBHAMQW4.cjs} +2 -2
  18. package/dist/errors.d.ts +2 -1
  19. package/dist/exit-parser.d.ts +37 -0
  20. package/dist/index.cjs +20 -18
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +14 -12
  23. package/dist/{llmz-N6KWKJ2Q.js → llmz-3E2JM3HM.js} +85 -42
  24. package/dist/{llmz-DYB74G5C.cjs → llmz-HGUVAYIN.cjs} +105 -62
  25. package/dist/llmz.d.ts +12 -0
  26. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  27. package/dist/result.d.ts +18 -0
  28. package/dist/{tool-GEBXW6AQ.js → tool-7QXH6A24.js} +3 -3
  29. package/dist/{tool-GMYMVXUK.cjs → tool-JVLOALQN.cjs} +4 -4
  30. package/dist/tool.d.ts +1 -1
  31. package/dist/{typings-3VYUEACY.js → typings-ALZEKGV6.js} +2 -2
  32. package/dist/{typings-2RAAZ2YP.cjs → typings-OLI56LGT.cjs} +3 -3
  33. package/dist/{vm-NGQ6DRS3.cjs → vm-VFORKC54.cjs} +3 -3
  34. package/dist/{vm-J6UNJGIN.js → vm-Y3WY2627.js} +2 -2
  35. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTypings
3
- } from "./chunk-IUE5BW56.js";
3
+ } from "./chunk-U4HWJLF2.js";
4
4
  import {
5
5
  convertObjectToZuiLiterals,
6
6
  isJsonSchema,
@@ -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,13 +2,13 @@ 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-23SY6IDW.js";
9
9
  import {
10
10
  LoopExceededError
11
- } from "./chunk-MYLTD5WT.js";
11
+ } from "./chunk-WSVDMGMR.js";
12
12
  import {
13
13
  Exit
14
14
  } from "./chunk-VPTFUOIK.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;
@@ -687,6 +972,9 @@ var Iteration = class {
687
972
  get model() {
688
973
  return this._parameters.model;
689
974
  }
975
+ set model(value) {
976
+ this._parameters.model = value;
977
+ }
690
978
  get temperature() {
691
979
  return this._parameters.temperature;
692
980
  }
@@ -1101,6 +1389,7 @@ var Context = class {
1101
1389
  };
1102
1390
 
1103
1391
  export {
1392
+ parseExit,
1104
1393
  Snapshot,
1105
1394
  ExecutionResult,
1106
1395
  SuccessExecutionResult,