Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve/nuxt): migrate Vercel production routing to the stable services model (#860)

Benjamin Canac1db41fd9dc25
diff --git a/.changeset/nuxt-stable-vercel-services.md b/.changeset/nuxt-stable-vercel-services.md
new file mode 100644
index 000000000..519eb3209
--- /dev/null
+++ b/.changeset/nuxt-stable-vercel-services.md
@@ -0,0 +1,7 @@
+---
+"eve": minor
+---
+
+`eve/nuxt` now deploys the agent through Vercel's stable services model: on Vercel builds the module generates an eve Build Output service and a `/eve/v1/*` service route instead of writing legacy `experimentalServices` to `vercel.json`, which Vercel no longer routes (every agent request returned a platform NOT_FOUND). The `configureVercelJson` and `servicePrefix` module options and the `EVE_NUXT_SERVICE_PREFIX` export were removed. Delete any generated `experimentalServices` block from `vercel.json` — the module warns when it sees one — or declare the eve service and its rewrite yourself under the stable `services` field to keep managing routing manually.
+
+A generated eve service build now also skips host middleware preservation when the host's Build Output config is not yet present, instead of failing the build. Unlike the Next.js integration, which writes that config early, the Nuxt web service emits it only at the end of its own build, so an isolated eve service build could crash reading a file that had no middleware to preserve.
diff --git a/apps/frameworks/nuxt/README.md b/apps/frameworks/nuxt/README.md
index 193dfe786..6896d6b41 100644
--- a/apps/frameworks/nuxt/README.md
+++ b/apps/frameworks/nuxt/README.md
@@ -1,7 +1,6 @@
# Nuxt with eve demo
-A Nuxt 4 app with an embedded eve agent, integrated through the `eve/nuxt`
-module:
+A Nuxt 4 app with an embedded eve agent, integrated through the `eve/nuxt` module:
```ts
export default defineNuxtConfig({
@@ -9,9 +8,7 @@ export default defineNuxtConfig({
});
```
-The agent lives in `agent/` (instructions, tools, channels) next to the Nuxt
-`app/` directory. In local development the module starts the eve runtime
-alongside the Nuxt dev server and proxies same-origin eve endpoints to it.
+The agent lives in `agent/` (instructions, tools, channels) next to the Nuxt `app/` directory. In local development the module starts the eve runtime alongside the Nuxt dev server and proxies same-origin eve endpoints to it.
## Run locally
@@ -21,6 +18,4 @@ pnpm --filter framework-nuxt dev
## Deploy
-`vercel.json` declares two services: the Nuxt app at `/` and eve behind the
-private `/_eve_internal/eve` service prefix. See
-[the Nuxt frontend docs](../../../docs/guides/frontend/nuxt.mdx) for details.
+On Vercel builds the module generates the eve service and its routing in the Build Output config, so no `vercel.json` is required. See [the Nuxt frontend docs](../../../docs/guides/frontend/nuxt.mdx) for details.
diff --git a/apps/frameworks/nuxt/vercel.json b/apps/frameworks/nuxt/vercel.json
deleted file mode 100644
index 4ea0a983e..000000000
--- a/apps/frameworks/nuxt/vercel.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "$schema": "https://openapi.vercel.sh/vercel.json",
- "experimentalServices": {
- "web": {
- "entrypoint": ".",
- "framework": "nuxtjs",
- "routePrefix": "/"
- },
- "eve": {
- "buildCommand": "eve build",
- "entrypoint": ".",
- "framework": "eve",
- "routePrefix": "/_eve_internal/eve"
- }
- }
-}
diff --git a/docs/guides/frontend/nuxt.mdx b/docs/guides/frontend/nuxt.mdx
index e0622129b..586a304de 100644
--- a/docs/guides/frontend/nuxt.mdx
+++ b/docs/guides/frontend/nuxt.mdx
@@ -74,7 +74,7 @@ For a public demo, use `none()` (also from `eve/channels/auth`) to skip authenti
## Dev vs deploy topology
- **Local dev.** `npm run dev` starts the eve dev server next to `nuxt dev` and proxies the eve routes through it. As far as the browser knows, everything is the Nuxt origin.
-- **Vercel.** A single Vercel project carries both the Nuxt app and the eve runtime. The web app stays public; the runtime sits behind it on the same origin. Set `eveBuildCommand` when the agent needs its own build step:
+- **Vercel.** The web app and the eve runtime deploy as a single project. On Vercel builds the module adds Build Output [`services`](https://vercel.com/docs/services) for eve and `routes` that send `/eve/v1/**` to that service before filesystem routing; the Nuxt app itself remains the default app. No `vercel.json` is required. By default the generated service runs the installed eve binary from the agent root, so the agent directory does not need its own `package.json`. When the agent needs its own build step, set `eveBuildCommand`:
```ts
export default defineNuxtConfig({
@@ -92,6 +92,27 @@ For a public demo, use `none()` (also from `eve/channels/auth`) to skip authenti
EVE_NUXT_PRODUCTION_PORT=5000 npm run build && npm run preview
```
+## Managing vercel.json yourself
+
+When `vercel.json` declares [`services`](https://vercel.com/docs/services), the module generates nothing and your configuration owns routing. It must include the eve service (`framework: "eve"`) and a rewrite that exposes the eve transport, or the module fails the build:
+
+```json title="vercel.json"
+{
+ "services": {
+ "web": { "root": ".", "framework": "nuxtjs" },
+ "eve": { "root": "agent", "framework": "eve", "buildCommand": "eve build" }
+ },
+ "rewrites": [{ "source": "/eve/v1/(.*)", "destination": { "service": "eve" } }]
+}
+```
+
+### Migrating from experimentalServices
+
+Earlier versions of the module wrote the legacy `experimentalServices` field into `vercel.json`. Vercel no longer routes that model — deployments build both services but every `/eve/v1/*` request returns a platform NOT_FOUND — so the module now ignores the field and warns when it sees one. Migrate either way:
+
+- **Generated (default).** Delete `vercel.json` (or just its `experimentalServices` block) and set the project's Framework Preset back to Nuxt.js. The module generates the eve service and its routing on every Vercel build.
+- **Hand-maintained.** Replace `experimentalServices` with the stable `services` and `rewrites` shown above, and keep the "Services" Framework Preset.
+
## What to read next
- [`useEveAgent` (Vue)](./use-eve-agent-vue): the composable API
diff --git a/packages/eve/src/internal/nitro/host/copy-host-middleware.integration.test.ts b/packages/eve/src/internal/nitro/host/copy-host-middleware.integration.test.ts
new file mode 100644
index 000000000..c16637a3f
--- /dev/null
+++ b/packages/eve/src/internal/nitro/host/copy-host-middleware.integration.test.ts
@@ -0,0 +1,73 @@
+import { access, mkdir, mkdtemp, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { afterEach, describe, expect, it } from "vitest";
+
+import { copyHostMiddlewareFunctions } from "#internal/nitro/host/copy-host-middleware.js";
+
+const tempRoots: string[] = [];
+
+async function createTempDir(): Promise<string> {
+ const dir = await mkdtemp(join(tmpdir(), "eve-host-middleware-"));
+ tempRoots.push(dir);
+ return dir;
+}
+
+async function pathExists(path: string): Promise<boolean> {
+ try {
+ await access(path);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+afterEach(async () => {
+ const { rm } = await import("node:fs/promises");
+ await Promise.all(tempRoots.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
+});
+
+describe("copyHostMiddlewareFunctions", () => {
+ it("skips silently when the host Build Output config is absent", async () => {
+ const hostOutputDirectory = await createTempDir();
+ const serviceOutputDirectory = await createTempDir();
+
+ await expect(
+ copyHostMiddlewareFunctions({ hostOutputDirectory, serviceOutputDirectory }),
+ ).resolves.toBeUndefined();
+ });
+
+ it("copies a host middleware function referenced by a route into the service output", async () => {
+ const hostOutputDirectory = await createTempDir();
+ const serviceOutputDirectory = await createTempDir();
+ const middlewareDir = join(hostOutputDirectory, "functions", "_middleware.func");
+ await mkdir(middlewareDir, { recursive: true });
+ await writeFile(join(middlewareDir, ".vc-config.json"), "{}\n");
+ await writeFile(
+ join(hostOutputDirectory, "config.json"),
+ `${JSON.stringify({ version: 3, routes: [{ middlewarePath: "/_middleware" }] })}\n`,
+ );
+
+ await copyHostMiddlewareFunctions({ hostOutputDirectory, serviceOutputDirectory });
+
+ expect(
+ await pathExists(
+ join(serviceOutputDirectory, "functions", "_middleware.func", ".vc-config.json"),
+ ),
+ ).toBe(true);
+ });
+
+ it("copies nothing when the host config declares no middleware", async () => {
+ const hostOutputDirectory = await createTempDir();
+ const serviceOutputDirectory = await createTempDir();
+ await writeFile(
+ join(hostOutputDirectory, "config.json"),
+ `${JSON.stringify({ version: 3, routes: [{ handle: "filesystem" }] })}\n`,
+ );
+
+ await copyHostMiddlewareFunctions({ hostOutputDirectory, serviceOutputDirectory });
+
+ expect(await pathExists(join(serviceOutputDirectory, "functions"))).toBe(false);
+ });
+});
diff --git a/packages/eve/src/internal/nitro/host/copy-host-middleware.ts b/packages/eve/src/internal/nitro/host/copy-host-middleware.ts
index 33ed7120d..54eae3bff 100644
--- a/packages/eve/src/internal/nitro/host/copy-host-middleware.ts
+++ b/packages/eve/src/internal/nitro/host/copy-host-middleware.ts
@@ -46,9 +46,24 @@ export async function copyHostMiddlewareFunctions(input: {
readonly hostOutputDirectory: string;
readonly serviceOutputDirectory: string;
}): Promise<void> {
- const config: unknown = JSON.parse(
- await readFile(join(input.hostOutputDirectory, "config.json"), "utf8"),
- );
+ let configContents: string;
+ try {
+ configContents = await readFile(join(input.hostOutputDirectory, "config.json"), "utf8");
+ } catch (error) {
+ // The host Build Output config need not exist when a generated service
+ // builds. A host that writes its config only at the end of its own build
+ // (e.g. the Nuxt web service, whose Nitro Vercel preset emits config.json
+ // last) may not have produced it when Vercel builds the generated service
+ // independently. There is no host middleware to preserve in that case, so
+ // skip the copy rather than failing the service build.
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
+ return;
+ }
+
+ throw error;
+ }
+
+ const config: unknown = JSON.parse(configContents);
if (!isRecord(config)) {
return;
diff --git a/packages/eve/src/internal/testing/scenario-apps/nuxt-eve-service.ts b/packages/eve/src/internal/testing/scenario-apps/nuxt-eve-service.ts
new file mode 100644
index 000000000..5a322d993
--- /dev/null
+++ b/packages/eve/src/internal/testing/scenario-apps/nuxt-eve-service.ts
@@ -0,0 +1,46 @@
+import type { ScenarioAppDescriptor } from "#internal/testing/scenario-app.js";
+
+// Not resolved from the installed workspace like the Next.js descriptor's
+// dependencies: `nuxt` is only an optional peer of eve, so no copy is
+// installed to resolve a version from.
+const NUXT_VERSION = "^4.0.0";
+const VUE_VERSION = "^3.5.0";
+
+export interface NuxtEveServiceDescriptorOptions {
+ readonly installDependencies?: boolean;
+}
+
+/**
+ * A Nuxt host with a generated eve Vercel service.
+ */
+export function createNuxtEveServiceDescriptor(
+ options: NuxtEveServiceDescriptorOptions = {},
+): ScenarioAppDescriptor {
+ return {
+ dependencies: {
+ nuxt: NUXT_VERSION,
+ vue: VUE_VERSION,
+ },
+ files: {
+ "agent/agent.mjs": `import { defineAgent } from "eve";
+
+export default defineAgent({ model: "openai/gpt-5.4" });
+`,
+ "agent/instructions.md": "You are a test agent.\n",
+ "app/app.vue": `<template>
+ <main>eve nuxt deployment</main>
+</template>
+`,
+ "nuxt.config.ts": `export default defineNuxtConfig({
+ compatibilityDate: "2026-05-27",
+ eve: { eveRoot: "agent" },
+ modules: ["eve/nuxt"],
+ telemetry: false,
+});
+`,
+ "pnpm-workspace.yaml": "minimumReleaseAge: 0\n",
+ },
+ installDependencies: options.installDependencies,
+ name: "nuxt-eve-service",
+ };
+}
diff --git a/packages/eve/src/public/next/index.integration.test.ts b/packages/eve/src/public/next/index.integration.test.ts
index e88eef348..ce2a44f12 100644
--- a/packages/eve/src/public/next/index.integration.test.ts
+++ b/packages/eve/src/public/next/index.integration.test.ts
@@ -4,7 +4,7 @@ import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
-vi.mock("./resolve-eve-binary.js", async () => {
+vi.mock("#shared/resolve-eve-binary.js", async () => {
const { join } = await import("node:path");
return {
// Pin resolution to the conventional app-local path so build-command
diff --git a/packages/eve/src/public/next/index.test.ts b/packages/eve/src/public/next/index.test.ts
index 845c05209..c8d2728d0 100644
--- a/packages/eve/src/public/next/index.test.ts
+++ b/packages/eve/src/public/next/index.test.ts
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
-vi.mock("./resolve-eve-binary.js", async () => {
+vi.mock("#shared/resolve-eve-binary.js", async () => {
const { join } = await import("node:path");
return {
// Pin resolution to the conventional app-local path so the default
diff --git a/packages/eve/src/public/next/index.ts b/packages/eve/src/public/next/index.ts
index a19cb4ede..3a05e1ce3 100644
--- a/packages/eve/src/public/next/index.ts
+++ b/packages/eve/src/public/next/index.ts
@@ -3,7 +3,7 @@ import { isAbsolute, relative, resolve } from "node:path";
import type { NextConfig } from "next";
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
-import { resolveEveBinaryPath } from "./resolve-eve-binary.js";
+import { resolveEveBinaryPath } from "#shared/resolve-eve-binary.js";
import { resolveEveDestinationPrefix } from "./server.js";
import { ensureEveVercelOutputConfig } from "./vercel-output-config.js";
diff --git a/packages/eve/src/public/nuxt/index.ts b/packages/eve/src/public/nuxt/index.ts
index 720f89a32..9d4b1f703 100644
--- a/packages/eve/src/public/nuxt/index.ts
+++ b/packages/eve/src/public/nuxt/index.ts
@@ -1 +1 @@
-export { default, EVE_NUXT_SERVICE_PREFIX, type EveNuxtModuleOptions } from "./module.js";
+export { default, type EveNuxtModuleOptions } from "./module.js";
diff --git a/packages/eve/src/public/nuxt/module.ts b/packages/eve/src/public/nuxt/module.ts
index 105b833b7..36806e383 100644
--- a/packages/eve/src/public/nuxt/module.ts
+++ b/packages/eve/src/public/nuxt/module.ts
@@ -6,19 +6,12 @@ import { addImports, defineNuxtModule, extendRouteRules } from "@nuxt/kit";
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
import { EVE_BASE_URL_ENV, resolveSharedEveDevServer } from "./dev-server.js";
+import { joinRoutePrefix, normalizeOrigin, resolveProductionTarget } from "./routing.js";
import {
- EVE_NUXT_SERVICE_PREFIX,
- createEveVercelRewriteRoute,
- joinRoutePrefix,
- normalizeOrigin,
- normalizeRoutePrefix,
- resolveProductionTarget,
-} from "./routing.js";
-import { ensureEveVercelJson } from "./vercel-json.js";
-
-export { EVE_NUXT_SERVICE_PREFIX };
-
-const DEFAULT_EVE_BUILD_COMMAND = "eve build";
+ ensureEveVercelServicesConfig,
+ mergeEveVercelConfig,
+ type NitroVercelBuildConfig,
+} from "./vercel-services.js";
/**
* Options for the eve Nuxt module.
@@ -27,28 +20,16 @@ export interface EveNuxtModuleOptions {
/**
* Path to the eve application root, resolved relative to the Nuxt project
* root unless absolute. Defaults to the Nuxt project root. The dev server is
- * spawned here and written as the eve service entrypoint in `vercel.json`
- * (relative to the Nuxt root).
+ * spawned here, and on Vercel it is the root the generated eve service
+ * builds from.
*/
eveRoot?: string;
/**
- * Build command for the generated eve Vercel service. Defaults to `"eve build"`.
+ * Command that builds the eve app inside the generated Vercel eve service.
+ * Defaults to running the installed eve binary from the Nuxt app's
+ * dependencies (`node <path-to>/eve/bin/eve.js build`).
*/
eveBuildCommand?: string;
- /**
- * Set to `false` to skip creating or updating `vercel.json`. By default the
- * module ensures `vercel.json` contains `experimentalServices` for the Nuxt
- * app and eve app.
- */
- configureVercelJson?: boolean;
- /**
- * Private Vercel service prefix eve transport is proxied to. Defaults to
- * {@link EVE_NUXT_SERVICE_PREFIX}. When `configureVercelJson` is enabled, it
- * is written as the eve service `routePrefix`, but an existing `routePrefix`
- * in `vercel.json` takes precedence. Normalized to a leading-slash,
- * no-trailing-slash route; cannot resolve to `/`.
- */
- servicePrefix?: string;
}
function resolveApplicationRoot(nuxtRoot: string, appPath: string | undefined): string {
@@ -59,25 +40,22 @@ function resolveApplicationRoot(nuxtRoot: string, appPath: string | undefined):
}
/**
- * Minimal view of the Nitro Vercel build-output config the module appends to.
- * The full `nitro` typing lives behind the nitropack/Nuxt augmentation, which
- * is not loaded in this package's build, so model only the surface we touch.
+ * Minimal view of the Nitro Vercel build-output config the module merges the
+ * eve service into. The full `nitro` typing lives behind the nitropack/Nuxt
+ * augmentation, which is not loaded in this package's build, so model only the
+ * surface we touch.
*/
interface NitroVercelConfigHost {
vercel?: {
- config?: {
- version?: number;
- routes?: unknown[];
- [key: string]: unknown;
- };
+ config?: NitroVercelBuildConfig;
[key: string]: unknown;
};
}
/**
* Resolve the destination eve routes proxy to. In dev this is an explicit
- * `EVE_BASE_URL` or a shared dev server spawned on demand; in production it is
- * the Vercel private service or a configured origin/port.
+ * `EVE_BASE_URL` or a shared dev server spawned on demand; in non-Vercel
+ * production it is a configured origin/port.
*
* When a dev server is spawned by this process, `onDevServerSpawned` is invoked
* with the child handle so the caller can wire lifecycle-scoped cleanup.
@@ -85,11 +63,10 @@ interface NitroVercelConfigHost {
async function resolveEveProxyTarget(input: {
readonly appRoot: string;
readonly dev: boolean;
- readonly servicePrefix: string;
readonly onDevServerSpawned?: (child: ChildProcess) => void;
}): Promise<string> {
if (!input.dev) {
- return resolveProductionTarget(input.servicePrefix);
+ return resolveProductionTarget();
}
const configuredEveBaseUrl = process.env[EVE_BASE_URL_ENV]?.trim();
@@ -108,11 +85,11 @@ async function resolveEveProxyTarget(input: {
/**
* Nuxt module that wires an eve agent into a Nuxt app. Register under `modules`
* (configured via the `eve` config key). It auto-imports the `useEveAgent()`
- * composable, routes eve transport requests (`/eve/v1/**`) to the eve service
- * (a shared dev server spawned on demand in dev, a Vercel sibling service or a
- * configured origin/port in production), and unless `configureVercelJson` is
- * `false`, ensures `vercel.json` declares both the Nuxt and eve services.
- * Requires Nuxt >= 4.0.0. Configure via {@link EveNuxtModuleOptions}.
+ * composable and routes eve transport requests (`/eve/v1/**`) to the eve
+ * service: a shared dev server spawned on demand in dev, a generated Vercel
+ * service on Vercel deployments, and a configured origin/port in non-Vercel
+ * production. Requires Nuxt >= 4.0.0. Configure via
+ * {@link EveNuxtModuleOptions}.
*/
export default defineNuxtModule<EveNuxtModuleOptions>({
meta: {
@@ -126,29 +103,31 @@ export default defineNuxtModule<EveNuxtModuleOptions>({
async setup(options, nuxt) {
const nuxtRoot = nuxt.options.rootDir;
const appRoot = resolveApplicationRoot(nuxtRoot, options.eveRoot);
- const servicePrefix = normalizeRoutePrefix(options.servicePrefix ?? EVE_NUXT_SERVICE_PREFIX);
- const shouldConfigureVercelJson = options.configureVercelJson !== false;
// Auto-import the Vue composable so app code can call `useEveAgent()`
// without an explicit import, matching Nuxt's composable conventions.
addImports({ name: "useEveAgent", from: "eve/vue" });
- // On Vercel the eve app deploys as a sibling experimental service. A Nitro
- // runtime `proxy` rule can't reach it — the proxied request loops back into
- // the Nuxt function and 404s — so route eve transport at the edge via a
- // build-config rewrite, mirroring the Next.js integration.
+ // On Vercel the eve app deploys as a sibling service. A Nitro runtime
+ // `proxy` rule can't reach it — the proxied request loops back into the
+ // Nuxt function and 404s — so declare the service and route eve transport
+ // to it at the edge through the build output config, mirroring the Next.js
+ // integration.
if (!nuxt.options.dev && process.env.VERCEL) {
- const rewrite = createEveVercelRewriteRoute(servicePrefix);
- const nitro = (nuxt.options as typeof nuxt.options & { nitro: NitroVercelConfigHost }).nitro;
- const existing = nitro.vercel?.config;
- nitro.vercel = {
- ...nitro.vercel,
- config: {
- version: 3,
- ...existing,
- routes: [rewrite, ...(existing?.routes ?? [])],
- },
- };
+ const configured = await ensureEveVercelServicesConfig({
+ appRoot,
+ eveBuildCommand: options.eveBuildCommand,
+ nuxtRoot,
+ });
+
+ if (configured.mode === "generated") {
+ const nitro = (nuxt.options as typeof nuxt.options & { nitro: NitroVercelConfigHost })
+ .nitro;
+ nitro.vercel = {
+ ...nitro.vercel,
+ config: mergeEveVercelConfig(nitro.vercel?.config, configured),
+ };
+ }
} else {
// Dev (and non-Vercel production, which proxies to an absolute origin):
// booting the shared eve dev server can take a while, so defer it out of
@@ -159,7 +138,6 @@ export default defineNuxtModule<EveNuxtModuleOptions>({
const proxyTarget = await resolveEveProxyTarget({
appRoot,
dev: nuxt.options.dev,
- servicePrefix,
onDevServerSpawned: (child) => {
// Prefer Nuxt's lifecycle for cleanup so the dev server is torn
// down on graceful shutdown and dev restarts. The process-exit
@@ -178,14 +156,5 @@ export default defineNuxtModule<EveNuxtModuleOptions>({
});
});
}
-
- if (shouldConfigureVercelJson) {
- await ensureEveVercelJson({
- appRoot,
- eveBuildCommand: options.eveBuildCommand ?? DEFAULT_EVE_BUILD_COMMAND,
- nuxtRoot,
- servicePrefix,
- });
- }
},
});
diff --git a/packages/eve/src/public/nuxt/routing.test.ts b/packages/eve/src/public/nuxt/routing.test.ts
index 7b3a9add8..bebfb3cc8 100644
--- a/packages/eve/src/public/nuxt/routing.test.ts
+++ b/packages/eve/src/public/nuxt/routing.test.ts
@@ -1,11 +1,8 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import {
- EVE_NUXT_SERVICE_PREFIX,
- createEveVercelRewriteRoute,
joinRoutePrefix,
normalizeOrigin,
- normalizeRoutePrefix,
readLocalProductionPort,
resolveProductionTarget,
} from "./routing.js";
@@ -16,28 +13,9 @@ afterEach(() => {
vi.unstubAllEnvs();
});
-describe("normalizeRoutePrefix", () => {
- it("prepends a leading slash when missing", () => {
- expect(normalizeRoutePrefix("internal/eve")).toBe("/internal/eve");
- });
-
- it("strips trailing slashes", () => {
- expect(normalizeRoutePrefix("/internal/eve///")).toBe("/internal/eve");
- });
-
- it("keeps an already-normalized prefix unchanged", () => {
- expect(normalizeRoutePrefix(EVE_NUXT_SERVICE_PREFIX)).toBe(EVE_NUXT_SERVICE_PREFIX);
- });
-
- it("throws when the prefix resolves to the root route", () => {
- expect(() => normalizeRoutePrefix("/")).toThrow(/cannot resolve to the root route/);
- expect(() => normalizeRoutePrefix("")).toThrow(/cannot resolve to the root route/);
- });
-});
-
describe("joinRoutePrefix", () => {
it("joins with exactly one slash", () => {
- expect(joinRoutePrefix("/_eve_internal/eve", "/eve/v1")).toBe("/_eve_internal/eve/eve/v1");
+ expect(joinRoutePrefix("http://127.0.0.1:4274", "eve/v1")).toBe("http://127.0.0.1:4274/eve/v1");
});
it("collapses duplicate slashes at the boundary", () => {
@@ -93,51 +71,14 @@ describe("readLocalProductionPort", () => {
});
});
-describe("createEveVercelRewriteRoute", () => {
- it("rewrites the eve transport prefix onto the service prefix", () => {
- expect(createEveVercelRewriteRoute(EVE_NUXT_SERVICE_PREFIX)).toEqual({
- src: `^${EVE_PROTOCOL_PREFIX}/(.*)$`,
- dest: `${EVE_NUXT_SERVICE_PREFIX}${EVE_PROTOCOL_PREFIX}/$1`,
- check: true,
- });
- });
-
- it("honors a custom service prefix", () => {
- expect(createEveVercelRewriteRoute("/agent")).toEqual({
- src: `^${EVE_PROTOCOL_PREFIX}/(.*)$`,
- dest: `/agent${EVE_PROTOCOL_PREFIX}/$1`,
- check: true,
- });
- });
-});
-
describe("resolveProductionTarget", () => {
- it("targets the private service prefix on Vercel", () => {
- vi.stubEnv("VERCEL", "1");
- expect(resolveProductionTarget(EVE_NUXT_SERVICE_PREFIX)).toBe(
- `${EVE_NUXT_SERVICE_PREFIX}${EVE_PROTOCOL_PREFIX}`,
- );
- });
-
- it("ignores a production origin override on Vercel", () => {
- vi.stubEnv("VERCEL", "1");
- vi.stubEnv("EVE_NUXT_PRODUCTION_ORIGIN", "https://agent.example.com");
- expect(resolveProductionTarget(EVE_NUXT_SERVICE_PREFIX)).toBe(
- `${EVE_NUXT_SERVICE_PREFIX}${EVE_PROTOCOL_PREFIX}`,
- );
- });
-
- it("uses a production origin override off Vercel", () => {
+ it("uses a production origin override", () => {
vi.stubEnv("EVE_NUXT_PRODUCTION_ORIGIN", "https://agent.example.com/root");
- expect(resolveProductionTarget(EVE_NUXT_SERVICE_PREFIX)).toBe(
- `https://agent.example.com${EVE_PROTOCOL_PREFIX}`,
- );
+ expect(resolveProductionTarget()).toBe(`https://agent.example.com${EVE_PROTOCOL_PREFIX}`);
});
- it("falls back to a local port off Vercel", () => {
+ it("falls back to a local port", () => {
vi.stubEnv("EVE_NUXT_PRODUCTION_PORT", "5000");
- expect(resolveProductionTarget(EVE_NUXT_SERVICE_PREFIX)).toBe(
- `http://127.0.0.1:5000${EVE_PROTOCOL_PREFIX}`,
- );
+ expect(resolveProductionTarget()).toBe(`http://127.0.0.1:5000${EVE_PROTOCOL_PREFIX}`);
});
});
diff --git a/packages/eve/src/public/nuxt/routing.ts b/packages/eve/src/public/nuxt/routing.ts
index 482d0b327..7046903d9 100644
--- a/packages/eve/src/public/nuxt/routing.ts
+++ b/packages/eve/src/public/nuxt/routing.ts
@@ -1,29 +1,9 @@
import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
-/**
- * Private route namespace used when a Vercel deployment hosts eve as a
- * separate experimental service behind the Nuxt app.
- */
-export const EVE_NUXT_SERVICE_PREFIX = "/_eve_internal/eve";
-
const EVE_NUXT_PRODUCTION_ORIGIN_ENV = "EVE_NUXT_PRODUCTION_ORIGIN";
const EVE_NUXT_PRODUCTION_PORT_ENV = "EVE_NUXT_PRODUCTION_PORT";
const DEFAULT_EVE_NUXT_PRODUCTION_PORT = 4274;
-/**
- * Normalize a user-supplied service prefix into a leading-slash, no-trailing-
- * slash route. Throws when the prefix resolves to the root route, which would
- * collide with the Nuxt web service.
- */
-export function normalizeRoutePrefix(prefix: string): string {
- const prefixed = prefix.startsWith("/") ? prefix : `/${prefix}`;
- const normalized = prefixed.replace(/\/+$/, "");
- if (normalized.length === 0) {
- throw new Error("eve Nuxt service prefix cannot resolve to the root route.");
- }
- return normalized;
-}
-
/**
* Join a route prefix and a path with exactly one separating slash.
*/
@@ -56,48 +36,12 @@ export function readLocalProductionPort(): number {
}
/**
- * An edge-level Vercel rewrite expressed in Build Output API v3 form.
- */
-export interface EveVercelRewriteRoute {
- readonly src: string;
- readonly dest: string;
- /**
- * Re-run route matching against the rewritten `dest`. Required so the
- * rewritten eve service path is routed to the sibling eve service instead of
- * being resolved inside the host service's own filesystem (which 404s).
- */
- readonly check: true;
-}
-
-/**
- * Build the edge-level Vercel rewrite that forwards eve transport requests
- * (`/eve/v1/**`) to the eve service prefix (`/_eve_internal/eve/eve/v1/**`).
- *
- * Mirrors the Next.js integration's `beforeFiles` rewrite. A Nitro runtime
- * `proxy` route rule cannot reach a sibling Vercel service — the proxied
- * request loops back into the Nuxt function and 404s — so production routing
- * must happen at the edge via the build output config instead.
+ * Resolve the proxy destination for eve routes in non-Vercel production: an
+ * explicit origin override (`EVE_NUXT_PRODUCTION_ORIGIN`) or a local port. On
+ * Vercel the module routes at the edge via a Build Output service route
+ * instead of proxying.
*/
-export function createEveVercelRewriteRoute(servicePrefix: string): EveVercelRewriteRoute {
- const destinationPrefix = joinRoutePrefix(servicePrefix, EVE_ROUTE_PREFIX);
- return {
- src: `^${EVE_ROUTE_PREFIX}/(.*)$`,
- dest: `${destinationPrefix}/$1`,
- check: true,
- };
-}
-
-/**
- * Resolve the proxy destination for eve routes in production.
- *
- * On Vercel the destination is the private service prefix. Off Vercel it is an
- * explicit origin override (`EVE_NUXT_PRODUCTION_ORIGIN`) or a local port.
- */
-export function resolveProductionTarget(servicePrefix: string): string {
- if (process.env.VERCEL) {
- return joinRoutePrefix(servicePrefix, EVE_ROUTE_PREFIX);
- }
-
+export function resolveProductionTarget(): string {
const configuredOrigin = process.env[EVE_NUXT_PRODUCTION_ORIGIN_ENV];
if (configuredOrigin !== undefined && configuredOrigin.trim().length > 0) {
return joinRoutePrefix(normalizeOrigin(configuredOrigin), EVE_ROUTE_PREFIX);
diff --git a/packages/eve/src/public/nuxt/vercel-json.integration.test.ts b/packages/eve/src/public/nuxt/vercel-json.integration.test.ts
deleted file mode 100644
index 95560d1bf..000000000
--- a/packages/eve/src/public/nuxt/vercel-json.integration.test.ts
+++ /dev/null
@@ -1,149 +0,0 @@
-import { mkdtemp, readFile, writeFile } from "node:fs/promises";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
-
-import { describe, expect, it } from "vitest";
-
-import { EVE_NUXT_SERVICE_PREFIX } from "./routing.js";
-import { ensureEveVercelJson } from "./vercel-json.js";
-
-async function createTempRoot(): Promise<string> {
- return await mkdtemp(join(tmpdir(), "eve-nuxt-vercel-"));
-}
-
-async function readJsonFile(path: string): Promise<unknown> {
- return JSON.parse(await readFile(path, "utf8")) as unknown;
-}
-
-describe("ensureEveVercelJson", () => {
- it("creates experimentalServices when vercel.json is missing", async () => {
- const nuxtRoot = await createTempRoot();
-
- const result = await ensureEveVercelJson({
- appRoot: nuxtRoot,
- eveBuildCommand: "eve build",
- nuxtRoot,
- servicePrefix: EVE_NUXT_SERVICE_PREFIX,
- });
-
- expect(result.servicePrefix).toBe(EVE_NUXT_SERVICE_PREFIX);
- expect(await readJsonFile(join(nuxtRoot, "vercel.json"))).toEqual({
- $schema: "https://openapi.vercel.sh/vercel.json",
- experimentalServices: {
- eve: {
- buildCommand: "eve build",
- entrypoint: ".",
- framework: "eve",
- routePrefix: EVE_NUXT_SERVICE_PREFIX,
- },
- web: {
- entrypoint: ".",
- framework: "nuxtjs",
- routePrefix: "/",
- },
- },
- });
- });
-
- it("resolves the eve entrypoint relative to the Nuxt root", async () => {
- const nuxtRoot = await createTempRoot();
- const appRoot = join(nuxtRoot, "agent");
-
- await ensureEveVercelJson({
- appRoot,
- eveBuildCommand: "eve build",
- nuxtRoot,
- servicePrefix: EVE_NUXT_SERVICE_PREFIX,
- });
-
- expect(await readJsonFile(join(nuxtRoot, "vercel.json"))).toMatchObject({
- experimentalServices: {
- eve: { entrypoint: "agent" },
- },
- });
- });
-
- it("uses a custom build command", async () => {
- const nuxtRoot = await createTempRoot();
-
- await ensureEveVercelJson({
- appRoot: nuxtRoot,
- eveBuildCommand: "pnpm build:eve",
- nuxtRoot,
- servicePrefix: EVE_NUXT_SERVICE_PREFIX,
- });
-
- expect(await readJsonFile(join(nuxtRoot, "vercel.json"))).toMatchObject({
- experimentalServices: {
- eve: { buildCommand: "pnpm build:eve" },
- },
- });
- });
-
- it("preserves an already-configured eve service and reuses its prefix", async () => {
- const nuxtRoot = await createTempRoot();
- const existing = {
- $schema: "https://openapi.vercel.sh/vercel.json",
- experimentalServices: {
- agent: {
- entrypoint: "agent",
- framework: "eve",
- routePrefix: "/private/agent",
- },
- frontend: {
- entrypoint: ".",
- framework: "nuxtjs",
- routePrefix: "/",
- },
- },
- };
- await writeFile(join(nuxtRoot, "vercel.json"), `${JSON.stringify(existing, null, 2)}\n`);
-
- const result = await ensureEveVercelJson({
- appRoot: nuxtRoot,
- eveBuildCommand: "eve build",
- nuxtRoot,
- servicePrefix: EVE_NUXT_SERVICE_PREFIX,
- });
-
- expect(result.servicePrefix).toBe("/private/agent");
- expect(await readJsonFile(join(nuxtRoot, "vercel.json"))).toEqual(existing);
- });
-
- it("preserves unrelated top-level keys", async () => {
- const nuxtRoot = await createTempRoot();
- await writeFile(
- join(nuxtRoot, "vercel.json"),
- `${JSON.stringify({ regions: ["iad1"] }, null, 2)}\n`,
- );
-
- await ensureEveVercelJson({
- appRoot: nuxtRoot,
- eveBuildCommand: "eve build",
- nuxtRoot,
- servicePrefix: EVE_NUXT_SERVICE_PREFIX,
- });
-
- expect(await readJsonFile(join(nuxtRoot, "vercel.json"))).toMatchObject({
- regions: ["iad1"],
- experimentalServices: {
- eve: { framework: "eve" },
- web: { framework: "nuxtjs" },
- },
- });
- });
-
- it("rejects a malformed vercel.json", async () => {
- const nuxtRoot = await createTempRoot();
- await writeFile(join(nuxtRoot, "vercel.json"), `${JSON.stringify(["not", "an", "object"])}\n`);
-
- await expect(
- ensureEveVercelJson({
- appRoot: nuxtRoot,
- eveBuildCommand: "eve build",
- nuxtRoot,
- servicePrefix: EVE_NUXT_SERVICE_PREFIX,
- }),
- ).rejects.toThrow(/must contain a JSON object/);
- });
-});
diff --git a/packages/eve/src/public/nuxt/vercel-json.ts b/packages/eve/src/public/nuxt/vercel-json.ts
deleted file mode 100644
index 6f448b137..000000000
--- a/packages/eve/src/public/nuxt/vercel-json.ts
+++ /dev/null
@@ -1,118 +0,0 @@
-import { readFile, writeFile } from "node:fs/promises";
-import { join, relative } from "node:path";
-
-const VERCEL_JSON_FILE_NAME = "vercel.json";
-const VERCEL_JSON_SCHEMA = "https://openapi.vercel.sh/vercel.json";
-
-interface VercelServiceConfig {
- readonly buildCommand?: string;
- readonly entrypoint: string;
- readonly framework: string;
- readonly routePrefix: string;
-}
-
-interface VercelJsonConfig {
- readonly $schema?: string;
- readonly experimentalServices?: Record<string, VercelServiceConfig>;
- readonly [key: string]: unknown;
-}
-
-export interface EnsureVercelJsonResult {
- readonly servicePrefix: string;
-}
-
-function isRecord(value: unknown): value is Record<string, unknown> {
- return value !== null && typeof value === "object" && !Array.isArray(value);
-}
-
-function resolveRelativeEntrypoint(fromRoot: string, toRoot: string): string {
- const relativePath = relative(fromRoot, toRoot);
- return relativePath.length === 0 ? "." : relativePath.replaceAll("\\", "/");
-}
-
-function normalizeVercelJsonConfig(value: unknown): VercelJsonConfig {
- if (!isRecord(value)) {
- throw new Error(`${VERCEL_JSON_FILE_NAME} must contain a JSON object.`);
- }
-
- const experimentalServices = value.experimentalServices;
-
- if (experimentalServices !== undefined && !isRecord(experimentalServices)) {
- throw new Error(`${VERCEL_JSON_FILE_NAME} experimentalServices must be a JSON object.`);
- }
-
- return value as VercelJsonConfig;
-}
-
-async function readVercelJsonConfig(path: string): Promise<VercelJsonConfig> {
- try {
- return normalizeVercelJsonConfig(JSON.parse(await readFile(path, "utf8")) as unknown);
- } catch (error) {
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
- return {};
- }
-
- throw error;
- }
-}
-
-function findServiceByFramework(
- services: Record<string, VercelServiceConfig>,
- framework: string,
-): VercelServiceConfig | undefined {
- return Object.values(services).find((service) => service.framework === framework);
-}
-
-/**
- * Ensure `vercel.json` declares the Nuxt web service and the eve agent
- * service so a Vercel deployment ships both from one project.
- *
- * Existing services are preserved untouched; an already-configured eve
- * service's `routePrefix` wins over {@link input.servicePrefix}. The file is
- * only rewritten when the resulting config differs from what is on disk.
- */
-export async function ensureEveVercelJson(input: {
- readonly appRoot: string;
- readonly eveBuildCommand: string;
- readonly nuxtRoot: string;
- readonly servicePrefix: string;
-}): Promise<EnsureVercelJsonResult> {
- const vercelJsonPath = join(input.nuxtRoot, VERCEL_JSON_FILE_NAME);
- const existingConfig = await readVercelJsonConfig(vercelJsonPath);
- const nuxtEntrypoint = ".";
- const eveEntrypoint = resolveRelativeEntrypoint(input.nuxtRoot, input.appRoot);
- const existingServices = existingConfig.experimentalServices ?? {};
- const configuredEveService = findServiceByFramework(existingServices, "eve");
- const configuredNuxtService = findServiceByFramework(existingServices, "nuxtjs");
- const servicePrefix = configuredEveService?.routePrefix ?? input.servicePrefix;
- const experimentalServices: Record<string, VercelServiceConfig> = { ...existingServices };
-
- if (configuredNuxtService === undefined) {
- experimentalServices.web = {
- entrypoint: nuxtEntrypoint,
- framework: "nuxtjs",
- routePrefix: "/",
- };
- }
-
- if (configuredEveService === undefined) {
- experimentalServices.eve = {
- buildCommand: input.eveBuildCommand,
- entrypoint: eveEntrypoint,
- framework: "eve",
- routePrefix: servicePrefix,
- };
- }
-
- const vercelConfig: VercelJsonConfig = {
- ...existingConfig,
- $schema: existingConfig.$schema ?? VERCEL_JSON_SCHEMA,
- experimentalServices,
- };
-
- if (JSON.stringify(existingConfig) !== JSON.stringify(vercelConfig)) {
- await writeFile(vercelJsonPath, `${JSON.stringify(vercelConfig, null, 2)}\n`);
- }
-
- return { servicePrefix };
-}
diff --git a/packages/eve/src/public/nuxt/vercel-services.integration.test.ts b/packages/eve/src/public/nuxt/vercel-services.integration.test.ts
new file mode 100644
index 000000000..1d6701330
--- /dev/null
+++ b/packages/eve/src/public/nuxt/vercel-services.integration.test.ts
@@ -0,0 +1,217 @@
+import { mkdir, mkdtemp, stat, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("#shared/resolve-eve-binary.js", async () => {
+ const { join } = await import("node:path");
+ return {
+ // Pin resolution to the conventional app-local path so build-command
+ // assertions stay deterministic without a real eve install on disk. The
+ // real resolver is exercised in resolve-eve-binary.integration.test.ts.
+ resolveEveBinaryPath: (appRoot: string) =>
+ join(appRoot, "node_modules", "eve", "bin", "eve.js"),
+ };
+});
+
+import { ensureEveVercelServicesConfig } from "./vercel-services.js";
+
+async function createTempNuxtRoot(): Promise<string> {
+ return await mkdtemp(join(tmpdir(), "eve-nuxt-services-"));
+}
+
+async function directoryExists(path: string): Promise<boolean> {
+ try {
+ return (await stat(path)).isDirectory();
+ } catch {
+ return false;
+ }
+}
+
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+describe("ensureEveVercelServicesConfig", () => {
+ it("generates the eve service when vercel.json is missing", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+
+ const result = await ensureEveVercelServicesConfig({
+ appRoot: nuxtRoot,
+ nuxtRoot,
+ });
+
+ expect(result).toEqual({
+ mode: "generated",
+ services: {
+ eve: {
+ buildCommand:
+ "cd '../../..' && export EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY='.eve/vercel-services/eve/.vercel/output' && export EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY='.vercel/output' && node 'node_modules/eve/bin/eve.js' build",
+ framework: "eve",
+ routes: [
+ {
+ src: "^/eve/v1/(.*)$",
+ transforms: [
+ {
+ args: "/eve/v1/$1",
+ op: "set",
+ type: "request.path",
+ },
+ ],
+ },
+ ],
+ root: ".eve/vercel-services/eve",
+ },
+ },
+ });
+ });
+
+ it("creates the isolated service build root", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+
+ await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+
+ expect(await directoryExists(join(nuxtRoot, ".eve", "vercel-services", "eve"))).toBe(true);
+ });
+
+ it("uses a custom eve build command verbatim", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+
+ const result = await ensureEveVercelServicesConfig({
+ appRoot: nuxtRoot,
+ eveBuildCommand: "pnpm build:eve",
+ nuxtRoot,
+ });
+
+ expect(result.mode).toBe("generated");
+ expect(result.mode === "generated" && result.services.eve?.buildCommand).toBe(
+ "cd '../../..' && export EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY='.eve/vercel-services/eve/.vercel/output' && export EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY='.vercel/output' && pnpm build:eve",
+ );
+ });
+
+ it("resolves relative paths for an eve app in a subdirectory", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ const appRoot = join(nuxtRoot, "agent");
+ await mkdir(appRoot, { recursive: true });
+
+ const result = await ensureEveVercelServicesConfig({ appRoot, nuxtRoot });
+
+ expect(result.mode === "generated" && result.services.eve?.buildCommand).toBe(
+ "cd '../../../agent' && export EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY='../.eve/vercel-services/eve/.vercel/output' && export EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY='../.vercel/output' && node '../node_modules/eve/bin/eve.js' build",
+ );
+ });
+
+ it("reads vercel.json from a linked Vercel project root", async () => {
+ const projectRoot = await createTempNuxtRoot();
+ const nuxtRoot = join(projectRoot, "apps", "web");
+ await mkdir(join(projectRoot, ".vercel"), { recursive: true });
+ await writeFile(join(projectRoot, ".vercel", "project.json"), "{}\n");
+ await mkdir(nuxtRoot, { recursive: true });
+ await writeFile(
+ join(projectRoot, "vercel.json"),
+ `${JSON.stringify({
+ services: {
+ web: { root: "apps/web", framework: "nuxtjs" },
+ eve: { root: "agent", framework: "eve" },
+ },
+ })}\n`,
+ );
+
+ const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+
+ expect(result).toEqual({ mode: "root" });
+ });
+
+ it("generates nothing when vercel.json declares services including eve", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ await writeFile(
+ join(nuxtRoot, "vercel.json"),
+ `${JSON.stringify({
+ services: {
+ web: { root: ".", framework: "nuxtjs" },
+ agent: { root: "agent", framework: "eve" },
+ },
+ })}\n`,
+ );
+
+ const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+
+ expect(result).toEqual({ mode: "root" });
+ expect(await directoryExists(join(nuxtRoot, ".eve", "vercel-services"))).toBe(false);
+ });
+
+ it("accepts the named service array form", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ await writeFile(
+ join(nuxtRoot, "vercel.json"),
+ `${JSON.stringify({
+ services: [
+ { name: "web", root: ".", framework: "nuxtjs" },
+ { name: "eve", root: "agent", framework: "eve" },
+ ],
+ })}\n`,
+ );
+
+ await expect(ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot })).resolves.toEqual({
+ mode: "root",
+ });
+ });
+
+ it("throws when vercel.json services omit the eve service", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ await writeFile(
+ join(nuxtRoot, "vercel.json"),
+ `${JSON.stringify({ services: { web: { root: ".", framework: "nuxtjs" } } })}\n`,
+ );
+
+ await expect(ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot })).rejects.toThrow(
+ /already defines services/,
+ );
+ });
+
+ it("warns and generates when vercel.json only has legacy experimentalServices", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+ await writeFile(
+ join(nuxtRoot, "vercel.json"),
+ `${JSON.stringify({
+ experimentalServices: {
+ web: { entrypoint: ".", framework: "nuxtjs", routePrefix: "/" },
+ eve: { entrypoint: ".", framework: "eve", routePrefix: "/_eve_internal/eve" },
+ },
+ })}\n`,
+ );
+
+ const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+
+ expect(result.mode).toBe("generated");
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining("experimentalServices"));
+ });
+
+ it("prefers stable services over legacy experimentalServices without warning", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+ await writeFile(
+ join(nuxtRoot, "vercel.json"),
+ `${JSON.stringify({
+ experimentalServices: { eve: { entrypoint: ".", framework: "eve", routePrefix: "/x" } },
+ services: { eve: { root: ".", framework: "eve" } },
+ })}\n`,
+ );
+
+ const result = await ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot });
+
+ expect(result).toEqual({ mode: "root" });
+ expect(warn).not.toHaveBeenCalled();
+ });
+
+ it("rejects a malformed vercel.json", async () => {
+ const nuxtRoot = await createTempNuxtRoot();
+ await writeFile(join(nuxtRoot, "vercel.json"), `["not", "an", "object"]\n`);
+
+ await expect(ensureEveVercelServicesConfig({ appRoot: nuxtRoot, nuxtRoot })).rejects.toThrow(
+ /must contain a JSON object/,
+ );
+ });
+});
diff --git a/packages/eve/src/public/nuxt/vercel-services.test.ts b/packages/eve/src/public/nuxt/vercel-services.test.ts
new file mode 100644
index 000000000..6899e513c
--- /dev/null
+++ b/packages/eve/src/public/nuxt/vercel-services.test.ts
@@ -0,0 +1,115 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ createEveServiceRequestPathRoute,
+ createEveServiceRoute,
+ mergeEveVercelConfig,
+ type EnsureEveVercelServicesConfigResult,
+} from "./vercel-services.js";
+
+const GENERATED: Extract<EnsureEveVercelServicesConfigResult, { mode: "generated" }> = {
+ mode: "generated",
+ services: {
+ eve: {
+ buildCommand: "eve build",
+ framework: "eve",
+ routes: [createEveServiceRequestPathRoute()],
+ root: ".eve/vercel-services/eve",
+ },
+ },
+};
+
+describe("createEveServiceRoute", () => {
+ it("routes the eve transport namespace to the eve service", () => {
+ expect(createEveServiceRoute()).toEqual({
+ destination: {
+ service: "eve",
+ type: "service",
+ },
+ src: "^/eve/v1/(.*)$",
+ });
+ });
+
+ it("targets a custom service name", () => {
+ expect(createEveServiceRoute("agent").destination.service).toBe("agent");
+ });
+});
+
+describe("createEveServiceRequestPathRoute", () => {
+ it("pins the request path to the eve transport namespace", () => {
+ expect(createEveServiceRequestPathRoute()).toEqual({
+ src: "^/eve/v1/(.*)$",
+ transforms: [
+ {
+ args: "/eve/v1/$1",
+ op: "set",
+ type: "request.path",
+ },
+ ],
+ });
+ });
+});
+
+describe("mergeEveVercelConfig", () => {
+ it("builds a fresh config when nothing exists", () => {
+ expect(mergeEveVercelConfig(undefined, GENERATED)).toEqual({
+ version: 3,
+ routes: [createEveServiceRoute()],
+ services: GENERATED.services,
+ });
+ });
+
+ it("prepends the service route before user routes", () => {
+ const userRoute = { src: "^/custom/(.*)$", dest: "/other/$1" };
+
+ expect(mergeEveVercelConfig({ routes: [userRoute] }, GENERATED).routes).toEqual([
+ createEveServiceRoute(),
+ userRoute,
+ ]);
+ });
+
+ it("inserts the service route before a user filesystem handle", () => {
+ const before = { src: "^/a$", dest: "/b" };
+ const after = { src: "^/c$", dest: "/d" };
+
+ expect(
+ mergeEveVercelConfig({ routes: [before, { handle: "filesystem" }, after] }, GENERATED).routes,
+ ).toEqual([before, createEveServiceRoute(), { handle: "filesystem" }, after]);
+ });
+
+ it("preserves a user-configured eve service and routes to it", () => {
+ const merged = mergeEveVercelConfig(
+ {
+ services: {
+ agent: { framework: "eve", buildCommand: "pnpm build:agent", root: "agent" },
+ other: { framework: "hono" },
+ },
+ },
+ GENERATED,
+ );
+
+ expect(merged.services).toEqual({
+ agent: {
+ framework: "eve",
+ buildCommand: "pnpm build:agent",
+ root: "agent",
+ routes: [createEveServiceRequestPathRoute()],
+ },
+ other: { framework: "hono" },
+ });
+ expect(merged.routes).toEqual([createEveServiceRoute("agent")]);
+ });
+
+ it("stays idempotent when merged twice", () => {
+ const once = mergeEveVercelConfig(undefined, GENERATED);
+
+ expect(mergeEveVercelConfig(once, GENERATED)).toEqual(once);
+ });
+
+ it("preserves unknown keys and an explicit version", () => {
+ const merged = mergeEveVercelConfig({ version: 2, cleanUrls: true }, GENERATED);
+
+ expect(merged.version).toBe(2);
+ expect(merged.cleanUrls).toBe(true);
+ });
+});
diff --git a/packages/eve/src/public/nuxt/vercel-services.ts b/packages/eve/src/public/nuxt/vercel-services.ts
new file mode 100644
index 000000000..b962e25c0
--- /dev/null
+++ b/packages/eve/src/public/nuxt/vercel-services.ts
@@ -0,0 +1,390 @@
+import { mkdir, readFile } from "node:fs/promises";
+import { dirname, join, relative } from "node:path";
+
+import {
+ EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV,
+ EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV,
+} from "#internal/application/paths.js";
+import { EVE_ROUTE_PREFIX } from "#protocol/routes.js";
+import { resolveEveBinaryPath } from "#shared/resolve-eve-binary.js";
+import { findClosestLinkedVercelDirectory } from "#shared/vercel-output-directory.js";
+
+const VERCEL_JSON_FILE_NAME = "vercel.json";
+const EVE_SERVICE_NAME = "eve";
+const EVE_SERVICE_ROUTE_SRC = `^${EVE_ROUTE_PREFIX}/(.*)$`;
+const EVE_SERVICE_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/$1`;
+const EVE_VERCEL_SERVICES_DIRECTORY = ".eve/vercel-services";
+
+interface VercelRequestPathTransform {
+ readonly args: string;
+ readonly op: "set";
+ readonly type: "request.path";
+}
+
+interface VercelServiceRouteDestination {
+ readonly service?: string;
+ readonly type?: string;
+}
+
+interface VercelRouteConfig {
+ readonly destination?: string | VercelServiceRouteDestination;
+ readonly handle?: string;
+ readonly src?: string;
+ readonly transforms?: readonly VercelRequestPathTransform[];
+ readonly [key: string]: unknown;
+}
+
+interface VercelServiceConfig {
+ readonly framework?: string;
+ readonly routes?: readonly VercelRouteConfig[];
+ readonly [key: string]: unknown;
+}
+
+interface VercelNamedServiceConfig extends VercelServiceConfig {
+ readonly name?: string;
+}
+
+type VercelServicesCollection =
+ | Record<string, VercelServiceConfig>
+ | readonly VercelNamedServiceConfig[];
+
+interface VercelJsonConfig {
+ readonly experimentalServices?: unknown;
+ readonly services?: VercelServicesCollection;
+ readonly [key: string]: unknown;
+}
+
+/**
+ * The top-level Vercel Build Output route that sends eve transport requests to
+ * the generated eve service.
+ */
+export type EveVercelServiceRoute = {
+ readonly destination: {
+ readonly service: string;
+ readonly type: "service";
+ };
+ readonly src: string;
+};
+
+/**
+ * A service-scoped route carrying the `request.path` transform that pins the
+ * path the eve runtime observes to the eve transport namespace.
+ */
+export type EveVercelServiceRequestPathRoute = {
+ readonly src: string;
+ readonly transforms: readonly [VercelRequestPathTransform];
+};
+
+/**
+ * The generated eve service entry written into the Vercel Build Output
+ * `services` record.
+ */
+export type EveVercelGeneratedService = {
+ readonly buildCommand: string;
+ readonly framework: "eve";
+ readonly routes: readonly VercelRouteConfig[];
+ readonly root: string;
+};
+
+/**
+ * Minimal shape of the Nitro Vercel build-output config the module merges the
+ * generated eve service into.
+ */
+export interface NitroVercelBuildConfig {
+ version?: number;
+ routes?: unknown[];
+ services?: Record<string, VercelServiceConfig>;
+ [key: string]: unknown;
+}
+
+/**
+ * Result of {@link ensureEveVercelServicesConfig}: `root` when `vercel.json`
+ * already declares stable services (the user owns routing; nothing is
+ * generated), `generated` with the service record to merge into the Nitro
+ * Vercel build config otherwise.
+ */
+export type EnsureEveVercelServicesConfigResult =
+ | { readonly mode: "root" }
+ | {
+ readonly mode: "generated";
+ readonly services: Record<string, EveVercelGeneratedService>;
+ };
+
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return value !== null && typeof value === "object" && !Array.isArray(value);
+}
+
+function toPosixRelative(from: string, to: string): string {
+ const relativePath = relative(from, to);
+ return relativePath.length === 0 ? "." : relativePath.replaceAll("\\", "/");
+}
+
+function quoteShellArgument(value: string): string {
+ return `'${value.replaceAll("'", "'\\''")}'`;
+}
+
+function isNamedServiceConfigArray(
+ services: VercelServicesCollection,
+): services is readonly VercelNamedServiceConfig[] {
+ return Array.isArray(services);
+}
+
+function createServiceConfigRecord(
+ services: VercelServicesCollection | undefined,
+): Record<string, VercelServiceConfig> {
+ if (services === undefined) {
+ return {};
+ }
+
+ if (isNamedServiceConfigArray(services)) {
+ const record: Record<string, VercelServiceConfig> = {};
+
+ for (const service of services) {
+ if (typeof service.name === "string" && service.name.trim().length > 0) {
+ const { name, ...serviceConfig } = service;
+ record[name] = serviceConfig;
+ }
+ }
+
+ return record;
+ }
+
+ return services;
+}
+
+function normalizeVercelJsonConfig(value: unknown): VercelJsonConfig {
+ if (!isRecord(value)) {
+ throw new Error(`${VERCEL_JSON_FILE_NAME} must contain a JSON object.`);
+ }
+
+ const services = value.services;
+
+ if (
+ services !== undefined &&
+ !isRecord(services) &&
+ !(
+ Array.isArray(services) &&
+ services.every(
+ (service) =>
+ isRecord(service) && typeof service.name === "string" && service.name.trim().length > 0,
+ )
+ )
+ ) {
+ throw new Error(
+ `${VERCEL_JSON_FILE_NAME} services must be a JSON object or named service array.`,
+ );
+ }
+
+ return value as VercelJsonConfig;
+}
+
+async function readVercelJsonConfig(path: string): Promise<VercelJsonConfig> {
+ try {
+ return normalizeVercelJsonConfig(JSON.parse(await readFile(path, "utf8")) as unknown);
+ } catch (error) {
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
+ return {};
+ }
+
+ throw error;
+ }
+}
+
+function findEveService(
+ services: Record<string, VercelServiceConfig>,
+): VercelServiceConfig | undefined {
+ return Object.values(services).find((service) => service.framework === "eve");
+}
+
+function assertRootServicesIncludeEve(services: Record<string, VercelServiceConfig>): void {
+ if (findEveService(services) === undefined) {
+ throw new Error(
+ `${VERCEL_JSON_FILE_NAME} already defines services, so the eve Nuxt module cannot add a generated eve service. Add an eve service (framework "eve") and a rewrite from ${EVE_ROUTE_PREFIX}/(.*) to it in ${VERCEL_JSON_FILE_NAME}, or remove services from ${VERCEL_JSON_FILE_NAME}.`,
+ );
+ }
+}
+
+/**
+ * Build the top-level Build Output route that exposes the eve service on the
+ * eve transport namespace (`/eve/v1/*`).
+ */
+export function createEveServiceRoute(
+ serviceName: string = EVE_SERVICE_NAME,
+): EveVercelServiceRoute {
+ return {
+ destination: {
+ service: serviceName,
+ type: "service",
+ },
+ src: EVE_SERVICE_ROUTE_SRC,
+ };
+}
+
+/**
+ * Build the eve service's own route that sets `request.path` so the eve
+ * runtime observes the transport path regardless of how the platform routed
+ * the request into the service.
+ */
+export function createEveServiceRequestPathRoute(): EveVercelServiceRequestPathRoute {
+ return {
+ src: EVE_SERVICE_ROUTE_SRC,
+ transforms: [
+ {
+ args: EVE_SERVICE_ROUTE_PATH,
+ op: "set",
+ type: "request.path",
+ },
+ ],
+ };
+}
+
+function isEveServiceRoute(route: VercelRouteConfig, serviceName: string): boolean {
+ const destination = route.destination;
+
+ return (
+ route.src === EVE_SERVICE_ROUTE_SRC &&
+ isRecord(destination) &&
+ destination.type === "service" &&
+ destination.service === serviceName
+ );
+}
+
+function insertEveServiceRoute(routes: readonly unknown[], serviceName: string): unknown[] {
+ const routesWithoutEveRoute = routes.filter(
+ (route) => !(isRecord(route) && isEveServiceRoute(route, serviceName)),
+ );
+ const filesystemRouteIndex = routesWithoutEveRoute.findIndex(
+ (route) => isRecord(route) && route.handle === "filesystem",
+ );
+
+ if (filesystemRouteIndex === -1) {
+ return [createEveServiceRoute(serviceName), ...routesWithoutEveRoute];
+ }
+
+ return [
+ ...routesWithoutEveRoute.slice(0, filesystemRouteIndex),
+ createEveServiceRoute(serviceName),
+ ...routesWithoutEveRoute.slice(filesystemRouteIndex),
+ ];
+}
+
+function insertEveServiceRequestPathRoute(
+ routes: readonly VercelRouteConfig[] | undefined,
+): readonly VercelRouteConfig[] {
+ const routesWithoutGeneratedRoute = (routes ?? []).filter(
+ (route) => route.src !== EVE_SERVICE_ROUTE_SRC,
+ );
+
+ return [createEveServiceRequestPathRoute(), ...routesWithoutGeneratedRoute];
+}
+
+function createGeneratedServiceBuild(input: {
+ readonly appRoot: string;
+ readonly eveBuildCommand?: string;
+ readonly nuxtRoot: string;
+}): { readonly buildCommand: string; readonly root: string; readonly rootDirectory: string } {
+ const rootDirectory = join(input.nuxtRoot, EVE_VERCEL_SERVICES_DIRECTORY, EVE_SERVICE_NAME);
+ const outputDirectory = join(rootDirectory, ".vercel", "output");
+ const hostOutputDirectory = join(input.nuxtRoot, ".vercel", "output");
+ const workingDirectory = toPosixRelative(rootDirectory, input.appRoot);
+ const configuredOutputDirectory = toPosixRelative(input.appRoot, outputDirectory);
+ const configuredHostOutputDirectory = toPosixRelative(input.appRoot, hostOutputDirectory);
+ const buildCommand =
+ input.eveBuildCommand ??
+ `node ${quoteShellArgument(toPosixRelative(input.appRoot, resolveEveBinaryPath(input.nuxtRoot)))} build`;
+
+ return {
+ buildCommand: `cd ${quoteShellArgument(workingDirectory)} && export ${EVE_INTERNAL_BUILD_OUTPUT_DIRECTORY_ENV}=${quoteShellArgument(configuredOutputDirectory)} && export ${EVE_INTERNAL_HOST_BUILD_OUTPUT_DIRECTORY_ENV}=${quoteShellArgument(configuredHostOutputDirectory)} && ${buildCommand}`,
+ root: toPosixRelative(input.nuxtRoot, rootDirectory),
+ rootDirectory,
+ };
+}
+
+/**
+ * Resolve the stable Vercel services configuration for a Nuxt + eve
+ * deployment.
+ *
+ * When `vercel.json` (looked up from the linked Vercel project root, falling
+ * back to the Nuxt root) already declares stable `services`, it must include
+ * an eve service and the module generates nothing. Otherwise this prepares a
+ * generated eve service — creating its isolated build root under
+ * `.eve/vercel-services/eve` so the eve build output cannot collide with the
+ * Nuxt Build Output — and returns the service record plus the public service
+ * route for the caller to merge into the Nitro Vercel build config. A legacy
+ * `experimentalServices` field is ignored with a migration warning: Vercel no
+ * longer routes it.
+ */
+export async function ensureEveVercelServicesConfig(input: {
+ readonly appRoot: string;
+ readonly eveBuildCommand?: string;
+ readonly nuxtRoot: string;
+}): Promise<EnsureEveVercelServicesConfigResult> {
+ const vercelDirectory = await findClosestLinkedVercelDirectory(input.nuxtRoot);
+ const projectRoot = vercelDirectory === undefined ? input.nuxtRoot : dirname(vercelDirectory);
+ const rootVercelConfig = await readVercelJsonConfig(join(projectRoot, VERCEL_JSON_FILE_NAME));
+ const rootServices = createServiceConfigRecord(rootVercelConfig.services);
+
+ if (Object.keys(rootServices).length > 0) {
+ assertRootServicesIncludeEve(rootServices);
+ return { mode: "root" };
+ }
+
+ if (rootVercelConfig.experimentalServices !== undefined) {
+ console.warn(
+ `[eve] ${VERCEL_JSON_FILE_NAME} defines experimentalServices, which Vercel no longer routes. The eve Nuxt module now generates the stable services config automatically — remove experimentalServices from ${VERCEL_JSON_FILE_NAME}.`,
+ );
+ }
+
+ const generatedServiceBuild = createGeneratedServiceBuild(input);
+ await mkdir(generatedServiceBuild.rootDirectory, { recursive: true });
+
+ return {
+ mode: "generated",
+ services: {
+ [EVE_SERVICE_NAME]: {
+ buildCommand: generatedServiceBuild.buildCommand,
+ framework: "eve",
+ routes: [createEveServiceRequestPathRoute()],
+ root: generatedServiceBuild.root,
+ },
+ },
+ };
+}
+
+/**
+ * Merge the generated eve service and its public route into a Nitro Vercel
+ * build config (`nitro.vercel.config`).
+ *
+ * The service route is inserted before an existing `handle: "filesystem"`
+ * route, or prepended when none exists — Nitro appends its own generated
+ * routes (including the filesystem handle) after this config's routes, so the
+ * eve route always resolves before the Nuxt app's filesystem routing. An eve
+ * service already configured by the user is preserved and only gains the
+ * `request.path` route; everything else passes through untouched.
+ */
+export function mergeEveVercelConfig(
+ existing: NitroVercelBuildConfig | undefined,
+ generated: Extract<EnsureEveVercelServicesConfigResult, { mode: "generated" }>,
+): NitroVercelBuildConfig {
+ const existingServices = existing?.services ?? {};
+ const configuredEveEntry = Object.entries(existingServices).find(
+ ([name, service]) => name === EVE_SERVICE_NAME || service.framework === "eve",
+ );
+ const serviceName = configuredEveEntry?.[0] ?? EVE_SERVICE_NAME;
+ const services = configuredEveEntry
+ ? {
+ ...existingServices,
+ [serviceName]: {
+ ...configuredEveEntry[1],
+ routes: insertEveServiceRequestPathRoute(configuredEveEntry[1].routes),
+ },
+ }
+ : { ...existingServices, ...generated.services };
+
+ return {
+ version: 3,
+ ...existing,
+ routes: insertEveServiceRoute(existing?.routes ?? [], serviceName),
+ services,
+ };
+}
diff --git a/packages/eve/src/public/next/resolve-eve-binary.integration.test.ts b/packages/eve/src/shared/resolve-eve-binary.integration.test.ts
similarity index 100%
rename from packages/eve/src/public/next/resolve-eve-binary.integration.test.ts
rename to packages/eve/src/shared/resolve-eve-binary.integration.test.ts
diff --git a/packages/eve/src/public/next/resolve-eve-binary.ts b/packages/eve/src/shared/resolve-eve-binary.ts
similarity index 79%
rename from packages/eve/src/public/next/resolve-eve-binary.ts
rename to packages/eve/src/shared/resolve-eve-binary.ts
index 65258edd8..e4014ee5e 100644
--- a/packages/eve/src/public/next/resolve-eve-binary.ts
+++ b/packages/eve/src/shared/resolve-eve-binary.ts
@@ -12,11 +12,11 @@ import { dirname, join } from "node:path";
* derive the bin path from the package root. Falls back to the conventional
* app-local path when eve cannot be resolved (e.g. before install).
*/
-export function resolveEveBinaryPath(nextRoot: string): string {
+export function resolveEveBinaryPath(appRoot: string): string {
try {
- const require = createRequire(join(nextRoot, "package.json"));
+ const require = createRequire(join(appRoot, "package.json"));
return join(dirname(require.resolve("eve/package.json")), "bin", "eve.js");
} catch {
- return join(nextRoot, "node_modules", "eve", "bin", "eve.js");
+ return join(appRoot, "node_modules", "eve", "bin", "eve.js");
}
}
diff --git a/packages/eve/test/scenarios/framework-nuxt-build.scenario.test.ts b/packages/eve/test/scenarios/framework-nuxt-build.scenario.test.ts
new file mode 100644
index 000000000..e4d6ab0a4
--- /dev/null
+++ b/packages/eve/test/scenarios/framework-nuxt-build.scenario.test.ts
@@ -0,0 +1,112 @@
+import { readFile } from "node:fs/promises";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+import { describe, expect, it } from "vitest";
+
+import { createNuxtEveServiceDescriptor } from "../../src/internal/testing/scenario-apps/nuxt-eve-service.js";
+import { useScenarioApp } from "../../src/internal/testing/scenario-app.js";
+import { runPnpmCommand } from "../../src/internal/testing/run-pnpm-command.js";
+
+const REPO_ROOT = fileURLToPath(new URL("../../../..", import.meta.url));
+const scenarioApp = useScenarioApp();
+
+const NUXT_EVE_SERVICE_DESCRIPTOR = createNuxtEveServiceDescriptor({
+ installDependencies: true,
+});
+
+async function readVercelOutputConfig(outputRoot: string): Promise<{
+ readonly routes: readonly unknown[];
+ readonly services: Record<string, unknown>;
+}> {
+ const config: unknown = JSON.parse(await readFile(join(outputRoot, "config.json"), "utf8"));
+
+ if (
+ typeof config !== "object" ||
+ config === null ||
+ !("routes" in config) ||
+ !Array.isArray(config.routes)
+ ) {
+ throw new Error("Expected Vercel Build Output config.json to contain a routes array.");
+ }
+
+ const services =
+ "services" in config && typeof config.services === "object" && config.services !== null
+ ? (config.services as Record<string, unknown>)
+ : {};
+
+ return { routes: config.routes, services };
+}
+
+function isEveServiceRoute(route: unknown): boolean {
+ return (
+ typeof route === "object" &&
+ route !== null &&
+ "src" in route &&
+ route.src === "^/eve/v1/(.*)$" &&
+ "destination" in route
+ );
+}
+
+function isFilesystemHandle(route: unknown): boolean {
+ return (
+ typeof route === "object" &&
+ route !== null &&
+ "handle" in route &&
+ route.handle === "filesystem"
+ );
+}
+
+describe("framework-nuxt build", () => {
+ it("builds the Nuxt framework fixture after regenerating eve dist", async () => {
+ await runPnpmCommand({
+ args: ["--filter", "framework-nuxt", "build"],
+ cwd: REPO_ROOT,
+ });
+ }, 300_000);
+
+ it("emits the eve service and route into the Vercel Build Output", async () => {
+ const app = await scenarioApp(NUXT_EVE_SERVICE_DESCRIPTOR);
+
+ // Build the Nuxt app directly with the env a real Vercel build container
+ // always provides. `VERCEL` triggers both Nitro's Vercel preset (via
+ // std-env provider detection) and the eve module's service generation;
+ // `NITRO_PRESET` pins the preset so the assertion does not depend on
+ // detection heuristics. `vercel build` is intentionally not used here: run
+ // unauthenticated it strips these system env vars, so Nitro would fall back
+ // to the node-server preset and emit no Build Output. Vercel's own
+ // assembly of the generated service is covered by the Next.js scenario.
+ await runPnpmCommand({
+ args: ["exec", "nuxt", "build"],
+ cwd: app.appRoot,
+ env: {
+ ...process.env,
+ NITRO_PRESET: "vercel",
+ VERCEL: "1",
+ VERCEL_ENV: "production",
+ },
+ });
+
+ const { routes, services } = await readVercelOutputConfig(
+ join(app.appRoot, ".vercel", "output"),
+ );
+ const eveRouteIndex = routes.findIndex(isEveServiceRoute);
+ const filesystemIndex = routes.findIndex(isFilesystemHandle);
+
+ expect(routes[eveRouteIndex]).toEqual(
+ expect.objectContaining({
+ destination: { service: "eve", type: "service" },
+ src: "^/eve/v1/(.*)$",
+ }),
+ );
+ if (filesystemIndex !== -1) {
+ expect(eveRouteIndex).toBeLessThan(filesystemIndex);
+ }
+ expect(services.eve).toEqual(
+ expect.objectContaining({
+ framework: "eve",
+ root: ".eve/vercel-services/eve",
+ }),
+ );
+ }, 300_000);
+});