llmz 0.9.0 → 1.0.2
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.
- package/DOCS.md +232 -1794
- package/ERRORS.md +101 -0
- package/README.md +96 -582
- package/dist/chat/chat.d.ts +63 -0
- package/dist/chat/component.d.ts +31 -0
- package/dist/chat/component.default.d.ts +58 -0
- package/dist/chat/response.d.ts +15 -0
- package/dist/compiler/compiler.d.ts +2 -7
- package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
- package/dist/compiler/plugins/replace-comment.d.ts +2 -3
- package/dist/compiler/plugins/return-async.d.ts +5 -4
- package/dist/compiler/plugins/termination.d.ts +8 -0
- package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
- package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
- package/dist/component-CMFoCHyu.cjs +649 -0
- package/dist/component-DncqP4fB.js +614 -0
- package/dist/context.d.ts +71 -378
- package/dist/custom-client-C-WXvLD9.js +1655 -0
- package/dist/custom-client-Cgt9_0r1.cjs +1732 -0
- package/dist/custom-client.d.ts +12 -2
- package/dist/errors/catalog.d.ts +294 -0
- package/dist/errors/hooks.d.ts +2 -0
- package/dist/errors-C6ppQUZX.cjs +893 -0
- package/dist/errors-Crk5P8jo.js +636 -0
- package/dist/errors.d.ts +24 -36
- package/dist/execute-CiYvPs5Q.js +2061 -0
- package/dist/execute-DTTfacsi.cjs +2062 -0
- package/dist/{exit-DUM96DN1.cjs → exit-BOtKWPuT.cjs} +38 -28
- package/dist/{exit-CDdxDBRT.js → exit-DMPwCSba.js} +37 -27
- package/dist/exit.d.ts +19 -16
- package/dist/index.cjs +177 -1237
- package/dist/index.d.ts +25 -28
- package/dist/index.js +137 -1213
- package/dist/index.workerd.js +8974 -11145
- package/dist/inspect.d.ts +18 -4
- package/dist/inspection.d.ts +40 -0
- package/dist/native-0bq5ATZM.cjs +212 -0
- package/dist/native-n_718Z-T.js +177 -0
- package/dist/objects.d.ts +2 -57
- package/dist/prompts/native.d.ts +2 -0
- package/dist/prompts/prompt.d.ts +10 -101
- package/dist/quickjs-variant-21IO97PF.cjs +1080 -0
- package/dist/quickjs-variant-CtuGagsb.js +985 -0
- package/dist/result.d.ts +30 -861
- package/dist/runtime/execute.d.ts +3 -2
- package/dist/runtime/execution-activity.d.ts +11 -0
- package/dist/runtime/execution-diagnostics.d.ts +11 -0
- package/dist/runtime/execution-report.d.ts +51 -0
- package/dist/runtime/fixtures/chat.d.ts +8 -0
- package/dist/runtime/fixtures/long-search.d.ts +1 -1
- package/dist/runtime/fixtures/native-client.d.ts +33 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +1 -1
- package/dist/runtime/forced-inspection.d.ts +13 -0
- package/dist/runtime/forced-inspection.test.d.ts +1 -0
- package/dist/runtime/generate.d.ts +23 -20
- package/dist/runtime/generate.test.d.ts +1 -0
- package/dist/runtime/hook-provenance.test.d.ts +1 -0
- package/dist/runtime/inspection-hook.test.d.ts +1 -0
- package/dist/runtime/inspection-values.d.ts +14 -0
- package/dist/runtime/inspection-values.test.d.ts +1 -0
- package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
- package/dist/runtime/interruption-settings.test.d.ts +1 -0
- package/dist/runtime/javascript-api.d.ts +62 -0
- package/dist/runtime/javascript-api.test.d.ts +1 -0
- package/dist/runtime/native-review.test.d.ts +1 -0
- package/dist/runtime/native-tools.d.ts +18 -0
- package/dist/runtime/native-tools.test.d.ts +1 -0
- package/dist/runtime/object-memory.test.d.ts +1 -0
- package/dist/runtime/single-tool.test.d.ts +1 -0
- package/dist/runtime/think-signal.test.d.ts +1 -0
- package/dist/runtime/token-budget.d.ts +22 -0
- package/dist/runtime/token-budget.test.d.ts +1 -0
- package/dist/runtime/tool-wrapper.d.ts +6 -5
- package/dist/runtime/traces.test.d.ts +1 -0
- package/dist/runtime/truncation.test.d.ts +1 -0
- package/dist/runtime/types.d.ts +47 -31
- package/dist/runtime/variable-recovery.test.d.ts +1 -0
- package/dist/runtime/vm-context.d.ts +6 -1
- package/dist/runtime/worker-completion.test.d.ts +1 -0
- package/dist/runtime-names.d.ts +4 -0
- package/dist/schema-CXlnbb3n.cjs +68 -0
- package/dist/schema-GE4ISPCR.js +45 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.test.d.ts +1 -0
- package/dist/session/compactor.d.ts +51 -0
- package/dist/session/compactor.test.d.ts +1 -0
- package/dist/session/history.d.ts +36 -0
- package/dist/session/history.test.d.ts +1 -0
- package/dist/session/json.d.ts +3 -0
- package/dist/session/json.test.d.ts +1 -0
- package/dist/session/memory-codec.d.ts +9 -0
- package/dist/session/memory-codec.test.d.ts +1 -0
- package/dist/session/memory-render.d.ts +15 -0
- package/dist/session/memory-render.test.d.ts +1 -0
- package/dist/session/memory.d.ts +112 -0
- package/dist/session/memory.test.d.ts +1 -0
- package/dist/session/messages.d.ts +19 -0
- package/dist/session/messages.test.d.ts +1 -0
- package/dist/session/serialization.d.ts +36 -0
- package/dist/session/serialization.test.d.ts +1 -0
- package/dist/session/session-memory.test.d.ts +1 -0
- package/dist/session/session.d.ts +121 -0
- package/dist/session/session.test.d.ts +1 -0
- package/dist/session/speaker.test.d.ts +1 -0
- package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
- package/dist/session/transcript.test.d.ts +1 -0
- package/dist/{tool-Bv8N4IPj.js → tool-DstssiAs.js} +144 -92
- package/dist/{tool-Dy6AJpJH.cjs → tool-_wK9hQOb.cjs} +146 -94
- package/dist/tool.d.ts +25 -17
- package/dist/truncate-BEKbdo3t.js +79 -0
- package/dist/truncate-uomAMGPs.cjs +102 -0
- package/dist/truncate.d.ts +24 -0
- package/dist/truncate.test.d.ts +1 -0
- package/dist/types.d.ts +33 -9
- package/dist/{typings-3lsqCbkn.cjs → typings-BA_XxAcY.cjs} +38 -193
- package/dist/{typings-CrBa7Tyy.js → typings-BEVDvtuk.js} +38 -175
- package/dist/typings-formatter.d.ts +1 -1
- package/dist/typings.d.ts +3 -0
- package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
- package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
- package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
- package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
- package/dist/vm/drivers/node.d.ts +1 -1
- package/dist/vm/drivers/quickjs.d.ts +1 -1
- package/dist/vm/errors.d.ts +4 -4
- package/dist/vm/index.d.ts +3 -4
- package/dist/vm/instrument.d.ts +14 -6
- package/dist/vm/member-proxy.d.ts +4 -0
- package/dist/vm/member-proxy.test.d.ts +1 -0
- package/dist/vm/memory.test.d.ts +1 -0
- package/dist/vm/return-semantics.test.d.ts +1 -0
- package/dist/vm/types.d.ts +20 -3
- package/dist/{vm-BLsHw1da.js → vm-C7SfutHn.js} +1187 -180
- package/dist/{vm-D6s1zF6M.cjs → vm-gmekHc0i.cjs} +1221 -207
- package/package.json +13 -6
- package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
- package/dist/_baseForOwn-CFhWe_W6.js +0 -48
- package/dist/_getPrototype-CG7Dxrrz.js +0 -6
- package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
- package/dist/_overArg-C5Hy7oCi.cjs +0 -196
- package/dist/_overArg-CRYbj1NH.js +0 -155
- package/dist/chat.d.ts +0 -401
- package/dist/common-BlRFtdf2.js +0 -807
- package/dist/common-BnvrDnIT.cjs +0 -860
- package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
- package/dist/compiler-C-OI9sim.cjs +0 -547
- package/dist/compiler-CW1VjQsn.js +0 -473
- package/dist/component-C6Agl2ns.cjs +0 -73
- package/dist/component-DGG7d_Mz.js +0 -44
- package/dist/component.d.ts +0 -88
- package/dist/component.default.d.ts +0 -278
- package/dist/custom-client-ChuZ63zp.js +0 -2658
- package/dist/custom-client-DAsGRnYc.cjs +0 -2729
- package/dist/dual-modes-DDkoCp3R.js +0 -3006
- package/dist/dual-modes-DPXiuvNe.cjs +0 -3090
- package/dist/errors-C962uJdS.cjs +0 -220
- package/dist/errors-Cg1G0Awu.js +0 -161
- package/dist/example-format.d.ts +0 -8
- package/dist/example.d.ts +0 -45
- package/dist/execute-BWcdv9so.js +0 -1059
- package/dist/execute-DM2-7y86.cjs +0 -1060
- package/dist/exit-parser.d.ts +0 -39
- package/dist/handlers.d.ts +0 -10
- package/dist/hoist.d.ts +0 -2
- package/dist/isEmpty-BhJRCqIF.js +0 -52
- package/dist/isEmpty-LY533Wmh.cjs +0 -57
- package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
- package/dist/isPlainObject-D39AzPO2.js +0 -51
- package/dist/jsx-CIgdGGVs.js +0 -52
- package/dist/jsx-owqxrquU.cjs +0 -75
- package/dist/jsx.d.ts +0 -11
- package/dist/message-stream/index.d.ts +0 -9
- package/dist/message-stream/instructions.d.ts +0 -30
- package/dist/message-stream/normalizer.d.ts +0 -21
- package/dist/message-stream/parser.d.ts +0 -89
- package/dist/message-stream/registry.d.ts +0 -14
- package/dist/message-stream/replayable.d.ts +0 -27
- package/dist/message-stream/response-parser.d.ts +0 -24
- package/dist/message-stream/sanitize.d.ts +0 -10
- package/dist/message-stream/stream.d.ts +0 -54
- package/dist/message-stream/types.d.ts +0 -97
- package/dist/message-stream/validator.d.ts +0 -23
- package/dist/prompts/chat-mode/protocol.d.ts +0 -2
- package/dist/prompts/chat-mode/system.d.ts +0 -2
- package/dist/prompts/chat-mode/system.md.d.ts +0 -2
- package/dist/prompts/chat-mode/user.d.ts +0 -2
- package/dist/prompts/chat-mode/user.md.d.ts +0 -2
- package/dist/prompts/code-examples.d.ts +0 -2
- package/dist/prompts/common.d.ts +0 -7
- package/dist/prompts/dual-modes.d.ts +0 -2
- package/dist/prompts/execution-history.d.ts +0 -6
- package/dist/prompts/execution-state.d.ts +0 -3
- package/dist/prompts/protocol-basics.d.ts +0 -5
- package/dist/prompts/protocol.d.ts +0 -31
- package/dist/prompts/worker-mode/protocol.d.ts +0 -2
- package/dist/prompts/worker-mode/system.d.ts +0 -2
- package/dist/prompts/worker-mode/system.md.d.ts +0 -2
- package/dist/prompts/worker-mode/user.d.ts +0 -2
- package/dist/prompts/worker-mode/user.md.d.ts +0 -2
- package/dist/quickjs-variant-BYhMBpwU.js +0 -45
- package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
- package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
- package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +0 -29
- package/dist/runtime/interpret-result.d.ts +0 -22
- package/dist/snapshots.d.ts +0 -249
- package/dist/stack-traces-BIE_5Xwf.js +0 -21
- package/dist/stack-traces-ntw_qhoy.cjs +0 -26
- package/dist/truncator-CLkouTCO.cjs +0 -276
- package/dist/truncator-DZqEqnpD.js +0 -253
- package/dist/truncator.d.ts +0 -118
- package/dist/utils-3ESwP3yg.cjs +0 -1075
- package/dist/utils-UBeAFeEI.js +0 -950
- /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
- /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
- /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
- /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
- /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
- /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
- /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
- /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
- /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
- /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
- /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
- /package/dist/{message-stream/response-parser.test.d.ts → result.test.d.ts} +0 -0
- /package/dist/{message-stream/stream.test.d.ts → runtime/chat-completion.test.d.ts} +0 -0
- /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
- /package/dist/{prompts/adherence.test.d.ts → runtime/chat-last-speaker.test.d.ts} +0 -0
- /package/dist/{prompts/catalogue-examples.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
- /package/dist/{prompts/code-examples.test.d.ts → runtime/context-registration.test.d.ts} +0 -0
- /package/dist/{prompts/common.test.d.ts → runtime/empty-completion.test.d.ts} +0 -0
- /package/dist/{prompts/concrete-patterns.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
- /package/dist/{prompts/long-search.test.d.ts → runtime/errors.test.d.ts} +0 -0
- /package/dist/{prompts/protocol-simple.test.d.ts → runtime/execution-activity.test.d.ts} +0 -0
- /package/dist/{prompts/protocol.test.d.ts → runtime/execution-diagnostics.test.d.ts} +0 -0
- /package/dist/{prompts/sections.test.d.ts → runtime/execution-report.test.d.ts} +0 -0
- /package/dist/runtime/{interpret-result.test.d.ts → execution-safety.test.d.ts} +0 -0
- /package/dist/{transcript.test.d.ts → runtime/exit-control-flow.test.d.ts} +0 -0
- /package/dist/{truncator.test.d.ts → runtime/fixtures/long-search.test.d.ts} +0 -0
|
@@ -1,473 +0,0 @@
|
|
|
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,73 +0,0 @@
|
|
|
1
|
-
const require_compiler = require("./compiler-C-OI9sim.cjs");
|
|
2
|
-
const require_jsx = require("./jsx-owqxrquU.cjs");
|
|
3
|
-
//#region src/component.ts
|
|
4
|
-
var component_exports = /* @__PURE__ */ require_compiler.__exportAll({
|
|
5
|
-
Component: () => Component,
|
|
6
|
-
assertValidComponent: () => assertValidComponent,
|
|
7
|
-
isAnyComponent: () => isAnyComponent,
|
|
8
|
-
isComponent: () => isComponent
|
|
9
|
-
});
|
|
10
|
-
function assertValidComponent(component) {
|
|
11
|
-
if (!component.name) throw new Error("Component must have a name");
|
|
12
|
-
const nameRegex = /^[A-Z]{3,50}$/i;
|
|
13
|
-
if (!nameRegex.test(component.name)) throw new Error(`Component name "${component.name}" must be 3-50 characters long and start with an uppercase letter`);
|
|
14
|
-
if (component.aliases) {
|
|
15
|
-
for (const alias of component.aliases) if (!nameRegex.test(alias)) throw new Error(`Alias "${alias}" must be 3-50 characters long and start with an uppercase letter`);
|
|
16
|
-
}
|
|
17
|
-
if (!component.description) throw new Error("Component must have a description");
|
|
18
|
-
if (component.type === "default" && !component.default) throw new Error("Default component must have default props and children");
|
|
19
|
-
if (component.type === "leaf" && !component.leaf) throw new Error("Leaf component must have leaf props");
|
|
20
|
-
if (component.type === "container" && !component.container) throw new Error("Container component must have container props and children");
|
|
21
|
-
}
|
|
22
|
-
var Component = class {
|
|
23
|
-
definition;
|
|
24
|
-
propsType;
|
|
25
|
-
constructor(definition) {
|
|
26
|
-
assertValidComponent(definition);
|
|
27
|
-
this.definition = definition;
|
|
28
|
-
}
|
|
29
|
-
render(props, children = []) {
|
|
30
|
-
return require_jsx.createJsxComponent({
|
|
31
|
-
type: this.definition.name,
|
|
32
|
-
props,
|
|
33
|
-
children
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
function isComponent(rendered, component) {
|
|
38
|
-
return require_jsx.isJsxComponent(component.definition.name, rendered);
|
|
39
|
-
}
|
|
40
|
-
function isAnyComponent(message) {
|
|
41
|
-
return require_jsx.isAnyJsxComponent(message);
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
Object.defineProperty(exports, "Component", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function() {
|
|
47
|
-
return Component;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(exports, "assertValidComponent", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function() {
|
|
53
|
-
return assertValidComponent;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, "component_exports", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function() {
|
|
59
|
-
return component_exports;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(exports, "isAnyComponent", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function() {
|
|
65
|
-
return isAnyComponent;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(exports, "isComponent", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function() {
|
|
71
|
-
return isComponent;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
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";
|
|
3
|
-
//#region src/component.ts
|
|
4
|
-
var component_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
-
Component: () => Component,
|
|
6
|
-
assertValidComponent: () => assertValidComponent,
|
|
7
|
-
isAnyComponent: () => isAnyComponent,
|
|
8
|
-
isComponent: () => isComponent
|
|
9
|
-
});
|
|
10
|
-
function assertValidComponent(component) {
|
|
11
|
-
if (!component.name) throw new Error("Component must have a name");
|
|
12
|
-
const nameRegex = /^[A-Z]{3,50}$/i;
|
|
13
|
-
if (!nameRegex.test(component.name)) throw new Error(`Component name "${component.name}" must be 3-50 characters long and start with an uppercase letter`);
|
|
14
|
-
if (component.aliases) {
|
|
15
|
-
for (const alias of component.aliases) if (!nameRegex.test(alias)) throw new Error(`Alias "${alias}" must be 3-50 characters long and start with an uppercase letter`);
|
|
16
|
-
}
|
|
17
|
-
if (!component.description) throw new Error("Component must have a description");
|
|
18
|
-
if (component.type === "default" && !component.default) throw new Error("Default component must have default props and children");
|
|
19
|
-
if (component.type === "leaf" && !component.leaf) throw new Error("Leaf component must have leaf props");
|
|
20
|
-
if (component.type === "container" && !component.container) throw new Error("Container component must have container props and children");
|
|
21
|
-
}
|
|
22
|
-
var Component = class {
|
|
23
|
-
definition;
|
|
24
|
-
propsType;
|
|
25
|
-
constructor(definition) {
|
|
26
|
-
assertValidComponent(definition);
|
|
27
|
-
this.definition = definition;
|
|
28
|
-
}
|
|
29
|
-
render(props, children = []) {
|
|
30
|
-
return createJsxComponent({
|
|
31
|
-
type: this.definition.name,
|
|
32
|
-
props,
|
|
33
|
-
children
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
function isComponent(rendered, component) {
|
|
38
|
-
return isJsxComponent(component.definition.name, rendered);
|
|
39
|
-
}
|
|
40
|
-
function isAnyComponent(message) {
|
|
41
|
-
return isAnyJsxComponent(message);
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { isComponent as a, isAnyComponent as i, assertValidComponent as n, component_exports as r, Component as t };
|
package/dist/component.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { z } from '@bpinternal/zui';
|
|
2
|
-
import { JsxComponent } from './jsx.js';
|
|
3
|
-
import type { BodyFormat, GenerativeComponentMetadata } from './message-stream/types.js';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated TSX-era examples are no longer shown to the model — llmz
|
|
6
|
-
* generates ■-protocol blocks, not TSX. Use `generation.examples`
|
|
7
|
-
* ({ props?, body? }) instead.
|
|
8
|
-
*/
|
|
9
|
-
export type ExampleUsage = {
|
|
10
|
-
name: string;
|
|
11
|
-
description: string;
|
|
12
|
-
code: string;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Optional body configuration for components that accept a message body
|
|
16
|
-
* (`default` and `container` types). Controls how the body is documented to
|
|
17
|
-
* the model in the ■ protocol reference.
|
|
18
|
-
*/
|
|
19
|
-
export type ComponentBodyOptions = {
|
|
20
|
-
/** How the body should be written: 'markdown' (default), 'text' (plain prose) or 'code'. */
|
|
21
|
-
format?: BodyFormat;
|
|
22
|
-
/** Model-facing description of what the body must contain. */
|
|
23
|
-
description?: string;
|
|
24
|
-
/** Whether a body is required. Defaults to true. */
|
|
25
|
-
required?: boolean;
|
|
26
|
-
};
|
|
27
|
-
export type ComponentChild = {
|
|
28
|
-
description: string;
|
|
29
|
-
component: ComponentDefinition;
|
|
30
|
-
};
|
|
31
|
-
export declare function assertValidComponent(component: ComponentDefinition): asserts component is ComponentDefinition;
|
|
32
|
-
export type DefaultComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
|
|
33
|
-
type: 'default';
|
|
34
|
-
name: string;
|
|
35
|
-
aliases: string[];
|
|
36
|
-
description: string;
|
|
37
|
-
/** @deprecated Not shown to the model. Use `generation.examples` instead. */
|
|
38
|
-
examples?: ExampleUsage[];
|
|
39
|
-
/** Body configuration for the ■ protocol reference, or false to disallow a body. */
|
|
40
|
-
body?: ComponentBodyOptions | false;
|
|
41
|
-
/** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props?, body? }). */
|
|
42
|
-
generation?: GenerativeComponentMetadata;
|
|
43
|
-
default: {
|
|
44
|
-
props: T;
|
|
45
|
-
children: Array<ComponentChild>;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
export type LeafComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
|
|
49
|
-
type: 'leaf';
|
|
50
|
-
name: string;
|
|
51
|
-
description: string;
|
|
52
|
-
aliases?: string[];
|
|
53
|
-
/** @deprecated Not shown to the model. Use `generation.examples` instead. */
|
|
54
|
-
examples?: ExampleUsage[];
|
|
55
|
-
/** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props? }). */
|
|
56
|
-
generation?: GenerativeComponentMetadata;
|
|
57
|
-
leaf: {
|
|
58
|
-
props: T;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export type ContainerComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
|
|
62
|
-
type: 'container';
|
|
63
|
-
name: string;
|
|
64
|
-
description: string;
|
|
65
|
-
aliases?: string[];
|
|
66
|
-
/** @deprecated Not shown to the model. Use `generation.examples` instead. */
|
|
67
|
-
examples?: ExampleUsage[];
|
|
68
|
-
/** Body configuration for the ■ protocol reference, or false to disallow a body. */
|
|
69
|
-
body?: ComponentBodyOptions | false;
|
|
70
|
-
/** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props?, body? }). */
|
|
71
|
-
generation?: GenerativeComponentMetadata;
|
|
72
|
-
container: {
|
|
73
|
-
props: T;
|
|
74
|
-
children: Array<ComponentChild>;
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
export type ComponentDefinition = DefaultComponentDefinition | LeafComponentDefinition | ContainerComponentDefinition;
|
|
78
|
-
type ExtractComponentProps<T extends ComponentDefinition> = T extends LeafComponentDefinition<infer P> ? z.infer<P> : T extends ContainerComponentDefinition<infer P> ? z.infer<P> : T extends DefaultComponentDefinition<infer P> ? z.infer<P> : never;
|
|
79
|
-
export type RenderedComponent<TProps extends {} = {}> = JsxComponent<string, TProps>;
|
|
80
|
-
export declare class Component<T extends ComponentDefinition = ComponentDefinition> {
|
|
81
|
-
readonly definition: T;
|
|
82
|
-
readonly propsType: ExtractComponentProps<T>;
|
|
83
|
-
constructor(definition: T);
|
|
84
|
-
render<TChildren extends any = any>(props: Component['propsType'], children?: Array<TChildren>): RenderedComponent;
|
|
85
|
-
}
|
|
86
|
-
export declare function isComponent<T extends ComponentDefinition>(rendered: RenderedComponent<any>, component: Component<T>): rendered is RenderedComponent<ExtractComponentProps<T>>;
|
|
87
|
-
export declare function isAnyComponent(message: unknown): message is RenderedComponent;
|
|
88
|
-
export {};
|