chat / state-ioredis
AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub
Guidance for coding agents working inside the ioredis state 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/state-ioredis is the same Chat SDK state contract as @chat-adapter/state-redis but built on ioredis. Pick this variant when you need: - Cluster mode — ioredis ships first-class Redis Cluster support, including topology refresh, MOVED redirection, and CROSSSLOT-safe hash tags. - Sentinel — automatic failover via…
- Reads credentials
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-web/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-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
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
If none of these apply, prefer @chat-adapter/state-redis for its smaller dependency footprint.
- Very specific: line 176
If the caller passes a client, the adapter assumes it is already connected and does not call quit() on disconnect().
- Distinctive: line 209
Use named exports throughout.
- Very specific: line 210
All key construction goes through a single prefixedKey helper.
≈ “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/state-ioredis
Guidance for coding agents working inside the ioredis state 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/state-ioredis is the same Chat SDK state contract as
@chat-adapter/state-redis but built on
ioredis. Pick this variant
when you need:
- Cluster mode —
ioredisships first-class Redis Cluster support, including topology refresh, MOVED redirection, and CROSSSLOT-safe hash tags. - Sentinel — automatic failover via Redis Sentinel.
- Pub/Sub + commands on the same client —
ioredisallows it (node-redisdoesn't without separate clients). - An existing codebase already standardised on
ioredis.
If none of these apply, prefer @chat-adapter/state-redis for its
smaller dependency footprint.
Directory layout
packages/state-ioredis/
├── src/
│ ├── index.ts # IoRedisStateAdapter + createIoRedisState
│ └── index.test.ts # full StateAdapter contract suite
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
└── README.mdThe package mirrors state-redis line-for-line where possible so
fixes apply to both. Behavioural deviations are limited to what
ioredis and node-redis express differently (transaction syntax,
script caching, cluster routing).
Build, test, typecheck
pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean
# from repo root
pnpm --filter @chat-adapter/state-ioredis build
pnpm --filter @chat-adapter/state-ioredis testThe unit tests use a vi.fn()-backed ioredis stub. Real Redis
integration tests live in
packages/integration-tests/src/state-ioredis.test.ts and run only
when REDIS_URL is exported.
Public surface
Main exports from src/index.ts:
createIoRedisState(options)— primary factory. Requires either aurlor an existingclient; there is noREDIS_URLauto-detection (unlikecreateRedisState).IoRedisStateAdapterclass — implements the Chat SDKStateAdapterinterface. Public methods: subscriptions, locks, cache, lists, queues, plusdisconnect().IoRedisStateAdapterOptions— options type, a union of the url-based and client-based variants.
Configuration
import { createIoRedisState } from "@chat-adapter/state-ioredis";
// With a connection URL
createIoRedisState({
url: process.env.REDIS_URL!,
keyPrefix: "chat-sdk",
logger: customLogger, // optional, defaults to a console logger
});
// Or with an existing ioredis client
createIoRedisState({ client: existingIoredisInstance });For cluster:
import { Cluster } from "ioredis";
const cluster = new Cluster([
{ host: "node-a", port: 6379 },
{ host: "node-b", port: 6379 },
]);
createIoRedisState({ client: cluster });For sentinel:
import Redis from "ioredis";
const client = new Redis({
sentinels: [{ host: "sentinel-a", port: 26379 }],
name: "mymaster",
});
createIoRedisState({ client });Internal key layout
Identical to state-redis:
{prefix}:subs:{threadId}
{prefix}:lock:{lockId}
{prefix}:cache:{cacheKey}
{prefix}:list:{listKey}
{prefix}:queue:{queueKey}
{prefix}:queue:{queueKey}:dedupeCluster mode uses hash-tag braces around the multi-key segment so locks and cache keys with the same logical ID land on the same slot:
{prefix}:{lockId}:lock # tagged variant for clusterThe adapter selects the tagged or untagged form based on whether the
client reports a cluster topology — see the
isClusterClient(client) helper.
Locking semantics
acquireLock(lockId, ttlMs) uses SET key value NX PX ttl exactly
as state-redis does. releaseLock(lockId, token) runs the same Lua
script via EVALSHA (with EVAL fallback on NOSCRIPT). Cluster
support is handled by ioredis's built-in script management.
forceReleaseLock(lockId) is unconditional DEL.
Capabilities
- Persistence — yes.
- Multi-instance — yes.
- Subscriptions — yes.
- Distributed locking — yes, atomic via Lua release script.
- Key-value cache — yes, with TTL.
- Lists — yes, with per-entry TTL.
- Queues — yes, with per-entry TTL + dedupe set.
- Automatic reconnect — yes (built into
ioredis). - Cluster — yes, with hash-tag slot routing.
- Sentinel — yes, via
ioredisSentinel transport. - Key prefix namespacing — yes.
Pipelines & transactions
ioredis exposes pipeline() separately from multi(). The adapter
uses multi().exec() for atomic composite operations (queue dedupe
check + enqueue, list trim + add) — pipelines are reserved for
performance optimisations that don't need atomicity.
Connection management
If the caller passes a client, the adapter assumes it is already
connected and does not call quit() on disconnect(). If the
adapter creates its own client, it owns the lifecycle.
The adapter listens for error, reconnecting, and end events on
the client and forwards them to logger. There is no automatic
re-creation of clients — ioredis handles reconnection internally.
Error handling
Mirrors state-redis:
WRONGPASS/NOAUTH→AuthenticationError.LOADING/BUSY→AdapterRateLimitErrorwith a short retry-after.- Connection errors →
NetworkError.
Cluster CLUSTERDOWN errors are surfaced as NetworkError so
handlers can apply uniform retry logic.
Testing approach
- The contract tests in
index.test.tsmirror thestate-redissuite. Whenever you fix something in one, port the test (and fix) to the other. - Real-cluster / real-Sentinel tests live in
packages/integration-tests/src/state-ioredis.test.tsand run only with the env vars present. - Cluster routing tests stub
ioredis.Clusterwith avi.fn()shim that records the resolved nodes per command.
Coding conventions
- Use named exports throughout. No default exports.
- All key construction goes through a single
prefixedKeyhelper. - Cluster-aware key construction lives in
keyTagged— never inline{}brace concatenation. - TTLs are stored as absolute epoch milliseconds for ZSET-backed structures and converted to relative ms (PX) for STRING-backed ones.
- Top-level regex literals only.
- Errors map to
@chat-adapter/shared(AuthenticationError,AdapterRateLimitError,NetworkError).
Releases
Behavioural changes need a changeset (pnpm changeset, choose
@chat-adapter/state-ioredis plus chat if a public StateAdapter
type changed). When fixing parity bugs, include both state-redis
and state-ioredis in the changeset.
Where to look next
- User-facing docs:
apps/docs/content/adapters/official/ioredis.mdx - README:
packages/state-ioredis/README.md - Core StateAdapter contract:
packages/chat/src/state.ts - Sibling state adapters:
packages/state-memorypackages/state-redispackages/state-pg
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.

