eve-chat-template-eve
Work safely on Eve-specific internals in the Eve chat template. Use when changing the Eve agent, withEve routes, eveChannel auth, useEveAgent, ClientSession/SessionState, persisted event logs, stream/resume behavior, connection authorization, Vercel Connect MCP connections, local Eve tools, or upstream Eve API assumptions.
- License 许可
- Apache-2.0
- 所属仓库
- vercel/eve
- 最近更新
- 2026-11-15
- Stars
- ★ 5.9k
- Forks
- 656
01 前言 Front Matter
- name
- eve-chat-template-eve
- description
- Work safely on Eve-specific internals in the Eve chat template. Use when changing the Eve agent, withEve routes, eveChannel auth, useEveAgent, ClientSession/SessionState, persisted event logs, stream/resume behavior, connection authorization, Vercel Connect MCP connections, local Eve tools, or upstream Eve API assumptions.
02 资源文件 1
- 参考文档agents/openai.yaml254 B
03 SKILL.md 正文
Eve Template Runtime
Overview
Use this skill to preserve the Eve protocol and durable-session invariants while changing the chat template.
First Pass
- Read
AGENTS.mdfirst. It requires reading the relevant guide undernode_modules/eve/docs/before writing code. - Read
docs/how-the-chatbot-works.mdfor architecture changes anddocs/setup-and-deploy.mdfor setup, auth, storage, or deployment changes. - Search with
rg "useEveAgent|ClientSession|SessionState|content.delta|interaction.opened|eveSession|chat_event|streamIndex|continuationToken|defineMcpClientConnection|defineTool". - Keep Eve runtime code separate from product shell code:
agent/defines agent behavior;app/_components/agent-chat.tsxbridges Eve to the web UI;lib/db/*persists app state.
Core Model
- Treat an app chat row and an Eve session as different things. The app row owns URL, title, user ownership,
pendingUserMessage, storedeveSession, and event rows. Eve owns the remote durable session and stream cursor. - Do not confuse
chat_event.eventIndexwithSessionState.streamIndex. The first orders local Postgres rows; the second resumes/eve/v1/session/:sessionId/stream. - Preserve same-origin Eve routes mounted by
withEve(nextConfig):POST /eve/v1/session,POST /eve/v1/session/:sessionId, andGET /eve/v1/session/:sessionId/stream?startIndex=n. - Keep
betterAuthEveAuth,localDev(), andvercelOidc()in the Eve channel unless deliberately changing local, browser, or Vercel auth behavior.
Persistence And Resume
- Persist
SessionStateimmediately after Eve returnssessionIdandcontinuationToken; do not wait for the stream to finish. - Persist each stream event as it arrives, then use the final snapshot as the canonical cleanup pass.
- Upsert events by local
eventIndex; on final snapshot, delete rows beyond the final event length. - Keep
pendingUserMessagefor interruption recovery. Mark it before sending, consume it once in the session page, hide it after a settled event, and clear it after snapshot or authorization skip. - When preserving initial events, merge by prefix and compare JSON structurally. Do not rely on
JSON.stringifykey order. - Reset per-chat refs on route changes: event index, known initial events, stream events, resumed events, local events, pending bubbles, resume-started flags, and finalize timers.
Streaming
useEveAgentreduces Eve events into renderable messages; the template wraps it with a customClientSessionto persist and resume sessions.- Treat
content.delta.data.deltaas the new text for itspartId. Treat reduced message text and rendered parts as cumulative;content.completedcarries a part's whole value. - Read the stream as NDJSON. Buffering until newline is normal parsing, not app-level response buffering.
- Consider a turn settled on an event
endsTurnfromeve/clientaccepts:turn.settled,session.ended, or aturn.pausedawaiting a person. Treat a sign-ininteraction.opened(request.kind: "sign-in") as a blocked state for normal text input. - Treat a
turn.pausedawaiting only calls as progress, not a settled turn: the turn waits on its tasks and resumes withturn.resumedfor the sameturnId. Keep following the stream until one of the settling events above. - On disconnect, reconnect from the next unread remote stream index. On refresh mid-turn, resume from saved
activeChat.sessionand layer resumed events until the final snapshot catches up.
Connections And Tools
- Define local tools in
agent/tools/<snake_case>.tswithdefineTool(...). Tool filenames become runtime tool names, so keep them ASCII snake_case. - Define Vercel Connect-backed MCP connections in
agent/connections/<name>.tswithdefineMcpClientConnection(...)andconnect(process.env.ENV_NAME ?? "local-name"). - Treat composer connection toggles as per-turn intent, not connector provisioning or OAuth state.
- Do not parse assistant text for auth requirements. Use sign-in
interaction.openedandinteraction.settledevents. - Implement Skip as a structured outcome: stop the stream, synthesize a declined
interaction.settledplus a cancelledturn.settled, apply those local events to the chat, persist them, and clear pending input. The chat's next message starts a new session.
Upstream Signals
- Prefer upstreaming generic Eve lifecycle needs:
onSessionStarted(session), hook-level resume APIs, durable event persistence adapters, authorization continuation helpers, structured connection policy, and stream debug helpers. - Keep template-specific concerns in the template: Better Auth UX, Neon/Drizzle schema, Upstash limits, sidebar pagination, Notion UI toggles, and setup docs.
- Do not split server events just to make coarse provider deltas look token-level. Preserve wire semantics and smooth only at the UI layer when needed.
Verification
- Run
pnpm typecheckfor protocol/type changes andpnpm buildbefore opening a PR that touches runtime, routes, or docs examples. - Manually verify first message, follow-up send, refresh during a response, authorization Connect/Skip, disabled input while auth is pending, and Notion enabled/disabled turns when those flows are touched.
04 同仓库更多 Skills
writing-quality
The review rubric: writing-quality rules and reference lists for judging a content draft, covering AI-sounding phrasing, bloated wording, structure, and web-content specs. Load at the start of every review.
writing-quality
Writing-quality guardrails for any prose the agent drafts or edits: blog posts, page copy, Notion drafts, release notes, marketing text. Use this skill whenever writing or revising content meant for humans to read, to keep the prose natural, plain, and free of AI-sounding phrasing. Not needed for code, queries, or structural CMS work.
seo-aeo-best-practices
SEO and AEO best practices for metadata, Open Graph, sitemaps, robots.txt, hreflang, JSON-LD structured data, EEAT, and content optimized for search engines and AI answer surfaces. Use this skill when implementing page SEO, technical SEO, schema markup, international SEO, AI-overview readiness, or improving content for Google, ChatGPT, Perplexity, and similar assistants.
sanity-best-practices
Sanity development best practices for schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, Blueprints, and framework integrations such as Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, Hydrogen, and the App SDK. Use this skill whenever working with Sanity schemas, defineType or defineField, GROQ or defineQuery, content modeling, Presentation or preview setups, Sanity-powered frontend integrations, Sanity Functions, documentEventHandler, defineDocumentFunction, defineMediaLibraryAssetFunction, @sanity/functions, @sanity/blueprints, sanity.blueprint.ts, event-driven content automation, or when reviewing and fixing a Sanity codebase.
portable-text-serialization
Render and serialize Portable Text to React, Svelte, Vue, Astro, HTML, Markdown, and plain text. Use when implementing Portable Text rendering in any frontend framework, building custom serializers for non-standard block types, converting Portable Text to HTML strings server-side, converting Portable Text to Markdown, extracting plain text from Portable Text, or troubleshooting rendering issues with marks, blocks, lists, or custom types.
portable-text-conversion
Convert HTML and Markdown content into Portable Text blocks for Sanity. Use when migrating content from legacy CMSs, importing HTML or Markdown into Sanity, building content pipelines that ingest external content, converting rich text between formats, or programmatically creating Portable Text documents. Covers @portabletext/markdown (markdownToPortableText), @portabletext/block-tools (htmlToBlocks), custom deserializers, and the Portable Text specification for manual block construction.