1import{j as t}from"./radix-ui-DXPtSXkA.js";import{r as i,L as c}from"./react-vendor-vSOrVpFR.js";import{u as N}from"./usePageMeta-BUwN3LGY.js";import{A as j}from"./AdminPageHeader-DFb3iT_m.js";import{A as y,c as _,d as v}from"./useAgentInbox-B7cw9QpZ.js";import{I as A,A as w}from"./lucide-DHpx159u.js";import"./BackButton-DOF1rrVO.js";import"./query-DwTbo07P.js";import"./index-D4axMTJe.js";import"./supabase-BBZflJSz.js";const o=new Map(y.map(s=>[s.id,s])),p={info:"bg-slate-100 text-slate-700 dark:bg-slate-800/50 dark:text-slate-200",result:"bg-emerald-50 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300",action:"bg-sky-50 text-sky-700 dark:bg-sky-900/30 dark:text-sky-300",warning:"bg-amber-50 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300",critical:"bg-rose-50 text-rose-700 dark:bg-rose-900/30 dark:text-rose-300"},u={scheduled:"bg-slate-100 text-slate-700 dark:bg-slate-800/50 dark:text-slate-200",running:"bg-sky-50 text-sky-700 dark:bg-sky-900/30 dark:text-sky-300",done:"bg-emerald-50 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300",failed:"bg-rose-50 text-rose-700 dark:bg-rose-900/30 dark:text-rose-300",cancelled:"bg-slate-100 text-slate-500 dark:bg-slate-800/50 dark:text-slate-400"},d=s=>s?new Date(s).toLocaleString("en-AU",{day:"numeric",month:"short",hour:"numeric",minute:"2-digit",timeZone:"Australia/Sydney"}):"â";function M(){N("Agent Inbox");const{data:s,isLoading:g,error:b,refetch:h}=_(),n=v(),[a,f]=i.useState("all"),k=i.useMemo(()=>[...new Set(((s==null?void 0:s.notes)??[]).map(e=>e.agent_id))].sort(),[s==null?void 0:s.notes]),m=((s==null?void 0:s.notes)??[]).filter(e=>a==="all"||e.agent_id===a),l=((s==null?void 0:s.watches)??[]).filter(e=>a==="all"||e.agent_id===a);return t.jsxs("div",{className:"space-y-6",children:[t.jsx(j,{icon:t.jsx(A,{className:"h-5 w-5"}),title:"Agent Inbox",subtitle:"Everything the agents have told you, and every check they were asked to run.",actions:t.jsxs(c,{to:"/admin/dashboard/home",className:"h-9 px-3 inline-flex items-center gap-1.5 rounded-md border border-border text-xs hover:bg-muted/40",children:[t.jsx(w,{className:"h-3.5 w-3.5"})," Dashboard"]})}),t.jsx("div",{className:"flex flex-wrap gap-2",role:"group","aria-label":"Filter by agent",children:["all",...k].map(e=>{var r;return t.jsx("button",{type:"button",onClick:()=>f(e),"aria-pressed":a===e,className:`h-8 px-3 rounded-md border text-xs ${a===e?"border-foreground bg-foreground text-background":"border-border hover:bg-muted/40"}`,children:e==="all"?"All agents":((r=o.get(e))==null?void 0:r.name)??e},e)})}),t.jsxs("section",{className:"bg-card border border-border rounded-md",children:[t.jsx("h2",{className:"px-4 sm:px-5 pt-4 font-mono text-sm font-semibold uppercase tracking-[0.18em] text-foreground",children:"Messages"}),g?t.jsx("p",{className:"px-4 sm:px-5 py-4 text-xs font-mono text-muted-foreground",children:"Loadingâ¦"}):b?t.jsxs("div",{className:"px-4 sm:px-5 py-4 flex items-center gap-3",children:[t.jsx("p",{className:"text-xs font-mono text-muted-foreground",children:"Couldn't load the inbox."}),t.jsx("button",{type:"button",onClick:()=>h(),className:"h-8 px-3 rounded-md border border-border text-xs hover:bg-muted/40",children:"Retry"})]}):m.length===0?t.jsx("p",{className:"px-4 sm:px-5 py-4 text-xs font-mono text-muted-foreground",children:"No messages yet."}):t.jsx("ul",{className:"divide-y divide-border mt-2",children:m.map(e=>{var x;const r=e.dismissed_at?"Dismissed":e.read_at?"Read":"Unread";return t.jsxs("li",{className:"px-4 sm:px-5 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.14em] text-muted-foreground",children:((x=o.get(e.agent_id))==null?void 0:x.name)??e.agent_id}),t.jsx("span",{className:`text-[9px] font-mono uppercase tracking-[0.16em] px-1.5 py-0.5 rounded ${p[e.kind]??p.info}`,children:e.kind}),t.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:r}),t.jsx("span",{className:"ml-auto text-[10px] font-mono text-muted-foreground tabular-nums",children:d(e.visible_from)})]}),t.jsx("p",{className:"text-sm font-medium text-foreground mt-1 break-words",children:e.title}),e.body&&t.jsx("p",{className:"text-xs text-muted-foreground mt-1 whitespace-pre-line break-words",children:e.body}),(e.dismissed_at||e.action_url&&e.action_url!=="/admin/dashboard")&&t.jsxs("div",{className:"flex gap-2 mt-2",children:[e.action_url&&e.action_url!=="/admin/dashboard"&&t.jsx(c,{to:e.action_url,className:"h-8 px-3 inline-flex items-center rounded-md border border-border text-xs hover:bg-muted/40",children:"Open"}),e.dismissed_at&&t.jsx("button",{type:"button",disabled:n.isPending,onClick:()=>n.mutate(e.id),className:"h-8 px-3 rounded-md border border-border text-xs hover:bg-muted/40 disabled:opacity-50",children:"Restore to inbox"})]})]},e.id)})}),(s==null?void 0:s.capped)&&t.jsx("p",{className:"px-4 sm:px-5 pb-4 text-[10px] font-mono text-muted-foreground",children:"Showing the 200 most recent messages."})]}),t.jsxs("section",{className:"bg-card border border-border rounded-md",children:[t.jsx("h2",{className:"px-4 sm:px-5 pt-4 font-mono text-sm font-semibold uppercase tracking-[0.18em] text-foreground",children:"Checks the agents were asked to run"}),l.length===0?t.jsx("p",{className:"px-4 sm:px-5 py-4 text-xs font-mono text-muted-foreground",children:"None yet."}):t.jsx("ul",{className:"divide-y divide-border mt-2",children:l.map(e=>{var r;return t.jsxs("li",{className:"px-4 sm:px-5 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"text-[10px] font-mono uppercase tracking-[0.14em] text-muted-foreground",children:((r=o.get(e.agent_id))==null?void 0:r.name)??e.agent_id}),t.jsx("span",{className:`text-[9px] font-mono uppercase tracking-[0.16em] px-1.5 py-0.5 rounded ${u[e.status]??u.scheduled}`,children:e.status}),t.jsx("span",{className:"ml-auto text-[10px] font-mono text-muted-foreground tabular-nums",children:e.status==="done"?`done ${d(e.completed_at)}`:`due ${d(e.due_at)}`})]}),t.jsx("p",{className:"text-sm text-foreground mt-1 break-words",children:e.title}),e.last_error&&t.jsxs("p",{className:"text-xs text-rose-700 dark:text-rose-300 mt-1 break-words",children:["Last error: ",e.last_error]})]},e.id)})})]})]})}export{M as AdminAgentInboxPage};
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.