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:
- A deterministic data snapshot —
getDashboardSummary()(today + range period metrics), the top 50 offers, the top 50 campaigns, and the 20 most recent transactions, all fetched in parallel via Supabase. - 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.
- 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_modelsrow (input/output cost per million is recorded on every run). - Logging — every run (success or failure) is persisted to
bv_ai_runswith the model, task (copilot), pricing, latency, and token usage.