1import{j as e,M as w,O as je,D as Y,q as Z,H as j,s as K,u as f,x as Q,N as y,G as D,a5 as he,a6 as pe,a7 as q,a8 as N,a9 as ge,aa as _,ab as fe,V as be,ac as Ne,W as g}from"./ui-CfRm5DTA.js";import{Z as X,_ as U,$ as ee,a0 as se,L as E,a1 as te,a2 as ae,r as o,S as _e,a3 as we,s as ye,a4 as W,B as ve}from"./icons-CoWim_VM.js";import{L as P,b as Ce,d as Se,a as Ae,f as De}from"./index-CO7lCi65.js";import{P as ke}from"./page-header-C_yrDXSw.js";import{E as Te}from"./empty-state-KFFUCOK_.js";import{J as re}from"./job-progress-B9McQ932.js";import{J as Ee}from"./job-status-Di13jtCF.js";import{a as k,A as T}from"./api-TVx_5Nik.js";import{u as Pe,P as Le}from"./pagination-controls-BIvW4wzY.js";import{u as $e}from"./use-tabview-DvAkwhEi.js";import{C as Me}from"./copy-agent-dialog-DTl5gMZA.js";import{C as ze}from"./confirm-dialog-vrDTVcTM.js";import{u as Oe,E as Re}from"./use-socket-Z38et2Rb.js";import"./colors-oV9wCiAl.js";import"./index-BiJdn4L4.js";function Be({agents:c,onDelete:d,onDuplicate:n,isSubmitting:l,onStart:p,onStop:b}){return c.map(s=>{var h,r;const m=((h=s.last_job)==null?void 0:h.job_id)&&!((r=s.last_job)!=null&&r.completed_at);return e.jsxs(w,{className:"flex flex-col gap-3",children:[e.jsxs(je,{className:"flex flex-row items-center justify-between space-y-0 pb-2 gap-2",children:[e.jsxs("div",{className:"flex items-center space-x-2 mr-3",children:[e.jsx("img",{src:s.icon,alt:s.name,className:"h-6 w-6 rounded-sm",onError:u=>{u.target.src="https://www.google.com/s2/favicons?domain=example.com&sz=32"}}),e.jsx(P,{to:`/agents/${s.type}/${s.agent_id}`,className:"flex items-center space-x-2",children:e.jsx("h3",{className:"font-semibold leading-none truncate max-w-[180px]",title:s.name,children:s.name})})]}),e.jsxs(Y,{children:[e.jsx(Z,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"icon",children:e.jsx(X,{className:"h-4 w-4"})})}),e.jsxs(K,{align:"end",children:[e.jsx(f,{asChild:!0,children:e.jsxs(P,{to:`/agents/${s.type}/${s.agent_id}`,children:[e.jsx(U,{className:"mr-2 h-4 w-4"}),"Edit"]})}),e.jsxs(f,{onClick:()=>n(s.agent_id),children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Make a copy"]}),e.jsx(Q,{}),e.jsxs(f,{className:"text-destructive",onClick:()=>d(s.agent_id),children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})]}),e.jsxs(y,{className:"space-y-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-1",children:s.description||s.type})}),s.last_job&&e.jsx(re,{job:s.last_job,status:!0,className:"w-full"}),e.jsx(j,{variant:m?"destructive":"default",size:"sm",className:"w-full mt-4",onClick:()=>{m?b(s.last_job.job_id,s.agent_id):p(s.agent_id)},disabled:l===s.agent_id,children:m?e.jsxs(e.Fragment,{children:[l===s.agent_id?e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(te,{className:"mr-2 h-4 w-4"}),"Stop"]}):e.jsxs(e.Fragment,{children:[l===s.agent_id?e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ae,{className:"mr-2 h-4 w-4"}),"Start"]})})]})]},s.agent_id)})}function Ge({currentFilter:c,onFilterChange:d,counts:n}){return e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsx(w,{className:D("cursor-pointer transition-colors hover:bg-muted/50",c==="all"&&"bg-muted"),onClick:()=>d("all"),children:e.jsxs(y,{children:[e.jsx("div",{className:"text-2xl font-bold",children:n.all}),e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"All Agents"})]})}),e.jsx(w,{className:D("cursor-pointer transition-colors hover:bg-muted/50",c==="running"&&"bg-muted"),onClick:()=>d("running"),children:e.jsxs(y,{children:[e.jsx("div",{className:"text-2xl font-bold text-blue-500",children:n.running}),e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Running"})]})}),e.jsx(w,{className:D("cursor-pointer transition-colors hover:bg-muted/50",c==="error"&&"bg-muted"),onClick:()=>d("error"),children:e.jsxs(y,{children:[e.jsx("div",{className:"text-2xl font-bold text-red-500",children:n.error}),e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Errors"})]})}),e.jsx(w,{className:D("cursor-pointer transition-colors hover:bg-muted/50",c==="pending"&&"bg-muted"),onClick:()=>d("pending"),children:e.jsxs(y,{children:[e.jsx("div",{className:"text-2xl font-bold text-gray-500",children:n.pending}),e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Not Yet Ran"})]})})]})}function He({agents:c,onDelete:d,onDuplicate:n,isSubmitting:l,onStart:p,onStop:b}){return e.jsx("div",{className:"rounded-md border",children:e.jsxs(he,{children:[e.jsx(pe,{children:e.jsxs(q,{children:[e.jsx(N,{children:"Agent"}),e.jsx(N,{children:"Type"}),e.jsx(N,{children:"Status"}),e.jsx(N,{children:"Last Job"}),e.jsx(N,{children:"Actions"})]})}),e.jsx(ge,{children:c.map(s=>{var h,r;const m=((h=s.last_job)==null?void 0:h.job_id)&&!((r=s.last_job)!=null&&r.completed_at);return e.jsxs(q,{children:[e.jsx(_,{className:"max-w-[300px]",children:e.jsxs(P,{to:`/agents/${s.type}/${s.agent_id}`,className:"flex items-center space-x-2",children:[e.jsx("img",{src:s.icon,alt:s.name,className:"h-6 w-6 rounded-sm",onError:u=>{u.target.src="https://www.google.com/s2/favicons?domain=example.com&sz=32"}}),e.jsxs("div",{className:"truncate",children:[e.jsx("div",{className:"font-medium",children:s.name}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s.description})]})]})}),e.jsx(_,{children:e.jsx(fe,{variant:"outline",children:s.type})}
1),e.jsx(_,{children:s.last_job&&e.jsx(Ee,{status:s.last_job.status,error:s.last_job.error})}),e.jsx(_,{children:s.last_job&&e.jsx(re,{job:s.last_job})}),e.jsx(_,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{variant:m?"destructive":"default",size:"sm",onClick:()=>{m?b(s.last_job.job_id,s.agent_id):p(s.agent_id)},disabled:l===s.agent_id,children:m?e.jsxs(e.Fragment,{children:[l===s.agent_id?e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(te,{className:"mr-2 h-4 w-4"}),"Stop"]}):e.jsxs(e.Fragment,{children:[l===s.agent_id?e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ae,{className:"mr-2 h-4 w-4"}),"Start"]})}),e.jsxs(Y,{modal:!1,children:[e.jsx(Z,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"icon",children:e.jsx(X,{className:"h-4 w-4"})})}),e.jsxs(K,{align:"end",children:[e.jsx(f,{asChild:!0,children:e.jsxs(P,{to:`/agents/${s.type}/${s.agent_id}`,children:[e.jsx(U,{className:"mr-2 h-4 w-4"}),"Edit"]})}),e.jsxs(f,{onClick:()=>n(s.agent_id),children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Make a copy"]}),e.jsx(Q,{}),e.jsxs(f,{className:"text-destructive",onClick:()=>d(s.agent_id),children:[e.jsx(se,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})]})})]},s.agent_id)})})]})})}function as(){const c=Ce(),d=Se(),{authUser:n}=Ae(),[l,p]=$e("agents",["list","grid"],"list"),[b,s]=o.useState(!0),[m,h]=o.useState("all"),[r,u]=o.useState([]),[z,v]=o.useState(null),[ne,L]=o.useState(!1),[le,ie]=o.useState(!1),[C,S]=o.useState(null),[O,oe]=o.useState(),{page:ce,limit:R,offset:B,search:A,setSearch:de,paged:me,setPage:xe,setLimit:ue,setPaged:G}=Pe({defaultLimit:20}),{onEventReceived:H}=Oe();o.useEffect(()=>{const t=H(Re.jobProgress,a=>{a!=null&&a.agent_id&&u(i=>i.map(x=>x.agent_id!==a.agent_id?x:{...x,last_job:{...x.last_job,...a}}))});return()=>{t==null||t()}},[H]);const J=o.useCallback(async()=>{try{const t=await k.list(T.agents,{offset:B,limit:R,search:A,ts:O});if(t!=null&&t.result){const{result:a,...i}=t;u(a),G({total:i.total,returned:i.returned})}}finally{s(!1)}},[B,R,A,O,G]);o.useEffect(()=>{J()},[J]);const $=async t=>{try{await k.delete(T.agents,t),g.success("The agent has been deleted successfully."),u(r.filter(a=>a.agent_id!==t))}catch(a){g.error(a.message)}},I=async t=>{v(t);try{const a=await k.post(T.jobs+"/start",{agent_id:t});u(i=>i.map(x=>x.agent_id===t?{...x,last_job:a}:x)),g.success("Agent has been started successfully.")}catch(a){g.error(a.message)}finally{v(null)}},V=async(t,a)=>{v(a);try{const i=await k.list(`${T.jobs}/${t}/stop`);u(x=>x.map(M=>M.agent_id===i.agent_id?{...M,last_job:i}:M)),g.success("Agent has been stopped successfully.")}catch(i){g.error(i.message)}finally{v(null)}},F=()=>{if((n==null?void 0:n.plan)==="Free"&&r.length>=3){d.open();return}c("/agents/builder")};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ke,{title:"Agents",description:"Manage and monitor your automation agents.",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(_e,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(be,{type:"search",placeholder:"Search agents...",className:"w-[200px] pl-8 rounded-md",value:A,onChange:t=>de(t.target.value)})]}),e.jsxs(Ne,{children:[e.jsx(j,{variant:l==="grid"?"outline":"secondary",size:"icon",onClick:()=>p("grid"),children:e.jsx(we,{className:"h-4 w-4"})}),e.jsx(j,{variant:l==="list"?"outline":"secondary",size:"icon",onClick:()=>p("list"),children:e.jsx(ye,{className:"h-4 w-4"})})]}),e.jsxs(j,{onClick:F,children:[e.jsx(W,{className:"mr-2 h-4 w-4"}),"Create Agent"]})]})}),e.jsx(Ge,{currentFilter:m,onFilterChange:t=>{h(t)},counts:{all:r.length,running:r.filter(t=>{var a;return((a=t.last_job)==null?void 0:a.status)==="running"}).length,error:r.filter(t=>{var a;return((a=t.last_job)==null?void 0:a.status)==="error"}).length,pending:r.filter(t=>!t.last_job).length}}),b?e.jsx(De,{}):r.length===0?e.jsx(Te,{icon:e.jsx(ve,{className:"w-full h-full"}),title:"No agents found",description:A?"No agents match your search criteria. Try adjusting your search terms.":m!=="all"?"No agents match the selected filter. Try selecting a different filter.":"Get started by creating your first agent.",action:e.jsxs(j,{onClick:F,children:[e.jsx(W,{className:"mr-2 h-4 w-4"}),"Create Agent"]})}):l==="grid"?e.jsx("div",{className:"grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:e.jsx(Be,{agents:r,onDelete:$,onDuplicate:t=>{S(t),L(!0)},isSubmitting:z,onStart:I,onStop:V})}):e.jsx(He,{agents:r,onDelete:$,onDuplicate:t=>{S(t),L(!0)},isSubmitting:z,onStart:I,onStop:V}),e.jsx(Le,{paged:me,onPageChange:xe,onLimitChange:ue,currentPage:ce}),C&&e.jsx(Me,{open:ne,onOpenChange:t=>{L(t),S(null),oe(new Date().getTime())},agent:r.find(t=>t.agent_id===C)}),C&&e.jsx(ze,{open:le,onOpenChange:ie,title:"Delete Agent",description:"Are you sure you want to delete this agent? This action cannot be undone.",onConfirm:()=>{$(C),S(null)},confirmLabel:"Delete",variant:"destructive"})]})}
1export{as 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.