llmz 0.7.0 → 0.8.0

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 (47) hide show
  1. package/dist/{_baseForOwn-buOZDFbK.cjs → _baseForOwn-BfWDTL8L.cjs} +0 -50
  2. package/dist/common-DdArNQhl.cjs +643 -0
  3. package/dist/common-pgJjFu2Y.js +596 -0
  4. package/dist/compiler-C-OI9sim.cjs +547 -0
  5. package/dist/compiler-CW1VjQsn.js +473 -0
  6. package/dist/{component-BwixNVH8.cjs → component-BXS8vAwO.cjs} +3 -3
  7. package/dist/{component-DGG7d_Mz.js → component-Dq7ZLdvy.js} +1 -1
  8. package/dist/component.d.ts +4 -4
  9. package/dist/component.default.d.ts +60 -87
  10. package/dist/component.default.test.d.ts +1 -0
  11. package/dist/context.d.ts +10 -0
  12. package/dist/{custom-client-CMuy7fXU.js → custom-client-2V9lmzUf.js} +119 -24
  13. package/dist/{custom-client-Bp1TgTKk.cjs → custom-client-HkM1Sdzv.cjs} +124 -29
  14. package/dist/{dual-modes-CfqTk9M8.cjs → dual-modes-Cb7ThvoV.cjs} +1268 -1062
  15. package/dist/{dual-modes-mNyMThtf.js → dual-modes-Cy0_W4O2.js} +1242 -1036
  16. package/dist/example.d.ts +45 -0
  17. package/dist/example.test.d.ts +1 -0
  18. package/dist/{execute-DP_17lYZ.js → execute-Aw4cbIx-.js} +23 -10
  19. package/dist/{execute-msui51b2.cjs → execute-COIHOIKR.cjs} +30 -18
  20. package/dist/{exit-BGi0Kk0y.cjs → exit-DUM96DN1.cjs} +3 -3
  21. package/dist/exit-parser.d.ts +2 -0
  22. package/dist/index.cjs +33 -356
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +13 -337
  25. package/dist/index.workerd.js +9981 -9388
  26. package/dist/{jsx-CIgdGGVs.js → jsx-B0iYyvfr.js} +50 -2
  27. package/dist/{jsx-BWvT6ukg.cjs → jsx-D5Y2cPo-.cjs} +58 -4
  28. package/dist/message-stream/parser.d.ts +3 -0
  29. package/dist/message-stream/types.d.ts +1 -1
  30. package/dist/prompts/chat-mode/system.d.ts +2 -0
  31. package/dist/prompts/chat-mode/user.d.ts +2 -0
  32. package/dist/prompts/execution-history.d.ts +6 -0
  33. package/dist/prompts/execution-state.d.ts +3 -0
  34. package/dist/prompts/prompt.d.ts +26 -0
  35. package/dist/prompts/protocol.test.d.ts +1 -0
  36. package/dist/prompts/worker-mode/system.d.ts +2 -0
  37. package/dist/prompts/worker-mode/user.d.ts +2 -0
  38. package/dist/runtime/types.d.ts +9 -0
  39. package/dist/{tool-ReA9gxMp.cjs → tool-Dy6AJpJH.cjs} +4 -4
  40. package/dist/{truncator-B6aaJaN1.cjs → truncator-CLkouTCO.cjs} +3 -3
  41. package/dist/{typings-BwAz_TM9.cjs → typings-3lsqCbkn.cjs} +3 -3
  42. package/dist/{utils-ZpJm00ed.cjs → utils-3ESwP3yg.cjs} +2 -2
  43. package/dist/{vm-C5vf1LH3.js → vm-BLsHw1da.js} +3 -462
  44. package/dist/{vm-BjkJqSQH.cjs → vm-D6s1zF6M.cjs} +28 -489
  45. package/package.json +2 -2
  46. package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
  47. package/dist/isPlainObject-D39AzPO2.js +0 -51
@@ -0,0 +1,473 @@
1
+ import { parse } from "acorn";
2
+ import MagicString from "magic-string";
3
+ //#region src/compiler/ast.ts
4
+ const TS_SMELL = /(^|[^:]):\s*(string|number|boolean|any|unknown|void)\b|\bas\s+(const\b|[A-Z])|\binterface\s+[A-Z]|^\s*type\s+[A-Z]|[a-zA-Z)\]]!\.|<(string|number|boolean)[,>]/m;
5
+ function parseScript(code, opts) {
6
+ try {
7
+ return parse(code, {
8
+ ecmaVersion: "latest",
9
+ sourceType: "script",
10
+ locations: true,
11
+ allowReturnOutsideFunction: true,
12
+ allowAwaitOutsideFunction: true,
13
+ ...opts,
14
+ onComment: opts === null || opts === void 0 ? void 0 : opts.comments
15
+ });
16
+ } catch (err) {
17
+ if (err instanceof SyntaxError && TS_SMELL.test(code)) err.message += ". The code must be plain JavaScript: do not use TypeScript syntax (type annotations, \"as\" casts, generics, interfaces or type aliases).";
18
+ throw err;
19
+ }
20
+ }
21
+ /**
22
+ * Depth-first pre-order walk. `ancestors` is ordered outermost → innermost and
23
+ * excludes `node` itself; `parent` is `ancestors[ancestors.length - 1]`.
24
+ */
25
+ function walk(root, enter) {
26
+ const ancestors = [];
27
+ const visit = (node) => {
28
+ enter(node, ancestors[ancestors.length - 1] ?? null, ancestors);
29
+ ancestors.push(node);
30
+ for (const key of Object.keys(node)) {
31
+ if (key === "loc") continue;
32
+ const value = node[key];
33
+ if (Array.isArray(value)) {
34
+ for (const child of value) if (isNode(child)) visit(child);
35
+ } else if (isNode(value)) visit(value);
36
+ }
37
+ ancestors.pop();
38
+ };
39
+ visit(root);
40
+ }
41
+ const isNode = (value) => !!value && typeof value === "object" && typeof value.type === "string";
42
+ const isStatementContainer = (node) => !!node && (node.type === "Program" || node.type === "BlockStatement" || node.type === "StaticBlock");
43
+ /**
44
+ * The statement that contains `node`: the outermost ancestor (or the node
45
+ * itself) whose parent is a statement container.
46
+ */
47
+ function enclosingStatement(node, ancestors) {
48
+ const chain = [...ancestors, node];
49
+ for (let i = chain.length - 1; i > 0; i--) if (isStatementContainer(chain[i - 1])) return chain[i];
50
+ return null;
51
+ }
52
+ /** The innermost node whose range contains [start, end] */
53
+ function innermostContaining(ast, start, end) {
54
+ let best = null;
55
+ walk(ast, (node) => {
56
+ if (node.start <= start && node.end >= end) {
57
+ if (!best || node.start >= best.start && node.end <= best.end) best = node;
58
+ }
59
+ });
60
+ return best;
61
+ }
62
+ //#endregion
63
+ //#region src/compiler/plugins/async-wrapper.ts
64
+ const Open = "async function __fn__() {";
65
+ const Close = "}";
66
+ const USER_CODE_START_MARKER = "/* __LLMZ_USER_CODE_START__ */";
67
+ const USER_CODE_END_MARKER = "/* __LLMZ_USER_CODE_END__ */";
68
+ /**
69
+ * Wraps user code in an async function so top-level `await` and `return` parse,
70
+ * and so plugins can target the `__fn__` declaration. The wrapper is removed
71
+ * after transformation — drivers re-wrap the bare statements themselves.
72
+ */
73
+ const AsyncWrapper = {
74
+ preProcessing: (code) => {
75
+ return `"use strict";
76
+ ${Open}
77
+ ${USER_CODE_START_MARKER}
78
+ ${code}
79
+ ${USER_CODE_END_MARKER}
80
+ ${Close}
81
+ `.trim();
82
+ },
83
+ postProcessing: (code) => {
84
+ code = code.slice(code.indexOf(Open) + 25);
85
+ code = code.slice(0, code.lastIndexOf(Close));
86
+ code = code.replace(USER_CODE_START_MARKER, "").replace(USER_CODE_END_MARKER, "");
87
+ return code.trimEnd();
88
+ }
89
+ };
90
+ //#endregion
91
+ //#region src/compiler/plugins/line-tracking.ts
92
+ const LineTrackingFnIdentifier = "__track__";
93
+ const TRACKED_TYPES = /* @__PURE__ */ new Set([
94
+ "FunctionDeclaration",
95
+ "MethodDefinition",
96
+ "ReturnStatement",
97
+ "AwaitExpression",
98
+ "ForOfStatement",
99
+ "CallExpression",
100
+ "UnaryExpression",
101
+ "VariableDeclaration",
102
+ "AssignmentExpression"
103
+ ]);
104
+ const SKIPPED_PARENT_TYPES = /* @__PURE__ */ new Set([
105
+ "ArrowFunctionExpression",
106
+ "Property",
107
+ "AwaitExpression",
108
+ "UnaryExpression",
109
+ "ReturnStatement",
110
+ "ForOfStatement",
111
+ "ForStatement",
112
+ "ForInStatement",
113
+ "VariableDeclaration",
114
+ "BinaryExpression",
115
+ "LogicalExpression"
116
+ ]);
117
+ /**
118
+ * Inserts a `__track__(<line>)` call before the statement containing each
119
+ * tracked node — at most one per source line.
120
+ */
121
+ function applyLineTracking(ctx) {
122
+ const trackedLines = /* @__PURE__ */ new Set();
123
+ walk(ctx.ast, (node, parent, ancestors) => {
124
+ if (!parent || !node.loc) return;
125
+ if (!TRACKED_TYPES.has(node.type) && parent.type !== "BlockStatement") return;
126
+ const line = node.loc.start.line;
127
+ if (trackedLines.has(line) || SKIPPED_PARENT_TYPES.has(parent.type)) return;
128
+ const statement = enclosingStatement(node, ancestors);
129
+ if (!statement) return;
130
+ trackedLines.add(line);
131
+ ctx.ms.appendLeft(statement.start, `${LineTrackingFnIdentifier}(${line});`);
132
+ });
133
+ }
134
+ //#endregion
135
+ //#region src/compiler/plugins/replace-comment.ts
136
+ const CommentFnIdentifier = "__comment__";
137
+ const MARKER_TAGS = [USER_CODE_START_MARKER, USER_CODE_END_MARKER].map((m) => m.replace(/\/\*|\*\/|\s/g, ""));
138
+ /** Blanks a range, keeping newlines so line numbers are preserved */
139
+ const blank = (ctx, start, end) => {
140
+ ctx.ms.update(start, end, ctx.code.slice(start, end).replace(/[^\n]/g, " "));
141
+ };
142
+ /**
143
+ * Replaces comments at statement position with `__comment__("<text>", <line>)`
144
+ * calls so the agent's inline "thinking" comments show up as traces at runtime.
145
+ * Comments inside expressions and the user-code markers are blanked; comments
146
+ * inside instrumented tool-call ranges are left verbatim.
147
+ */
148
+ function applyCommentReplacement(ctx, skipRanges) {
149
+ for (const comment of ctx.comments) {
150
+ const text = comment.value.trim();
151
+ if (MARKER_TAGS.some((tag) => text.includes(tag))) {
152
+ blank(ctx, comment.start, comment.end);
153
+ continue;
154
+ }
155
+ if (skipRanges.some(([start, end]) => comment.start >= start && comment.end <= end)) continue;
156
+ const container = innermostContaining(ctx.ast, comment.start, comment.end);
157
+ if (isStatementContainer(container)) {
158
+ const newlines = ctx.code.slice(comment.start, comment.end).replace(/[^\n]/g, "");
159
+ ctx.ms.update(comment.start, comment.end, `;${CommentFnIdentifier}(${JSON.stringify(text)}, ${comment.loc.start.line});${newlines}`);
160
+ } else blank(ctx, comment.start, comment.end);
161
+ }
162
+ }
163
+ //#endregion
164
+ //#region src/compiler/plugins/return-async.ts
165
+ /**
166
+ * Plans the instrumentation of the last statement of the `__fn__` wrapper so
167
+ * the generated code always returns an awaited value (the isolated VM cannot
168
+ * return a pending Promise):
169
+ * - `return expr` → `return await (expr)`
170
+ * - a trailing `call()` / `await call()` statement → `return await (…)`
171
+ *
172
+ * The prefix must be applied before, and the suffix after, all other edits so
173
+ * they wrap around the tool-call instrumentation.
174
+ */
175
+ function planLastLineInstrumentation(ast) {
176
+ const fn = ast.body.find((node) => {
177
+ var _id;
178
+ return node.type === "FunctionDeclaration" && ((_id = node.id) === null || _id === void 0 ? void 0 : _id.name) === "__fn__";
179
+ });
180
+ if (!fn) return null;
181
+ const statements = fn.body.body;
182
+ const last = statements[statements.length - 1];
183
+ if (!last) return null;
184
+ if (last.type === "ReturnStatement") {
185
+ if (!last.argument) return null;
186
+ return {
187
+ prefixPos: last.argument.start,
188
+ prefix: "await (",
189
+ suffixPos: last.argument.end,
190
+ suffix: ")"
191
+ };
192
+ }
193
+ if (last.type === "ExpressionStatement" && (last.expression.type === "CallExpression" || last.expression.type === "AwaitExpression")) return {
194
+ prefixPos: last.expression.start,
195
+ prefix: "return await (",
196
+ suffixPos: last.expression.end,
197
+ suffix: ")"
198
+ };
199
+ return null;
200
+ }
201
+ //#endregion
202
+ //#region src/compiler/plugins/track-tool-calls.ts
203
+ const ToolCallTrackerFnIdentifier = "__toolc__";
204
+ const ToolTrackerRetIdentifier = "__ret__";
205
+ /**
206
+ * Wraps every outermost call expression in an IIFE that reports
207
+ * `__toolc__(<id>, "start" | "end", …)` events around the call:
208
+ *
209
+ * const x = (() => {
210
+ * try {
211
+ * __toolc__(0, "start");
212
+ * const __ret__ = tool();
213
+ * __toolc__(0, "end", __ret__);
214
+ * return __ret__;
215
+ * } catch (err) { __toolc__(1, "end", err); throw new Error(err.message); }
216
+ * })()
217
+ *
218
+ * Calls assigned to a variable are registered in `calls` (keyed by the id used
219
+ * in the catch clause — the id the runtime sees when a tool throws a
220
+ * SnapshotSignal). Awaited calls get an async IIFE that awaits the call.
221
+ *
222
+ * Returns the wrapped source ranges so later passes can avoid editing inside.
223
+ */
224
+ function applyToolCallTracking(ctx, calls) {
225
+ let callId = 0;
226
+ const wrappedRanges = [];
227
+ const src = ctx.code;
228
+ const sliceOf = (node) => src.slice(node.start, node.end);
229
+ const extractAssignment = (lval) => {
230
+ const source = sliceOf(lval);
231
+ if (lval.type === "Identifier") return {
232
+ type: "single",
233
+ left: source,
234
+ evalFn: `let ${source} = arguments[0]; return { ${source} };`
235
+ };
236
+ if (lval.type === "ArrayPattern") {
237
+ const elements = lval.elements.map((el) => el ? sliceOf(el) : "").join(", ");
238
+ return {
239
+ type: "array",
240
+ left: elements,
241
+ evalFn: `let [${elements}] = arguments[0] ?? []; return { ${elements} };`
242
+ };
243
+ }
244
+ if (lval.type === "ObjectPattern") return {
245
+ type: "object",
246
+ left: source,
247
+ evalFn: `let ${source} = arguments[0] ?? {}; return ${source};`
248
+ };
249
+ return {
250
+ type: "unsupported",
251
+ left: "",
252
+ evalFn: ""
253
+ };
254
+ };
255
+ walk(ctx.ast, (node, parent, ancestors) => {
256
+ if (node.type !== "CallExpression") return;
257
+ if (wrappedRanges.some(([start, end]) => node.start >= start && node.end <= end)) return;
258
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === "YieldExpression") return;
259
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) !== "AwaitExpression") {
260
+ let containsAwait = false;
261
+ walk(node, (child, _parent, ancestors) => {
262
+ if (child.type === "AwaitExpression" && !ancestors.some((ancestor) => [
263
+ "FunctionDeclaration",
264
+ "FunctionExpression",
265
+ "ArrowFunctionExpression"
266
+ ].includes(ancestor.type))) containsAwait = true;
267
+ });
268
+ if (containsAwait) return;
269
+ }
270
+ const declaration = [...ancestors].reverse().find((n) => n.type === "VariableDeclaration");
271
+ const assignment = [...ancestors].reverse().find((n) => n.type === "AssignmentExpression");
272
+ let lval = null;
273
+ if (declaration) {
274
+ var _;
275
+ lval = ((_ = declaration.declarations[0]) === null || _ === void 0 ? void 0 : _.id) ?? null;
276
+ }
277
+ if (assignment) lval = assignment.left;
278
+ const isAsync = (parent === null || parent === void 0 ? void 0 : parent.type) === "AwaitExpression";
279
+ const start = (id) => `${ToolCallTrackerFnIdentifier}(${id}, "start");`;
280
+ const end = (id, value) => `${ToolCallTrackerFnIdentifier}(${id}, "end", ${value});`;
281
+ const prefix = (id) => `(${isAsync ? "async " : ""}() => {try {${start(id)}const ${ToolTrackerRetIdentifier} = ${isAsync ? "await " : ""}`;
282
+ const successSuffix = (id) => `;${end(id, ToolTrackerRetIdentifier)}return ${ToolTrackerRetIdentifier};}`;
283
+ if (!lval) {
284
+ if (!sliceOf(node).trim().length) return;
285
+ const catchClause = ` catch (err) {${end(callId, "err")}const __newError = new Error(err.message);__newError.stack = err.stack + ("\\n" + __newError.stack);throw __newError;}})()`;
286
+ ctx.ms.appendLeft(node.start, prefix(callId));
287
+ ctx.ms.appendRight(node.end, successSuffix(callId) + catchClause);
288
+ wrappedRanges.push([node.start, node.end]);
289
+ callId++;
290
+ return;
291
+ }
292
+ const assign = extractAssignment(lval);
293
+ if (assign.type === "unsupported") return;
294
+ const tryId = callId;
295
+ callId++;
296
+ const callee = node.callee;
297
+ let object = "global";
298
+ let tool = callee.type === "Identifier" ? callee.name : sliceOf(callee);
299
+ if (callee.type === "MemberExpression") {
300
+ object = sliceOf(callee.object);
301
+ const property = callee.property;
302
+ tool = property.type === "Identifier" ? property.name : property.type === "Literal" ? String(property.value) : sliceOf(property);
303
+ }
304
+ const catchClause = ` catch (err) {${end(callId, "err")}throw new Error(err.message);}})()`;
305
+ ctx.ms.appendLeft(node.start, prefix(tryId));
306
+ ctx.ms.appendRight(node.end, successSuffix(tryId) + catchClause);
307
+ wrappedRanges.push([node.start, node.end]);
308
+ calls.set(callId, {
309
+ object,
310
+ tool,
311
+ assignment: assign
312
+ });
313
+ });
314
+ return wrappedRanges;
315
+ }
316
+ //#endregion
317
+ //#region src/compiler/plugins/variable-extraction.ts
318
+ const VariableTrackingFnIdentifier = "__var__";
319
+ /**
320
+ * Tracks user variables so the VM can read their values between iterations:
321
+ * - after each variable declaration: `__var__("a", () => eval("a"));`
322
+ * - at the top of function bodies, for their parameters
323
+ *
324
+ * The `eval` indirection captures the variable lazily in its own scope.
325
+ */
326
+ function applyVariableTracking(ctx, variables) {
327
+ const trackerFor = (name) => {
328
+ if (name.startsWith("__")) return null;
329
+ variables.add(name);
330
+ return `${VariableTrackingFnIdentifier}(${JSON.stringify(name)}, () => eval(${JSON.stringify(name)}));`;
331
+ };
332
+ const track = (names) => names.map(trackerFor).filter((t) => !!t).join("");
333
+ const declaredNames = (id) => {
334
+ if (id.type === "Identifier") return [id.name];
335
+ if (id.type === "ObjectPattern") {
336
+ const names = [];
337
+ for (const prop of id.properties) {
338
+ if (prop.type !== "Property") continue;
339
+ if (prop.value.type === "Identifier") names.push(prop.value.name);
340
+ else if (prop.value.type === "ObjectPattern") names.push(...declaredNames(prop.value));
341
+ else if (prop.value.type === "AssignmentPattern" && prop.value.left.type === "Identifier") names.push(prop.value.left.name);
342
+ }
343
+ return names;
344
+ }
345
+ if (id.type === "ArrayPattern") {
346
+ const names = [];
347
+ for (const element of id.elements) {
348
+ if (!element) continue;
349
+ if (element.type === "Identifier") names.push(element.name);
350
+ else if (element.type === "RestElement" && element.argument.type === "Identifier") names.push(element.argument.name);
351
+ else if (element.type === "AssignmentPattern" && element.left.type === "Identifier") names.push(element.left.name);
352
+ }
353
+ return names;
354
+ }
355
+ return [];
356
+ };
357
+ const paramNames = (params) => {
358
+ const names = [];
359
+ for (const param of params) if (param.type === "Identifier") names.push(param.name);
360
+ else if (param.type === "AssignmentPattern" && param.left.type === "Identifier") names.push(param.left.name);
361
+ else if (param.type === "ObjectPattern") {
362
+ for (const prop of param.properties) if (prop.type === "Property" && prop.value.type === "Identifier") names.push(prop.value.name);
363
+ } else if (param.type === "ArrayPattern") {
364
+ for (const element of param.elements) if ((element === null || element === void 0 ? void 0 : element.type) === "Identifier") names.push(element.name);
365
+ }
366
+ return names;
367
+ };
368
+ walk(ctx.ast, (node, parent) => {
369
+ if (node.type === "VariableDeclaration") {
370
+ if (parent && (parent.type === "ForStatement" || parent.type === "ForInStatement" || parent.type === "ForOfStatement")) return;
371
+ const trackers = track(node.declarations.flatMap((d) => declaredNames(d.id)));
372
+ if (trackers) {
373
+ const semi = ctx.code[node.end - 1] === ";" ? "" : ";";
374
+ ctx.ms.appendRight(node.end, `${semi}${trackers}`);
375
+ }
376
+ return;
377
+ }
378
+ if (node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") {
379
+ const trackers = track(paramNames(node.params));
380
+ if (!trackers) return;
381
+ const body = node.body;
382
+ if (body.type === "BlockStatement") ctx.ms.appendRight(body.start + 1, trackers);
383
+ else {
384
+ const expressions = trackers.slice(0, -1).replaceAll(";", ",");
385
+ ctx.ms.prependLeft(body.start, `(${expressions}, (`);
386
+ ctx.ms.appendRight(body.end, "))");
387
+ }
388
+ }
389
+ });
390
+ }
391
+ //#endregion
392
+ //#region src/compiler/compiler.ts
393
+ const Identifiers = {
394
+ ConsoleObjIdentifier: "console",
395
+ LineTrackingFnIdentifier,
396
+ VariableTrackingFnIdentifier,
397
+ ToolCallTrackerFnIdentifier,
398
+ ToolTrackerRetIdentifier,
399
+ CommentFnIdentifier
400
+ };
401
+ const FUNCTION_TYPES = /* @__PURE__ */ new Set([
402
+ "FunctionDeclaration",
403
+ "FunctionExpression",
404
+ "ArrowFunctionExpression"
405
+ ]);
406
+ /**
407
+ * Whether the code contains a top-level `return` statement (one that would
408
+ * return from the generated code itself, not from a nested function). Unlike a
409
+ * regex, this ignores `return` inside comments, strings and nested functions.
410
+ * Falls back to a word-boundary match if the code cannot be parsed.
411
+ */
412
+ function hasTopLevelReturn(code) {
413
+ try {
414
+ const ast = parseScript(code);
415
+ let found = false;
416
+ walk(ast, (node, _parent, ancestors) => {
417
+ if (node.type === "ReturnStatement" && !ancestors.some((a) => FUNCTION_TYPES.has(a.type))) found = true;
418
+ });
419
+ return found;
420
+ } catch {
421
+ return /\breturn\b/.test(code);
422
+ }
423
+ }
424
+ /**
425
+ * Compiles the agent's generated JavaScript for VM execution:
426
+ *
427
+ * 1. wraps it in an async `__fn__` so top-level `await`/`return` parse
428
+ * 2. instruments it in a single parse + text-edit pass:
429
+ * line tracking, last-line return, tool-call tracking, comment tracing
430
+ * and variable tracking
431
+ * 3. unwraps it — the VM drivers re-wrap the bare statements themselves
432
+ *
433
+ * All edits preserve line numbers 1:1 with the wrapped source, so positions
434
+ * reported at runtime map straight back to the user code.
435
+ */
436
+ function compile(code) {
437
+ const wrapped = AsyncWrapper.preProcessing(code);
438
+ const comments = [];
439
+ const ast = parseScript(wrapped, { comments });
440
+ const variables = /* @__PURE__ */ new Set();
441
+ const toolCalls = /* @__PURE__ */ new Map();
442
+ const lastLine = planLastLineInstrumentation(ast);
443
+ const msMarkers = new MagicString(wrapped);
444
+ if (lastLine) {
445
+ msMarkers.appendLeft(lastLine.prefixPos, lastLine.prefix);
446
+ msMarkers.appendRight(lastLine.suffixPos, lastLine.suffix);
447
+ }
448
+ const codeWithMarkers = msMarkers.toString();
449
+ const ms = new MagicString(wrapped);
450
+ const ctx = {
451
+ code: wrapped,
452
+ ms,
453
+ ast,
454
+ comments
455
+ };
456
+ applyLineTracking(ctx);
457
+ if (lastLine) ms.appendLeft(lastLine.prefixPos, lastLine.prefix);
458
+ applyCommentReplacement(ctx, applyToolCallTracking(ctx, toolCalls));
459
+ applyVariableTracking(ctx, variables);
460
+ if (lastLine) ms.appendRight(lastLine.suffixPos, lastLine.suffix);
461
+ return {
462
+ code: AsyncWrapper.postProcessing(ms.toString()),
463
+ codeWithMarkers,
464
+ map: ms.generateMap({
465
+ hires: true,
466
+ source: "<anonymous>"
467
+ }),
468
+ variables,
469
+ toolCalls
470
+ };
471
+ }
472
+ //#endregion
473
+ export { USER_CODE_START_MARKER as i, compile as n, hasTopLevelReturn as r, Identifiers as t };
@@ -1,7 +1,7 @@
1
- const require__baseForOwn = require("./_baseForOwn-buOZDFbK.cjs");
2
- const require_jsx = require("./jsx-BWvT6ukg.cjs");
1
+ const require_compiler = require("./compiler-C-OI9sim.cjs");
2
+ const require_jsx = require("./jsx-D5Y2cPo-.cjs");
3
3
  //#region src/component.ts
4
- var component_exports = /* @__PURE__ */ require__baseForOwn.__exportAll({
4
+ var component_exports = /* @__PURE__ */ require_compiler.__exportAll({
5
5
  Component: () => Component,
6
6
  assertValidComponent: () => assertValidComponent,
7
7
  isAnyComponent: () => isAnyComponent,
@@ -1,5 +1,5 @@
1
1
  import { n as __exportAll } from "./rolldown-runtime-EAsCxrDo.js";
2
- import { n as isAnyJsxComponent, r as isJsxComponent, t as createJsxComponent } from "./jsx-CIgdGGVs.js";
2
+ import { n as isAnyJsxComponent, r as isJsxComponent, t as createJsxComponent } from "./jsx-B0iYyvfr.js";
3
3
  //#region src/component.ts
4
4
  var component_exports = /* @__PURE__ */ __exportAll({
5
5
  Component: () => Component,
@@ -36,8 +36,8 @@ export type DefaultComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<
36
36
  description: string;
37
37
  /** @deprecated Not shown to the model. Use `generation.examples` instead. */
38
38
  examples?: ExampleUsage[];
39
- /** Body configuration for the ■ protocol reference (format, description, required). */
40
- body?: ComponentBodyOptions;
39
+ /** Body configuration for the ■ protocol reference, or false to disallow a body. */
40
+ body?: ComponentBodyOptions | false;
41
41
  /** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props?, body? }). */
42
42
  generation?: GenerativeComponentMetadata;
43
43
  default: {
@@ -65,8 +65,8 @@ export type ContainerComponentDefinition<T extends z.ZodObject<any> = z.ZodObjec
65
65
  aliases?: string[];
66
66
  /** @deprecated Not shown to the model. Use `generation.examples` instead. */
67
67
  examples?: ExampleUsage[];
68
- /** Body configuration for the ■ protocol reference (format, description, required). */
69
- body?: ComponentBodyOptions;
68
+ /** Body configuration for the ■ protocol reference, or false to disallow a body. */
69
+ body?: ComponentBodyOptions | false;
70
70
  /** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props?, body? }). */
71
71
  generation?: GenerativeComponentMetadata;
72
72
  container: {