The Open Framework for Building Agents
fix(eve): support local Vercel prebuilt deployments (#746)
Casey Gowrie4649f7034785
diff --git a/.changeset/warm-prebuilt-builds.md b/.changeset/warm-prebuilt-builds.mdnew file mode 100644index 000000000..ec31fba12--- /dev/null+++ b/.changeset/warm-prebuilt-builds.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Local `vercel build` runs now select the hosted Workflow runtime and prewarm sandbox templates, so their output can be deployed with `vercel deploy --prebuilt`. Builds that require templates fail with setup guidance when Vercel OIDC credentials are unavailable instead of emitting broken prebuilt output.diff --git a/.github/workflows/bundle-analysis.yml b/.github/workflows/bundle-analysis.ymlindex 8119ba93d..e164904f3 100644--- a/.github/workflows/bundle-analysis.yml+++ b/.github/workflows/bundle-analysis.yml@@ -151,7 +151,9 @@ jobs:id: baseline_buildcontinue-on-error: trueworking-directory: ${{ steps.baseline.outputs.root }}- run: VERCEL=1 pnpm --filter "${STEPS_BASELINE_WEATHER_APP_OUTPUTS_FILTER}" build+ run: >-+ VERCEL=1 pnpm --filter "${STEPS_BASELINE_WEATHER_APP_OUTPUTS_FILTER}"+ exec eve build --skip-sandbox-prewarmenv:STEPS_BASELINE_WEATHER_APP_OUTPUTS_FILTER: ${{ steps.baseline_weather_app.outputs.filter }}@@ -180,7 +182,9 @@ jobs:- name: Build weather-agent in Vercel modeif: ${{ steps.mode.outputs.acknowledge_only != 'true' }}- run: VERCEL=1 pnpm --filter weather-agent build+ run: >-+ VERCEL=1 pnpm --filter weather-agent+ exec eve build --skip-sandbox-prewarm- name: Generate bundle reportif: ${{ steps.mode.outputs.acknowledge_only != 'true' }}diff --git a/.github/workflows/e2e-vercel.yml b/.github/workflows/e2e-vercel.ymlindex 91f0ae161..c5e99b7cb 100644--- a/.github/workflows/e2e-vercel.yml+++ b/.github/workflows/e2e-vercel.yml@@ -132,7 +132,6 @@ jobs:VERCEL_ENV=preview \VERCEL_TARGET_ENV=preview \VERCEL_PROJECT_ID="$VERCEL_PROJECT_ID" \- VERCEL_DEPLOYMENT_ID="dpl_eve_e2e_${{ matrix.name }}_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}" \pnpm exec eve buildDEPLOYMENT_URL="$(pnpm exec vc deploy --prebuilt --yes --target=preview "${token_args[@]}" | tail -n 1)"diff --git a/docs/guides/deployment.md b/docs/guides/deployment.mdindex 2183debdd..005e155fe 100644--- a/docs/guides/deployment.md+++ b/docs/guides/deployment.md@@ -99,9 +99,9 @@ For a self-deployed process, leave `defaultBackend()` in place or choose an expl## 5. Build-time sandbox prewarm-During hosted builds, eve prewarms reusable Vercel sandbox templates so the first session doesn't pay the cold-start cost:+During Vercel-targeted builds, eve prewarms reusable Vercel sandbox templates so the first session doesn't pay the cold-start cost. This includes hosted builds and local `vercel build` runs:-- Prewarm runs only when both `VERCEL` and `VERCEL_DEPLOYMENT_ID` are present.+- Prewarm runs for hosted Vercel builds and linked local `vercel build` runs.- A sandbox with no `bootstrap()` and no workspace seed files gets skipped.- Seed-only templates are keyed by skills and workspace file contents, so unchanged seeds reuse a template across deploys.- Templates with a `bootstrap()` are keyed by the optional resolved `revalidationKey()` plus the authored sandbox source and seed contents, so matching inputs reuse a template across deploys.@@ -109,7 +109,7 @@ During hosted builds, eve prewarms reusable Vercel sandbox templates so the firs- Prewarming only covers template construction. `onSession()` still runs at runtime, once per session.- **If build-time prewarm fails, the build fails.**-If `VERCEL` is set but `VERCEL_DEPLOYMENT_ID` is missing, eve warns that it skipped prewarming. Do not deploy that build with `vercel deploy --prebuilt`; its output may reference sandbox templates that were never provisioned. Run `vercel deploy` instead so Vercel builds the source in its hosted build environment.+Local builds must be linked to a Vercel project with credentials that can provision Vercel Sandbox templates. If authentication or template provisioning fails, eve fails the build rather than emitting output that would fail after deployment.## 6. Authdiff --git a/docs/reference/cli.md b/docs/reference/cli.mdindex b423ef2a7..a552afa1c 100644--- a/docs/reference/cli.md+++ b/docs/reference/cli.md@@ -93,7 +93,7 @@ Run this first when something behaves unexpectedly. It confirms a file was discoeve build```-No flags. Compiles to `.eve/` and builds the host output, then prints the built output path.+Compiles to `.eve/` and builds the host output, then prints the built output path.Useful artifacts written under `.eve/` (preserved even on partial failure):diff --git a/e2e/README.md b/e2e/README.mdindex 251d61fd5..c39d3af31 100644--- a/e2e/README.md+++ b/e2e/README.md@@ -50,7 +50,6 @@ vc link --yes --project "$VERCEL_PROJECT_ID"vc env pull --yes --environment=previewVERCEL=1 VERCEL_ENV=preview VERCEL_TARGET_ENV=preview \VERCEL_PROJECT_ID="$VERCEL_PROJECT_ID" \- VERCEL_DEPLOYMENT_ID="dpl_eve_e2e_manual" \pnpm exec eve buildDEPLOYMENT_URL="$(vc deploy --prebuilt --yes --target=preview | tail -n 1)"npx eve eval --strict --url "$DEPLOYMENT_URL"diff --git a/e2e/fixtures/agent-tools-sandbox/evals/sandbox/redeploy.eval.ts b/e2e/fixtures/agent-tools-sandbox/evals/sandbox/redeploy.eval.tsindex 061d47cb2..03567e9b2 100644--- a/e2e/fixtures/agent-tools-sandbox/evals/sandbox/redeploy.eval.ts+++ b/e2e/fixtures/agent-tools-sandbox/evals/sandbox/redeploy.eval.ts@@ -151,8 +151,7 @@ export default defineEval({/** Builds the fixture and repoints the alias at the fresh deployment. */async function deployToAlias(t: EveEvalContext, alias: string, phase: string): Promise<void> {// Mirror the workflow's build env. Sandbox templates key on- // VERCEL_PROJECT_ID (already in the environment); the deployment id is- // deliberately ignored by sandbox keys but must be present at build.+ // VERCEL_PROJECT_ID, which is already present in the environment.await execFileAsync("pnpm", ["exec", "eve", "build"], {...EXEC_OPTIONS,env: {@@ -160,7 +159,6 @@ async function deployToAlias(t: EveEvalContext, alias: string, phase: string): PVERCEL: "1",VERCEL_ENV: "preview",VERCEL_TARGET_ENV: "preview",- VERCEL_DEPLOYMENT_ID: `dpl_eve_e2e_redeploy_${phase}_${Date.now()}`,},});diff --git a/packages/eve/src/cli/run.ts b/packages/eve/src/cli/run.tsindex 9ea5f117e..420e5653d 100644--- a/packages/eve/src/cli/run.ts+++ b/packages/eve/src/cli/run.ts@@ -19,6 +19,7 @@ import { startCliLiveRow } from "#cli/ui/live-row.js";import { createCliTheme, renderCliTaggedLine } from "#cli/ui/output.js";import { createLogger } from "#internal/logging.js";import type {+ ApplicationBuildOptions,DevelopmentServer,DevelopmentServerOptions,ProductionServerHandle,@@ -58,13 +59,17 @@ interface ProductionCliOptions {port?: number;}+interface BuildCliOptions {+ skipSandboxPrewarm?: boolean;+}+interface CliRuntimeDependencies {isCodingAgentLaunch(): Promise<boolean>;isActiveDevelopmentServerForApp(input: {readonly appRoot: string;readonly serverUrl: string;}): Promise<boolean>;- buildHost(appRoot: string): Promise<string>;+ buildHost(appRoot: string, options: ApplicationBuildOptions): Promise<string>;printApplicationInfo(logger: CliLogger,appRoot: string,@@ -363,13 +368,19 @@ function createCliProgram(logger: CliLogger, runtime: CliRuntimeOverrides): Commprogram.command("build").description("Build the current eve application.")- .action(async () => {+ .option(+ "--skip-sandbox-prewarm",+ "Skip Vercel sandbox template prewarm; output may not be deployable",+ )+ .action(async (options: BuildCliOptions) => {const { loadDevelopmentEnvironmentFiles } = await import("#cli/dev/environment.js");loadDevelopmentEnvironmentFiles(appRoot);const buildHost = runtime.buildHost ?? (await loadBuildHost());- const outputDir = await buildHost(appRoot);+ const outputDir = await buildHost(appRoot, {+ skipVercelSandboxPrewarm: options.skipSandboxPrewarm === true,+ });logger.log(renderCliTaggedLine(theme, {message: `built output at ${outputDir}`,diff --git a/packages/eve/src/internal/application/compiled-artifacts.test.ts b/packages/eve/src/internal/application/compiled-artifacts.test.tsindex 5b2e13b34..10628bfe2 100644--- a/packages/eve/src/internal/application/compiled-artifacts.test.ts+++ b/packages/eve/src/internal/application/compiled-artifacts.test.ts@@ -1,18 +1,14 @@-import { afterEach, describe, expect, it } from "vitest";+import { describe, expect, it } from "vitest";import { createWorkflowWorldPluginSource } from "#internal/application/compiled-artifacts.js";describe("createWorkflowWorldPluginSource", () => {- afterEach(() => {- delete process.env.VERCEL_DEPLOYMENT_ID;- delete process.env.WORKFLOW_TARGET_WORLD;- });-it("imports a configured world package and delegates its construction to Workflow", () => {- const source = createWorkflowWorldPluginSource(- "@acme/eve-world",- "/app/.eve/compile/compiled-artifacts-bootstrap.mjs",- );+ const source = createWorkflowWorldPluginSource({+ compiledArtifactsBootstrapPath: "/app/.eve/compile/compiled-artifacts-bootstrap.mjs",+ configuredWorld: "@acme/eve-world",+ defaultWorld: "vercel",+ });expect(source).toContain('import "/app/.eve/compile/compiled-artifacts-bootstrap.mjs";');expect(source).toContain('import * as workflowWorldModule from "@acme/eve-world";');@@ -29,14 +25,19 @@ describe("createWorkflowWorldPluginSource", () => {});it("selects vendored local and Vercel world packages with Workflow's selector", () => {- expect(createWorkflowWorldPluginSource(undefined)).toContain(- "/compiled/@workflow/world-local/index.js",- );-- process.env.VERCEL_DEPLOYMENT_ID = "deployment-id";-- expect(createWorkflowWorldPluginSource(undefined)).toContain(- "/compiled/@workflow/world-vercel/index.js",- );+ expect(+ createWorkflowWorldPluginSource({+ compiledArtifactsBootstrapPath: "/app/.eve/compile/bootstrap.mjs",+ configuredWorld: undefined,+ defaultWorld: "local",+ }),+ ).toContain("/compiled/@workflow/world-local/index.js");+ expect(+ createWorkflowWorldPluginSource({+ compiledArtifactsBootstrapPath: "/app/.eve/compile/bootstrap.mjs",+ configuredWorld: undefined,+ defaultWorld: "vercel",+ }),+ ).toContain("/compiled/@workflow/world-vercel/index.js");});});diff --git a/packages/eve/src/internal/application/compiled-artifacts.ts b/packages/eve/src/internal/application/compiled-artifacts.tsindex bce21b0be..78a72e0ba 100644--- a/packages/eve/src/internal/application/compiled-artifacts.ts+++ b/packages/eve/src/internal/application/compiled-artifacts.ts@@ -13,6 +13,8 @@ import {} from "#internal/application/package.js";import type { AgentWorkflowWorldDefinition } from "#shared/agent-definition.js";+export type BuiltInWorkflowWorldTarget = "local" | "vercel";+/*** Paths to the generated compiled-artifacts files shared by Nitro and the* vendored workflow bundles for one application.@@ -46,6 +48,7 @@ export interface GeneratedCompiledArtifactsFiles {*/export async function writeCompiledArtifactsFiles(input: {compileResult: CompileAgentResult;+ defaultWorkflowWorld: BuiltInWorkflowWorldTarget;outDir: string;}): Promise<GeneratedCompiledArtifactsFiles> {const bootstrapPath = join(input.outDir, "compiled-artifacts-bootstrap.mjs");@@ -65,10 +68,11 @@ export async function writeCompiledArtifactsFiles(input: {);await writeFile(workflowWorldPluginPath,- createWorkflowWorldPluginSource(- input.compileResult.manifest.config.experimental?.workflow?.world,- bootstrapPath,- ),+ createWorkflowWorldPluginSource({+ compiledArtifactsBootstrapPath: bootstrapPath,+ configuredWorld: input.compileResult.manifest.config.experimental?.workflow?.world,+ defaultWorld: input.defaultWorkflowWorld,+ }),);if (instrumentationPath !== undefined) {@@ -170,15 +174,13 @@ export async function createCompiledArtifactsBootstrapSource(input: {].join("\n");}-export function createWorkflowWorldPluginSource(- configuredWorld: AgentWorkflowWorldDefinition | undefined,- compiledArtifactsBootstrapPath?: string,-): string {- const packageName = getWorldImport(- configuredWorld === undefined- ? process.env- : { ...process.env, WORKFLOW_TARGET_WORLD: configuredWorld },- );+export function createWorkflowWorldPluginSource(input: {+ compiledArtifactsBootstrapPath: string;+ configuredWorld: AgentWorkflowWorldDefinition | undefined;+ defaultWorld: BuiltInWorkflowWorldTarget;+}): string {+ const targetWorld = input.configuredWorld ?? input.defaultWorld;+ const packageName = getWorldImport({ WORKFLOW_TARGET_WORLD: targetWorld });const importSpecifier =packageName === "@workflow/world-local" || packageName === "@workflow/world-vercel"? resolvePackageCompiledFilePath(`src/compiled/${packageName}/index.js`)@@ -192,15 +194,13 @@ export function createWorkflowWorldPluginSource(return ["// Generated by eve. Do not edit by hand.",- ...(compiledArtifactsBootstrapPath === undefined- ? []- : [`import ${stringifyEsmImportSpecifier(compiledArtifactsBootstrapPath)};`]),+ `import ${stringifyEsmImportSpecifier(input.compiledArtifactsBootstrapPath)};`,`import * as workflowWorldModule from ${stringifyEsmImportSpecifier(importSpecifier)};`,`import { createWorldFromModule, getWorld, setWorld } from ${stringifyEsmImportSpecifier(workflowRuntimeImportSpecifier)};`,`import { validateWorkflowWorld } from ${stringifyEsmImportSpecifier(workflowWorldValidationImportSpecifier)};`,"","const workflowWorld = await createWorldFromModule(workflowWorldModule);",- `validateWorkflowWorld({ packageName: ${JSON.stringify(configuredWorld)}, world: workflowWorld });`,+ `validateWorkflowWorld({ packageName: ${JSON.stringify(input.configuredWorld)}, world: workflowWorld });`,"setWorld(workflowWorld);","await getWorld();","await workflowWorld.start?.();",diff --git a/packages/eve/src/internal/nitro/host/build-application.scenario.test.ts b/packages/eve/src/internal/nitro/host/build-application.scenario.test.tsindex c0352827f..9af1c8adc 100644--- a/packages/eve/src/internal/nitro/host/build-application.scenario.test.ts+++ b/packages/eve/src/internal/nitro/host/build-application.scenario.test.ts@@ -93,6 +93,7 @@ vi.mock("../../workflow-bundle/builder.js", () => ({}));const createScratchDirectory = useTemporaryDirectories();+const DEPLOYABLE_BUILD_OPTIONS = { skipVercelSandboxPrewarm: false } as const;function createPreparedHost(appRoot: string): PreparedApplicationHost {const agentRoot = join(appRoot, "agent");@@ -166,7 +167,7 @@ describe("buildApplication", () => {]);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- const builtOutputDir = await buildApplication(appRoot);+ const builtOutputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);expect(builtOutputDir).toBe(outputDir);expect(createApplicationNitroMock).toHaveBeenCalledTimes(1);@@ -250,7 +251,7 @@ describe("buildApplication", () => {);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);expect(outputDir).toBe(join(appRoot, ".vercel", "output"));expect(createApplicationNitroMock).toHaveBeenCalledTimes(2);@@ -318,6 +319,35 @@ describe("buildApplication", () => {expect((summary.agent as { name: string }).name).toBe("scenario-test-agent");});+ it("skips Vercel sandbox prewarm only when the build opts out", async () => {+ vi.stubEnv("VERCEL", "1");+ const appRoot = await createScratchDirectory("eve-build-application-skip-prewarm-");++ prepareApplicationHostMock.mockResolvedValueOnce(createPreparedHost(appRoot));+ createApplicationNitroMock.mockImplementation(+ async (+ _preparedHost: PreparedApplicationHost,+ _dev: boolean,+ options: { outputDir?: string; surface?: string } = {},+ ) => {+ if (options.surface === "app") {+ return createNitroStub(join(appRoot, ".vercel", "output"));+ }++ return createNitroStub(options.outputDir ?? join(appRoot, ".output"));+ },+ );++ const { buildApplication } = await import("#internal/nitro/host/build-application.js");+ const outputDir = await buildApplication(appRoot, {+ skipVercelSandboxPrewarm: true,+ });++ expect(outputDir).toBe(join(appRoot, ".vercel", "output"));+ expect(runVercelBuildPrewarmMock).not.toHaveBeenCalled();+ expect(workflowBuilderBuildVercelOutputMock).toHaveBeenCalledTimes(1);+ });+it("normalizes eve function output behind a non-Next host service", async () => {vi.stubEnv("VERCEL", "1");const appRoot = await createScratchDirectory("eve-build-application-vercel-nuxt-");@@ -361,7 +391,7 @@ describe("buildApplication", () => {);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- await buildApplication(appRoot);+ await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const sharedFunctionStats = await lstat(join(appRoot, ".vercel", "output", "functions", "eve", "__server.func"),@@ -426,7 +456,7 @@ describe("buildApplication", () => {);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- await buildApplication(appRoot);+ await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const vercelConfig = JSON.parse(await readFile(join(appRoot, ".vercel", "output", "config.json"), "utf8"),@@ -489,7 +519,7 @@ describe("buildApplication", () => {);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- await buildApplication(appRoot);+ await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const vercelConfig = JSON.parse(await readFile(join(appRoot, ".vercel", "output", "config.json"), "utf8"),@@ -547,7 +577,7 @@ describe("buildApplication", () => {]);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);expect(outputDir).toBe(join(appRoot, ".vercel", "output"));const vercelConfig = JSON.parse(@@ -581,7 +611,7 @@ describe("buildApplication", () => {);const { buildApplication } = await import("#internal/nitro/host/build-application.js");- await buildApplication(appRoot);+ await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const rootFunctionStats = await lstat(join(appRoot, ".vercel", "output", "functions", "index.func"),diff --git a/packages/eve/src/internal/nitro/host/build-application.ts b/packages/eve/src/internal/nitro/host/build-application.tsindex 5ab59275a..e08118582 100644--- a/packages/eve/src/internal/nitro/host/build-application.ts+++ b/packages/eve/src/internal/nitro/host/build-application.ts@@ -17,7 +17,11 @@ import { emitVercelAgentSummary } from "#internal/nitro/host/build-vercel-agent-import { tryReadExtensionBuildConfig } from "#internal/nitro/host/build-extension.js";import { prepareApplicationHost } from "#internal/nitro/host/prepare-application-host.js";import { runVercelBuildPrewarm } from "#internal/nitro/host/vercel-build-prewarm.js";-import type { NitroBuildSurface, PreparedApplicationHost } from "#internal/nitro/host/types.js";+import type {+ ApplicationBuildOptions,+ NitroBuildSurface,+ PreparedApplicationHost,+} from "#internal/nitro/host/types.js";import { findClosestVercelOutputDirectory } from "#shared/vercel-output-directory.js";function trimTrailingSlash(path: string): string {@@ -291,7 +295,10 @@ async function buildVercelNitroSurface(/*** Builds the production Nitro output for an eve application.*/-export async function buildApplication(rootDir: string): Promise<string> {+export async function buildApplication(+ rootDir: string,+ options: ApplicationBuildOptions,+): Promise<string> {// Extension packages use `eve extension build`. Keep agent `eve build` agent-only// so a mistaken run fails with a clear redirect instead of a half-Nitro path.const extensionBuild = await tryReadExtensionBuildConfig(rootDir);@@ -331,12 +338,14 @@ export async function buildApplication(rootDir: string): Promise<string> {// Run sandbox prewarm before emitting the workflow functions so a// prewarm failure aborts the build before we spend time bundling// function output that we would never deploy.- await runVercelBuildPrewarm({- appRoot: preparedHost.appRoot,- log(message) {- console.log(message);- },- });+ if (!options.skipVercelSandboxPrewarm) {+ await runVercelBuildPrewarm({+ appRoot: preparedHost.appRoot,+ log(message) {+ console.log(message);+ },+ });+ }const flowNitroOutputDir = await buildVercelNitroSurface(preparedHost, "flow");await emitVercelWorkflowFunctions({agentName: preparedHost.compileResult.manifest.config.name,diff --git a/packages/eve/src/internal/nitro/host/prepare-application-host.scenario.test.ts b/packages/eve/src/internal/nitro/host/prepare-application-host.scenario.test.tsindex fc762b5af..5bd56e33e 100644--- a/packages/eve/src/internal/nitro/host/prepare-application-host.scenario.test.ts+++ b/packages/eve/src/internal/nitro/host/prepare-application-host.scenario.test.ts@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";import { readFile, writeFile } from "node:fs/promises";import { join } from "node:path";-import { describe, expect, it } from "vitest";+import { afterEach, describe, expect, it, vi } from "vitest";import { normalizeEsmImportSpecifier } from "#internal/application/import-specifier.js";import {@@ -26,6 +26,31 @@ async function readDevelopmentRuntimePointer(appRoot: string): Promise<Developme}describe("prepareApplicationHost", () => {+ afterEach(() => {+ vi.unstubAllEnvs();+ });++ it("selects the Vercel Workflow world for a prebuilt production host", async () => {+ vi.stubEnv("VERCEL", "1");+ vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");+ const { agentRoot, appRoot } = await createAppRoot("eve-vercel-production-world-", {+ files: {+ "agent/instructions.md": "Use the configured model.",+ },+ packageName: "vercel-production-world",+ });+ await writeFile(join(agentRoot, "agent.mjs"), 'export default { model: "openai/gpt-5.4" };\n');++ const preparedHost = await prepareApplicationHost(appRoot);+ const workflowWorldPlugin = await readFile(+ preparedHost.compiledArtifacts.workflowWorldPluginPath,+ "utf8",+ );++ expect(workflowWorldPlugin).toContain("/compiled/@workflow/world-vercel/index.js");+ expect(workflowWorldPlugin).not.toContain("/compiled/@workflow/world-local/index.js");+ });+it("keeps Nitro host inputs stable when their runtime snapshot is pruned", async () => {const { agentRoot, appRoot } = await createAppRoot("eve-stable-dev-host-artifacts-", {files: {diff --git a/packages/eve/src/internal/nitro/host/prepare-application-host.ts b/packages/eve/src/internal/nitro/host/prepare-application-host.tsindex fee9c9072..f29e3fff2 100644--- a/packages/eve/src/internal/nitro/host/prepare-application-host.ts+++ b/packages/eve/src/internal/nitro/host/prepare-application-host.ts@@ -1,7 +1,10 @@import { compileAgent } from "#compiler/compile-agent.js";import { createScheduleRegistrations } from "#runtime/schedules/register.js";import { loadResolvedCompiledSchedules } from "#runtime/schedules/resolve-schedule.js";-import { writeCompiledArtifactsFiles } from "#internal/application/compiled-artifacts.js";+import {+ type BuiltInWorkflowWorldTarget,+ writeCompiledArtifactsFiles,+} from "#internal/application/compiled-artifacts.js";import {resolveApplicationHostArtifactsDirectory,resolveWorkflowBuildDirectory,@@ -39,6 +42,7 @@ export async function prepareApplicationHost(: undefined;const compiledArtifacts = await writeCompiledArtifactsFiles({compileResult,+ defaultWorkflowWorld: resolveDefaultWorkflowWorld(options),outDir: resolveApplicationHostArtifactsDirectory(compileResult.project.appRoot),});if (runtimeArtifactsSnapshot !== undefined) {@@ -57,3 +61,13 @@ export async function prepareApplicationHost(workflowBuildDir,};}++function resolveDefaultWorkflowWorld(options: {+ readonly dev?: boolean;+}): BuiltInWorkflowWorldTarget {+ if (options.dev === true) {+ return "local";+ }++ return process.env.VERCEL ? "vercel" : "local";+}diff --git a/packages/eve/src/internal/nitro/host/types.ts b/packages/eve/src/internal/nitro/host/types.tsindex 835ecb42f..46e0a0df5 100644--- a/packages/eve/src/internal/nitro/host/types.ts+++ b/packages/eve/src/internal/nitro/host/types.ts@@ -9,6 +9,11 @@ import type { DevBootProgressReporter } from "#internal/dev-boot-progress.js";*/export type NitroBuildSurface = "all" | "app" | "flow";+/** Options for one production application build. */+export interface ApplicationBuildOptions {+ readonly skipVercelSandboxPrewarm: boolean;+}+/** Outcome of starting a Nitro development server the current process owns. */export interface StartedDevelopmentServer {readonly kind: "started";diff --git a/packages/eve/src/internal/nitro/host/vercel-build-prewarm.ts b/packages/eve/src/internal/nitro/host/vercel-build-prewarm.tsindex 6ef946e85..617d9489b 100644--- a/packages/eve/src/internal/nitro/host/vercel-build-prewarm.ts+++ b/packages/eve/src/internal/nitro/host/vercel-build-prewarm.ts@@ -2,44 +2,34 @@ import { prewarmAppSandboxes } from "#execution/sandbox/prewarm.js";type PrewarmAppSandboxesInput = Parameters<typeof prewarmAppSandboxes>[0];-const VERCEL_BUILD_PREWARM_SKIPPED_WARNING =- "[eve] WARNING: Skipped Vercel sandbox template prewarm because VERCEL_DEPLOYMENT_ID is missing. " +- "The generated .vercel/output may reference sandbox templates that were not provisioned. " +- 'Do not deploy it with "vercel deploy --prebuilt"; use "vercel deploy" so Vercel builds from source.';--/**- * Detects whether the current build is running inside Vercel with a- * stable deployment identifier. Build-time sandbox prewarm runs only- * when this returns true so dev runs and one-off builds don't try to- * provision templates against the platform.- */-export function shouldPrewarmVercelBuild(): boolean {- const vercel = process.env.VERCEL?.trim();- const deploymentId = process.env.VERCEL_DEPLOYMENT_ID?.trim();-- return (- typeof vercel === "string" &&- vercel.length > 0 &&- typeof deploymentId === "string" &&- deploymentId.length > 0- );-}+const MISSING_VERCEL_BUILD_OIDC_ERROR =+ "Cannot build deployable Vercel output because this app requires sandbox templates and " ++ "VERCEL_OIDC_TOKEN is missing. Run `vercel link` and `vercel pull`, then retry " ++ "`vercel build`. Do not deploy the generated .vercel/output.";/*** Vercel build-time sandbox prewarm hook. Failures here are treated as* build failures because the same sandbox bootstrap would otherwise* break at runtime.*- * Returns `true` when the prewarm ran, `false` when the current- * environment is not a Vercel build.+ * Returns `true` after validating a Vercel build's template requirements,+ * `false` outside a Vercel build.*/export async function runVercelBuildPrewarm(input: PrewarmAppSandboxesInput): Promise<boolean> {- if (!shouldPrewarmVercelBuild()) {- if (process.env.VERCEL?.trim() && !process.env.VERCEL_DEPLOYMENT_ID?.trim()) {- console.warn(VERCEL_BUILD_PREWARM_SKIPPED_WARNING);- }+ if (!process.env.VERCEL?.trim()) {return false;}- await prewarmAppSandboxes(input);++ if (process.env.VERCEL_OIDC_TOKEN?.trim()) {+ await prewarmAppSandboxes(input);+ return true;+ }++ await prewarmAppSandboxes({+ ...input,+ async dispatch() {+ throw new Error(MISSING_VERCEL_BUILD_OIDC_ERROR);+ },+ });return true;}diff --git a/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts b/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.tsindex 6c08e0855..454181496 100644--- a/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts+++ b/packages/eve/test/scenarios/app-runtime-dependencies.scenario.test.ts@@ -12,9 +12,16 @@ import {import { buildApplication } from "../../src/internal/nitro/host.js";import { useTemporaryDirectories } from "../../src/internal/testing/use-temporary-app-roots.js";+vi.mock("../../src/internal/nitro/host/vercel-build-prewarm.js", () => ({+ runVercelBuildPrewarm: async () => true,+}));+const EVE_PACKAGE_INFO = resolveInstalledPackageInfo();const EVE_PACKAGE_ROOT = resolvePackageRoot();const createScratchDirectory = useTemporaryDirectories();+const DEPLOYABLE_BUILD_OPTIONS = {+ skipVercelSandboxPrewarm: false,+} as const;async function readJavaScriptModulesRecursively(rootDirectory: string): Promise<string> {// `withFileTypes` so directories named like modules (for example the@@ -145,7 +152,7 @@ describe("app runtime dependency tracing", () => {].join("\n"),);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const tracedServerPackageJson = await readTracedServerPackageJson(outputDir);const serverModuleDirectory = join(outputDir, "server");const serverModuleEntries = await readdir(serverModuleDirectory, {@@ -249,7 +256,7 @@ describe("app runtime dependency tracing", () => {].join("\n"),);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const serverModuleDirectory = join(outputDir, "server");const serverModuleEntries = await readdir(serverModuleDirectory, {recursive: true,@@ -336,6 +343,7 @@ describe("app runtime dependency tracing", () => {const disabledOutputDir = await buildApplication(await createWorkflowAssetsApp("disabled", false),+ DEPLOYABLE_BUILD_OPTIONS,);const disabledTracedPackageJson = await readTracedServerPackageJson(disabledOutputDir);const disabledServerSource = await readJavaScriptModulesRecursively(@@ -344,7 +352,10 @@ describe("app runtime dependency tracing", () => {expect(disabledServerSource).not.toContain("[Unprintable QuickJS value]");- const enabledOutputDir = await buildApplication(await createWorkflowAssetsApp("enabled", true));+ const enabledOutputDir = await buildApplication(+ await createWorkflowAssetsApp("enabled", true),+ DEPLOYABLE_BUILD_OPTIONS,+ );const tracedServerPackageJson = await readTracedServerPackageJson(enabledOutputDir);const enabledServerSource = await readJavaScriptModulesRecursively(join(enabledOutputDir, "server"),@@ -410,6 +421,7 @@ describe("app runtime dependency tracing", () => {// opt-in — nothing of just-bash may reach the hosted output.const dockerOutputDir = await buildApplication(await createMinimalApp({ justBashEngine: false, label: "docker" }),+ DEPLOYABLE_BUILD_OPTIONS,);const dockerTraced = await readTracedServerPackageJson(dockerOutputDir);expect(dockerTraced.dependencies).not.toHaveProperty("just-bash");@@ -424,6 +436,7 @@ describe("app runtime dependency tracing", () => {// externalized and traced so the output stays self-contained.const justBashOutputDir = await buildApplication(await createMinimalApp({ justBashEngine: true, label: "just-bash" }),+ DEPLOYABLE_BUILD_OPTIONS,);const justBashTraced = await readTracedServerPackageJson(justBashOutputDir);expect(justBashTraced.dependencies).toHaveProperty("just-bash");@@ -512,7 +525,7 @@ describe("app runtime dependency tracing", () => {].join("\n"),);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const serverModuleDirectory = join(outputDir, "server");const serverModuleEntries = await readdir(serverModuleDirectory, {recursive: true,@@ -617,7 +630,7 @@ describe("app runtime dependency tracing", () => {].join("\n"),);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const serverModuleDirectory = join(outputDir, "server");const serverModuleEntries = await readdir(serverModuleDirectory, {recursive: true,@@ -677,7 +690,7 @@ describe("app runtime dependency tracing", () => {["---", "description: Weather help.", "---", ""].join("\n"),);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const serverFunctionDirectory = join(outputDir, "functions", "__server.func");const functionEntries = await readdir(join(outputDir, "functions"), {recursive: true,@@ -715,7 +728,7 @@ describe("app runtime dependency tracing", () => {expect(serverModuleSource).toContain("URL must start with http:// or https://");}, 30_000);- it("does not bundle dev-only watcher handling into hosted Vercel server output", async () => {+ it("does not bundle local-only runtime infrastructure into hosted Vercel output", async () => {vi.stubEnv("VERCEL", "1");vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");@@ -745,7 +758,7 @@ describe("app runtime dependency tracing", () => {"Verify deployed runtime contents.\n",);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const vercelFunctionsSource = await readJavaScriptModulesRecursively(join(outputDir, "functions"),);@@ -754,6 +767,8 @@ describe("app runtime dependency tracing", () => {expect(vercelFunctionsSource).not.toContain("chokidar");expect(vercelFunctionsSource).not.toContain("[eve:dev]");expect(vercelFunctionsSource).not.toContain("rollup:reload");+ expect(vercelFunctionsSource).not.toContain("WORKFLOW_LOCAL_DATA_DIR");+ expect(vercelFunctionsSource).not.toContain("DataDirAccessError");}, 30_000);it("loads instrumentation runtime dependencies from hosted Vercel output", async () => {@@ -864,7 +879,7 @@ describe("app runtime dependency tracing", () => {].join("\n"),);- const outputDir = await buildApplication(appRoot);+ const outputDir = await buildApplication(appRoot, DEPLOYABLE_BUILD_OPTIONS);const serverFunctionDirectory = join(outputDir, "functions", "__server.func");const serverEntries = await readdir(serverFunctionDirectory, {recursive: true,diff --git a/packages/eve/test/scenarios/cli.scenario.test.ts b/packages/eve/test/scenarios/cli.scenario.test.tsindex 4da5912aa..b594c5b38 100644--- a/packages/eve/test/scenarios/cli.scenario.test.ts+++ b/packages/eve/test/scenarios/cli.scenario.test.ts@@ -400,7 +400,9 @@ describe("runCli", () => {const { buildApplication } = await import("../../src/internal/nitro/host.js");const appRoot = await createMinimalAppRoot("eve-cli-start-health-");- await buildApplication(appRoot);+ await buildApplication(appRoot, {+ skipVercelSandboxPrewarm: false,+ });const server = await startPackagedEveStart(appRoot);@@ -517,7 +519,9 @@ describe("runCli", () => {process.chdir(previousCwd);}- expect(buildHost).toHaveBeenCalledWith(resolvedWorkspaceRoot);+ expect(buildHost).toHaveBeenCalledWith(resolvedWorkspaceRoot, {+ skipVercelSandboxPrewarm: false,+ });expect(observedEnvironment).toEqual({EVE_BUILD_DEFAULT_ONLY: "from-env",EVE_BUILD_DEVELOPMENT_LOCAL_ONLY: "from-development-local",@@ -527,4 +531,29 @@ describe("runCli", () => {EVE_BUILD_SHELL_ONLY: "from-shell",});});++ it("forwards the sandbox prewarm opt-out to the build host", async () => {+ const workspaceRoot = await createScratchDirectory("eve-cli-build-skip-prewarm-");+ const resolvedWorkspaceRoot = await realpath(workspaceRoot);+ const previousCwd = process.cwd();+ const logger = {+ error: vi.fn(),+ log: vi.fn(),+ };+ const buildHost = vi.fn(async () => join(workspaceRoot, ".vercel", "output"));++ process.chdir(workspaceRoot);++ try {+ await runCli(["build", "--skip-sandbox-prewarm"], logger, {+ buildHost,+ });+ } finally {+ process.chdir(previousCwd);+ }++ expect(buildHost).toHaveBeenCalledWith(resolvedWorkspaceRoot, {+ skipVercelSandboxPrewarm: true,+ });+ });});diff --git a/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.ts b/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.tsindex d02c82e12..d4cc234f3 100644--- a/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.ts+++ b/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.ts@@ -36,6 +36,7 @@ describe("writeCompiledArtifactsFiles", () => {});const generatedArtifacts = await writeCompiledArtifactsFiles({compileResult,+ defaultWorkflowWorld: "local",outDir,});const bootstrapSource = await readFile(generatedArtifacts.bootstrapPath, "utf8");@@ -78,6 +79,7 @@ describe("writeCompiledArtifactsFiles", () => {});const generatedArtifacts = await writeCompiledArtifactsFiles({compileResult,+ defaultWorkflowWorld: "local",outDir,});const bootstrapSource = await readFile(generatedArtifacts.bootstrapPath, "utf8");@@ -129,6 +131,7 @@ describe("writeCompiledArtifactsFiles", () => {});const generatedArtifacts = await writeCompiledArtifactsFiles({compileResult,+ defaultWorkflowWorld: "local",outDir,});const instrumentationPluginPath = generatedArtifacts.instrumentationPluginPath;@@ -175,6 +178,7 @@ describe("writeCompiledArtifactsFiles", () => {});const generatedArtifacts = await writeCompiledArtifactsFiles({compileResult,+ defaultWorkflowWorld: "local",outDir,});diff --git a/packages/eve/test/scenarios/vercel-build-prewarm.scenario.test.ts b/packages/eve/test/scenarios/vercel-build-prewarm.scenario.test.tsindex 706781d7e..b0b267221 100644--- a/packages/eve/test/scenarios/vercel-build-prewarm.scenario.test.ts+++ b/packages/eve/test/scenarios/vercel-build-prewarm.scenario.test.ts@@ -5,10 +5,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";import { compileAgent } from "../../src/compiler/compile-agent.js";import { prewarmAppSandboxes } from "../../src/execution/sandbox/prewarm.js";-import {- runVercelBuildPrewarm,- shouldPrewarmVercelBuild,-} from "../../src/internal/nitro/host/vercel-build-prewarm.js";+import { runVercelBuildPrewarm } from "../../src/internal/nitro/host/vercel-build-prewarm.js";import type {SandboxBackendPrewarmInput,SandboxBackendPrewarmResult,@@ -54,7 +51,8 @@ describe("Vercel build-time sandbox prewarm", () => {it("fails the hosted build when sandbox bootstrap fails during prewarm", async () => {vi.stubEnv("VERCEL", "1");- vi.stubEnv("VERCEL_DEPLOYMENT_ID", "dpl_test_build_prewarm");+ vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");+ vi.stubEnv("VERCEL_OIDC_TOKEN", createVercelOidcToken("prj_hosted_build"));const appRoot = await createScenarioAppRoot();@@ -70,29 +68,70 @@ describe("Vercel build-time sandbox prewarm", () => {).rejects.toThrow("bootstrap command failed");});- it("only enables prewarm when both Vercel env variables are present", () => {- expect(shouldPrewarmVercelBuild()).toBe(false);+ it("skips sandbox prewarm outside a Vercel build", async () => {+ await expect(+ runVercelBuildPrewarm({+ appRoot: "/unused",+ }),+ ).resolves.toBe(false);+ });+ it("rejects Vercel output that requires sandbox templates without an OIDC token", async () => {vi.stubEnv("VERCEL", "1");- expect(shouldPrewarmVercelBuild()).toBe(false);+ vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");+ vi.stubEnv("VERCEL_OIDC_TOKEN", "");- vi.stubEnv("VERCEL_DEPLOYMENT_ID", "dpl_test_build_prewarm");- expect(shouldPrewarmVercelBuild()).toBe(true);+ const appRoot = await createScenarioAppRoot();++ await compileAgent({+ startPath: appRoot,+ });++ await expect(+ runVercelBuildPrewarm({+ appRoot,+ }),+ ).rejects.toThrow(+ "Cannot build deployable Vercel output because this app requires sandbox templates and VERCEL_OIDC_TOKEN is missing. Run `vercel link` and `vercel pull`, then retry `vercel build`. Do not deploy the generated .vercel/output.",+ );});- it("warns when a Vercel build cannot prewarm sandbox templates", async () => {+ it("allows a Vercel build without OIDC when no sandbox template is required", async () => {vi.stubEnv("VERCEL", "1");- const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);+ vi.stubEnv("VERCEL_OIDC_TOKEN", "");++ const appRoot = await createTemplateFreeScenarioAppRoot();++ await compileAgent({+ startPath: appRoot,+ });await expect(runVercelBuildPrewarm({- appRoot: "/unused",+ appRoot,}),- ).resolves.toBe(false);+ ).resolves.toBe(true);+ });- expect(warn).toHaveBeenCalledWith(- '[eve] WARNING: Skipped Vercel sandbox template prewarm because VERCEL_DEPLOYMENT_ID is missing. The generated .vercel/output may reference sandbox templates that were not provisioned. Do not deploy it with "vercel deploy --prebuilt"; use "vercel deploy" so Vercel builds from source.',- );+ it("prewarms sandbox templates for a local Vercel build without a deployment id", async () => {+ vi.stubEnv("VERCEL", "1");+ vi.stubEnv("VERCEL_DEPLOYMENT_ID", "");+ vi.stubEnv("VERCEL_OIDC_TOKEN", createVercelOidcToken("prj_local_build"));++ const appRoot = await createScenarioAppRoot();+ const events = createPrewarmEvents();++ await compileAgent({+ startPath: appRoot,+ });++ await expect(+ runVercelBuildPrewarm({+ appRoot,+ dispatch: createRecordingDispatch(events),+ }),+ ).resolves.toBe(true);+ expect(events.templateKeys).toHaveLength(2);});it("prewarms sandbox templates with per-agent skill seed files", async () => {@@ -120,6 +159,28 @@ describe("Vercel build-time sandbox prewarm", () => {});});+function createVercelOidcToken(projectId: string): string {+ const payload = Buffer.from(+ JSON.stringify({ owner_id: "team_test", project_id: projectId }),+ ).toString("base64url");+ return `header.${payload}.signature`;+}++async function createTemplateFreeScenarioAppRoot(): Promise<string> {+ const appRoot = await createScratchDirectory("eve-vercel-build-without-prewarm-");+ const agentRoot = join(appRoot, "agent");++ await mkdir(agentRoot, { recursive: true });+ await writeFile(+ join(appRoot, "package.json"),+ JSON.stringify({ name: "vercel-build-without-prewarm", type: "module" }, null, 2),+ );+ await writeFile(join(agentRoot, "agent.ts"), 'export default { model: "openai/gpt-5.4" };\n');+ await writeFile(join(agentRoot, "instructions.md"), "Root system prompt.\n");++ return appRoot;+}+async function createScenarioAppRoot(input: { readonly withSkills?: boolean } = {},): Promise<string> {