页面简介
A unified TypeScript SDK for building chat bots with type-safe handlers, JSX cards, and multi-platform support—powered by Vercel
正文摘录
Universal chat layer for building bots and agentsA unified TypeScript SDK for building chat bots with type-safe handlers, JSX cards, and multi-platform support—powered by VercelFor humansFor agents$npm install chatPlatformSlackTeamsGoogle ChatDiscordWhatsAppTelegrambot.tsximport { Actions, Button, Card, CardText } from "chat"; bot.onNewMention(async (thread) => { await thread.post( <Card title="Deploy to production?"> <CardText>PR #103 passed every check.</CardText> <Actions> <Button id="approve" style="primary">Approve</Button> <Button id="cancel">Cancel</Button> </Actions> </Card> ); }); // deploy() returns an AsyncIterable<string>, so the reply streams bot.onAction("approve", async (event) => { await event.thread?.post(deploy(103)); }); bot.onAction("cancel", async (event) => { await event.thread?.post("Deploy canceled."); }); AAlice9:41 AM@DeployBot can we ship PR #103?DDeployBotApp9:41 AMDeploy to production?PR #103 passed every check.ApproveCancelSame code on every platform. See all adaptersWeekly downloads6.7MGitHub stars2.5KContributors151+Adapters15+The platform agnostic chat toolkitThe open-source chat toolkit designed to help developers build chat bots that run on Slack, Teams, Google Chat, Discord, WhatsApp, and more.Multi-platform supportShip to every chat platform from one codebase, without per-platform rewrites.Event-driven by designReact to mentions, reactions, and replies with handlers scoped to each thread.Type-safe by defaultStrict types for adapters, handlers, and JSX cards, checked at build time.Explore Chat SDKChat SDK CoreA unified API for building event-driven chat bots. Listen for mentions, subscribe to threads, and post rich cards across multiple platforms.AI agentsStream AI SDK responses into a thread, and give agents tools to read, post, and react across your chat platforms.AdaptersRun the same handlers on Slack, Teams, Google Chat, and more, and keep thread state in Redis, Postgres, or memory.Read the docsBot SetupEvent HandlersRich CardsError Handlingimport { Chat } from "chat"; import { createSlackAdapter } from "@chat-adapter/slack"; import { createRedisState } from "@chat-adapter/state-redis"; export const bot = new Chat({ userName: "mybot", adapters: { slack: createSlackAdapter(), }, state: createRedisState(), }); bot.onNewMention(async (thread) => { await thread.subscribe(); await thread.post("Hello! I'm listening to this thread now."); }); bot.onSubscribedMessage(async (thread, message) => { await thread.post(`You said: ${message.text}`); }); Scale with confidencePlug Chat SDK into an entire ecosystem designed for AI-native chat experiences that scale.AI SDKBuild AI agents with streaming, tool calls, and structured outputs.$ npm i aiVercel AI GatewayAccess 400+ models with one API key and no markup.$ npm i aiVercel SandboxBuild knowledge agents with persistent filesystems to search, index, and read files.$ npm i @vercel/sandboxWorkflows NEWBuild durable chat agents that suspend, resume, and survive function timeouts.$ npm i workflowBuild with Chat SDK todayStart from a template, or follow a guide to use Chat SDK with Vercel Connect and eve.Read the docs$npx create-chat-sdk@latestVercel Connect GuideAuthenticate a Slack bot with Vercel Connect instead of stored secrets.const slack = createSlackAdapter({ // Credentials come from Vercel Connect // instead of stored secrets ...connectSlackAdapter("slack/acme-slack"),}); export const bot = new Chat({ userName: "mybot", adapters: { slack }, state: createRedisState(),});Knowledge Agent TemplateAnswer questions from synced docs and repos with file-system search.// Search synced docs and reposconst savoir = createSavoir({ apiUrl: process.env.SAVOIR_URL, apiKey: process.env.SAVOIR_API_KEY,}); const { text } = await generateText({ model, tools: savoir.tools, prompt: "How do I configure auth?",});eve Integration GuideSend Chat SDK messages to an eve agent and stream its replies back to the thread.const { bot, send } = chatSdkChannel({ userName: "my-agent", adapters: { slack }, state: createRedisState(),}); bot.onNewMention(async (thread, message) => { await thread.subscribe(); await send(message.text, { thread });});