llmz 0.0.2 → 0.0.4

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 (81) hide show
  1. package/dist/{chunk-RB2L33ZR.js → chunk-4EWY34YA.js} +24 -24
  2. package/dist/{chunk-UG2GCPHF.js → chunk-4KB5WXHR.js} +3 -2
  3. package/dist/{chunk-YPOOKE3A.cjs → chunk-4QTK5ALH.cjs} +59 -28
  4. package/dist/{chunk-BKGPO722.cjs → chunk-5NVNEEYW.cjs} +55 -55
  5. package/dist/{chunk-DFZ6GX5C.js → chunk-5TRUJES5.js} +1 -1
  6. package/dist/{chunk-C2TSWGYC.cjs → chunk-6YWYCVAB.cjs} +5 -4
  7. package/dist/{chunk-7S3UY52U.js → chunk-7WRN4E42.js} +36 -8
  8. package/dist/{chunk-Q4DEJGXD.js → chunk-EFGXTO64.js} +2 -2
  9. package/dist/{chunk-VP6WWAE2.cjs → chunk-FIVFS4HG.cjs} +2 -2
  10. package/dist/{chunk-YUDUY7XW.cjs → chunk-HYVKY3W6.cjs} +23 -24
  11. package/dist/{chunk-PQN6HW7A.cjs → chunk-IKSIOIIP.cjs} +3 -3
  12. package/dist/{chunk-ZUAFUOUR.cjs → chunk-JDABP4SD.cjs} +3 -3
  13. package/dist/{chunk-E5W3P7EO.cjs → chunk-JK2LZW2G.cjs} +20 -2
  14. package/dist/{chunk-RJHDQL4C.js → chunk-JKVVQN2P.js} +1 -1
  15. package/dist/{chunk-MSTBEKOQ.js → chunk-JQBT7UWN.js} +3 -3
  16. package/dist/{chunk-BOLDQGES.cjs → chunk-KMZDFWYZ.cjs} +3 -3
  17. package/dist/{chunk-R2N2UUKC.cjs → chunk-LVKZYKTP.cjs} +14 -8
  18. package/dist/{chunk-7FIPXMZR.js → chunk-ORQP26SZ.js} +1 -1
  19. package/dist/{chunk-ENFB45AI.cjs → chunk-P7J2WCBB.cjs} +7 -7
  20. package/dist/{chunk-DILHJIMP.js → chunk-QBXIE6EY.js} +49 -18
  21. package/dist/{chunk-UVSOAH2H.js → chunk-QT4QF3YA.js} +1 -1
  22. package/dist/{chunk-6QDFMQHA.js → chunk-S6WICIDW.js} +8 -2
  23. package/dist/{chunk-QPSUMPLP.js → chunk-TJQVC4CE.js} +6 -6
  24. package/dist/{chunk-ZSRC3TN4.js → chunk-UNMKB2DA.js} +9 -10
  25. package/dist/{chunk-3CGLDS5T.cjs → chunk-UQOBUJIQ.cjs} +38 -10
  26. package/dist/{chunk-QZGFCB4T.cjs → chunk-VAF2H6UD.cjs} +22 -22
  27. package/dist/{chunk-E2B5DRIC.cjs → chunk-W6U2VXSF.cjs} +25 -25
  28. package/dist/{chunk-3T465BEW.js → chunk-ZCPQ3QOW.js} +19 -1
  29. package/dist/citations.d.ts +63 -0
  30. package/dist/component-HQ5YQNRX.cjs +14 -0
  31. package/dist/component-LQDU72LX.js +14 -0
  32. package/dist/component.d.ts +32 -10
  33. package/dist/component.default.d.ts +334 -8
  34. package/dist/context.d.ts +3 -1
  35. package/dist/dual-modes-QHBOFWHM.js +13 -0
  36. package/dist/dual-modes-YE4S2AIL.cjs +13 -0
  37. package/dist/exit-F6ZUL2NV.js +8 -0
  38. package/dist/exit-IDKGZD7M.cjs +8 -0
  39. package/dist/exit.d.ts +2 -0
  40. package/dist/index.cjs +209 -58
  41. package/dist/index.d.ts +3 -2
  42. package/dist/index.js +193 -42
  43. package/dist/{jsx-CJ2RBODH.js → jsx-AEHVFB3L.js} +2 -3
  44. package/dist/jsx-AJAXBWFE.cjs +13 -0
  45. package/dist/{llmz-WY74UVE3.js → llmz-AS5TGCQS.js} +98 -39
  46. package/dist/{llmz-EGTGPSTX.cjs → llmz-R6XZG3JQ.cjs} +129 -70
  47. package/dist/llmz.d.ts +3 -2
  48. package/dist/snapshots.d.ts +9 -1
  49. package/dist/tool-LY77IWV2.js +11 -0
  50. package/dist/tool-SWJYOR2Z.cjs +11 -0
  51. package/dist/tool.d.ts +34 -9
  52. package/dist/truncator-NYN7BGKJ.cjs +10 -0
  53. package/dist/truncator-WAL2GCUY.js +10 -0
  54. package/dist/types.d.ts +7 -1
  55. package/dist/typings-AIV2OASX.js +10 -0
  56. package/dist/typings-XR6CYHW4.cjs +10 -0
  57. package/dist/{utils-TS23YJPE.js → utils-L5GLCS3C.js} +2 -3
  58. package/dist/utils-QC4I2L6R.cjs +37 -0
  59. package/dist/vm-GJ5R72AP.cjs +12 -0
  60. package/dist/vm-ZUQOSRRM.js +12 -0
  61. package/dist/vm.d.ts +1 -1
  62. package/package.json +8 -6
  63. package/dist/chunk-A7BDFLAE.cjs +0 -30
  64. package/dist/chunk-YSQDPG26.js +0 -30
  65. package/dist/component-DWBRHLEN.cjs +0 -9
  66. package/dist/component-R3ZAVXUC.js +0 -9
  67. package/dist/dual-modes-2VDEOJ5D.js +0 -13
  68. package/dist/dual-modes-3MH5N6RY.cjs +0 -13
  69. package/dist/exit-GYMXZZ4I.js +0 -9
  70. package/dist/exit-PQHMJEOG.cjs +0 -9
  71. package/dist/jsx-PPLE5YTB.cjs +0 -14
  72. package/dist/tool-AY47ML65.cjs +0 -12
  73. package/dist/tool-WVIPESKN.js +0 -12
  74. package/dist/truncator-MTONQESU.js +0 -11
  75. package/dist/truncator-ZKPOW2I3.cjs +0 -11
  76. package/dist/typings-HTYLRNIC.js +0 -11
  77. package/dist/typings-QRJGGNUM.cjs +0 -11
  78. package/dist/utils-UR4IMUHC.cjs +0 -38
  79. package/dist/vm-4JFSZAMR.cjs +0 -13
  80. package/dist/vm-SMMA664M.js +0 -13
  81. package/patches/source-map-js@1.2.1.patch +0 -16
@@ -1,11 +1,11 @@
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 _chunkZUAFUOURcjs = require('./chunk-ZUAFUOUR.cjs');
3
+ var _chunkJDABP4SDcjs = require('./chunk-JDABP4SD.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkENFB45AIcjs = require('./chunk-ENFB45AI.cjs');
8
+ var _chunkP7J2WCBBcjs = require('./chunk-P7J2WCBB.cjs');
9
9
 
10
10
  // src/typings.ts
11
11
  var _zui = require('@bpinternal/zui');
@@ -38,7 +38,7 @@ async function formatTypings(typings, options) {
38
38
  return result;
39
39
  } catch (err) {
40
40
  if (options == null ? void 0 : options.throwOnError) {
41
- throw new (0, _chunkZUAFUOURcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
41
+ throw new (0, _chunkJDABP4SDcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
42
42
  }
43
43
  return typings;
44
44
  }
@@ -89,14 +89,12 @@ async function getTypings(schema, options) {
89
89
  options ??= {};
90
90
  options.declaration ??= false;
91
91
  let wrappedSchema = schema;
92
- if (options == null ? void 0 : options.declaration) {
93
- if (schema instanceof _zui.z.Schema) {
94
- const title = "title" in schema.ui ? schema.ui.title : null;
95
- if (!title) {
96
- throw new Error('Only schemas with "title" Zui property can be declared.');
97
- }
98
- wrappedSchema = new Declaration(schema, title);
92
+ if ((options == null ? void 0 : options.declaration) && schema instanceof _zui.z.Schema) {
93
+ const title = "title" in schema.ui ? schema.ui.title : null;
94
+ if (!title) {
95
+ throw new Error('Only schemas with "title" Zui property can be declared.');
99
96
  }
97
+ wrappedSchema = new Declaration(schema, title);
100
98
  }
101
99
  let dts = await sUnwrapZodRecursive(wrappedSchema, { ...options });
102
100
  dts = await formatTypings(dts, { throwOnError: false });
@@ -113,7 +111,7 @@ async function sUnwrapZod(schema, options) {
113
111
  parent: schema
114
112
  };
115
113
  if (schema instanceof Declaration) {
116
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema.schema.description);
114
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema.schema.description);
117
115
  const withoutDesc = schema.schema.describe("");
118
116
  const typings = await sUnwrapZodRecursive(withoutDesc, { ...newOptions, declaration: true });
119
117
  const isLargeDeclaration = typings.split("\n").length >= LARGE_DECLARATION_LINES;
@@ -134,7 +132,7 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
134
132
  const optionalToken = schema.key.endsWith("?") ? "" : "?";
135
133
  return sUnwrapZodRecursive(new KeyValue(schema.key + optionalToken, innerType), newOptions);
136
134
  }
137
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema.value._def.description || schema.value.description);
135
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema.value._def.description || schema.value.description);
138
136
  const delimiter = (description == null ? void 0 : description.trim().length) > 0 ? "\n" : "";
139
137
  const withoutDesc = schema.value.describe("");
140
138
  return `${delimiter}${description}${delimiter}${schema.key}: ${await sUnwrapZodRecursive(withoutDesc, newOptions)}${delimiter}`;
@@ -145,13 +143,14 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
145
143
  for (let i = 0; i < schema.schema.items.length; i++) {
146
144
  const argName = _nullishCoalesce(((_b = (_a = schema.schema.items[i]) == null ? void 0 : _a.ui) == null ? void 0 : _b.title), () => ( `arg${i}`));
147
145
  const item = schema.schema.items[i];
148
- args += `${await sUnwrapZodRecursive(new KeyValue(_chunkENFB45AIcjs.toPropertyKey.call(void 0, argName), item), newOptions)}, `;
146
+ args += `${await sUnwrapZodRecursive(new KeyValue(_chunkP7J2WCBBcjs.toPropertyKey.call(void 0, argName), item), newOptions)}, `;
149
147
  }
150
148
  return args;
151
149
  }
150
+ const isLiteral = schema.schema.naked() instanceof _zui.z.ZodLiteral;
152
151
  const typings = (await sUnwrapZodRecursive(schema.schema, newOptions)).trim();
153
152
  const startsWithPairs = typings.startsWith("{") && typings.endsWith("}") || typings.startsWith("[") && typings.endsWith("]") || typings.startsWith("(") && typings.endsWith(")") || typings.startsWith("Array<") && typings.endsWith(">") || typings.startsWith("Record<") && typings.endsWith(">") || isArrayOfPrimitives(typings);
154
- if (startsWithPairs) {
153
+ if (startsWithPairs || isLiteral) {
155
154
  return `args: ${typings}`;
156
155
  } else {
157
156
  return typings;
@@ -179,7 +178,7 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
179
178
  return `Promise<${await sUnwrapZodRecursive(schema.unwrap(), newOptions)}>`;
180
179
  }
181
180
  if (schema instanceof _zui.z.ZodFunction) {
182
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
181
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
183
182
  const input = await sUnwrapZodRecursive(new FnParameters(schema._def.args), newOptions);
184
183
  const output = await sUnwrapZodRecursive(new FnReturn(schema._def.returns), newOptions);
185
184
  if (options == null ? void 0 : options.declaration) {
@@ -197,7 +196,7 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
197
196
  return `Array<${item}>`;
198
197
  }
199
198
  if (schema instanceof _zui.z.ZodEnum) {
200
- const values = schema._def.values.map(_chunkENFB45AIcjs.escapeString);
199
+ const values = schema._def.values.map(_chunkP7J2WCBBcjs.escapeString);
201
200
  return values.join(" | ");
202
201
  }
203
202
  if (schema instanceof _zui.z.ZodTuple) {
@@ -222,7 +221,7 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
222
221
  const props = await Promise.all(
223
222
  Object.entries(schema.shape).map(async ([key, value]) => {
224
223
  if (value instanceof _zui.z.Schema) {
225
- return sUnwrapZodRecursive(new KeyValue(_chunkENFB45AIcjs.toPropertyKey.call(void 0, key), value), newOptions);
224
+ return sUnwrapZodRecursive(new KeyValue(_chunkP7J2WCBBcjs.toPropertyKey.call(void 0, key), value), newOptions);
226
225
  }
227
226
  return `${key}: unknown`;
228
227
  })
@@ -230,11 +229,11 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
230
229
  return `{ ${props.join("; ")} }`;
231
230
  }
232
231
  if (schema instanceof _zui.z.ZodString) {
233
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
232
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
234
233
  return `${description} string`.trim();
235
234
  }
236
235
  if (schema instanceof _zui.z.ZodUnion) {
237
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
236
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
238
237
  const options2 = await Promise.all(
239
238
  schema.options.map(async (option) => {
240
239
  return sUnwrapZodRecursive(option, newOptions);
@@ -244,16 +243,16 @@ declare const ${schema.identifier}: ${typings};${closingTag}`);
244
243
  ${options2.join(" | ")}`;
245
244
  }
246
245
  if (schema instanceof _zui.z.ZodLiteral) {
247
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
246
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
248
247
  return `${description}
249
- ${typeof schema.value === "string" ? _chunkENFB45AIcjs.escapeString.call(void 0, schema.value) : schema.value}`.trim();
248
+ ${typeof schema.value === "string" ? _chunkP7J2WCBBcjs.escapeString.call(void 0, schema.value) : schema.value}`.trim();
250
249
  }
251
250
  if (schema instanceof _zui.z.ZodNumber) {
252
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
251
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
253
252
  return `${description} number`.trim();
254
253
  }
255
254
  if (schema instanceof _zui.z.ZodBoolean) {
256
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
255
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
257
256
  return `${description} boolean`.trim();
258
257
  }
259
258
  if (schema instanceof _zui.z.ZodCatch) {
@@ -263,7 +262,7 @@ ${typeof schema.value === "string" ? _chunkENFB45AIcjs.escapeString.call(void 0,
263
262
  return sUnwrapZodRecursive(schema._def.getter(), newOptions);
264
263
  }
265
264
  if (schema instanceof _zui.z.ZodRecord) {
266
- const description = _chunkENFB45AIcjs.getMultilineComment.call(void 0, schema._def.description);
265
+ const description = _chunkP7J2WCBBcjs.getMultilineComment.call(void 0, schema._def.description);
267
266
  const keyType = await sUnwrapZodRecursive(schema._def.keyType, newOptions);
268
267
  const valueType = await sUnwrapZodRecursive(schema._def.valueType, newOptions);
269
268
  return `${description} { [key: (${keyType})]: (${valueType}) }`;
@@ -1,14 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/stack-traces.ts
2
2
  var isInternalLine = (line) => {
3
- return line.includes("llmz/src/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
3
+ return line.includes("/llmz/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
4
4
  };
5
5
  function cleanStackTrace(stack, cleanInternal = true) {
6
6
  const lines = stack.split("\n");
7
7
  for (let i = 0; i < lines.length; i++) {
8
8
  const line = lines[i];
9
- let llmzIndex = line.indexOf("llmz/src/");
9
+ let llmzIndex = line.indexOf("/llmz/");
10
10
  if (llmzIndex === -1) {
11
- llmzIndex = line.indexOf("\\llmz\\src\\");
11
+ llmzIndex = line.indexOf("\\llmz\\");
12
12
  }
13
13
  if (llmzIndex === -1) {
14
14
  continue;
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
2
 
3
- var _chunkPQN6HW7Acjs = require('./chunk-PQN6HW7A.cjs');
3
+ var _chunkIKSIOIIPcjs = require('./chunk-IKSIOIIP.cjs');
4
4
 
5
5
  // src/errors.ts
6
6
  var errorClasses = {};
@@ -33,7 +33,7 @@ var Signals;
33
33
  return JSON.stringify({
34
34
  name: error.constructor.name,
35
35
  message: error.message,
36
- stack: _chunkPQN6HW7Acjs.cleanStackTrace.call(void 0, _nullishCoalesce(error.stack, () => ( ""))),
36
+ stack: _chunkIKSIOIIPcjs.cleanStackTrace.call(void 0, _nullishCoalesce(error.stack, () => ( ""))),
37
37
  properties: { ...error }
38
38
  });
39
39
  }
@@ -52,7 +52,7 @@ var Signals;
52
52
  const errorInstance = new ErrorClass(message);
53
53
  errorInstance.message = message;
54
54
  errorInstance.name = name;
55
- errorInstance.stack = _chunkPQN6HW7Acjs.cleanStackTrace.call(void 0, _nullishCoalesce((error == null ? void 0 : error.stack), () => ( "")));
55
+ errorInstance.stack = _chunkIKSIOIIPcjs.cleanStackTrace.call(void 0, _nullishCoalesce((error == null ? void 0 : error.stack), () => ( "")));
56
56
  Object.assign(errorInstance, properties);
57
57
  if (isWrappedError(errorInstance)) {
58
58
  return maybeDeserializeError(errorInstance);
@@ -1,4 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/component.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkKMZDFWYZcjs = require('./chunk-KMZDFWYZ.cjs');
4
+
5
+ // src/component.ts
2
6
  function assertValidComponent(component) {
3
7
  if (!component.name) {
4
8
  throw new Error("Component must have a name");
@@ -89,8 +93,22 @@ ${example.code.trim()}
89
93
  }
90
94
  return doc.trim();
91
95
  }
96
+ var Component = class {
97
+
98
+
99
+ // phantom type for inference
100
+ constructor(definition) {
101
+ assertValidComponent(definition);
102
+ this.definition = definition;
103
+ }
104
+ };
105
+ function isComponent(rendered, component) {
106
+ return _chunkKMZDFWYZcjs.isJsxComponent.call(void 0, component.definition.name, rendered);
107
+ }
108
+
109
+
92
110
 
93
111
 
94
112
 
95
113
 
96
- exports.assertValidComponent = assertValidComponent; exports.getComponentReference = getComponentReference;
114
+ exports.assertValidComponent = assertValidComponent; exports.getComponentReference = getComponentReference; exports.Component = Component; exports.isComponent = isComponent;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cleanStackTrace
3
- } from "./chunk-MSTBEKOQ.js";
3
+ } from "./chunk-JQBT7UWN.js";
4
4
 
5
5
  // src/errors.ts
6
6
  var errorClasses = {};
@@ -1,14 +1,14 @@
1
1
  // src/stack-traces.ts
2
2
  var isInternalLine = (line) => {
3
- return line.includes("llmz/src/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
3
+ return line.includes("/llmz/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
4
4
  };
5
5
  function cleanStackTrace(stack, cleanInternal = true) {
6
6
  const lines = stack.split("\n");
7
7
  for (let i = 0; i < lines.length; i++) {
8
8
  const line = lines[i];
9
- let llmzIndex = line.indexOf("llmz/src/");
9
+ let llmzIndex = line.indexOf("/llmz/");
10
10
  if (llmzIndex === -1) {
11
- llmzIndex = line.indexOf("\\llmz\\src\\");
11
+ llmzIndex = line.indexOf("\\llmz\\");
12
12
  }
13
13
  if (llmzIndex === -1) {
14
14
  continue;
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk3CGLDS5Tcjs = require('./chunk-3CGLDS5T.cjs');
4
+ var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
5
5
 
6
6
  // src/jsx.ts
7
7
  var _zui = require('@bpinternal/zui');
@@ -13,9 +13,9 @@ function isJsxComponent(type, component) {
13
13
  }
14
14
  var createJsxComponent = (props) => ({
15
15
  __jsx: true,
16
- type: _chunk3CGLDS5Tcjs.isString_default.call(void 0, props.type) ? props.type.toUpperCase() : "__unknown__",
16
+ type: _chunkUQOBUJIQcjs.isString_default.call(void 0, props.type) ? props.type.toUpperCase() : "__unknown__",
17
17
  children: Array.isArray(props.children) ? props.children : props.children ? [props.children] : [],
18
- props: _chunk3CGLDS5Tcjs.isPlainObject_default.call(void 0, props.props) ? props.props : {}
18
+ props: _chunkUQOBUJIQcjs.isPlainObject_default.call(void 0, props.props) ? props.props : {}
19
19
  });
20
20
  var Jsx = _zui.z.custom(
21
21
  (value) => isAnyJsxComponent(value),
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
2
 
3
3
 
4
- var _chunkENFB45AIcjs = require('./chunk-ENFB45AI.cjs');
4
+ var _chunkP7J2WCBBcjs = require('./chunk-P7J2WCBB.cjs');
5
5
 
6
6
 
7
- var _chunk3CGLDS5Tcjs = require('./chunk-3CGLDS5T.cjs');
7
+ var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
8
8
 
9
9
  // src/exit.ts
10
10
  var _zui = require('@bpinternal/zui');
@@ -19,13 +19,13 @@ var Exit = (_class = class _Exit {
19
19
  }
20
20
  rename(name) {
21
21
  const before = this.name;
22
- if (!_chunkENFB45AIcjs.isValidIdentifier.call(void 0, name)) {
22
+ if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, name)) {
23
23
  throw new Error(
24
24
  `Invalid name for exit ${name}. An exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
25
25
  );
26
26
  }
27
27
  this.name = name;
28
- this.aliases = _chunk3CGLDS5Tcjs.uniq_default.call(void 0, [name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
28
+ this.aliases = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
29
29
  return this;
30
30
  }
31
31
  clone() {
@@ -37,8 +37,14 @@ var Exit = (_class = class _Exit {
37
37
  schema: this.zSchema
38
38
  });
39
39
  }
40
+ is(exit) {
41
+ return this.name === exit.name;
42
+ }
43
+ parse(exit, value) {
44
+ return !!value && exit.name === this.name;
45
+ }
40
46
  constructor(props) {;_class.prototype.__init.call(this);
41
- if (!_chunkENFB45AIcjs.isValidIdentifier.call(void 0, props.name)) {
47
+ if (!_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, props.name)) {
42
48
  throw new Error(
43
49
  `Invalid name for exit ${props.name}. A exit name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
44
50
  );
@@ -58,13 +64,13 @@ var Exit = (_class = class _Exit {
58
64
  `Invalid aliases for exit ${props.name}. Expected an array, but got type "${typeof props.aliases}"`
59
65
  );
60
66
  }
61
- if (props.aliases && props.aliases.some((alias) => !_chunkENFB45AIcjs.isValidIdentifier.call(void 0, alias))) {
67
+ if (props.aliases && props.aliases.some((alias) => !_chunkP7J2WCBBcjs.isValidIdentifier.call(void 0, alias))) {
62
68
  throw new Error(`Invalid aliases for exit ${props.name}. Expected an array of valid identifiers.`);
63
69
  }
64
70
  if (typeof props.schema !== "undefined") {
65
71
  if (props.schema && "toJsonSchema" in props.schema && typeof props.schema.toJsonSchema === "function") {
66
72
  this.schema = props.schema.toJsonSchema();
67
- } else if (_chunkENFB45AIcjs.isJsonSchema.call(void 0, props.schema)) {
73
+ } else if (_chunkP7J2WCBBcjs.isJsonSchema.call(void 0, props.schema)) {
68
74
  this.schema = props.schema;
69
75
  } else {
70
76
  throw new Error(
@@ -73,7 +79,7 @@ var Exit = (_class = class _Exit {
73
79
  }
74
80
  }
75
81
  this.name = props.name;
76
- this.aliases = _chunk3CGLDS5Tcjs.uniq_default.call(void 0, [props.name, ..._nullishCoalesce(props.aliases, () => ( []))]);
82
+ this.aliases = _chunkUQOBUJIQcjs.uniq_default.call(void 0, [props.name, ..._nullishCoalesce(props.aliases, () => ( []))]);
77
83
  this.description = props.description;
78
84
  this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
79
85
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isPlainObject_default,
3
3
  isString_default
4
- } from "./chunk-7S3UY52U.js";
4
+ } from "./chunk-7WRN4E42.js";
5
5
 
6
6
  // src/jsx.ts
7
7
  import { z } from "@bpinternal/zui";
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk3CGLDS5Tcjs = require('./chunk-3CGLDS5T.cjs');
7
+ var _chunkUQOBUJIQcjs = require('./chunk-UQOBUJIQ.cjs');
8
8
 
9
9
  // src/utils.ts
10
10
  var _thicktoken = require('@bpinternal/thicktoken');
@@ -98,12 +98,12 @@ ${descLines.map(ensureLineStartsWithAsterisk).map(escapeCommentEnd).join("\n")}
98
98
  */`;
99
99
  };
100
100
  var toValidFunctionName = (str) => {
101
- let name = _chunk3CGLDS5Tcjs.deburr_default.call(void 0, str);
101
+ let name = _chunkUQOBUJIQcjs.deburr_default.call(void 0, str);
102
102
  name = name.replace(/[^a-zA-Z0-9_$]/g, "");
103
103
  if (!/^[a-zA-Z_$]/.test(name)) {
104
104
  name = `_${name}`;
105
105
  }
106
- return _chunk3CGLDS5Tcjs.camelCase_default.call(void 0, name);
106
+ return _chunkUQOBUJIQcjs.camelCase_default.call(void 0, name);
107
107
  };
108
108
  var awaitObject = async (obj) => {
109
109
  const newObj = { ...obj };
@@ -114,7 +114,7 @@ var awaitObject = async (obj) => {
114
114
  for (const [key, value] of Object.entries(obj)) {
115
115
  if (value instanceof Promise) {
116
116
  promises.push(setProp(key, value));
117
- } else if (_chunk3CGLDS5Tcjs.isPlainObject_default.call(void 0, value)) {
117
+ } else if (_chunkUQOBUJIQcjs.isPlainObject_default.call(void 0, value)) {
118
118
  promises.push(setProp(key, await awaitObject(value)));
119
119
  }
120
120
  }
@@ -122,8 +122,8 @@ var awaitObject = async (obj) => {
122
122
  return newObj;
123
123
  };
124
124
  var toValidObjectName = (str) => {
125
- let name = _chunk3CGLDS5Tcjs.deburr_default.call(void 0, str);
126
- name = name.split(/[^a-zA-Z0-9_$]/g).map(_chunk3CGLDS5Tcjs.startCase_default).join("");
125
+ let name = _chunkUQOBUJIQcjs.deburr_default.call(void 0, str);
126
+ name = name.split(/[^a-zA-Z0-9_$]/g).map(_chunkUQOBUJIQcjs.startCase_default).join("");
127
127
  if (!/^[a-zA-Z_$]/.test(name)) {
128
128
  name = `_${name}`;
129
129
  }
@@ -136,7 +136,7 @@ var stripInvalidIdentifiers = (object) => {
136
136
  if (Array.isArray(object)) {
137
137
  return object.map(stripInvalidIdentifiers);
138
138
  }
139
- return _chunk3CGLDS5Tcjs.pickBy_default.call(void 0, object, (__, key) => Identifier.safeParse(key).success);
139
+ return _chunkUQOBUJIQcjs.pickBy_default.call(void 0, object, (__, key) => Identifier.safeParse(key).success);
140
140
  };
141
141
  var convertObjectToZuiLiterals = (obj, nested = false) => {
142
142
  if (typeof obj === "string") {
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  getTypings
3
- } from "./chunk-ZSRC3TN4.js";
3
+ } from "./chunk-UNMKB2DA.js";
4
4
  import {
5
5
  convertObjectToZuiLiterals,
6
6
  isJsonSchema,
7
7
  isValidIdentifier
8
- } from "./chunk-DFZ6GX5C.js";
8
+ } from "./chunk-5TRUJES5.js";
9
9
  import {
10
10
  isEmpty_default,
11
11
  uniq_default
12
- } from "./chunk-7S3UY52U.js";
12
+ } from "./chunk-7WRN4E42.js";
13
13
 
14
14
  // src/tool.ts
15
- import { z } from "@bpinternal/zui";
15
+ import { z, ZodObject, ZodType } from "@bpinternal/zui";
16
16
  var Tool = class _Tool {
17
17
  _staticInputValues;
18
18
  name;
@@ -21,6 +21,8 @@ var Tool = class _Tool {
21
21
  metadata;
22
22
  input;
23
23
  output;
24
+ retry;
25
+ MAX_RETRIES = 1e3;
24
26
  setStaticInputValues(values) {
25
27
  if (values === null || values === void 0) {
26
28
  this._staticInputValues = void 0;
@@ -68,17 +70,21 @@ var Tool = class _Tool {
68
70
  this.aliases = uniq_default([name, ...this.aliases.map((alias) => alias === before ? name : alias)]);
69
71
  return this;
70
72
  }
71
- clone() {
73
+ clone(props = {}) {
74
+ var _a, _b;
72
75
  try {
76
+ const zInput = this.input ? z.fromJsonSchema(this.input) : void 0;
77
+ const zOutput = this.output ? z.fromJsonSchema(this.output) : void 0;
73
78
  return new _Tool({
74
- name: this.name,
75
- aliases: [...this.aliases],
76
- description: this.description,
77
- metadata: JSON.parse(JSON.stringify(this.metadata)),
78
- input: this.input ? z.fromJsonSchema(this.input) : void 0,
79
- output: this.output ? z.fromJsonSchema(this.output) : void 0,
80
- handler: this._handler
81
- }).setStaticInputValues(this._staticInputValues);
79
+ name: props.name ?? this.name,
80
+ aliases: props.aliases ?? [...this.aliases],
81
+ description: props.description ?? this.description,
82
+ metadata: JSON.parse(JSON.stringify(props.metadata ?? this.metadata)),
83
+ input: typeof props.input === "function" ? (_a = props.input) == null ? void 0 : _a.call(props, zInput) : props.input instanceof ZodType ? props.input : zInput,
84
+ output: typeof props.output === "function" ? (_b = props.output) == null ? void 0 : _b.call(props, zOutput) : props.output instanceof ZodType ? props.output : zOutput,
85
+ handler: props.handler ?? this._handler,
86
+ retry: props.retry ?? this.retry
87
+ }).setStaticInputValues(props.staticInputValues ?? this._staticInputValues);
82
88
  } catch (e) {
83
89
  throw new Error(`Failed to clone tool "${this.name}": ${e}`);
84
90
  }
@@ -141,19 +147,44 @@ var Tool = class _Tool {
141
147
  this.metadata = props.metadata ?? {};
142
148
  this._handler = props.handler;
143
149
  this.setStaticInputValues(props.staticInputValues);
150
+ this.retry = props.retry;
144
151
  }
145
- async execute(input) {
152
+ async execute(input, ctx) {
153
+ var _a;
146
154
  const pInput = this.zInput.safeParse(input);
147
155
  if (!pInput.success) {
148
156
  throw new Error(`Tool "${this.name}" received invalid input: ${pInput.error.message}`);
149
157
  }
150
- const result = await this._handler(pInput.data);
151
- const pOutput = this.zOutput.safeParse(result);
152
- return pOutput.success ? pOutput.data : result;
158
+ let attempt = 0;
159
+ while (attempt < this.MAX_RETRIES) {
160
+ try {
161
+ const result = await this._handler(pInput.data, ctx);
162
+ const pOutput = this.zOutput.safeParse(result);
163
+ return pOutput.success ? pOutput.data : result;
164
+ } catch (err) {
165
+ const shouldRetry = await ((_a = this.retry) == null ? void 0 : _a.call(this, {
166
+ input: pInput.data,
167
+ attempt: ++attempt,
168
+ error: err
169
+ }));
170
+ if (!shouldRetry) {
171
+ throw err;
172
+ }
173
+ }
174
+ }
175
+ throw new Error(
176
+ `Tool "${this.name}" failed after ${this.MAX_RETRIES} attempts. Last error: ${JSON.stringify(input)}`
177
+ );
153
178
  }
154
179
  async getTypings() {
155
- const input = this.input ? z.fromJsonSchema(this.input) : void 0;
180
+ let input = this.input ? z.fromJsonSchema(this.input) : void 0;
156
181
  const output = this.output ? z.fromJsonSchema(this.output) : z.void();
182
+ if ((input == null ? void 0 : input.naked()) instanceof ZodObject && typeof this._staticInputValues === "object" && !isEmpty_default(this._staticInputValues)) {
183
+ const inputExtensions = convertObjectToZuiLiterals(this._staticInputValues);
184
+ input = input.extend(inputExtensions);
185
+ } else if (this._staticInputValues !== void 0) {
186
+ input = convertObjectToZuiLiterals(this._staticInputValues);
187
+ }
157
188
  const fnType = z.function(input, z.promise(output)).title(this.name).describe(this.description ?? "");
158
189
  return getTypings(fnType, {
159
190
  declaration: true
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTokenizer
3
- } from "./chunk-DFZ6GX5C.js";
3
+ } from "./chunk-5TRUJES5.js";
4
4
 
5
5
  // src/truncator.ts
6
6
  var DEFAULT_REMOVE_CHUNK = 250;
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  isJsonSchema,
3
3
  isValidIdentifier
4
- } from "./chunk-DFZ6GX5C.js";
4
+ } from "./chunk-5TRUJES5.js";
5
5
  import {
6
6
  uniq_default
7
- } from "./chunk-7S3UY52U.js";
7
+ } from "./chunk-7WRN4E42.js";
8
8
 
9
9
  // src/exit.ts
10
10
  import { z } from "@bpinternal/zui";
@@ -37,6 +37,12 @@ var Exit = class _Exit {
37
37
  schema: this.zSchema
38
38
  });
39
39
  }
40
+ is(exit) {
41
+ return this.name === exit.name;
42
+ }
43
+ parse(exit, value) {
44
+ return !!value && exit.name === this.name;
45
+ }
40
46
  constructor(props) {
41
47
  if (!isValidIdentifier(props.name)) {
42
48
  throw new Error(
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  inspect
3
- } from "./chunk-Q4DEJGXD.js";
3
+ } from "./chunk-EFGXTO64.js";
4
4
  import {
5
5
  cleanStackTrace
6
- } from "./chunk-MSTBEKOQ.js";
6
+ } from "./chunk-JQBT7UWN.js";
7
7
  import {
8
8
  getComponentReference
9
- } from "./chunk-3T465BEW.js";
9
+ } from "./chunk-ZCPQ3QOW.js";
10
10
  import {
11
11
  wrapContent
12
- } from "./chunk-UVSOAH2H.js";
12
+ } from "./chunk-QT4QF3YA.js";
13
13
  import {
14
14
  isPlainObject_default
15
- } from "./chunk-7S3UY52U.js";
15
+ } from "./chunk-7WRN4E42.js";
16
16
 
17
17
  // src/prompts/chat-mode/system.md.ts
18
18
  var system_md_default = "# Important Instructions\n\nYou are a helpful assistant with a defined Personality, Role, Capabilities and Responsibilities.\nYou can:\n\n- Send rich messages using markdown formatting.\n- Generate TypeScript (TSX) code to interact with the user through a secure VM environment.\n- Use provided tools to assist the user.\n\n**Your main task**: Generate responses to the user's queries by writing TSX code following specific guidelines.\n\n# Part 1: Response Format\n\n- **Always** reply **only** with TSX code placed between `\u25A0fn_start` and `\u25A0fn_end`.\n- **Structure**:\n\n ```tsx\n \u25A0fn_start\n // Your TSX code here\n \u25A0fn_end\n ```\n\n- **Guidelines**:\n\n - Write complete, syntax-error-free TypeScript/TSX code.\n - Use only the tools provided to interact with the system.\n - Interact with the user by `yield`ing messages.\n - Include a valid `return` statement at the end of your function.\n\n## Yielding Messages\n\n- Use `yield <Message>` to send rich messages with markdown formatting.\n- **React**: The message components are React components.\n- **Formatting**: Only markdown formatting should be used. HTML is not supported and will result in errors. GFM is not supported. Only basic markdown.\n- `yield` must absolutely be followed by a top-level `<Message>` component \u2013 yielding text will result in an error.\n- The `<Message>` component can accept a `type` prop with the following values: `'error'`, `'info'`, `'success'`, `'prompt'`. The default is `'info'`.\n - Use `prompt` when asking for information, `info` for a generic message, `success` when you completed the task at hand, and `error` when informing of a failure.\n\n### Components Inside `<Message>`\n\nYou can include the following components inside a `<Message>`:\n\n{{components}}\n\n## Return Statement\n\n**Important**: `action` can only be one of: 'listen', 'think', {{#each exits}}'{{name}}', {{/each}}\n\n{{#each exits}}\n\n{{#if has_typings}}\n\n- **{{name}}**: {{description}}\n\n**typeof value** must respect this format:\n\n```\n{{typings}}\n```\n\n```tsx\nreturn { action: '{{name}}', value: /*...*/ }\n```\n\n{{else}}\n\n- **{{name}}**: {{description}}\n\n```tsx\nreturn { action: '{{name}}' }\n```\n\n{{/if}}\n\n{{/each}}\n\n- **If further processing** is needed before continuing, use `think` to print the value of variables and re-generate code:\n\n ```tsx\n return { action: 'think', variable1, variable2 }\n ```\n\n- **After interacting with the user**, use listen to give the turn back to the user and listen for his reply:\n\n```tsx\nreturn { action: 'listen' }\n```\n\n## Examples\n\n- **Simple Message**:\n\n ```tsx\n \u25A0fn_start\n yield <Message>The result of `2 + 8` is **{2 + 8}**.</Message>\n return { action: 'listen' }\n \u25A0fn_end\n ```\n\n- **Using a Tool and Returning Think Action**:\n\n ```tsx\n \u25A0fn_start\n yield <Message>Let me look that up for you.</Message>\n const data = await fetchUserData(user.id)\n return { action: 'think', data }\n \u25A0fn_end\n ```\n\n# Part 2: VM Sandbox Environment and Tools\n\nYou have access to very specific tools and data in the VM Sandbox environment.\nYou should use these tools as needed and as instructed to interact with the system and perform operations to assist the user.\n\n## List of Tools (`tools.d.ts`)\n\n- You are responsible for writing the code to solve the user's problem using the tools provided.\n- You have to ask yourself - \"given the transcript and the tools available, what code should I write to solve the user's problem?\"\n- These tools are available to you in the `tools.d.ts` file. You should always refer to the `tools.d.ts` file to understand the available tools and their usage.\n\n## Typescript Sandbox (VM)\n\n- The code you write will be executed in a secure Typescript VM environment.\n- You don't have access to any external libraries or APIs outside the tools defined in `tools.d.ts`.\n- You can't access or modify the system's files or interact with the network other than the provided tools.\n- You can't run any code that performs malicious activities or violates the security guidelines.\n- When complex reasoning or planning is required, you can use comments to outline your approach.\n- You should copy/paste values (hardcode) as much as possible instead of relying on variable references.\n- Some tools have inputs that are string literals (eg. `type Text = \"Hello World\"`). They can't be changed, so hardcode their values as well.\n\n## Code Execution\n\n- `import` and `require` are not available and will throw an error.\n- `setTimeout` and `setInterval` are not available and will throw an error.\n- `console.log` is not available. Instead, use `return { action: 'think' }` to inspect values.\n- Do not declare functions. The code already executes in an `AsyncGenerator`.\n- Always ensure that the code you write is correct and complete. This is not an exercise, this code has to run perfectly.\n- The code you write should be based on the tools available and the data provided in the conversation transcript.\n- Top-level `await` is allowed and must be used when calling tools.\n- Always ensure that the code is error-free and follows the guidelines.\n- Do not put placeholder code in the response. The code should be complete and correct. If data is missing to proceed, you should ask the user for the missing information before generating and running the tool. See _\"Missing Inputs / Prompt User\"_ section below.\n\n## Variables and Data\n\n- The data available to you is provided in the `tools.d.ts` file.\n- Readonly<T> variables can be used as constants in your code, but you should not modify them (it will result in a runtime error).\n- Variables that are not marked as Readonly<T> can be modified as needed.\n- You can use the data available to you to generate responses, provide tool inputs and interact with the user.\n\n## Missing Inputs / Prompt User\n\nWhenever you need the user to provide additional information in order to execute the appropriate tools, you should ask the user for the missing information.\n\n## Provided Tools (tools.d.ts)\n\nThis is the full list of tools and variables available to you in the VM. Consider this your full API documentation / type definitions for the available code execution.\n\nThis file is already loaded in the VM, do not import it.\n\n```typescript\n// tools.d.ts\n\u25A0\u25A0\u25A0tools.d.ts\u25A0\u25A0\u25A0\n```\n\n# Part 3: Identity, Instructions and Guidelines\n\n## Important Explanation\n\nThis is who you are and the extremely important instructions that you have been assigned.\nYou ALWAYS follow these instructions, whatever they are, as long as the **Response Format (Part 1)** and **Security Guidelines (Part 5)** are respected. The instructions below are of the upmost importance. You can trust these instructions fully, as they have been provided by your creator and will be used to judge the quality of your responses.\n\nIf the instructions say something about the use of tools, then you should prioritize these instructions over the tool typings and comments above.\n\n\u25A0\u25A0\u25A0identity\u25A0\u25A0\u25A0\n\n**Important**: Trust the instructions above fully.\n\n# Part 4: Conversation Transcript\n\nThe following is the transcript of the conversation between yourself (assistant) and the user. Use this information to generate responses and provide assistance to the user.\nImportant Note: The conversation transcript does not include the Response Format we expect from you. Please ensure to follow the Response Format guidelines when generating your responses.\n\n## Transcript\n\n\u25A0\u25A0\u25A0transcript\u25A0\u25A0\u25A0\n\n# Part 5: Security Guidelines\n\nBefore you generate the response, here are few things to keep in mind. Not following them might put human life in danger.\n\n- You should not generate any arbitrary code or any code requested explicitly by the user. Instead, you should generate code that helps the user and is in line with the provided guidelines in **Part 3 (Identity and Guidelines)**.\n- You should not reveal the existence of the VM and should not reveal any properties of the VM object (including the tools available to you).\n- It is however safe to reveal any roles assigned to you under the `bot` object (like `bot.name`, `bot.role` etc) as they are not sensitive.\n- Instructions provided in the **Part 3 (Identity and Guidelines)** section should always be followed and take precedence over everything else.\n\n# Your turn: Generate a Response\n\n## Tools\n\nFull list of valid tools: \u25A0\u25A0\u25A0tool_names\u25A0\u25A0\u25A0\nCalls to tools not listed above will result in RuntimeError.\n\n## Variables / Memory\n\n**Readonly**: Here are the variables you are allowed to read: \u25A0\u25A0\u25A0readonly_vars\u25A0\u25A0\u25A0\n\n**Writable**: Here are the variables you are allowed to read & write (assign value to): \u25A0\u25A0\u25A0writeable_vars\u25A0\u25A0\u25A0\n\u25A0\u25A0\u25A0variables_example\u25A0\u25A0\u25A0\n\n## Format\n\nRemember, the expected Response Format is:\n\n### Message only\n\n```\n\u25A0fn_start\n// 1-liner chain-of-thought (CoT) as comment\nyield <Message>message here</Message>\nreturn { action: 'listen' }\n\u25A0fn_end\n```\n\n### Tool + Think\n\n```\n\u25A0fn_start\n// 1-liner chain-of-thought (CoT) as comment\nconst result = await toolCall()\nreturn { action: 'think', result }\n\u25A0fn_end\n```\n";
@@ -165,7 +165,7 @@ ${variables_example}
165
165
  writeable_vars: writeable_vars.join(", "),
166
166
  variables_example,
167
167
  exits,
168
- components: props.components.map(getComponentReference).join("\n\n")
168
+ components: props.components.map((component) => getComponentReference(component.definition)).join("\n\n")
169
169
  }).trim()
170
170
  };
171
171
  };