1import{j as e,r as g,d as I,u as y,c}from"./vendor-tanstack-D3FldrMT.js";import{L,B as i}from"./index-BsMKmnxD.js";import{b2 as b,o as j,b1 as E,s as q,b3 as $,aX as z,ap as D,w as N,b4 as M,ao as Q,X as K,b6 as O}from"./vendor-ui-DqJK9vZj.js";import{A as R,a as B,u as W}from"./admin-auth-CNbOn2-S.js";import"./vendor-react-Cgg2GOmP.js";import"./vendor-radix-BCwydRYy.js";const J=[{id:"manual",label:"Manual",description:"Run on demand"},{id:"scheduled",label:"Scheduled",description:"Run on a schedule"},{id:"event",label:"Event-based",description:"Run when triggered"}];function U(){const[d,o]=g.useState(null),[w,m]=g.useState(!1),[a,n]=g.useState({name:"",description:"",agentIds:[],schedule:"",triggerType:"manual",isActive:1}),{logout:C}=W(),r=I(),{data:u,isLoading:k}=y({queryKey:["/api/flows"]}),{data:A}=y({queryKey:["/api/agents"]}),x=c({mutationFn:async s=>(await fetch("/api/flows",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})).json(),onSuccess:()=>{r.invalidateQueries({queryKey:["/api/flows"]}),l()}}),h=c({mutationFn:async({id:s,data:t})=>(await fetch(`/api/flows/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json(),onSuccess:()=>{r.invalidateQueries({queryKey:["/api/flows"]}),l()}}),v=c({mutationFn:async s=>(await fetch(`/api/flows/${s}`,{method:"DELETE"})).json(),onSuccess:()=>{r.invalidateQueries({queryKey:["/api/flows"]}),l()}}),p=c({mutationFn:async s=>(await fetch(`/api/flows/${s}/run`,{method:"POST"})).json(),onSuccess:()=>{r.invalidateQueries({queryKey:["/api/flows"]})}}),l=()=>{n({name:"",description:"",agentIds:[],schedule:"",triggerType:"manual",isActive:1}),o(null),m(!1)},T=s=>{o(s),n({name:s.name,description:s.description||"",agentIds:s.agentIds||[],schedule:s.schedule||"",triggerType:s.triggerType,isActive:s.isActive}),m(!1)},F=()=>{m(!0),o(null),n({name:"",description:"",agentIds:[],schedule:"",triggerType:"manual",isActive:1})},S=()=>{d?h.mutate({id:d.id,data:a}):x.mutate(a)},P=s=>{n(t=>({...t,agentIds:t.agentIds.includes(s)?t.agentIds.filter(f=>f!==s):[...t.agentIds,s]}))};return e.jsx(L,{children:e.jsx("section",{className:"py-12 bg-gradient-to-b from-background to-muted/20",children:e.jsx("div",{className:"container px-4 md:px-6",children:e.jsxs("div",{className:"max-w-6xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary/10 text-primary",children:e.jsx(b,{className:"h-8 w-8"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold","data-testid":"flows-title",children:"Flow Configuration"}),e.jsxs("p",{className:"text-muted-foreground","data-testid":"text-flows-count",children:[u?.length||0," workflows configured"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{href:"/admin/agents",children:e.jsxs(i,{variant:"outline",size:"sm",className:"gap-2","data-testid":"nav-agents",children:[e.jsx(E,{className:"h-4 w-4"}),"Agents"]})}),e.jsx(j,{href:"/admin/proposals",children:e.jsxs(i,{variant:"outline",size:"sm",className:"gap-2","data-testid":"nav-proposals",children:[e.jsx(q,{className:"h-4 w-4"}),"Proposals"]})}),e.jsx(j,{href:"/admin/queue",children:e.jsxs(i,{variant:"outline",size:"sm",className:"gap-2","data-testid":"nav-queue",children:[e.jsx($,{className:"h-4 w-4"}),"Queue"]})}),e.jsxs(i,{variant:"outline",size:"sm",onClick:C,className:"gap-2","data-testid":"admin-logout",children:[e.jsx(z,{className:"h-4 w-4"}),"Logout"]})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-[1fr_400px] gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Workflows"}),e.jsxs(i,{onClick:F,size:"sm",className:"gap-2","data-testid":"create-flow",children:[e.jsx(D,{className:"h-4 w-4"}),"New Flow"]})]}),k?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(N,{className:"h-8 w-8 animate-spin text-primary"})}):u?.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground bg-muted/20 rounded-lg",children:[e.jsx(b,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No workflows configured yet"}),e.jsx("p",{className:"text-sm",children:"Create a new flow to get started"})]}):e.jsx("div",{className:"space-y-3",children:u?.map(s=>e.jsx("div",{className:`bg-card rounded-xl border p-4 cursor-pointer transition-all ${d?.id===s.id?"ring-2 ring-primary":"hover:border-primary/50"}`,onClick:()=>T(s),"data-testid":`flow-${s.id}`,children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:s.name}),e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs ${s.isActive?"bg-green-100 text-green-800":"bg-gray-100 text-gray-600"}`,children:s.isActive?"Active":"Inactive"}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs bg-blue-100 text-blue-800",children:s.triggerType})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[s.agentIds?.length||0," agents ⢠",s.runCount," runs",s.lastRunAt&&` ⢠Last run: ${new Date(s.lastRunAt).toLocaleDateString()}`]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(i,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),p.mutate(s.id)},disabled:p.isPending,"data-testid":`run-${s.id}`,children:p.isPending?e.jsx(N,{className:"h-4 w-4 animate-spin"}):e.jsx(M,{className:"h-4 w-4"})}),e.jsx(i,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),v.mutate(s.id)},disabled:v.isPending,className:"text-red-600 hover:text-red-700","data-testid":`delete-${s.id}`,children:e.jsx(Q,{className:"h-4 w-4"})})]})]})},s.id))})]}),(d||w)&&e.jsxs("div",{className:"bg-card rounded-xl border p-6 h-fit sticky top-24","data-testid":"flow-editor",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold",children:d?"Edit Flow":"New Flow"}),e.jsx(i,{variant:"ghost",size:"sm",onClick:l,children:e.jsx(K,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Name"}),e.jsx("input",{type:"text",value:a.name,onChange:s=>n({...a,name:s.target.value}),className:"w-full px-3 py-2 border rounded-lg",placeholder:"Flow name","data-testid":"input-name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Description"}),e.jsx("textarea",{value:a.description,onChange:s=>n({...a,description:s.target.value}),className:"w-full px-3 py-2 border rounded-lg",rows:2,placeholder:"What does this flow do?","data-testid":"input-description"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"Trigger Type"}),e.jsx("div",{className:"space-y-2",children:J.map(s=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"triggerType",value:s.id,checked:a.triggerType===s.id,onChange:t=>n({...a,triggerType:t.target.value}),className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:s.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["- ",s.description]})]},s.id))})]}),a.triggerType==="scheduled"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Schedule (Cron)"}),e.jsx("input",{type:"text",value:a.schedule,onChange:s=>n({...a,schedule:s.target.value}),className:"w-full px-3 py-2 border rounded-lg font-mono text-sm",placeholder:"0 9 * * * (daily at 9 AM)","data-testid":"input-schedule"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm font-medium mb-2 block",children:["Agents (",a.agentIds.length," selected)"]}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1 border rounded-lg p-2",children:A?.agents.map(s=>e.jsxs("label",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.agentIds.includes(s.id
1),onChange:()=>P(s.id),className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.category})]},s.id))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"isActive",checked:a.isActive===1,onChange:s=>n({...a,isActive:s.target.checked?1:0}),className:"h-4 w-4"}),e.jsx("label",{htmlFor:"isActive",className:"text-sm font-medium",children:"Active"})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsxs(i,{onClick:S,disabled:x.isPending||h.isPending||!a.name,className:"flex-1 gap-2","data-testid":"save-flow",children:[x.isPending||h.isPending?e.jsx(N,{className:"h-4 w-4 animate-spin"}):e.jsx(O,{className:"h-4 w-4"}),d?"Update":"Create"]}),e.jsx(i,{variant:"outline",onClick:l,children:"Cancel"})]})]})]})]})]})})})})}function Z(){return e.jsx(R,{children:e.jsx(B,{children:e.jsx(U,{})})})}export{Z 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.