Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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), and interrupts(threadId, requestedAt) for the listing paths. If the backend implements listReclaimable, also index runs(status, detachedSince). If it implements listByParentRun, also index runs(parentRunId, startedAt).
  • run.error is a structured RunError ({ message: string, code?: string }), not a bare string. message is the provider's prose; code is the stable, machine-branchable classification an operator filters and groups by. In a SQL-backed table,
Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить ai-persistence/build-custom-adapter с