Overview
ff-ai is an AI conversation management SDK built on top of the Vercel AI SDK with first-class Effect.ts integration. It provides type-safe, functional patterns for managing AI conversations, messages, and model usage costs.
Key Features
Conversation Store
Abstract interface for persisting and retrieving conversation messages
Turn Handler
Manage multi-turn conversations with automatic message persistence
Model Pricing
Calculate usage costs for AI models from models.dev
Drizzle Provider
PostgreSQL-backed conversation storage using Drizzle ORM
Installation
Peer Dependencies
The SDK requires the following peer dependencies:Quick Start
Here’s a simple example of using ff-ai with the Drizzle provider:Core Concepts
Effect.ts Integration
All operations in ff-ai are Effect-based, providing:- Type-safe error handling: Errors are part of the type signature
- Composability: Chain operations using Effect operators
- Dependency injection: Use Effect’s Context for services
- Resource management: Automatic cleanup with structured concurrency
Thread Identifiers
Conversations are identified by a combination of:resourceId: The resource or user the conversation belongs tothreadId: A unique identifier for the conversation thread
Message Format
Messages extend the AI SDK’sModelMessage type with:
id: UUID v7 identifiercreatedAt: Timestamp for ordering and retrieval