UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

100 lines (73 loc) 3.59 kB
--- title: "Nuxt" description: "Run an eve agent and a Nuxt app as one project with the eve/nuxt module." --- The `eve/nuxt` module runs a Nuxt frontend and an eve agent as a single project from one dev server and one Vercel deploy. The auto-imported [`useEveAgent`](./use-eve-agent-vue) composable finds the mounted routes on its own, so there's no CORS to configure and no URL env vars to keep in sync. ## Prerequisites - The `eve` package installed in your project (`npm install eve@latest`). - An existing eve agent directory. If you don't have one, start from [Getting started](../../getting-started). - A Nuxt app to mount the agent in. ## Register the module ```ts title="nuxt.config.ts" export default defineNuxtConfig({ modules: ["eve/nuxt"], }); ``` The module looks for an `agent/` folder in the Nuxt project root. Pass `eveRoot` when the agent lives elsewhere: ```ts export default defineNuxtConfig({ modules: ["eve/nuxt"], eve: { eveRoot: "../my-agent", }, }); ``` The `eve` key accepts only two options, `eveRoot` and `eveBuildCommand`. ## Call the composable `useEveAgent` (`eve/vue`) is auto-imported, so a component calls it without an explicit import and without naming a host: ```vue <script setup lang="ts"> const { status, send } = useEveAgent(); const isBusy = computed(() => status.value === "submitted" || status.value === "streaming"); const message = ref(""); async function handleSubmit() { const text = message.value.trim(); if (!text || isBusy.value) return; message.value = ""; await send({ message: text }); } </script> <template> <form @submit.prevent="handleSubmit"> <input v-model="message" :disabled="isBusy" /> <button type="submit" :disabled="isBusy">Send</button> </form> </template> ``` The default eve channel is fail-closed. With no `agent/channels/eve.ts` authored, eve registers `eveChannel({ auth: [localDev(), vercelOidc()] })`: `localDev()` opens the routes on localhost, `vercelOidc()` admits Vercel OIDC callers in production, and everything else gets a `401`. To run your own auth policy, add `agent/channels/eve.ts`: ```ts title="agent/channels/eve.ts" import { eveChannel } from "eve/channels/eve"; import { localDev, vercelOidc } from "eve/channels/auth"; export default eveChannel({ auth: [localDev(), vercelOidc()] }); ``` For a public demo, use `none()` (also from `eve/channels/auth`) to skip authentication. See [Channels](../../channels/overview) and [Auth & route protection](../auth-and-route-protection). ## 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: ```ts export default defineNuxtConfig({ modules: ["eve/nuxt"], eve: { eveBuildCommand: "npm run build:eve", }, }); ``` - **Non-Vercel hosts.** Point Nuxt at a separate eve origin with `EVE_NUXT_PRODUCTION_ORIGIN`. To override the local port (default `4274`), use `EVE_NUXT_PRODUCTION_PORT`: ```bash EVE_NUXT_PRODUCTION_ORIGIN=https://agent.example.com npm run build EVE_NUXT_PRODUCTION_PORT=5000 npm run build && npm run preview ``` ## What to read next - [`useEveAgent` (Vue)](./use-eve-agent-vue): the composable API - [Auth & route protection](../auth-and-route-protection) - [Deployment](../deployment)