import 'dotenv/config'; import { prisma } from '@omniloq/db'; const SYSTEM_PROMPT = "Tu es l'assistant du garage {{garage_name}}, un garage automobile fictif. Réponds de façon concise, en français. " + "Utilise les outils fournis uniquement quand c'est nécessaire. " + "Ne fabrique JAMAIS un résultat : si un outil renvoie une erreur, transmets honnêtement cette erreur au client."; /** Seed minimal : un tenant "garage" complet avec agent, révision, MCP, outils, canal, identité, conversation. */ export async function seedGarageDemo(slug: string) { const tenant = await prisma.tenant.create({ data: { name: slug, slug } }); const agent = await prisma.agent.create({ data: { tenantId: tenant.id, name: 'garage-assistant' }, }); const revision = await prisma.agentRevision.create({ data: { agentId: agent.id, systemPrompt: SYSTEM_PROMPT, provider: 'deepseek', model: process.env.MODEL ?? 'deepseek-v4-flash', maxSteps: 6, temperature: 0.3, toolsetVersion: 'v1', }, }); await prisma.agent.update({ where: { id: agent.id }, data: { activeRevisionId: revision.id } }); await prisma.variable.create({ data: { agentId: agent.id, key: 'garage_name', value: 'Garage Atlas' }, }); const mcpServer = await prisma.mcpServer.create({ data: { tenantId: tenant.id, name: 'garage-mock', transport: 'stdio' }, }); await prisma.agentTool.createMany({ data: [ { agentId: agent.id, mcpServerId: mcpServer.id, toolName: 'get_balance' }, { agentId: agent.id, mcpServerId: mcpServer.id, toolName: 'list_available_slots' }, { agentId: agent.id, mcpServerId: mcpServer.id, toolName: 'book_appointment' }, ], }); const channelAccount = await prisma.channelAccount.create({ data: { tenantId: tenant.id, channelType: 'whatsapp', provider: 'meta', label: 'test' }, }); const channelIdentity = await prisma.channelIdentity.create({ data: { tenantId: tenant.id, channelType: 'whatsapp', channelAccountId: channelAccount.id, externalUserId: `test-user-${slug}`, }, }); const conversation = await prisma.conversation.create({ data: { tenantId: tenant.id, agentId: agent.id, channelIdentityId: channelIdentity.id }, }); return { tenant, agent, revision, mcpServer, channelAccount, channelIdentity, conversation }; } /** Crée un message inbound sur la conversation (déjà rattaché avant le run). */ export async function createInbound(conversationId: string, text: string) { return prisma.message.create({ data: { conversationId, direction: 'inbound', senderType: 'contact', content: [{ type: 'text', text }] as any, status: 'received', }, }); } /** Nettoie un tenant de test (ordre inverse des dépendances). */ export async function cleanupTenant(tenantId: string) { const tenant = await prisma.tenant.findUnique({ where: { id: tenantId }, include: { agents: true, channelAccounts: true } }); if (!tenant) return; for (const a of tenant.agents) { await prisma.agentTool.deleteMany({ where: { agentId: a.id } }); await prisma.agentRevision.deleteMany({ where: { agentId: a.id } }); await prisma.variable.deleteMany({ where: { agentId: a.id } }); } await prisma.tenant.delete({ where: { id: tenantId } }); }