cre-sync/lib/control-center/conversation-service.ts
BusyBee3333 4e6467ffb0 Add CRESync CRM application with Setup page
- Build complete Next.js CRM for commercial real estate
- Add authentication with JWT sessions and role-based access
- Add GoHighLevel API integration for contacts, conversations, opportunities
- Add AI-powered Control Center with tool calling
- Add Setup page with onboarding checklist (/setup)
- Add sidebar navigation with Setup menu item
- Fix type errors in onboarding API, GHL services, and control center tools
- Add Prisma schema with SQLite for local development
- Add UI components with clay morphism design system

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:30:55 -05:00

72 lines
1.8 KiB
TypeScript

import { prisma } from '@/lib/db';
import type { Prisma } from '@prisma/client';
export class ConversationService {
async create(userId: string, title?: string) {
return prisma.controlCenterConversation.create({
data: { userId, title }
});
}
async getById(id: string) {
return prisma.controlCenterConversation.findUnique({
where: { id },
include: { messages: { orderBy: { createdAt: 'asc' } } }
});
}
async listByUser(userId: string, limit = 20, offset = 0) {
return prisma.controlCenterConversation.findMany({
where: { userId },
orderBy: { updatedAt: 'desc' },
take: limit,
skip: offset,
include: { _count: { select: { messages: true } } }
});
}
async addMessage(conversationId: string, data: {
role: 'user' | 'assistant';
content: string;
toolCalls?: Prisma.InputJsonValue;
toolResults?: Prisma.InputJsonValue;
model?: string;
inputTokens?: number;
outputTokens?: number;
}) {
// Update conversation timestamp and add message
await prisma.controlCenterConversation.update({
where: { id: conversationId },
data: { updatedAt: new Date() }
});
return prisma.controlCenterMessage.create({
data: {
conversationId,
role: data.role,
content: data.content,
toolCalls: data.toolCalls,
toolResults: data.toolResults,
model: data.model,
inputTokens: data.inputTokens,
outputTokens: data.outputTokens,
}
});
}
async updateTitle(id: string, title: string) {
return prisma.controlCenterConversation.update({
where: { id },
data: { title }
});
}
async delete(id: string) {
return prisma.controlCenterConversation.delete({
where: { id }
});
}
}
export const conversationService = new ConversationService();