@assistant-ui/x-generative-compiler 0.0.12 → 0.0.15
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/dist/compile.d.ts +11 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +18 -5
- package/dist/compile.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/package.js +1 -1
- package/package.json +4 -4
- package/src/compile.test.ts +75 -0
- package/src/compile.ts +47 -2
- package/src/index.ts +1 -0
package/dist/compile.d.ts
CHANGED
|
@@ -17,6 +17,15 @@ interface CompileOptions {
|
|
|
17
17
|
* throw — see the Vite integration.
|
|
18
18
|
*/
|
|
19
19
|
injectServerOnly?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* No backend of the app imports this module's server build (e.g. cloud-hosted
|
|
22
|
+
* runs), so the client is the only place the model can learn the schemas
|
|
23
|
+
* from. The `client` target then keeps frontend/human tool schemas
|
|
24
|
+
* uploadable — no `unstable_backendDefault` marker is stamped — and local
|
|
25
|
+
* `new JSONGenerativeUI({ ... })` instances are constructed with
|
|
26
|
+
* `backendless: true` so their `present`/`prompt_user` schemas upload too.
|
|
27
|
+
*/
|
|
28
|
+
backendless?: boolean;
|
|
20
29
|
}
|
|
21
30
|
interface CompileResult {
|
|
22
31
|
code: string;
|
|
@@ -28,11 +37,12 @@ declare class GenerativeCompileError extends Error {
|
|
|
28
37
|
}
|
|
29
38
|
/** Whether a source string opts into generative compilation via the directive. */
|
|
30
39
|
declare function isGenerativeModule(code: string): boolean;
|
|
40
|
+
declare const isGenerativeSource: (filename: string, source: string) => boolean;
|
|
31
41
|
/**
|
|
32
42
|
* Rewrites a `"use generative"` module for a single build target, keeping only the
|
|
33
43
|
* regions that target needs and pruning the imports the dropped regions used.
|
|
34
44
|
*/
|
|
35
45
|
declare function compileGenerative(code: string, options: CompileOptions): CompileResult;
|
|
36
46
|
//#endregion
|
|
37
|
-
export { CompileOptions, CompileResult, GenerativeCompileError, ToolType, compileGenerative, isGenerativeModule };
|
|
47
|
+
export { CompileOptions, CompileResult, GenerativeCompileError, ToolType, compileGenerative, isGenerativeModule, isGenerativeSource };
|
|
38
48
|
//# sourceMappingURL=compile.d.ts.map
|
package/dist/compile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","names":[],"sources":["../src/compile.ts"],"mappings":";;KA0BY;UA2CK;;EAEf,QAAQ;;EAER;;EAEA;;;;;;;;;EASA;;UAGe;EACf;EACA;;;cAIW,+BAA+B;EAC9B,YAAA,iBAAiB;;;iBASf,mBAAmB;;;;;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","names":[],"sources":["../src/compile.ts"],"mappings":";;KA0BY;UA2CK;;EAEf,QAAQ;;EAER;;EAEA;;;;;;;;;EASA;;;;;;;;;EASA;;UAGe;EACf;EACA;;;cAIW,+BAA+B;EAC9B,YAAA,iBAAiB;;;iBASf,mBAAmB;cAgCtB,qBAAsB,kBAAkB;;;;;iBAkHrC,kBACd,cACA,SAAS,iBACR"}
|
package/dist/compile.js
CHANGED
|
@@ -78,6 +78,7 @@ function isGenerativeModule(code) {
|
|
|
78
78
|
if (code[directiveEnd] !== quote) return false;
|
|
79
79
|
return hasDirectiveTerminator(code, directiveEnd + 1);
|
|
80
80
|
}
|
|
81
|
+
const isGenerativeSource = (filename, source) => /\.[cm]?[jt]sx?$/.test(filename) && isGenerativeModule(source);
|
|
81
82
|
function hasDirectiveTerminator(code, start) {
|
|
82
83
|
let i = start;
|
|
83
84
|
let sawLineTerminator = false;
|
|
@@ -160,6 +161,7 @@ function isLineTerminator(char) {
|
|
|
160
161
|
*/
|
|
161
162
|
function compileGenerative(code, options) {
|
|
162
163
|
const { target, filename } = options;
|
|
164
|
+
const backendless = options.backendless ?? false;
|
|
163
165
|
const ast = parse(code, {
|
|
164
166
|
sourceType: "module",
|
|
165
167
|
plugins: parserPlugins
|
|
@@ -186,7 +188,7 @@ function compileGenerative(code, options) {
|
|
|
186
188
|
}
|
|
187
189
|
if (t.isIdentifier(callee, { name: TOOLKIT_WRAPPER })) {
|
|
188
190
|
if (!object) throw new GenerativeCompileError(`${TOOLKIT_WRAPPER}() takes an inline object literal of tools`, filename);
|
|
189
|
-
compileToolkit(object, target, generativeInstances, interactableToolImports, toolkitSpreadNames, namespaceImports, flags, filename);
|
|
191
|
+
compileToolkit(object, target, generativeInstances, interactableToolImports, toolkitSpreadNames, namespaceImports, flags, backendless, filename);
|
|
190
192
|
path.replaceWith(object);
|
|
191
193
|
path.skip();
|
|
192
194
|
}
|
|
@@ -347,6 +349,15 @@ function collectGenerativeInstances(ast) {
|
|
|
347
349
|
}
|
|
348
350
|
return names;
|
|
349
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Wraps a pass-through generative entry (`generative.present()`) so the tool it
|
|
354
|
+
* returns loses its `unstable_backendDefault` marker. The library stamps the
|
|
355
|
+
* marker at runtime, out of this compiler's reach, so a backendless client
|
|
356
|
+
* build strips it post-hoc instead of threading an option into the library.
|
|
357
|
+
*/
|
|
358
|
+
function stripBackendDefaultExpression(expr) {
|
|
359
|
+
return t.callExpression(t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier("unstable_backendDefault"), t.identifier("_backendDefault")), t.restElement(t.identifier("tool"))])], t.identifier("tool")), [expr]);
|
|
360
|
+
}
|
|
350
361
|
function collectGenerativeFactoryImports(ast) {
|
|
351
362
|
const names = /* @__PURE__ */ new Set();
|
|
352
363
|
for (const statement of ast.program.body) {
|
|
@@ -761,7 +772,7 @@ function compileComponents(object, target, flags, filename) {
|
|
|
761
772
|
* `generative.present()` passes through, the library having already split it.
|
|
762
773
|
* Mutates the object in place and records outcomes in {@link TargetFlags}.
|
|
763
774
|
*/
|
|
764
|
-
function compileToolkit(object, target, instances, interactableToolImports, toolkitSpreadNames, namespaceImports, flags, filename) {
|
|
775
|
+
function compileToolkit(object, target, instances, interactableToolImports, toolkitSpreadNames, namespaceImports, flags, backendless, filename) {
|
|
765
776
|
if (target === "client") warnDuplicateToolkitNames(object, toolkitSpreadNames, filename);
|
|
766
777
|
const nextProperties = [];
|
|
767
778
|
for (const entry of object.properties) {
|
|
@@ -773,6 +784,7 @@ function compileToolkit(object, target, instances, interactableToolImports, tool
|
|
|
773
784
|
}
|
|
774
785
|
const raw = entryRawValue(entry);
|
|
775
786
|
if (raw && isGenerativeToolEntry(raw, instances)) {
|
|
787
|
+
if (backendless && target === "client" && t.isObjectProperty(entry)) entry.value = stripBackendDefaultExpression(raw);
|
|
776
788
|
nextProperties.push(entry);
|
|
777
789
|
continue;
|
|
778
790
|
}
|
|
@@ -817,7 +829,7 @@ function compileToolkit(object, target, instances, interactableToolImports, tool
|
|
|
817
829
|
}
|
|
818
830
|
}
|
|
819
831
|
setToolType(value, type);
|
|
820
|
-
setBackendDefault(value, target, type);
|
|
832
|
+
setBackendDefault(value, target, type, backendless);
|
|
821
833
|
nextProperties.push(entry);
|
|
822
834
|
}
|
|
823
835
|
object.properties = nextProperties;
|
|
@@ -928,8 +940,9 @@ function setToolType(object, type) {
|
|
|
928
940
|
removeMember(object, "type");
|
|
929
941
|
object.properties.push(t.objectProperty(t.identifier("type"), t.stringLiteral(type)));
|
|
930
942
|
}
|
|
931
|
-
function setBackendDefault(object, target, type) {
|
|
943
|
+
function setBackendDefault(object, target, type, backendless) {
|
|
932
944
|
removeMember(object, "unstable_backendDefault");
|
|
945
|
+
if (backendless) return;
|
|
933
946
|
if (target !== "client" || type !== "frontend" && type !== "human") return;
|
|
934
947
|
object.properties.push(t.objectProperty(t.identifier("unstable_backendDefault"), t.objectExpression([t.objectProperty(t.identifier("parameters"), t.booleanLiteral(true))])));
|
|
935
948
|
}
|
|
@@ -1011,6 +1024,6 @@ function isRemovableInit(node) {
|
|
|
1011
1024
|
return t.isArrowFunctionExpression(node) || t.isFunctionExpression(node) || t.isClassExpression(node) || t.isIdentifier(node) || t.isMemberExpression(node) && !node.computed || t.isJSXElement(node) || t.isJSXFragment(node) || t.isLiteral(node);
|
|
1012
1025
|
}
|
|
1013
1026
|
//#endregion
|
|
1014
|
-
export { GenerativeCompileError, compileGenerative, isGenerativeModule };
|
|
1027
|
+
export { GenerativeCompileError, compileGenerative, isGenerativeModule, isGenerativeSource };
|
|
1015
1028
|
|
|
1016
1029
|
//# sourceMappingURL=compile.js.map
|
package/dist/compile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","names":["pkgJson.version"],"sources":["../src/compile.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as nodePath from \"node:path\";\nimport { parse } from \"@babel/parser\";\nimport _traverse, { type NodePath } from \"@babel/traverse\";\nimport _generate from \"@babel/generator\";\nimport * as t from \"@babel/types\";\nimport { satisfies } from \"semver\";\nimport { DIRECTIVE, type Target } from \"./constants\";\nimport pkgJson from \"../package.json\" with { type: \"json\" };\n\nconst parserPlugins = [\n \"typescript\",\n \"jsx\",\n \"explicitResourceManagement\",\n] as NonNullable<NonNullable<Parameters<typeof parse>[1]>[\"plugins\"]>;\n\n// @babel/traverse and @babel/generator are CJS; their default export is the\n// function itself under some interop and `{ default }` under others.\nconst traverse = (\n typeof _traverse === \"function\" ? _traverse : (_traverse as any).default\n) as typeof _traverse;\nconst generate = (\n typeof _generate === \"function\" ? _generate : (_generate as any).default\n) as typeof _generate;\n\nexport type ToolType = \"frontend\" | \"backend\" | \"human\" | \"provider\";\n\n/** The required wrapper around a toolkit's tools (stripped at build time). */\nconst TOOLKIT_WRAPPER = \"defineToolkit\";\n/** The helper that produces MCP-only toolkit fragments. */\nconst MCP_TOOLKIT_WRAPPER = \"defineMcpToolkit\";\n/** The required wrapper around a generative-UI library (stripped at build time). */\nconst COMPONENTS_WRAPPER = \"defineGenerativeComponents\";\n/** The core package whose metadata declares supported compiler versions. */\nconst CORE_PACKAGE = \"@assistant-ui/core\";\n/** This package, checked against core's compatibility range. */\nconst COMPILER_PACKAGE = \"@assistant-ui/x-generative-compiler\";\n/** Packages that re-export core's generative markers. */\nconst DISTRIBUTION_PACKAGES = [\n CORE_PACKAGE,\n \"@assistant-ui/react\",\n \"@assistant-ui/react-native\",\n \"@assistant-ui/react-ink\",\n] as const;\n/** Package that exports the generative UI runtime split by export condition. */\nconst GENERATIVE_UI_PACKAGE = \"@assistant-ui/react-generative-ui\";\n/**\n * The class whose instances expose split-by-condition tools (`present()`,\n * `promptUser()`). A toolkit entry that calls a method on one of these passes\n * through untouched — the library, not this compiler, routes its halves.\n */\nconst GENERATIVE_FACTORY = \"JSONGenerativeUI\";\n/**\n * The factory producing an interactable's complete tool entry. Unlike\n * `JSONGenerativeUI`, its package has no per-target builds, so this compiler\n * splits the inline config: the client keeps `render`, the server drops it.\n * The factory's own `execute` is internal and client-safe (frontend tool).\n */\nconst INTERACTABLE_TOOL_FACTORY = \"unstable_interactableTool\";\n\n/** Mutable per-build outcomes the toolkit pass reports back for directive/guard injection. */\ninterface TargetFlags {\n /** A `render` survived on a client build (→ emit `\"use client\"`). */\n keptRender: boolean;\n /** A backend `execute` survived on a server build (→ emit `import \"server-only\"`). */\n keptBackendExecute: boolean;\n}\n\nexport interface CompileOptions {\n /** Which build target to emit. */\n target: Target;\n /** Source filename, used for error messages and source maps. */\n filename?: string;\n /** Emit a source map alongside the code. */\n sourceMaps?: boolean;\n /**\n * Whether the `server` target prepends `import \"server-only\"` when it keeps a\n * backend `execute`. Defaults to `true` (the Next.js/RSC convention, where the\n * guard fires via the `react-server` condition). Set `false` for bundlers\n * without a `react-server` layer (e.g. a Vite/TanStack Start `ssr` build),\n * where the split is already structural and importing `server-only` would\n * throw — see the Vite integration.\n */\n injectServerOnly?: boolean;\n}\n\nexport interface CompileResult {\n code: string;\n map?: object | null;\n}\n\n/** Thrown when a `\"use generative\"` file violates an authoring constraint. */\nexport class GenerativeCompileError extends Error {\n constructor(message: string, filename?: string) {\n super(\n `[assistant-ui/use-generative]${filename ? ` ${filename}:` : \"\"} ${message}`,\n );\n this.name = \"GenerativeCompileError\";\n }\n}\n\n/** Whether a source string opts into generative compilation via the directive. */\nexport function isGenerativeModule(code: string): boolean {\n // The directive must be a leading statement, preceded only by an optional BOM,\n // whitespace, and line/block comments. Scanned linearly — a regex over the\n // comment prefix is prone to catastrophic backtracking on crafted input.\n let i = code.charCodeAt(0) === 0xfeff ? 1 : 0;\n for (;;) {\n while (i < code.length && /\\s/.test(code[i]!)) i++;\n if (code.startsWith(\"//\", i)) {\n const nl = code.indexOf(\"\\n\", i);\n if (nl === -1) return false;\n i = nl + 1;\n } else if (code.startsWith(\"/*\", i)) {\n const end = code.indexOf(\"*/\", i + 2);\n if (end === -1) return false;\n i = end + 2;\n } else {\n break;\n }\n }\n\n const quote = code[i];\n if (quote !== '\"' && quote !== \"'\") return false;\n\n const directiveStart = i + 1;\n if (!code.startsWith(DIRECTIVE, directiveStart)) return false;\n\n const directiveEnd = directiveStart + DIRECTIVE.length;\n if (code[directiveEnd] !== quote) return false;\n\n return hasDirectiveTerminator(code, directiveEnd + 1);\n}\n\nfunction hasDirectiveTerminator(code: string, start: number): boolean {\n let i = start;\n let sawLineTerminator = false;\n for (;;) {\n if (i >= code.length) return true;\n\n const char = code.charCodeAt(i);\n if (isSemicolon(char)) return true;\n if (isLineTerminator(char)) {\n sawLineTerminator = true;\n i++;\n continue;\n }\n\n if (code.startsWith(\"//\", i)) {\n const lineEnd = nextLineTerminatorIndex(code, i + 2);\n if (lineEnd === -1) return true;\n sawLineTerminator = true;\n i = lineEnd + 1;\n continue;\n }\n\n if (code.startsWith(\"/*\", i)) {\n const end = code.indexOf(\"*/\", i + 2);\n if (end === -1) return false;\n sawLineTerminator ||= containsLineTerminator(code, i + 2, end);\n i = end + 2;\n continue;\n }\n\n if (/\\s/.test(code[i]!)) {\n i++;\n continue;\n }\n\n return sawLineTerminator && !startsExpressionContinuation(code, i);\n }\n}\n\nfunction nextLineTerminatorIndex(code: string, start: number): number {\n for (let i = start; i < code.length; i++) {\n if (isLineTerminator(code.charCodeAt(i))) return i;\n }\n return -1;\n}\n\nfunction containsLineTerminator(\n code: string,\n start: number,\n end: number,\n): boolean {\n for (let i = start; i < end; i++) {\n if (isLineTerminator(code.charCodeAt(i))) return true;\n }\n return false;\n}\n\nfunction startsExpressionContinuation(code: string, start: number): boolean {\n switch (code[start]) {\n case \".\":\n case \"+\":\n case \"-\":\n case \"*\":\n case \"/\":\n case \"%\":\n case \"<\":\n case \">\":\n case \"=\":\n case \"!\":\n case \"&\":\n case \"|\":\n case \"^\":\n case \"?\":\n case \":\":\n case \",\":\n case \"[\":\n case \"(\":\n case \"`\":\n return true;\n }\n\n return (\n startsKeywordContinuation(code, start, \"as\") ||\n startsKeywordContinuation(code, start, \"in\") ||\n startsKeywordContinuation(code, start, \"instanceof\") ||\n startsKeywordContinuation(code, start, \"satisfies\")\n );\n}\n\nfunction startsKeywordContinuation(\n code: string,\n start: number,\n keyword: string,\n): boolean {\n if (!code.startsWith(keyword, start)) return false;\n const next = code[start + keyword.length];\n return next === undefined || !/[\\p{ID_Continue}$]/u.test(next);\n}\n\nfunction isSemicolon(char: number): boolean {\n return char === 59;\n}\n\nfunction isLineTerminator(char: number): boolean {\n return char === 10 || char === 13 || char === 0x2028 || char === 0x2029;\n}\n\n/**\n * Rewrites a `\"use generative\"` module for a single build target, keeping only the\n * regions that target needs and pruning the imports the dropped regions used.\n */\nexport function compileGenerative(\n code: string,\n options: CompileOptions,\n): CompileResult {\n const { target, filename } = options;\n\n const ast = parse(code, {\n sourceType: \"module\",\n plugins: parserPlugins,\n });\n\n if (!ast.program.directives.some((d) => d.value.value === DIRECTIVE)) {\n throw new GenerativeCompileError(\n `missing \"${DIRECTIVE}\" directive`,\n filename,\n );\n }\n\n ensureCompilerCompatibleWithCore(ast, filename);\n\n // A module may hold several `defineToolkit(...)` / `defineGenerativeComponents(...)`\n // calls anywhere (e.g. a library built inside `new JSONGenerativeUI(...)` plus\n // the toolkit that exposes it). Tools may reference a `JSONGenerativeUI`\n // instance's `present()`/`promptUser()`, which the library — not this compiler —\n // splits across builds via export conditions; collect those instance names so\n // such entries pass through.\n ensureDefaultExport(ast, filename);\n const generativeInstances = collectGenerativeInstances(ast);\n const interactableToolImports = collectInteractableToolImports(ast);\n const { spreadNames: toolkitSpreadNames, namespaceImports } =\n collectToolkitSpreadNames(ast, filename, createToolkitNameContext());\n\n const flags: TargetFlags = { keptRender: false, keptBackendExecute: false };\n\n traverse(ast, {\n CallExpression(path: NodePath<t.CallExpression>) {\n const callee = path.node.callee;\n const object = t.isObjectExpression(path.node.arguments[0])\n ? path.node.arguments[0]\n : null;\n\n if (t.isIdentifier(callee, { name: COMPONENTS_WRAPPER })) {\n if (!object) {\n throw new GenerativeCompileError(\n `${COMPONENTS_WRAPPER}() takes an inline object literal of components`,\n filename,\n );\n }\n compileComponents(object, target, flags, filename);\n // Unwrap the authoring helper to the bare library object so its import\n // can be pruned.\n path.replaceWith(object);\n path.skip();\n return;\n }\n\n if (t.isIdentifier(callee, { name: TOOLKIT_WRAPPER })) {\n if (!object) {\n throw new GenerativeCompileError(\n `${TOOLKIT_WRAPPER}() takes an inline object literal of tools`,\n filename,\n );\n }\n compileToolkit(\n object,\n target,\n generativeInstances,\n interactableToolImports,\n toolkitSpreadNames,\n namespaceImports,\n flags,\n filename,\n );\n path.replaceWith(object);\n path.skip();\n }\n },\n });\n\n const { keptRender, keptBackendExecute } = flags;\n\n pruneUnused(ast);\n\n // Replace the module directives with the target-appropriate one.\n ast.program.directives = ast.program.directives.filter(\n (d) => d.value.value !== DIRECTIVE && d.value.value !== \"use client\",\n );\n if (target === \"client\" && keptRender) {\n ast.program.directives.unshift(\n t.directive(t.directiveLiteral(\"use client\")),\n );\n }\n if (\n target === \"server\" &&\n keptBackendExecute &&\n (options.injectServerOnly ?? true)\n ) {\n ast.program.body.unshift(\n t.importDeclaration([], t.stringLiteral(\"server-only\")),\n );\n }\n\n const result = generate(\n ast,\n {\n sourceMaps: options.sourceMaps ?? false,\n ...(filename ? { filename } : {}),\n jsescOption: { minimal: true },\n },\n code,\n );\n\n return { code: result.code, map: result.map };\n}\n\ninterface PackageJson {\n name?: string;\n version?: string;\n optionalDevDependencies?: Record<string, string>;\n}\n\nconst checkedCorePackageJsonPaths = new Set<string>();\n\n// This compiler's own version, inlined from package.json at build time. Read via\n// an import (not by walking the filesystem at runtime) so the literal survives\n// being bundled into a host package like `@assistant-ui/metro`, where no\n// standalone `@assistant-ui/x-generative-compiler` sits on disk to walk up to.\nconst COMPILER_VERSION = pkgJson.version;\n\nfunction ensureCompilerCompatibleWithCore(\n ast: t.File,\n filename: string | undefined,\n): void {\n const corePackageJsonPath = resolveCorePackageJson(ast, filename);\n if (\n !corePackageJsonPath ||\n checkedCorePackageJsonPaths.has(corePackageJsonPath)\n ) {\n return;\n }\n\n const corePackageJson = readPackageJson(corePackageJsonPath);\n const range = corePackageJson?.optionalDevDependencies?.[COMPILER_PACKAGE];\n if (!range) {\n checkedCorePackageJsonPaths.add(corePackageJsonPath);\n return;\n }\n\n let compatible = false;\n try {\n compatible = satisfies(COMPILER_VERSION, range, {\n includePrerelease: true,\n });\n } catch {\n throw new GenerativeCompileError(\n `${CORE_PACKAGE}@${corePackageJson.version ?? \"unknown\"} declares an ` +\n `invalid optionalDevDependencies range for ${COMPILER_PACKAGE}: ` +\n JSON.stringify(range),\n filename,\n );\n }\n\n if (!compatible) {\n throw new GenerativeCompileError(\n `${CORE_PACKAGE}@${corePackageJson.version ?? \"unknown\"} requires ` +\n `${COMPILER_PACKAGE} ${range}, but the current compiler is ` +\n `${COMPILER_VERSION}. Update @assistant-ui/next, @assistant-ui/vite, ` +\n \"or @assistant-ui/metro so their compiler satisfies the core package's \" +\n \"optionalDevDependencies range.\",\n filename,\n );\n }\n\n checkedCorePackageJsonPaths.add(corePackageJsonPath);\n}\n\nfunction resolveCorePackageJson(\n ast: t.File,\n filename: string | undefined,\n): string | null {\n for (const packageName of collectImportedDistributionPackages(ast)) {\n const packageJsonPath = resolvePackageJson(packageName, filename);\n if (!packageJsonPath) continue;\n if (packageName === CORE_PACKAGE) return packageJsonPath;\n\n const corePackageJsonPath = resolvePackageJson(\n CORE_PACKAGE,\n packageJsonPath,\n );\n if (corePackageJsonPath) return corePackageJsonPath;\n }\n\n return null;\n}\n\nfunction collectImportedDistributionPackages(ast: t.File): Set<string> {\n const packages = new Set<string>();\n\n for (const statement of ast.program.body) {\n const source =\n (t.isImportDeclaration(statement) ||\n t.isExportNamedDeclaration(statement) ||\n t.isExportAllDeclaration(statement)) &&\n statement.source\n ? statement.source.value\n : null;\n if (!source) continue;\n\n const packageName = packageNameFromSpecifier(source);\n if (packageName) packages.add(packageName);\n }\n\n return packages;\n}\n\nfunction packageNameFromSpecifier(specifier: string): string | null {\n for (const packageName of DISTRIBUTION_PACKAGES) {\n if (specifier === packageName || specifier.startsWith(`${packageName}/`)) {\n return packageName;\n }\n }\n\n return null;\n}\n\nfunction resolvePackageJson(\n packageName: string,\n filename: string | undefined,\n): string | null {\n const requirePath = normalizeRequirePath(filename);\n const require = createRequire(requirePath);\n\n try {\n return findPackageJson(require.resolve(packageName), packageName);\n } catch {\n return findPackageJsonFromNodeModules(packageName, requirePath);\n }\n}\n\nfunction normalizeRequirePath(filename: string | undefined): string {\n return cleanAbsoluteFilename(filename) ?? import.meta.url;\n}\n\n/** Strips a `?query`/`#hash` suffix and returns the path only if it is absolute. */\nfunction cleanAbsoluteFilename(filename: string | undefined): string | null {\n if (!filename) return null;\n const clean = filename.split(/[?#]/, 1)[0]!;\n return nodePath.isAbsolute(clean) ? clean : null;\n}\n\nfunction findPackageJson(\n fromPathOrUrl: string,\n packageName: string,\n): string | null {\n let current = nodePath.dirname(\n fromPathOrUrl.startsWith(\"file:\")\n ? new URL(fromPathOrUrl).pathname\n : nodePath.resolve(fromPathOrUrl),\n );\n\n for (;;) {\n const packageJsonPath = nodePath.join(current, \"package.json\");\n const packageJson = readPackageJson(packageJsonPath);\n if (packageJson?.name === packageName) return packageJsonPath;\n\n const parent = nodePath.dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n\nfunction findPackageJsonFromNodeModules(\n packageName: string,\n fromPathOrUrl: string,\n): string | null {\n const parts = packageName.split(\"/\");\n let current = nodePath.dirname(\n fromPathOrUrl.startsWith(\"file:\")\n ? new URL(fromPathOrUrl).pathname\n : nodePath.resolve(fromPathOrUrl),\n );\n\n for (;;) {\n const packageJsonPath = nodePath.join(\n current,\n \"node_modules\",\n ...parts,\n \"package.json\",\n );\n const packageJson = readPackageJson(packageJsonPath);\n if (packageJson?.name === packageName) return packageJsonPath;\n\n const parent = nodePath.dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n\nfunction readPackageJson(packageJsonPath: string): PackageJson | null {\n if (!existsSync(packageJsonPath)) return null;\n try {\n return JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as PackageJson;\n } catch (error) {\n throw new GenerativeCompileError(\n `could not parse package metadata at ${packageJsonPath}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n}\n\n/**\n * Errors unless the module's default export is the toolkit — a `defineToolkit(...)`\n * call (through `satisfies`/`as`/parens). This is the security boundary: the\n * default export is what the runtime registers, so it must be wrapped (and thus\n * split). A bare `export default { ... }` would ship a backend `execute` to the\n * client even if some *other* `defineToolkit(...)` exists elsewhere in the file.\n */\nfunction ensureDefaultExport(ast: t.File, filename: string | undefined): void {\n const def = ast.program.body.find(\n (stmt): stmt is t.ExportDefaultDeclaration =>\n t.isExportDefaultDeclaration(stmt),\n );\n if (!def) {\n throw new GenerativeCompileError(\"missing a default export\", filename);\n }\n if (!unwrapToToolkitCall(def.declaration)) {\n throw new GenerativeCompileError(\n `the default export must be ${TOOLKIT_WRAPPER}({ ... }) or ` +\n `${MCP_TOOLKIT_WRAPPER}({ ... }) (imported from \"@assistant-ui/react\"); ` +\n \"wrapping is required so a backend `execute` can't be authored in a way \" +\n \"that reaches the client\",\n filename,\n );\n }\n}\n\n/**\n * Unwraps a node through `satisfies`/`as`/parens to a call of the named function,\n * or returns `null`.\n */\nfunction unwrapToCall(node: t.Node, name: string): t.CallExpression | null {\n if (t.isTSSatisfiesExpression(node) || t.isTSAsExpression(node)) {\n return unwrapToCall(node.expression, name);\n }\n if (t.isParenthesizedExpression(node)) {\n return unwrapToCall(node.expression, name);\n }\n if (t.isCallExpression(node) && t.isIdentifier(node.callee, { name })) {\n return node;\n }\n return null;\n}\n\n/**\n * Unwraps a statement to its variable declaration through an `export` wrapper,\n * or returns `null`.\n */\nfunction asVariableDeclaration(\n statement: t.Statement,\n): t.VariableDeclaration | null {\n if (t.isVariableDeclaration(statement)) return statement;\n if (\n t.isExportNamedDeclaration(statement) &&\n t.isVariableDeclaration(statement.declaration)\n ) {\n return statement.declaration;\n }\n return null;\n}\n\n/**\n * Collects the names bound to `new JSONGenerativeUI(...)` (e.g.\n * `const generative = new JSONGenerativeUI({ library })`). A toolkit entry that\n * calls a method on one of these is a generative tool whose halves the library\n * routes by export condition, so it passes through the toolkit pass untouched.\n */\nfunction collectGenerativeInstances(ast: t.File): Set<string> {\n const names = new Set<string>();\n const generativeFactories = collectGenerativeFactoryImports(ast);\n for (const statement of ast.program.body) {\n const variableDeclaration = asVariableDeclaration(statement);\n if (!variableDeclaration) continue;\n for (const declaration of variableDeclaration.declarations) {\n const { id, init } = declaration;\n if (\n t.isIdentifier(id) &&\n t.isNewExpression(init) &&\n t.isIdentifier(init.callee) &&\n generativeFactories.has(init.callee.name)\n ) {\n names.add(id.name);\n }\n }\n }\n return names;\n}\n\nfunction collectGenerativeFactoryImports(ast: t.File): Set<string> {\n const names = new Set<string>();\n for (const statement of ast.program.body) {\n if (\n !t.isImportDeclaration(statement) ||\n statement.source.value !== GENERATIVE_UI_PACKAGE\n ) {\n continue;\n }\n\n for (const specifier of statement.specifiers) {\n if (\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported, { name: GENERATIVE_FACTORY })\n ) {\n names.add(specifier.local.name);\n }\n }\n }\n return names;\n}\n\ntype ToolkitStaticNames = readonly string[] | null;\ntype ToolkitSpreadNames = Map<string, ToolkitStaticNames>;\n\ninterface ToolkitNameContext {\n importedToolkitNamesByFile: Map<string, ToolkitStaticNames | undefined>;\n resolvingImportedToolkitNames: Set<string>;\n}\n\n/**\n * The toolkit spreads a single module's pass can recognize: safe-to-spread\n * bindings plus the namespace imports that point at a generative module. The\n * namespace set is kept separate from {@link ToolkitSpreadNames} so a\n * whole-namespace `...kit` is not mistaken for a safe identifier spread — only\n * the default export crosses the build-split boundary, so a namespace spread is\n * rejected with a specific callout rather than allowed.\n */\ninterface ToolkitSpreadInfo {\n spreadNames: ToolkitSpreadNames;\n namespaceImports: Set<string>;\n}\n\n/**\n * Collects the local names `unstable_interactableTool` is imported under from a\n * distribution package, so toolkit entries calling it can be recognized\n * (and a same-named local function can't smuggle an arbitrary call through).\n */\nfunction collectInteractableToolImports(ast: t.File): Set<string> {\n const names = new Set<string>();\n for (const statement of ast.program.body) {\n if (!t.isImportDeclaration(statement)) continue;\n if (!packageNameFromSpecifier(statement.source.value)) continue;\n for (const specifier of statement.specifiers) {\n if (\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported, { name: INTERACTABLE_TOOL_FACTORY })\n ) {\n names.add(specifier.local.name);\n }\n }\n }\n return names;\n}\n\nfunction createToolkitNameContext(): ToolkitNameContext {\n return {\n importedToolkitNamesByFile: new Map(),\n resolvingImportedToolkitNames: new Set(),\n };\n}\n\n/**\n * The inline config of an `unstable_interactableTool({ ... })` toolkit entry, or `null`\n * when the entry is some other expression.\n */\nfunction interactableToolConfig(\n value: t.Node,\n imports: Set<string>,\n): t.ObjectExpression | null {\n return t.isCallExpression(value) &&\n t.isIdentifier(value.callee) &&\n imports.has(value.callee.name) &&\n t.isObjectExpression(value.arguments[0])\n ? value.arguments[0]\n : null;\n}\n\n/**\n * Toolkit identifiers that are safe to spread into a `defineToolkit({ ... })`,\n * paired with the static tool names they contain. A `null` name list means the\n * spread is safe, but its names are not statically known for duplicate checks.\n *\n * Two kinds qualify:\n *\n * - A local variable whose initializer is visible to this compiler pass: a\n * `defineToolkit(...)` binding is compiled in-place before a later spread\n * reads it, and `defineMcpToolkit(...)` entries can't contain executable code.\n * - The default import of another `\"use generative\"` module: that module is\n * split per-target by its own compiler pass, so spreading its default-exported\n * toolkit can't leak a backend `execute` to the client. Only the default\n * export crosses the generative-module boundary, so named imports don't\n * qualify — they would be `undefined` once that module is build-split.\n *\n * A namespace import (`import * as kit from \"...\"`) of a generative module is\n * tracked separately in `namespaceImports` so a `...kit` / `...kit.default`\n * spread can be rejected with a specific callout: only the default export\n * crosses the boundary, so a namespace spread is never safe.\n */\nfunction collectToolkitSpreadNames(\n ast: t.File,\n filename: string | undefined,\n context: ToolkitNameContext,\n): ToolkitSpreadInfo {\n const spreadNames: ToolkitSpreadNames = new Map();\n const namespaceImports = new Set<string>();\n const localToolkitCalls = new Map<string, t.CallExpression>();\n\n for (const statement of ast.program.body) {\n const localDeclaration = asVariableDeclaration(statement);\n if (localDeclaration) {\n for (const declaration of localDeclaration.declarations) {\n const { id, init } = declaration;\n if (t.isIdentifier(id) && init) {\n const toolkitCall = unwrapToToolkitCall(init);\n if (toolkitCall) localToolkitCalls.set(id.name, toolkitCall);\n }\n }\n continue;\n }\n\n if (t.isImportDeclaration(statement)) {\n const defaultSpecifier = statement.specifiers.find(\n (specifier): specifier is t.ImportDefaultSpecifier =>\n t.isImportDefaultSpecifier(specifier),\n );\n const namespaceSpecifier = statement.specifiers.find(\n (specifier): specifier is t.ImportNamespaceSpecifier =>\n t.isImportNamespaceSpecifier(specifier),\n );\n if (!defaultSpecifier && !namespaceSpecifier) continue;\n\n const names = getGenerativeImportToolkitNames(\n statement.source.value,\n filename,\n context,\n );\n if (names === undefined) continue;\n\n if (defaultSpecifier) spreadNames.set(defaultSpecifier.local.name, names);\n if (namespaceSpecifier)\n namespaceImports.add(namespaceSpecifier.local.name);\n }\n }\n\n const resolveLocal = (name: string): ToolkitStaticNames | undefined => {\n if (spreadNames.has(name)) return spreadNames.get(name);\n\n const call = localToolkitCalls.get(name);\n if (!call) return undefined;\n\n const object = t.isObjectExpression(call.arguments[0])\n ? call.arguments[0]\n : null;\n const names = object\n ? collectToolkitObjectNames(object, spreadNames)\n : null;\n const publicNames = uniqueToolkitNames(names);\n\n spreadNames.set(name, publicNames);\n return publicNames;\n };\n\n for (const name of localToolkitCalls.keys()) {\n resolveLocal(name);\n }\n\n return { spreadNames, namespaceImports };\n}\n\nconst MODULE_EXTENSIONS = [\n \".ts\",\n \".tsx\",\n \".mts\",\n \".cts\",\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n] as const;\n\n/** Extensions a specifier may carry that actually map to a TS source file. */\nconst REWRITABLE_JS_EXTENSIONS = new Set([\".js\", \".jsx\", \".mjs\", \".cjs\"]);\n\n/**\n * Reads the static tool names from the default export of an imported\n * `\"use generative\"` module. Relative specifiers and `tsconfig` path aliases\n * (e.g. `@/tools`) are resolved; anything else (a bare package, an unresolvable\n * alias) is treated as non-generative, and thus an unsafe spread.\n */\nfunction getGenerativeImportToolkitNames(\n source: string,\n filename: string | undefined,\n context: ToolkitNameContext,\n): ToolkitStaticNames | undefined {\n const cleanFilename = cleanAbsoluteFilename(filename);\n if (!cleanFilename) return undefined;\n\n const resolved = resolveImportedModuleFile(source, cleanFilename);\n if (!resolved) return undefined;\n\n if (context.importedToolkitNamesByFile.has(resolved)) {\n return context.importedToolkitNamesByFile.get(resolved);\n }\n if (context.resolvingImportedToolkitNames.has(resolved)) return null;\n\n let code: string;\n try {\n code = readFileSync(resolved, \"utf8\");\n } catch {\n context.importedToolkitNamesByFile.set(resolved, undefined);\n return undefined;\n }\n\n if (!isGenerativeModule(code)) {\n context.importedToolkitNamesByFile.set(resolved, undefined);\n return undefined;\n }\n\n context.resolvingImportedToolkitNames.add(resolved);\n try {\n const importedAst = parse(code, {\n sourceType: \"module\",\n plugins: parserPlugins,\n });\n const names = getDefaultExportToolkitNames(importedAst, resolved, context);\n context.importedToolkitNamesByFile.set(resolved, names);\n return names;\n } catch (error) {\n if (error instanceof GenerativeCompileError) throw error;\n context.importedToolkitNamesByFile.set(resolved, null);\n return null;\n } finally {\n context.resolvingImportedToolkitNames.delete(resolved);\n }\n}\n\nfunction getDefaultExportToolkitNames(\n ast: t.File,\n filename: string | undefined,\n context: ToolkitNameContext,\n): ToolkitStaticNames {\n const def = ast.program.body.find(\n (stmt): stmt is t.ExportDefaultDeclaration =>\n t.isExportDefaultDeclaration(stmt),\n );\n if (!def) return null;\n\n const toolkitCall = unwrapToToolkitCall(def.declaration);\n if (!toolkitCall || !t.isObjectExpression(toolkitCall.arguments[0])) {\n return null;\n }\n\n const { spreadNames } = collectToolkitSpreadNames(ast, filename, context);\n return uniqueToolkitNames(\n collectToolkitObjectNames(toolkitCall.arguments[0], spreadNames),\n );\n}\n\n/** Resolves an import specifier (relative or `tsconfig`-aliased) to a file on disk. */\nfunction resolveImportedModuleFile(\n source: string,\n fromFilename: string,\n): string | null {\n if (source.startsWith(\".\")) {\n const base = nodePath.resolve(nodePath.dirname(fromFilename), source);\n return resolveModuleFileAtPath(base);\n }\n return resolveAliasImport(source, fromFilename);\n}\n\n/**\n * Resolves a candidate module path, trying TS/JS extensions then index files. A\n * specifier may carry a `.js`-family extension that maps to a `.ts`/`.tsx`\n * source (TypeScript's `bundler`/`nodenext` resolution), so the extension is\n * dropped before probing.\n */\nfunction resolveModuleFileAtPath(base: string): string | null {\n const ext = nodePath.extname(base);\n if (ext && existsSync(base)) return base;\n\n const stem = REWRITABLE_JS_EXTENSIONS.has(ext)\n ? base.slice(0, -ext.length)\n : base;\n\n for (const candidateExt of MODULE_EXTENSIONS) {\n const candidate = `${stem}${candidateExt}`;\n if (existsSync(candidate)) return candidate;\n }\n for (const candidateExt of MODULE_EXTENSIONS) {\n const candidate = nodePath.join(base, `index${candidateExt}`);\n if (existsSync(candidate)) return candidate;\n }\n return null;\n}\n\ninterface TsconfigAliases {\n /** Absolute directory that `paths` targets resolve against. */\n baseDir: string;\n paths: Record<string, string[]>;\n}\n\n/** Resolves a `tsconfig` path alias (e.g. `@/tools/x`) to a file on disk. */\nfunction resolveAliasImport(\n source: string,\n fromFilename: string,\n): string | null {\n const tsconfig = loadTsconfigAliases(nodePath.dirname(fromFilename));\n if (!tsconfig) return null;\n\n // TypeScript matches the most specific key first: an exact (wildcard-free) key\n // beats a wildcard one, and a longer static prefix beats a shorter one.\n const patterns = Object.entries(tsconfig.paths).sort(\n ([a], [b]) => aliasSpecificity(b) - aliasSpecificity(a),\n );\n\n for (const [pattern, targets] of patterns) {\n const matched = matchAliasPattern(pattern, source);\n if (matched === null) continue;\n\n for (const target of targets) {\n const specifier = substituteAliasWildcard(target, matched);\n const file = resolveModuleFileAtPath(\n nodePath.resolve(tsconfig.baseDir, specifier),\n );\n if (file) return file;\n }\n }\n return null;\n}\n\n/** Ranks a `paths` key: an exact key outranks any wildcard; longer prefixes win. */\nfunction aliasSpecificity(pattern: string): number {\n const star = pattern.indexOf(\"*\");\n return star === -1 ? pattern.length + 1 : star;\n}\n\n/** Substitutes the single `*` in a `paths` target with the matched text. */\nfunction substituteAliasWildcard(target: string, matched: string): string {\n const star = target.indexOf(\"*\");\n if (star === -1) return target;\n return target.slice(0, star) + matched + target.slice(star + 1);\n}\n\n/**\n * Matches an import specifier against a `tsconfig` `paths` key. Returns the text\n * captured by the key's `*` (or `\"\"` for an exact, wildcard-free key), or `null`\n * when the specifier doesn't match.\n */\nfunction matchAliasPattern(pattern: string, source: string): string | null {\n const star = pattern.indexOf(\"*\");\n if (star === -1) return pattern === source ? \"\" : null;\n\n const prefix = pattern.slice(0, star);\n const suffix = pattern.slice(star + 1);\n if (\n source.length >= prefix.length + suffix.length &&\n source.startsWith(prefix) &&\n source.endsWith(suffix)\n ) {\n return source.slice(prefix.length, source.length - suffix.length);\n }\n return null;\n}\n\n/**\n * Memoizes resolved aliases per start directory. The compiler runs once per\n * file across a build, so without this every aliased spread re-walks and\n * re-parses the same `tsconfig.json`. Process-lifetime, like\n * `checkedCorePackageJsonPaths`.\n */\nconst tsconfigAliasesByDir = new Map<string, TsconfigAliases | null>();\n\n/** Walks up from a directory to the nearest `tsconfig.json` that declares `paths`. */\nfunction loadTsconfigAliases(fromDir: string): TsconfigAliases | null {\n const cached = tsconfigAliasesByDir.get(fromDir);\n if (cached !== undefined) return cached;\n\n let aliases: TsconfigAliases | null = null;\n let dir = fromDir;\n for (;;) {\n const tsconfigPath = nodePath.join(dir, \"tsconfig.json\");\n if (existsSync(tsconfigPath)) {\n aliases = readTsconfigAliases(tsconfigPath, new Set());\n if (aliases) break;\n }\n const parent = nodePath.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n tsconfigAliasesByDir.set(fromDir, aliases);\n return aliases;\n}\n\n/** Reads `baseUrl`/`paths` from a tsconfig, following a single `extends` chain. */\nfunction readTsconfigAliases(\n tsconfigPath: string,\n seen: Set<string>,\n): TsconfigAliases | null {\n if (seen.has(tsconfigPath)) return null;\n seen.add(tsconfigPath);\n\n let config: {\n extends?: string | string[];\n compilerOptions?: { baseUrl?: string; paths?: Record<string, string[]> };\n } | null;\n try {\n config = parseJsonc(readFileSync(tsconfigPath, \"utf8\"));\n } catch {\n return null;\n }\n if (!config) return null;\n\n const configDir = nodePath.dirname(tsconfigPath);\n const { baseUrl, paths } = config.compilerOptions ?? {};\n\n if (paths) {\n return {\n baseDir: baseUrl ? nodePath.resolve(configDir, baseUrl) : configDir,\n paths,\n };\n }\n\n // `extends` may be a string or (TS 5.0+) a string array; later entries take\n // precedence, so try them last-first. Parsed from untrusted JSONC, so the\n // array case is a real runtime shape, not just a type.\n const extendsList = Array.isArray(config.extends)\n ? config.extends\n : config.extends\n ? [config.extends]\n : [];\n for (let i = extendsList.length - 1; i >= 0; i--) {\n const entry = extendsList[i];\n if (typeof entry !== \"string\") continue;\n const extended = resolveExtendedTsconfig(entry, configDir);\n if (extended) {\n const aliases = readTsconfigAliases(extended, seen);\n if (aliases) return aliases;\n }\n }\n return null;\n}\n\n/** Resolves a tsconfig `extends` value (relative path or installed package). */\nfunction resolveExtendedTsconfig(\n extendsValue: string,\n configDir: string,\n): string | null {\n if (extendsValue.startsWith(\".\")) {\n const base = nodePath.resolve(configDir, extendsValue);\n const candidates =\n nodePath.extname(base) === \".json\" ? [base] : [`${base}.json`, base];\n return candidates.find((candidate) => existsSync(candidate)) ?? null;\n }\n try {\n return createRequire(nodePath.join(configDir, \"package.json\")).resolve(\n extendsValue.endsWith(\".json\") ? extendsValue : `${extendsValue}.json`,\n );\n } catch {\n return null;\n }\n}\n\n/** Parses JSON with `//` and block comments and trailing commas stripped (tsconfig is JSONC). */\nfunction parseJsonc(text: string): any {\n const withoutComments = text.replace(\n /\"(?:[^\"\\\\]|\\\\.)*\"|\\/\\/[^\\n\\r]*|\\/\\*[\\s\\S]*?\\*\\//g,\n (match) => (match.startsWith('\"') ? match : \"\"),\n );\n const withoutTrailingCommas = withoutComments.replace(/,(\\s*[}\\]])/g, \"$1\");\n return JSON.parse(withoutTrailingCommas);\n}\n\nfunction unwrapToToolkitCall(node: t.Node): t.CallExpression | null {\n return (\n unwrapToCall(node, TOOLKIT_WRAPPER) ??\n unwrapToCall(node, MCP_TOOLKIT_WRAPPER)\n );\n}\n\nfunction collectToolkitObjectNames(\n object: t.ObjectExpression,\n toolkitSpreadNames: ToolkitSpreadNames,\n): ToolkitStaticNames {\n const names: string[] = [];\n\n for (const entry of object.properties) {\n const entryNames = toolkitEntryNames(entry, toolkitSpreadNames);\n if (!entryNames) return null;\n names.push(...entryNames);\n }\n\n return names;\n}\n\nfunction uniqueToolkitNames(names: ToolkitStaticNames): ToolkitStaticNames {\n return names ? [...new Set(names)] : names;\n}\n\nfunction toolkitEntryNames(\n entry: t.ObjectExpression[\"properties\"][number],\n toolkitSpreadNames: ToolkitSpreadNames,\n): ToolkitStaticNames {\n if (t.isSpreadElement(entry)) {\n if (t.isIdentifier(entry.argument)) {\n return toolkitSpreadNames.get(entry.argument.name) ?? null;\n }\n\n const directMcpToolkit = unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER);\n if (\n directMcpToolkit &&\n t.isObjectExpression(directMcpToolkit.arguments[0])\n ) {\n return collectToolkitObjectNames(\n directMcpToolkit.arguments[0],\n toolkitSpreadNames,\n );\n }\n\n return null;\n }\n\n if (t.isObjectProperty(entry) || t.isObjectMethod(entry)) {\n const name = memberName(entry.key, entry.computed);\n return name ? [name] : [];\n }\n\n return [];\n}\n\nfunction toolkitEntrySourceLabel(entry: Entry): string {\n if (t.isSpreadElement(entry)) {\n if (t.isIdentifier(entry.argument)) return `...${entry.argument.name}`;\n if (unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER)) {\n return `...${MCP_TOOLKIT_WRAPPER}(...)`;\n }\n return \"...\";\n }\n\n if (t.isObjectProperty(entry) || t.isObjectMethod(entry)) {\n const line = entry.loc?.start.line;\n return line === undefined\n ? \"inline property\"\n : `inline property (line ${line})`;\n }\n\n return \"inline property\";\n}\n\nfunction warnDuplicateToolkitNames(\n object: t.ObjectExpression,\n toolkitSpreadNames: ToolkitSpreadNames,\n filename: string | undefined,\n): void {\n const sourcesByToolName = new Map<string, string[]>();\n for (const entry of object.properties) {\n const entryNames = toolkitEntryNames(entry, toolkitSpreadNames);\n if (!entryNames) continue;\n const source = toolkitEntrySourceLabel(entry);\n for (const name of entryNames) {\n const sources = sourcesByToolName.get(name);\n if (sources) sources.push(source);\n else sourcesByToolName.set(name, [source]);\n }\n }\n\n for (const [name, sources] of sourcesByToolName) {\n const winner = sources.at(-1);\n const overridden = sources.slice(0, -1);\n if (winner === undefined || overridden.length === 0) continue;\n console.warn(\n new GenerativeCompileError(\n `Duplicate tool name \"${name}\": ${winner} overrides ` +\n `${overridden.join(\", \")}. ` +\n \"JavaScript object spread keeps the last definition.\",\n filename,\n ).message,\n );\n }\n}\n\nfunction isSafeToolkitSpread(\n entry: t.SpreadElement,\n toolkitSpreadNames: ToolkitSpreadNames,\n): boolean {\n if (t.isIdentifier(entry.argument)) {\n return toolkitSpreadNames.has(entry.argument.name);\n }\n\n const directMcpToolkit = unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER);\n return (\n !!directMcpToolkit && t.isObjectExpression(directMcpToolkit.arguments[0])\n );\n}\n\nfunction genericUnsafeToolkitEntryMessage(): string {\n return (\n \"each tool must be an inline object literal (`name: { ... }`) or a \" +\n \"compiler-visible toolkit spread / generative tool (e.g. \" +\n \"`...defineMcpToolkit(...)`, `...baseToolkit`, \" +\n \"`generative.present()`, or `unstable_interactableTool(...)`) so its \" +\n \"`execute` can be routed\"\n );\n}\n\nfunction describeUnsafeToolkitEntry(entry: Entry): string {\n if (!t.isObjectProperty(entry)) return genericUnsafeToolkitEntryMessage();\n\n const toolName = memberName(entry.key, entry.computed);\n const raw = entryRawValue(entry);\n if (!toolName || !raw) return genericUnsafeToolkitEntryMessage();\n\n return (\n `tool \"${toolName}\" cannot be \\`${generate(raw).code}\\`; use an inline ` +\n `object literal (\\`${toolName}: { ... }\\`) or a compiler-visible toolkit ` +\n \"spread / generative tool so its `execute` can be routed\"\n );\n}\n\nfunction namespaceToolkitSpreadMessage(): string {\n return (\n 'a namespace import (`import * as kit from \"...\"`) can\\'t be spread into ' +\n `${TOOLKIT_WRAPPER}({ ... }); only a generative module's default export ` +\n \"crosses the build-split boundary, so import it as a default \" +\n '(`import kit from \"...\"`) and spread `...kit` instead'\n );\n}\n\n/** The `kit` in `...kit` or `...kit.default`, or null for a computed/opaque base. */\nfunction namespaceSpreadBaseName(argument: t.Expression): string | null {\n if (t.isIdentifier(argument)) return argument.name;\n if (\n t.isMemberExpression(argument) &&\n !argument.computed &&\n t.isIdentifier(argument.object)\n ) {\n return argument.object.name;\n }\n return null;\n}\n\n/** The `JSONGenerativeUI` methods that produce a split-by-condition tool. */\nconst GENERATIVE_TOOL_METHODS = new Set([\"present\", \"promptUser\"]);\n\n/**\n * Whether a toolkit entry's value is a call to a tool-producing method on a\n * collected `JSONGenerativeUI` instance (`generative.present()`), which passes\n * through. The method name is checked too, so a typo like `generative.presnt()`\n * is a compile error here rather than a pass-through that fails at runtime.\n */\nfunction isGenerativeToolEntry(value: t.Node, instances: Set<string>): boolean {\n return (\n t.isCallExpression(value) &&\n t.isMemberExpression(value.callee) &&\n !value.callee.computed &&\n t.isIdentifier(value.callee.object) &&\n instances.has(value.callee.object.name) &&\n t.isIdentifier(value.callee.property) &&\n GENERATIVE_TOOL_METHODS.has(value.callee.property.name)\n );\n}\n\n/**\n * Splits a `defineGenerativeComponents({ ... })` library for a build target:\n * a component's `render` (and the client imports it alone uses) is dropped on\n * the server; `properties`/`description` stay on both, since they drive the tool\n * schema either way. Mutates the object in place.\n */\nfunction compileComponents(\n object: t.ObjectExpression,\n target: Target,\n flags: TargetFlags,\n filename: string | undefined,\n): void {\n for (const entry of object.properties) {\n const value = entryValue(entry);\n if (!value) {\n throw new GenerativeCompileError(\n `each component in ${COMPONENTS_WRAPPER}() must be an inline object ` +\n \"literal (`name: { ... }`) so its `render` can be routed\",\n filename,\n );\n }\n if (!findMember(value, \"render\")) continue;\n // The client keeps `render` (and so needs the module marked `\"use client\"`);\n // the server drops it, since only the schema reaches the model there.\n if (target === \"client\") flags.keptRender = true;\n else removeMember(value, \"render\");\n }\n}\n\n/**\n * Splits a `defineToolkit({ ... })` for a build target. Each inline tool is\n * routed by inferred type (see the per-entry logic); a generative entry like\n * `generative.present()` passes through, the library having already split it.\n * Mutates the object in place and records outcomes in {@link TargetFlags}.\n */\nfunction compileToolkit(\n object: t.ObjectExpression,\n target: Target,\n instances: Set<string>,\n interactableToolImports: Set<string>,\n toolkitSpreadNames: ToolkitSpreadNames,\n namespaceImports: Set<string>,\n flags: TargetFlags,\n filename: string | undefined,\n): void {\n // Split builds compile both targets; emit target-independent warnings from\n // the client pass so each duplicate is logged once.\n if (target === \"client\") {\n warnDuplicateToolkitNames(object, toolkitSpreadNames, filename);\n }\n\n const nextProperties: t.ObjectExpression[\"properties\"] = [];\n\n for (const entry of object.properties) {\n const value = entryValue(entry);\n if (!value) {\n if (\n t.isSpreadElement(entry) &&\n isSafeToolkitSpread(entry, toolkitSpreadNames)\n ) {\n nextProperties.push(entry);\n continue;\n }\n // A generative tool (`generative.present()`) is split by the library's\n // export conditions, so it is safe to keep verbatim. Anything else — a\n // method or opaque call like `makeTool()` — can't be analyzed, so its\n // `execute` could reach the client unstripped.\n const raw = entryRawValue(entry);\n if (raw && isGenerativeToolEntry(raw, instances)) {\n nextProperties.push(entry);\n continue;\n }\n const config =\n raw && interactableToolConfig(raw, interactableToolImports);\n if (config) {\n if (target === \"client\") flags.keptRender = true;\n else removeMember(config, \"render\");\n nextProperties.push(entry);\n continue;\n }\n if (t.isSpreadElement(entry)) {\n const namespaceBase = namespaceSpreadBaseName(entry.argument);\n if (namespaceBase && namespaceImports.has(namespaceBase)) {\n throw new GenerativeCompileError(\n namespaceToolkitSpreadMessage(),\n filename,\n );\n }\n }\n throw new GenerativeCompileError(\n describeUnsafeToolkitEntry(entry),\n filename,\n );\n }\n\n // Nature is inferred from `execute` (see inferToolType), not an authored\n // `type`. The resolved type is written back below so the runtime keeps it.\n const toolName = t.isObjectProperty(entry)\n ? memberName(entry.key, entry.computed)\n : undefined;\n const execute = findMember(value, \"execute\");\n const isStub = execute ? executeIsStubTool(execute) : false;\n const isExternal = execute ? executeIsExternalTool(execute) : false;\n const type = inferToolType(value, toolName, filename);\n const hasRender = !!findMember(value, \"render\");\n const hasRenderText = !!findMember(value, \"renderText\");\n\n if (type === \"frontend\" && !hasRender && !hasRenderText) {\n throw new GenerativeCompileError(\n `${typedToolSubject(\"frontend\", toolName)} must declare a ` +\n \"`render` or `renderText` \" +\n \"(it has no server execute to show otherwise)\",\n filename,\n );\n }\n\n if (type === \"human\" && !hasRender) {\n throw new GenerativeCompileError(\n `${typedToolSubject(\"human\", toolName)} must declare a ` +\n \"`render` so it can collect input\",\n filename,\n );\n }\n\n if (type === \"provider\" && execute) {\n applyProviderToolConfig(value, execute, toolName, filename);\n }\n\n if (isExternal) {\n if (!hasRender && !hasRenderText) {\n throw new GenerativeCompileError(\n `${typedToolSubject(\"external\", toolName)} must declare a ` +\n \"`render` or `renderText` \" +\n \"(assistant-ui only renders calls for tools defined elsewhere)\",\n filename,\n );\n }\n if (target === \"server\") continue;\n stripExternalToolMetadata(value);\n }\n\n if (target === \"client\") {\n // A non-stub frontend execute stays (its `\"use client\"` marker is no longer needed\n // once the module is client); backend, sentinel, and stub executes are dropped.\n if (execute && type === \"frontend\" && !isStub) stripUseClient(execute);\n else if (execute) removeMember(value, \"execute\");\n if (hasRender || hasRenderText) flags.keptRender = true;\n } else {\n // server: render is never needed; only a non-external backend execute survives.\n if (hasRender) removeMember(value, \"render\");\n if (hasRenderText) removeMember(value, \"renderText\");\n if (execute) {\n if (type === \"backend\" && !isExternal) flags.keptBackendExecute = true;\n else removeMember(value, \"execute\");\n }\n }\n\n setToolType(value, type);\n setBackendDefault(value, target, type);\n nextProperties.push(entry);\n }\n\n object.properties = nextProperties;\n}\n\nfunction applyProviderToolConfig(\n object: t.ObjectExpression,\n execute: t.ObjectProperty | t.ObjectMethod,\n toolName: string | undefined,\n filename: string | undefined,\n): void {\n if (\n !t.isObjectProperty(execute) ||\n !t.isCallExpression(execute.value) ||\n execute.value.arguments.length !== 1 ||\n !t.isObjectExpression(execute.value.arguments[0])\n ) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` must receive an inline object literal\",\n filename,\n );\n }\n\n const existingNames = new Set(\n object.properties.flatMap((prop) => {\n if (!t.isObjectProperty(prop) && !t.isObjectMethod(prop)) return [];\n const name = memberName(prop.key, prop.computed);\n return name ? [name] : [];\n }),\n );\n const configNames = new Set<string>();\n\n for (const prop of execute.value.arguments[0].properties) {\n if (!t.isObjectProperty(prop)) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` config can only contain object properties\",\n filename,\n );\n }\n const name = memberName(prop.key, prop.computed);\n if (!name) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` config can only contain static property names\",\n filename,\n );\n }\n if (\n t.isFunctionExpression(prop.value) ||\n t.isArrowFunctionExpression(prop.value)\n ) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` config cannot contain function-valued properties\",\n filename,\n );\n }\n if (existingNames.has(name) || configNames.has(name)) {\n const toolLabel = toolName ? ` for \"${toolName}\"` : \"\";\n throw new GenerativeCompileError(\n `\\`providerTool(...)\\` config${toolLabel} duplicates \"${name}\"`,\n filename,\n );\n }\n configNames.add(name);\n object.properties.push(prop);\n }\n}\n\ntype Entry = t.ObjectExpression[\"properties\"][number];\n\n/** The raw AST value of an entry (any expression), or null for spreads/methods. */\nfunction entryRawValue(entry: Entry): t.Expression | null {\n if (t.isObjectProperty(entry) && t.isExpression(entry.value)) {\n return entry.value;\n }\n return null;\n}\n\nfunction entryValue(entry: Entry): t.ObjectExpression | null {\n if (t.isObjectProperty(entry) && t.isObjectExpression(entry.value)) {\n return entry.value;\n }\n return null;\n}\n\n/** A member of an entry object: `render`/`execute`/`type`, as property or method. */\nfunction findMember(\n object: t.ObjectExpression,\n name: string,\n): t.ObjectProperty | t.ObjectMethod | undefined {\n return object.properties.find(\n (p): p is t.ObjectProperty | t.ObjectMethod =>\n (t.isObjectProperty(p) || t.isObjectMethod(p)) &&\n memberName(p.key, p.computed) === name,\n );\n}\n\nfunction removeMember(object: t.ObjectExpression, name: string): void {\n object.properties = object.properties.filter(\n (p) =>\n !(\n (t.isObjectProperty(p) || t.isObjectMethod(p)) &&\n memberName(p.key, p.computed) === name\n ),\n );\n}\n\n/** The `BlockStatement` body of an `execute` member, if it has one. */\nfunction executeBody(\n member: t.ObjectProperty | t.ObjectMethod,\n): t.BlockStatement | undefined {\n if (t.isObjectMethod(member)) return member.body;\n const value = member.value;\n if (\n (t.isArrowFunctionExpression(value) || t.isFunctionExpression(value)) &&\n t.isBlockStatement(value.body)\n ) {\n return value.body;\n }\n return undefined;\n}\n\n/** Whether an `execute` opts into the client via a leading `\"use client\"`. */\nfunction executeIsClient(member: t.ObjectProperty | t.ObjectMethod): boolean {\n return !!executeBody(member)?.directives.some(\n (d) => d.value.value === \"use client\",\n );\n}\n\nfunction executeIsSentinel(\n member: t.ObjectProperty | t.ObjectMethod,\n name: string,\n): boolean {\n return (\n t.isObjectProperty(member) &&\n t.isCallExpression(member.value) &&\n t.isIdentifier(member.value.callee, { name })\n );\n}\n\n/** Whether an `execute` is the human-in-the-loop sentinel. */\nfunction executeIsHumanTool(\n member: t.ObjectProperty | t.ObjectMethod,\n): boolean {\n return (\n executeIsSentinel(member, \"humanTool\") ||\n executeIsSentinel(member, \"hitlTool\") ||\n executeIsSentinel(member, \"hitl\")\n );\n}\n\n/** Whether an `execute` is the provider-tool sentinel. */\nfunction executeIsProviderTool(\n member: t.ObjectProperty | t.ObjectMethod,\n): boolean {\n return executeIsSentinel(member, \"providerTool\");\n}\n\n/** Whether an `execute` is the local override sentinel. */\nfunction executeIsStubTool(member: t.ObjectProperty | t.ObjectMethod): boolean {\n return executeIsSentinel(member, \"stubTool\");\n}\n\n/** Whether an `execute` is the externally-defined backend tool sentinel. */\nfunction executeIsExternalTool(\n member: t.ObjectProperty | t.ObjectMethod,\n): boolean {\n return executeIsSentinel(member, \"externalTool\");\n}\n\n/** Drops the `\"use client\"` directive from an `execute` body (kept frontend). */\nfunction stripUseClient(member: t.ObjectProperty | t.ObjectMethod): void {\n const body = executeBody(member);\n if (body) {\n body.directives = body.directives.filter(\n (d) => d.value.value !== \"use client\",\n );\n }\n}\n\n/**\n * The tool's nature, inferred from its (mandatory) `execute` rather than an\n * authored `type`: `humanTool()` → `human`; `providerTool(...)` → `provider`;\n * `stubTool()` → `frontend`; `externalTool()` → `backend`; `\"use client\"` →\n * `frontend`; otherwise `backend`.\n * The loader writes the result back as a `type` field (see {@link setToolType})\n * so the runtime keeps it.\n */\nfunction inferToolType(\n object: t.ObjectExpression,\n toolName: string | undefined,\n filename: string | undefined,\n): ToolType {\n const execute = findMember(object, \"execute\");\n if (!execute) {\n throw new GenerativeCompileError(\n `${toolSubject(toolName)} must declare an \\`execute\\`; use ` +\n \"`humanTool()` for a human-in-the-loop tool\",\n filename,\n );\n }\n if (executeIsHumanTool(execute)) return \"human\";\n if (executeIsProviderTool(execute)) return \"provider\";\n if (executeIsStubTool(execute)) return \"frontend\";\n if (executeIsExternalTool(execute)) return \"backend\";\n return executeIsClient(execute) ? \"frontend\" : \"backend\";\n}\n\nfunction toolSubject(toolName: string | undefined): string {\n return toolName ? `tool \"${toolName}\"` : \"every tool\";\n}\n\nfunction typedToolSubject(type: string, toolName: string | undefined): string {\n if (toolName) return `${type} tool \"${toolName}\"`;\n const article = /^[aeiou]/i.test(type) ? \"an\" : \"a\";\n return `${article} ${type} tool`;\n}\n\nfunction stripExternalToolMetadata(object: t.ObjectExpression): void {\n // Mirror BackendTool's forbidden metadata fields: execute is stripped by the\n // main routing loop, while streamCall is also removed because there is no\n // assistant-ui executor to stream from.\n removeMember(object, \"description\");\n removeMember(object, \"parameters\");\n removeMember(object, \"disabled\");\n removeMember(object, \"toModelOutput\");\n removeMember(object, \"experimental_onSchemaValidationError\");\n removeMember(object, \"providerOptions\");\n removeMember(object, \"streamCall\");\n}\n\n/** Writes the resolved `type` back onto the tool object (replacing any author's). */\nfunction setToolType(object: t.ObjectExpression, type: ToolType): void {\n removeMember(object, \"type\");\n // Append (not prepend) so the inferred type wins over any earlier spread.\n object.properties.push(\n t.objectProperty(t.identifier(\"type\"), t.stringLiteral(type)),\n );\n}\n\nfunction setBackendDefault(\n object: t.ObjectExpression,\n target: Target,\n type: ToolType,\n): void {\n // Always strip any hand-authored marker first; only re-add it for client\n // frontend/human tools whose schema is already known by the backend.\n removeMember(object, \"unstable_backendDefault\");\n if (target !== \"client\" || (type !== \"frontend\" && type !== \"human\")) return;\n\n object.properties.push(\n t.objectProperty(\n t.identifier(\"unstable_backendDefault\"),\n t.objectExpression([\n t.objectProperty(t.identifier(\"parameters\"), t.booleanLiteral(true)),\n ]),\n ),\n );\n}\n\nfunction memberName(\n key: t.Node,\n computed: boolean | undefined,\n): string | undefined {\n if (computed) return undefined;\n if (t.isIdentifier(key)) return key.name;\n if (t.isStringLiteral(key)) return key.value;\n return undefined;\n}\n\n/**\n * Removes declarations and import specifiers left unreferenced after region\n * removal, to a fixpoint (a dropped helper frees what it used). Keeps exports,\n * side-effect imports, and possibly-side-effectful initializers.\n */\nfunction pruneUnused(ast: t.File): void {\n const hadSpecifiers = new WeakSet<t.ImportDeclaration>();\n for (const stmt of ast.program.body) {\n if (t.isImportDeclaration(stmt) && stmt.specifiers.length > 0) {\n hadSpecifiers.add(stmt);\n }\n }\n\n let removedSomething = true;\n while (removedSomething) {\n removedSomething = false;\n traverse(ast, {\n Program(path: NodePath<t.Program>) {\n path.scope.crawl();\n const isUnused = (name: string): boolean => {\n const binding = path.scope.getBinding(name);\n return !!binding && !binding.referenced;\n };\n\n path.node.body = path.node.body.filter((stmt) => {\n if (\n (t.isFunctionDeclaration(stmt) || t.isClassDeclaration(stmt)) &&\n stmt.id &&\n isUnused(stmt.id.name)\n ) {\n removedSomething = true;\n return false;\n }\n if (t.isVariableDeclaration(stmt)) {\n stmt.declarations = stmt.declarations.filter((decl) => {\n // Handles destructuring too: drop the declarator only when *every*\n // bound name is unused (else a `const { a } = server` survives and\n // keeps a server import in the client graph). Restricted to plain\n // patterns so a default/computed-key side effect isn't dropped.\n const names = Object.keys(t.getBindingIdentifiers(decl.id));\n if (\n names.length > 0 &&\n isPlainPattern(decl.id) &&\n isRemovableInit(decl.init) &&\n names.every(isUnused)\n ) {\n removedSomething = true;\n return false;\n }\n return true;\n });\n if (stmt.declarations.length === 0) return false;\n }\n return true;\n });\n path.stop();\n },\n });\n }\n\n traverse(ast, {\n Program(path: NodePath<t.Program>) {\n path.scope.crawl();\n for (const stmt of path.node.body) {\n if (!t.isImportDeclaration(stmt)) continue;\n stmt.specifiers = stmt.specifiers.filter((spec) => {\n const binding = path.scope.getBinding(spec.local.name);\n return binding ? binding.referenced : true;\n });\n }\n path.node.body = path.node.body.filter(\n (stmt) =>\n !(\n t.isImportDeclaration(stmt) &&\n stmt.specifiers.length === 0 &&\n hadSpecifiers.has(stmt)\n ),\n );\n path.stop();\n },\n });\n}\n\n/**\n * Whether a binding pattern is side-effect-free to drop: a plain identifier, or\n * an object/array pattern of plain bindings — no default values\n * (`{ a = expr }`) or computed keys (`{ [expr]: a }`), which would evaluate (and\n * thus could have side effects) at destructuring time.\n */\nfunction isPlainPattern(node: t.Node): boolean {\n if (t.isIdentifier(node)) return true;\n if (t.isObjectPattern(node)) {\n return node.properties.every((p) =>\n t.isRestElement(p)\n ? isPlainPattern(p.argument)\n : !p.computed && isPlainPattern(p.value),\n );\n }\n if (t.isArrayPattern(node)) {\n return node.elements.every((el) => el == null || isPlainPattern(el));\n }\n return false; // AssignmentPattern (default), member expr, etc.\n}\n\n/** Whether a variable initializer is safe to drop (no observable side effects). */\nfunction isRemovableInit(node: t.Expression | null | undefined): boolean {\n if (node == null) return true;\n if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node)) {\n return isRemovableInit(node.expression);\n }\n // Containers are removable only if every element is — a nested call (e.g.\n // `[track()]`) has an observable side effect that dropping would lose.\n if (t.isArrayExpression(node)) {\n return node.elements.every(\n (el) => el == null || (t.isExpression(el) && isRemovableInit(el)),\n );\n }\n if (t.isObjectExpression(node)) {\n return node.properties.every(\n (p) =>\n t.isObjectProperty(p) &&\n !p.computed &&\n t.isExpression(p.value) &&\n isRemovableInit(p.value),\n );\n }\n if (t.isTemplateLiteral(node)) {\n return node.expressions.every(\n (e) => t.isExpression(e) && isRemovableInit(e),\n );\n }\n return (\n t.isArrowFunctionExpression(node) ||\n t.isFunctionExpression(node) ||\n t.isClassExpression(node) ||\n t.isIdentifier(node) ||\n // non-computed only — `obj[fn()]` could hide a side-effectful key\n (t.isMemberExpression(node) && !node.computed) ||\n t.isJSXElement(node) ||\n t.isJSXFragment(node) ||\n t.isLiteral(node)\n );\n}\n"],"mappings":";;;;;;;;;;;AAWA,MA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Aa,CAAC,KAAK,gBAAgB,CAAC,CAC/C;CAEF,OACE,EAAE,0BAA0B,IAAI,KAChC,EAAE,qBAAqB,IAAI,KAC3B,EAAE,kBAAkB,IAAI,KACxB,EAAE,aAAa,IAAI,KAElB,EAAE,mBAAmB,IAAI,KAAK,CAAC,KAAK,YACrC,EAAE,aAAa,IAAI,KACnB,EAAE,cAAc,IAAI,KACpB,EAAE,UAAU,IAAI;AAEpB"}
|
|
1
|
+
{"version":3,"file":"compile.js","names":["pkgJson.version"],"sources":["../src/compile.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as nodePath from \"node:path\";\nimport { parse } from \"@babel/parser\";\nimport _traverse, { type NodePath } from \"@babel/traverse\";\nimport _generate from \"@babel/generator\";\nimport * as t from \"@babel/types\";\nimport { satisfies } from \"semver\";\nimport { DIRECTIVE, type Target } from \"./constants\";\nimport pkgJson from \"../package.json\" with { type: \"json\" };\n\nconst parserPlugins = [\n \"typescript\",\n \"jsx\",\n \"explicitResourceManagement\",\n] as NonNullable<NonNullable<Parameters<typeof parse>[1]>[\"plugins\"]>;\n\n// @babel/traverse and @babel/generator are CJS; their default export is the\n// function itself under some interop and `{ default }` under others.\nconst traverse = (\n typeof _traverse === \"function\" ? _traverse : (_traverse as any).default\n) as typeof _traverse;\nconst generate = (\n typeof _generate === \"function\" ? _generate : (_generate as any).default\n) as typeof _generate;\n\nexport type ToolType = \"frontend\" | \"backend\" | \"human\" | \"provider\";\n\n/** The required wrapper around a toolkit's tools (stripped at build time). */\nconst TOOLKIT_WRAPPER = \"defineToolkit\";\n/** The helper that produces MCP-only toolkit fragments. */\nconst MCP_TOOLKIT_WRAPPER = \"defineMcpToolkit\";\n/** The required wrapper around a generative-UI library (stripped at build time). */\nconst COMPONENTS_WRAPPER = \"defineGenerativeComponents\";\n/** The core package whose metadata declares supported compiler versions. */\nconst CORE_PACKAGE = \"@assistant-ui/core\";\n/** This package, checked against core's compatibility range. */\nconst COMPILER_PACKAGE = \"@assistant-ui/x-generative-compiler\";\n/** Packages that re-export core's generative markers. */\nconst DISTRIBUTION_PACKAGES = [\n CORE_PACKAGE,\n \"@assistant-ui/react\",\n \"@assistant-ui/react-native\",\n \"@assistant-ui/react-ink\",\n] as const;\n/** Package that exports the generative UI runtime split by export condition. */\nconst GENERATIVE_UI_PACKAGE = \"@assistant-ui/react-generative-ui\";\n/**\n * The class whose instances expose split-by-condition tools (`present()`,\n * `promptUser()`). A toolkit entry that calls a method on one of these passes\n * through untouched — the library, not this compiler, routes its halves.\n */\nconst GENERATIVE_FACTORY = \"JSONGenerativeUI\";\n/**\n * The factory producing an interactable's complete tool entry. Unlike\n * `JSONGenerativeUI`, its package has no per-target builds, so this compiler\n * splits the inline config: the client keeps `render`, the server drops it.\n * The factory's own `execute` is internal and client-safe (frontend tool).\n */\nconst INTERACTABLE_TOOL_FACTORY = \"unstable_interactableTool\";\n\n/** Mutable per-build outcomes the toolkit pass reports back for directive/guard injection. */\ninterface TargetFlags {\n /** A `render` survived on a client build (→ emit `\"use client\"`). */\n keptRender: boolean;\n /** A backend `execute` survived on a server build (→ emit `import \"server-only\"`). */\n keptBackendExecute: boolean;\n}\n\nexport interface CompileOptions {\n /** Which build target to emit. */\n target: Target;\n /** Source filename, used for error messages and source maps. */\n filename?: string;\n /** Emit a source map alongside the code. */\n sourceMaps?: boolean;\n /**\n * Whether the `server` target prepends `import \"server-only\"` when it keeps a\n * backend `execute`. Defaults to `true` (the Next.js/RSC convention, where the\n * guard fires via the `react-server` condition). Set `false` for bundlers\n * without a `react-server` layer (e.g. a Vite/TanStack Start `ssr` build),\n * where the split is already structural and importing `server-only` would\n * throw — see the Vite integration.\n */\n injectServerOnly?: boolean;\n /**\n * No backend of the app imports this module's server build (e.g. cloud-hosted\n * runs), so the client is the only place the model can learn the schemas\n * from. The `client` target then keeps frontend/human tool schemas\n * uploadable — no `unstable_backendDefault` marker is stamped — and local\n * `new JSONGenerativeUI({ ... })` instances are constructed with\n * `backendless: true` so their `present`/`prompt_user` schemas upload too.\n */\n backendless?: boolean;\n}\n\nexport interface CompileResult {\n code: string;\n map?: object | null;\n}\n\n/** Thrown when a `\"use generative\"` file violates an authoring constraint. */\nexport class GenerativeCompileError extends Error {\n constructor(message: string, filename?: string) {\n super(\n `[assistant-ui/use-generative]${filename ? ` ${filename}:` : \"\"} ${message}`,\n );\n this.name = \"GenerativeCompileError\";\n }\n}\n\n/** Whether a source string opts into generative compilation via the directive. */\nexport function isGenerativeModule(code: string): boolean {\n // The directive must be a leading statement, preceded only by an optional BOM,\n // whitespace, and line/block comments. Scanned linearly — a regex over the\n // comment prefix is prone to catastrophic backtracking on crafted input.\n let i = code.charCodeAt(0) === 0xfeff ? 1 : 0;\n for (;;) {\n while (i < code.length && /\\s/.test(code[i]!)) i++;\n if (code.startsWith(\"//\", i)) {\n const nl = code.indexOf(\"\\n\", i);\n if (nl === -1) return false;\n i = nl + 1;\n } else if (code.startsWith(\"/*\", i)) {\n const end = code.indexOf(\"*/\", i + 2);\n if (end === -1) return false;\n i = end + 2;\n } else {\n break;\n }\n }\n\n const quote = code[i];\n if (quote !== '\"' && quote !== \"'\") return false;\n\n const directiveStart = i + 1;\n if (!code.startsWith(DIRECTIVE, directiveStart)) return false;\n\n const directiveEnd = directiveStart + DIRECTIVE.length;\n if (code[directiveEnd] !== quote) return false;\n\n return hasDirectiveTerminator(code, directiveEnd + 1);\n}\n\nexport const isGenerativeSource = (filename: string, source: string): boolean =>\n /\\.[cm]?[jt]sx?$/.test(filename) && isGenerativeModule(source);\n\nfunction hasDirectiveTerminator(code: string, start: number): boolean {\n let i = start;\n let sawLineTerminator = false;\n for (;;) {\n if (i >= code.length) return true;\n\n const char = code.charCodeAt(i);\n if (isSemicolon(char)) return true;\n if (isLineTerminator(char)) {\n sawLineTerminator = true;\n i++;\n continue;\n }\n\n if (code.startsWith(\"//\", i)) {\n const lineEnd = nextLineTerminatorIndex(code, i + 2);\n if (lineEnd === -1) return true;\n sawLineTerminator = true;\n i = lineEnd + 1;\n continue;\n }\n\n if (code.startsWith(\"/*\", i)) {\n const end = code.indexOf(\"*/\", i + 2);\n if (end === -1) return false;\n sawLineTerminator ||= containsLineTerminator(code, i + 2, end);\n i = end + 2;\n continue;\n }\n\n if (/\\s/.test(code[i]!)) {\n i++;\n continue;\n }\n\n return sawLineTerminator && !startsExpressionContinuation(code, i);\n }\n}\n\nfunction nextLineTerminatorIndex(code: string, start: number): number {\n for (let i = start; i < code.length; i++) {\n if (isLineTerminator(code.charCodeAt(i))) return i;\n }\n return -1;\n}\n\nfunction containsLineTerminator(\n code: string,\n start: number,\n end: number,\n): boolean {\n for (let i = start; i < end; i++) {\n if (isLineTerminator(code.charCodeAt(i))) return true;\n }\n return false;\n}\n\nfunction startsExpressionContinuation(code: string, start: number): boolean {\n switch (code[start]) {\n case \".\":\n case \"+\":\n case \"-\":\n case \"*\":\n case \"/\":\n case \"%\":\n case \"<\":\n case \">\":\n case \"=\":\n case \"!\":\n case \"&\":\n case \"|\":\n case \"^\":\n case \"?\":\n case \":\":\n case \",\":\n case \"[\":\n case \"(\":\n case \"`\":\n return true;\n }\n\n return (\n startsKeywordContinuation(code, start, \"as\") ||\n startsKeywordContinuation(code, start, \"in\") ||\n startsKeywordContinuation(code, start, \"instanceof\") ||\n startsKeywordContinuation(code, start, \"satisfies\")\n );\n}\n\nfunction startsKeywordContinuation(\n code: string,\n start: number,\n keyword: string,\n): boolean {\n if (!code.startsWith(keyword, start)) return false;\n const next = code[start + keyword.length];\n return next === undefined || !/[\\p{ID_Continue}$]/u.test(next);\n}\n\nfunction isSemicolon(char: number): boolean {\n return char === 59;\n}\n\nfunction isLineTerminator(char: number): boolean {\n return char === 10 || char === 13 || char === 0x2028 || char === 0x2029;\n}\n\n/**\n * Rewrites a `\"use generative\"` module for a single build target, keeping only the\n * regions that target needs and pruning the imports the dropped regions used.\n */\nexport function compileGenerative(\n code: string,\n options: CompileOptions,\n): CompileResult {\n const { target, filename } = options;\n const backendless = options.backendless ?? false;\n\n const ast = parse(code, {\n sourceType: \"module\",\n plugins: parserPlugins,\n });\n\n if (!ast.program.directives.some((d) => d.value.value === DIRECTIVE)) {\n throw new GenerativeCompileError(\n `missing \"${DIRECTIVE}\" directive`,\n filename,\n );\n }\n\n ensureCompilerCompatibleWithCore(ast, filename);\n\n // A module may hold several `defineToolkit(...)` / `defineGenerativeComponents(...)`\n // calls anywhere (e.g. a library built inside `new JSONGenerativeUI(...)` plus\n // the toolkit that exposes it). Tools may reference a `JSONGenerativeUI`\n // instance's `present()`/`promptUser()`, which the library — not this compiler —\n // splits across builds via export conditions; collect those instance names so\n // such entries pass through.\n ensureDefaultExport(ast, filename);\n const generativeInstances = collectGenerativeInstances(ast);\n const interactableToolImports = collectInteractableToolImports(ast);\n const { spreadNames: toolkitSpreadNames, namespaceImports } =\n collectToolkitSpreadNames(ast, filename, createToolkitNameContext());\n\n const flags: TargetFlags = { keptRender: false, keptBackendExecute: false };\n\n traverse(ast, {\n CallExpression(path: NodePath<t.CallExpression>) {\n const callee = path.node.callee;\n const object = t.isObjectExpression(path.node.arguments[0])\n ? path.node.arguments[0]\n : null;\n\n if (t.isIdentifier(callee, { name: COMPONENTS_WRAPPER })) {\n if (!object) {\n throw new GenerativeCompileError(\n `${COMPONENTS_WRAPPER}() takes an inline object literal of components`,\n filename,\n );\n }\n compileComponents(object, target, flags, filename);\n // Unwrap the authoring helper to the bare library object so its import\n // can be pruned.\n path.replaceWith(object);\n path.skip();\n return;\n }\n\n if (t.isIdentifier(callee, { name: TOOLKIT_WRAPPER })) {\n if (!object) {\n throw new GenerativeCompileError(\n `${TOOLKIT_WRAPPER}() takes an inline object literal of tools`,\n filename,\n );\n }\n compileToolkit(\n object,\n target,\n generativeInstances,\n interactableToolImports,\n toolkitSpreadNames,\n namespaceImports,\n flags,\n backendless,\n filename,\n );\n path.replaceWith(object);\n path.skip();\n }\n },\n });\n\n const { keptRender, keptBackendExecute } = flags;\n\n pruneUnused(ast);\n\n // Replace the module directives with the target-appropriate one.\n ast.program.directives = ast.program.directives.filter(\n (d) => d.value.value !== DIRECTIVE && d.value.value !== \"use client\",\n );\n if (target === \"client\" && keptRender) {\n ast.program.directives.unshift(\n t.directive(t.directiveLiteral(\"use client\")),\n );\n }\n if (\n target === \"server\" &&\n keptBackendExecute &&\n (options.injectServerOnly ?? true)\n ) {\n ast.program.body.unshift(\n t.importDeclaration([], t.stringLiteral(\"server-only\")),\n );\n }\n\n const result = generate(\n ast,\n {\n sourceMaps: options.sourceMaps ?? false,\n ...(filename ? { filename } : {}),\n jsescOption: { minimal: true },\n },\n code,\n );\n\n return { code: result.code, map: result.map };\n}\n\ninterface PackageJson {\n name?: string;\n version?: string;\n optionalDevDependencies?: Record<string, string>;\n}\n\nconst checkedCorePackageJsonPaths = new Set<string>();\n\n// This compiler's own version, inlined from package.json at build time. Read via\n// an import (not by walking the filesystem at runtime) so the literal survives\n// being bundled into a host package like `@assistant-ui/metro`, where no\n// standalone `@assistant-ui/x-generative-compiler` sits on disk to walk up to.\nconst COMPILER_VERSION = pkgJson.version;\n\nfunction ensureCompilerCompatibleWithCore(\n ast: t.File,\n filename: string | undefined,\n): void {\n const corePackageJsonPath = resolveCorePackageJson(ast, filename);\n if (\n !corePackageJsonPath ||\n checkedCorePackageJsonPaths.has(corePackageJsonPath)\n ) {\n return;\n }\n\n const corePackageJson = readPackageJson(corePackageJsonPath);\n const range = corePackageJson?.optionalDevDependencies?.[COMPILER_PACKAGE];\n if (!range) {\n checkedCorePackageJsonPaths.add(corePackageJsonPath);\n return;\n }\n\n let compatible = false;\n try {\n compatible = satisfies(COMPILER_VERSION, range, {\n includePrerelease: true,\n });\n } catch {\n throw new GenerativeCompileError(\n `${CORE_PACKAGE}@${corePackageJson.version ?? \"unknown\"} declares an ` +\n `invalid optionalDevDependencies range for ${COMPILER_PACKAGE}: ` +\n JSON.stringify(range),\n filename,\n );\n }\n\n if (!compatible) {\n throw new GenerativeCompileError(\n `${CORE_PACKAGE}@${corePackageJson.version ?? \"unknown\"} requires ` +\n `${COMPILER_PACKAGE} ${range}, but the current compiler is ` +\n `${COMPILER_VERSION}. Update @assistant-ui/next, @assistant-ui/vite, ` +\n \"or @assistant-ui/metro so their compiler satisfies the core package's \" +\n \"optionalDevDependencies range.\",\n filename,\n );\n }\n\n checkedCorePackageJsonPaths.add(corePackageJsonPath);\n}\n\nfunction resolveCorePackageJson(\n ast: t.File,\n filename: string | undefined,\n): string | null {\n for (const packageName of collectImportedDistributionPackages(ast)) {\n const packageJsonPath = resolvePackageJson(packageName, filename);\n if (!packageJsonPath) continue;\n if (packageName === CORE_PACKAGE) return packageJsonPath;\n\n const corePackageJsonPath = resolvePackageJson(\n CORE_PACKAGE,\n packageJsonPath,\n );\n if (corePackageJsonPath) return corePackageJsonPath;\n }\n\n return null;\n}\n\nfunction collectImportedDistributionPackages(ast: t.File): Set<string> {\n const packages = new Set<string>();\n\n for (const statement of ast.program.body) {\n const source =\n (t.isImportDeclaration(statement) ||\n t.isExportNamedDeclaration(statement) ||\n t.isExportAllDeclaration(statement)) &&\n statement.source\n ? statement.source.value\n : null;\n if (!source) continue;\n\n const packageName = packageNameFromSpecifier(source);\n if (packageName) packages.add(packageName);\n }\n\n return packages;\n}\n\nfunction packageNameFromSpecifier(specifier: string): string | null {\n for (const packageName of DISTRIBUTION_PACKAGES) {\n if (specifier === packageName || specifier.startsWith(`${packageName}/`)) {\n return packageName;\n }\n }\n\n return null;\n}\n\nfunction resolvePackageJson(\n packageName: string,\n filename: string | undefined,\n): string | null {\n const requirePath = normalizeRequirePath(filename);\n const require = createRequire(requirePath);\n\n try {\n return findPackageJson(require.resolve(packageName), packageName);\n } catch {\n return findPackageJsonFromNodeModules(packageName, requirePath);\n }\n}\n\nfunction normalizeRequirePath(filename: string | undefined): string {\n return cleanAbsoluteFilename(filename) ?? import.meta.url;\n}\n\n/** Strips a `?query`/`#hash` suffix and returns the path only if it is absolute. */\nfunction cleanAbsoluteFilename(filename: string | undefined): string | null {\n if (!filename) return null;\n const clean = filename.split(/[?#]/, 1)[0]!;\n return nodePath.isAbsolute(clean) ? clean : null;\n}\n\nfunction findPackageJson(\n fromPathOrUrl: string,\n packageName: string,\n): string | null {\n let current = nodePath.dirname(\n fromPathOrUrl.startsWith(\"file:\")\n ? new URL(fromPathOrUrl).pathname\n : nodePath.resolve(fromPathOrUrl),\n );\n\n for (;;) {\n const packageJsonPath = nodePath.join(current, \"package.json\");\n const packageJson = readPackageJson(packageJsonPath);\n if (packageJson?.name === packageName) return packageJsonPath;\n\n const parent = nodePath.dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n\nfunction findPackageJsonFromNodeModules(\n packageName: string,\n fromPathOrUrl: string,\n): string | null {\n const parts = packageName.split(\"/\");\n let current = nodePath.dirname(\n fromPathOrUrl.startsWith(\"file:\")\n ? new URL(fromPathOrUrl).pathname\n : nodePath.resolve(fromPathOrUrl),\n );\n\n for (;;) {\n const packageJsonPath = nodePath.join(\n current,\n \"node_modules\",\n ...parts,\n \"package.json\",\n );\n const packageJson = readPackageJson(packageJsonPath);\n if (packageJson?.name === packageName) return packageJsonPath;\n\n const parent = nodePath.dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n\nfunction readPackageJson(packageJsonPath: string): PackageJson | null {\n if (!existsSync(packageJsonPath)) return null;\n try {\n return JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as PackageJson;\n } catch (error) {\n throw new GenerativeCompileError(\n `could not parse package metadata at ${packageJsonPath}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n}\n\n/**\n * Errors unless the module's default export is the toolkit — a `defineToolkit(...)`\n * call (through `satisfies`/`as`/parens). This is the security boundary: the\n * default export is what the runtime registers, so it must be wrapped (and thus\n * split). A bare `export default { ... }` would ship a backend `execute` to the\n * client even if some *other* `defineToolkit(...)` exists elsewhere in the file.\n */\nfunction ensureDefaultExport(ast: t.File, filename: string | undefined): void {\n const def = ast.program.body.find(\n (stmt): stmt is t.ExportDefaultDeclaration =>\n t.isExportDefaultDeclaration(stmt),\n );\n if (!def) {\n throw new GenerativeCompileError(\"missing a default export\", filename);\n }\n if (!unwrapToToolkitCall(def.declaration)) {\n throw new GenerativeCompileError(\n `the default export must be ${TOOLKIT_WRAPPER}({ ... }) or ` +\n `${MCP_TOOLKIT_WRAPPER}({ ... }) (imported from \"@assistant-ui/react\"); ` +\n \"wrapping is required so a backend `execute` can't be authored in a way \" +\n \"that reaches the client\",\n filename,\n );\n }\n}\n\n/**\n * Unwraps a node through `satisfies`/`as`/parens to a call of the named function,\n * or returns `null`.\n */\nfunction unwrapToCall(node: t.Node, name: string): t.CallExpression | null {\n if (t.isTSSatisfiesExpression(node) || t.isTSAsExpression(node)) {\n return unwrapToCall(node.expression, name);\n }\n if (t.isParenthesizedExpression(node)) {\n return unwrapToCall(node.expression, name);\n }\n if (t.isCallExpression(node) && t.isIdentifier(node.callee, { name })) {\n return node;\n }\n return null;\n}\n\n/**\n * Unwraps a statement to its variable declaration through an `export` wrapper,\n * or returns `null`.\n */\nfunction asVariableDeclaration(\n statement: t.Statement,\n): t.VariableDeclaration | null {\n if (t.isVariableDeclaration(statement)) return statement;\n if (\n t.isExportNamedDeclaration(statement) &&\n t.isVariableDeclaration(statement.declaration)\n ) {\n return statement.declaration;\n }\n return null;\n}\n\n/**\n * Collects the names bound to `new JSONGenerativeUI(...)` (e.g.\n * `const generative = new JSONGenerativeUI({ library })`). A toolkit entry that\n * calls a method on one of these is a generative tool whose halves the library\n * routes by export condition, so it passes through the toolkit pass untouched.\n */\nfunction collectGenerativeInstances(ast: t.File): Set<string> {\n const names = new Set<string>();\n const generativeFactories = collectGenerativeFactoryImports(ast);\n for (const statement of ast.program.body) {\n const variableDeclaration = asVariableDeclaration(statement);\n if (!variableDeclaration) continue;\n for (const declaration of variableDeclaration.declarations) {\n const { id, init } = declaration;\n if (\n t.isIdentifier(id) &&\n t.isNewExpression(init) &&\n t.isIdentifier(init.callee) &&\n generativeFactories.has(init.callee.name)\n ) {\n names.add(id.name);\n }\n }\n }\n return names;\n}\n\n/**\n * Wraps a pass-through generative entry (`generative.present()`) so the tool it\n * returns loses its `unstable_backendDefault` marker. The library stamps the\n * marker at runtime, out of this compiler's reach, so a backendless client\n * build strips it post-hoc instead of threading an option into the library.\n */\nfunction stripBackendDefaultExpression(expr: t.Expression): t.Expression {\n return t.callExpression(\n t.arrowFunctionExpression(\n [\n t.objectPattern([\n t.objectProperty(\n t.identifier(\"unstable_backendDefault\"),\n t.identifier(\"_backendDefault\"),\n ),\n t.restElement(t.identifier(\"tool\")),\n ]),\n ],\n t.identifier(\"tool\"),\n ),\n [expr],\n );\n}\n\nfunction collectGenerativeFactoryImports(ast: t.File): Set<string> {\n const names = new Set<string>();\n for (const statement of ast.program.body) {\n if (\n !t.isImportDeclaration(statement) ||\n statement.source.value !== GENERATIVE_UI_PACKAGE\n ) {\n continue;\n }\n\n for (const specifier of statement.specifiers) {\n if (\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported, { name: GENERATIVE_FACTORY })\n ) {\n names.add(specifier.local.name);\n }\n }\n }\n return names;\n}\n\ntype ToolkitStaticNames = readonly string[] | null;\ntype ToolkitSpreadNames = Map<string, ToolkitStaticNames>;\n\ninterface ToolkitNameContext {\n importedToolkitNamesByFile: Map<string, ToolkitStaticNames | undefined>;\n resolvingImportedToolkitNames: Set<string>;\n}\n\n/**\n * The toolkit spreads a single module's pass can recognize: safe-to-spread\n * bindings plus the namespace imports that point at a generative module. The\n * namespace set is kept separate from {@link ToolkitSpreadNames} so a\n * whole-namespace `...kit` is not mistaken for a safe identifier spread — only\n * the default export crosses the build-split boundary, so a namespace spread is\n * rejected with a specific callout rather than allowed.\n */\ninterface ToolkitSpreadInfo {\n spreadNames: ToolkitSpreadNames;\n namespaceImports: Set<string>;\n}\n\n/**\n * Collects the local names `unstable_interactableTool` is imported under from a\n * distribution package, so toolkit entries calling it can be recognized\n * (and a same-named local function can't smuggle an arbitrary call through).\n */\nfunction collectInteractableToolImports(ast: t.File): Set<string> {\n const names = new Set<string>();\n for (const statement of ast.program.body) {\n if (!t.isImportDeclaration(statement)) continue;\n if (!packageNameFromSpecifier(statement.source.value)) continue;\n for (const specifier of statement.specifiers) {\n if (\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported, { name: INTERACTABLE_TOOL_FACTORY })\n ) {\n names.add(specifier.local.name);\n }\n }\n }\n return names;\n}\n\nfunction createToolkitNameContext(): ToolkitNameContext {\n return {\n importedToolkitNamesByFile: new Map(),\n resolvingImportedToolkitNames: new Set(),\n };\n}\n\n/**\n * The inline config of an `unstable_interactableTool({ ... })` toolkit entry, or `null`\n * when the entry is some other expression.\n */\nfunction interactableToolConfig(\n value: t.Node,\n imports: Set<string>,\n): t.ObjectExpression | null {\n return t.isCallExpression(value) &&\n t.isIdentifier(value.callee) &&\n imports.has(value.callee.name) &&\n t.isObjectExpression(value.arguments[0])\n ? value.arguments[0]\n : null;\n}\n\n/**\n * Toolkit identifiers that are safe to spread into a `defineToolkit({ ... })`,\n * paired with the static tool names they contain. A `null` name list means the\n * spread is safe, but its names are not statically known for duplicate checks.\n *\n * Two kinds qualify:\n *\n * - A local variable whose initializer is visible to this compiler pass: a\n * `defineToolkit(...)` binding is compiled in-place before a later spread\n * reads it, and `defineMcpToolkit(...)` entries can't contain executable code.\n * - The default import of another `\"use generative\"` module: that module is\n * split per-target by its own compiler pass, so spreading its default-exported\n * toolkit can't leak a backend `execute` to the client. Only the default\n * export crosses the generative-module boundary, so named imports don't\n * qualify — they would be `undefined` once that module is build-split.\n *\n * A namespace import (`import * as kit from \"...\"`) of a generative module is\n * tracked separately in `namespaceImports` so a `...kit` / `...kit.default`\n * spread can be rejected with a specific callout: only the default export\n * crosses the boundary, so a namespace spread is never safe.\n */\nfunction collectToolkitSpreadNames(\n ast: t.File,\n filename: string | undefined,\n context: ToolkitNameContext,\n): ToolkitSpreadInfo {\n const spreadNames: ToolkitSpreadNames = new Map();\n const namespaceImports = new Set<string>();\n const localToolkitCalls = new Map<string, t.CallExpression>();\n\n for (const statement of ast.program.body) {\n const localDeclaration = asVariableDeclaration(statement);\n if (localDeclaration) {\n for (const declaration of localDeclaration.declarations) {\n const { id, init } = declaration;\n if (t.isIdentifier(id) && init) {\n const toolkitCall = unwrapToToolkitCall(init);\n if (toolkitCall) localToolkitCalls.set(id.name, toolkitCall);\n }\n }\n continue;\n }\n\n if (t.isImportDeclaration(statement)) {\n const defaultSpecifier = statement.specifiers.find(\n (specifier): specifier is t.ImportDefaultSpecifier =>\n t.isImportDefaultSpecifier(specifier),\n );\n const namespaceSpecifier = statement.specifiers.find(\n (specifier): specifier is t.ImportNamespaceSpecifier =>\n t.isImportNamespaceSpecifier(specifier),\n );\n if (!defaultSpecifier && !namespaceSpecifier) continue;\n\n const names = getGenerativeImportToolkitNames(\n statement.source.value,\n filename,\n context,\n );\n if (names === undefined) continue;\n\n if (defaultSpecifier) spreadNames.set(defaultSpecifier.local.name, names);\n if (namespaceSpecifier)\n namespaceImports.add(namespaceSpecifier.local.name);\n }\n }\n\n const resolveLocal = (name: string): ToolkitStaticNames | undefined => {\n if (spreadNames.has(name)) return spreadNames.get(name);\n\n const call = localToolkitCalls.get(name);\n if (!call) return undefined;\n\n const object = t.isObjectExpression(call.arguments[0])\n ? call.arguments[0]\n : null;\n const names = object\n ? collectToolkitObjectNames(object, spreadNames)\n : null;\n const publicNames = uniqueToolkitNames(names);\n\n spreadNames.set(name, publicNames);\n return publicNames;\n };\n\n for (const name of localToolkitCalls.keys()) {\n resolveLocal(name);\n }\n\n return { spreadNames, namespaceImports };\n}\n\nconst MODULE_EXTENSIONS = [\n \".ts\",\n \".tsx\",\n \".mts\",\n \".cts\",\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n] as const;\n\n/** Extensions a specifier may carry that actually map to a TS source file. */\nconst REWRITABLE_JS_EXTENSIONS = new Set([\".js\", \".jsx\", \".mjs\", \".cjs\"]);\n\n/**\n * Reads the static tool names from the default export of an imported\n * `\"use generative\"` module. Relative specifiers and `tsconfig` path aliases\n * (e.g. `@/tools`) are resolved; anything else (a bare package, an unresolvable\n * alias) is treated as non-generative, and thus an unsafe spread.\n */\nfunction getGenerativeImportToolkitNames(\n source: string,\n filename: string | undefined,\n context: ToolkitNameContext,\n): ToolkitStaticNames | undefined {\n const cleanFilename = cleanAbsoluteFilename(filename);\n if (!cleanFilename) return undefined;\n\n const resolved = resolveImportedModuleFile(source, cleanFilename);\n if (!resolved) return undefined;\n\n if (context.importedToolkitNamesByFile.has(resolved)) {\n return context.importedToolkitNamesByFile.get(resolved);\n }\n if (context.resolvingImportedToolkitNames.has(resolved)) return null;\n\n let code: string;\n try {\n code = readFileSync(resolved, \"utf8\");\n } catch {\n context.importedToolkitNamesByFile.set(resolved, undefined);\n return undefined;\n }\n\n if (!isGenerativeModule(code)) {\n context.importedToolkitNamesByFile.set(resolved, undefined);\n return undefined;\n }\n\n context.resolvingImportedToolkitNames.add(resolved);\n try {\n const importedAst = parse(code, {\n sourceType: \"module\",\n plugins: parserPlugins,\n });\n const names = getDefaultExportToolkitNames(importedAst, resolved, context);\n context.importedToolkitNamesByFile.set(resolved, names);\n return names;\n } catch (error) {\n if (error instanceof GenerativeCompileError) throw error;\n context.importedToolkitNamesByFile.set(resolved, null);\n return null;\n } finally {\n context.resolvingImportedToolkitNames.delete(resolved);\n }\n}\n\nfunction getDefaultExportToolkitNames(\n ast: t.File,\n filename: string | undefined,\n context: ToolkitNameContext,\n): ToolkitStaticNames {\n const def = ast.program.body.find(\n (stmt): stmt is t.ExportDefaultDeclaration =>\n t.isExportDefaultDeclaration(stmt),\n );\n if (!def) return null;\n\n const toolkitCall = unwrapToToolkitCall(def.declaration);\n if (!toolkitCall || !t.isObjectExpression(toolkitCall.arguments[0])) {\n return null;\n }\n\n const { spreadNames } = collectToolkitSpreadNames(ast, filename, context);\n return uniqueToolkitNames(\n collectToolkitObjectNames(toolkitCall.arguments[0], spreadNames),\n );\n}\n\n/** Resolves an import specifier (relative or `tsconfig`-aliased) to a file on disk. */\nfunction resolveImportedModuleFile(\n source: string,\n fromFilename: string,\n): string | null {\n if (source.startsWith(\".\")) {\n const base = nodePath.resolve(nodePath.dirname(fromFilename), source);\n return resolveModuleFileAtPath(base);\n }\n return resolveAliasImport(source, fromFilename);\n}\n\n/**\n * Resolves a candidate module path, trying TS/JS extensions then index files. A\n * specifier may carry a `.js`-family extension that maps to a `.ts`/`.tsx`\n * source (TypeScript's `bundler`/`nodenext` resolution), so the extension is\n * dropped before probing.\n */\nfunction resolveModuleFileAtPath(base: string): string | null {\n const ext = nodePath.extname(base);\n if (ext && existsSync(base)) return base;\n\n const stem = REWRITABLE_JS_EXTENSIONS.has(ext)\n ? base.slice(0, -ext.length)\n : base;\n\n for (const candidateExt of MODULE_EXTENSIONS) {\n const candidate = `${stem}${candidateExt}`;\n if (existsSync(candidate)) return candidate;\n }\n for (const candidateExt of MODULE_EXTENSIONS) {\n const candidate = nodePath.join(base, `index${candidateExt}`);\n if (existsSync(candidate)) return candidate;\n }\n return null;\n}\n\ninterface TsconfigAliases {\n /** Absolute directory that `paths` targets resolve against. */\n baseDir: string;\n paths: Record<string, string[]>;\n}\n\n/** Resolves a `tsconfig` path alias (e.g. `@/tools/x`) to a file on disk. */\nfunction resolveAliasImport(\n source: string,\n fromFilename: string,\n): string | null {\n const tsconfig = loadTsconfigAliases(nodePath.dirname(fromFilename));\n if (!tsconfig) return null;\n\n // TypeScript matches the most specific key first: an exact (wildcard-free) key\n // beats a wildcard one, and a longer static prefix beats a shorter one.\n const patterns = Object.entries(tsconfig.paths).sort(\n ([a], [b]) => aliasSpecificity(b) - aliasSpecificity(a),\n );\n\n for (const [pattern, targets] of patterns) {\n const matched = matchAliasPattern(pattern, source);\n if (matched === null) continue;\n\n for (const target of targets) {\n const specifier = substituteAliasWildcard(target, matched);\n const file = resolveModuleFileAtPath(\n nodePath.resolve(tsconfig.baseDir, specifier),\n );\n if (file) return file;\n }\n }\n return null;\n}\n\n/** Ranks a `paths` key: an exact key outranks any wildcard; longer prefixes win. */\nfunction aliasSpecificity(pattern: string): number {\n const star = pattern.indexOf(\"*\");\n return star === -1 ? pattern.length + 1 : star;\n}\n\n/** Substitutes the single `*` in a `paths` target with the matched text. */\nfunction substituteAliasWildcard(target: string, matched: string): string {\n const star = target.indexOf(\"*\");\n if (star === -1) return target;\n return target.slice(0, star) + matched + target.slice(star + 1);\n}\n\n/**\n * Matches an import specifier against a `tsconfig` `paths` key. Returns the text\n * captured by the key's `*` (or `\"\"` for an exact, wildcard-free key), or `null`\n * when the specifier doesn't match.\n */\nfunction matchAliasPattern(pattern: string, source: string): string | null {\n const star = pattern.indexOf(\"*\");\n if (star === -1) return pattern === source ? \"\" : null;\n\n const prefix = pattern.slice(0, star);\n const suffix = pattern.slice(star + 1);\n if (\n source.length >= prefix.length + suffix.length &&\n source.startsWith(prefix) &&\n source.endsWith(suffix)\n ) {\n return source.slice(prefix.length, source.length - suffix.length);\n }\n return null;\n}\n\n/**\n * Memoizes resolved aliases per start directory. The compiler runs once per\n * file across a build, so without this every aliased spread re-walks and\n * re-parses the same `tsconfig.json`. Process-lifetime, like\n * `checkedCorePackageJsonPaths`.\n */\nconst tsconfigAliasesByDir = new Map<string, TsconfigAliases | null>();\n\n/** Walks up from a directory to the nearest `tsconfig.json` that declares `paths`. */\nfunction loadTsconfigAliases(fromDir: string): TsconfigAliases | null {\n const cached = tsconfigAliasesByDir.get(fromDir);\n if (cached !== undefined) return cached;\n\n let aliases: TsconfigAliases | null = null;\n let dir = fromDir;\n for (;;) {\n const tsconfigPath = nodePath.join(dir, \"tsconfig.json\");\n if (existsSync(tsconfigPath)) {\n aliases = readTsconfigAliases(tsconfigPath, new Set());\n if (aliases) break;\n }\n const parent = nodePath.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n tsconfigAliasesByDir.set(fromDir, aliases);\n return aliases;\n}\n\n/** Reads `baseUrl`/`paths` from a tsconfig, following a single `extends` chain. */\nfunction readTsconfigAliases(\n tsconfigPath: string,\n seen: Set<string>,\n): TsconfigAliases | null {\n if (seen.has(tsconfigPath)) return null;\n seen.add(tsconfigPath);\n\n let config: {\n extends?: string | string[];\n compilerOptions?: { baseUrl?: string; paths?: Record<string, string[]> };\n } | null;\n try {\n config = parseJsonc(readFileSync(tsconfigPath, \"utf8\"));\n } catch {\n return null;\n }\n if (!config) return null;\n\n const configDir = nodePath.dirname(tsconfigPath);\n const { baseUrl, paths } = config.compilerOptions ?? {};\n\n if (paths) {\n return {\n baseDir: baseUrl ? nodePath.resolve(configDir, baseUrl) : configDir,\n paths,\n };\n }\n\n // `extends` may be a string or (TS 5.0+) a string array; later entries take\n // precedence, so try them last-first. Parsed from untrusted JSONC, so the\n // array case is a real runtime shape, not just a type.\n const extendsList = Array.isArray(config.extends)\n ? config.extends\n : config.extends\n ? [config.extends]\n : [];\n for (let i = extendsList.length - 1; i >= 0; i--) {\n const entry = extendsList[i];\n if (typeof entry !== \"string\") continue;\n const extended = resolveExtendedTsconfig(entry, configDir);\n if (extended) {\n const aliases = readTsconfigAliases(extended, seen);\n if (aliases) return aliases;\n }\n }\n return null;\n}\n\n/** Resolves a tsconfig `extends` value (relative path or installed package). */\nfunction resolveExtendedTsconfig(\n extendsValue: string,\n configDir: string,\n): string | null {\n if (extendsValue.startsWith(\".\")) {\n const base = nodePath.resolve(configDir, extendsValue);\n const candidates =\n nodePath.extname(base) === \".json\" ? [base] : [`${base}.json`, base];\n return candidates.find((candidate) => existsSync(candidate)) ?? null;\n }\n try {\n return createRequire(nodePath.join(configDir, \"package.json\")).resolve(\n extendsValue.endsWith(\".json\") ? extendsValue : `${extendsValue}.json`,\n );\n } catch {\n return null;\n }\n}\n\n/** Parses JSON with `//` and block comments and trailing commas stripped (tsconfig is JSONC). */\nfunction parseJsonc(text: string): any {\n const withoutComments = text.replace(\n /\"(?:[^\"\\\\]|\\\\.)*\"|\\/\\/[^\\n\\r]*|\\/\\*[\\s\\S]*?\\*\\//g,\n (match) => (match.startsWith('\"') ? match : \"\"),\n );\n const withoutTrailingCommas = withoutComments.replace(/,(\\s*[}\\]])/g, \"$1\");\n return JSON.parse(withoutTrailingCommas);\n}\n\nfunction unwrapToToolkitCall(node: t.Node): t.CallExpression | null {\n return (\n unwrapToCall(node, TOOLKIT_WRAPPER) ??\n unwrapToCall(node, MCP_TOOLKIT_WRAPPER)\n );\n}\n\nfunction collectToolkitObjectNames(\n object: t.ObjectExpression,\n toolkitSpreadNames: ToolkitSpreadNames,\n): ToolkitStaticNames {\n const names: string[] = [];\n\n for (const entry of object.properties) {\n const entryNames = toolkitEntryNames(entry, toolkitSpreadNames);\n if (!entryNames) return null;\n names.push(...entryNames);\n }\n\n return names;\n}\n\nfunction uniqueToolkitNames(names: ToolkitStaticNames): ToolkitStaticNames {\n return names ? [...new Set(names)] : names;\n}\n\nfunction toolkitEntryNames(\n entry: t.ObjectExpression[\"properties\"][number],\n toolkitSpreadNames: ToolkitSpreadNames,\n): ToolkitStaticNames {\n if (t.isSpreadElement(entry)) {\n if (t.isIdentifier(entry.argument)) {\n return toolkitSpreadNames.get(entry.argument.name) ?? null;\n }\n\n const directMcpToolkit = unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER);\n if (\n directMcpToolkit &&\n t.isObjectExpression(directMcpToolkit.arguments[0])\n ) {\n return collectToolkitObjectNames(\n directMcpToolkit.arguments[0],\n toolkitSpreadNames,\n );\n }\n\n return null;\n }\n\n if (t.isObjectProperty(entry) || t.isObjectMethod(entry)) {\n const name = memberName(entry.key, entry.computed);\n return name ? [name] : [];\n }\n\n return [];\n}\n\nfunction toolkitEntrySourceLabel(entry: Entry): string {\n if (t.isSpreadElement(entry)) {\n if (t.isIdentifier(entry.argument)) return `...${entry.argument.name}`;\n if (unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER)) {\n return `...${MCP_TOOLKIT_WRAPPER}(...)`;\n }\n return \"...\";\n }\n\n if (t.isObjectProperty(entry) || t.isObjectMethod(entry)) {\n const line = entry.loc?.start.line;\n return line === undefined\n ? \"inline property\"\n : `inline property (line ${line})`;\n }\n\n return \"inline property\";\n}\n\nfunction warnDuplicateToolkitNames(\n object: t.ObjectExpression,\n toolkitSpreadNames: ToolkitSpreadNames,\n filename: string | undefined,\n): void {\n const sourcesByToolName = new Map<string, string[]>();\n for (const entry of object.properties) {\n const entryNames = toolkitEntryNames(entry, toolkitSpreadNames);\n if (!entryNames) continue;\n const source = toolkitEntrySourceLabel(entry);\n for (const name of entryNames) {\n const sources = sourcesByToolName.get(name);\n if (sources) sources.push(source);\n else sourcesByToolName.set(name, [source]);\n }\n }\n\n for (const [name, sources] of sourcesByToolName) {\n const winner = sources.at(-1);\n const overridden = sources.slice(0, -1);\n if (winner === undefined || overridden.length === 0) continue;\n console.warn(\n new GenerativeCompileError(\n `Duplicate tool name \"${name}\": ${winner} overrides ` +\n `${overridden.join(\", \")}. ` +\n \"JavaScript object spread keeps the last definition.\",\n filename,\n ).message,\n );\n }\n}\n\nfunction isSafeToolkitSpread(\n entry: t.SpreadElement,\n toolkitSpreadNames: ToolkitSpreadNames,\n): boolean {\n if (t.isIdentifier(entry.argument)) {\n return toolkitSpreadNames.has(entry.argument.name);\n }\n\n const directMcpToolkit = unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER);\n return (\n !!directMcpToolkit && t.isObjectExpression(directMcpToolkit.arguments[0])\n );\n}\n\nfunction genericUnsafeToolkitEntryMessage(): string {\n return (\n \"each tool must be an inline object literal (`name: { ... }`) or a \" +\n \"compiler-visible toolkit spread / generative tool (e.g. \" +\n \"`...defineMcpToolkit(...)`, `...baseToolkit`, \" +\n \"`generative.present()`, or `unstable_interactableTool(...)`) so its \" +\n \"`execute` can be routed\"\n );\n}\n\nfunction describeUnsafeToolkitEntry(entry: Entry): string {\n if (!t.isObjectProperty(entry)) return genericUnsafeToolkitEntryMessage();\n\n const toolName = memberName(entry.key, entry.computed);\n const raw = entryRawValue(entry);\n if (!toolName || !raw) return genericUnsafeToolkitEntryMessage();\n\n return (\n `tool \"${toolName}\" cannot be \\`${generate(raw).code}\\`; use an inline ` +\n `object literal (\\`${toolName}: { ... }\\`) or a compiler-visible toolkit ` +\n \"spread / generative tool so its `execute` can be routed\"\n );\n}\n\nfunction namespaceToolkitSpreadMessage(): string {\n return (\n 'a namespace import (`import * as kit from \"...\"`) can\\'t be spread into ' +\n `${TOOLKIT_WRAPPER}({ ... }); only a generative module's default export ` +\n \"crosses the build-split boundary, so import it as a default \" +\n '(`import kit from \"...\"`) and spread `...kit` instead'\n );\n}\n\n/** The `kit` in `...kit` or `...kit.default`, or null for a computed/opaque base. */\nfunction namespaceSpreadBaseName(argument: t.Expression): string | null {\n if (t.isIdentifier(argument)) return argument.name;\n if (\n t.isMemberExpression(argument) &&\n !argument.computed &&\n t.isIdentifier(argument.object)\n ) {\n return argument.object.name;\n }\n return null;\n}\n\n/** The `JSONGenerativeUI` methods that produce a split-by-condition tool. */\nconst GENERATIVE_TOOL_METHODS = new Set([\"present\", \"promptUser\"]);\n\n/**\n * Whether a toolkit entry's value is a call to a tool-producing method on a\n * collected `JSONGenerativeUI` instance (`generative.present()`), which passes\n * through. The method name is checked too, so a typo like `generative.presnt()`\n * is a compile error here rather than a pass-through that fails at runtime.\n */\nfunction isGenerativeToolEntry(value: t.Node, instances: Set<string>): boolean {\n return (\n t.isCallExpression(value) &&\n t.isMemberExpression(value.callee) &&\n !value.callee.computed &&\n t.isIdentifier(value.callee.object) &&\n instances.has(value.callee.object.name) &&\n t.isIdentifier(value.callee.property) &&\n GENERATIVE_TOOL_METHODS.has(value.callee.property.name)\n );\n}\n\n/**\n * Splits a `defineGenerativeComponents({ ... })` library for a build target:\n * a component's `render` (and the client imports it alone uses) is dropped on\n * the server; `properties`/`description` stay on both, since they drive the tool\n * schema either way. Mutates the object in place.\n */\nfunction compileComponents(\n object: t.ObjectExpression,\n target: Target,\n flags: TargetFlags,\n filename: string | undefined,\n): void {\n for (const entry of object.properties) {\n const value = entryValue(entry);\n if (!value) {\n throw new GenerativeCompileError(\n `each component in ${COMPONENTS_WRAPPER}() must be an inline object ` +\n \"literal (`name: { ... }`) so its `render` can be routed\",\n filename,\n );\n }\n if (!findMember(value, \"render\")) continue;\n // The client keeps `render` (and so needs the module marked `\"use client\"`);\n // the server drops it, since only the schema reaches the model there.\n if (target === \"client\") flags.keptRender = true;\n else removeMember(value, \"render\");\n }\n}\n\n/**\n * Splits a `defineToolkit({ ... })` for a build target. Each inline tool is\n * routed by inferred type (see the per-entry logic); a generative entry like\n * `generative.present()` passes through, the library having already split it.\n * Mutates the object in place and records outcomes in {@link TargetFlags}.\n */\nfunction compileToolkit(\n object: t.ObjectExpression,\n target: Target,\n instances: Set<string>,\n interactableToolImports: Set<string>,\n toolkitSpreadNames: ToolkitSpreadNames,\n namespaceImports: Set<string>,\n flags: TargetFlags,\n backendless: boolean,\n filename: string | undefined,\n): void {\n // Split builds compile both targets; emit target-independent warnings from\n // the client pass so each duplicate is logged once.\n if (target === \"client\") {\n warnDuplicateToolkitNames(object, toolkitSpreadNames, filename);\n }\n\n const nextProperties: t.ObjectExpression[\"properties\"] = [];\n\n for (const entry of object.properties) {\n const value = entryValue(entry);\n if (!value) {\n if (\n t.isSpreadElement(entry) &&\n isSafeToolkitSpread(entry, toolkitSpreadNames)\n ) {\n nextProperties.push(entry);\n continue;\n }\n // A generative tool (`generative.present()`) is split by the library's\n // export conditions, so it is safe to keep verbatim. Anything else — a\n // method or opaque call like `makeTool()` — can't be analyzed, so its\n // `execute` could reach the client unstripped.\n const raw = entryRawValue(entry);\n if (raw && isGenerativeToolEntry(raw, instances)) {\n if (backendless && target === \"client\" && t.isObjectProperty(entry)) {\n entry.value = stripBackendDefaultExpression(raw);\n }\n nextProperties.push(entry);\n continue;\n }\n const config =\n raw && interactableToolConfig(raw, interactableToolImports);\n if (config) {\n if (target === \"client\") flags.keptRender = true;\n else removeMember(config, \"render\");\n nextProperties.push(entry);\n continue;\n }\n if (t.isSpreadElement(entry)) {\n const namespaceBase = namespaceSpreadBaseName(entry.argument);\n if (namespaceBase && namespaceImports.has(namespaceBase)) {\n throw new GenerativeCompileError(\n namespaceToolkitSpreadMessage(),\n filename,\n );\n }\n }\n throw new GenerativeCompileError(\n describeUnsafeToolkitEntry(entry),\n filename,\n );\n }\n\n // Nature is inferred from `execute` (see inferToolType), not an authored\n // `type`. The resolved type is written back below so the runtime keeps it.\n const toolName = t.isObjectProperty(entry)\n ? memberName(entry.key, entry.computed)\n : undefined;\n const execute = findMember(value, \"execute\");\n const isStub = execute ? executeIsStubTool(execute) : false;\n const isExternal = execute ? executeIsExternalTool(execute) : false;\n const type = inferToolType(value, toolName, filename);\n const hasRender = !!findMember(value, \"render\");\n const hasRenderText = !!findMember(value, \"renderText\");\n\n if (type === \"frontend\" && !hasRender && !hasRenderText) {\n throw new GenerativeCompileError(\n `${typedToolSubject(\"frontend\", toolName)} must declare a ` +\n \"`render` or `renderText` \" +\n \"(it has no server execute to show otherwise)\",\n filename,\n );\n }\n\n if (type === \"human\" && !hasRender) {\n throw new GenerativeCompileError(\n `${typedToolSubject(\"human\", toolName)} must declare a ` +\n \"`render` so it can collect input\",\n filename,\n );\n }\n\n if (type === \"provider\" && execute) {\n applyProviderToolConfig(value, execute, toolName, filename);\n }\n\n if (isExternal) {\n if (!hasRender && !hasRenderText) {\n throw new GenerativeCompileError(\n `${typedToolSubject(\"external\", toolName)} must declare a ` +\n \"`render` or `renderText` \" +\n \"(assistant-ui only renders calls for tools defined elsewhere)\",\n filename,\n );\n }\n if (target === \"server\") continue;\n stripExternalToolMetadata(value);\n }\n\n if (target === \"client\") {\n // A non-stub frontend execute stays (its `\"use client\"` marker is no longer needed\n // once the module is client); backend, sentinel, and stub executes are dropped.\n if (execute && type === \"frontend\" && !isStub) stripUseClient(execute);\n else if (execute) removeMember(value, \"execute\");\n if (hasRender || hasRenderText) flags.keptRender = true;\n } else {\n // server: render is never needed; only a non-external backend execute survives.\n if (hasRender) removeMember(value, \"render\");\n if (hasRenderText) removeMember(value, \"renderText\");\n if (execute) {\n if (type === \"backend\" && !isExternal) flags.keptBackendExecute = true;\n else removeMember(value, \"execute\");\n }\n }\n\n setToolType(value, type);\n setBackendDefault(value, target, type, backendless);\n nextProperties.push(entry);\n }\n\n object.properties = nextProperties;\n}\n\nfunction applyProviderToolConfig(\n object: t.ObjectExpression,\n execute: t.ObjectProperty | t.ObjectMethod,\n toolName: string | undefined,\n filename: string | undefined,\n): void {\n if (\n !t.isObjectProperty(execute) ||\n !t.isCallExpression(execute.value) ||\n execute.value.arguments.length !== 1 ||\n !t.isObjectExpression(execute.value.arguments[0])\n ) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` must receive an inline object literal\",\n filename,\n );\n }\n\n const existingNames = new Set(\n object.properties.flatMap((prop) => {\n if (!t.isObjectProperty(prop) && !t.isObjectMethod(prop)) return [];\n const name = memberName(prop.key, prop.computed);\n return name ? [name] : [];\n }),\n );\n const configNames = new Set<string>();\n\n for (const prop of execute.value.arguments[0].properties) {\n if (!t.isObjectProperty(prop)) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` config can only contain object properties\",\n filename,\n );\n }\n const name = memberName(prop.key, prop.computed);\n if (!name) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` config can only contain static property names\",\n filename,\n );\n }\n if (\n t.isFunctionExpression(prop.value) ||\n t.isArrowFunctionExpression(prop.value)\n ) {\n throw new GenerativeCompileError(\n \"`providerTool(...)` config cannot contain function-valued properties\",\n filename,\n );\n }\n if (existingNames.has(name) || configNames.has(name)) {\n const toolLabel = toolName ? ` for \"${toolName}\"` : \"\";\n throw new GenerativeCompileError(\n `\\`providerTool(...)\\` config${toolLabel} duplicates \"${name}\"`,\n filename,\n );\n }\n configNames.add(name);\n object.properties.push(prop);\n }\n}\n\ntype Entry = t.ObjectExpression[\"properties\"][number];\n\n/** The raw AST value of an entry (any expression), or null for spreads/methods. */\nfunction entryRawValue(entry: Entry): t.Expression | null {\n if (t.isObjectProperty(entry) && t.isExpression(entry.value)) {\n return entry.value;\n }\n return null;\n}\n\nfunction entryValue(entry: Entry): t.ObjectExpression | null {\n if (t.isObjectProperty(entry) && t.isObjectExpression(entry.value)) {\n return entry.value;\n }\n return null;\n}\n\n/** A member of an entry object: `render`/`execute`/`type`, as property or method. */\nfunction findMember(\n object: t.ObjectExpression,\n name: string,\n): t.ObjectProperty | t.ObjectMethod | undefined {\n return object.properties.find(\n (p): p is t.ObjectProperty | t.ObjectMethod =>\n (t.isObjectProperty(p) || t.isObjectMethod(p)) &&\n memberName(p.key, p.computed) === name,\n );\n}\n\nfunction removeMember(object: t.ObjectExpression, name: string): void {\n object.properties = object.properties.filter(\n (p) =>\n !(\n (t.isObjectProperty(p) || t.isObjectMethod(p)) &&\n memberName(p.key, p.computed) === name\n ),\n );\n}\n\n/** The `BlockStatement` body of an `execute` member, if it has one. */\nfunction executeBody(\n member: t.ObjectProperty | t.ObjectMethod,\n): t.BlockStatement | undefined {\n if (t.isObjectMethod(member)) return member.body;\n const value = member.value;\n if (\n (t.isArrowFunctionExpression(value) || t.isFunctionExpression(value)) &&\n t.isBlockStatement(value.body)\n ) {\n return value.body;\n }\n return undefined;\n}\n\n/** Whether an `execute` opts into the client via a leading `\"use client\"`. */\nfunction executeIsClient(member: t.ObjectProperty | t.ObjectMethod): boolean {\n return !!executeBody(member)?.directives.some(\n (d) => d.value.value === \"use client\",\n );\n}\n\nfunction executeIsSentinel(\n member: t.ObjectProperty | t.ObjectMethod,\n name: string,\n): boolean {\n return (\n t.isObjectProperty(member) &&\n t.isCallExpression(member.value) &&\n t.isIdentifier(member.value.callee, { name })\n );\n}\n\n/** Whether an `execute` is the human-in-the-loop sentinel. */\nfunction executeIsHumanTool(\n member: t.ObjectProperty | t.ObjectMethod,\n): boolean {\n return (\n executeIsSentinel(member, \"humanTool\") ||\n executeIsSentinel(member, \"hitlTool\") ||\n executeIsSentinel(member, \"hitl\")\n );\n}\n\n/** Whether an `execute` is the provider-tool sentinel. */\nfunction executeIsProviderTool(\n member: t.ObjectProperty | t.ObjectMethod,\n): boolean {\n return executeIsSentinel(member, \"providerTool\");\n}\n\n/** Whether an `execute` is the local override sentinel. */\nfunction executeIsStubTool(member: t.ObjectProperty | t.ObjectMethod): boolean {\n return executeIsSentinel(member, \"stubTool\");\n}\n\n/** Whether an `execute` is the externally-defined backend tool sentinel. */\nfunction executeIsExternalTool(\n member: t.ObjectProperty | t.ObjectMethod,\n): boolean {\n return executeIsSentinel(member, \"externalTool\");\n}\n\n/** Drops the `\"use client\"` directive from an `execute` body (kept frontend). */\nfunction stripUseClient(member: t.ObjectProperty | t.ObjectMethod): void {\n const body = executeBody(member);\n if (body) {\n body.directives = body.directives.filter(\n (d) => d.value.value !== \"use client\",\n );\n }\n}\n\n/**\n * The tool's nature, inferred from its (mandatory) `execute` rather than an\n * authored `type`: `humanTool()` → `human`; `providerTool(...)` → `provider`;\n * `stubTool()` → `frontend`; `externalTool()` → `backend`; `\"use client\"` →\n * `frontend`; otherwise `backend`.\n * The loader writes the result back as a `type` field (see {@link setToolType})\n * so the runtime keeps it.\n */\nfunction inferToolType(\n object: t.ObjectExpression,\n toolName: string | undefined,\n filename: string | undefined,\n): ToolType {\n const execute = findMember(object, \"execute\");\n if (!execute) {\n throw new GenerativeCompileError(\n `${toolSubject(toolName)} must declare an \\`execute\\`; use ` +\n \"`humanTool()` for a human-in-the-loop tool\",\n filename,\n );\n }\n if (executeIsHumanTool(execute)) return \"human\";\n if (executeIsProviderTool(execute)) return \"provider\";\n if (executeIsStubTool(execute)) return \"frontend\";\n if (executeIsExternalTool(execute)) return \"backend\";\n return executeIsClient(execute) ? \"frontend\" : \"backend\";\n}\n\nfunction toolSubject(toolName: string | undefined): string {\n return toolName ? `tool \"${toolName}\"` : \"every tool\";\n}\n\nfunction typedToolSubject(type: string, toolName: string | undefined): string {\n if (toolName) return `${type} tool \"${toolName}\"`;\n const article = /^[aeiou]/i.test(type) ? \"an\" : \"a\";\n return `${article} ${type} tool`;\n}\n\nfunction stripExternalToolMetadata(object: t.ObjectExpression): void {\n // Mirror BackendTool's forbidden metadata fields: execute is stripped by the\n // main routing loop, while streamCall is also removed because there is no\n // assistant-ui executor to stream from.\n removeMember(object, \"description\");\n removeMember(object, \"parameters\");\n removeMember(object, \"disabled\");\n removeMember(object, \"toModelOutput\");\n removeMember(object, \"experimental_onSchemaValidationError\");\n removeMember(object, \"providerOptions\");\n removeMember(object, \"streamCall\");\n}\n\n/** Writes the resolved `type` back onto the tool object (replacing any author's). */\nfunction setToolType(object: t.ObjectExpression, type: ToolType): void {\n removeMember(object, \"type\");\n // Append (not prepend) so the inferred type wins over any earlier spread.\n object.properties.push(\n t.objectProperty(t.identifier(\"type\"), t.stringLiteral(type)),\n );\n}\n\nfunction setBackendDefault(\n object: t.ObjectExpression,\n target: Target,\n type: ToolType,\n backendless: boolean,\n): void {\n // Always strip any hand-authored marker first; only re-add it for client\n // frontend/human tools whose schema is already known by the backend. A\n // backendless build has no such backend, so nothing is marked.\n removeMember(object, \"unstable_backendDefault\");\n if (backendless) return;\n if (target !== \"client\" || (type !== \"frontend\" && type !== \"human\")) return;\n\n object.properties.push(\n t.objectProperty(\n t.identifier(\"unstable_backendDefault\"),\n t.objectExpression([\n t.objectProperty(t.identifier(\"parameters\"), t.booleanLiteral(true)),\n ]),\n ),\n );\n}\n\nfunction memberName(\n key: t.Node,\n computed: boolean | undefined,\n): string | undefined {\n if (computed) return undefined;\n if (t.isIdentifier(key)) return key.name;\n if (t.isStringLiteral(key)) return key.value;\n return undefined;\n}\n\n/**\n * Removes declarations and import specifiers left unreferenced after region\n * removal, to a fixpoint (a dropped helper frees what it used). Keeps exports,\n * side-effect imports, and possibly-side-effectful initializers.\n */\nfunction pruneUnused(ast: t.File): void {\n const hadSpecifiers = new WeakSet<t.ImportDeclaration>();\n for (const stmt of ast.program.body) {\n if (t.isImportDeclaration(stmt) && stmt.specifiers.length > 0) {\n hadSpecifiers.add(stmt);\n }\n }\n\n let removedSomething = true;\n while (removedSomething) {\n removedSomething = false;\n traverse(ast, {\n Program(path: NodePath<t.Program>) {\n path.scope.crawl();\n const isUnused = (name: string): boolean => {\n const binding = path.scope.getBinding(name);\n return !!binding && !binding.referenced;\n };\n\n path.node.body = path.node.body.filter((stmt) => {\n if (\n (t.isFunctionDeclaration(stmt) || t.isClassDeclaration(stmt)) &&\n stmt.id &&\n isUnused(stmt.id.name)\n ) {\n removedSomething = true;\n return false;\n }\n if (t.isVariableDeclaration(stmt)) {\n stmt.declarations = stmt.declarations.filter((decl) => {\n // Handles destructuring too: drop the declarator only when *every*\n // bound name is unused (else a `const { a } = server` survives and\n // keeps a server import in the client graph). Restricted to plain\n // patterns so a default/computed-key side effect isn't dropped.\n const names = Object.keys(t.getBindingIdentifiers(decl.id));\n if (\n names.length > 0 &&\n isPlainPattern(decl.id) &&\n isRemovableInit(decl.init) &&\n names.every(isUnused)\n ) {\n removedSomething = true;\n return false;\n }\n return true;\n });\n if (stmt.declarations.length === 0) return false;\n }\n return true;\n });\n path.stop();\n },\n });\n }\n\n traverse(ast, {\n Program(path: NodePath<t.Program>) {\n path.scope.crawl();\n for (const stmt of path.node.body) {\n if (!t.isImportDeclaration(stmt)) continue;\n stmt.specifiers = stmt.specifiers.filter((spec) => {\n const binding = path.scope.getBinding(spec.local.name);\n return binding ? binding.referenced : true;\n });\n }\n path.node.body = path.node.body.filter(\n (stmt) =>\n !(\n t.isImportDeclaration(stmt) &&\n stmt.specifiers.length === 0 &&\n hadSpecifiers.has(stmt)\n ),\n );\n path.stop();\n },\n });\n}\n\n/**\n * Whether a binding pattern is side-effect-free to drop: a plain identifier, or\n * an object/array pattern of plain bindings — no default values\n * (`{ a = expr }`) or computed keys (`{ [expr]: a }`), which would evaluate (and\n * thus could have side effects) at destructuring time.\n */\nfunction isPlainPattern(node: t.Node): boolean {\n if (t.isIdentifier(node)) return true;\n if (t.isObjectPattern(node)) {\n return node.properties.every((p) =>\n t.isRestElement(p)\n ? isPlainPattern(p.argument)\n : !p.computed && isPlainPattern(p.value),\n );\n }\n if (t.isArrayPattern(node)) {\n return node.elements.every((el) => el == null || isPlainPattern(el));\n }\n return false; // AssignmentPattern (default), member expr, etc.\n}\n\n/** Whether a variable initializer is safe to drop (no observable side effects). */\nfunction isRemovableInit(node: t.Expression | null | undefined): boolean {\n if (node == null) return true;\n if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node)) {\n return isRemovableInit(node.expression);\n }\n // Containers are removable only if every element is — a nested call (e.g.\n // `[track()]`) has an observable side effect that dropping would lose.\n if (t.isArrayExpression(node)) {\n return node.elements.every(\n (el) => el == null || (t.isExpression(el) && isRemovableInit(el)),\n );\n }\n if (t.isObjectExpression(node)) {\n return node.properties.every(\n (p) =>\n t.isObjectProperty(p) &&\n !p.computed &&\n t.isExpression(p.value) &&\n isRemovableInit(p.value),\n );\n }\n if (t.isTemplateLiteral(node)) {\n return node.expressions.every(\n (e) => t.isExpression(e) && isRemovableInit(e),\n );\n }\n return (\n t.isArrowFunctionExpression(node) ||\n t.isFunctionExpression(node) ||\n t.isClassExpression(node) ||\n t.isIdentifier(node) ||\n // non-computed only — `obj[fn()]` could hide a side-effectful key\n (t.isMemberExpression(node) && !node.computed) ||\n t.isJSXElement(node) ||\n t.isJSXFragment(node) ||\n t.isLiteral(node)\n );\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,gBAAgB;CACpB;CACA;CACA;AACF;AAIA,MAAM,WACJ,OAAO,cAAc,aAAa,YAAa,UAAkB;AAEnE,MAAM,WACJ,OAAO,cAAc,aAAa,YAAa,UAAkB;;AAMnE,MAAM,kBAAkB;;AAExB,MAAM,sBAAsB;;AAE5B,MAAM,qBAAqB;;AAE3B,MAAM,eAAe;;AAErB,MAAM,mBAAmB;;AAEzB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;AACF;;AAEA,MAAM,wBAAwB;;;;;;AAM9B,MAAM,qBAAqB;;;;;;;AAO3B,MAAM,4BAA4B;;AA2ClC,IAAa,yBAAb,cAA4C,MAAM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,EAAE,KAAK,CAC3B;CAEF,IAAI,EAAE,kBAAkB,IAAI,GAC1B,OAAO,KAAK,YAAY,OACrB,MAAM,EAAE,aAAa,CAAC,KAAK,gBAAgB,CAAC,CAC/C;CAEF,OACE,EAAE,0BAA0B,IAAI,KAChC,EAAE,qBAAqB,IAAI,KAC3B,EAAE,kBAAkB,IAAI,KACxB,EAAE,aAAa,IAAI,KAElB,EAAE,mBAAmB,IAAI,KAAK,CAAC,KAAK,YACrC,EAAE,aAAa,IAAI,KACnB,EAAE,cAAc,IAAI,KACpB,EAAE,UAAU,IAAI;AAEpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DIRECTIVE, Target } from "./constants.js";
|
|
2
|
-
import { CompileOptions, CompileResult, GenerativeCompileError, ToolType, compileGenerative, isGenerativeModule } from "./compile.js";
|
|
3
|
-
export { type CompileOptions, type CompileResult, DIRECTIVE, GenerativeCompileError, type Target, type ToolType, compileGenerative, isGenerativeModule };
|
|
2
|
+
import { CompileOptions, CompileResult, GenerativeCompileError, ToolType, compileGenerative, isGenerativeModule, isGenerativeSource } from "./compile.js";
|
|
3
|
+
export { type CompileOptions, type CompileResult, DIRECTIVE, GenerativeCompileError, type Target, type ToolType, compileGenerative, isGenerativeModule, isGenerativeSource };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DIRECTIVE } from "./constants.js";
|
|
2
|
-
import { GenerativeCompileError, compileGenerative, isGenerativeModule } from "./compile.js";
|
|
3
|
-
export { DIRECTIVE, GenerativeCompileError, compileGenerative, isGenerativeModule };
|
|
2
|
+
import { GenerativeCompileError, compileGenerative, isGenerativeModule, isGenerativeSource } from "./compile.js";
|
|
3
|
+
export { DIRECTIVE, GenerativeCompileError, compileGenerative, isGenerativeModule, isGenerativeSource };
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/x-generative-compiler",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.15",
|
|
5
5
|
"description": "Internal: the framework-agnostic \"use generative\" compiler that splits a colocated tool (schema + server-only execute + client-only render) into per-target builds. Shared by @assistant-ui/next and @assistant-ui/vite.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"assistant-ui",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"semver": "^7.8.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@assistant-ui/x-buildutils": "0.0.24",
|
|
39
40
|
"@types/babel__generator": "^7.27.0",
|
|
40
41
|
"@types/babel__traverse": "^7.28.0",
|
|
41
|
-
"@types/node": "^26.
|
|
42
|
+
"@types/node": "^26.2.0",
|
|
42
43
|
"@types/semver": "^7.8.0",
|
|
43
|
-
"vitest": "^4.1.
|
|
44
|
-
"@assistant-ui/x-buildutils": "0.0.22"
|
|
44
|
+
"vitest": "^4.1.11"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public",
|
package/src/compile.test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { describe, it, expect, vi } from "vitest";
|
|
|
5
5
|
import {
|
|
6
6
|
compileGenerative,
|
|
7
7
|
isGenerativeModule,
|
|
8
|
+
isGenerativeSource,
|
|
8
9
|
GenerativeCompileError,
|
|
9
10
|
} from "./compile";
|
|
10
11
|
|
|
@@ -1884,4 +1885,78 @@ export default defineToolkit({
|
|
|
1884
1885
|
),
|
|
1885
1886
|
).toBe(false);
|
|
1886
1887
|
});
|
|
1888
|
+
|
|
1889
|
+
it("detects generative source files", () => {
|
|
1890
|
+
const source = `"use generative";\nexport default {};`;
|
|
1891
|
+
|
|
1892
|
+
for (const filename of [
|
|
1893
|
+
"toolkit.ts",
|
|
1894
|
+
"toolkit.tsx",
|
|
1895
|
+
"toolkit.mts",
|
|
1896
|
+
"toolkit.cjsx",
|
|
1897
|
+
]) {
|
|
1898
|
+
expect(isGenerativeSource(filename, source)).toBe(true);
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
expect(isGenerativeSource("toolkit.css", source)).toBe(false);
|
|
1902
|
+
expect(isGenerativeSource("toolkit.ts", "export default {};")).toBe(false);
|
|
1903
|
+
});
|
|
1904
|
+
});
|
|
1905
|
+
|
|
1906
|
+
describe("backendless builds", () => {
|
|
1907
|
+
const source = `"use generative";
|
|
1908
|
+
import { defineToolkit, humanTool } from "@assistant-ui/react";
|
|
1909
|
+
import { JSONGenerativeUI } from "@assistant-ui/react-generative-ui";
|
|
1910
|
+
const generative = new JSONGenerativeUI({ library: {} });
|
|
1911
|
+
export default defineToolkit({
|
|
1912
|
+
toast: {
|
|
1913
|
+
parameters: { type: "object", properties: {} },
|
|
1914
|
+
execute: async () => {
|
|
1915
|
+
"use client";
|
|
1916
|
+
return 1;
|
|
1917
|
+
},
|
|
1918
|
+
render: () => null,
|
|
1919
|
+
},
|
|
1920
|
+
ask: {
|
|
1921
|
+
parameters: { type: "object", properties: {} },
|
|
1922
|
+
execute: humanTool(),
|
|
1923
|
+
render: () => null,
|
|
1924
|
+
},
|
|
1925
|
+
present: generative.present(),
|
|
1926
|
+
});
|
|
1927
|
+
`;
|
|
1928
|
+
|
|
1929
|
+
it("does not mark client frontend/human tools with backend defaults", () => {
|
|
1930
|
+
const code = compileGenerative(source, {
|
|
1931
|
+
target: "client",
|
|
1932
|
+
backendless: true,
|
|
1933
|
+
}).code;
|
|
1934
|
+
expect(code).not.toContain("unstable_backendDefault: {");
|
|
1935
|
+
expect(code).toContain('type: "frontend"');
|
|
1936
|
+
expect(code).toContain('type: "human"');
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
it("strips the runtime marker from pass-through generative entries", () => {
|
|
1940
|
+
const code = compileGenerative(source, {
|
|
1941
|
+
target: "client",
|
|
1942
|
+
backendless: true,
|
|
1943
|
+
}).code;
|
|
1944
|
+
expect(code).toContain("generative.present()");
|
|
1945
|
+
expect(code).toContain("...tool");
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
it("leaves generative entries untouched without the flag", () => {
|
|
1949
|
+
const code = compileGenerative(source, { target: "client" }).code;
|
|
1950
|
+
expect(code).toContain("present: generative.present()");
|
|
1951
|
+
expect(code).not.toContain("...tool");
|
|
1952
|
+
});
|
|
1953
|
+
|
|
1954
|
+
it("emits an identical server build with and without the flag", () => {
|
|
1955
|
+
const withFlag = compileGenerative(source, {
|
|
1956
|
+
target: "server",
|
|
1957
|
+
backendless: true,
|
|
1958
|
+
}).code;
|
|
1959
|
+
const withoutFlag = compileGenerative(source, { target: "server" }).code;
|
|
1960
|
+
expect(withFlag).toBe(withoutFlag);
|
|
1961
|
+
});
|
|
1887
1962
|
});
|
package/src/compile.ts
CHANGED
|
@@ -83,6 +83,15 @@ export interface CompileOptions {
|
|
|
83
83
|
* throw — see the Vite integration.
|
|
84
84
|
*/
|
|
85
85
|
injectServerOnly?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* No backend of the app imports this module's server build (e.g. cloud-hosted
|
|
88
|
+
* runs), so the client is the only place the model can learn the schemas
|
|
89
|
+
* from. The `client` target then keeps frontend/human tool schemas
|
|
90
|
+
* uploadable — no `unstable_backendDefault` marker is stamped — and local
|
|
91
|
+
* `new JSONGenerativeUI({ ... })` instances are constructed with
|
|
92
|
+
* `backendless: true` so their `present`/`prompt_user` schemas upload too.
|
|
93
|
+
*/
|
|
94
|
+
backendless?: boolean;
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
export interface CompileResult {
|
|
@@ -133,6 +142,9 @@ export function isGenerativeModule(code: string): boolean {
|
|
|
133
142
|
return hasDirectiveTerminator(code, directiveEnd + 1);
|
|
134
143
|
}
|
|
135
144
|
|
|
145
|
+
export const isGenerativeSource = (filename: string, source: string): boolean =>
|
|
146
|
+
/\.[cm]?[jt]sx?$/.test(filename) && isGenerativeModule(source);
|
|
147
|
+
|
|
136
148
|
function hasDirectiveTerminator(code: string, start: number): boolean {
|
|
137
149
|
let i = start;
|
|
138
150
|
let sawLineTerminator = false;
|
|
@@ -249,6 +261,7 @@ export function compileGenerative(
|
|
|
249
261
|
options: CompileOptions,
|
|
250
262
|
): CompileResult {
|
|
251
263
|
const { target, filename } = options;
|
|
264
|
+
const backendless = options.backendless ?? false;
|
|
252
265
|
|
|
253
266
|
const ast = parse(code, {
|
|
254
267
|
sourceType: "module",
|
|
@@ -315,6 +328,7 @@ export function compileGenerative(
|
|
|
315
328
|
toolkitSpreadNames,
|
|
316
329
|
namespaceImports,
|
|
317
330
|
flags,
|
|
331
|
+
backendless,
|
|
318
332
|
filename,
|
|
319
333
|
);
|
|
320
334
|
path.replaceWith(object);
|
|
@@ -642,6 +656,30 @@ function collectGenerativeInstances(ast: t.File): Set<string> {
|
|
|
642
656
|
return names;
|
|
643
657
|
}
|
|
644
658
|
|
|
659
|
+
/**
|
|
660
|
+
* Wraps a pass-through generative entry (`generative.present()`) so the tool it
|
|
661
|
+
* returns loses its `unstable_backendDefault` marker. The library stamps the
|
|
662
|
+
* marker at runtime, out of this compiler's reach, so a backendless client
|
|
663
|
+
* build strips it post-hoc instead of threading an option into the library.
|
|
664
|
+
*/
|
|
665
|
+
function stripBackendDefaultExpression(expr: t.Expression): t.Expression {
|
|
666
|
+
return t.callExpression(
|
|
667
|
+
t.arrowFunctionExpression(
|
|
668
|
+
[
|
|
669
|
+
t.objectPattern([
|
|
670
|
+
t.objectProperty(
|
|
671
|
+
t.identifier("unstable_backendDefault"),
|
|
672
|
+
t.identifier("_backendDefault"),
|
|
673
|
+
),
|
|
674
|
+
t.restElement(t.identifier("tool")),
|
|
675
|
+
]),
|
|
676
|
+
],
|
|
677
|
+
t.identifier("tool"),
|
|
678
|
+
),
|
|
679
|
+
[expr],
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
|
|
645
683
|
function collectGenerativeFactoryImports(ast: t.File): Set<string> {
|
|
646
684
|
const names = new Set<string>();
|
|
647
685
|
for (const statement of ast.program.body) {
|
|
@@ -1358,6 +1396,7 @@ function compileToolkit(
|
|
|
1358
1396
|
toolkitSpreadNames: ToolkitSpreadNames,
|
|
1359
1397
|
namespaceImports: Set<string>,
|
|
1360
1398
|
flags: TargetFlags,
|
|
1399
|
+
backendless: boolean,
|
|
1361
1400
|
filename: string | undefined,
|
|
1362
1401
|
): void {
|
|
1363
1402
|
// Split builds compile both targets; emit target-independent warnings from
|
|
@@ -1384,6 +1423,9 @@ function compileToolkit(
|
|
|
1384
1423
|
// `execute` could reach the client unstripped.
|
|
1385
1424
|
const raw = entryRawValue(entry);
|
|
1386
1425
|
if (raw && isGenerativeToolEntry(raw, instances)) {
|
|
1426
|
+
if (backendless && target === "client" && t.isObjectProperty(entry)) {
|
|
1427
|
+
entry.value = stripBackendDefaultExpression(raw);
|
|
1428
|
+
}
|
|
1387
1429
|
nextProperties.push(entry);
|
|
1388
1430
|
continue;
|
|
1389
1431
|
}
|
|
@@ -1473,7 +1515,7 @@ function compileToolkit(
|
|
|
1473
1515
|
}
|
|
1474
1516
|
|
|
1475
1517
|
setToolType(value, type);
|
|
1476
|
-
setBackendDefault(value, target, type);
|
|
1518
|
+
setBackendDefault(value, target, type, backendless);
|
|
1477
1519
|
nextProperties.push(entry);
|
|
1478
1520
|
}
|
|
1479
1521
|
|
|
@@ -1718,10 +1760,13 @@ function setBackendDefault(
|
|
|
1718
1760
|
object: t.ObjectExpression,
|
|
1719
1761
|
target: Target,
|
|
1720
1762
|
type: ToolType,
|
|
1763
|
+
backendless: boolean,
|
|
1721
1764
|
): void {
|
|
1722
1765
|
// Always strip any hand-authored marker first; only re-add it for client
|
|
1723
|
-
// frontend/human tools whose schema is already known by the backend.
|
|
1766
|
+
// frontend/human tools whose schema is already known by the backend. A
|
|
1767
|
+
// backendless build has no such backend, so nothing is marked.
|
|
1724
1768
|
removeMember(object, "unstable_backendDefault");
|
|
1769
|
+
if (backendless) return;
|
|
1725
1770
|
if (target !== "client" || (type !== "frontend" && type !== "human")) return;
|
|
1726
1771
|
|
|
1727
1772
|
object.properties.push(
|