llmz 0.2.1 → 0.2.3

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 (62) hide show
  1. package/CLAUDE.md +0 -1
  2. package/dist/{chunk-WWZ2W4WR.cjs → chunk-3UZKLXAD.cjs} +410 -514
  3. package/dist/{chunk-HM5H556L.js → chunk-72ZWBNZV.js} +1 -1
  4. package/dist/{chunk-D6PU5YAS.cjs → chunk-DDSJTR6Q.cjs} +8 -7
  5. package/dist/{chunk-665O7CAN.js → chunk-GDJTKI7J.js} +5 -1
  6. package/dist/{chunk-YX27XM67.js → chunk-GLXADNTR.js} +13 -1
  7. package/dist/{chunk-FPLSJF4S.cjs → chunk-GOWPACSK.cjs} +15 -3
  8. package/dist/{chunk-XVVYNOTX.js → chunk-HB2G32AK.js} +3 -2
  9. package/dist/{chunk-YQT5G77W.cjs → chunk-HEAQAEFZ.cjs} +2 -2
  10. package/dist/{chunk-DD4AZSP5.cjs → chunk-HMMM32RG.cjs} +19 -15
  11. package/dist/{chunk-MY26EAOP.cjs → chunk-KG5E3UZZ.cjs} +20 -20
  12. package/dist/{chunk-YGKQEVQQ.cjs → chunk-OVRDJMZJ.cjs} +29 -37
  13. package/dist/{chunk-E5NHK3FS.js → chunk-OXEKAOVI.js} +6 -14
  14. package/dist/{chunk-ETYFOCWC.cjs → chunk-PZE6PIPG.cjs} +12 -11
  15. package/dist/chunk-RGUG3UMF.cjs +26 -0
  16. package/dist/{chunk-GC5IQDGV.js → chunk-TDALRNGL.js} +4 -3
  17. package/dist/chunk-UGHFNCPD.js +26 -0
  18. package/dist/{chunk-ZWUWCRHG.js → chunk-XMFQVARN.js} +5 -5
  19. package/dist/{chunk-DH35WO5G.js → chunk-YRS7KRKP.js} +401 -505
  20. package/dist/compiler/ast.d.ts +26 -0
  21. package/dist/compiler/compiler.d.ts +13 -11
  22. package/dist/compiler/plugins/line-tracking.d.ts +6 -4
  23. package/dist/compiler/plugins/replace-comment.d.ts +8 -4
  24. package/dist/compiler/plugins/return-async.d.ts +18 -4
  25. package/dist/compiler/plugins/track-tool-calls.d.ts +21 -4
  26. package/dist/compiler/plugins/variable-extraction.d.ts +9 -4
  27. package/dist/component.default.d.ts +13 -91
  28. package/dist/{dual-modes-RMF7V7ZQ.js → dual-modes-BYABHBDI.js} +3 -3
  29. package/dist/dual-modes-HO6RRIZ5.cjs +10 -0
  30. package/dist/emscripten-module.wasm +0 -0
  31. package/dist/{execute-LNUBLVMZ.js → execute-DSGJ2UNL.js} +9 -8
  32. package/dist/{execute-2AGZ5QUN.cjs → execute-MRZZ4AYY.cjs} +41 -40
  33. package/dist/exit-MX56VN2C.cjs +8 -0
  34. package/dist/{exit-VJATJTQI.js → exit-UQ3EUX5D.js} +2 -2
  35. package/dist/exit.d.ts +1 -1
  36. package/dist/index.cjs +210 -253
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.js +184 -227
  39. package/dist/index.workerd.js +17328 -0
  40. package/dist/prompts/chat-mode/system.md.d.ts +1 -1
  41. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  42. package/dist/prompts/worker-mode/user.md.d.ts +1 -1
  43. package/dist/quickjs-variant.d.ts +22 -0
  44. package/dist/quickjs-variant.workerd.d.ts +22 -0
  45. package/dist/{tool-HTAYKIA2.js → tool-KD7FL45V.js} +3 -3
  46. package/dist/{tool-V55GD2FS.cjs → tool-VE2YHIY2.cjs} +4 -4
  47. package/dist/{truncator-OZOBNYON.js → truncator-73RCL52Y.js} +2 -2
  48. package/dist/truncator-FZNLYSDL.cjs +12 -0
  49. package/dist/{typings-SCKZCAPN.js → typings-E2RROCLT.js} +2 -2
  50. package/dist/{typings-S6I6IPTG.cjs → typings-LQOBZXSO.cjs} +3 -3
  51. package/dist/typings-formatter.d.ts +19 -0
  52. package/dist/{utils-ZEZ66X6Q.js → utils-IATCUNKF.js} +5 -1
  53. package/dist/utils-ITB4NEL7.cjs +43 -0
  54. package/dist/utils.d.ts +18 -0
  55. package/dist/vm-6D3IIIU7.cjs +12 -0
  56. package/dist/{vm-44H4UKI2.js → vm-QO5FSGPN.js} +2 -1
  57. package/package.json +8 -14
  58. package/dist/dual-modes-ZZY6QPYT.cjs +0 -10
  59. package/dist/exit-LUJY7JIG.cjs +0 -8
  60. package/dist/truncator-7PGEGCHV.cjs +0 -12
  61. package/dist/utils-GLZVMRWO.cjs +0 -39
  62. package/dist/vm-A3OTQVIR.cjs +0 -11
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2; var _class3; var _class4;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2; var _class3; var _class4;
2
2
 
3
3
 
4
4
 
@@ -10,21 +10,28 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkMY26EAOPcjs = require('./chunk-MY26EAOP.cjs');
13
+ var _chunkKG5E3UZZcjs = require('./chunk-KG5E3UZZ.cjs');
14
14
 
15
15
 
16
16
 
17
17
 
18
18
 
19
19
 
20
- var _chunkYGKQEVQQcjs = require('./chunk-YGKQEVQQ.cjs');
20
+ var _chunkOVRDJMZJcjs = require('./chunk-OVRDJMZJ.cjs');
21
21
 
22
22
 
23
- var _chunkETYFOCWCcjs = require('./chunk-ETYFOCWC.cjs');
23
+ var _chunkRGUG3UMFcjs = require('./chunk-RGUG3UMF.cjs');
24
24
 
25
25
 
26
+ var _chunkPZE6PIPGcjs = require('./chunk-PZE6PIPG.cjs');
26
27
 
27
- var _chunkDD4AZSP5cjs = require('./chunk-DD4AZSP5.cjs');
28
+
29
+
30
+
31
+
32
+
33
+
34
+ var _chunkHMMM32RGcjs = require('./chunk-HMMM32RG.cjs');
28
35
 
29
36
 
30
37
 
@@ -34,7 +41,7 @@ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
34
41
  require('./chunk-KIN7Y247.cjs');
35
42
 
36
43
 
37
- var _chunkD6PU5YAScjs = require('./chunk-D6PU5YAS.cjs');
44
+ var _chunkDDSJTR6Qcjs = require('./chunk-DDSJTR6Q.cjs');
38
45
 
39
46
 
40
47
 
@@ -46,7 +53,7 @@ require('./chunk-5ZF6NTYI.cjs');
46
53
 
47
54
 
48
55
 
49
- var _chunkYQT5G77Wcjs = require('./chunk-YQT5G77W.cjs');
56
+ var _chunkHEAQAEFZcjs = require('./chunk-HEAQAEFZ.cjs');
50
57
 
51
58
 
52
59
 
@@ -55,238 +62,194 @@ var _chunkYQT5G77Wcjs = require('./chunk-YQT5G77W.cjs');
55
62
 
56
63
 
57
64
 
58
- var _chunkFPLSJF4Scjs = require('./chunk-FPLSJF4S.cjs');
59
65
 
66
+ var _chunkGOWPACSKcjs = require('./chunk-GOWPACSK.cjs');
60
67
 
61
68
 
62
69
  var _chunkHC2QZTVTcjs = require('./chunk-HC2QZTVT.cjs');
63
70
 
64
71
  // package.json
65
- var version = "0.2.1";
72
+ var version = "0.2.3";
66
73
 
67
74
  // src/objects.ts
68
75
  var _zui = require('@bpinternal/zui');
69
76
 
70
77
  // src/hoist.ts
71
- var _generator = require('@babel/generator');
72
- var _parser2 = require('@babel/parser');
73
- var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
74
- var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
75
- var traverse = _traverse2.default;
76
- function getTypingsWithoutComments(type) {
77
- const typeClone = _chunkHC2QZTVTcjs.cloneDeep_default.call(void 0, type);
78
- removeBabelComments(typeClone);
79
- return new (0, _generator.CodeGenerator)(typeClone, { comments: false }).generate().code;
78
+ function printNodes(nodes) {
79
+ let out = "";
80
+ let afterLineComment = false;
81
+ const emit = (n) => {
82
+ const newlines = Math.min(_nullishCoalesce(n.nl, () => ( 0)), 2);
83
+ if (newlines > 0) {
84
+ out += "\n".repeat(newlines);
85
+ } else if (afterLineComment) {
86
+ out += "\n";
87
+ } else if (out.length && !out.endsWith("\n")) {
88
+ out += " ";
89
+ }
90
+ afterLineComment = false;
91
+ if (_chunkHMMM32RGcjs.isGroup.call(void 0, n)) {
92
+ out += n.open;
93
+ for (const child of n.children) {
94
+ emit(child);
95
+ }
96
+ if (afterLineComment) {
97
+ out += "\n";
98
+ afterLineComment = false;
99
+ }
100
+ out += n.close;
101
+ } else {
102
+ out += n.text;
103
+ afterLineComment = n.kind === "line-comment";
104
+ }
105
+ };
106
+ for (const n of nodes) {
107
+ emit(n);
108
+ }
109
+ return out;
80
110
  }
81
- function removeBabelComments(node) {
82
- node.leadingComments = null;
83
- node.trailingComments = null;
84
- node.innerComments = null;
85
- Object.keys(node).forEach((key) => {
86
- const val = node[key];
87
- if (Array.isArray(val)) {
88
- val.forEach((child) => child && typeof child === "object" && removeBabelComments(child));
89
- } else if (val && typeof val === "object" && val.type) {
90
- removeBabelComments(val);
111
+ function keyOf(group) {
112
+ const parts = [];
113
+ const visit = (n) => {
114
+ if (_chunkHMMM32RGcjs.isGroup.call(void 0, n)) {
115
+ parts.push(n.open);
116
+ n.children.forEach(visit);
117
+ parts.push(n.close);
118
+ } else if (n.kind === "word" || n.kind === "string" || n.kind === "punct" && n.text !== ";" && n.text !== ",") {
119
+ parts.push(n.text);
91
120
  }
92
- });
121
+ };
122
+ visit(group);
123
+ return parts.join(" ");
93
124
  }
94
- function extractAndHoistTypes(ast) {
95
- const typeMap = /* @__PURE__ */ new Map();
96
- const typeCounts = /* @__PURE__ */ new Map();
97
- const hoistedTypes = [];
98
- function addTypeToMap(typeNode) {
99
- const typeString = getTypingsWithoutComments(typeNode.typeAnnotation);
100
- if (!typeMap.has(typeString)) {
101
- typeMap.set(typeString, typeNode);
125
+ var prevMeaningful = (siblings, index) => {
126
+ for (let i = index - 1; i >= 0; i--) {
127
+ const n = siblings[i];
128
+ if (_chunkHMMM32RGcjs.isGroup.call(void 0, n) || n.kind !== "block-comment" && n.kind !== "line-comment") {
129
+ return n;
102
130
  }
103
131
  }
104
- function generateUniqueTypeName(baseName) {
105
- let typeName = baseName;
106
- let counter = 1;
107
- while ([...typeMap.values()].some((typeNode) => typeNode.id.name === typeName)) {
108
- typeName = `${baseName}${counter++}`;
109
- }
110
- return typeName;
111
- }
112
- function createTypeAlias(name, type) {
113
- return t.tsTypeAliasDeclaration(t.identifier(name), null, type);
114
- }
115
- function getTypePaths(path) {
116
- var _a, _b, _c;
117
- let currPath = path;
118
- const parts = /* @__PURE__ */ new Set();
119
- while (currPath) {
120
- const { node, parentPath } = currPath;
121
- if (t.isIdentifier(node) && node.name) {
122
- parts.add(node.name);
123
- }
124
- if (t.isTSMethodSignature(node) && currPath.key === "parameters") {
125
- parts.add("Input");
126
- }
127
- if (currPath.key === "returnType") {
128
- parts.add("Output");
129
- const methodName = "id" in parentPath.node && "name" in parentPath.node.id && ((_b = (_a = parentPath == null ? void 0 : parentPath.node) == null ? void 0 : _a.id) == null ? void 0 : _b.name);
130
- if (methodName) {
131
- parts.add(methodName);
132
- }
133
- }
134
- if (((_c = node == null ? void 0 : node.key) == null ? void 0 : _c.type) === "Identifier") {
135
- parts.add(node.key.name);
136
- }
137
- if (t.isTSParameterProperty(node) || t.isTSFunctionType(node)) {
138
- parts.add("Input");
139
- }
140
- if (t.isTSFunctionType(node)) {
141
- parts.add("Output");
142
- }
143
- currPath = parentPath;
132
+ return void 0;
133
+ };
134
+ var asName = (text) => _chunkHC2QZTVTcjs.upperFirst_default.call(void 0, text.replace(/['"]/g, "").replace(/[^A-Za-z0-9_$]/g, ""));
135
+ function segmentsAt(siblings, index) {
136
+ var _a;
137
+ const prev = prevMeaningful(siblings, index);
138
+ if (!prev || _chunkHMMM32RGcjs.isGroup.call(void 0, prev)) {
139
+ return [];
140
+ }
141
+ if (_chunkHMMM32RGcjs.isPunct.call(void 0, prev, "=>")) {
142
+ return ["Output"];
143
+ }
144
+ if (_chunkHMMM32RGcjs.isPunct.call(void 0, prev, ":") || _chunkHMMM32RGcjs.isPunct.call(void 0, prev, "<")) {
145
+ let i = siblings.indexOf(prev) - 1;
146
+ while (i >= 0 && !_chunkHMMM32RGcjs.isGroup.call(void 0, siblings[i]) && ((_a = siblings[i].kind) == null ? void 0 : _a.includes("comment"))) {
147
+ i--;
144
148
  }
145
- return parts.size ? Array.from(parts).reverse().map(_chunkHC2QZTVTcjs.upperFirst_default) : ["UnnamedType"];
146
- }
147
- function generateTypeName(path) {
148
- return getTypePaths(path).join("");
149
- }
150
- function findNestedTypes(path) {
151
- const node = path.node;
152
- if (t.isTSTypeLiteral(node)) {
153
- const typeString = getTypingsWithoutComments(node);
154
- typeCounts.set(typeString, (typeCounts.get(typeString) || 0) + 1);
155
- if (typeMap.has(typeString) && (typeCounts.get(typeString) || 0) > 1) {
156
- path.replaceWith(t.tsTypeReference(typeMap.get(typeString).id));
157
- } else if (!typeMap.has(typeString) && (typeCounts.get(typeString) || 0) > 1) {
158
- const typeName = generateUniqueTypeName(generateTypeName(path));
159
- const typeAlias = createTypeAlias(typeName, node);
160
- addTypeToMap(typeAlias);
161
- path.replaceWith(t.tsTypeReference(t.identifier(typeName)));
162
- }
163
- const members = path.get("members");
164
- const memberPaths = Array.isArray(members) ? members : [members];
165
- memberPaths.forEach((memberPath) => {
166
- findNestedTypes(memberPath);
167
- });
149
+ let q = siblings[i];
150
+ if (q && !_chunkHMMM32RGcjs.isGroup.call(void 0, q) && q.kind === "punct" && q.text === "?") {
151
+ q = siblings[--i];
168
152
  }
169
- if (t.isTSPropertySignature(node) && path.get("typeAnnotation")) {
170
- const annPath = path.get("typeAnnotation.typeAnnotation");
171
- if (annPath == null ? void 0 : annPath.node) {
172
- findNestedTypes(annPath);
173
- }
153
+ if (q && _chunkHMMM32RGcjs.isGroup.call(void 0, q) && q.open === "(") {
154
+ const fnWord = prevMeaningful(siblings, i);
155
+ return fnWord && !_chunkHMMM32RGcjs.isGroup.call(void 0, fnWord) && fnWord.kind === "word" ? [asName(fnWord.text), "Output"] : ["Output"];
174
156
  }
175
- if (t.isTSArrayType(node)) {
176
- findNestedTypes(path.get("elementType"));
157
+ if (q && !_chunkHMMM32RGcjs.isGroup.call(void 0, q) && (q.kind === "word" || q.kind === "string")) {
158
+ return [asName(q.text)];
177
159
  }
178
- if (t.isTSUnionType(node) || t.isTSIntersectionType(node)) {
179
- ;
180
- path.get("types").forEach((p) => findNestedTypes(p));
160
+ }
161
+ return [];
162
+ }
163
+ function walkLiterals(siblings, path, visit) {
164
+ var _a;
165
+ for (let i = 0; i < siblings.length; i++) {
166
+ const node = siblings[i];
167
+ if (!_chunkHMMM32RGcjs.isGroup.call(void 0, node)) {
168
+ continue;
181
169
  }
182
- if (t.isTSTypeReference(node) && node.typeParameters) {
183
- ;
184
- path.get("typeParameters.params").forEach((param) => findNestedTypes(param));
170
+ if (node.open === "(") {
171
+ const fnWord = prevMeaningful(siblings, i);
172
+ const fnName = fnWord && !_chunkHMMM32RGcjs.isGroup.call(void 0, fnWord) && fnWord.kind === "word" ? [asName(fnWord.text)] : [];
173
+ walkLiterals(node.children, [...path, ...fnName], visit);
174
+ continue;
185
175
  }
186
- if (t.isTSFunctionType(node)) {
187
- const returnPath = path.get("typeAnnotation");
188
- if (returnPath == null ? void 0 : returnPath.node)
189
- findNestedTypes(returnPath);
190
- const params = path.get("parameters");
191
- params.forEach((paramPath) => {
192
- const ta = paramPath.get("typeAnnotation.typeAnnotation");
193
- if (ta == null ? void 0 : ta.node)
194
- findNestedTypes(ta);
195
- });
176
+ if (node.open === "<" || node.open === "[") {
177
+ walkLiterals(node.children, [...path, ...segmentsAt(siblings, i)], visit);
178
+ continue;
196
179
  }
197
- if (t.isTSMethodSignature(node)) {
198
- const returnPath = path.get("typeAnnotation");
199
- if (returnPath == null ? void 0 : returnPath.node) {
200
- findNestedTypes(returnPath);
180
+ const prev = prevMeaningful(siblings, i);
181
+ if (prev && _chunkHMMM32RGcjs.isPunct.call(void 0, prev, "=")) {
182
+ const eqIdx = siblings.indexOf(prev);
183
+ const nameTok = siblings[eqIdx - 1];
184
+ const typeTok = siblings[eqIdx - 2];
185
+ const isAlias = nameTok && typeTok && !_chunkHMMM32RGcjs.isGroup.call(void 0, nameTok) && !_chunkHMMM32RGcjs.isGroup.call(void 0, typeTok) && nameTok.kind === "word" && typeTok.kind === "word" && typeTok.text === "type";
186
+ if (!isAlias) {
187
+ continue;
188
+ }
189
+ const aliasName = nameTok.text;
190
+ visit({ siblings, index: i, group: node, path: [aliasName], aliasName });
191
+ if (siblings[i] === node) {
192
+ walkLiterals(node.children, [aliasName], visit);
201
193
  }
202
- const params = path.get("parameters");
203
- params.forEach((paramPath) => {
204
- const ta = paramPath.get("typeAnnotation.typeAnnotation");
205
- if (ta == null ? void 0 : ta.node)
206
- findNestedTypes(ta);
207
- });
194
+ continue;
195
+ }
196
+ const prevIsNamespace = prev && !_chunkHMMM32RGcjs.isGroup.call(void 0, prev) && prev.kind === "word" && ((_a = prevMeaningful(siblings, siblings.indexOf(prev))) == null ? void 0 : _a.kind) === "word";
197
+ const namespaceLike = prevIsNamespace && ["namespace", "module"].includes(prevMeaningful(siblings, siblings.indexOf(prev)).text);
198
+ const segments = segmentsAt(siblings, i);
199
+ const newPath = [...path, ...segments];
200
+ if (!namespaceLike) {
201
+ visit({ siblings, index: i, group: node, path: newPath });
208
202
  }
209
- if (t.isTSDeclareFunction(node)) {
210
- const params = path.get("params");
211
- params.forEach((p) => {
212
- const ta = p.get("typeAnnotation.typeAnnotation");
213
- if (ta == null ? void 0 : ta.node)
214
- findNestedTypes(ta);
215
- });
216
- const returnType = path.get("returnType.typeAnnotation");
217
- if (returnType == null ? void 0 : returnType.node)
218
- findNestedTypes(returnType);
203
+ if (siblings[i] === node) {
204
+ walkLiterals(node.children, namespaceLike ? [...path, asName(prev.text)] : newPath, visit);
219
205
  }
220
206
  }
221
- traverse(ast, {
222
- TSTypeAliasDeclaration(path) {
223
- const typeString = getTypingsWithoutComments(path.node.typeAnnotation);
224
- typeCounts.set(typeString, (typeCounts.get(typeString) || 0) + 1);
225
- if (typeMap.has(typeString) && (typeCounts.get(typeString) || 0) > 1) {
226
- const existing = typeMap.get(typeString);
227
- path.replaceWith(
228
- t.tsTypeAliasDeclaration(path.node.id, null, t.tsTypeReference(t.identifier(existing.id.name)))
229
- );
230
- } else {
231
- addTypeToMap(path.node);
232
- }
233
- },
234
- TSPropertySignature(path) {
235
- const annPath = path.get("typeAnnotation.typeAnnotation");
236
- if (annPath == null ? void 0 : annPath.node)
237
- findNestedTypes(annPath);
238
- },
239
- TSFunctionType(path) {
240
- const returnPath = path.get("typeAnnotation");
241
- if (returnPath.node)
242
- findNestedTypes(returnPath);
243
- const params = path.get("parameters");
244
- params.forEach((param) => {
245
- const ta = param.get("typeAnnotation.typeAnnotation");
246
- if (ta == null ? void 0 : ta.node)
247
- findNestedTypes(ta);
248
- });
249
- },
250
- TSMethodSignature(path) {
251
- const returnPath = path.get("typeAnnotation.typeAnnotation");
252
- if (returnPath == null ? void 0 : returnPath.node) {
253
- findNestedTypes(returnPath);
254
- }
255
- const params = path.get("parameters");
256
- params.forEach((param) => {
257
- const ta = param.get("typeAnnotation.typeAnnotation");
258
- if (ta == null ? void 0 : ta.node)
259
- findNestedTypes(ta);
260
- });
261
- },
262
- TSDeclareFunction(path) {
263
- const params = path.get("params");
264
- params.forEach((p) => {
265
- const ta = p.get("typeAnnotation.typeAnnotation");
266
- if (ta == null ? void 0 : ta.node)
267
- findNestedTypes(ta);
268
- });
269
- const returnPath = path.get("returnType.typeAnnotation");
270
- if (returnPath == null ? void 0 : returnPath.node)
271
- findNestedTypes(returnPath);
207
+ }
208
+ function extractAndHoistTypes(code) {
209
+ const top = _chunkHMMM32RGcjs.parse.call(void 0, _chunkHMMM32RGcjs.tokenize.call(void 0, code));
210
+ const counts = /* @__PURE__ */ new Map();
211
+ const aliasByKey = /* @__PURE__ */ new Map();
212
+ const usedNames = /* @__PURE__ */ new Set();
213
+ walkLiterals(top, [], ({ group, path, aliasName }) => {
214
+ const key = keyOf(group);
215
+ counts.set(key, (_nullishCoalesce(counts.get(key), () => ( 0))) + 1);
216
+ if (aliasName && !aliasByKey.has(key)) {
217
+ aliasByKey.set(key, aliasName);
218
+ }
219
+ for (const segment of path) {
220
+ usedNames.add(segment);
221
+ }
222
+ if (aliasName) {
223
+ usedNames.add(aliasName);
272
224
  }
273
225
  });
274
- typeMap.forEach((typeNode, typeString) => {
275
- if ((typeCounts.get(typeString) || 0) > 1) {
276
- if (!hoistedTypes.some((ht) => {
277
- return getTypingsWithoutComments(ht.typeAnnotation) === getTypingsWithoutComments(typeNode.typeAnnotation);
278
- })) {
279
- hoistedTypes.push(typeNode);
280
- }
226
+ const uniqueName = (base) => {
227
+ let name = base;
228
+ let counter = 1;
229
+ while (usedNames.has(name)) {
230
+ name = `${base}${counter++}`;
281
231
  }
232
+ usedNames.add(name);
233
+ return name;
234
+ };
235
+ const newAliases = [];
236
+ walkLiterals(top, [], ({ siblings, index, group, aliasName, path }) => {
237
+ const key = keyOf(group);
238
+ if ((_nullishCoalesce(counts.get(key), () => ( 0))) < 2 || aliasName) {
239
+ return;
240
+ }
241
+ let name = aliasByKey.get(key);
242
+ if (!name) {
243
+ const deduped = [...new Set(path)];
244
+ name = uniqueName(deduped.length ? deduped.join("") : "UnnamedType");
245
+ aliasByKey.set(key, name);
246
+ newAliases.push(`type ${name} = ${printNodes([{ ...group, nl: 0 }])}`);
247
+ }
248
+ siblings[index] = { kind: "word", text: name, nl: group.nl };
282
249
  });
283
- ast.program.body = [
284
- ...hoistedTypes,
285
- ...ast.program.body.filter(
286
- (node) => !hoistedTypes.some((ht) => t.isTSTypeAliasDeclaration(node) && node.id.name === ht.id.name)
287
- )
288
- ];
289
- return ast;
250
+ const body = printNodes(top);
251
+ return newAliases.length ? `${newAliases.join("\n")}
252
+ ${body}` : body;
290
253
  }
291
254
  async function hoistTypings(code, formatOptions) {
292
255
  formatOptions ??= {};
@@ -294,15 +257,7 @@ async function hoistTypings(code, formatOptions) {
294
257
  for (let i = 1; i <= 5; i++) {
295
258
  try {
296
259
  const initialCode = code;
297
- const ast = _parser2.parse.call(void 0, code, {
298
- sourceType: "module",
299
- plugins: ["typescript"]
300
- });
301
- const transformedAst = extractAndHoistTypes(ast);
302
- code = new (0, _generator.CodeGenerator)(transformedAst, {
303
- // quotes: 'single',
304
- compact: false
305
- }).generate().code;
260
+ code = extractAndHoistTypes(code);
306
261
  if (initialCode === code) {
307
262
  break;
308
263
  }
@@ -314,7 +269,7 @@ async function hoistTypings(code, formatOptions) {
314
269
  break;
315
270
  }
316
271
  }
317
- return _chunkDD4AZSP5cjs.formatTypings.call(void 0, code, formatOptions);
272
+ return _chunkHMMM32RGcjs.formatTypings.call(void 0, code, formatOptions);
318
273
  }
319
274
 
320
275
  // src/objects.ts
@@ -383,7 +338,7 @@ var ObjectInstance = class {
383
338
  */
384
339
  constructor(props) {
385
340
  var _a;
386
- if (!_chunkFPLSJF4Scjs.isValidIdentifier.call(void 0, props.name)) {
341
+ if (!_chunkGOWPACSKcjs.isValidIdentifier.call(void 0, props.name)) {
387
342
  throw new Error(
388
343
  `Invalid name for tool ${props.name}. A tool name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
389
344
  );
@@ -416,7 +371,7 @@ var ObjectInstance = class {
416
371
  if (props.properties.filter((p) => p.name === prop.name).length > 1) {
417
372
  throw new Error(`Duplicate property name "${prop.name}" in tool ${props.name}`);
418
373
  }
419
- if (!_chunkFPLSJF4Scjs.isValidIdentifier.call(void 0, prop.name)) {
374
+ if (!_chunkGOWPACSKcjs.isValidIdentifier.call(void 0, prop.name)) {
420
375
  throw new Error(
421
376
  `Invalid name for property ${prop.name}. A property name must start with a letter and contain only letters, numbers, and underscores. It must be 1-50 characters long.`
422
377
  );
@@ -440,7 +395,7 @@ var ObjectInstance = class {
440
395
  this.description = props.description;
441
396
  this.metadata = _nullishCoalesce(props.metadata, () => ( {}));
442
397
  this.properties = props.properties;
443
- this.tools = _chunkETYFOCWCcjs.Tool.withUniqueNames(_nullishCoalesce(props.tools, () => ( [])));
398
+ this.tools = _chunkPZE6PIPGcjs.Tool.withUniqueNames(_nullishCoalesce(props.tools, () => ( [])));
444
399
  }
445
400
  /**
446
401
  * Generates TypeScript namespace declarations for this object.
@@ -517,11 +472,11 @@ function getObjectTypings(obj) {
517
472
  for (const prop of _nullishCoalesce(obj.properties, () => ( []))) {
518
473
  const description = _nullishCoalesce(prop.description, () => ( ""));
519
474
  if (description == null ? void 0 : description.trim().length) {
520
- typings.push(_chunkFPLSJF4Scjs.getMultilineComment.call(void 0, description));
475
+ typings.push(_chunkGOWPACSKcjs.getMultilineComment.call(void 0, description));
521
476
  }
522
477
  let type = "unknown";
523
478
  if (prop.type) {
524
- type = await _chunkDD4AZSP5cjs.getTypings.call(void 0, prop.type, {});
479
+ type = await _chunkHMMM32RGcjs.getTypings.call(void 0, prop.type, {});
525
480
  } else if (prop.value !== void 0) {
526
481
  type = typeof prop.value;
527
482
  }
@@ -541,7 +496,7 @@ function getObjectTypings(obj) {
541
496
  typings.push("");
542
497
  for (const tool of obj.tools) {
543
498
  const fnType = _zui.z.function(tool.zInput, tool.zOutput).title(tool.name).describe(_nullishCoalesce(tool.description, () => ( "")));
544
- let temp = await _chunkDD4AZSP5cjs.getTypings.call(void 0, fnType, {
499
+ let temp = await _chunkHMMM32RGcjs.getTypings.call(void 0, fnType, {
545
500
  declaration: true
546
501
  });
547
502
  temp = temp.replace("declare function ", "function ");
@@ -562,9 +517,9 @@ function getObjectTypings(obj) {
562
517
  typings.push("}" + closingBracket);
563
518
  let header = "";
564
519
  if ((_a = obj.description) == null ? void 0 : _a.trim().length) {
565
- header = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, obj.description);
520
+ header = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, obj.description);
566
521
  }
567
- return _chunkDD4AZSP5cjs.formatTypings.call(void 0,
522
+ return _chunkHMMM32RGcjs.formatTypings.call(void 0,
568
523
  `${header}
569
524
  export namespace ${obj.name} {
570
525
  ${body}
@@ -595,7 +550,7 @@ function getObjectTypings(obj) {
595
550
  }
596
551
  function embedPropertyValue(property) {
597
552
  if (typeof property.value === "string") {
598
- return _chunkFPLSJF4Scjs.escapeString.call(void 0, property.value);
553
+ return _chunkGOWPACSKcjs.escapeString.call(void 0, property.value);
599
554
  }
600
555
  if (Number.isNaN(property.value)) {
601
556
  return "NaN";
@@ -613,7 +568,7 @@ function embedPropertyValue(property) {
613
568
  return `new Date('${property.value.toISOString()}')`;
614
569
  }
615
570
  if (property.value instanceof RegExp) {
616
- return `new RegExp(${_chunkFPLSJF4Scjs.escapeString.call(void 0, property.value.source)}, ${_chunkFPLSJF4Scjs.escapeString.call(void 0, property.value.flags)})`;
571
+ return `new RegExp(${_chunkGOWPACSKcjs.escapeString.call(void 0, property.value.source)}, ${_chunkGOWPACSKcjs.escapeString.call(void 0, property.value.flags)})`;
617
572
  }
618
573
  if (property.value === null) {
619
574
  return "null";
@@ -631,7 +586,7 @@ function embedPropertyValue(property) {
631
586
  return `${property.value}n`;
632
587
  }
633
588
  if (property.value instanceof Error) {
634
- return `Error(${_chunkFPLSJF4Scjs.escapeString.call(void 0, property.value.message)})`;
589
+ return `Error(${_chunkGOWPACSKcjs.escapeString.call(void 0, property.value.message)})`;
635
590
  }
636
591
  if (property.value instanceof Map) {
637
592
  return `new Map(${JSON.stringify(Array.from(property.value.entries()))})`;
@@ -1212,7 +1167,7 @@ var SendResponse = class extends BaseResponse {
1212
1167
  return this.item.props;
1213
1168
  }
1214
1169
  static formatToText(component, props, body) {
1215
- const header = `${_chunkYGKQEVQQcjs.MARKER}send=${component}${props && Object.keys(props).length ? ` ${JSON.stringify(props)}` : ""}`;
1170
+ const header = `${_chunkOVRDJMZJcjs.MARKER}send=${component}${props && Object.keys(props).length ? ` ${JSON.stringify(props)}` : ""}`;
1216
1171
  return body ? `${header}
1217
1172
  ${body}` : header;
1218
1173
  }
@@ -1223,7 +1178,7 @@ var RunResponse = class extends BaseResponse {
1223
1178
  this.code = code;
1224
1179
  }
1225
1180
  static formatToText(code) {
1226
- return `${_chunkYGKQEVQQcjs.MARKER}run
1181
+ return `${_chunkOVRDJMZJcjs.MARKER}run
1227
1182
  ${code}`;
1228
1183
  }
1229
1184
  };
@@ -1238,7 +1193,7 @@ var NextResponse = class extends BaseResponse {
1238
1193
  return this.item.props;
1239
1194
  }
1240
1195
  static formatToText(name, props) {
1241
- return `${_chunkYGKQEVQQcjs.MARKER}next=${name}${props && Object.keys(props).length ? ` ${JSON.stringify(props)}` : ""}`;
1196
+ return `${_chunkOVRDJMZJcjs.MARKER}next=${name}${props && Object.keys(props).length ? ` ${JSON.stringify(props)}` : ""}`;
1242
1197
  }
1243
1198
  };
1244
1199
  var EventPump = (_class3 = class {
@@ -1295,7 +1250,7 @@ function parseText(text, options) {
1295
1250
  );
1296
1251
  }
1297
1252
  async function* parseResponses(stream, options) {
1298
- const parser = new (0, _chunkYGKQEVQQcjs.StreamingMessageParser)(options);
1253
+ const parser = new (0, _chunkOVRDJMZJcjs.StreamingMessageParser)(options);
1299
1254
  const pump = new EventPump(stream, parser);
1300
1255
  let activeBody;
1301
1256
  while (true) {
@@ -1352,7 +1307,7 @@ var ComponentRegistry = (_class4 = class {
1352
1307
  }
1353
1308
  }
1354
1309
  register(definition) {
1355
- if (!_chunkYGKQEVQQcjs.NAME_REGEX.test(definition.name)) {
1310
+ if (!_chunkOVRDJMZJcjs.NAME_REGEX.test(definition.name)) {
1356
1311
  throw new Error(
1357
1312
  `Invalid component name "${definition.name}". Component names must be lowercase ([a-z][a-z0-9_-]*).`
1358
1313
  );
@@ -1379,7 +1334,7 @@ var EMPTY_PROPS_SCHEMA = { type: "object", properties: {}, additionalProperties:
1379
1334
  var normalizeComponentName = (name) => name.trim().toLowerCase();
1380
1335
  function normalizeComponentDefinition(definition) {
1381
1336
  const name = normalizeComponentName(_nullishCoalesce(definition.name, () => ( "")));
1382
- if (!_chunkYGKQEVQQcjs.NAME_REGEX.test(name)) {
1337
+ if (!_chunkOVRDJMZJcjs.NAME_REGEX.test(name)) {
1383
1338
  throw new Error(
1384
1339
  `Invalid component name "${definition.name}". Component names must be lowercase ([a-z][a-z0-9_-]*).`
1385
1340
  );
@@ -1400,14 +1355,14 @@ function normalizePropsSchema(props, name) {
1400
1355
  if (props === void 0) {
1401
1356
  return EMPTY_PROPS_SCHEMA;
1402
1357
  }
1403
- if (_chunkFPLSJF4Scjs.isZuiSchema.call(void 0, props)) {
1358
+ if (_chunkGOWPACSKcjs.isZuiSchema.call(void 0, props)) {
1404
1359
  try {
1405
1360
  return _zui.transforms.toJSONSchema(props);
1406
1361
  } catch (e2) {
1407
1362
  return _zui.transforms.toJSONSchemaLegacy(props);
1408
1363
  }
1409
1364
  }
1410
- if (_chunkFPLSJF4Scjs.isJsonSchema.call(void 0, props)) {
1365
+ if (_chunkGOWPACSKcjs.isJsonSchema.call(void 0, props)) {
1411
1366
  return props;
1412
1367
  }
1413
1368
  throw new Error(
@@ -1561,31 +1516,31 @@ var _checkValue = (value, schema, path, errors) => {
1561
1516
  };
1562
1517
 
1563
1518
  // src/message-stream/sanitize.ts
1564
- var sanitizeMessageText = (value, options = {}) => value.replaceAll(_chunkYGKQEVQQcjs.MARKER, _nullishCoalesce(options.markerReplacement, () => ( "\u25AA")));
1519
+ var sanitizeMessageText = (value, options = {}) => value.replaceAll(_chunkOVRDJMZJcjs.MARKER, _nullishCoalesce(options.markerReplacement, () => ( "\u25AA")));
1565
1520
 
1566
1521
  // src/index.ts
1567
1522
  var utils = {
1568
- toValidObjectName: _chunkFPLSJF4Scjs.toValidObjectName,
1569
- toValidFunctionName: _chunkFPLSJF4Scjs.toValidFunctionName,
1570
- wrapContent: _chunkYQT5G77Wcjs.wrapContent,
1571
- truncateWrappedContent: _chunkYQT5G77Wcjs.truncateWrappedContent,
1572
- stripTruncationTags: _chunkYQT5G77Wcjs.stripTruncationTags
1523
+ toValidObjectName: _chunkGOWPACSKcjs.toValidObjectName,
1524
+ toValidFunctionName: _chunkGOWPACSKcjs.toValidFunctionName,
1525
+ wrapContent: _chunkHEAQAEFZcjs.wrapContent,
1526
+ truncateWrappedContent: _chunkHEAQAEFZcjs.truncateWrappedContent,
1527
+ stripTruncationTags: _chunkHEAQAEFZcjs.stripTruncationTags
1573
1528
  };
1574
1529
  var execute = async (props) => {
1575
- const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-2AGZ5QUN.cjs")));
1530
+ const { executeContext } = await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-MRZZ4AYY.cjs")));
1576
1531
  return executeContext(props);
1577
1532
  };
1578
1533
  var init = async () => {
1579
- await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-2AGZ5QUN.cjs")));
1534
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./execute-MRZZ4AYY.cjs")));
1580
1535
  await Promise.resolve().then(() => _interopRequireWildcard(require("./component-2NYFY6CW.cjs")));
1581
- await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-V55GD2FS.cjs")));
1582
- await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-LUJY7JIG.cjs")));
1536
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./tool-VE2YHIY2.cjs")));
1537
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./exit-MX56VN2C.cjs")));
1583
1538
  await Promise.resolve().then(() => _interopRequireWildcard(require("./jsx-ULPWX5TW.cjs")));
1584
- await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-A3OTQVIR.cjs")));
1585
- await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-GLZVMRWO.cjs")));
1586
- await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-7PGEGCHV.cjs")));
1587
- await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-S6I6IPTG.cjs")));
1588
- await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-ZZY6QPYT.cjs")));
1539
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./vm-6D3IIIU7.cjs")));
1540
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./utils-ITB4NEL7.cjs")));
1541
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./truncator-FZNLYSDL.cjs")));
1542
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./typings-LQOBZXSO.cjs")));
1543
+ await Promise.resolve().then(() => _interopRequireWildcard(require("./dual-modes-HO6RRIZ5.cjs")));
1589
1544
  };
1590
1545
 
1591
1546
 
@@ -1636,4 +1591,6 @@ var init = async () => {
1636
1591
 
1637
1592
 
1638
1593
 
1639
- exports.BaseResponse = BaseResponse; exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkI56MPOVGcjs.Component; exports.ComponentRegistry = ComponentRegistry; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunkMY26EAOPcjs.DefaultExit; exports.ErrorExecutionResult = _chunkMY26EAOPcjs.ErrorExecutionResult; exports.ExecutionResult = _chunkMY26EAOPcjs.ExecutionResult; exports.Exit = _chunkD6PU5YAScjs.Exit; exports.ListenExit = _chunkMY26EAOPcjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.MARKER = _chunkYGKQEVQQcjs.MARKER; exports.NAME_REGEX = _chunkYGKQEVQQcjs.NAME_REGEX; exports.NextResponse = NextResponse; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunkMY26EAOPcjs.PartialExecutionResult; exports.ReplayableAsyncIterable = ReplayableAsyncIterable; exports.RunResponse = RunResponse; exports.SendResponse = SendResponse; exports.Snapshot = _chunkMY26EAOPcjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.StreamingMessageParser = _chunkYGKQEVQQcjs.StreamingMessageParser; exports.SuccessExecutionResult = _chunkMY26EAOPcjs.SuccessExecutionResult; exports.ThinkExit = _chunkMY26EAOPcjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkETYFOCWCcjs.Tool; exports._CustomModelClient = _chunkMY26EAOPcjs._CustomModelClient; exports.assertValidComponent = _chunkI56MPOVGcjs.assertValidComponent; exports.collectText = collectText; exports.execute = execute; exports.generateInstructions = _chunkYGKQEVQQcjs.generateInstructions; exports.getValue = _chunkMY26EAOPcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkI56MPOVGcjs.isAnyComponent; exports.isComponent = _chunkI56MPOVGcjs.isComponent; exports.normalizeComponentDefinition = normalizeComponentDefinition; exports.normalizeComponentName = normalizeComponentName; exports.normalizePropsSchema = normalizePropsSchema; exports.parseExit = _chunkMY26EAOPcjs.parseExit; exports.parseStream = parseStream; exports.parseText = parseText; exports.sanitizeMessageText = sanitizeMessageText; exports.tryParseJson = _chunkYGKQEVQQcjs.tryParseJson; exports.utils = utils; exports.validateComponent = validateComponent; exports.validateProps = validateProps; exports.version = version;
1594
+
1595
+
1596
+ exports.BaseResponse = BaseResponse; exports.Chat = Chat; exports.CitationsManager = CitationsManager; exports.Component = _chunkI56MPOVGcjs.Component; exports.ComponentRegistry = ComponentRegistry; exports.DefaultComponents = DefaultComponents; exports.DefaultExit = _chunkKG5E3UZZcjs.DefaultExit; exports.ErrorExecutionResult = _chunkKG5E3UZZcjs.ErrorExecutionResult; exports.ExecutionResult = _chunkKG5E3UZZcjs.ExecutionResult; exports.Exit = _chunkDDSJTR6Qcjs.Exit; exports.ListenExit = _chunkKG5E3UZZcjs.ListenExit; exports.LoopExceededError = _chunkPK72FAKDcjs.LoopExceededError; exports.MARKER = _chunkOVRDJMZJcjs.MARKER; exports.NAME_REGEX = _chunkOVRDJMZJcjs.NAME_REGEX; exports.NextResponse = NextResponse; exports.ObjectInstance = ObjectInstance; exports.PartialExecutionResult = _chunkKG5E3UZZcjs.PartialExecutionResult; exports.ReplayableAsyncIterable = ReplayableAsyncIterable; exports.RunResponse = RunResponse; exports.SendResponse = SendResponse; exports.Snapshot = _chunkKG5E3UZZcjs.Snapshot; exports.SnapshotSignal = _chunkPK72FAKDcjs.SnapshotSignal; exports.StreamingMessageParser = _chunkOVRDJMZJcjs.StreamingMessageParser; exports.SuccessExecutionResult = _chunkKG5E3UZZcjs.SuccessExecutionResult; exports.ThinkExit = _chunkKG5E3UZZcjs.ThinkExit; exports.ThinkSignal = _chunkPK72FAKDcjs.ThinkSignal; exports.Tool = _chunkPZE6PIPGcjs.Tool; exports._CustomModelClient = _chunkKG5E3UZZcjs._CustomModelClient; exports.assertValidComponent = _chunkI56MPOVGcjs.assertValidComponent; exports.collectText = collectText; exports.configureQuickJS = _chunkRGUG3UMFcjs.configureQuickJS; exports.configureTokenizer = _chunkGOWPACSKcjs.configureTokenizer; exports.execute = execute; exports.generateInstructions = _chunkOVRDJMZJcjs.generateInstructions; exports.getValue = _chunkKG5E3UZZcjs.getValue; exports.init = init; exports.isAnyComponent = _chunkI56MPOVGcjs.isAnyComponent; exports.isComponent = _chunkI56MPOVGcjs.isComponent; exports.normalizeComponentDefinition = normalizeComponentDefinition; exports.normalizeComponentName = normalizeComponentName; exports.normalizePropsSchema = normalizePropsSchema; exports.parseExit = _chunkKG5E3UZZcjs.parseExit; exports.parseStream = parseStream; exports.parseText = parseText; exports.sanitizeMessageText = sanitizeMessageText; exports.tryParseJson = _chunkOVRDJMZJcjs.tryParseJson; exports.utils = utils; exports.validateComponent = validateComponent; exports.validateProps = validateProps; exports.version = version;