1import{u as L,a as k,c as M,j as e}from"./vendor-query-CyuAx_uY.js";import{r as w,L as q}from"./vendor-react-zJ7Ub6x4.js";import{c as $,u as A,X as _,a as u}from"./index-DwZYJ2bC.js";import{I as C}from"./inbox-DuigWYAi.js";import{C as E}from"./circle-alert-Cgz9bng7.js";import{E as z}from"./external-link-Da-5Kn8q.js";import{C as F}from"./check-CkLN-gph.js";import"./vendor-auth-B8PCyEaA.js";import"./vendor-motion-C5NynTTt.js";/** 2 * @license lucide-react v0.513.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const P=[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]],Q=$("check-check",P);/** 7 * @license lucide-react v0.513.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const T=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],K=$("history",T);function x(o){return`${o.agent_token_id}:${o.id}`}function R(o){const s=Math.max(0,Math.floor(Date.now()/1e3)-o);return s<60?`${s}s ago`:s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}const D={approved:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",executed:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20",denied:"bg-red-500/10 text-red-400 border-red-500/20",failed:"bg-amber-500/10 text-amber-400 border-amber-500/20"};function W(){var N,v;const{csrfToken:o}=A(),s=L(),[i,g]=w.useState("pending"),[a,p]=w.useState(new Set),c=k({queryKey:["inbox","pending"],queryFn:()=>u.inbox.list(),refetchInterval:15e3,enabled:i==="pending"}),h=k({queryKey:["inbox","history"],queryFn:()=>u.inbox.history(),enabled:i==="history"}),l=M({mutationFn:({items:t,decision:n})=>u.inbox.batch(t.map(d=>({tokenId:d.agent_token_id,approvalId:d.id})),n,o),onSuccess:()=>{p(new Set),s.invalidateQueries({queryKey:["inbox"]})}}),r=((N=c.data)==null?void 0:N.items)??[],f=((v=h.data)==null?void 0:v.items)??[],y=r.filter(t=>a.has(x(t))),j=r.length>0&&a.size===r.length,S=t=>p(n=>{const d=new Set(n),b=x(t);return d.has(b)?d.delete(b):d.add(b),d}),I=()=>p(j?new Set:new Set(r.map(x))),m=(t,n)=>{t.length===0||l.isPending||l.mutate({items:t,decision:n})};return e.jsxs("div",{className:"mx-auto max-w-3xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:"h-5 w-5 text-impact"}),e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:"Approval Inbox"})]}),e.jsxs("div",{className:"flex rounded-lg border border-border bg-surface-raised p-0.5 text-xs",children:[e.jsxs("button",{onClick:()=>g("pending"),className:`px-3 py-1.5 rounded-md font-medium transition-colors ${i==="pending"?"bg-impact/10 text-impact":"text-text-muted hover:text-text-secondary"}`,children:["Pending",r.length>0?` (${r.length})`:""]}),e.jsx("button",{onClick:()=>g("history"),className:`px-3 py-1.5 rounded-md font-medium transition-colors ${i==="history"?"bg-impact/10 text-impact":"text-text-muted hover:text-text-secondary"}`,children:"History"})]})]}),i==="pending"&&e.jsxs(e.Fragment,{children:[r.length>0&&e.jsxs("div",{className:"flex items-center justify-between mb-4 rounded-xl border border-border bg-surface-raised px-4 py-2.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-text-secondary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:j,onChange:I,className:"accent-impact"}),a.size>0?`${a.size} selected`:"Select all"]}),a.size>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{disabled:l.isPending,onClick:()=>m(y,"approve"),className:"inline-flex items-center gap-1.5 rounded-lg bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 px-3 py-1.5 text-xs font-medium hover:bg-emerald-500/20 disabled:opacity-50",children:[e.jsx(Q,{className:"h-3.5 w-3.5"}),"Approve ",a.size]}),e.jsxs("button",{disabled:l.isPending,onClick:()=>m(y,"deny"),className:"inline-flex items-center gap-1.5 rounded-lg bg-red-500/10 text-red-400 border border-red-500/20 px-3 py-1.5 text-xs font-medium hover:bg-red-500/20 disabled:opacity-50",children:[e.jsx(_,{className:"h-3.5 w-3.5"}),"Reject ",a.size]})]})]}),c.isLoading&&e.jsx("div",{className:"h-24 rounded-xl border border-border bg-surface-overlay animate-pulse"}),c.isError&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-red-400",children:[e.jsx(E,{className:"h-3.5 w-3.5"}),"Failed to load inbox."]}),!c.isLoading&&!c.isError&&r.length===0&&e.jsxs("div",{className:"rounded-2xl border border-border bg-surface-raised p-8 text-center",children:[e.jsx(C,{className:"h-8 w-8 text-text-muted mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-text-muted",children:"No pending approvals. Items your agents queue for your approval show up here."})]}),e.jsx("ul",{className:"space-y-3",children:r.map(t=>{const n=x(t);return e.jsx("li",{className:"rounded-xl border border-border bg-surface-overlay p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:a.has(n),onChange:()=>S(t),className:"mt-1 accent-impact"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5 flex-wrap",children:[e.jsx("span",{className:"text-[11px] font-mono font-medium uppercase tracking-wider text-text-secondary",children:t.action_type}),e.jsxs(q,{to:`/dashboard/agent/${t.agent_token_id}`,className:"inline-flex items-center gap-1 text-[11px] text-impact hover:underline",children:[t.agent_name||`Agent #${t.agent_token_id}`,e.jsx(z,{className:"h-3 w-3"})]}),e.jsx("span",{className:"text-[11px] text-text-muted",children:R(t.created_at)})]}),e.jsx("p",{className:"text-sm text-text-primary break-words whitespace-pre-wrap",children:t.preview_text||"(no preview)"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{disabled:l.isPending,onClick:()=>
11m([t],"approve"),title:"Approve",className:"inline-flex items-center justify-center rounded-lg bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 h-8 w-8 hover:bg-emerald-500/20 disabled:opacity-50",children:e.jsx(F,{className:"h-4 w-4"})}),e.jsx("button",{disabled:l.isPending,onClick:()=>m([t],"deny"),title:"Reject",className:"inline-flex items-center justify-center rounded-lg bg-red-500/10 text-red-400 border border-red-500/20 h-8 w-8 hover:bg-red-500/20 disabled:opacity-50",children:e.jsx(_,{className:"h-4 w-4"})})]})]})},n)})})]}),i==="history"&&e.jsxs(e.Fragment,{children:[h.isLoading&&e.jsx("div",{className:"h-24 rounded-xl border border-border bg-surface-overlay animate-pulse"}),!h.isLoading&&f.length===0&&e.jsxs("div",{className:"rounded-2xl border border-border bg-surface-raised p-8 text-center",children:[e.jsx(K,{className:"h-8 w-8 text-text-muted mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-text-muted",children:"No decided items yet."})]}),e.jsx("ul",{className:"space-y-2",children:f.map(t=>e.jsxs("li",{className:"rounded-xl border border-border bg-surface-overlay p-3.5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"text-[11px] font-mono uppercase tracking-wider text-text-secondary",children:t.action_type}),e.jsx("span",{className:"text-[11px] text-text-muted",children:t.agent_name||`Agent #${t.agent_token_id}`}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium border ${D[t.status]||"bg-surface text-text-muted border-border"}`,children:t.status})]}),e.jsx("p",{className:"text-xs text-text-muted break-words line-clamp-2",children:t.preview_text||""}),t.error&&e.jsx("p",{className:"text-[11px] text-amber-400 mt-1",children:t.error})]},x(t)))})]})]})}export{W as DashboardInbox};
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.