ai-persistence/build-prisma-adapter

Generates a Prisma-backed chat persistence layer for TanStack AI applications.

3.1k|316|Updated Oct 8, 2025
One-click install
npx skills add https://github.com/TanStack/ai --skill ai-persistence-build-prisma-adapter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ai-persistence/build-prisma-adapter
Source: https://github.com/TanStack/ai/tree/main/packages/ai-persistence/skills/ai-persistence/build-prisma-adapter
Command: npx skills add https://github.com/TanStack/ai --skill ai-persistence-build-prisma-adapter

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/ai-persistence, @tanstack/ai, @prisma/client.

What problem does it solve?

Apps that already run Prisma need durable storage for TanStack AI chat threads, runs, interrupts, and metadata, but writing the four store implementations by hand is error-prone around idempotency, BigInt timestamps, and JSON serialization.

Core Features & Use Cases

  • Schema Generation: Adds four models (ChatThread, ChatRun, ChatInterrupt, ChatMetadata) to the app's existing schema.prisma with correct indexes and BigInt timestamp columns.
  • Store Implementation: Writes a single chat-persistence.ts implementing MessageStore, RunStore, InterruptStore, and MetadataStore against the app's existing PrismaClient singleton.
  • Idempotency & Edge Cases: Handles upsert-with-empty-update semantics, updateMany no-op patches, explicit-undefined field clearing, and structured RunError columns.
  • Use Case: A Next.js app using Prisma and TanStack AI needs resumable chat runs; this Skill produces the persistence file, schema additions, route wiring with withPersistence, and a conformance test using runPersistenceConformance.

Quick Start

Add Prisma-backed chat persistence to my app by generating the schema models and chat-persistence.ts against my existing PrismaClient.

Frequently Asked Questions about ai-persistence/build-prisma-adapter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Prisma chat persistence to a TanStack AI app?

Add four models (ChatThread, ChatRun, ChatInterrupt, ChatMetadata) to your existing schema.prisma, run your own prisma migrate dev, then create a chat-persistence.ts that implements the four stores against your existing PrismaClient singleton and pass it to withPersistence middleware.

How do I make Prisma run creation idempotent for chat resume?

Use prisma upsert with an empty update object, which acts as ON CONFLICT DO NOTHING so an existing runId comes back untouched. This makes resume and double-submit safe without extra existence checks.

Does this work with both Prisma 6 and Prisma 7?

Yes. The store code only uses the delegate query API (findUnique, upsert, updateMany, findMany, deleteMany), which is unchanged between Prisma 6 and 7, so either generated client works regardless of output location.

Why use updateMany instead of update for patching runs in Prisma?

Prisma's update throws P2025 when the row is missing, but the store contract requires patching an unknown runId to be a silent no-op. updateMany matches zero rows without throwing, satisfying the contract.

Can I use Prisma Json columns instead of String for chat payloads?

Yes, on Postgres or MySQL you can switch the *Json fields to Prisma's Json type and drop the JSON.stringify/parse calls in the mappers. Keep String if the app targets SQLite or supports multiple providers.

Why does patching detachedSince with undefined not clear the column?

Checking patch.detachedSince !== undefined cannot distinguish 'clear this' from 'not mentioned'. The store uses the 'in' operator so an explicit undefined writes NULL, otherwise reattached runs appear permanently detached to the reaper.