ai-persistence/stores
БесплатноБез исполняемых скриптовНе проверенImplement the MessageStore, RunStore, InterruptStore, MetadataStore contracts for @tanstack/ai-persistence against any database. defineAIPersistence…
от TanStack★ 3 396 звёзд на GitHubОб этом скилле
Persistence Stores
Builds on ai-persistence and ai-persistence/server.
@tanstack/ai-persistence ships contracts, not a backend for your
database. An adapter is an object with a stores map; implement the stores you
need against whatever you already run and hand the result to
withPersistence. The core never inspects your tables, so the schema is yours.
Use memoryPersistence() for dev and tests. Everything durable is an adapter
you write. This skill is the contract reference; the per-stack recipes that
write a chat-persistence.ts into an app are
ai-persistence/build-{drizzle,prisma,cloudflare,custom}-adapter, and
a complete node:sqlite implementation lives in
examples/ts-react-chat/src/lib/sqlite-persistence.ts.
Choose a shape
import { defineAIPersistence } from '@tanstack/ai-persistence'
import type { ChatWithInterruptsPersistence } from '@tanstack/ai-persistence'
import { messages, runs, interrupts } from './stores'
// Sparse is fine — only implement what you need.
export const persistence: ChatWithInterruptsPersistence = defineAIPersistence({
stores: {
messages, // required for withPersistence / reconstructChat
runs, // required if you have interrupts
interrupts,
// metadata optional
},
})
| Shape | Contents |
|---|---|
ChatTranscriptPersistence |
messages (+ optional runs/interrupts/metadata) |
ChatWithInterruptsPersistence |
messages + runs + interrupts |
ChatPersistence |
all four chat stores |
defineAIPersistence preserves exact keys and rejects unknown keys at runtime.
Annotate your factory with a named shape. Bare AIPersistence is the
all-optional sparse bag, so withPersistence and reconstructChat reject it
(stores.messages is possibly undefined). This is the single most common
mistake when writing an adapter.
stores accepts exactly four keys — messages, runs, interrupts,
metadata. Anything else (notably locks or sandbox instance maps) throws
Unknown AIPersistence store key at runtime and fails to type-check. Locks:
ai-core/locks / @tanstack/ai/locks. Sandbox instance resume:
@tanstack/ai-sandbox.
Contracts and invariants
MessageStore
import type { ModelMessage } from '@tanstack/ai'
interface MessagePage {
messages: Array<ModelMessage>
truncated: boolean
cursor?: string
}
interface MessageStore {
loadThread: (
threadId: string,
options?: { limit?: number; before?: string },
) => Promise<Array<ModelMessage> | MessagePage>
saveThread: (threadId: string, messages: Array<ModelMessage>) => Promise<void>
}
- Call
loadThreadwith onlythreadIdand return the full array ([]for unknown threads, nevernull). Never aMessagePage. limitandbeforeare an optional hydrate hint. Ignore them and return the full array, or return aMessagePage.beforeis opaque. You mint the cursor.saveThreadis a full replace of the merged list, not append. Merge by id iswithPersistence, not this store.
RunStore
RunStatus, TerminalRunStatus, RunRecord, RunStore, defineRunStore, and
isTerminalRunStatus are defined in @tanstack/ai and re-exported from
@tanstack/ai-persistence. Import those from either; the recipes in this skill
import from @tanstack/ai-persistence so an adapter author needs only one
package name.
RunError is the exception — it is NOT re-exported. Import it from
@tanstack/ai directly (import type { RunError } from '@tanstack/ai'); the
@tanstack/ai-persistence barrel has no such export and the import fails to
resolve.
Four methods are required (createOrResume / update / get /
findActiveRun). Three are optional: implement only the ones your backend needs,
and leave the rest off the object entirely (not undefined, just absent). A
four-method RunStore is a fully valid backend.
withPersistence calls createOrResume and update. The query methods have
other consumers. Each missing optional method disables one feature:
| method | consumer | absent means |
|---|---|---|
findActiveRun |
reconstruct.ts (stores.runs?.findActiveRun(threadId)) |
required. A null stub hides a live run |
listReclaimable |
reapDetachedRuns in @tanstack/ai-sandbox |
the store cannot be reaped at all |
listByThread |
reconstructChat, when the transcript has tool calls |
the cards of children that a tool call started stay absent |
listByParentRun |
`reconstruct |
Установить ai-persistence/stores в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ai-persistence/stores?
Implement the MessageStore, RunStore, InterruptStore, MetadataStore contracts for @tanstack/ai-persistence against any database. defineAIPersistence, composePersistence overrides, critical invariants (full-replace saveThread, optional loadThread limit/before hint, insert-if-absent createOrResume and interrupt create), authorize thread access, runPersistenceConformance testkit. Use whenever you need server persistence — the package ships contracts, not a backend for your database.
Как установить скилл ai-persistence/stores?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ai-persistence/stores запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic