# Vite ChatGPT Agent An AI chat and research assistant built with Vite, TanStack Start, Hono, the AI SDK and OpenRouter: streaming responses, model selection, optional Firecrawl web research, file attachments, and conversations saved in IndexedDB. Ported from `nextjs-templates/nextjs-chatgpt`. Runs in the nodesandbox runtime: `npm install` → `npm run dev` → port 3000. ## Getting started ```sh cp .env.example .env.local # set OPENROUTER_API_KEY corepack enable # uses the Yarn 4 pinned in package.json yarn install yarn dev # http://localhost:3000 ``` | Script | What it does | | ---------------- | --------------------------------------------------------- | | `yarn dev` | Vite dev server with SSR | | `yarn build` | Production build; Nitro packages the server for the host | | `yarn start` | Run the Node build from `.output/` | | `yarn typecheck` | `tsc` | | `yarn test` | Streaming tests against the real API handler (no network) | ## Environment `OPENROUTER_API_KEY`, `OPENROUTER_MODEL` and `FIRECRAWL_API_KEY` are server-only (no `VITE_` prefix), so they never reach client JavaScript. `vite.config.mjs` loads `.env` / `.env.local` into `process.env` in dev; on Vercel set them in the project settings. ## Deploying to Vercel Push and deploy — no dashboard settings. `vercel.json` selects the TanStack Start preset and installs with Yarn 4 via Corepack; Nitro writes `.vercel/output/` during `vite build` with a 300s function duration for long agent runs. ## nodesandbox compatibility The sandbox runs Vite's native tools as WebAssembly (`NAPI_RS_FORCE_WASI`), and its installer resolves from `package.json` ranges rather than `yarn.lock`. The toolchain versions match `vite-shopify-storefront`: - `vite` is pinned to **8.3.2** (rolldown 1.2.x WASI binding). - WASI bindings (`@rolldown/binding-wasm32-wasi`, `@tailwindcss/oxide-wasm32-wasi`) are **not** listed: the runtime installs each package's `*-wasm32-wasi` optional dependency itself, and npm on other hosts rejects them. - `@vitejs/plugin-react` (6.0.0) and Tailwind (4.3.1) match the harness samples. - Nitro (the hosting adapter) only loads for `vite build`, never in `vite dev`. ## Layout ``` src/ server.ts Start's server entry: Hono routes /api/*, the rest goes to Start server/ app.ts Hono API chat.ts POST /api/chat — streams the agent's reply chat.functions.ts server function for the page's server-only settings routes/ File routes (__root.tsx is the document shell, index.tsx the chat) components/ Chat UI, AI Elements and shadcn/ui components services/ Model, instructions, Firecrawl tools, IndexedDB chat store lib/openrouter.ts Supported models ```