chat / adapter-web
AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub
Guidance for coding agents working inside the Web adapter package. The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls. @chat-adapter/web lets a Chat SDK bot serve a browser chat UI alongside Slack, Teams, Discord, and the rest. The same handlers fire for every platform — the Web adapter just speaks the @ai-sdk/react useChat UI message stream protocol so a <Chat> React component can drop in…
Trending
Quiet since March.thin dataabout the whole repository
Who's talking about vercel/chat
- @camilleroux.com“Un SDK TypeScript unifié pour créer des chatbots qui fonctionnent sur Slack, Teams, Google Chat, Discord, …”Bluesky · Mar 3, 2026 · 3 likes
- @technews4869.bsky.social“github.com/vercel/chat GitHub - vercel/chat: A unified TypeScript SDK for building chat bots across Slack, …”Bluesky · Mar 7, 2026 · 1 likes
- @yug1224.com“チャットアプリ開発に使える統一SDKを提供するツールらしい 様々なプラットフォーム対応で便利そうだな yug1224 starred vercel/chat https://github.com/vercel/chat”Bluesky · Mar 7, 2026 · 1 likes
- @news.humancoders.com“Vercel lance Chat SDK : un SDK TypeScript unifié pour créer des bots multi-plateformes”Bluesky · Mar 5, 2026 · 1 likes
- @github-trending-js.bsky.social“🔥 Hot Repo! 🔥 (100+ new stars) 📦 vercel / chat ⭐ 871 (+121) 🗒 TypeScript A unified TypeScript SDK for …”Bluesky · Feb 27, 2026 · 1 likes
The biggest 5 of 5 mentions linking to the repository that our crawl found. Each line is their own headline.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- apps/docs/AGENTS.mdAGENTS.md
- chat-sdkAGENTS.md
- packages/adapter-discord/AGENTS.mdAGENTS.md
- packages/adapter-gchat/AGENTS.mdAGENTS.md
- packages/adapter-github/AGENTS.mdAGENTS.md
- packages/adapter-instagram/AGENTS.mdAGENTS.md
- packages/adapter-linear/AGENTS.mdAGENTS.md
- packages/adapter-messenger/AGENTS.mdAGENTS.md
- packages/adapter-notion/AGENTS.mdAGENTS.md
- packages/adapter-slack/AGENTS.mdAGENTS.md
- packages/adapter-teams/AGENTS.mdAGENTS.md
- packages/adapter-telegram/AGENTS.mdAGENTS.md
- packages/adapter-whatsapp/AGENTS.mdAGENTS.md
- packages/chat/src/adapters/AGENTS.mdAGENTS.md
- packages/create-chat-sdk/AGENTS.mdAGENTS.md
- packages/create-chat-sdk/_template/AGENTS.mdAGENTS.md
- packages/state-ioredis/AGENTS.mdAGENTS.md
- packages/state-memory/AGENTS.mdAGENTS.md
- packages/state-pg/AGENTS.mdAGENTS.md
- packages/state-redis/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- packages/adapter-discord/CLAUDE.mdCLAUDE.md
- packages/adapter-gchat/CLAUDE.mdCLAUDE.md
- packages/adapter-github/CLAUDE.mdCLAUDE.md
- packages/adapter-linear/CLAUDE.mdCLAUDE.md
- packages/adapter-messenger/CLAUDE.mdCLAUDE.md
- packages/adapter-slack/CLAUDE.mdCLAUDE.md
- packages/adapter-teams/CLAUDE.mdCLAUDE.md
- packages/adapter-telegram/CLAUDE.mdCLAUDE.md
- packages/adapter-web/CLAUDE.mdCLAUDE.md
- packages/adapter-whatsapp/CLAUDE.mdCLAUDE.md
- packages/create-chat-sdk/CLAUDE.mdCLAUDE.md
- packages/create-chat-sdk/_template/CLAUDE.mdCLAUDE.md
- packages/state-ioredis/CLAUDE.mdCLAUDE.md
- packages/state-memory/CLAUDE.mdCLAUDE.md
- packages/state-pg/CLAUDE.mdCLAUDE.md
- packages/state-redis/CLAUDE.mdCLAUDE.md
- add-adapterSkill
- technical-writerSkill
- chat-sdkSkill
- chat-sdkSkill
- chat-sdkSkill
- chat-sdkSkill
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 121
Only the latest user message is consumed (the rest of the array is untrusted client state), and tool parts are stripped from it so a …
- Very specific: line 229
Aborts on unmount: When the user navigates away, the browser closes the SSE connection.
- Distinctive: line 233
Use it instead of mutable adapter state for anything request- scoped.
- Distinctive: line 250
Use named exports throughout.
- Very specific: line 251
Keep server code free of React imports.
- Very specific: line 258
Avoid mutable adapter state — use AsyncLocalStorage via als.ts for request-scoped values.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — @chat-adapter/web
Guidance for coding agents working inside the Web adapter package. The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls.
Overview
@chat-adapter/web lets a Chat SDK bot serve a browser chat UI
alongside Slack, Teams, Discord, and the rest. The same handlers fire
for every platform — the Web adapter just speaks the
@ai-sdk/react useChat UI message stream protocol so a <Chat>
React component can drop in next to the bot's existing webhooks.
What it covers:
- HTTP endpoint at
/api/chat(or wherever the adapter is mounted). Handles POST requests carrying theuseChatrequest body and responds with an SSE UI message stream. - Native streaming via the SSE protocol — no edit loop, no rate
limiting, abort propagation through
request.signalto the handler. - DM-style routing — every browser session is treated as a DM thread scoped to the resolved user.
- Optional persisted message history through the configured state
adapter (so handlers can use
thread.messagesacross requests). - Thin React wrapper at
@chat-adapter/web/reactthat preconfigures@ai-sdk/react'suseChatwith aDefaultChatTransport.
Directory layout
packages/adapter-web/
├── src/
│ ├── index.ts # createWebAdapter factory + public types
│ ├── adapter.ts # WebAdapter class implementation
│ ├── als.ts # AsyncLocalStorage scope for the active request
│ ├── format-converter.ts # WebFormatConverter (mdast ↔ markdown)
│ ├── index.test.ts
│ ├── types.ts # WebUser, request shape, postable types
│ └── react/
│ └── index.ts # useChat wrapper for the React entry point
├── package.json
├── tsconfig.json
├── tsup.config.ts # builds two entry points (server + react)
├── vitest.config.ts
└── README.mdThe react/ subentry is published as @chat-adapter/web/react. Keep
the server entry free of any React imports — only react/index.ts
should reference @ai-sdk/react.
Build, test, typecheck
pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean
# from repo root
pnpm --filter @chat-adapter/web build
pnpm --filter @chat-adapter/web testTests are pure unit tests — there are no replay fixtures because the
Web adapter has no platform side. Integration coverage comes via
examples/nextjs-chat.
Public surface
Server entry (@chat-adapter/web → src/index.ts):
createWebAdapter(config)— primary factory. Required:userName(bot name) andgetUser(request)resolver. Optional:persistMessageHistory,threadIdFor,logger.WebAdapterclass — implementsAdapter<WebThreadId, unknown>. Public methods:handleWebhook(mounted at/api/chatetc.),postMessage,editMessage,deleteMessage,addReaction,removeReaction,startTyping,fetchThread,fetchMessages,fetchSingleMessage,openDM.- Configuration:
WebAdapterConfig,WebUser,WebThreadId. encodeThreadId,decodeThreadId,isDM.
React entry (@chat-adapter/web/react → src/react/index.ts):
useChat(options)— wraps@ai-sdk/react'suseChatwith aDefaultChatTransportpreconfigured to talk to the Web adapter endpoint.
Thread ID format
web:{user.id}:{conversationId}user.id comes from getUser(request). conversationId is the
id field useChat sends in its request body — when the client
supplies one (useChat({ id: "support-chat" })), it persists across
reloads; otherwise a fresh id is generated per request.
threadIdFor overrides the default if you want a different scheme
(e.g. one thread per user). Ids returned by getUser that contain
: are rejected with HTTP 400 — normalize them inside getUser
(base64-encode if your auth provider emits provider:sub-style ids).
isDM(threadId) always returns true — the Web adapter has no
group concept.
Webhook flow
The adapter's handleWebhook(request, options) is mounted at the
chat route (typically /api/chat). It:
- Calls
getUser(request). Returningnullproduces HTTP 401. - Decodes the
useChatrequest body to extractidandmessages[]. Only the latest user message is consumed (the rest of the array is untrusted client state), and tool parts are stripped from it so a browser can't inject forged tool-call or approval state. Text, file, anddata-*parts pass through. - Resolves the thread id via
threadIdFor(defaultweb:{user.id}:{conversationId}). - Routes to
chat.processMessage, which persists the message into the configured state adapter whenpersistMessageHistory: true. - Streams the handler's
thread.postoutput back to the browser as SSE chunks following the AI message stream protocol.
request.signal is plumbed through als.ts so calling stop() from
the React side aborts the handler's iterator.
Authentication
getUser is the security boundary. Every request comes from a
browser with no Slack-style platform signature, so the adapter
delegates the identity check to the user-supplied function.
Patterns to support:
- NextAuth —
getServerSession(authOptions). - Clerk —
auth()+sessionClaims. - Custom JWT — verify the bearer token in
Authorization. - Cookies — read a session cookie and look it up against your store.
Returning null produces 401; returning a WebUser with id set
unlocks the rest of the request lifecycle.
Streaming
thread.post accepts an AsyncIterable<string | StreamChunk> and
pumps deltas straight onto the SSE response. There's no edit loop
and no rate limiting because the protocol is duplex by design — the
browser is the only consumer.
This pairs neatly with streamText from the AI SDK:
import { streamText } from "ai";
bot.onDirectMessage(async (thread, message) => {
const result = streamText({ model, prompt: message.text });
await thread.post(result.textStream);
});The adapter honours request.signal, so the iterator is short-
circuited as soon as the browser disconnects.
Format conversion
WebFormatConverter (in format-converter.ts) maps mdast to plain
markdown — the browser renderer (typically streamdown or
react-markdown) handles the actual rendering.
- mdast → markdown — straightforward; emits CommonMark plus GFM extensions (tables, strikethrough, task lists).
- markdown → mdast — relies on
mdast-util-from-markdownfrom the corechatpackage.
renderPostable is identical to the markdown emitter for this
adapter — there's no platform-specific rewriting.
Persistence
persistMessageHistory defaults to true. The Web adapter has no
platform-side history API, so the only way for handlers to see prior
turns via thread.messages is through the state adapter's cache.
The request body's messages[] is not an alternative source: the
adapter deliberately ignores everything except the latest user
message because a browser controls the array. Setting the flag to
false leaves handlers with only the current message.
React hook
@chat-adapter/web/react's useChat is a thin wrapper around
@ai-sdk/react's hook of the same name:
import { useChat } from "@chat-adapter/web/react";
const { messages, sendMessage, status, stop, regenerate } = useChat({
api: "/api/chat",
threadId: "support-1",
});Options:
api— endpoint path (default/api/chat).threadId— Chat SDK thread id surfaced as the request body'sid. Strongly recommended.experimental_throttle— throttle wait in ms.resume— resume an in-flight stream....rest— passes through to@ai-sdk/react'suseChat.
For advanced configuration, use @ai-sdk/react's useChat directly;
there's nothing magical in the wrapper.
Web quirks worth remembering
- No platform side. Many adapter behaviours (reactions, edit /
delete, file uploads, modals) are no-ops because the browser
renderer doesn't need them. The contract methods exist but throw
NotImplementedErrorfor the unsupported ones. - Aborts on unmount. When the user navigates away, the browser
closes the SSE connection. The adapter forwards that as
request.signal.abort(); handlers must stop work promptly. - Per-request
AsyncLocalStoragescope is provided byals.ts. Use it instead of mutable adapter state for anything request- scoped. - No webhook signature, no platform secret.
getUseris everything. - Text-only formatting. Cards, modals, and reactions are not
exposed in the v1 protocol — the browser handles all rich UI
itself via
ai-elementsor custom React.
Testing approach
- Unit tests in
index.test.tsexercise the request decoder, thread-id derivation, persistence path, and SSE output. - The integration story is the
examples/nextjs-chatapp — run it locally to validate manual flows.
Coding conventions
- Use named exports throughout. No default exports.
- Keep server code free of React imports. The bundler emits two
entry points; only
src/react/index.tsmay import from@ai-sdk/react. - Errors map to
@chat-adapter/shared(AuthenticationError,ValidationError). The Web adapter has no rate-limit or network errors of its own. - Top-level regex literals only.
- Avoid mutable adapter state — use
AsyncLocalStorageviaals.tsfor request-scoped values.
Releases
Behavioural changes need a changeset (pnpm changeset, choose
@chat-adapter/web plus chat if a public type changed). React
hook changes belong in the same package since they share the
version with the server entry.
Where to look next
- User-facing docs:
apps/docs/content/adapters/official/web.mdx - README:
packages/adapter-web/README.md - Shared error/utility helpers:
packages/adapter-shared/src/index.ts - Core Adapter contract:
packages/chat/src/adapter.ts - Example app:
examples/nextjs-chat
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

