1import{j as e}from"./vendor-ui-BeVD6iDL.js";import{a as f}from"./vendor-query-vEtoV3ax.js";import{s as g,dX as _,dV as b}from"./index-cXBC_5Uy.js";import{u as w}from"./useAICosts-CZEAR2Pq.js";import{A}from"./AdminPageShell-B5XdvC8l.js";import{L as x}from"./vendor-react-Dmhbt9i7.js";import"./vendor-motion-CENv1AvF.js";import"./BackIcon-B0Ptl-7G.js";const y=6e4;function N(r){return new Date(Date.now()-r*3600*1e3).toISOString()}function S(r=24){return f({queryKey:["scal-metrics","errors",r],queryFn:async()=>{const{data:l,error:o}=await g.from("platform_error_logs").select("category, level, occurrences").gte("last_seen_at",N(r)).limit(1e3);if(o)throw o;const c=new Map;for(const a of l??[]){const t=`${a.category??"unknown"}::${a.level??"error"}`,i=c.get(t)??{category:a.category??"unknown",level:a.level??"error",count:0};i.count+=Number(a.occurrences??1),c.set(t,i)}return Array.from(c.values()).sort((a,t)=>t.count-a.count)},staleTime:y,refetchOnWindowFocus:!1})}function k(r=24){return f({queryKey:["scal-metrics","perf",r],queryFn:async()=>{const{data:l,error:o}=await g.from("performance_metrics").select("metric_name, metric_type, value_ms").gte("recorded_at",N(r)).limit(5e3);if(o)throw o;const c=new Map;for(const t of l??[]){const i=t.metric_name,n=c.get(i)??{type:t.metric_type,values:[]};n.values.push(Number(t.value_ms??0)),c.set(i,n)}const a=[];for(const[t,i]of c){const n=[...i.values].sort((d,m)=>d-m),h=n.reduce((d,m)=>d+m,0)/n.length,p=n[Math.floor(n.length*.95)]??n[n.length-1];a.push({metric_name:t,metric_type:i.type,samples:n.length,avg_ms:Math.round(h),p95_ms:Math.round(p)})}return a.sort((t,i)=>i.p95_ms-t.p95_ms)},staleTime:y,refetchOnWindowFocus:!1})}function M(r={}){const{unackOnly:l=!1}=r;return f({queryKey:["platform-alerts",{unackOnly:l}],queryFn:async()=>{let c=g.from("platform_alerts").select("*").order("created_at",{ascending:!1}).limit(100);l&&(c=c.is("acknowledged_at",null));const{data:a,error:t}=await c;if(t)throw t;return a??[]},staleTime:3e4,refetchInterval:6e4,refetchOnWindowFocus:!1})}function u({title:r,children:l,action:o}){return e.jsxs("div",{className:"border rounded-lg p-4 bg-card",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"font-semibold",children:r}),o]}),l]})}function j(r,l){return l?Math.min(100,Math.round(r/l*100)):0}function $(){const{data:r,isLoading:l}=S(24),{data:o,isLoading:c}=k(24),{data:a}=w(1),{data:t}=_(),{data:i}=b(),{data:n=[]}=M({unackOnly:!0}),h=i?Object.entries(i).filter(([s,v])=>s.startsWith("disable_")&&v===!0).map(([s])=>s):[],p=(t??[]).filter(s=>j(s.daily_used,s.daily_limit)>=70),d=(r??[]).slice(0,8),m=(o??[]).slice(0,8);return e.jsx(A,{title:"Escalabilidade & Observabilidade",description:"Visão geral 24h. Para controles, use os atalhos.",width:"narrow",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsx(u,{title:`Alertas ativos (${n.length})`,action:e.jsx(x,{className:"text-xs underline",to:"/admin/edge-health",children:"Edge Health"}),children:n.length===0?e.jsx("p",{className:"text-sm text-emerald-600",children:"Nenhum alerta pendente."}):e.jsx("ul",{className:"text-sm space-y-1",children:n.slice(0,5).map(s=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:`mt-1.5 w-2 h-2 rounded-full shrink-0 ${s.severity==="critical"?"bg-destructive":s.severity==="warning"?"bg-yellow-500":"bg-blue-500"}`}),e.jsx("span",{className:"flex-1 truncate",children:s.message})]},s.id))})}),e.jsx(u,{title:"System Status",action:e.jsx(x,{className:"text-xs underline",to:"/admin/system-status",children:"Editar"}),children:h.length===0?e.jsx("p",{className:"text-sm text-emerald-600",children:"Todos os subsistemas ativos."}):e.jsx("ul",{className:"text-sm text-amber-600 space-y-1",children:h.map(s=>e.jsxs("li",{children:["â ",s," ativo"]},s))})}),e.jsx(u,{title:"Cotas IA (â¥70%)",action:e.jsx(x,{className:"text-xs underline",to:"/admin/ai-quota",children:"Gerenciar"}),children:p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sem features próximas do teto."}):e.jsx("ul",{className:"text-sm space-y-1",children:p.map(s=>e.jsxs("li",{children:[s.feature,": ",j(s.daily_used,s.daily_limit),"% (",s.daily_used,"/",s.daily_limit,")"]},s.feature))})}),e.jsx(u,{title:"IA â Ãltima hora",action:e.jsx(x,{className:"text-xs underline",to:"/admin/ai-costs",children:"Detalhes"}),children:e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{children:["Calls: ",e.jsx("span",{className:"font-mono",children:a?.total_calls??0})]}),e.jsxs("div",{children:["Custo: ",e.jsxs("span",{className:"font-mono",children:["$",(a?.total_cost??0).toFixed(4)]})]}),e.jsxs("div",{children:["Erro: ",e.jsxs("span",{className:"font-mono",children:[((a?.error_rate??0)*100).toFixed(1),"%"]})]})]})}),e.jsx(u,{title:"Erros (24h)",action:e.jsx(x,{className:"text-xs underline",to:"/admin/error-logs",children:"Logs"}),children:l?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregandoâ¦"}):d.length===0?e.jsx("p",{className:"text-sm text-emerald-600",children:"Sem erros recentes."}):e.jsx("ul",{className:"text-sm space-y-1",children:d.map(s=>e.jsxs("li",{className:"flex justify-between gap-2",children:[e.jsxs("span",{className:"truncate",children:[s.category," ",e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s.level,")"]})]}),e.jsx("span",{className:"font-mono",children:s.count})]},`${s.category}-${s.level}`))})})]}),e.jsx(u,{title:"Performance â p95 mais altos (24h)",children:c?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregandoâ¦"}):m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sem amostras nas últimas 24h."}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-xs text-muted-foreground border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left py-1",children:"Métrica"}),e.jsx("th",{className:"text-left py-1",children:"Tipo"}),e.jsx("th",{className:"text-right py-1",children:"Amostras"}),e.jsx("th",{className:"text-right py-1",children:"Avg"}),e.jsx("th",{className:"text-right py-1",children:"p95"})]})}),e.jsx("tbody",{children:m.map(s=>e.jsxs("tr",{className:"border-b border-muted",children:[e.jsx("td",{className:"py-1",children:s.metric_name}),e.jsx("td",{className:"py-1 text-xs text-muted-foreground",children:s.metric_type}),e.jsx("td",{className:"py-1 text-right font-mono",children:s.samples}),e.jsxs("td",{className:"py-1 text-right font-mono",children:[s.avg_ms,"ms"]}),e.jsxs("td",{className:"py-1 text-right font-mono",children:[s.p95_ms,"ms"]})]},s.metric_name))})]})}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Rate-limiting server-side está pendente â backend ainda não tem primitivas dedicadas. Por enquanto, a quota global de IA + cache de borda nas funções públicas absorvem a maior parte do risco."})]})})}export{$ as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.