llmz 0.1.5 → 0.2.1

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 (88) hide show
  1. package/README.md +185 -98
  2. package/dist/chat.d.ts +34 -0
  3. package/dist/chunk-665O7CAN.js +788 -0
  4. package/dist/chunk-DD4AZSP5.cjs +788 -0
  5. package/dist/{chunk-EFEF2AL7.js → chunk-DH35WO5G.js} +93 -556
  6. package/dist/chunk-E5NHK3FS.js +1637 -0
  7. package/dist/{chunk-WODK7Y4J.cjs → chunk-ETYFOCWC.cjs} +2 -2
  8. package/dist/{chunk-IRCB4FRM.js → chunk-GC5IQDGV.js} +1 -1
  9. package/dist/{chunk-L74UZONX.js → chunk-HM5H556L.js} +3 -1
  10. package/dist/chunk-I56MPOVG.cjs +62 -0
  11. package/dist/chunk-KWQTYXAT.js +62 -0
  12. package/dist/{chunk-C7T6OJB4.cjs → chunk-MY26EAOP.cjs} +146 -88
  13. package/dist/{chunk-JXD2KJVB.cjs → chunk-WWZ2W4WR.cjs} +103 -566
  14. package/dist/chunk-YGKQEVQQ.cjs +1637 -0
  15. package/dist/{chunk-ZPHRTTQX.cjs → chunk-YQT5G77W.cjs} +3 -1
  16. package/dist/{chunk-TIZWOIDF.js → chunk-ZWUWCRHG.js} +135 -77
  17. package/dist/compiler/compiler.d.ts +7 -2
  18. package/dist/compiler/index.d.ts +1 -1
  19. package/dist/compiler/plugins/async-wrapper.d.ts +11 -0
  20. package/dist/component-2NYFY6CW.cjs +14 -0
  21. package/dist/{component-2Z3KLWLX.js → component-ASNZHQUR.js} +3 -7
  22. package/dist/component.d.ts +3 -10
  23. package/dist/context.d.ts +88 -2
  24. package/dist/{dual-modes-HEXPFVUE.js → dual-modes-RMF7V7ZQ.js} +2 -4
  25. package/dist/dual-modes-ZZY6QPYT.cjs +10 -0
  26. package/dist/{execute-22PSGL7P.cjs → execute-2AGZ5QUN.cjs} +333 -89
  27. package/dist/{execute-ZENBZBWL.js → execute-LNUBLVMZ.js} +323 -79
  28. package/dist/formatting.d.ts +1 -2
  29. package/dist/index.cjs +511 -36
  30. package/dist/index.d.ts +8 -5
  31. package/dist/index.js +495 -20
  32. package/dist/message-stream/index.d.ts +9 -0
  33. package/dist/message-stream/instructions.d.ts +22 -0
  34. package/dist/message-stream/normalizer.d.ts +21 -0
  35. package/dist/message-stream/parser.d.ts +81 -0
  36. package/dist/message-stream/registry.d.ts +14 -0
  37. package/dist/message-stream/replayable.d.ts +27 -0
  38. package/dist/message-stream/sanitize.d.ts +10 -0
  39. package/dist/message-stream/stream.d.ts +54 -0
  40. package/dist/message-stream/types.d.ts +96 -0
  41. package/dist/message-stream/validator.d.ts +23 -0
  42. package/dist/message-stream/validator.test.d.ts +1 -0
  43. package/dist/prompts/chat-mode/system.md.d.ts +1 -1
  44. package/dist/prompts/chat-mode/user.md.d.ts +1 -1
  45. package/dist/prompts/common.d.ts +5 -5
  46. package/dist/prompts/prompt.d.ts +43 -6
  47. package/dist/prompts/protocol.d.ts +18 -0
  48. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  49. package/dist/prompts/worker-mode/user.md.d.ts +1 -1
  50. package/dist/result.d.ts +31 -0
  51. package/dist/runtime/execute.test.d.ts +1 -0
  52. package/dist/runtime/generate.d.ts +24 -1
  53. package/dist/runtime/interpret-result.d.ts +10 -0
  54. package/dist/runtime/types.d.ts +29 -4
  55. package/dist/{tool-DNHVW3KC.js → tool-HTAYKIA2.js} +2 -2
  56. package/dist/{tool-GJ6ZXWS2.cjs → tool-V55GD2FS.cjs} +3 -3
  57. package/dist/truncator-7PGEGCHV.cjs +12 -0
  58. package/dist/{truncator-3U2QUUJJ.js → truncator-OZOBNYON.js} +3 -1
  59. package/dist/truncator.d.ts +2 -0
  60. package/dist/types.d.ts +8 -1
  61. package/dist/{typings-ZTFPPA5W.cjs → typings-S6I6IPTG.cjs} +2 -2
  62. package/dist/{typings-3YV3RDMP.js → typings-SCKZCAPN.js} +1 -1
  63. package/dist/typings-formatter.d.ts +15 -0
  64. package/dist/typings-formatter.test.d.ts +1 -0
  65. package/dist/vm/drivers/quickjs.d.ts +2 -0
  66. package/dist/vm/index.d.ts +7 -0
  67. package/dist/vm/instrument.d.ts +1 -1
  68. package/dist/{vm-PYCKS77H.js → vm-44H4UKI2.js} +5 -4
  69. package/dist/{vm-VHB67FVH.cjs → vm-A3OTQVIR.cjs} +4 -3
  70. package/package.json +6 -7
  71. package/dist/chunk-2O3UTPVH.js +0 -813
  72. package/dist/chunk-3T5IU7OU.js +0 -186
  73. package/dist/chunk-7LMIOS6H.cjs +0 -287
  74. package/dist/chunk-BBX2LDZE.cjs +0 -813
  75. package/dist/chunk-CQ3UJW76.cjs +0 -186
  76. package/dist/chunk-TOGYDN6U.js +0 -287
  77. package/dist/compiler/plugins/async-iterator.d.ts +0 -6
  78. package/dist/compiler/plugins/braces-tsx.d.ts +0 -3
  79. package/dist/compiler/plugins/html-to-markdown.d.ts +0 -21
  80. package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +0 -5
  81. package/dist/compiler/plugins/jsx-undefined-vars.d.ts +0 -14
  82. package/dist/component-NNHBHD72.cjs +0 -18
  83. package/dist/dual-modes-LLIWZCHC.cjs +0 -12
  84. package/dist/truncator-3ZN7W6NB.cjs +0 -10
  85. /package/dist/{compiler/plugins/html-to-markdown.test.d.ts → message-stream/instructions.test.d.ts} +0 -0
  86. /package/dist/{compiler/plugins/jsx-undefined-vars.test.d.ts → message-stream/normalizer.test.d.ts} +0 -0
  87. /package/dist/{component.test.d.ts → message-stream/parser.test.d.ts} +0 -0
  88. /package/dist/{vm/vm-jsx.test.d.ts → message-stream/stream.test.d.ts} +0 -0
@@ -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(); } }
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(); } }
2
2
 
3
3
 
4
4
 
@@ -10,9 +10,6 @@ var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
10
10
  var _chunkKIN7Y247cjs = require('./chunk-KIN7Y247.cjs');
11
11
 
12
12
 
13
- var _chunk5ZF6NTYIcjs = require('./chunk-5ZF6NTYI.cjs');
14
-
15
-
16
13
 
17
14
 
18
15
 
@@ -1937,15 +1934,14 @@ var require_source_map = _chunkHC2QZTVTcjs.__commonJS.call(void 0, {
1937
1934
  var import_source_map_js = _chunkHC2QZTVTcjs.__toESM.call(void 0, require_source_map(), 1);
1938
1935
 
1939
1936
  // src/compiler/compiler.ts
1940
- var _plugintransformreactjsx = require('@babel/plugin-transform-react-jsx'); var _plugintransformreactjsx2 = _interopRequireDefault(_plugintransformreactjsx);
1941
1937
  var _standalone = require('@babel/standalone'); var Babel = _interopRequireWildcard(_standalone);
1942
1938
 
1943
- // src/compiler/plugins/async-iterator.ts
1944
- var Open = "async function* __fn__() {";
1939
+ // src/compiler/plugins/async-wrapper.ts
1940
+ var Open = "async function __fn__() {";
1945
1941
  var Close = "}";
1946
1942
  var USER_CODE_START_MARKER = "/* __LLMZ_USER_CODE_START__ */";
1947
1943
  var USER_CODE_END_MARKER = "/* __LLMZ_USER_CODE_END__ */";
1948
- var AsyncIterator = {
1944
+ var AsyncWrapper = {
1949
1945
  preProcessing: (code) => {
1950
1946
  return `"use strict";
1951
1947
  ${Open}
@@ -1963,445 +1959,10 @@ ${Close}
1963
1959
  }
1964
1960
  };
1965
1961
 
1966
- // src/compiler/plugins/braces-tsx.ts
1967
- var _parser = require('@babel/parser');
1968
- function fixTSXUntilNoErrors(rawCode, maxAttempts = 50) {
1969
- let code = rawCode;
1970
- for (let attempt = 0; attempt < maxAttempts; attempt++) {
1971
- try {
1972
- _parser.parse.call(void 0, code, {
1973
- sourceType: "module",
1974
- plugins: ["typescript", "jsx"]
1975
- });
1976
- return code;
1977
- } catch (err) {
1978
- if (err.code !== "BABEL_PARSER_SYNTAX_ERROR" || !err.loc) {
1979
- throw err;
1980
- }
1981
- const fixed = fixOneBraceProblemAt(code, err.loc);
1982
- if (!fixed) {
1983
- throw err;
1984
- }
1985
- code = fixed;
1986
- }
1987
- }
1988
- throw new Error("Hit maxAttempts while trying to fix TSX code");
1989
- }
1990
- function fixOneBraceProblemAt(code, loc) {
1991
- const lines = code.split("\n");
1992
- if (loc.line < 1 || loc.line > lines.length) {
1993
- return null;
1994
- }
1995
- const lineStr = lines[loc.line - 1];
1996
- if (loc.column < 0 || lineStr && loc.column > lineStr.length) {
1997
- return null;
1998
- }
1999
- const absIndex = lines.slice(0, loc.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + loc.column;
2000
- const braceIndex = findNearestBrace(code, absIndex);
2001
- if (braceIndex == null) {
2002
- return null;
2003
- }
2004
- const braceChar = code[braceIndex];
2005
- if (braceChar !== "{" && braceChar !== "}") {
2006
- return null;
2007
- }
2008
- const entity = braceChar === "{" ? "&#123;" : "&#125;";
2009
- return code.slice(0, braceIndex) + entity + code.slice(braceIndex + 1);
2010
- }
2011
- function findNearestBrace(code, startIndex) {
2012
- for (let i = startIndex; i >= 0; i--) {
2013
- if (code[i] === "{" || code[i] === "}") {
2014
- return i;
2015
- }
2016
- }
2017
- for (let i = startIndex; i < code.length; i++) {
2018
- if (code[i] === "{" || code[i] === "}") {
2019
- return i;
2020
- }
2021
- }
2022
- return null;
2023
- }
2024
- var HTML_ENTITIES = {
2025
- "{": "&#123;",
2026
- "}": "&#125;",
2027
- "<": "&lt;",
2028
- ">": "&gt;",
2029
- "&": "&amp;",
2030
- '"': "&quot;",
2031
- "'": "&#39;",
2032
- "`": "&#96;"
2033
- };
2034
- function escapeBracesInCodeFences(tsx) {
2035
- let i = 0;
2036
- let output = "";
2037
- let insideFencedBlock = false;
2038
- let jsxDepth = 0;
2039
- let braceDepth = 0;
2040
- while (i < tsx.length) {
2041
- const char = tsx[i];
2042
- if (char === "<" && !insideFencedBlock) {
2043
- if (tsx[i + 1] !== "/") {
2044
- jsxDepth++;
2045
- } else {
2046
- jsxDepth--;
2047
- }
2048
- output += char;
2049
- i++;
2050
- continue;
2051
- }
2052
- if (jsxDepth > 0 && !insideFencedBlock) {
2053
- if (char === "{") {
2054
- braceDepth++;
2055
- output += char;
2056
- i++;
2057
- continue;
2058
- } else if (char === "}") {
2059
- braceDepth--;
2060
- output += char;
2061
- i++;
2062
- continue;
2063
- }
2064
- }
2065
- if (tsx.startsWith("```", i)) {
2066
- insideFencedBlock = !insideFencedBlock;
2067
- output += "```";
2068
- i += 3;
2069
- continue;
2070
- }
2071
- if (jsxDepth > 0 && braceDepth === 0 && !insideFencedBlock && char === "`") {
2072
- const closingIndex = tsx.indexOf("`", i + 1);
2073
- if (closingIndex !== -1) {
2074
- const inlineCode = tsx.slice(i + 1, closingIndex);
2075
- let escaped = "`";
2076
- for (const c of inlineCode) {
2077
- escaped += HTML_ENTITIES[c] || c;
2078
- }
2079
- escaped += "`";
2080
- output += escaped;
2081
- i = closingIndex + 1;
2082
- continue;
2083
- }
2084
- }
2085
- if (insideFencedBlock && char in HTML_ENTITIES) {
2086
- output += HTML_ENTITIES[char];
2087
- i++;
2088
- continue;
2089
- }
2090
- output += char;
2091
- i++;
2092
- }
2093
- return output;
2094
- }
2095
- var JSXMarkdown = {
2096
- preProcessing: (code) => {
2097
- code = escapeBracesInCodeFences(code);
2098
- code = fixTSXUntilNoErrors(code);
2099
- return code;
2100
- }
2101
- };
2102
-
2103
- // src/compiler/plugins/html-to-markdown.ts
2104
- var _core = require('@babel/core');
2105
- function htmlToMarkdownPlugin() {
2106
- return {
2107
- name: "html-to-markdown",
2108
- visitor: {
2109
- JSXElement(path) {
2110
- const { openingElement } = path.node;
2111
- const tagName = _core.types.isJSXIdentifier(openingElement.name) ? openingElement.name.name : null;
2112
- if (!tagName)
2113
- return;
2114
- const lowerTagName = tagName.toLowerCase();
2115
- if (lowerTagName === "strong" || lowerTagName === "b") {
2116
- convertToMarkdown(path, "**", "**");
2117
- } else if (lowerTagName === "em" || lowerTagName === "i") {
2118
- convertToMarkdown(path, "*", "*");
2119
- } else if (lowerTagName === "u") {
2120
- convertToMarkdown(path, "__", "__");
2121
- } else if (lowerTagName === "a") {
2122
- convertLinkToMarkdown(path);
2123
- } else if (lowerTagName === "br") {
2124
- convertBrToNewline(path);
2125
- } else if (lowerTagName === "p") {
2126
- convertParagraphToMarkdown(path);
2127
- } else if (lowerTagName === "ul") {
2128
- convertUnorderedListToMarkdown(path);
2129
- } else if (lowerTagName === "ol") {
2130
- convertOrderedListToMarkdown(path);
2131
- }
2132
- }
2133
- }
2134
- };
2135
- }
2136
- function hasOnlyTextChildren(children) {
2137
- return children.every(
2138
- (child) => _core.types.isJSXText(child) || _core.types.isJSXExpressionContainer(child) && !_core.types.isJSXElement(child.expression) || _core.types.isJSXElement(child) && canConvertToMarkdown(child)
2139
- );
2140
- }
2141
- function canConvertToMarkdown(element) {
2142
- const { openingElement } = element;
2143
- const tagName = _core.types.isJSXIdentifier(openingElement.name) ? openingElement.name.name.toLowerCase() : null;
2144
- if (!tagName)
2145
- return false;
2146
- const allowedTags = ["strong", "b", "em", "i", "u", "br", "p", "a", "li", "ul", "ol"];
2147
- if (!allowedTags.includes(tagName))
2148
- return false;
2149
- if (tagName === "a") {
2150
- return openingElement.attributes.length === 1 && _core.types.isJSXAttribute(openingElement.attributes[0]) && _core.types.isJSXIdentifier(openingElement.attributes[0].name) && openingElement.attributes[0].name.name === "href";
2151
- }
2152
- if (tagName === "br") {
2153
- return openingElement.attributes.length === 0;
2154
- }
2155
- return openingElement.attributes.length === 0;
2156
- }
2157
- function convertToMarkdown(path, prefix, suffix) {
2158
- const element = path.node;
2159
- if (!canConvertToMarkdown(element))
2160
- return;
2161
- const children = element.children;
2162
- if (!hasOnlyTextChildren(children))
2163
- return;
2164
- const textContent = extractTextContent(children);
2165
- if (!textContent)
2166
- return;
2167
- const markdownText = `${prefix}${textContent}${suffix}`;
2168
- path.replaceWith(_core.types.jsxText(markdownText));
2169
- }
2170
- function convertLinkToMarkdown(path) {
2171
- const element = path.node;
2172
- if (!canConvertToMarkdown(element))
2173
- return;
2174
- const children = element.children;
2175
- if (!hasOnlyTextChildren(children))
2176
- return;
2177
- const hrefAttr = element.openingElement.attributes.find(
2178
- (attr) => _core.types.isJSXAttribute(attr) && _core.types.isJSXIdentifier(attr.name) && attr.name.name === "href"
2179
- );
2180
- if (!hrefAttr || !_core.types.isJSXAttribute(hrefAttr))
2181
- return;
2182
- let href = "";
2183
- if (_core.types.isStringLiteral(hrefAttr.value)) {
2184
- href = hrefAttr.value.value;
2185
- } else if (_core.types.isJSXExpressionContainer(hrefAttr.value) && _core.types.isStringLiteral(hrefAttr.value.expression)) {
2186
- href = hrefAttr.value.expression.value;
2187
- } else {
2188
- return;
2189
- }
2190
- const textContent = extractTextContent(children);
2191
- if (!textContent)
2192
- return;
2193
- const markdownText = `[${textContent}](${href})`;
2194
- path.replaceWith(_core.types.jsxText(markdownText));
2195
- }
2196
- function convertBrToNewline(path) {
2197
- const element = path.node;
2198
- if (!canConvertToMarkdown(element))
2199
- return;
2200
- path.replaceWith(_core.types.jsxText("\n"));
2201
- }
2202
- function convertParagraphToMarkdown(path) {
2203
- const element = path.node;
2204
- if (!canConvertToMarkdown(element))
2205
- return;
2206
- const children = element.children;
2207
- if (!hasOnlyTextChildren(children))
2208
- return;
2209
- const textContent = extractTextContent(children);
2210
- if (!textContent)
2211
- return;
2212
- const markdownText = `${textContent}
2213
-
2214
- `;
2215
- path.replaceWith(_core.types.jsxText(markdownText));
2216
- }
2217
- function convertUnorderedListToMarkdown(path) {
2218
- const element = path.node;
2219
- if (element.openingElement.attributes.length > 0)
2220
- return;
2221
- const children = element.children;
2222
- const listItems = [];
2223
- for (const child of children) {
2224
- if (_core.types.isJSXElement(child)) {
2225
- const tagName = _core.types.isJSXIdentifier(child.openingElement.name) ? child.openingElement.name.name : null;
2226
- if ((tagName == null ? void 0 : tagName.toLowerCase()) === "li" && canConvertToMarkdown(child)) {
2227
- const itemText = extractTextContent(child.children);
2228
- if (itemText) {
2229
- listItems.push(`- ${itemText}`);
2230
- }
2231
- } else {
2232
- return;
2233
- }
2234
- } else if (_core.types.isJSXText(child) && child.value.trim()) {
2235
- return;
2236
- }
2237
- }
2238
- if (listItems.length === 0)
2239
- return;
2240
- const markdownText = listItems.join("\n") + "\n";
2241
- path.replaceWith(_core.types.jsxText(markdownText));
2242
- }
2243
- function convertOrderedListToMarkdown(path) {
2244
- const element = path.node;
2245
- if (element.openingElement.attributes.length > 0)
2246
- return;
2247
- const children = element.children;
2248
- const listItems = [];
2249
- for (const child of children) {
2250
- if (_core.types.isJSXElement(child)) {
2251
- const tagName = _core.types.isJSXIdentifier(child.openingElement.name) ? child.openingElement.name.name : null;
2252
- if ((tagName == null ? void 0 : tagName.toLowerCase()) === "li" && canConvertToMarkdown(child)) {
2253
- const itemText = extractTextContent(child.children);
2254
- if (itemText) {
2255
- listItems.push(`${listItems.length + 1}. ${itemText}`);
2256
- }
2257
- } else {
2258
- return;
2259
- }
2260
- } else if (_core.types.isJSXText(child) && child.value.trim()) {
2261
- return;
2262
- }
2263
- }
2264
- if (listItems.length === 0)
2265
- return;
2266
- const markdownText = listItems.join("\n") + "\n";
2267
- path.replaceWith(_core.types.jsxText(markdownText));
2268
- }
2269
- function extractTextContent(children) {
2270
- let text = "";
2271
- for (const child of children) {
2272
- if (_core.types.isJSXText(child)) {
2273
- text += child.value;
2274
- } else if (_core.types.isJSXExpressionContainer(child)) {
2275
- return "";
2276
- } else if (_core.types.isJSXElement(child)) {
2277
- const nestedText = extractTextContent(child.children);
2278
- if (!nestedText)
2279
- return "";
2280
- const tagName = _core.types.isJSXIdentifier(child.openingElement.name) ? child.openingElement.name.name.toLowerCase() : null;
2281
- switch (tagName) {
2282
- case "strong":
2283
- case "b":
2284
- text += `**${nestedText}**`;
2285
- break;
2286
- case "em":
2287
- case "i":
2288
- text += `*${nestedText}*`;
2289
- break;
2290
- case "u":
2291
- text += `__${nestedText}__`;
2292
- break;
2293
- case "br":
2294
- text += "\n";
2295
- break;
2296
- default:
2297
- return "";
2298
- }
2299
- }
2300
- }
2301
- return text;
2302
- }
2303
-
2304
- // src/compiler/plugins/jsx-preserve-newlines.ts
2305
-
2306
-
2307
-
2308
-
2309
- var _types = require('@babel/types');
2310
- var preserveJSXNewLines = {
2311
- visitor: {
2312
- JSXText(path) {
2313
- const rawText = path.node.value;
2314
- const modifiedText = rawText.replace(/\n/g, "\n\u200B");
2315
- if (rawText !== modifiedText) {
2316
- path.replaceWith(_types.jsxText.call(void 0, modifiedText));
2317
- path.skip();
2318
- }
2319
- },
2320
- JSXOpeningElement(path) {
2321
- if (_types.isJSXIdentifier.call(void 0, path.node.name)) {
2322
- path.node.name = _types.jsxIdentifier.call(void 0, path.node.name.name.toLowerCase());
2323
- }
2324
- },
2325
- JSXClosingElement(path) {
2326
- if (_types.isJSXIdentifier.call(void 0, path.node.name)) {
2327
- path.node.name = _types.jsxIdentifier.call(void 0, path.node.name.name.toLowerCase());
2328
- }
2329
- }
2330
- }
2331
- };
2332
- var postProcessing = (code) => {
2333
- return code.replaceAll("\\u200B", "\\n");
2334
- };
2335
- var JSXNewLines = {
2336
- babelPlugin: preserveJSXNewLines,
2337
- postProcessing
2338
- };
2339
-
2340
- // src/compiler/plugins/jsx-undefined-vars.ts
2341
-
2342
- function jsxUndefinedVarsPlugin() {
2343
- return {
2344
- name: "jsx-undefined-vars",
2345
- visitor: {
2346
- JSXExpressionContainer(path) {
2347
- const expression = path.node.expression;
2348
- if (_core.types.isJSXEmptyExpression(expression)) {
2349
- return;
2350
- }
2351
- if (!_core.types.isIdentifier(expression)) {
2352
- return;
2353
- }
2354
- const varName = expression.name;
2355
- const knownGlobals = /* @__PURE__ */ new Set([
2356
- "undefined",
2357
- "null",
2358
- "true",
2359
- "false",
2360
- "NaN",
2361
- "Infinity",
2362
- "console",
2363
- "Math",
2364
- "JSON",
2365
- "Object",
2366
- "Array",
2367
- "String",
2368
- "Number",
2369
- "Boolean",
2370
- "Date",
2371
- "RegExp",
2372
- "Error",
2373
- "Promise",
2374
- "Symbol"
2375
- ]);
2376
- if (knownGlobals.has(varName)) {
2377
- return;
2378
- }
2379
- const iife = _core.types.callExpression(
2380
- _core.types.arrowFunctionExpression(
2381
- [],
2382
- _core.types.blockStatement([
2383
- _core.types.tryStatement(
2384
- _core.types.blockStatement([_core.types.returnStatement(_core.types.identifier(varName))]),
2385
- _core.types.catchClause(
2386
- null,
2387
- // no error binding needed
2388
- _core.types.blockStatement([_core.types.returnStatement(_core.types.stringLiteral(varName))])
2389
- )
2390
- )
2391
- ])
2392
- ),
2393
- []
2394
- );
2395
- path.node.expression = iife;
2396
- }
2397
- }
2398
- };
2399
- }
2400
-
2401
1962
  // src/compiler/plugins/line-tracking.ts
2402
-
1963
+ var _types = require('@babel/types');
2403
1964
  var LineTrackingFnIdentifier = "__track__";
2404
- var lineTrackingBabelPlugin = function({ types: t3 }) {
1965
+ var lineTrackingBabelPlugin = function({ types: t }) {
2405
1966
  return {
2406
1967
  visitor: {
2407
1968
  Program(path) {
@@ -2422,8 +1983,8 @@ var lineTrackingBabelPlugin = function({ types: t3 }) {
2422
1983
  console.error(e);
2423
1984
  }
2424
1985
  };
2425
- if (t3.isFunctionDeclaration(node) || t3.isClassMethod(node) || t3.isReturnStatement(node) || t3.isAwaitExpression(node) || t3.isForOfStatement(node) || t3.isCallExpression(node) || t3.isUnaryExpression(node) || t3.isVariableDeclaration(node) || t3.isBlockStatement(path2.parent) || t3.isAssignmentExpression(node)) {
2426
- if (!trackedLines.has(startLine) && !t3.isArrowFunctionExpression(path2.parent) && !t3.isObjectProperty(path2.parent) && !t3.isAwaitExpression(path2.parent) && !t3.isUnaryExpression(path2.parent) && !t3.isReturnStatement(path2.parent) && !t3.isForOfStatement(path2.parent) && !t3.isForStatement(path2.parent) && !t3.isForInStatement(path2.parent) && !t3.isVariableDeclaration(path2.parent) && !t3.isBinaryExpression(path2.parent) && !t3.isLogicalExpression(path2.parent)) {
1986
+ if (t.isFunctionDeclaration(node) || t.isClassMethod(node) || t.isReturnStatement(node) || t.isAwaitExpression(node) || t.isForOfStatement(node) || t.isCallExpression(node) || t.isUnaryExpression(node) || t.isVariableDeclaration(node) || t.isBlockStatement(path2.parent) || t.isAssignmentExpression(node)) {
1987
+ if (!trackedLines.has(startLine) && !t.isArrowFunctionExpression(path2.parent) && !t.isObjectProperty(path2.parent) && !t.isAwaitExpression(path2.parent) && !t.isUnaryExpression(path2.parent) && !t.isReturnStatement(path2.parent) && !t.isForOfStatement(path2.parent) && !t.isForStatement(path2.parent) && !t.isForInStatement(path2.parent) && !t.isVariableDeclaration(path2.parent) && !t.isBinaryExpression(path2.parent) && !t.isLogicalExpression(path2.parent)) {
2427
1988
  track();
2428
1989
  }
2429
1990
  }
@@ -2438,7 +1999,7 @@ var lineTrackingBabelPlugin = function({ types: t3 }) {
2438
1999
  // src/compiler/plugins/replace-comment.ts
2439
2000
  var CommentFnIdentifier = "__comment__";
2440
2001
  var replaceCommentBabelPlugin = function({
2441
- types: t3
2002
+ types: t
2442
2003
  }) {
2443
2004
  return {
2444
2005
  visitor: {
@@ -2457,13 +2018,13 @@ var replaceCommentBabelPlugin = function({
2457
2018
  return;
2458
2019
  }
2459
2020
  processed.add(comment.loc);
2460
- const commentCall = t3.expressionStatement(
2461
- t3.callExpression(t3.identifier(CommentFnIdentifier), [
2462
- t3.stringLiteral(comment.value.trim()),
2463
- t3.numericLiteral(_nullishCoalesce(((_a = comment.loc) == null ? void 0 : _a.start.line), () => ( 0)))
2021
+ const commentCall = t.expressionStatement(
2022
+ t.callExpression(t.identifier(CommentFnIdentifier), [
2023
+ t.stringLiteral(comment.value.trim()),
2024
+ t.numericLiteral(_nullishCoalesce(((_a = comment.loc) == null ? void 0 : _a.start.line), () => ( 0)))
2464
2025
  ])
2465
2026
  );
2466
- const isInsideObjectProperty = t3.isObjectProperty(node) || path2.findParent((path3) => t3.isObjectProperty(path3.node));
2027
+ const isInsideObjectProperty = t.isObjectProperty(node) || path2.findParent((path3) => t.isObjectProperty(path3.node));
2467
2028
  if (!isInsideObjectProperty) {
2468
2029
  insertMethod(commentCall);
2469
2030
  }
@@ -2482,7 +2043,7 @@ var replaceCommentBabelPlugin = function({
2482
2043
 
2483
2044
  // src/compiler/plugins/return-async.ts
2484
2045
  var instrumentLastLinePlugin = function({
2485
- types: t3
2046
+ types: t
2486
2047
  }) {
2487
2048
  return {
2488
2049
  visitor: {
@@ -2496,14 +2057,14 @@ var instrumentLastLinePlugin = function({
2496
2057
  return;
2497
2058
  }
2498
2059
  const lastStatement = statements[statements.length - 1];
2499
- if (t3.isReturnStatement(lastStatement)) {
2500
- if (t3.isExpression(lastStatement.argument)) {
2501
- lastStatement.argument = t3.awaitExpression(lastStatement.argument);
2060
+ if (t.isReturnStatement(lastStatement)) {
2061
+ if (t.isExpression(lastStatement.argument)) {
2062
+ lastStatement.argument = t.awaitExpression(lastStatement.argument);
2502
2063
  }
2503
2064
  return;
2504
2065
  }
2505
- if (t3.isExpressionStatement(lastStatement) && (t3.isCallExpression(lastStatement.expression) || t3.isAwaitExpression(lastStatement.expression))) {
2506
- const returnStatement3 = t3.returnStatement(t3.awaitExpression(lastStatement.expression));
2066
+ if (t.isExpressionStatement(lastStatement) && (t.isCallExpression(lastStatement.expression) || t.isAwaitExpression(lastStatement.expression))) {
2067
+ const returnStatement3 = t.returnStatement(t.awaitExpression(lastStatement.expression));
2507
2068
  (_b = path.get("body").get("body")[statements.length - 1]) == null ? void 0 : _b.replaceWith(returnStatement3);
2508
2069
  }
2509
2070
  }
@@ -2721,7 +2282,7 @@ var toolCallTrackingPlugin = (calls = /* @__PURE__ */ new Map()) => function({})
2721
2282
 
2722
2283
 
2723
2284
  var VariableTrackingFnIdentifier = "__var__";
2724
- var variableTrackingPlugin = (variables = /* @__PURE__ */ new Set()) => function({ types: t3 }) {
2285
+ var variableTrackingPlugin = (variables = /* @__PURE__ */ new Set()) => function({ types: t }) {
2725
2286
  let trackingStatements = [];
2726
2287
  const trackVariable = (variableName) => {
2727
2288
  if (variableName.startsWith("__")) {
@@ -2741,19 +2302,19 @@ var variableTrackingPlugin = (variables = /* @__PURE__ */ new Set()) => function
2741
2302
  visitor: {
2742
2303
  FunctionDeclaration(path) {
2743
2304
  path.node.params.forEach((param) => {
2744
- if (t3.isIdentifier(param)) {
2305
+ if (t.isIdentifier(param)) {
2745
2306
  trackVariable(param.name);
2746
- } else if (t3.isAssignmentPattern(param) && t3.isIdentifier(param.left)) {
2307
+ } else if (t.isAssignmentPattern(param) && t.isIdentifier(param.left)) {
2747
2308
  trackVariable(param.left.name);
2748
- } else if (t3.isObjectPattern(param)) {
2309
+ } else if (t.isObjectPattern(param)) {
2749
2310
  param.properties.forEach((prop) => {
2750
- if (t3.isObjectProperty(prop) && t3.isIdentifier(prop.value)) {
2311
+ if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
2751
2312
  trackVariable(prop.value.name);
2752
2313
  }
2753
2314
  });
2754
- } else if (t3.isArrayPattern(param)) {
2315
+ } else if (t.isArrayPattern(param)) {
2755
2316
  param.elements.forEach((element) => {
2756
- if (t3.isIdentifier(element)) {
2317
+ if (t.isIdentifier(element)) {
2757
2318
  trackVariable(element.name);
2758
2319
  }
2759
2320
  });
@@ -2766,19 +2327,19 @@ var variableTrackingPlugin = (variables = /* @__PURE__ */ new Set()) => function
2766
2327
  },
2767
2328
  ArrowFunctionExpression(path) {
2768
2329
  path.node.params.forEach((param) => {
2769
- if (t3.isIdentifier(param)) {
2330
+ if (t.isIdentifier(param)) {
2770
2331
  trackVariable(param.name);
2771
- } else if (t3.isAssignmentPattern(param) && t3.isIdentifier(param.left)) {
2332
+ } else if (t.isAssignmentPattern(param) && t.isIdentifier(param.left)) {
2772
2333
  trackVariable(param.left.name);
2773
- } else if (t3.isObjectPattern(param)) {
2334
+ } else if (t.isObjectPattern(param)) {
2774
2335
  param.properties.forEach((prop) => {
2775
- if (t3.isObjectProperty(prop) && t3.isIdentifier(prop.value)) {
2336
+ if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
2776
2337
  trackVariable(prop.value.name);
2777
2338
  }
2778
2339
  });
2779
- } else if (t3.isArrayPattern(param)) {
2340
+ } else if (t.isArrayPattern(param)) {
2780
2341
  param.elements.forEach((element) => {
2781
- if (t3.isIdentifier(element)) {
2342
+ if (t.isIdentifier(element)) {
2782
2343
  trackVariable(element.name);
2783
2344
  }
2784
2345
  });
@@ -2799,11 +2360,11 @@ var variableTrackingPlugin = (variables = /* @__PURE__ */ new Set()) => function
2799
2360
  const parent = path.parentPath;
2800
2361
  const handleObjectPattern = (pattern) => {
2801
2362
  pattern.properties.forEach((prop) => {
2802
- if (t3.isObjectProperty(prop) && t3.isIdentifier(prop.value)) {
2363
+ if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
2803
2364
  trackVariable(prop.value.name);
2804
- } else if (t3.isObjectProperty(prop) && t3.isObjectPattern(prop.value)) {
2365
+ } else if (t.isObjectProperty(prop) && t.isObjectPattern(prop.value)) {
2805
2366
  handleObjectPattern(prop.value);
2806
- } else if (t3.isObjectProperty(prop) && t3.isAssignmentPattern(prop.value) && t3.isIdentifier(prop.value.left)) {
2367
+ } else if (t.isObjectProperty(prop) && t.isAssignmentPattern(prop.value) && t.isIdentifier(prop.value.left)) {
2807
2368
  trackVariable(prop.value.left.name);
2808
2369
  }
2809
2370
  });
@@ -2812,19 +2373,19 @@ var variableTrackingPlugin = (variables = /* @__PURE__ */ new Set()) => function
2812
2373
  if (parent.isForXStatement() || parent.isForStatement()) {
2813
2374
  return;
2814
2375
  }
2815
- if (t3.isIdentifier(declarator.id)) {
2376
+ if (t.isIdentifier(declarator.id)) {
2816
2377
  trackVariable(declarator.id.name);
2817
2378
  }
2818
- if (t3.isObjectPattern(declarator.id)) {
2379
+ if (t.isObjectPattern(declarator.id)) {
2819
2380
  handleObjectPattern(declarator.id);
2820
2381
  }
2821
- if (t3.isArrayPattern(declarator.id)) {
2382
+ if (t.isArrayPattern(declarator.id)) {
2822
2383
  declarator.id.elements.forEach((element) => {
2823
- if (t3.isIdentifier(element)) {
2384
+ if (t.isIdentifier(element)) {
2824
2385
  trackVariable(element.name);
2825
- } else if (t3.isRestElement(element) && t3.isIdentifier(element.argument)) {
2386
+ } else if (t.isRestElement(element) && t.isIdentifier(element.argument)) {
2826
2387
  trackVariable(element.argument.name);
2827
- } else if (t3.isAssignmentPattern(element) && t3.isIdentifier(element.left)) {
2388
+ } else if (t.isAssignmentPattern(element) && t.isIdentifier(element.left)) {
2828
2389
  trackVariable(element.left.name);
2829
2390
  }
2830
2391
  });
@@ -2853,8 +2414,6 @@ var DEFAULT_TRANSFORM_OPTIONS = {
2853
2414
  retainLines: true
2854
2415
  };
2855
2416
  var Identifiers = {
2856
- JSXFnIdentifier: "__jsx__",
2857
- AsyncIterYieldFnIdentifier: "__async_iter_yield__",
2858
2417
  ConsoleObjIdentifier: "console",
2859
2418
  LineTrackingFnIdentifier,
2860
2419
  VariableTrackingFnIdentifier,
@@ -2862,32 +2421,43 @@ var Identifiers = {
2862
2421
  ToolTrackerRetIdentifier,
2863
2422
  CommentFnIdentifier
2864
2423
  };
2424
+ function hasTopLevelReturn(code) {
2425
+ let found = false;
2426
+ const detectTopLevelReturnPlugin = () => ({
2427
+ visitor: {
2428
+ ReturnStatement(path) {
2429
+ if (!path.getFunctionParent()) {
2430
+ found = true;
2431
+ }
2432
+ }
2433
+ }
2434
+ });
2435
+ try {
2436
+ Babel.transform(code, {
2437
+ parserOpts: {
2438
+ allowReturnOutsideFunction: true,
2439
+ allowAwaitOutsideFunction: true
2440
+ },
2441
+ presets: ["typescript"],
2442
+ plugins: [detectTopLevelReturnPlugin],
2443
+ filename: "<anonymous>.ts",
2444
+ code: false
2445
+ });
2446
+ } catch (e2) {
2447
+ return /\breturn\b/.test(code);
2448
+ }
2449
+ return found;
2450
+ }
2865
2451
  function compile(code) {
2866
- code = AsyncIterator.preProcessing(code);
2867
- code = JSXMarkdown.preProcessing(code);
2452
+ code = AsyncWrapper.preProcessing(code);
2868
2453
  let output = Babel.transform(code, {
2869
2454
  parserOpts: {
2870
2455
  allowReturnOutsideFunction: true,
2871
2456
  allowAwaitOutsideFunction: true
2872
2457
  },
2873
2458
  presets: ["typescript"],
2874
- plugins: [
2875
- JSXNewLines.babelPlugin,
2876
- htmlToMarkdownPlugin,
2877
- // Convert simple HTML to markdown first
2878
- jsxUndefinedVarsPlugin,
2879
- // Must run BEFORE JSX transform
2880
- [
2881
- _plugintransformreactjsx2.default,
2882
- {
2883
- throwIfNamespace: false,
2884
- runtime: "classic",
2885
- pragma: Identifiers.JSXFnIdentifier
2886
- }
2887
- ],
2888
- instrumentLastLinePlugin
2889
- ],
2890
- filename: "<anonymous>.tsx",
2459
+ plugins: [instrumentLastLinePlugin],
2460
+ filename: "<anonymous>.ts",
2891
2461
  sourceFileName: "<anonymous>",
2892
2462
  sourceMaps: true,
2893
2463
  minified: false,
@@ -2910,8 +2480,7 @@ function compile(code) {
2910
2480
  retainLines: true
2911
2481
  });
2912
2482
  let outputCode = output.code;
2913
- outputCode = AsyncIterator.postProcessing(outputCode);
2914
- outputCode = JSXNewLines.postProcessing(outputCode);
2483
+ outputCode = AsyncWrapper.postProcessing(outputCode);
2915
2484
  return {
2916
2485
  code: outputCode,
2917
2486
  codeWithMarkers,
@@ -2946,7 +2515,7 @@ var handleErrorQuickJS = (err, code, _consumer, traces, variables, lines_execute
2946
2515
  const stackTrace = err.stack || "";
2947
2516
  const LINE_OFFSET = 1;
2948
2517
  const regex = /<quickjs>:(\d+)/g;
2949
- const QUICKJS_WRAPPER_OFFSET = 10;
2518
+ const QUICKJS_WRAPPER_OFFSET = 9;
2950
2519
  const matches = Array.from(stackTrace.matchAll(regex)).map((x) => {
2951
2520
  const quickjsLine = Number(x[1]);
2952
2521
  const transformedCodeLine = quickjsLine - QUICKJS_WRAPPER_OFFSET;
@@ -3091,7 +2660,6 @@ var NO_TRACKING = [
3091
2660
  Identifiers.ToolCallTrackerFnIdentifier,
3092
2661
  Identifiers.ToolTrackerRetIdentifier,
3093
2662
  Identifiers.VariableTrackingFnIdentifier,
3094
- Identifiers.JSXFnIdentifier,
3095
2663
  Identifiers.ConsoleObjIdentifier
3096
2664
  ];
3097
2665
  function instrumentContext(context, transformed, traces, variables, lines_executed, consumer, userCodeStartLine) {
@@ -3108,7 +2676,6 @@ function instrumentContext(context, transformed, traces, variables, lines_execut
3108
2676
  const userCodeLine = Math.max(1, mappedLine - userCodeStartLine);
3109
2677
  lines_executed.set(userCodeLine, (_nullishCoalesce(lines_executed.get(userCodeLine), () => ( 0))) + 1);
3110
2678
  };
3111
- context[Identifiers.JSXFnIdentifier] = (tool, props, ...children) => _chunk5ZF6NTYIcjs.createJsxComponent.call(void 0, { type: tool, props, children });
3112
2679
  context[Identifiers.VariableTrackingFnIdentifier] = (name, getter) => {
3113
2680
  if (NO_TRACKING.includes(name)) {
3114
2681
  return;
@@ -3120,7 +2687,7 @@ function instrumentContext(context, transformed, traces, variables, lines_execut
3120
2687
  return "[[non-primitive]]";
3121
2688
  }
3122
2689
  return value;
3123
- } catch (e2) {
2690
+ } catch (e3) {
3124
2691
  return "[[non-primitive]]";
3125
2692
  }
3126
2693
  };
@@ -3141,21 +2708,6 @@ function instrumentContext(context, transformed, traces, variables, lines_execut
3141
2708
  traces.push({ type: "log", message, args, started_at: Date.now() });
3142
2709
  }
3143
2710
  };
3144
- context[Identifiers.AsyncIterYieldFnIdentifier] = async function(value) {
3145
- const startedAt = Date.now();
3146
- try {
3147
- if (typeof value.type !== "string" || value.type.trim().length === 0) {
3148
- throw new Error("A yield statement must yield a valid tool");
3149
- }
3150
- const toolName = Object.keys(context).find((x) => x.toUpperCase() === value.type.toUpperCase());
3151
- if (!toolName) {
3152
- throw new Error(`Yield tool "${value.type}", but tool is not found`);
3153
- }
3154
- await context[toolName](value);
3155
- } finally {
3156
- traces.push({ type: "yield", value, started_at: startedAt, ended_at: Date.now() });
3157
- }
3158
- };
3159
2711
  return state;
3160
2712
  }
3161
2713
  function findUserCodeStartLine(transformed) {
@@ -3175,7 +2727,7 @@ var NodeDriver = class {
3175
2727
  async execute(ctx) {
3176
2728
  const { transformed, consumer, context, traces, code, lines_executed, variables } = ctx;
3177
2729
  const state = instrumentContext(context, transformed, traces, variables, lines_executed, consumer, 0);
3178
- const AsyncFunction = async function* () {
2730
+ const AsyncFunction = async function() {
3179
2731
  }.constructor;
3180
2732
  return await (async () => {
3181
2733
  const descriptors = Object.getOwnPropertyDescriptors(context);
@@ -3192,14 +2744,7 @@ var NodeDriver = class {
3192
2744
  const assigner = `let __${Identifiers.LineTrackingFnIdentifier} = ${Identifiers.LineTrackingFnIdentifier}; ${Identifiers.LineTrackingFnIdentifier} = function(line) { ${reportAll}; __${Identifiers.LineTrackingFnIdentifier}(line);}`;
3193
2745
  const wrapper = `"use strict"; try { ${assigner};${transformed.code} } finally { ${reportAll} };`;
3194
2746
  const fn = AsyncFunction(...Object.keys(context), wrapper);
3195
- const res = fn(...Object.values(context));
3196
- do {
3197
- const { value, done } = await res.next();
3198
- if (done) {
3199
- return value;
3200
- }
3201
- await context[Identifiers.AsyncIterYieldFnIdentifier](value);
3202
- } while (true);
2747
+ return await fn(...Object.values(context));
3203
2748
  })().then((res) => {
3204
2749
  res = _chunkPK72FAKDcjs.Signals.maybeDeserializeError(res);
3205
2750
  return {
@@ -3218,6 +2763,8 @@ var NodeDriver = class {
3218
2763
 
3219
2764
 
3220
2765
  var _quickjsemscriptencore = require('quickjs-emscripten-core');
2766
+ var _quickJSModule;
2767
+ var loadQuickJSModule = () => _quickJSModule ??= _quickjsemscriptencore.newQuickJSWASMModuleFromVariant.call(void 0, BundledReleaseSyncVariant);
3221
2768
  var QuickJSDriver = class {
3222
2769
  async execute(ctx) {
3223
2770
  const { transformed, consumer, context, traces, signal, timeout, code, lines_executed, variables } = ctx;
@@ -3231,7 +2778,7 @@ var QuickJSDriver = class {
3231
2778
  consumer,
3232
2779
  userCodeStartLine
3233
2780
  );
3234
- const QuickJS = await _quickjsemscriptencore.newQuickJSWASMModuleFromVariant.call(void 0, BundledReleaseSyncVariant);
2781
+ const QuickJS = await loadQuickJSModule();
3235
2782
  const runtime = QuickJS.newRuntime();
3236
2783
  runtime.setMemoryLimit(128 * 1024 * 1024);
3237
2784
  const startTime = Date.now();
@@ -3333,9 +2880,9 @@ var QuickJSDriver = class {
3333
2880
  valueResult.unwrap().dispose();
3334
2881
  try {
3335
2882
  context[key] = vmValue;
3336
- } catch (e3) {
2883
+ } catch (e4) {
3337
2884
  }
3338
- } catch (e4) {
2885
+ } catch (e5) {
3339
2886
  }
3340
2887
  }
3341
2888
  };
@@ -3362,7 +2909,7 @@ var QuickJSDriver = class {
3362
2909
  if (errorValue !== null && errorValue !== "") {
3363
2910
  try {
3364
2911
  copyBackContextFromVM();
3365
- } catch (e5) {
2912
+ } catch (e6) {
3366
2913
  }
3367
2914
  const errorStackResult = vm.evalCode("globalThis.__llmz_error_stack");
3368
2915
  const errorStack = vm.dump(errorStackResult.unwrap()) || "";
@@ -3438,11 +2985,11 @@ var QuickJSDriver = class {
3438
2985
  } finally {
3439
2986
  try {
3440
2987
  vm.dispose();
3441
- } catch (e6) {
2988
+ } catch (e7) {
3442
2989
  }
3443
2990
  try {
3444
2991
  runtime.dispose();
3445
- } catch (e7) {
2992
+ } catch (e8) {
3446
2993
  }
3447
2994
  }
3448
2995
  }
@@ -3679,7 +3226,7 @@ function setupVariableTrackingBridge(vm, variables) {
3679
3226
  } else {
3680
3227
  variables[name] = value;
3681
3228
  }
3682
- } catch (e8) {
3229
+ } catch (e9) {
3683
3230
  variables[name] = "[[non-primitive]]";
3684
3231
  }
3685
3232
  }
@@ -3694,35 +3241,15 @@ globalThis.__llmz_result = undefined;
3694
3241
  globalThis.__llmz_result_set = false;
3695
3242
  globalThis.__llmz_error = null;
3696
3243
  globalThis.__llmz_error_stack = null;
3697
- globalThis.__llmz_yields = [];
3698
3244
 
3699
3245
  (async () => {
3700
3246
  try {
3701
- async function* __fn__() {
3247
+ async function __fn__() {
3702
3248
  ${transformedCode}
3703
3249
  }
3704
3250
 
3705
- const fn = __fn__();
3706
- let iteration = 0;
3707
- const maxIterations = 10000;
3708
-
3709
- while (iteration < maxIterations) {
3710
- const { value, done } = await fn.next();
3711
-
3712
- if (done) {
3713
- globalThis.__llmz_result = value;
3714
- globalThis.__llmz_result_set = true;
3715
- break;
3716
- }
3717
-
3718
- globalThis.__llmz_yields.push(value);
3719
- await ${Identifiers.AsyncIterYieldFnIdentifier}(value);
3720
- iteration++;
3721
- }
3722
-
3723
- if (iteration >= maxIterations) {
3724
- throw new Error('Maximum iterations exceeded');
3725
- }
3251
+ globalThis.__llmz_result = await __fn__();
3252
+ globalThis.__llmz_result_set = true;
3726
3253
  } catch (err) {
3727
3254
  globalThis.__llmz_error = typeof err === 'string' ? err : String(err.message || err || '');
3728
3255
  globalThis.__llmz_error_stack = '' + (err.stack || '');
@@ -3733,8 +3260,17 @@ ${transformedCode}
3733
3260
 
3734
3261
  // src/vm/index.ts
3735
3262
  var MAX_VM_EXECUTION_TIME = 6e4;
3736
- async function runAsyncFunction(context, code, traces = [], signal = null, timeout = MAX_VM_EXECUTION_TIME) {
3263
+ var useQuickJS = () => {
3737
3264
  var _a;
3265
+ return typeof process === "undefined" || ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.USE_QUICKJS) !== "false";
3266
+ };
3267
+ var warmupVM = () => {
3268
+ if (useQuickJS()) {
3269
+ loadQuickJSModule().catch(() => {
3270
+ });
3271
+ }
3272
+ };
3273
+ async function runAsyncFunction(context, code, traces = [], signal = null, timeout = MAX_VM_EXECUTION_TIME) {
3738
3274
  const transformed = (() => {
3739
3275
  try {
3740
3276
  return compile(code);
@@ -3764,8 +3300,7 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
3764
3300
  delete context[name];
3765
3301
  }
3766
3302
  let driver;
3767
- const useQuickJS = typeof process === "undefined" || ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.USE_QUICKJS) !== "false";
3768
- if (useQuickJS) {
3303
+ if (useQuickJS()) {
3769
3304
  try {
3770
3305
  driver = new QuickJSDriver();
3771
3306
  return await driver.execute({
@@ -3813,4 +3348,6 @@ async function runAsyncFunction(context, code, traces = [], signal = null, timeo
3813
3348
 
3814
3349
 
3815
3350
 
3816
- exports.runAsyncFunction = runAsyncFunction;
3351
+
3352
+
3353
+ exports.hasTopLevelReturn = hasTopLevelReturn; exports.warmupVM = warmupVM; exports.runAsyncFunction = runAsyncFunction;