mirror of
https://github.com/vercel/chat.git
synced 2026-09-14 18:32:29 +08:00
0f8503198b
* feat(chat): make message dedup TTL configurable to prevent Slack retry duplicates * changeset * fix * bump default to 5 min * fix * Fix: Test, JSDoc, and README all reference the old default dedupe TTL of 60,000ms after the constant was changed to 300,000ms (5 minutes), causing test failure. This commit fixes the issue reported at packages/chat/src/chat.test.ts:140 **Bug:** The `DEDUPE_TTL_MS` constant in `packages/chat/src/chat.ts` line 51 was changed from `60_000` (60 seconds) to `5 * 60 * 1000` (300,000 ms = 5 minutes). However, three other locations were not updated to match: 1. **Test (`chat.test.ts` line 140):** The test "should use default dedupe TTL of 60 seconds" asserts that `mockState.set` is called with `60_000` as the TTL. Since the actual code now uses `300_000`, the test fails — confirmed by running the test suite which shows 1 failed test: expected `60000` but received `300000`. 2. **JSDoc (`types.ts` line 40):** The documentation comment says "Defaults to 60000 (60 seconds)" which is incorrect — it's now 300000 (5 minutes). 3. **README.md (line 52):** The Configuration table lists the default as `60000` which is now wrong. **Evidence:** Running `npx vitest run` shows 1 test failure out of 443 tests. After applying the fix, all 443 tests pass. **Fix:** 1. Updated the test in `chat.test.ts`: Changed the test description from "60 seconds" to "5 minutes" and the expected value from `60_000` to `300_000`. 2. Updated the JSDoc in `types.ts`: Changed "Defaults to 60000 (60 seconds)" to "Defaults to 300000 (5 minutes)". 3. Updated the README.md: Changed the default value in the Configuration table from `60000` to `300000`. Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com> Co-authored-by: NicolasMontone <montonenicolas01@gmail.com> * fix --------- Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
2.6 KiB
2.6 KiB
chat
Core SDK for building multi-platform chat bots. Provides the Chat class, event handlers, JSX card runtime, emoji helpers, and type-safe message formatting.
Installation
npm install chat
Usage
import { Chat } from "chat";
import { createSlackAdapter } from "@chat-adapter/slack";
import { createRedisState } from "@chat-adapter/state-redis";
const bot = new Chat({
userName: "mybot",
adapters: {
slack: createSlackAdapter({
botToken: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
}),
},
state: createRedisState({ url: process.env.REDIS_URL! }),
dedupeTtlMs: 600_000, // 10 minutes (default: 5 min)
});
bot.onNewMention(async (thread) => {
await thread.subscribe();
await thread.post("Hello! I'm listening to this thread.");
});
bot.onSubscribedMessage(async (thread, message) => {
await thread.post(`You said: ${message.text}`);
});
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
userName |
string |
required | Default bot username across all adapters |
adapters |
Record<string, Adapter> |
required | Map of adapter name to adapter instance |
state |
StateAdapter |
required | State adapter for subscriptions, locking, and dedup |
logger |
Logger | LogLevel |
"info" |
Logger instance or log level ("silent" to disable) |
streamingUpdateIntervalMs |
number |
500 |
Update interval for fallback streaming (post + edit) in ms |
dedupeTtlMs |
number |
300000 |
TTL for message deduplication entries in ms. Increase if webhook cold starts cause platform retries (e.g., Slack's http_timeout retry) that arrive after the default window |
AI coding agent support
If you use an AI coding agent like Claude Code, you can teach it about Chat SDK:
npx skills add vercel/chat
Documentation
Full documentation is available at chat-sdk.dev/docs.
- Usage — event handlers, threads, messages, channels
- Chat API — full
Chatclass reference - Cards — JSX-based interactive cards
- Streaming — AI SDK integration
- Emoji — cross-platform emoji helpers
License
MIT