Codapult includes a working AI chat surface, not just provider configuration. The module combines a dashboard chat UI, persisted conversations, a streaming API route, provider adapters, model selection, organization quotas, and optional RAG context injection.
Runtime flow
- The user sends a message from
src/components/ai/ChatUI. POST /api/chatauthenticates the session and validates the request.- The route checks rate limits and organization AI quota.
- The selected model is resolved through
src/lib/ai/providers.ts. - RAG context is retrieved when enabled and appended to the system prompt.
- The response streams back through the Vercel AI SDK.
- Conversation and message rows are persisted for history.
Key files
| File | Purpose |
|---|---|
src/app/api/chat/route.ts | Streaming chat endpoint |
src/components/ai/ChatUI | Dashboard chat experience |
src/lib/ai/models.ts | Client-safe model list |
src/lib/ai/providers.ts | Provider/model resolver |
src/lib/ai/conversations.ts | Conversation and message persistence |
src/lib/ai/rag.ts | Optional retrieval context |
Models
Models are declared in src/lib/ai/models.ts. Each entry has an ID, label, and provider. src/lib/ai/providers.ts maps that ID to a provider-backed language model.
To restrict the UI to a subset of models, set appConfig.ai.allowedModels in src/config/app.ts. An empty array means every model in models.ts is available.
Tool calls
The chat route supports Vercel AI SDK tool calls. Add product-specific tools in /api/chat/route.ts with a Zod parameter schema and an execute function. Keep tools small and domain-specific: lookup a record, update a workflow, fetch a report, or call an internal service.
Configuration
| Setting | Location |
|---|---|
| Default model | appConfig.ai.defaultModel |
| System prompt | appConfig.ai.systemPrompt |
| Allowed models | appConfig.ai.allowedModels |
| OpenAI key | OPENAI_API_KEY |
| Anthropic key | ANTHROPIC_API_KEY |