The Open Framework for Building Agents
fix(eve): dev bundling - delegate dependency packaging to Nitro (#803)
Andrew Barbadddfb20f360a
diff --git a/.changeset/bright-bundles-wait.md b/.changeset/bright-bundles-wait.mdnew file mode 100644index 000000000..4a39ae8a0--- /dev/null+++ b/.changeset/bright-bundles-wait.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Fix `eve dev` generation bundling for authored modules whose dependencies use dynamic imports. Development generations now bundle ordinary dependencies directly instead of inheriting a copied server-external package list and tracing dependency closures; Nitro remains the sole owner of hosted dependency packaging.diff --git a/docs/agent-config.md b/docs/agent-config.mdindex e6da47ecd..21d574530 100644--- a/docs/agent-config.md+++ b/docs/agent-config.md@@ -214,6 +214,8 @@ installed package must stay external in hosted output, list it in`externalDependencies` is a packaging control only. It keeps selected packages as runtime dependencies in the hosted output; it does not authorize, configure, or review any third-party service those packages may call.+During `eve dev`, ordinary dependencies are bundled into each retained runtime generation. Packages listed in `externalDependencies` keep normal Node.js resolution instead, so replacing one of those packages requires restarting the dev server.+## Where adjacent settings live| Concern | Lives in |diff --git a/e2e/fixtures/agent-tools/agent/lib/dynamic-import-marker.ts b/e2e/fixtures/agent-tools/agent/lib/dynamic-import-marker.tsnew file mode 100644index 000000000..917e7eab3--- /dev/null+++ b/e2e/fixtures/agent-tools/agent/lib/dynamic-import-marker.ts@@ -0,0 +1 @@+export const marker = "authored-dynamic-import-loaded";diff --git a/e2e/fixtures/agent-tools/agent/tools/read-dynamic-dependency.ts b/e2e/fixtures/agent-tools/agent/tools/read-dynamic-dependency.tsnew file mode 100644index 000000000..e89bd972d--- /dev/null+++ b/e2e/fixtures/agent-tools/agent/tools/read-dynamic-dependency.ts@@ -0,0 +1,17 @@+import { readDynamicImportMarker } from "@eve-e2e/dynamic-import-dependency";+import { defineTool } from "eve/tools";+import { z } from "zod";++export default defineTool({+ description:+ "Loads the dynamic dependency marker. Only call when the user explicitly asks to use `read-dynamic-dependency`.",+ inputSchema: z.object({}),+ async execute() {+ const [{ marker: authoredMarker }, dependencyMarker] = await Promise.all([+ import("../lib/dynamic-import-marker"),+ readDynamicImportMarker(),+ ]);++ return { authoredMarker, dependencyMarker };+ },+});diff --git a/e2e/fixtures/agent-tools/evals/static-tools/dynamic-dependency-import.eval.ts b/e2e/fixtures/agent-tools/evals/static-tools/dynamic-dependency-import.eval.tsnew file mode 100644index 000000000..0d138ccdb--- /dev/null+++ b/e2e/fixtures/agent-tools/evals/static-tools/dynamic-dependency-import.eval.ts@@ -0,0 +1,20 @@+import { defineEval } from "eve/evals";++export default defineEval({+ description: "Static tools smoke: authored modules and dependencies can use dynamic imports.",+ async test(t) {+ await t.send(+ "Call the `read-dynamic-dependency` tool. Reply with its marker exactly as returned.",+ );++ t.succeeded();+ t.calledTool("read-dynamic-dependency", {+ output: (value: unknown) =>+ typeof value === "object" &&+ value !== null &&+ !Array.isArray(value) &&+ (value as Record<string, unknown>).authoredMarker === "authored-dynamic-import-loaded" &&+ (value as Record<string, unknown>).dependencyMarker === "dynamic-dependency-loaded",+ });+ },+});diff --git a/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/index.d.ts b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/index.d.tsnew file mode 100644index 000000000..802bc5186--- /dev/null+++ b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/index.d.ts@@ -0,0 +1 @@+export declare function readDynamicImportMarker(): Promise<string>;diff --git a/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/index.js b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/index.jsnew file mode 100644index 000000000..8454d3596--- /dev/null+++ b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/index.js@@ -0,0 +1,4 @@+export async function readDynamicImportMarker() {+ const { marker } = await import("./marker.js");+ return marker;+}diff --git a/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/marker.js b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/marker.jsnew file mode 100644index 000000000..712e0676b--- /dev/null+++ b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/marker.js@@ -0,0 +1 @@+export const marker = "dynamic-dependency-loaded";diff --git a/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/package.json b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/package.jsonnew file mode 100644index 000000000..4126ea9c2--- /dev/null+++ b/e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency/package.json@@ -0,0 +1,12 @@+{+ "name": "@eve-e2e/dynamic-import-dependency",+ "version": "0.0.0",+ "private": true,+ "type": "module",+ "exports": {+ ".": {+ "types": "./index.d.ts",+ "import": "./index.js"+ }+ }+}diff --git a/e2e/fixtures/agent-tools/package.json b/e2e/fixtures/agent-tools/package.jsonindex 30b07afc0..869a1b9a1 100644--- a/e2e/fixtures/agent-tools/package.json+++ b/e2e/fixtures/agent-tools/package.json@@ -11,6 +11,7 @@"test:e2e": "eve eval --strict"},"dependencies": {+ "@eve-e2e/dynamic-import-dependency": "file:./fixtures/dynamic-import-dependency","@opentelemetry/core": "2.6.1","@opentelemetry/sdk-trace-base": "2.6.1","@vercel/otel": "2.1.2",diff --git a/packages/eve/src/internal/authored-module-loader.scenario.test.ts b/packages/eve/src/internal/authored-module-loader.scenario.test.tsindex 8268dbf93..01fffef1d 100644--- a/packages/eve/src/internal/authored-module-loader.scenario.test.ts+++ b/packages/eve/src/internal/authored-module-loader.scenario.test.ts@@ -477,7 +477,7 @@ describe("loadAuthoredModuleNamespace", () => {}});- it("keeps default external dependencies external when imported from workspace packages", async () => {+ it("bundles unconfigured dependencies imported from workspace packages", async () => {const app = await scenarioApp({files: {"agent/channels/api/contact-sales/webhook.ts": [@@ -487,9 +487,9 @@ describe("loadAuthoredModuleNamespace", () => {"",].join("\n"),},- name: "workspace-package-default-external",+ name: "workspace-package-bundled-dependency",});- const workspaceRoot = await mkdtemp(join(tmpdir(), "eve-workspace-default-external-"));+ const workspaceRoot = await mkdtemp(join(tmpdir(), "eve-workspace-bundled-dependency-"));try {const packageRoot = join(workspaceRoot, "packages", "enrichment");@@ -532,7 +532,7 @@ describe("loadAuthoredModuleNamespace", () => {);await writeFile(join(externalPackageRoot, "runtimeConfig.shared.js"),- "module.exports = { value: 'default-externalized' };\n",+ "module.exports = { value: 'bundled-dependency' };\n",);await mkdir(join(app.appRoot, "node_modules", "@repo"), { recursive: true });@@ -546,7 +546,7 @@ describe("loadAuthoredModuleNamespace", () => {join(app.appRoot, "agent", "channels", "api", "contact-sales", "webhook.ts"),);- expect(moduleNamespace.result).toBe("default-externalized");+ expect(moduleNamespace.result).toBe("bundled-dependency");} finally {await rm(workspaceRoot, { force: true, recursive: true });}diff --git a/packages/eve/src/internal/authored-module-loader.ts b/packages/eve/src/internal/authored-module-loader.tsindex d7b873c2c..4632e1d4e 100644--- a/packages/eve/src/internal/authored-module-loader.ts+++ b/packages/eve/src/internal/authored-module-loader.ts@@ -22,7 +22,6 @@ import {buildWithNitroRolldown,getSingleRolldownChunk,} from "#internal/bundler/nitro-rolldown.js";-import type { ResolvedAuthoredExternalModule } from "#internal/materialize-authored-external-dependencies.js";import { createNodeEsmCompatBannerPlugin } from "#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION = /\.[cm]?[jt]sx?$/;@@ -44,11 +43,6 @@ export interface AuthoredModuleLoadOptions {readonly extensionScopeNamespace?: string;}-export interface AuthoredGenerationModuleBundle {- readonly code: string;- readonly externalModules: readonly ResolvedAuthoredExternalModule[];-}-function getChannelModuleCache(): Map<string, unknown> | undefined {return (globalThis as Record<string, unknown>)[CHANNEL_MODULE_CACHE_KEY] as| Map<string, unknown>@@ -158,15 +152,13 @@ export async function bundleAuthoredModuleCode(/*** Bundles one authored entry for an immutable development generation. Ordinary* package dependencies are inlined so the emitted code stays executable after- * the original workspace changes; framework runtime imports and configured- * external dependencies stay external, and every configured external the- * bundle references is reported for closure materialization.+ * the original workspace changes; framework runtime imports and explicitly+ * configured external dependencies keep their normal runtime resolution.*/export async function bundleAuthoredModuleForGeneration(modulePath: string,options: AuthoredModuleLoadOptions = {},-): Promise<AuthoredGenerationModuleBundle> {- const externalModules = new Map<string, ResolvedAuthoredExternalModule>();+): Promise<string> {const code = await buildAuthoredModuleBundle(modulePath, options, {// Generation bundles must not reference process state: the channel// identity plugin emits reads of a process-global cache keyed by live@@ -175,25 +167,12 @@ export async function bundleAuthoredModuleForGeneration(packageBoundaryPlugin: createGenerationPackageBoundaryPlugin({externalDependencies: normalizeExternalDependencies(options.externalDependencies),packageRoot: resolveAuthoredPackageRoot(modulePath),- recordExternalModule(externalModule) {- externalModules.set(- `${externalModule.packageName}\0${externalModule.resolvedId}`,- externalModule,- );- },}),plugins: [createAuthoredDirectiveGuardPlugin()],sourcemap: false,});- return {- code: removeRolldownModuleRegionComments(code),- externalModules: [...externalModules.values()].sort((left, right) =>- `${left.packageName}\0${left.resolvedId}`.localeCompare(- `${right.packageName}\0${right.resolvedId}`,- ),- ),- };+ return removeRolldownModuleRegionComments(code);}async function buildAuthoredModuleBundle(@@ -284,6 +263,7 @@ async function buildAuthoredModuleBundle(tsconfig: tsconfigPath,write: false,output: {+ codeSplitting: false,comments: false,format: "esm",sourcemap: configuration.sourcemap,diff --git a/packages/eve/src/internal/authored-package-boundary.ts b/packages/eve/src/internal/authored-package-boundary.tsindex 28c96d3bb..2748e3a26 100644--- a/packages/eve/src/internal/authored-package-boundary.ts+++ b/packages/eve/src/internal/authored-package-boundary.ts@@ -1,9 +1,6 @@import { existsSync, realpathSync } from "node:fs";import { join, resolve, sep } from "node:path";-import type { ResolvedAuthoredExternalModule } from "#internal/materialize-authored-external-dependencies.js";-import { SERVER_EXTERNAL_PACKAGES } from "#internal/nitro/host/server-external-packages.js";-export const CACHED_CHANNEL_PREFIX = "eve-cached-channel:";export const RESOLVE_EXTENSIONS = [@@ -30,10 +27,14 @@ export type RolldownResolveContext = {): Promise<RolldownResolveResult | null>;};+interface ResolvedAuthoredExternalModule {+ readonly packageName: string;+ readonly resolvedId: string;+}+export function createGenerationPackageBoundaryPlugin(input: {readonly externalDependencies: readonly string[];readonly packageRoot: string;- readonly recordExternalModule: (externalModule: ResolvedAuthoredExternalModule) => void;}): Record<string, unknown> {return {name: "eve-generation-package-boundary",@@ -65,7 +66,6 @@ export function createGenerationPackageBoundaryPlugin(input: {return undefined;}- input.recordExternalModule(externalModule);return { external: true, id: source };},};@@ -191,7 +191,10 @@ async function resolveConfiguredExternalModule(export function normalizeExternalDependencies(externalDependencies: readonly string[] = [],): string[] {- return [...new Set([...SERVER_EXTERNAL_PACKAGES, ...externalDependencies])].sort();+ // This is intentionally explicit-only. Nitro owns hosted dependency+ // classification; applying its trace set to authored generation bundles+ // would turn bundleable packages into a second dev-only packaging graph.+ return [...new Set(externalDependencies)].sort();}function resolveConfiguredExternalDependency(diff --git a/packages/eve/src/internal/bundler/nitro-node-file-trace.ts b/packages/eve/src/internal/bundler/nitro-node-file-trace.tsdeleted file mode 100644index a419206a8..000000000--- a/packages/eve/src/internal/bundler/nitro-node-file-trace.ts+++ /dev/null@@ -1,49 +0,0 @@-import { createRequire } from "node:module";-import { pathToFileURL } from "node:url";--interface NodeFileTraceResult {- readonly fileList: ReadonlySet<string>;- readonly warnings: ReadonlySet<Error>;-}--type NodeFileTrace = (- files: string[],- options: {- readonly base: string;- readonly conditions: string[];- readonly processCwd: string;- },-) => Promise<NodeFileTraceResult>;--interface NodeFileTraceModule {- readonly nodeFileTrace: NodeFileTrace;-}--let nodeFileTraceModulePromise: Promise<NodeFileTraceModule> | undefined;--async function loadNitroNodeFileTrace(): Promise<NodeFileTraceModule> {- nodeFileTraceModulePromise ??= (async () => {- const require = createRequire(import.meta.url);- const nitroRequire = createRequire(require.resolve("nitro/package.json"));- const modulePath = nitroRequire.resolve("@vercel/nft");- return (await import(pathToFileURL(modulePath).href)) as NodeFileTraceModule;- })();-- return await nodeFileTraceModulePromise;-}--// Traces under `node` + `import` conditions: the runtime loads materialized-// externals with ESM `import()`, so tracing through `require` conditions-// would materialize files the runtime never resolves.-export async function traceNodeEsmFiles(input: {- readonly base: string;- readonly entries: readonly string[];- readonly processCwd: string;-}): Promise<NodeFileTraceResult> {- const { nodeFileTrace } = await loadNitroNodeFileTrace();- return await nodeFileTrace([...input.entries], {- base: input.base,- conditions: ["node", "import"],- processCwd: input.processCwd,- });-}diff --git a/packages/eve/src/internal/materialize-authored-external-dependencies.ts b/packages/eve/src/internal/materialize-authored-external-dependencies.tsdeleted file mode 100644index 821b245e3..000000000--- a/packages/eve/src/internal/materialize-authored-external-dependencies.ts+++ /dev/null@@ -1,397 +0,0 @@-import { createHash } from "node:crypto";-import { constants as fsConstants } from "node:fs";-import {- copyFile,- lstat,- mkdir,- readFile,- readdir,- readlink,- realpath,- rm,- stat,- symlink,-} from "node:fs/promises";-import { dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";--import { traceNodeEsmFiles } from "#internal/bundler/nitro-node-file-trace.js";--const COPY_MODE = fsConstants.COPYFILE_FICLONE;--export interface ResolvedAuthoredExternalModule {- readonly packageName: string;- readonly resolvedId: string;-}--export async function materializeAuthoredExternalDependencies(input: {- readonly appRoot: string;- readonly externalModules: readonly ResolvedAuthoredExternalModule[];- readonly snapshotSourceRoot: string;- readonly sourceRoot: string;-}): Promise<string> {- if (input.externalModules.length === 0) {- return createHash("sha256").digest("hex");- }-- const sourceRoot = await realpath(input.sourceRoot);- const appRoot = await realpath(input.appRoot);- const packages = await resolveExternalPackages(input.externalModules);-- const fingerprint = createHash("sha256");- const tracedPaths = await traceExternalDependencyPaths(packages, appRoot);- const materializedPaths = new Set<string>();- const materializedDirectories = new Set<string>();-- for (const externalPackage of packages) {- await materializeDependencyDirectory({- fingerprint,- materializedDirectories,- materializedPaths,- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath: externalPackage.packageRoot,- sourceRoot,- });- }-- for (const tracedPath of tracedPaths) {- const packageRoot = await findNearestPackageRoot(tracedPath);- if (packageRoot !== undefined) {- await materializeDependencyDirectory({- fingerprint,- materializedDirectories,- materializedPaths,- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath: packageRoot,- sourceRoot,- });- }- }-- for (const tracedPath of tracedPaths) {- await materializeTracedPath({- fingerprint,- materializedPaths,- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath: tracedPath,- sourceRoot,- });- }-- for (const externalPackage of packages) {- const materializedPackageRoot = toMaterializedPath({- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath: externalPackage.packageRoot,- sourceRoot,- });- const runtimePackageRoot = join(- toMaterializedPath({- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath: appRoot,- sourceRoot,- }),- "node_modules",- ...externalPackage.packageName.split("/"),- );-- if (resolve(runtimePackageRoot) !== resolve(materializedPackageRoot)) {- await rm(runtimePackageRoot, { force: true, recursive: true });- await mkdir(dirname(runtimePackageRoot), { recursive: true });- await symlink(- relative(dirname(runtimePackageRoot), materializedPackageRoot) || ".",- runtimePackageRoot,- "junction",- );- }-- fingerprint- .update("package\0")- .update(externalPackage.packageName)- .update("\0")- .update(toSemanticPath(externalPackage.packageRoot, sourceRoot))- .update("\0");- }-- return fingerprint.digest("hex");-}--async function traceExternalDependencyPaths(- packages: readonly ExternalPackage[],- processCwd: string,-): Promise<string[]> {- const groups = new Map<string, { base: string; entries: string[] }>();-- for (const externalPackage of packages) {- const base = parse(externalPackage.resolvedId).root;- const key = normalizePathRoot(base);- const group = groups.get(key) ?? { base, entries: [] };- group.entries.push(externalPackage.resolvedId);- groups.set(key, group);- }-- const tracedPaths = new Set<string>();- const warnings: Error[] = [];-- for (const group of [...groups.values()].sort((left, right) =>- normalizePathRoot(left.base).localeCompare(normalizePathRoot(right.base)),- )) {- const trace = await traceNodeEsmFiles({- base: group.base,- entries: group.entries.sort(),- processCwd,- });- warnings.push(...trace.warnings);-- for (const tracedPath of trace.fileList) {- tracedPaths.add(isAbsolute(tracedPath) ? tracedPath : resolve(group.base, tracedPath));- }- }-- if (warnings.length > 0) {- const messages = warnings.map((warning) => warning.message).sort();- throw new Error(- `Failed to trace the complete authored external dependency closure:\n${messages.join("\n")}`,- );- }-- return [...tracedPaths].sort((left, right) => left.localeCompare(right));-}--async function materializeDependencyDirectory(input: {- readonly fingerprint: ReturnType<typeof createHash>;- readonly materializedDirectories: Set<string>;- readonly materializedPaths: Set<string>;- readonly snapshotSourceRoot: string;- readonly sourcePath: string;- readonly sourceRoot: string;-}): Promise<void> {- const canonicalDirectory = await realpath(input.sourcePath);- if (input.materializedDirectories.has(canonicalDirectory)) {- return;- }- input.materializedDirectories.add(canonicalDirectory);-- for (const entry of (await readdir(canonicalDirectory, { withFileTypes: true })).sort(- (left, right) => left.name.localeCompare(right.name),- )) {- const sourcePath = join(canonicalDirectory, entry.name);- const sourceStats = await lstat(sourcePath);-- if (sourceStats.isDirectory()) {- await materializeDependencyDirectory({ ...input, sourcePath });- continue;- }-- if (sourceStats.isSymbolicLink()) {- await materializeTracedPath({- fingerprint: input.fingerprint,- materializedPaths: input.materializedPaths,- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath,- sourceRoot: input.sourceRoot,- });- continue;- }-- await materializeTracedPath({- fingerprint: input.fingerprint,- materializedPaths: input.materializedPaths,- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath,- sourceRoot: input.sourceRoot,- });- }-}--interface ExternalPackage {- readonly packageName: string;- readonly packageRoot: string;- readonly resolvedId: string;-}--async function resolveExternalPackages(- modules: readonly ResolvedAuthoredExternalModule[],-): Promise<ExternalPackage[]> {- const packagesByName = new Map<string, ExternalPackage>();-- for (const module of modules) {- const packageRoot = await findPackageRoot(module.resolvedId, module.packageName);- const existing = packagesByName.get(module.packageName);-- if (existing !== undefined && resolve(existing.packageRoot) !== resolve(packageRoot)) {- throw new Error(- `Authored external dependency "${module.packageName}" resolves to multiple package instances.`,- );- }-- packagesByName.set(module.packageName, {- packageName: module.packageName,- packageRoot,- resolvedId: module.resolvedId,- });- }-- return [...packagesByName.values()].sort((left, right) =>- left.packageName.localeCompare(right.packageName),- );-}--async function findPackageRoot(resolvedId: string, packageName: string): Promise<string> {- let current = dirname(await realpath(resolvedId));-- while (true) {- const packageJsonPath = join(current, "package.json");-- try {- const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8")) as {- readonly name?: unknown;- };-- if (packageJson.name === packageName) {- return current;- }- } catch (error) {- if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {- throw error;- }- }-- const parent = dirname(current);- if (parent === current) {- throw new Error(- `Cannot find package root for authored external dependency "${packageName}" from "${resolvedId}".`,- );- }- current = parent;- }-}--async function findNearestPackageRoot(path: string): Promise<string | undefined> {- const canonicalPath = await realpath(path);- let current = (await stat(canonicalPath)).isDirectory() ? canonicalPath : dirname(canonicalPath);-- while (true) {- try {- const packageJson = JSON.parse(await readFile(join(current, "package.json"), "utf8")) as {- readonly name?: unknown;- };- if (typeof packageJson.name === "string" && packageJson.name.length > 0) {- return current;- }- } catch (error) {- if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {- throw error;- }- }-- const parent = dirname(current);- if (parent === current) {- return undefined;- }- current = parent;- }-}--async function materializeTracedPath(input: {- readonly fingerprint: ReturnType<typeof createHash>;- readonly materializedPaths: Set<string>;- readonly snapshotSourceRoot: string;- readonly sourcePath: string;- readonly sourceRoot: string;-}): Promise<void> {- const materializedPathKey = toSemanticPath(input.sourcePath, input.sourceRoot);- if (input.materializedPaths.has(materializedPathKey)) {- return;- }- input.materializedPaths.add(materializedPathKey);-- const targetPath = toMaterializedPath(input);- const sourceStats = await lstat(input.sourcePath);- const portablePath = toSemanticPath(input.sourcePath, input.sourceRoot);-- if (sourceStats.isSymbolicLink()) {- const declaredTarget = await readlink(input.sourcePath);- const resolvedTarget = await realpath(resolve(dirname(input.sourcePath), declaredTarget));- const targetLinkTarget = toMaterializedPath({- snapshotSourceRoot: input.snapshotSourceRoot,- sourcePath: resolvedTarget,- sourceRoot: input.sourceRoot,- });- const targetStats = await stat(input.sourcePath);-- await rm(targetPath, { force: true, recursive: true });- await mkdir(dirname(targetPath), { recursive: true });- await symlink(- relative(dirname(targetPath), targetLinkTarget) || ".",- targetPath,- targetStats.isDirectory() ? "junction" : "file",- );- input.fingerprint- .update(portablePath)- .update("\0link\0")- .update(toSemanticPath(resolvedTarget, input.sourceRoot))- .update("\0");- return;- }-- if (!sourceStats.isFile()) {- throw new Error(`Unsupported traced authored dependency path "${input.sourcePath}".`);- }-- await mkdir(dirname(targetPath), { recursive: true });- await copyFile(input.sourcePath, targetPath, COPY_MODE);- input.fingerprint- .update(portablePath)- .update("\0file\0")- .update(await readFile(input.sourcePath))- .update("\0");-}--function toMaterializedPath(input: {- readonly snapshotSourceRoot: string;- readonly sourcePath: string;- readonly sourceRoot: string;-}): string {- if (isPathInsideOrEqual(input.sourcePath, input.sourceRoot)) {- return join(input.snapshotSourceRoot, relative(input.sourceRoot, input.sourcePath));- }-- const pathRoot = parse(resolve(input.sourcePath)).root;- return join(- input.snapshotSourceRoot,- ".eve",- "external-dependencies",- createPathRootKey(pathRoot),- relative(pathRoot, input.sourcePath),- );-}--function toSemanticPath(path: string, sourceRoot: string): string {- if (isPathInsideOrEqual(path, sourceRoot)) {- return `source/${toPortablePath(relative(sourceRoot, path))}`;- }-- const pathRoot = parse(resolve(path)).root;- return `external/${createPathRootKey(pathRoot)}/${toPortablePath(relative(pathRoot, path))}`;-}--function createPathRootKey(pathRoot: string): string {- return createHash("sha256").update(normalizePathRoot(pathRoot)).digest("hex").slice(0, 12);-}--function isPathInsideOrEqual(path: string, directory: string): boolean {- const relativePath = relative(resolve(directory), resolve(path));- return !(- isAbsolute(relativePath) ||- relativePath === ".." ||- relativePath.startsWith(`..${sep}`) ||- relativePath.startsWith(sep)- );-}--function normalizePathRoot(pathRoot: string): string {- return toPortablePath(pathRoot).toLowerCase();-}--function toPortablePath(path: string): string {- return path.split(sep).join("/");-}diff --git a/packages/eve/src/internal/materialized-authored-modules.ts b/packages/eve/src/internal/materialized-authored-modules.tsindex 470e8f770..d08457408 100644--- a/packages/eve/src/internal/materialized-authored-modules.ts+++ b/packages/eve/src/internal/materialized-authored-modules.ts@@ -8,10 +8,6 @@ import { COMPILED_AGENT_MANIFEST_KIND, ROOT_COMPILED_AGENT_NODE_ID } from "#compimport { collectModuleRefsForManifest } from "#compiler/module-map.js";import { bundleAuthoredModuleForGeneration } from "#internal/authored-module-loader.js";import { serializeCompiledManifestForFingerprint } from "#internal/compiled-manifest-fingerprint.js";-import {- materializeAuthoredExternalDependencies,- type ResolvedAuthoredExternalModule,-} from "#internal/materialize-authored-external-dependencies.js";const MATERIALIZED_MODULES_DIRECTORY = "authored-modules";const MATERIALIZED_MODULES_INDEX = "authored-modules.json";@@ -25,17 +21,13 @@ export interface MaterializedAuthoredModuleIndex {}export async function materializeAuthoredModules(input: {- readonly appRoot: string;readonly runtimeAppRoot: string;- readonly snapshotSourceRoot: string;- readonly sourceRoot: string;}): Promise<MaterializedAuthoredModuleIndex> {const compileRoot = join(input.runtimeAppRoot, ".eve", "compile");const manifest = await readCompiledManifest(join(compileRoot, "compiled-agent-manifest.json"));const modulesRoot = join(compileRoot, MATERIALIZED_MODULES_DIRECTORY);const scopeIndex = createExtensionScopeIndex(manifest);const nodes: Record<string, { modules: Record<string, string> }> = {};- const externalModules: ResolvedAuthoredExternalModule[] = [];const fingerprint = createHash("sha256");await mkdir(modulesRoot, { recursive: true });@@ -54,24 +46,20 @@ export async function materializeAuthoredModules(input: {for (const ref of collectModuleRefsForManifest(node.manifest).sort((left, right) =>left.sourceId.localeCompare(right.sourceId),)) {- const bundle = await bundleAuthoredModuleForGeneration(- join(node.agentRoot, ref.logicalPath),- {- externalDependencies: node.manifest.config.build?.externalDependencies ?? [],- extensionScopeNamespace: extensionNamespaceForSourceId(ref.sourceId, scopeIndex),- },- );- const fileName = createMaterializedModuleFileName(node.nodeId, ref.sourceId, bundle.code);+ const code = await bundleAuthoredModuleForGeneration(join(node.agentRoot, ref.logicalPath), {+ externalDependencies: node.manifest.config.build?.externalDependencies ?? [],+ extensionScopeNamespace: extensionNamespaceForSourceId(ref.sourceId, scopeIndex),+ });+ const fileName = createMaterializedModuleFileName(node.nodeId, ref.sourceId, code);- await writeFile(join(modulesRoot, fileName), bundle.code);- externalModules.push(...bundle.externalModules);+ await writeFile(join(modulesRoot, fileName), code);fingerprint.update("module\0").update(node.nodeId).update("\0").update(ref.sourceId).update("\0")- .update(bundle.code)+ .update(code).update("\0");modules[ref.sourceId] = join(MATERIALIZED_MODULES_DIRECTORY, fileName);}@@ -83,19 +71,18 @@ export async function materializeAuthoredModules(input: {let instrumentationPath: string | undefined;if (instrumentation !== undefined) {- const bundle = await bundleAuthoredModuleForGeneration(instrumentation, {+ const code = await bundleAuthoredModuleForGeneration(instrumentation, {externalDependencies: manifest.config.build?.externalDependencies ?? [],});const fileName = createMaterializedModuleFileName(ROOT_COMPILED_AGENT_NODE_ID,"instrumentation",- bundle.code,+ code,);- await writeFile(join(modulesRoot, fileName), bundle.code);- externalModules.push(...bundle.externalModules);+ await writeFile(join(modulesRoot, fileName), code);instrumentationPath = join(MATERIALIZED_MODULES_DIRECTORY, fileName);- fingerprint.update("instrumentation\0").update(bundle.code).update("\0");+ fingerprint.update("instrumentation\0").update(code).update("\0");}await hashDirectoryIfPresent({@@ -103,18 +90,6 @@ export async function materializeAuthoredModules(input: {path: join(compileRoot, "workspace-resources"),root: join(compileRoot, "workspace-resources"),});- fingerprint- .update("external-dependencies\0")- .update(- await materializeAuthoredExternalDependencies({- appRoot: input.appRoot,- externalModules,- snapshotSourceRoot: input.snapshotSourceRoot,- sourceRoot: input.sourceRoot,- }),- )- .update("\0");-const index: {fingerprint: string;instrumentation?: string;diff --git a/packages/eve/src/internal/nitro/dev-generation-artifacts.scenario.test.ts b/packages/eve/src/internal/nitro/dev-generation-artifacts.scenario.test.tsindex b9d3bcab3..b5dc0e1d7 100644--- a/packages/eve/src/internal/nitro/dev-generation-artifacts.scenario.test.ts+++ b/packages/eve/src/internal/nitro/dev-generation-artifacts.scenario.test.ts@@ -17,7 +17,75 @@ import { useScenarioApp } from "#internal/testing/scenario-app.js";describe("development generation artifacts", () => {const scenarioApp = useScenarioApp();- it("executes its ESM external closure after the original source and dependencies are removed", async () => {+ it("executes dynamic imports after the original bundled dependency is removed", async () => {+ const evaluationMarker = "__eveGenerationDynamicImportEvaluated__";+ const globals = globalThis as Record<string, unknown>;+ delete globals[evaluationMarker];+ const app = await scenarioApp({+ dependencies: {+ pg: "1.0.0",+ },+ files: {+ "agent/agent.mjs": 'export default { model: "openai/gpt-5.4" };\n',+ "agent/instructions.md": "Use the available tools.",+ "agent/tools/read_dynamic.mjs": [+ 'import { readDynamicValue } from "pg";',+ "",+ "export default {",+ ' description: "Read a dynamically imported value.",',+ " execute: readDynamicValue,",+ "};",+ "",+ ].join("\n"),+ },+ name: "generation-dynamic-import",+ });+ const dependencyRoot = join(app.appRoot, "node_modules", "pg");+ await mkdir(dependencyRoot, { recursive: true });+ await writeFile(+ join(dependencyRoot, "package.json"),+ `${JSON.stringify({ exports: "./index.mjs", name: "pg", type: "module" })}\n`,+ );+ await writeFile(+ join(dependencyRoot, "index.mjs"),+ [+ "export async function readDynamicValue() {",+ ' return (await import("./dynamic.mjs")).value;',+ "}",+ "",+ ].join("\n"),+ );+ await writeFile(+ join(dependencyRoot, "dynamic.mjs"),+ [+ `globalThis[${JSON.stringify(evaluationMarker)}] = true;`,+ 'export const value = "original";',+ "",+ ].join("\n"),+ );++ const compileResult = await compileAgent({ startPath: app.appRoot });+ const snapshot = await stageDevelopmentGeneration(compileResult);++ await rm(join(app.appRoot, "node_modules"), { force: true, recursive: true });+ const moduleMap = await loadCompiledModuleMapFromAuthoredSource({+ compiledArtifactsSource: createAuthoredSourceRuntimeCompiledArtifactsSource(+ snapshot.runtimeAppRoot,+ ),+ });+ const toolSourceId = compileResult.manifest.tools[0]?.sourceId;+ expect(toolSourceId).toBeDefined();+ const tool = moduleMap.nodes[ROOT_COMPILED_AGENT_NODE_ID]?.modules[toolSourceId!] as {+ default: { execute(): Promise<string> };+ };++ expect(globals[evaluationMarker]).toBeUndefined();+ await expect(tool.default.execute()).resolves.toBe("original");+ expect(globals[evaluationMarker]).toBe(true);+ delete globals[evaluationMarker];+ });++ it("bundles ordinary dependencies while configured externals keep runtime resolution", async () => {const app = await scenarioApp({dependencies: {"fixture-bundled": "1.0.0",@@ -52,25 +120,17 @@ describe("development generation artifacts", () => {const compileResult = await compileAgent({ startPath: app.appRoot });const snapshot = await stageDevelopmentGeneration(compileResult);const externalPackagePath = join(snapshot.runtimeAppRoot, "node_modules", "fixture-external");- const materializedExternalPath = await realpath(externalPackagePath);+ const resolvedExternalPath = await realpath(externalPackagePath);const canonicalSnapshotRoot = await realpath(snapshot.snapshotRoot);- expect(relative(canonicalSnapshotRoot, materializedExternalPath)).not.toMatch(- /^\.\.(?:[\\/]|$)/u,- );- expect(existsSync(join(materializedExternalPath, "binding.node"))).toBe(true);+ expect(relative(canonicalSnapshotRoot, resolvedExternalPath)).toMatch(/^\.\.(?:[\\/]|$)/u);+ expect(existsSync(join(resolvedExternalPath, "binding.node"))).toBe(true);- await writeFile(- join(externalFixtureRoot, "fixture-transitive", "index.mjs"),- 'export const transitiveValue = "external-changed";\n',- );- const changedDependencies = await stageDevelopmentGeneration(- await compileAgent({ startPath: app.appRoot }),- );- expect(changedDependencies.fingerprint).not.toBe(snapshot.fingerprint);-- await rm(join(app.appRoot, "node_modules"), { force: true, recursive: true });- await rm(externalFixtureRoot, { force: true, recursive: true });+ await rm(join(app.appRoot, "node_modules", "fixture-bundled"), {+ force: true,+ recursive: true,+ });+ await rm(join(app.appRoot, "node_modules", "@workflow"), { force: true, recursive: true });await writeFile(join(app.appRoot, "agent", "tools", "read_value.mjs"),'throw new Error("mutated source loaded");\n',@@ -90,6 +150,7 @@ describe("development generation artifacts", () => {expect(tool.default.execute()).toBe("bundled-original:serde-original:external-original:payload-original",);+ await rm(externalFixtureRoot, { force: true, recursive: true });});it("uses a path-independent fingerprint that includes instrumentation", async () => {diff --git a/packages/eve/src/internal/nitro/development-generation.ts b/packages/eve/src/internal/nitro/development-generation.tsindex 1379e9f19..b3eb97966 100644--- a/packages/eve/src/internal/nitro/development-generation.ts+++ b/packages/eve/src/internal/nitro/development-generation.ts@@ -28,10 +28,7 @@ export async function stageDevelopmentGeneration(try {const materialized = await materializeAuthoredModules({- appRoot: compileResult.project.appRoot,runtimeAppRoot: snapshot.runtimeAppRoot,- snapshotSourceRoot: snapshot.snapshotSourceRoot,- sourceRoot: snapshot.sourceRoot,});return {diff --git a/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts b/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.tsindex c10e9d1f3..6316486a0 100644--- a/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts+++ b/packages/eve/src/internal/nitro/host/create-application-nitro.scenario.test.ts@@ -511,7 +511,7 @@ describe("application Nitro creation", () => {).toBeNull();});- it("merges default server external packages with configured hosted dependencies", async () => {+ it("merges framework and configured hosted dependencies", async () => {const allNitroStub = createNitroStub();const appNitroStub = createNitroStub();const flowNitroStub = createNitroStub();@@ -546,7 +546,7 @@ describe("application Nitro creation", () => {for (const call of createNitroMock.mock.calls.slice(0, 3)) {const traceDeps = call[0].traceDeps;expect(traceDeps).toEqual(- expect.arrayContaining(["@napi-rs/keyring", "@prisma/client", "sharp", "fixture-external"]),+ expect.arrayContaining(["@napi-rs/keyring", "sharp", "fixture-external"]),);expect(traceDeps.filter((dependencyName: string) => dependencyName === "sharp")).toHaveLength(1,@@ -600,7 +600,7 @@ describe("application Nitro creation", () => {);});- it("traces framework and server defaults even when no externals are configured", async () => {+ it("leaves Nitro to classify unconfigured hosted dependencies", async () => {const nitroStub = createNitroStub();createNitroMock.mockResolvedValueOnce(nitroStub.nitro);@@ -613,17 +613,7 @@ describe("application Nitro creation", () => {createProductionOptions(preparedHost, "all"),);- expect(createNitroMock.mock.calls[0]?.[0].traceDeps).toEqual(- expect.arrayContaining([- "@aws-sdk/client-kms",- "@aws-sdk/client-sso",- "@datadog/flagging-core",- "@napi-rs/keyring",- "@prisma/client",- "@smithy/util-stream",- "dd-trace",- ]),- );+ expect(createNitroMock.mock.calls[0]?.[0].traceDeps).toEqual(["@napi-rs/keyring"]);});it("includes the Workflow sandbox runtime plugin only when Workflow is enabled", async () => {diff --git a/packages/eve/src/internal/nitro/host/create-application-nitro.ts b/packages/eve/src/internal/nitro/host/create-application-nitro.tsindex 6b2694a3d..f5a6191d0 100644--- a/packages/eve/src/internal/nitro/host/create-application-nitro.ts+++ b/packages/eve/src/internal/nitro/host/create-application-nitro.ts@@ -30,7 +30,6 @@ import {} from "#internal/nitro/host/optional-engine-dependency-plugin.js";import { addNitroRoutingImportSpecifierPlugin } from "#internal/nitro/host/nitro-routing-import-specifier-plugin.js";import { registerScheduleTaskHandlers } from "#internal/nitro/host/schedule-task-routes.js";-import { SERVER_EXTERNAL_PACKAGES } from "#internal/nitro/host/server-external-packages.js";import type {NitroBuildSurface,PreparedApplicationHost,@@ -121,6 +120,9 @@ function collectHostedTraceDependencies(const configuredExternalDependencies = agentNodes.flatMap((node) => node.config.build?.externalDependencies ?? [],);+ // Nitro already classifies known native and non-bundleable packages through+ // its nf3 database. traceDeps is only for eve-owned or author-configured+ // additions to that upstream policy.const merged = new Set<string>([...FRAMEWORK_HOSTED_EXTERNAL_PACKAGES,// Optional engine packages (just-bash, microsandbox) join the@@ -130,7 +132,6 @@ function collectHostedTraceDependencies(// so a resolvable-but-unrequested install adds nothing to hosted// output....configuredOptionalEnginePackages,- ...SERVER_EXTERNAL_PACKAGES,...configuredExternalDependencies,]);return [...merged].filter((dependencyName) => dependencyName !== EVE_PACKAGE_NAME);diff --git a/packages/eve/src/internal/nitro/host/server-external-packages.ts b/packages/eve/src/internal/nitro/host/server-external-packages.tsdeleted file mode 100644index 82ea33240..000000000--- a/packages/eve/src/internal/nitro/host/server-external-packages.ts+++ /dev/null@@ -1,111 +0,0 @@-/**- * Default server-side packages that should stay external and be traced into- * hosted output, copied from Next.js' server-external-packages config.- */-export const SERVER_EXTERNAL_PACKAGES = [- // alineacms.com generates this package at build time and it should not end up in a cache (much like the @prisma/client package)- "@alinea/generated",- "@appsignal/nodejs",- "@aws-sdk/client-kms",- "@aws-sdk/client-s3",- "@aws-sdk/client-sso",- "@aws-sdk/s3-presigned-post",- "@blockfrost/blockfrost-js",- "@datadog/flagging-core",- "@highlight-run/node",- "@huggingface/transformers",- "@jpg-store/lucid-cardano",- "@libsql/client",- "@mikro-orm/core",- "@mikro-orm/knex",- "@node-rs/argon2",- "@node-rs/bcrypt",- "@prisma/client",- "@react-pdf/renderer",- // Native Node.js addons- "@sentry/profiling-node",- "@smithy/util-stream",- "@sparticuz/chromium",- "@sparticuz/chromium-min",- // Native Node.js addons- "@statsig/statsig-node-core",- // Native Node.js addons- "@swc/core",- "@xenova/transformers",- // Builds on top of @prisma/client so dynamically loads the version.- "@zenstackhq/runtime",- "argon2",- "autoprefixer",- "aws-crt",- "bcrypt",- "better-sqlite3",- "canvas",- "chromadb-default-embed",- // Contains an unconditional require to a undeclared dependency 'coffee-script'- "config",- // Native Node.js addons- "cpu-features",- "cypress",- "dd-trace",- "eslint",- "express",- "firebase-admin",- "htmlrewriter",- // Patches the module system to shim modules- "import-in-the-middle",- // Native Node.js addons- "isolated-vm",- "jest",- "jsdom",- // Used to contain a very dynamic require to load the DB backend:- // https://github.com/jaredwray/keyv/blob/78b247b5b7a8c9b12154fbfae4295d6fb29158cf/packages/keyv/src/index.js#L22- "keyv",- "libsql",- "mdx-bundler",- "mongodb",- "mongoose",- "newrelic",- "next-mdx-remote",- "next-seo",- "node-cron",- "node-pty",- "node-web-audio-api",- "onnxruntime-node",- "oslo",- "pg",- // [email protected]/lib/transport.js passes `join(__dirname, 'worker.js')` to thread-stream which ends- // up `require`ing that filepath, leading to- // `Cannot find module '/ROOT/node_modules/.pnpm/[email protected]/node_modules/pino/lib/worker.js'`- "pino",- // A "plugin" that is passed to pino as a string (and is then required in a worker)- "pino-pretty",- // A "plugin" that is passed to pino as a string (and is then required in a worker)- "pino-roll",- "playwright",- "playwright-core",- "postcss",- "prettier",- "prisma",- "puppeteer",- "puppeteer-core",- "ravendb",- // Patches the module system to shim modules- "require-in-the-middle",- "rimraf",- // Native Node.js addons- "sharp",- "shiki",- "sqlite3",- // dynamic `new Worker` call in [email protected]/index.js which pulls in various non-code files- // as well (trying to parse README and invalid test files)- "thread-stream",- // Slow to compile because it pulls in typescript- "ts-morph",- "ts-node",- "typescript",- "vscode-oniguruma",- "webpack",- "websocket",- // Native Node.js addons- "zeromq",-] as const;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 48d7a8760..bd91bec2b 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -886,6 +886,9 @@ importers:e2e/fixtures/agent-tools:dependencies:+ '@eve-e2e/dynamic-import-dependency':+ specifier: file:./fixtures/dynamic-import-dependency+ version: file:e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency'@opentelemetry/core':specifier: 2.6.1version: 2.6.1(@opentelemetry/[email protected])@@ -2516,6 +2519,9 @@ packages:resolution: {integrity: sha512-+CNAzxglkrpNf/kKywqQfk74QjtceuOE7Qm+AF8miRvPF/wmmK5+OJOgVh3AVTT3RP2mH3+FOaxlE5v72owk0A==}engines: {node: ^20.19.0 || ^22.13.0 || >=24}+ '@eve-e2e/dynamic-import-dependency@file:e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency':+ resolution: {directory: e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency, type: directory}+'@fastify/[email protected]':resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==}engines: {node: '>=14'}@@ -14834,6 +14840,8 @@ snapshots:'@eslint/core': 1.2.1levn: 0.4.1+ '@eve-e2e/dynamic-import-dependency@file:e2e/fixtures/agent-tools/fixtures/dynamic-import-dependency': {}+'@fastify/[email protected]': {}'@floating-ui/[email protected]':