ai-persistence/build-custom-adapter
БесплатноБез исполняемых скриптовНе проверенUse when an app needs TanStack AI chat persistence on a database with no dedicated recipe — raw Postgres (pg/postgres.js), Kysely, node:sqlite, MongoDB…
от TanStack★ 3 396 звёзд на GitHubОб этом скилле
Custom Chat Persistence
The deliverable is one file in the app — src/lib/chat-persistence.ts —
exporting a ChatPersistence built from the database client the app already
has. Plus whatever DDL that database needs, added through the app's existing
migration flow.
Do not create a package, a second client, or a migration runner.
Always write all four tables (or collections) and all four stores: thread, run, interrupt,
metadata. The docs call interrupts and metadata optional for a
hand-rolled adapter; this recipe is not that case. withPersistence needs
all four to type-check as ChatPersistence, and the conformance suite fails
without them. Do not stop at a thread table and a run table.
Route first. If the app already runs one of these, stop and use that skill — it has the driver-specific code:
| App runs | Use |
|---|---|
| Drizzle ORM (any dialect) | ai-persistence/build-drizzle-adapter |
| Prisma | ai-persistence/build-prisma-adapter |
| Cloudflare Workers + D1 | ai-persistence/build-cloudflare-adapter |
Everything else lands here. The full contracts and their invariants are in
ai-persistence/stores and docs/persistence/store-reference.md; the
complete worked node:sqlite walkthrough is
docs/persistence/build-your-own-chat-adapter.md and
examples/ts-react-chat/src/lib/sqlite-persistence.ts.
1. Read the app before writing anything
| Find | Where to look | What it decides |
|---|---|---|
| The client | src/db.ts, src/lib/db.ts, src/server/db.ts |
What the file imports — never construct a second pool |
| Client lifetime | module singleton vs per-request factory (getDb(), bindings) |
export const chatPersistence vs export function |
| Migration flow | migrations/, drizzle/, supabase/migrations/, an ORM CLI |
How the DDL gets applied — use theirs, add nothing new |
| Naming conventions | existing tables/collections | Prefix (chat_*) so nothing collides |
| JSON support | jsonb (Postgres), json (MySQL 5.7+), text (SQLite) |
Whether mappers stringify/parse |
| Import alias | tsconfig.json paths |
@/db, ~/db, #/db, or a relative path |
2. Shape the storage
Four logical records. Whatever the engine, keep these keys — the store methods look records up by exactly these:
| Record | Key | Fields |
|---|---|---|
| thread | threadId |
messages (array, full transcript) |
| run | runId |
threadId, status, startedAt, finishedAt?, error?, usage?, parentRunId?, subagentRunId?, name?, sandboxKey?, detachedSince?, cancelRequested?, driverEpoch? |
| interrupt | interruptId |
runId, threadId, status, requestedAt, resolvedAt?, payload, response? |
| metadata | (namespace, key) |
value |
- Timestamps are epoch milliseconds (
number) in records. Store them however the engine prefers and convert in the mapper. (namespace, key)is a composite key. Never join with a separator —('a:b','c')and('a','b:c')must stay distinct records, and the conformance suite checks it.- Index
runs(threadId, status),runs(threadId, startedAt), andinterrupts(threadId, requestedAt)for the listing paths. If the backend implementslistReclaimable, also indexruns(status, detachedSince). If it implementslistByParentRun, also indexruns(parentRunId, startedAt). run.erroris a structuredRunError({ message: string, code?: string }), not a bare string.messageis the provider's prose;codeis the stable, machine-branchable classification an operator filters and groups by. In a SQL-backed table,
Установить ai-persistence/build-custom-adapter в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ai-persistence/build-custom-adapter?
Use when an app needs TanStack AI chat persistence on a database with no dedicated recipe — raw Postgres (pg/postgres.js), Kysely, node:sqlite, MongoDB, Supabase, Redis. Writes a chat-persistence.ts against the app's existing client, covering the four stores, the idempotency invariants, and the conformance gate. Route to the Drizzle, Prisma, or Cloudflare skills instead when one of those matches.
Как установить скилл ai-persistence/build-custom-adapter?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ai-persistence/build-custom-adapter запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic