1import{r as L,u as S,d as K,j as e}from"./vendor-query-CnAhr2B8.js";import{a as O,a_ as A,H as w,p as j,q as N,aT as f,r as y,s as g,ac as q,d as o,bw as R,B,ak as C,aN as P,aA as H,i as E,j as F,k as G,l as I,_ as $,aQ as D,S as Q,F as V,W as J,ag as U}from"./index-CLUtDhnY.js";import{T as M,a as W,b as _,c as v,d as Z,e as b}from"./table-2PZjRc6u.js";import{L as z,b as k}from"./shared-CAkFySQR.js";import{P as Y}from"./play-rh91jfbb.js";import{S as X}from"./star-W3rPNB9i.js";import{H as ee}from"./heart-BPUPw7pK.js";import{T as se}from"./target-B8Bp25HY.js";import{B as te}from"./brain-C4pXsSiY.js";import"./vendor-ui-CYA7SV0W.js";import"./vendor-charts-CPMWc2oJ.js";import"./vendor-forms-UY-il7MQ.js";import"./circle-x-CDWbgxd-.js";import"./building-CwsInd-C.js";const ae={churn_prediction:e.jsx(te,{className:"h-5 w-5 text-red-500"}),onboarding_coach:e.jsx(se,{className:"h-5 w-5 text-blue-500"}),lead_scoring:e.jsx(U,{className:"h-5 w-5 text-emerald-500"}),health_score:e.jsx(ee,{className:"h-5 w-5 text-pink-500"}),support_triage:e.jsx(J,{className:"h-5 w-5 text-amber-500"}),revenue_optimization:e.jsx($,{className:"h-5 w-5 text-purple-500"}),content_seo:e.jsx(V,{className:"h-5 w-5 text-cyan-500"}),testimonial:e.jsx(X,{className:"h-5 w-5 text-yellow-500"}),competitive_intel:e.jsx(Q,{className:"h-5 w-5 text-indigo-500"}),social_media:e.jsx(D,{className:"h-5 w-5 text-sky-500"}),coordinator:e.jsx($,{className:"h-5 w-5 text-orange-500"})},re={retention:"bg-red-100 text-red-800",growth:"bg-blue-100 text-blue-800",operations:"bg-amber-100 text-amber-800",revenue:"bg-purple-100 text-purple-800",marketing:"bg-cyan-100 text-cyan-800",strategy:"bg-indigo-100 text-indigo-800"};function ie(r){if(!r)return"â";try{const a=typeof r=="string"?JSON.parse(r):r;if(a.score!==void 0&&a.riskLevel)return`Score: ${a.score} (${a.riskLevel})`;if(a.tier)return`Tier: ${a.tier}${a.score!==void 0?` (${a.score})`:""}`;if(a.category)return`${a.category}: ${a.description||a.severity||""}`;if(a.step)return`Step: ${a.label||a.step}`;if(a.type)return`${a.type}: ${a.recommendation||a.businessName||""}`;if(a.contentType)return`${a.contentType}: ${a.title||a.industry||""}`;if(a.businessName)return a.businessName;if(a.recommendation)return a.recommendation;const m=Object.keys(a);return m.length>0?`${m[0]}: ${JSON.stringify(a[m[0]]).slice(0,60)}`:"â"}catch{return String(r).slice(0,80)}}function ne({details:r,action:a,businessId:m}){var x;const s=typeof r=="string"?(()=>{try{return JSON.parse(r)}catch{return{}}})():r;if(!s)return e.jsx("p",{className:"text-muted-foreground",children:"No details available."});if(s.churnScore!==void 0||s.score!==void 0&&s.riskLevel){const t=s.churnScore||s.score,n=s.riskLevel||(t>=70?"high":t>=40?"medium":"low"),d=n==="high"?"text-red-600":n==="medium"?"text-amber-600":"text-emerald-600",u=s.factors||s.topFactors||[],h=s.recommendations||[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:`text-4xl font-bold ${d}`,children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Churn Risk"})]}),e.jsxs("div",{children:[e.jsxs(o,{variant:n==="high"?"destructive":n==="medium"?"secondary":"default",children:[n," risk"]}),s.businessName&&e.jsx("p",{className:"text-sm font-medium mt-1",children:s.businessName})]})]}),u.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Risk Factors"}),e.jsx("ul",{className:"space-y-1",children:u.map((i,l)=>e.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[e.jsx("span",{className:"text-red-400 mt-0.5",children:"â¢"}),typeof i=="string"?i:i.detail||i.factor]},l))})]}),h.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Recommended Actions"}),e.jsx("ul",{className:"space-y-1",children:h.map((i,l)=>e.jsxs("li",{className:"text-sm text-blue-700 flex items-start gap-2",children:[e.jsx("span",{className:"mt-0.5",children:"â"})," ",i]},l))})]}),s.interventionType&&e.jsx("div",{className:"bg-emerald-50 border border-emerald-200 rounded-lg p-3",children:e.jsxs("p",{className:"text-sm text-emerald-800 font-medium",children:["Intervention sent: ",s.interventionType.replace(/_/g," ")
1]})})]})}return s.contentType==="blog"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Blog Post Draft"}),e.jsx("h3",{className:"text-lg font-semibold mt-1",children:s.title})]}),s.industry&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{variant:"outline",children:s.industry}),s.businessCount&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s.businessCount," businesses)"]}),s.generatedVia&&e.jsx(o,{variant:"secondary",className:"text-xs",children:s.generatedVia==="openai"?"AI Generated":"Template"})]}),s.outline&&s.outline.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Outline"}),e.jsx("ol",{className:"list-decimal list-inside space-y-1",children:s.outline.map((t,n)=>e.jsx("li",{className:"text-sm text-muted-foreground",children:t},n))})]}),s.targetKeywords&&s.targetKeywords.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Target Keywords"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.targetKeywords.map((t,n)=>e.jsx(o,{variant:"outline",className:"text-xs",children:t},n))})]})]}):s.contentType==="social"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Social Media Post Draft"}),e.jsx("h3",{className:"text-lg font-semibold mt-1",children:s.title})]}),s.industry&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{variant:"outline",children:s.industry}),s.generatedVia&&e.jsx(o,{variant:"secondary",className:"text-xs",children:s.generatedVia==="openai"?"AI Generated":"Template"})]}),s.body&&e.jsx("div",{className:"bg-muted rounded-lg p-4",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:s.body})}),s.targetKeywords&&s.targetKeywords.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Target Keywords"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.targetKeywords.map((t,n)=>e.jsx(o,{variant:"outline",className:"text-xs",children:t},n))})]})]}):s.tier||s.breakdown?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-4xl font-bold",children:s.score}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Health Score"})]}),e.jsx(o,{variant:s.tier==="critical"?"destructive":s.tier==="at_risk"?"secondary":"default",className:"text-sm",children:(x=s.tier)==null?void 0:x.replace(/_/g," ")})]}),s.breakdown&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Score Breakdown"}),e.jsx("div",{className:"space-y-1",children:Object.entries(s.breakdown).map(([t,n])=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:t.replace(/([A-Z])/g," $1").replace(/^./,d=>d.toUpperCase())}),e.jsx("span",{className:"font-medium",children:String(n)})]},t))})]}),s.message&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:e.jsx("p",{className:"text-sm text-red-800",children:s.message})})]}):s.alertType||s.message?e.jsxs("div",{className:"space-y-4",children:[s.alertType&&e.jsx(o,{variant:"destructive",children:s.alertType.replace(/_/g," ")}),s.message&&e.jsx("p",{className:"text-sm",children:s.message}),s.score!==void 0&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Score: ",s.score]})]}):e.jsx("div",{className:"space-y-2",children:Object.entries(s).map(([t,n])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("span",{className:"text-sm font-medium min-w-[120px]",children:[t.replace(/([A-Z])/g," $1").replace(/^./,d=>d.toUpperCase()),":"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:typeof n=="object"?(()=>{try{return JSON.stringify(n,null,2)}catch{return"[complex object]"}})():String(n)})]},t))})}function le({agent:r,isExpanded:a,onToggle:m,onRun:s,isRunning:x}){var l;const[t,n]=L.useState(null),{data:d,isLoading:u}=S({queryKey:[`/api/admin/platform-agents/${r.id}/activity`],queryFn:async()=>(await w("GET",`/api/admin/platform-agents/${r.id}/activity?limit=20`)).json(),enabled:a}),h=ae[r.id]||e.jsx(q,{className:"h-5 w-5"}),i=re[r.category]||"bg-gray-100 text-gray-800";return e.jsxs(j,{className:r.alertsLast24h>0?"border-red-200":"",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 cursor-pointer hover:bg-muted/50 transition-colors",onClick:m,children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex-shrink-0",children:h}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:r.name}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${i}`,children:r.category}),r.alertsLast24h>0&&e.jsxs(o,{variant:"destructive",className:"text-xs flex items-center gap-1",children:[e.jsx(R,{className:"h-3 w-3"}),r.alertsLast24h]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.description})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-right hidden md:block",children:[e.jsxs("p",{className:"text-sm font-medium",children:[r.actionsLast24h," actions"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.lastRunAt?`Last run: ${k(r.lastRunAt)}`:"Never run"})]}),e.jsx(B,{size:"sm",variant:"outline",onClick:c=>{c.stopPropagation(),s()},disabled:x,className:"flex-shrink-0",children:x?e.jsx(C,{className:"h-4 w-4 animate-spin"}):e.jsx(Y,{className:"h-4 w-4"})}),a?e.jsx(P,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(H,{className:"h-4 w-4 text-muted-foreground"})]})]}),a&&e.jsxs(g,{className:"border-t pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Recent Activity"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Schedule: ",r.schedule]})]}),u?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(C,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):d!=null&&d.logs&&d.logs.length>0?e.jsx("div",{className:"max-h-80 overflow-y-auto",children:e.jsxs(M,{children:[e.jsx(W,{children:e.jsxs(_,{children:[e.jsx(v,{children:"Time"}),e.jsx(v,{children:"Action"}),e.jsx(v,{children:"Business"}),e.jsx(v,{children:"Details"})]})}),e.jsx(Z,{children:d.logs.map(c=>e.jsxs(_,{className:"cursor-pointer hover:bg-muted/60",onClick:()=>n(c),children:[e.jsx(b,{className:"text-xs text-muted-foreground whitespace-nowrap",children:c.createdAt?k(c.createdAt):"â"}),e.jsx(b,{children:e.jsx(o,{variant:c.action==="alert_generated"?"destructive":"secondary",className:"text-xs",children:c.action.replace(/_/g," ")})}),e.jsx(b,{className:"text-sm",children:c.businessId>0?`#${c.businessId}`:"Platform"}),e.jsx(b,{className:"text-xs text-muted-foreground max-w-xs truncate",children:ie(c.details)})]},c.id))})]})}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No activity yet. Click the play button to run this agent."})]}),e.jsx(E,{open:!!t,onOpenChange:()=>n(null),children:e.jsxs(F,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsx(G,{children:e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(o,{variant:(t==null?void 0:t.action)==="alert_generated"?"destructive":"secondary",className:"text-xs",children:(l=t==null?void 0:t.action)==null?void 0:l.replace(/_/g," ")}),e.jsx("span",{className:"text-muted-foreground text-sm font-normal",children:t!=null&&t.createdAt?k(t.createdAt):""})]})}),t&&e.jsx(ne,{details:t.details,action:t.action,businessId:t.businessId})]})})]})}function be(){const[r,a]=L.useState(null),{toast:m}=O(),{data:s,isLoading:x}=S({queryKey:["/api/admin/platform-agents"],queryFn:async()=>(await w("GET","/api/admin/platform-agents")).json()}),{data:t}=S({queryKey:["/api/admin/platform-agents-summary"],queryFn:async()=>(await w("GET","/api/admin/platform-agents-summary")).json()}),n=K({mutationFn:async i=>(await w("POST",`/api/admin/platform-agents/${i}/run`)).json(),onSuccess:(i,l)=>{var p;const c=((p=s==null?void 0:s.agents.find(T=>T.id===l))==null?void 0:p.name)||l;m({title:"Agent completed",description:`${c} finished running successfully.`}
1),A.invalidateQueries({queryKey:["/api/admin/platform-agents"]}),A.invalidateQueries({queryKey:["/api/admin/platform-agents-summary"]}),A.invalidateQueries({queryKey:[`/api/admin/platform-agents/${l}/activity`]})},onError:(i,l)=>{var p;const c=((p=s==null?void 0:s.agents.find(T=>T.id===l))==null?void 0:p.name)||l;m({title:"Agent failed",description:`${c} encountered an error: ${i.message}`,variant:"destructive"})}});if(x)return e.jsx(z,{});const d=(s==null?void 0:s.agents)||[],u=d.reduce((i,l)=>i+l.alertsLast24h,0),h=(t==null?void 0:t.totalActionsLast24h)||0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(j,{children:[e.jsxs(N,{className:"pb-2",children:[e.jsx(f,{children:"Active Agents"}),e.jsx(y,{className:"text-3xl text-emerald-600",children:d.length})]}),e.jsx(g,{children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Platform-level AI agents running"})})]}),e.jsxs(j,{children:[e.jsxs(N,{className:"pb-2",children:[e.jsx(f,{children:"Actions (24h)"}),e.jsx(y,{className:"text-3xl text-blue-600",children:h})]}),e.jsx(g,{children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total agent actions taken"})})]}),e.jsxs(j,{children:[e.jsxs(N,{className:"pb-2",children:[e.jsx(f,{children:"Alerts (24h)"}),e.jsx(y,{className:`text-3xl ${u>0?"text-red-600":"text-emerald-600"}`,children:u})]}),e.jsx(g,{children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"High-priority items requiring attention"})})]}),e.jsxs(j,{children:[e.jsxs(N,{className:"pb-2",children:[e.jsx(f,{children:"Alerts (7d)"}),e.jsx(y,{className:"text-3xl text-amber-600",children:(t==null?void 0:t.totalAlertsLast7d)||0})]}),e.jsx(g,{children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Weekly alert trend"})})]})]}),e.jsx("div",{className:"space-y-3",children:d.map(i=>e.jsx(le,{agent:i,isExpanded:r===i.id,onToggle:()=>a(r===i.id?null:i.id),onRun:()=>n.mutate(i.id),isRunning:n.isPending&&n.variables===i.id},i.id))})]})}export{be 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.