feat: initial Next.js 15 client portal scaffold with Supabase & shadcn

This commit is contained in:
Marcos Fargas
2026-09-21 00:44:41 +02:00
parent e78fd98cf1
commit 3b5d77f515
20 changed files with 752 additions and 0 deletions

35
src/app/api/chat/route.ts Normal file
View File

@@ -0,0 +1,35 @@
import { NextRequest } from 'next/server';
export async function POST(req: NextRequest) {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://supabase.4ventures.es';
const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || '';
let kpis: any[] = [];
try {
const res = await fetch(`${supabaseUrl}/rest/v1/kpi_weekly?select=*`, {
headers: {
apikey: serviceKey,
Authorization: `Bearer ${serviceKey}`
}
});
if (res.ok) {
kpis = await res.json();
}
} catch (e) {
console.error('Error fetching KPIs for assistant:', e);
}
if (kpis.length === 0) {
return Response.json([{
text: 'Actualmente no constan datos consolidados en la vista de KPIs para este periodo. Por favor, asegúrate de que el webhook de leads y la sincronización diaria de Windsor.ai hayan registrado datos.'
}]);
}
const channelsSummary = kpis.map((k: any) =>
`- Canal ${k.channel.toUpperCase()}: ${k.total_leads} leads captados, inversión de ${Number(k.total_spend || 0).toFixed(2)} €, ${k.cohort_deals_won} clientes ganados, CAC: ${k.cac_cohort} €, ROAS: ${k.roas_cohort}x.`
).join('\n');
const answer = `📊 Resumen de Rendimiento Analítico (Fuente: kpi_weekly, corte horario):\n\n${channelsSummary}\n\n💡 Regla de Atribución: Calculado según el modelo oficial de cohorte a 60 días.`;
return Response.json([{ text: answer }]);
}