Spaces:
Running
Running
| import{u as I,h as b,j as e,T as P,C as S,i as T,e as V,I as K,L as U}from"./index-B6LgHwxl.js";import{r}from"./vendor-C1HQAMsB.js";import{S as w,a as y,b as A,c as C,d as i,u as _}from"./select-BTyTGp6Q.js";import{u as z}from"./useQuery-CvuO27gq.js";import{u as O}from"./index-qzoWfvwJ.js";import{C as h,a as u,b as j,c as p}from"./Card-BQbkbI2V.js";import{C as k}from"./clock-DUDoE4xk.js";import{F as X}from"./funnel-DZQBvwbA.js";import{B as D}from"./badge-DJBNGBCQ.js";import{A as R}from"./AccessibleButton-B9jiZpHu.js";import"./index-BVvRaxKj.js";import"./index-J8KhNejV.js";import"./check-DhhLKPH8.js";const G=()=>{const t=I(),s=z({queryKey:["agentApprovals"],queryFn:()=>b.getAgentApprovals()}),a=O({mutationFn:({id:o,status:l})=>b.updateApprovalStatus(o,l),onSuccess:()=>{t.invalidateQueries({queryKey:["agentApprovals"]})}});return{approvals:s.data||[],isLoading:s.isLoading,isError:s.isError,updateApproval:a.mutate,isUpdating:a.isPending}},J=({approvals:t})=>{const s={total:t.length,pending:t.filter(a=>a.status==="pending").length,approved:t.filter(a=>a.status==="approved").length,rejected:t.filter(a=>a.status==="rejected").length};return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs(h,{children:[e.jsxs(u,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Total Actions"}),e.jsx(P,{className:"w-4 h-4 text-muted-foreground"})]}),e.jsx(p,{children:e.jsx("div",{className:"text-2xl font-bold",children:s.total})})]}),e.jsxs(h,{children:[e.jsxs(u,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Pending"}),e.jsx(k,{className:"w-4 h-4 text-yellow-500"})]}),e.jsx(p,{children:e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:s.pending})})]}),e.jsxs(h,{children:[e.jsxs(u,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Approved"}),e.jsx(S,{className:"w-4 h-4 text-green-500"})]}),e.jsx(p,{children:e.jsx("div",{className:"text-2xl font-bold text-green-600",children:s.approved})})]}),e.jsxs(h,{children:[e.jsxs(u,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(j,{className:"text-sm font-medium",children:"Rejected"}),e.jsx(T,{className:"w-4 h-4 text-red-500"})]}),e.jsx(p,{children:e.jsx("div",{className:"text-2xl font-bold text-red-600",children:s.rejected})})]})]})},W=({searchTerm:t,onSearchChange:s,statusFilter:a,onStatusChange:o,riskFilter:l,onRiskChange:n})=>e.jsxs(h,{children:[e.jsx(u,{children:e.jsxs(j,{className:"flex items-center gap-2",children:[e.jsx(X,{className:"w-5 h-5"}),"Filters"]})}),e.jsx(p,{children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"relative",children:[e.jsx(V,{className:"absolute left-3 top-3 w-4 h-4 text-muted-foreground"}),e.jsx(K,{placeholder:"Search agent actions...",value:t,onChange:N=>s(N.target.value),className:"pl-9"})]})}),e.jsxs(w,{value:a,onValueChange:o,children:[e.jsx(y,{className:"w-full md:w-48",children:e.jsx(A,{placeholder:"Filter by status"})}),e.jsxs(C,{children:[e.jsx(i,{value:"all",children:"All Status"}),e.jsx(i,{value:"pending",children:"Pending"}),e.jsx(i,{value:"approved",children:"Approved"}),e.jsx(i,{value:"rejected",children:"Rejected"})]})]}),e.jsxs(w,{value:l,onValueChange:n,children:[e.jsx(y,{className:"w-full md:w-48",children:e.jsx(A,{placeholder:"Filter by risk"})}),e.jsxs(C,{children:[e.jsx(i,{value:"all",children:"All Risk Levels"}),e.jsx(i,{value:"high",children:"High Risk"}),e.jsx(i,{value:"medium",children:"Medium Risk"}),e.jsx(i,{value:"low",children:"Low Risk"})]})]})]})})]}),F=r.forwardRef(({className:t,...s},a)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:a,className:`w-full caption-bottom text-sm ${t}`,...s})}));F.displayName="Table";const L=r.forwardRef(({className:t,...s},a)=>e.jsx("thead",{ref:a,className:`[&_tr]:border-b ${t}`,...s}));L.displayName="TableHeader";const $=r.forwardRef(({className:t,...s},a)=>e.jsx("tbody",{ref:a,className:`[&_tr:last-child]:border-0 ${t}`,...s}));$.displayName="TableBody";const Y=r.forwardRef(({className:t,...s},a)=>e.jsx("tfoot",{ref:a,className:`border-t bg-muted/50 font-medium [&>tr]:last:border-b-0 ${t}`,...s}));Y.displayName="TableFooter";const v=r.forwardRef(({className:t,...s},a)=>e.jsx("tr",{ref:a,className:`border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted ${t}`,...s}));v.displayName="TableRow";const c=r.forwardRef(({className:t,...s},a)=>e.jsx("th",{ref:a,className:`h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 ${t}`,...s}));c.displayName="TableHead";const d=r.forwardRef(({className:t,...s},a)=>e.jsx("td",{ref:a,className:`p-4 align-middle [&:has([role=checkbox])]:pr-0 ${t}`,...s}));d.displayName="TableCell";const Z=r.forwardRef(({className:t,...s},a)=>e.jsx("caption",{ref:a,className:`mt-4 text-sm text-muted-foreground ${t}`,...s}));Z.displayName="TableCaption";const ee=({approvals:t,onApproval:s})=>{const a=l=>{switch(l){case"approved":return e.jsx(S,{className:"w-4 h-4 text-green-500"});case"rejected":return e.jsx(T,{className:"w-4 h-4 text-red-500"});default:return e.jsx(k,{className:"w-4 h-4 text-yellow-500"})}},o=l=>{const n={high:"destructive",medium:"secondary",low:"outline"};return e.jsx(D,{variant:n[l],children:l.toUpperCase()})};return e.jsxs(h,{children:[e.jsx(u,{children:e.jsx(j,{children:"Agent Actions Queue"})}),e.jsxs(p,{children:[e.jsxs(F,{children:[e.jsx(L,{children:e.jsxs(v,{children:[e.jsx(c,{children:"Agent"}),e.jsx(c,{children:"Action"}),e.jsx(c,{children:"Target"}),e.jsx(c,{children:"Confidence"}),e.jsx(c,{children:"Risk"}),e.jsx(c,{children:"Status"}),e.jsx(c,{children:"Actions"})]})}),e.jsx($,{children:t.map(l=>e.jsxs(v,{children:[e.jsx(d,{className:"font-medium",children:l.agentName}),e.jsx(d,{children:l.action}),e.jsx(d,{className:"font-mono text-sm",children:l.target}),e.jsx(d,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-12 bg-secondary rounded-full h-2",children:e.jsx("div",{className:"bg-primary h-2 rounded-full",style:{width:`${l.confidence*100}%`}})}),e.jsxs("span",{className:"text-sm",children:[Math.round(l.confidence*100),"%"]})]})}),e.jsx(d,{children:o(l.risk)}),e.jsx(d,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[a(l.status),e.jsx("span",{className:"capitalize",children:l.status})]})}),e.jsx(d,{children:l.status==="pending"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{onClick:()=>s(l.id,"approve"),className:"bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded text-sm","aria-label":`Approve action ${l.action}`,children:"Approve"}),e.jsx(R,{onClick:()=>s(l.id,"reject"),variant:"outline",className:"border-red-300 text-red-600 hover:bg-red-50 px-3 py-1 rounded text-sm","aria-label":`Reject action ${l.action}`,children:"Reject"})]})})]},l.id))})]}),t.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No agent approvals match your filters."})]})]})},ue=()=>{const{toast:t}=_(),{approvals:s,isLoading:a,isError:o,updateApproval:l}=G(),[n,N]=r.useState(""),[f,B]=r.useState("all"),[g,E]=r.useState("all"),H=r.useMemo(()=>s.filter(x=>{const m=x.agentName.toLowerCase().includes(n.toLowerCase())||x.action.toLowerCase().includes(n.toLowerCase())||x.target.toLowerCase().includes(n.toLowerCase()),M=f==="all"||x.status===f,Q=g==="all"||x.risk===g;return m&&M&&Q}),[s,n,f,g]),q=(x,m)=>{l({id:x,status:m==="approve"?"approved":"rejected"},{onSuccess:()=>{t({title:m==="approve"?"Approved":"Rejected",description:`Agent action ${m}d successfully`})},onError:()=>{t({title:"Operation Failed",description:`Could not ${m} the agent action`,variant:"destructive"})}})};return a?e.jsx("div",{className:"p-6",children:e.jsx(U,{text:"Loading Agent Approvals..."})}):o?e.jsx("div",{className:"p-6 text-center",children:e.jsx("p",{className:"text-red-500",children:"Failed to load agent approvals queue."})}):e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Agent Approvals"}),e.jsx("p",{className:"text-slate-600 dark:text-slate-400 mt-2",children:"Review and approve automated agent actions"})]})}),e.jsx(J,{approvals:s}),e.jsx(W,{searchTerm:n,onSearchChange:N,statusFilter:f,onStatusChange:B,riskFilter:g,onRiskChange:E}),e.jsx(ee,{approvals:H,onApproval:q})]})};export{ue as default}; | |