Skip to content

Copilot

The Copiloto IA (Copilot) is a chat assistant over the operator's real business data. It answers questions in the same language as the question (Portuguese question → Portuguese answer) and can recommend actions — but it never executes anything; the human decides.


How it works

The copilot endpoint (api/ai/copilot/route.ts) combines three things at request time:

  1. A deterministic data snapshotgetDashboardSummary() (today + range period metrics), the top 50 offers, the top 50 campaigns, and the 20 most recent transactions, all fetched in parallel via Supabase.
  2. Business-data rules in the system prompt — the model is told every monetary value is in USD and it must never invent, estimate, or extrapolate numbers. Missing/zero data is reported explicitly.
  3. The operator's question — with fixed metric definitions so answers are consistent:
Metric Definition
net_revenue revenue − refunds − chargebacks − fees
profit net_revenue − ad_spend − opex
roas revenue / ad_spend
net_roas net_revenue / ad_spend

Guardrails

  • Authentication — requires a valid session (getSessionUser) and workspace (getWorkspace).
  • Model binding — the question is routed through the selected active bv_ai_models row (input/output cost per million is recorded on every run).
  • Logging — every run (success or failure) is persisted to bv_ai_runs with the model, task (copilot), pricing, latency, and token usage.