@testver/testver 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/bin/testver.js +8 -1
  2. package/dist/index.js +1309 -781
  3. package/dist/py-agent/__pycache__/testver_appium.cpython-313.pyc +0 -0
  4. package/package.json +7 -6
  5. package/src/ui/static/assets/AIPanel-D09Ni3a4.js +32 -0
  6. package/src/ui/static/assets/AIRecordPanel-DZtUZnRe.js +40 -0
  7. package/src/ui/static/assets/AIStreamUI-BsxKziYG.js +9 -0
  8. package/src/ui/static/assets/AITestGenPage-Cg21-P1W.js +5 -0
  9. package/src/ui/static/assets/APITestingPage-Cdc8EZz2.js +19 -0
  10. package/src/ui/static/assets/AboutPage-yJLCr2_q.js +1 -0
  11. package/src/ui/static/assets/AdvancedPage-DB-6sJ6s.js +3 -0
  12. package/src/ui/static/assets/AnalyticsPage-gTPFsiLZ.js +1 -0
  13. package/src/ui/static/assets/AuditLogPage-DE45E_PV.js +1 -0
  14. package/src/ui/static/assets/ChangesSummary-C-7oi_sx.js +2 -0
  15. package/src/ui/static/assets/CodeMapPage-DgU6ZYBO.js +3 -0
  16. package/src/ui/static/assets/ConfirmDialog-DNU3qoAP.js +1 -0
  17. package/src/ui/static/assets/CoveragePage-BpTjgcdV.js +2 -0
  18. package/src/ui/static/assets/CronBuilder-DsnX-vRr.js +1 -0
  19. package/src/ui/static/assets/Dashboard-DRWbVyTb.js +1 -0
  20. package/src/ui/static/assets/DefectsPage-BtMNbq6Z.js +72 -0
  21. package/src/ui/static/assets/DiffViewer-DPglzjPH.js +2 -0
  22. package/src/ui/static/assets/EmptyState-BH_aDO0P.js +1 -0
  23. package/src/ui/static/assets/ExportButton-Ce_MxnM1.js +1 -0
  24. package/src/ui/static/assets/FileViewer-iYL0lxyY.js +18 -0
  25. package/src/ui/static/assets/GitPage-CQqV8JBC.js +12 -0
  26. package/src/ui/static/assets/ImportExportPage-DXk7Koaq.js +36 -0
  27. package/src/ui/static/assets/JiraPushDialog-CqftoLh8.js +1 -0
  28. package/src/ui/static/assets/LiveExecutionView-BD0wE8sz.js +1 -0
  29. package/src/ui/static/assets/ManagePage-B8iG6Q0B.js +1 -0
  30. package/src/ui/static/assets/MediaModal-DiSINwmh.js +1 -0
  31. package/src/ui/static/assets/MobileRunPicker-BNs2lZFf.js +1 -0
  32. package/src/ui/static/assets/MobileRunTarget-D2Nqcj10.js +6 -0
  33. package/src/ui/static/assets/ModuleExplorer-BmkoQrHb.js +1 -0
  34. package/src/ui/static/assets/OutputPage-Dcsr7cmr.js +1 -0
  35. package/src/ui/static/assets/PipelinesPanel-CMMXCSda.js +1 -0
  36. package/src/ui/static/assets/ProfilePage-ByshrcwC.js +1 -0
  37. package/src/ui/static/assets/ProjectExplorer-B9B___ij.js +1 -0
  38. package/src/ui/static/assets/RemoteFileStrip-DbPnaZ-v.js +1 -0
  39. package/src/ui/static/assets/ReportCard-BbNfk85h.js +2 -0
  40. package/src/ui/static/assets/ReportFullView-Cg1rggho.js +1 -0
  41. package/src/ui/static/assets/ReportsPage-CFv3OAhe.js +48 -0
  42. package/src/ui/static/assets/ResultsPage-B4LwZH-R.js +115 -0
  43. package/src/ui/static/assets/RunTargets-C7Vqd4TU.js +1 -0
  44. package/src/ui/static/assets/ScriptMappingPage-BrANeHv0.js +1 -0
  45. package/src/ui/static/assets/SearchableDevicePicker-CFJ_DUAA.js +1 -0
  46. package/src/ui/static/assets/SettingsPage-BwOiebKG.js +83 -0
  47. package/src/ui/static/assets/SharedReportView-BAbW1WOs.js +1 -0
  48. package/src/ui/static/assets/SourcesPage-C_QVQwiA.js +14 -0
  49. package/src/ui/static/assets/TestExplorerPage-BRRWtwde.js +7 -0
  50. package/src/ui/static/assets/TestManagementPage-Ch4PthuU.js +10 -0
  51. package/src/ui/static/assets/TestPlansPage-Bno2vpGd.js +5 -0
  52. package/src/ui/static/assets/TestverCreditsDetail-cSW0SpNx.js +1 -0
  53. package/src/ui/static/assets/TestverCreditsRing-CUsMGEe3.js +1 -0
  54. package/src/ui/static/assets/UncommittedDiffViewer-B5HSURk8.js +2 -0
  55. package/src/ui/static/assets/UserManagementPage-BjY3ftxf.js +10 -0
  56. package/src/ui/static/assets/WorkflowsPage-BUu-LjZ8.js +83 -0
  57. package/src/ui/static/assets/aiHandoff-vhtR29Fh.js +1 -0
  58. package/src/ui/static/assets/ansiToHtml-DYRzYQV1.js +1 -0
  59. package/src/ui/static/assets/dark-logo-DCPcGDyT.svg +1 -0
  60. package/src/ui/static/assets/excel-BrxuVus5.js +1 -0
  61. package/src/ui/static/assets/formatDate-T65-Y6Mi.js +1 -0
  62. package/src/ui/static/assets/formatTestName-BKd2Uqhs.js +1 -0
  63. package/src/ui/static/assets/hiddenLlmProviders-setxgY_B.js +1 -0
  64. package/src/ui/static/assets/index-B0klHYbO.css +1 -0
  65. package/src/ui/static/assets/index-DpQhqcHv.js +11 -0
  66. package/src/ui/static/assets/index-DtBWNlVD.js +47 -0
  67. package/src/ui/static/assets/logo-C7ltqfpq.svg +1 -0
  68. package/src/ui/static/assets/runSelected-WlgnZcSF.js +1 -0
  69. package/src/ui/static/assets/sandboxStorage-BrzaG3ny.js +1 -0
  70. package/src/ui/static/assets/simpleMarkdown-kWs-10D8.js +5 -0
  71. package/src/ui/static/assets/useChartTheme-BFz2QcND.js +1 -0
  72. package/src/ui/static/assets/useDebouncedValue-BsHptIvX.js +1 -0
  73. package/src/ui/static/assets/useFeatureFlags-DqhngqgG.js +1 -0
  74. package/src/ui/static/assets/useJiraConnector-TM1Rfj1s.js +1 -0
  75. package/src/ui/static/assets/useOwnership-eW6Egd7X.js +1 -0
  76. package/src/ui/static/assets/useSuites-CvtMGakZ.js +1 -0
  77. package/src/ui/static/assets/useTabParam-ChbOedP1.js +1 -0
  78. package/src/ui/static/assets/useTestExplorer-HqvURJAc.js +1 -0
  79. package/src/ui/static/assets/useTestLifecycle-CL7-zz0Q.js +1 -0
  80. package/src/ui/static/assets/useTestManagement-ZTA1_VUm.js +2 -0
  81. package/src/ui/static/assets/useTestResults-Bm-JyMhB.js +1 -0
  82. package/src/ui/static/assets/vendor-charts-DWFQlmCz.js +73 -0
  83. package/src/ui/static/assets/vendor-excel-BFHGVHVC.js +24 -0
  84. package/src/ui/static/assets/vendor-flow-BnuhLJ6X.css +1 -0
  85. package/src/ui/static/assets/vendor-flow-YGpC9U9I.js +23 -0
  86. package/src/ui/static/assets/vendor-icons-B0wLOBoh.js +1421 -0
  87. package/src/ui/static/assets/vendor-query-BrzmPFT3.js +1 -0
  88. package/src/ui/static/assets/vendor-quill-CTpA5PSA.css +7 -0
  89. package/src/ui/static/assets/{index-Dy7b6SNH.js → vendor-quill-W-RoQfb6.js} +1 -1
  90. package/src/ui/static/assets/vendor-react-CTbHBddL.js +61 -0
  91. package/src/ui/static/assets/visibleInterval-BKsLfJZ3.js +1 -0
  92. package/src/ui/static/dark-logo.svg +1 -1
  93. package/src/ui/static/index.html +5 -2
  94. package/src/ui/static/logo.svg +1 -1
  95. package/src/ui/static/assets/dark-logo-BddlJH8z.svg +0 -1
  96. package/src/ui/static/assets/index-Bt4_s1e0.css +0 -7
  97. package/src/ui/static/assets/index-C9pBWd6z.js +0 -2250
  98. package/src/ui/static/assets/logo-DwQCjTm_.svg +0 -1
@@ -0,0 +1,83 @@
1
+ import{r,j as e,n as Ma}from"./vendor-react-CTbHBddL.js";import{f as wt,a as Oa}from"./formatDate-T65-Y6Mi.js";import{u as la}from"./useTabParam-ChbOedP1.js";import{a5 as Ta,fZ as Aa,f_ as Da,a6 as Pa,f$ as gs,g0 as bs,g1 as ys,g2 as La,g3 as Ra,g4 as Wa,g5 as Ya,g6 as Fa,g7 as _a,g8 as Xa,g9 as Ha,ga as Ba,gb as Ua,gc as is,gd as Ga,b as Va,ge as Wt,gf as Rs,gg as Ae,gh as Ka,gi as Ja,gj as Za,gk as qa,gl as Qa,gm as er,gn as tr,go as sr}from"./index-DtBWNlVD.js";import{b5 as Ct,a8 as He,av as St,ag as zt,Z as Re,da as $t,G as Et,ab as Je,by as Ze,b4 as qe,a7 as kt,cT as ia,b9 as lt,a3 as be,ak as Se,X as he,db as oa,bb as ca,u as ke,b6 as Ie,aZ as ar,aY as rr,aW as nr,ar as lr,dc as ir,dd as or,al as Xe,ax as cr,cg as dr,v as ot,b2 as xr,b8 as da,o as Ne,ap as Ws,y as Ee,t as Ce,cR as Yt,co as _e,cn as xa,a5 as os,bT as ur,b0 as fs,k as js,a2 as mr,a as qt,bd as Qt,S as nt,d as vt,cH as Ys,cI as Fs,cW as ua,R as pr,cu as _s,bP as hr,a9 as fr,aL as gr,C as ma,ce as br,D as yr,be as Ft,E as jr,c8 as cs,bB as Nr,ae as vr,bz as Xs,a1 as ds,cz as wr}from"./vendor-icons-B0wLOBoh.js";import{A as Ns}from"./AIStreamUI-BsxKziYG.js";import{R as bt,j as kr,h as _t,X as Xt,Y as Ht,T as yt,L as Cr,k as Sr,A as zr,B as Hs,l as Bs,P as $r,m as Er,n as Ir}from"./vendor-charts-DWFQlmCz.js";import"./vendor-query-BrzmPFT3.js";function it(t){return t.type?t.type:t.skill?"skill":t.tool||t.command?"tool":t.mcp?"mcp":t.if!==void 0?"condition":t.forEach?"loop":t.parallelSteps?"parallel":t.message&&!t.skill&&!t.tool&&!t.mcp?"checkpoint":t.waitSeconds!==void 0?"delay":t.workflowId?"subworkflow":t.script?"script":"tool"}const Me={skill:{label:"Skill",iconName:"Brain",description:"Invoke a skill with LLM reasoning",category:"actions",color:"purple",bgClass:"bg-purple-500/15",borderClass:"border-purple-500/30",textClass:"text-purple-400",accentColor:"#a855f7"},tool:{label:"Tool",iconName:"Wrench",description:"Call a built-in tool directly",category:"actions",color:"cyan",bgClass:"bg-cyan-500/15",borderClass:"border-cyan-500/30",textClass:"text-cyan-400",accentColor:"#22d3ee"},mcp:{label:"MCP",iconName:"Plug",description:"Call an MCP server tool",category:"actions",color:"emerald",bgClass:"bg-emerald-500/15",borderClass:"border-emerald-500/30",textClass:"text-emerald-400",accentColor:"#34d399"},condition:{label:"Condition",iconName:"GitBranch",description:"If/else branching logic",category:"flow",color:"amber",bgClass:"bg-amber-500/15",borderClass:"border-amber-500/30",textClass:"text-amber-400",accentColor:"#f59e0b"},loop:{label:"Loop",iconName:"Repeat",description:"Iterate over a list",category:"flow",color:"blue",bgClass:"bg-blue-500/15",borderClass:"border-blue-500/30",textClass:"text-blue-400",accentColor:"#3b82f6"},parallel:{label:"Parallel",iconName:"Zap",description:"Run steps concurrently",category:"flow",color:"yellow",bgClass:"bg-yellow-500/15",borderClass:"border-yellow-500/30",textClass:"text-yellow-400",accentColor:"#eab308"},checkpoint:{label:"Checkpoint",iconName:"ShieldCheck",description:"Pause for human approval",category:"utilities",color:"orange",bgClass:"bg-orange-500/15",borderClass:"border-orange-500/30",textClass:"text-orange-400",accentColor:"#f97316"},delay:{label:"Delay",iconName:"Timer",description:"Wait for duration or condition",category:"utilities",color:"gray",bgClass:"bg-gray-500/15",borderClass:"border-gray-500/30",textClass:"text-gray-400",accentColor:"#6b7280"},subworkflow:{label:"Sub-Workflow",iconName:"Workflow",description:"Embed another workflow",category:"utilities",color:"pink",bgClass:"bg-pink-500/15",borderClass:"border-pink-500/30",textClass:"text-pink-400",accentColor:"#ec4899"},script:{label:"Script",iconName:"FileCode",description:"Run custom JavaScript",category:"actions",color:"teal",bgClass:"bg-teal-500/15",borderClass:"border-teal-500/30",textClass:"text-teal-400",accentColor:"#14b8a6"}},xs=260,Us=80,us=50,Mr=80,Bt=60;function Or(t){if(t.length===0)return{nodes:[],edges:[],width:0,height:0};const s=new Map(t.map(l=>[l.id,l])),n=new Map;function o(l,M=new Set){if(n.has(l))return n.get(l);if(M.has(l))return 0;M.add(l);const h=s.get(l);if(!(h!=null&&h.dependsOn)||h.dependsOn.length===0)return n.set(l,0),0;const u=Math.max(...h.dependsOn.map(D=>s.has(D)?o(D,M)+1:0));return n.set(l,u),u}for(const l of t)o(l.id);const w=new Map;for(const[l,M]of n)w.has(M)||w.set(M,[]),w.get(M).push(l);const j=Math.max(...n.values(),0),d=[];for(let l=0;l<=j;l++){const M=w.get(l)??[];M.length*(xs+us)-us;const h=Bt;M.forEach((u,D)=>{const O=s.get(u);d.push({id:u,step:O,x:h+D*(xs+us),y:Bt+l*(Us+Mr),width:xs,height:Us,layer:l,column:D})})}const $=new Map(d.map(l=>[l.id,l])),I=[];for(const l of t)if(l.dependsOn)for(const M of l.dependsOn){const h=$.get(M),u=$.get(l.id);h&&u&&I.push({from:M,to:l.id,fromX:h.x+h.width/2,fromY:h.y+h.height,toX:u.x+u.width/2,toY:u.y})}const E=Math.max(...d.map(l=>l.x+l.width),0)+Bt,k=Math.max(...d.map(l=>l.y+l.height),0)+Bt;return{nodes:d,edges:I,width:E,height:k}}function ms(t){switch(t){case"completed":return{bg:"bg-emerald-500/15",text:"text-emerald-400",border:"border-emerald-500/30"};case"running":return{bg:"bg-cyan-500/15",text:"text-cyan-400",border:"border-cyan-500/30"};case"failed":return{bg:"bg-red-500/15",text:"text-red-400",border:"border-red-500/30"};case"skipped":return{bg:"bg-gray-500/15",text:"text-gray-400",border:"border-gray-500/30"};case"waiting":return{bg:"bg-amber-500/15",text:"text-amber-400",border:"border-amber-500/30"};case"pending":return{bg:"bg-surface-2",text:"text-gray-500",border:"border-white/5"};default:return{bg:"bg-surface-2",text:"text-gray-500",border:"border-white/5"}}}function je(t){if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(1)}s`;const s=Math.floor(t/6e4),n=Math.round(t%6e4/1e3);return`${s}m ${n}s`}const Tr={Brain:qe,Wrench:Ze,Plug:Je,GitBranch:Et,Repeat:$t,Zap:Re,ShieldCheck:zt,Timer:St,Workflow:He,FileCode:Ct};function Ar({node:t,selected:s,stepStatus:n,stepDuration:o,onClick:w,onDelete:j,onToggleDisable:d,onExecuteStep:$,readOnly:I,isConnecting:E,isDragging:k,onDragStart:l}){const[M,h]=r.useState(!1),u=it(t.step),D=Me[u],O=n||"pending",c=O==="running",z=O==="completed",C=O==="failed",L=O==="skipped",m=O==="waiting",g=!!t.step.disabled,F=t.step.description||t.step.action||t.step.command||t.step.skill||t.step.tool||t.step.mcp||t.id,V=F.length>30?F.slice(0,27)+"...":F,N=Tr[D.iconName],B=C?"#ef4444":z?"#34d399":c?"#22d3ee":D.accentColor;return e.jsx("div",{className:`absolute ${k?"z-50":""}`,style:{left:t.x,top:t.y,width:t.width,height:t.height,opacity:k?.85:void 0,cursor:k?"grabbing":void 0},onMouseEnter:()=>h(!0),onMouseLeave:()=>{h(!1)},children:e.jsxs("div",{className:"relative",children:[M&&!I&&!E&&e.jsxs("div",{className:"absolute z-20 flex items-center gap-0.5 bg-surface-1 border border-white/10 rounded-lg p-0.5 shadow-lg shadow-black/30",style:{animation:"fadeIn 0.15s ease-out",top:-4,right:-4},onMouseDown:v=>v.stopPropagation(),children:[$&&e.jsx("button",{onClick:v=>{v.stopPropagation(),$(t.id)},className:"p-1 rounded hover:bg-emerald-500/20 text-gray-400 hover:text-emerald-400 transition-colors",title:"Execute step",children:e.jsx(kt,{size:12})}),d&&e.jsx("button",{onClick:v=>{v.stopPropagation(),d(t.id)},className:`p-1 rounded hover:bg-amber-500/20 transition-colors ${g?"text-amber-400":"text-gray-400 hover:text-amber-400"}`,title:g?"Enable step":"Disable step",children:e.jsx(ia,{size:12})}),j&&e.jsx("button",{onClick:v=>{v.stopPropagation(),j(t.id)},className:"p-1 rounded hover:bg-red-500/20 text-gray-400 hover:text-red-400 transition-colors",title:"Delete step",children:e.jsx(lt,{size:12})})]}),e.jsx("div",{onMouseDown:v=>{l&&!I&&l(t.id,v)},style:{height:t.height,borderColor:k||s?void 0:B,borderWidth:"1px"},className:`w-full flex rounded-xl overflow-hidden transition-all duration-150
2
+ ${k?"ring-2 ring-cyan-400/60 !border-cyan-500/50 shadow-2xl shadow-cyan-500/20 cursor-grabbing":l&&!I?"cursor-grab":"cursor-pointer"}
3
+ ${!k&&s?"ring-2 ring-cyan-400/50 !border-cyan-500/50 shadow-lg shadow-cyan-500/10":!k&&M?"shadow-lg shadow-black/30":k?"":"shadow-md shadow-black/20"}
4
+ ${c?"wf-node-running":""}
5
+ ${g?"opacity-40 grayscale":""}
6
+ bg-surface-1`,onClick:()=>w(t.id),children:e.jsxs("div",{className:"flex-1 flex flex-col justify-center px-3 py-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${D.bgClass}`,style:{boxShadow:`0 0 0 1px ${B}20`},children:N&&e.jsx(N,{size:16,className:D.textClass})}),e.jsx("span",{className:"text-[13px] font-semibold text-gray-200 truncate flex-1",children:t.id}),e.jsxs("span",{className:"shrink-0",children:[c&&e.jsx(be,{size:15,className:"animate-spin text-cyan-400"}),z&&e.jsx(Se,{size:15,className:"text-emerald-400"}),C&&e.jsx(he,{size:15,className:"text-red-400"}),L&&e.jsx(oa,{size:15,className:"text-gray-500"}),m&&e.jsx(ca,{size:15,className:"text-amber-400"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md font-medium ${D.bgClass} ${D.textClass}`,children:D.label}),e.jsx("span",{className:"text-[11px] text-gray-500 truncate flex-1",title:F,children:V}),o!==void 0&&o>0&&e.jsxs("span",{className:"text-[10px] text-gray-600 flex items-center gap-0.5 shrink-0",children:[e.jsx(ke,{size:9}),je(o)]})]})]})})]})})}const Ut=180,Gt=120,Vt=12,Dr=({nodes:t,canvasWidth:s,canvasHeight:n,viewportWidth:o,viewportHeight:w,pan:j,zoom:d,onPanTo:$})=>{const I=r.useRef(null),E=r.useMemo(()=>{if(t.length===0)return{minX:0,minY:0,maxX:s,maxY:n};let m=1/0,g=1/0,F=-1/0,V=-1/0;for(const N of t)m=Math.min(m,N.x),g=Math.min(g,N.y),F=Math.max(F,N.x+N.width),V=Math.max(V,N.y+N.height);return m=Math.min(m,0),g=Math.min(g,0),F=Math.max(F,s),V=Math.max(V,n),{minX:m-Vt,minY:g-Vt,maxX:F+Vt,maxY:V+Vt}},[t,s,n]),k=E.maxX-E.minX,l=E.maxY-E.minY,M=Math.min(Ut/k,Gt/l),h=m=>(m-E.minX)*M,u=m=>(m-E.minY)*M,D=-j.x/d,O=-j.y/d,c=o/d,z=w/d,C=r.useCallback(m=>{const g=I.current;if(!g)return;const F=g.getBoundingClientRect(),V=m.clientX-F.left,N=m.clientY-F.top,B=V/M+E.minX,v=N/M+E.minY,A=-(B-c/2)*d,J=-(v-z/2)*d;$(A,J)},[M,E,c,z,d,$]),L=r.useMemo(()=>t.map(m=>{const g=it(m.step),F=Me[g],V=Math.max(m.width*M,4),N=Math.max(m.height*M,3);return{key:m.id,x:h(m.x),y:u(m.y),w:V,h:N,color:F.accentColor}}),[t,M,E]);return e.jsx("div",{className:"absolute bottom-4 right-4 z-30 select-none bg-surface-1/90 backdrop-blur-sm border border-white/10 rounded-lg overflow-hidden shadow-lg",style:{width:Ut,height:Gt},children:e.jsxs("svg",{ref:I,width:Ut,height:Gt,className:"cursor-crosshair",onClick:C,children:[e.jsx("rect",{width:Ut,height:Gt,fill:"transparent"}),L.map(m=>e.jsx("rect",{x:m.x,y:m.y,width:m.w,height:m.h,rx:1,fill:m.color,opacity:.85},m.key)),e.jsx("rect",{x:h(D),y:u(O),width:c*M,height:z*M,fill:"none",stroke:"#22d3ee",strokeWidth:1.5,strokeDasharray:"4 2",rx:2,opacity:.9})]})})},Pr={Brain:qe,Wrench:Ze,Plug:Je,GitBranch:Et,Repeat:$t,Zap:Re,ShieldCheck:zt,Timer:St,Workflow:He,FileCode:Ct},Gs=[{type:"skill",label:"Skill Step"},{type:"tool",label:"Tool Step"},{type:"mcp",label:"MCP Step"},{type:"condition",label:"Condition"},{type:"loop",label:"Loop"},{type:"parallel",label:"Parallel"},{type:"checkpoint",label:"Checkpoint"},{type:"delay",label:"Delay"},{type:"subworkflow",label:"Sub-Workflow"},{type:"script",label:"Script"}];function Lr({steps:t,selectedStepId:s,activeRun:n,onSelectStep:o,onAddStep:w,onDeleteStep:j,onToggleDisable:d,onDuplicateStep:$,onAddConnection:I,onRemoveConnection:E,onRemoveAndReconnect:k,readOnly:l}){var oe,mt;const M=r.useRef(null),h=r.useMemo(()=>Or(t),[t]),[u,D]=r.useState({}),O=r.useRef(t);r.useEffect(()=>{O.current!==t&&(D({}),O.current=t)},[t]);const c=r.useMemo(()=>{const p=h.nodes.map(ce=>{const ve=u[ce.id];return ve?{...ce,x:ve.x,y:ve.y}:ce}),q=new Map(p.map(ce=>[ce.id,ce])),Q=h.edges.map(ce=>{const ve=q.get(ce.from),Oe=q.get(ce.to);return ve&&Oe?{...ce,fromX:ve.x+ve.width/2,fromY:ve.y+ve.height,toX:Oe.x+Oe.width/2,toY:Oe.y}:ce}),fe=p.length>0?Math.max(...p.map(ce=>ce.x+ce.width))+60:h.width,pe=p.length>0?Math.max(...p.map(ce=>ce.y+ce.height))+60:h.height;return{nodes:p,edges:Q,width:fe,height:pe}},[h,u]),[z,C]=r.useState(1),[L,m]=r.useState({x:0,y:0}),[g,F]=r.useState(!1),[V,N]=r.useState(!1),B=r.useRef({x:0,y:0,panX:0,panY:0}),[v,A]=r.useState(null),J=r.useRef({x:0,y:0,nodeX:0,nodeY:0}),ne=r.useRef(!1),[ue,b]=r.useState(null),[H,le]=r.useState(null),[me,ye]=r.useState(null),[we,S]=r.useState(!1),[T,G]=r.useState(void 0),[re,y]=r.useState(null),[_,X]=r.useState(null),[U,Z]=r.useState(null),[f,P]=r.useState(!0),[K,ie]=r.useState(!1),ct=r.useCallback(()=>C(p=>Math.min(p+.15,2.5)),[]),It=r.useCallback(()=>C(p=>Math.max(p-.15,.3)),[]),Be=r.useCallback(()=>{C(1),m({x:0,y:0})},[]),Mt=r.useCallback(()=>{if(!M.current)return;const p=M.current,q=(p.clientWidth-80)/(c.width||1),Q=(p.clientHeight-80)/(c.height||1),fe=Math.min(Math.max(Math.min(q,Q),.3),1.5);C(fe);const pe=(p.clientWidth-c.width*fe)/2,ce=(p.clientHeight-c.height*fe)/2;m({x:Math.max(0,pe),y:Math.max(0,ce)})},[c.width,c.height]),es=r.useCallback(p=>{p.preventDefault();const q=p.deltaY>0?-.08:.08;C(Q=>Math.min(Math.max(Q+q,.3),2.5))},[]),Fe=r.useCallback(p=>{if(v)return;const q=p.target,Q=q!==p.currentTarget&&q.closest("[data-node-wrapper]");(p.button===1||p.button===0&&(!Q||V))&&(F(!0),B.current={x:p.clientX,y:p.clientY,panX:L.x,panY:L.y},b(null))},[L,V,v]),Ue=r.useCallback(p=>{if(v&&M.current){const q=(p.clientX-J.current.x)/z,Q=(p.clientY-J.current.y)/z;(Math.abs(q)>3||Math.abs(Q)>3)&&(ne.current=!0),D(fe=>({...fe,[v]:{x:J.current.nodeX+q,y:J.current.nodeY+Q}}));return}if(g&&m({x:B.current.panX+(p.clientX-B.current.x),y:B.current.panY+(p.clientY-B.current.y)}),H&&M.current){const q=M.current.getBoundingClientRect();ye({x:(p.clientX-q.left-L.x)/z,y:(p.clientY-q.top-L.y)/z})}},[g,H,L,z,v]),Qe=r.useCallback(()=>{F(!1),A(null),H&&(le(null),ye(null))},[H]),et=r.useCallback((p,q)=>{if(l||V)return;q.stopPropagation(),q.preventDefault();const Q=c.nodes.find(fe=>fe.id===p);Q&&(ne.current=!1,A(p),J.current={x:q.clientX,y:q.clientY,nodeX:Q.x,nodeY:Q.y})},[l,V,c.nodes]),Ge=r.useCallback(p=>{l||!w||p.dataTransfer.types.includes("application/x-workflow-step-type")&&(p.preventDefault(),p.dataTransfer.dropEffect="copy",ie(!0))},[l,w]),Ve=r.useCallback(()=>{ie(!1)},[]),dt=r.useCallback(p=>{if(ie(!1),l||!w)return;const q=p.dataTransfer.getData("application/x-workflow-step-type");q&&(p.preventDefault(),w(q))},[l,w]);r.useEffect(()=>{function p(Q){Q.target instanceof HTMLInputElement||Q.target instanceof HTMLTextAreaElement||Q.target instanceof HTMLSelectElement||(Q.key===" "&&(Q.preventDefault(),N(!0)),Q.key==="Escape"&&(b(null),S(!1),Z(null),o("")),(Q.key==="Delete"||Q.key==="Backspace")&&s&&j&&!l&&(Q.preventDefault(),j(s)),Q.key==="d"&&(Q.ctrlKey||Q.metaKey)&&s&&$&&!l&&(Q.preventDefault(),$(s)),Q.key==="Tab"&&!l&&w&&(Q.preventDefault(),G(void 0),S(!0)))}function q(Q){Q.key===" "&&N(!1)}return window.addEventListener("keydown",p),window.addEventListener("keyup",q),()=>{window.removeEventListener("keydown",p),window.removeEventListener("keyup",q)}},[s,j,$,l,w,o]);const ts=r.useCallback((p,q)=>{p.preventDefault(),p.stopPropagation(),!l&&b({x:p.clientX,y:p.clientY,stepId:q})},[l]),xt=r.useCallback(p=>{l||le(p)},[l]),ss=r.useCallback(p=>{H&&H!==p&&I&&I(H,p),le(null),ye(null)},[H,I]),Ot=r.useCallback(p=>{re&&I&&E?(E(re.from,re.to),w==null||w(p,re.from)):w==null||w(p,T),S(!1),G(void 0),y(null)},[w,T,re,I,E]),Tt=r.useCallback(p=>{Z(null),p.target===p.currentTarget&&(b(null),S(!1))},[]),At=r.useCallback((p,q)=>{m({x:p,y:q})},[]),ze=H?c.nodes.find(p=>p.id===H):null,tt=((oe=M.current)==null?void 0:oe.clientWidth)||800,ut=((mt=M.current)==null?void 0:mt.clientHeight)||600;return t.length===0?e.jsxs("div",{className:"flex-1 flex items-center justify-center relative overflow-hidden",style:{backgroundColor:"var(--canvas-bg)",backgroundImage:"radial-gradient(circle, var(--canvas-dot) 1px, transparent 1px)",backgroundSize:"20px 20px"},onDragOver:Ge,onDragLeave:Ve,onDrop:dt,children:[K&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-cyan-500/5 border-2 border-dashed border-cyan-500/30 rounded-xl pointer-events-none",children:e.jsx("div",{className:"text-cyan-400 text-sm font-medium",children:"Drop to add step"})}),e.jsxs("div",{className:"text-center max-w-md",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-surface-1 border border-white/10 flex items-center justify-center mx-auto mb-5 shadow-lg shadow-black/20",children:e.jsx(He,{size:28,className:"text-cyan-400"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-200 mb-2",children:"Start building your workflow"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:"Drag steps from the palette or click to add"}),!l&&w&&e.jsx("div",{className:"flex items-center justify-center gap-3",children:e.jsxs("button",{onClick:()=>{G(void 0),S(!0)},className:"px-4 py-2.5 bg-cyan-600 hover:bg-cyan-500 text-white rounded-lg text-sm inline-flex items-center gap-2 shadow-lg shadow-cyan-600/20 transition-colors",children:[e.jsx(Ie,{size:16})," Add First Step"]})})]})]}):e.jsxs("div",{ref:M,className:"flex-1 overflow-hidden relative",style:{cursor:v||g?"grabbing":V?"grab":H?"crosshair":"default",backgroundColor:"var(--canvas-bg)",backgroundImage:"radial-gradient(circle, var(--canvas-dot) 1px, transparent 1px)",backgroundSize:`${20*z}px ${20*z}px`,backgroundPosition:`${L.x}px ${L.y}px`},onWheel:es,onMouseDown:Fe,onMouseMove:Ue,onMouseUp:Qe,onClick:Tt,onContextMenu:p=>{p.preventDefault()},onDragOver:Ge,onDragLeave:Ve,onDrop:dt,children:[K&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center pointer-events-none",children:e.jsx("div",{className:"px-4 py-2 bg-cyan-500/10 border border-cyan-500/30 rounded-xl text-cyan-400 text-sm font-medium backdrop-blur-sm",children:"Drop to add step"})}),e.jsxs("div",{className:"absolute top-3 right-3 z-20 flex flex-col items-center gap-0.5 bg-surface-1 backdrop-blur-sm border border-white/10 rounded-xl p-1 shadow-lg shadow-black/20",children:[e.jsx("button",{onClick:ct,className:"p-1.5 hover:bg-surface-3/50 rounded-lg transition-all",title:"Zoom in",children:e.jsx(ar,{size:15,className:"text-gray-400"})}),e.jsxs("span",{className:"text-xs text-gray-500 font-mono py-0.5 select-none w-10 text-center",children:[Math.round(z*100),"%"]}),e.jsx("button",{onClick:It,className:"p-1.5 hover:bg-surface-3/50 rounded-lg transition-all",title:"Zoom out",children:e.jsx(rr,{size:15,className:"text-gray-400"})}),e.jsx("div",{className:"w-6 h-px bg-white/10 my-0.5"}),e.jsx("button",{onClick:Mt,className:"p-1.5 hover:bg-surface-3/50 rounded-lg transition-all",title:"Fit to view",children:e.jsx(nr,{size:15,className:"text-gray-400"})}),e.jsx("button",{onClick:Be,className:"p-1.5 hover:bg-surface-3/50 rounded-lg transition-all",title:"Reset zoom (100%)",children:e.jsx(lr,{size:14,className:"text-gray-400"})}),e.jsx("div",{className:"w-6 h-px bg-white/10 my-0.5"}),e.jsx("button",{onClick:()=>P(p=>!p),className:`p-1.5 rounded-lg transition-all ${f?"bg-cyan-500/15 text-cyan-400":"hover:bg-surface-3/50 text-gray-400"}`,title:"Toggle minimap",children:e.jsx(ir,{size:14})})]}),!l&&w&&e.jsx("div",{className:"absolute top-3 left-3 z-20",children:e.jsx("button",{onClick:()=>{G(void 0),y(null),S(!we)},className:"p-2.5 bg-cyan-600 hover:bg-cyan-500 text-white rounded-xl shadow-lg shadow-cyan-600/20 transition-colors",title:"Add step (Tab)",children:e.jsx(Ie,{size:18})})}),e.jsx("div",{style:{position:"relative",transform:`translate(${L.x}px, ${L.y}px) scale(${z})`,transformOrigin:"0 0",width:c.width+100,height:c.height+100,transition:g||v?"none":"transform 0.08s ease-out"},children:e.jsxs("div",{className:"relative",style:{width:c.width+100,height:c.height+100},children:[c.nodes.map(p=>{const q=n==null?void 0:n.stepResults[p.id],Q=v===p.id;return e.jsxs("div",{"data-node-wrapper":"true",onContextMenu:fe=>ts(fe,p.id),onMouseUp:()=>{H&&H!==p.id&&ss(p.id)},style:{zIndex:Q?50:1},children:[e.jsx(Ar,{node:p,selected:s===p.id,stepStatus:q==null?void 0:q.status,stepDuration:q==null?void 0:q.duration,onClick:fe=>{if(ne.current){ne.current=!1;return}o(fe)},onDelete:l?void 0:j,onToggleDisable:l?void 0:d,readOnly:l,isConnecting:!!H,isDragging:Q,onDragStart:l?void 0:et}),!l&&I&&e.jsx("div",{className:`absolute w-3 h-3 rounded-full border-2 transition-all duration-150 z-10
7
+ ${H?"border-gray-600 bg-surface-2":"border-gray-500 bg-surface-2 hover:border-cyan-400 hover:bg-cyan-500/20 hover:scale-125"}`,style:{left:p.x+p.width/2-6,top:p.y+p.height-3,cursor:"crosshair"},title:"Drag to connect",onMouseDown:fe=>{fe.stopPropagation(),xt(p.id)}}),!l&&H&&H!==p.id&&e.jsx("div",{className:"absolute w-3.5 h-3.5 rounded-full bg-cyan-500/20 border-2 border-cyan-400 z-10",style:{left:p.x+p.width/2-7,top:p.y-5,animation:"portPulse 1.5s ease-in-out infinite"}}),!l&&!H&&p.step.dependsOn&&p.step.dependsOn.length>0&&e.jsx("div",{className:"absolute w-3 h-3 rounded-full border-2 border-gray-600 bg-surface-2 z-10",style:{left:p.x+p.width/2-6,top:p.y-4}})]},p.id)}),e.jsxs("svg",{style:{position:"absolute",top:0,left:0,width:c.width+100,height:c.height+100,pointerEvents:"none",overflow:"visible",zIndex:2},children:[e.jsxs("defs",{children:[e.jsx("marker",{id:"arrow-default",markerWidth:"10",markerHeight:"8",refX:"5",refY:"4",orient:"auto",markerUnits:"userSpaceOnUse",children:e.jsx("polygon",{points:"0 0, 10 4, 0 8",fill:"#9ca3af"})}),e.jsx("marker",{id:"arrow-active",markerWidth:"10",markerHeight:"8",refX:"5",refY:"4",orient:"auto",markerUnits:"userSpaceOnUse",children:e.jsx("polygon",{points:"0 0, 10 4, 0 8",fill:"#22D3EE"})}),e.jsx("marker",{id:"arrow-hover",markerWidth:"10",markerHeight:"8",refX:"5",refY:"4",orient:"auto",markerUnits:"userSpaceOnUse",children:e.jsx("polygon",{points:"0 0, 10 4, 0 8",fill:"#EF4444"})})]}),c.edges.map((p,q)=>{var Pt,Lt;const Q=(Pt=n==null?void 0:n.stepResults[p.from])==null?void 0:Pt.status,fe=(Lt=n==null?void 0:n.stepResults[p.to])==null?void 0:Lt.status,pe=Q==="completed"||Q==="running",ce=Q==="completed"&&(fe==="running"||fe==="pending"),ve=`${p.from}->${p.to}`,Oe=Math.abs(p.toY-p.fromY),pt=Math.abs(p.toX-p.fromX),ht=Math.max(Oe*.5,pt*.3,40),Te=`M ${p.fromX} ${p.fromY} C ${p.fromX} ${p.fromY+ht}, ${p.toX} ${p.toY-ht}, ${p.toX} ${p.toY-6}`,Dt=(p.fromX+p.toX)/2,xe=(p.fromY+p.toY)/2;return e.jsxs("g",{children:[!l&&e.jsx("path",{d:Te,fill:"none",stroke:"transparent",strokeWidth:16,style:{cursor:"pointer",pointerEvents:"stroke"},onMouseEnter:()=>X(ve),onMouseLeave:()=>X(null),onClick:ft=>{ft.stopPropagation(),Z(Rt=>Rt===ve?null:ve)}}),e.jsx("path",{d:Te,fill:"none",stroke:pe?"#22D3EE":"var(--edge-color)",strokeWidth:pe?1.5:1,markerEnd:`url(#arrow-${pe?"active":"default"})`,style:{pointerEvents:"none",filter:pe?"drop-shadow(0 0 2px rgba(34,211,238,0.4))":void 0}}),ce&&e.jsx("circle",{r:4.5,fill:"#22D3EE",opacity:.9,children:e.jsx("animateMotion",{dur:"1.5s",repeatCount:"indefinite",path:Te})}),U===ve&&!l&&E&&e.jsx("foreignObject",{x:Dt-14,y:xe-14,width:28,height:28,style:{overflow:"visible",pointerEvents:"auto"},children:e.jsx("div",{className:"w-7 h-7 rounded-lg bg-red-500 hover:bg-red-400 text-white flex items-center justify-center cursor-pointer shadow-lg shadow-black/40 border border-red-400/40 transition-all",onClick:ft=>{ft.stopPropagation(),E(p.from,p.to),X(null),Z(null)},title:"Remove connection",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),e.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),e.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})})})]},`${p.from}-${p.to}-${q}`)}),ze&&me&&e.jsx("path",{d:`M ${ze.x+ze.width/2} ${ze.y+ze.height} C ${ze.x+ze.width/2} ${ze.y+ze.height+40}, ${me.x} ${me.y-40}, ${me.x} ${me.y}`,fill:"none",stroke:"#22D3EE",strokeWidth:2,strokeDasharray:"8 4",opacity:.7,style:{pointerEvents:"none",filter:"drop-shadow(0 0 2px rgba(34,211,238,0.4))"}})]})]})}),ue&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>b(null)}),e.jsxs("div",{className:"fixed z-40 bg-surface-1 backdrop-blur-sm border border-white/10 rounded-xl shadow-xl shadow-black/30 py-1.5 min-w-[170px]",style:{left:ue.x,top:ue.y},children:[e.jsx(st,{icon:e.jsx(or,{size:13}),label:"Connect to...",onClick:()=>{xt(ue.stepId),b(null)}}),e.jsx(st,{icon:e.jsx(Ie,{size:13}),label:"Insert after",onClick:()=>{G(ue.stepId),S(!0),b(null)}}),e.jsx(st,{icon:e.jsx(Xe,{size:13}),label:"Duplicate",shortcut:"Ctrl+D",onClick:()=>{$==null||$(ue.stepId),b(null)}}),e.jsx(st,{icon:e.jsx(cr,{size:13}),label:"Toggle disable",onClick:()=>{d==null||d(ue.stepId),b(null)}}),e.jsx(st,{icon:e.jsx(dr,{size:13}),label:"Remove & reconnect",onClick:()=>{k==null||k(ue.stepId),b(null)}}),e.jsx("div",{className:"border-t border-white/5 my-1"}),e.jsx(st,{icon:e.jsx(lt,{size:13}),label:"Delete",shortcut:"Del",danger:!0,onClick:()=>{j==null||j(ue.stepId),b(null)}})]})]}),f&&c.nodes.length>0&&e.jsx(Dr,{nodes:c.nodes,canvasWidth:c.width,canvasHeight:c.height,viewportWidth:tt,viewportHeight:ut,pan:L,zoom:z,onPanTo:At}),we&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onWheel:p=>p.stopPropagation(),children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>S(!1)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[480px] max-h-[80vh] flex flex-col animate-fade-in shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/5 bg-surface-2/30 rounded-t-2xl",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"Add Step"}),e.jsx("button",{onClick:()=>S(!1),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-400 hover:text-gray-200 transition-all",children:e.jsx(he,{size:16})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-5",children:e.jsx(Rr,{onSelect:Ot,onClose:()=>S(!1)})})]})]})]})}function st({icon:t,label:s,shortcut:n,danger:o,onClick:w}){return e.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-xs flex items-center gap-2 hover:bg-surface-2/40 transition-all
8
+ ${o?"text-red-400 hover:text-red-300":"text-gray-300 hover:text-gray-100"}`,onClick:w,children:[t,e.jsx("span",{className:"flex-1",children:s}),n&&e.jsx("span",{className:"text-xs text-gray-600 ml-2",children:n})]})}function Rr({onSelect:t,onClose:s}){const[n,o]=r.useState(""),w=Gs.filter(d=>{const $=Me[d.type],I=n.toLowerCase();return d.label.toLowerCase().includes(I)||d.type.toLowerCase().includes(I)||$.description.toLowerCase().includes(I)}),j=[{key:"actions",label:"Actions"},{key:"flow",label:"Flow Control"},{key:"utilities",label:"Utilities"}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 bg-surface-2/40 rounded-xl px-3 py-2 border border-white/5 focus-within:border-cyan-500/30 transition-all mb-4",children:[e.jsx(ot,{size:14,className:"text-gray-500 shrink-0"}),e.jsx("input",{type:"text",value:n,onChange:d=>o(d.target.value),placeholder:"Search steps...",className:"bg-transparent text-sm text-gray-200 placeholder-gray-500 outline-none w-full",autoFocus:!0})]}),e.jsxs("div",{className:"space-y-3",children:[n.trim()?w.map(d=>e.jsx(Vs,{type:d.type,onSelect:t},d.type)):j.map(d=>{const $=Gs.filter(I=>Me[I.type].category===d.key);return e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider px-1 mb-1.5",children:d.label}),e.jsx("div",{className:"space-y-0.5",children:$.map(I=>e.jsx(Vs,{type:I.type,onSelect:t},I.type))})]},d.key)}),w.length===0&&e.jsx("p",{className:"text-sm text-gray-500 py-4 text-center",children:"No matching steps"})]})]})}function Vs({type:t,onSelect:s}){const n=Me[t],o=Pr[n.iconName];return e.jsxs("button",{onClick:()=>s(t),className:"w-full px-3 py-2.5 text-left rounded-xl hover:bg-surface-2/40 flex items-center gap-3 transition-all group",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center shrink-0 ${n.bgClass}`,children:o&&e.jsx(o,{size:16,className:n.textClass})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200 block",children:n.label}),e.jsx("span",{className:"text-xs text-gray-500 block truncate",children:n.description})]}),e.jsx(Ie,{size:14,className:"text-gray-600 group-hover:text-cyan-400 shrink-0"})]})}const Ks={Brain:qe,Wrench:Ze,Plug:Je,GitBranch:Et,Repeat:$t,Zap:Re,ShieldCheck:zt,Timer:St,Workflow:He,FileCode:Ct},Wr=["abort","retry","skip","fallback","human"],Yr=["fixed","linear","exponential"],Fr=["skill","tool","mcp","condition","loop","parallel","checkpoint","delay","subworkflow","script"];function _r({step:t,allStepIds:s,activeRun:n,onClose:o,onUpdateStep:w,readOnly:j}){var v,A,J,ne,ue;const d=it(t),$=Me[d],I=n==null?void 0:n.stepResults[t.id],E=!j&&!!w,[k,l]=r.useState({skills:[],tools:[],mcpTools:[],mcpServers:[],workflows:[],loading:!0});r.useEffect(()=>{let b=!1;async function H(){try{const[le,me,ye,we,S]=await Promise.allSettled([Ta(),Aa(),Da(),Pa(),gs()]);if(b)return;l({skills:le.status==="fulfilled"?le.value.skills.filter(T=>T.enabled):[],tools:me.status==="fulfilled"?me.value.tools:[],mcpTools:ye.status==="fulfilled"?ye.value.tools:[],mcpServers:we.status==="fulfilled"?we.value.servers:[],workflows:S.status==="fulfilled"?S.value.workflows:[],loading:!1})}catch{b||l(le=>({...le,loading:!1}))}}return H(),()=>{b=!0}},[]);const[M,h]=r.useState(!1),[u,D]=r.useState({}),[O,c]=r.useState({basic:!0,typeConfig:!0,dependencies:!1,errorHandling:!1,io:!1,flags:!1});r.useEffect(()=>{h(!1),D({})},[t.id]);const z=r.useCallback(()=>{h(!0),D({id:t.id,description:t.description||"",skill:t.skill||"",action:t.action||"",tool:t.tool||"",command:t.command||"",mcp:t.mcp||"",if:t.if||"",forEach:t.forEach||"",message:t.message||"",waitSeconds:t.waitSeconds,workflowId:t.workflowId||"",script:t.script||"",continueOnError:t.continueOnError||!1,disabled:t.disabled||!1,timeout:t.timeout,dependsOn:[...t.dependsOn||[]],onError:t.onError?{...t.onError}:void 0})},[t]),C=r.useCallback(()=>{if(!w)return;const b={};for(const[le,me]of Object.entries(u))le!=="id"&&(me===""||me===void 0||Array.isArray(me)&&me.length===0||(b[le]=me));const H=(u.id||"").trim();H&&H!==t.id&&(b.id=H),w(t.id,b),h(!1)},[u,w,t.id]),L=r.useCallback(()=>{h(!1),D({})},[]),m=(b,H)=>{D(le=>({...le,[b]:H}))},g=b=>{c(H=>({...H,[b]:!H[b]}))},F=b=>{const H=[...u.dependsOn||[]];H.includes(b)||H.push(b),m("dependsOn",H)},V=b=>{m("dependsOn",(u.dependsOn||[]).filter(H=>H!==b))},N=s.filter(b=>b!==t.id&&!(u.dependsOn||[]).includes(b)),B=M&&u.type||d;return e.jsxs("div",{className:"w-[340px] flex-shrink-0 border-l border-white/5 bg-surface-1 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/5 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("span",{className:`w-8 h-8 flex items-center justify-center rounded-lg shrink-0 ${$.bgClass}`,children:(()=>{const b=Ks[$.iconName];return b?e.jsx(b,{size:16,className:$.textClass}):null})()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[M?e.jsx("input",{type:"text",value:u.id||t.id,onChange:b=>m("id",b.target.value.replace(/[^a-zA-Z0-9_-]/g,"")),className:"text-sm font-semibold text-gray-100 bg-surface-2/60 border border-cyan-500/30 rounded-lg px-2 py-0.5 w-full focus:outline-none focus:border-cyan-500/50 transition-all",placeholder:"step-id"}):e.jsx("h3",{className:"text-sm font-semibold text-gray-100 break-words",children:t.id}),e.jsxs("span",{className:`text-xs font-medium ${$.textClass}`,children:[$.label," Step"]})]})]}),e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:C,className:"p-1.5 rounded-lg bg-emerald-600/20 hover:bg-emerald-600/30 text-emerald-400 transition-all",title:"Save",children:e.jsx(xr,{size:14})}),e.jsx("button",{onClick:L,className:"p-1.5 rounded-lg hover:bg-red-500/20 text-gray-500 hover:text-red-400 transition-all",title:"Cancel",children:e.jsx(he,{size:14})})]}):e.jsxs(e.Fragment,{children:[E&&e.jsxs("button",{onClick:z,className:"px-2.5 py-1 text-xs rounded-lg bg-cyan-600/20 hover:bg-cyan-600/30 text-cyan-400 font-medium flex items-center gap-1 transition-colors",children:[e.jsx(da,{size:11})," Edit"]}),e.jsx("button",{onClick:o,className:"p-1 rounded-lg hover:bg-surface-3/50 text-gray-500 transition-all",children:e.jsx(he,{size:16})})]})})]}),I&&e.jsxs("div",{className:`mx-4 mt-3 px-3 py-2 rounded-lg border ${ms(I.status).bg} ${ms(I.status).border}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:`text-xs font-semibold capitalize ${ms(I.status).text}`,children:I.status}),I.duration!==void 0&&e.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1",children:[e.jsx(ke,{size:10}),je(I.duration)]})]}),I.error&&e.jsxs("div",{className:"mt-2 flex items-start gap-1.5",children:[e.jsx(Ne,{size:12,className:"text-red-400 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-red-300 break-all",children:I.error})]})]}),e.jsxs("div",{className:"p-3 space-y-1",children:[e.jsx(at,{title:"Basic Info",expanded:O.basic,onToggle:()=>g("basic"),children:M?e.jsxs("div",{className:"space-y-3",children:[e.jsx(Le,{label:"Description",value:u.description||"",onChange:b=>m("description",b),placeholder:"What does this step do?"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Step Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-1",children:Fr.map(b=>{const H=Me[b],le=Ks[H.iconName],me=B===b;return e.jsxs("button",{onClick:()=>m("type",b),className:`flex items-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium border transition-all
9
+ ${me?`${H.bgClass} ${H.borderClass} ${H.textClass}`:"border-transparent hover:bg-surface-2/40 text-gray-400 hover:text-gray-200"}`,children:[le&&e.jsx(le,{size:12}),H.label]},b)})})]})]}):e.jsxs("div",{className:"space-y-2",children:[t.description&&e.jsx(De,{label:"Description",value:t.description}),e.jsx(De,{label:"Type",value:$.label})]})}),e.jsx(at,{title:`${((v=Me[B])==null?void 0:v.label)||"Step"} Configuration`,expanded:O.typeConfig,onToggle:()=>g("typeConfig"),accentColor:$.textClass,children:M?e.jsx(Xr,{stepType:B,editData:u,updateField:m,resources:k}):e.jsx(en,{step:t,stepType:d})}),e.jsxs(at,{title:`Dependencies${(A=t.dependsOn)!=null&&A.length?` (${t.dependsOn.length})`:""}`,expanded:O.dependencies,onToggle:()=>g("dependencies"),children:[M?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[(u.dependsOn||[]).map(b=>e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-surface-2 text-gray-300 flex items-center gap-1 border border-white/5",children:[e.jsx(Ws,{size:9,className:"text-cyan-400"}),b,e.jsx("button",{onClick:()=>V(b),className:"text-gray-500 hover:text-red-400 ml-0.5",children:e.jsx(he,{size:10})})]},b)),(u.dependsOn||[]).length===0&&e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No dependencies — step runs immediately"})]}),N.length>0&&e.jsxs("select",{className:"w-full px-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-lg text-xs text-gray-400 cursor-pointer",value:"",onChange:b=>{b.target.value&&F(b.target.value)},children:[e.jsx("option",{value:"",children:"+ Add dependency..."}),N.map(b=>e.jsx("option",{value:b,children:b},b))]})]}):e.jsx("div",{className:"flex flex-wrap gap-1",children:t.dependsOn&&t.dependsOn.length>0?t.dependsOn.map(b=>e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-surface-2 text-gray-300 flex items-center gap-1 border border-white/5",children:[e.jsx(Ws,{size:9,className:"text-cyan-400"}),b]},b)):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No dependencies"})}),t.then&&t.then.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-emerald-500 block mb-1",children:"Then →"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.then.map(b=>e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:b},b))})]}),t.else&&t.else.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-red-500 block mb-1",children:"Else →"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.else.map(b=>e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-red-500/10 text-red-400 border border-red-500/20",children:b},b))})]})]}),e.jsx(at,{title:"Error Handling",expanded:O.errorHandling,onToggle:()=>g("errorHandling"),children:M?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Strategy"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Wr.map(b=>{var H;return e.jsx("button",{onClick:()=>m("onError",{...u.onError||{},strategy:b}),className:`px-2.5 py-1 rounded-lg text-xs font-medium border transition-all capitalize
10
+ ${(((H=u.onError)==null?void 0:H.strategy)||"abort")===b?"bg-cyan-500/15 border-cyan-500/30 text-cyan-400":"border-white/5 text-gray-400 hover:bg-surface-2"}`,children:b},b)})})]}),((J=u.onError)==null?void 0:J.strategy)==="retry"&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 p-2 bg-surface-2/60 rounded-lg border border-white/5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Max Retries"}),e.jsx("input",{type:"number",min:0,max:10,className:"w-full px-2 py-1 bg-surface-1 border border-white/5 rounded-lg text-xs text-gray-200",value:((ne=u.onError)==null?void 0:ne.maxRetries)??3,onChange:b=>m("onError",{...u.onError||{},maxRetries:Number(b.target.value)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Delay (ms)"}),e.jsx("input",{type:"number",min:0,className:"w-full px-2 py-1 bg-surface-1 border border-white/5 rounded-lg text-xs text-gray-200",value:((ue=u.onError)==null?void 0:ue.retryDelay)??1e3,onChange:b=>m("onError",{...u.onError||{},retryDelay:Number(b.target.value)})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Backoff"}),e.jsx("div",{className:"flex gap-1",children:Yr.map(b=>{var H;return e.jsx("button",{onClick:()=>m("onError",{...u.onError||{},backoff:b}),className:`flex-1 px-2 py-1 rounded-lg text-xs capitalize border transition-all
11
+ ${(((H=u.onError)==null?void 0:H.backoff)||"fixed")===b?"bg-cyan-500/15 border-cyan-500/30 text-cyan-400":"border-white/5 text-gray-400 hover:bg-surface-2"}`,children:b},b)})})]})]})]}):t.onError?e.jsxs("div",{className:"text-xs text-gray-400 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500",children:"Strategy:"}),e.jsx("span",{className:"px-2 py-0.5 rounded-lg bg-surface-3/50 text-gray-300 capitalize border border-white/5",children:t.onError.strategy})]}),t.onError.maxRetries!==void 0&&e.jsxs("p",{children:["Max Retries: ",e.jsx("span",{className:"text-gray-300",children:t.onError.maxRetries})]}),t.onError.retryDelay!==void 0&&e.jsxs("p",{children:["Retry Delay: ",e.jsxs("span",{className:"text-gray-300",children:[t.onError.retryDelay,"ms"]})]})]}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"Default (abort on error)"})}),e.jsxs(at,{title:`Inputs / Outputs${t.inputs&&Object.keys(t.inputs).length||t.outputs&&Object.keys(t.outputs).length?" ●":""}`,expanded:O.io,onToggle:()=>g("io"),children:[M?e.jsxs("div",{className:"space-y-3",children:[e.jsx(qs,{label:"Inputs",data:u.inputs||t.inputs||{},onChange:b=>m("inputs",b),keyColor:"text-cyan-400"}),e.jsx(qs,{label:"Output Mappings",data:u.outputs||t.outputs||{},onChange:b=>m("outputs",b),keyColor:"text-emerald-400"})]}):e.jsxs("div",{className:"space-y-3",children:[t.inputs&&Object.keys(t.inputs).length>0?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-1",children:"Inputs"}),e.jsx("div",{className:"bg-surface-2/60 rounded-lg p-2 space-y-1 border border-white/5",children:Object.entries(t.inputs).map(([b,H])=>e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"text-cyan-400",children:b}),e.jsx("span",{className:"text-gray-600",children:": "}),e.jsx("span",{className:"text-gray-300",children:typeof H=="string"?H:JSON.stringify(H)})]},b))})]}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No inputs configured"}),t.outputs&&Object.keys(t.outputs).length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-1",children:"Output Mappings"}),e.jsx("div",{className:"bg-surface-2/60 rounded-lg p-2 space-y-1 border border-white/5",children:Object.entries(t.outputs).map(([b,H])=>e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"text-emerald-400",children:b}),e.jsx("span",{className:"text-gray-600",children:" ← "}),e.jsx("span",{className:"text-gray-400",children:H})]},b))})]})]}),(I==null?void 0:I.outputs)&&Object.keys(I.outputs).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-cyan-500 block mb-1",children:"Run Outputs"}),e.jsx("div",{className:"bg-surface-2/60 rounded-lg p-2 max-h-40 overflow-y-auto border border-cyan-500/10",children:e.jsx("pre",{className:"text-xs text-gray-400 whitespace-pre-wrap break-all",children:JSON.stringify(I.outputs,null,2).slice(0,1e3)})})]})]}),e.jsx(at,{title:"Flags & Advanced",expanded:O.flags,onToggle:()=>g("flags"),children:M?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-300 cursor-pointer hover:text-white transition-colors",children:[e.jsx("input",{type:"checkbox",checked:u.continueOnError||!1,onChange:b=>m("continueOnError",b.target.checked),className:"rounded border-gray-600 bg-surface-2/60 text-cyan-500 focus:ring-cyan-500/30"}),"Continue on Error"]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-300 cursor-pointer hover:text-white transition-colors",children:[e.jsx("input",{type:"checkbox",checked:u.disabled||!1,onChange:b=>m("disabled",b.target.checked),className:"rounded border-gray-600 bg-surface-2/60 text-cyan-500 focus:ring-cyan-500/30"}),"Disabled"]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500 block mb-0.5",children:"Timeout (ms)"}),e.jsx("input",{type:"number",min:0,className:"w-full px-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-lg text-xs text-gray-200",value:u.timeout??"",onChange:b=>m("timeout",b.target.value?Number(b.target.value):void 0),placeholder:"No timeout"})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.continueOnError&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-amber-500/10 text-amber-400 border border-amber-500/20",children:"Continue on Error"}),t.disabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-gray-500/10 text-gray-500 border border-gray-500/20",children:"Disabled"}),t.timeout!==void 0&&e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-surface-2 text-gray-400 border border-white/5",children:["Timeout: ",je(t.timeout)]}),!t.continueOnError&&!t.disabled&&t.timeout===void 0&&e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No special flags"})]})})]})]})}function Xr({stepType:t,editData:s,updateField:n,resources:o}){switch(t){case"skill":return e.jsx(Hr,{editData:s,updateField:n,resources:o});case"tool":return e.jsx(Br,{editData:s,updateField:n,resources:o});case"mcp":return e.jsx(Ur,{editData:s,updateField:n,resources:o});case"condition":return e.jsx(Gr,{editData:s,updateField:n});case"loop":return e.jsx(Vr,{editData:s,updateField:n});case"parallel":return e.jsx(Kr,{editData:s,updateField:n});case"checkpoint":return e.jsx(Jr,{editData:s,updateField:n});case"delay":return e.jsx(Zr,{editData:s,updateField:n});case"subworkflow":return e.jsx(qr,{editData:s,updateField:n,resources:o});case"script":return e.jsx(Qr,{editData:s,updateField:n});default:return e.jsx("p",{className:"text-xs text-gray-600 italic",children:"No configuration for this type"})}}function Hr({editData:t,updateField:s,resources:n}){const[o,w]=r.useState(""),j=n.skills.filter(d=>d.slug.toLowerCase().includes(o.toLowerCase())||d.name.toLowerCase().includes(o.toLowerCase())||d.description.toLowerCase().includes(o.toLowerCase()));return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wider text-purple-400 block mb-1",children:[e.jsx(qe,{size:10,className:"inline mr-1"}),"Select Skill"]}),n.loading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 py-2",children:[e.jsx(be,{size:12,className:"animate-spin"})," Loading skills..."]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mb-1.5",children:[e.jsx(ot,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:o,onChange:d=>w(d.target.value),placeholder:"Search skills...",className:"w-full pl-7 pr-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-lg text-xs text-gray-200 placeholder-gray-500"})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5 rounded-lg border border-white/5 bg-surface-2/60 p-1",children:[j.length===0&&e.jsx("p",{className:"text-xs text-gray-600 p-2 text-center",children:"No skills found"}),j.map(d=>e.jsxs("button",{onClick:()=>s("skill",d.slug),className:`w-full text-left px-2 py-1.5 rounded-lg text-xs flex items-start gap-2 transition-colors
12
+ ${t.skill===d.slug?"bg-purple-500/15 text-purple-300 border border-purple-500/30":"hover:bg-surface-2/40 text-gray-300 border border-transparent"}`,children:[e.jsx(qe,{size:12,className:"text-purple-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:d.name}),e.jsx("div",{className:"text-xs text-gray-500 truncate",children:d.description}),d.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-0.5 mt-0.5",children:d.tags.slice(0,3).map($=>e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-lg bg-purple-500/10 text-purple-400",children:$},$))})]})]},d.slug))]}),t.skill&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Selected:"}),e.jsx("span",{className:"px-2 py-0.5 rounded-lg bg-purple-500/15 text-purple-300 font-medium",children:t.skill})]})]})]}),e.jsx(Le,{label:"Action / Instructions",value:t.action||"",onChange:d=>s("action",d),multiline:!0,placeholder:"What should this skill do? e.g. 'Run all login page tests'"})]})}function Js(t){return t?new Set(t.split(",").map(s=>s.trim()).filter(Boolean)):new Set}function Br({editData:t,updateField:s,resources:n}){const[o,w]=r.useState(""),[j,d]=r.useState(()=>{const u=Js(t.tool),D=new Set;for(const O of n.tools)u.has(O.name)&&D.add(O.category||"other");return D.size>0?D:new Set(["command"])}),$=r.useMemo(()=>Js(t.tool),[t.tool]),I=r.useMemo(()=>{const u={};for(const D of n.tools){if(o&&!D.name.toLowerCase().includes(o.toLowerCase())&&!D.description.toLowerCase().includes(o.toLowerCase())&&!D.category.toLowerCase().includes(o.toLowerCase()))continue;const O=D.category||"other";u[O]||(u[O]=[]),u[O].push(D)}return u},[n.tools,o]),E=u=>{const D=new Set($);D.has(u)?D.delete(u):D.add(u),s("tool",Array.from(D).join(",")||void 0)},k=u=>{const O=(I[u]||[]).map(C=>C.name),c=O.every(C=>$.has(C)),z=new Set($);c?O.forEach(C=>z.delete(C)):(O.forEach(C=>z.add(C)),d(C=>new Set(C).add(u))),s("tool",Array.from(z).join(",")||void 0)},l=u=>{d(D=>{const O=new Set(D);return O.has(u)?O.delete(u):O.add(u),O})},M=u=>{const D=new Set($);D.delete(u),s("tool",Array.from(D).join(",")||void 0)},h=Object.values(I).reduce((u,D)=>u+D.length,0);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wider text-cyan-400 block mb-1.5",children:[e.jsx(Ze,{size:10,className:"inline mr-1"}),"Select Tools",h>0&&e.jsxs("span",{className:"text-gray-500 normal-case font-normal ml-1",children:["(",h,")"]})]}),n.loading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 py-2",children:[e.jsx(be,{size:12,className:"animate-spin"})," Loading tools..."]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mb-1.5",children:[e.jsx(ot,{size:12,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:o,onChange:u=>w(u.target.value),placeholder:"Search tools...",className:"w-full pl-7 pr-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-xl text-xs text-gray-200 placeholder-gray-500 focus:outline-none focus:border-cyan-500/30 transition-all"})]}),e.jsxs("div",{className:"max-h-[250px] overflow-y-auto space-y-0.5 rounded-xl border border-white/5 bg-surface-2/40 p-1",children:[Object.keys(I).length===0&&e.jsx("p",{className:"text-xs text-gray-600 p-2 text-center",children:"No tools found"}),Object.entries(I).map(([u,D])=>{const O=D.map(C=>C.name),c=O.every(C=>$.has(C)),z=O.some(C=>$.has(C));return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 hover:bg-surface-2/60 rounded-lg transition-all",children:[e.jsxs("button",{onClick:()=>k(u),className:`w-4 h-4 rounded flex items-center justify-center shrink-0 border transition-all ${c?"bg-cyan-500 border-cyan-400":z?"bg-cyan-500/50 border-cyan-400/50":"border-white/20 bg-surface-2/60"}`,children:[c&&e.jsx(Se,{size:10,className:"text-white"}),z&&!c&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-sm bg-white"})]}),e.jsxs("button",{onClick:()=>l(u),className:"flex items-center gap-1 flex-1 text-left",children:[j.has(u)?e.jsx(Ee,{size:10,className:"text-gray-500"}):e.jsx(Ce,{size:10,className:"text-gray-500"}),e.jsx("span",{className:"text-xs font-semibold text-cyan-400 uppercase tracking-wider",children:u}),e.jsxs("span",{className:"text-xs text-gray-600 normal-case font-normal",children:["(",D.length,")"]})]})]}),j.has(u)&&D.map(C=>{const L=$.has(C.name);return e.jsxs("button",{onClick:()=>E(C.name),className:`w-full text-left px-2 py-1.5 ml-3 rounded-lg text-xs flex items-center gap-2 transition-all border ${L?"bg-cyan-500/15 text-cyan-300 border-cyan-500/30":"hover:bg-surface-2/60 text-gray-300 border-transparent"}`,style:{width:"calc(100% - 12px)"},children:[e.jsx("div",{className:`w-3.5 h-3.5 rounded flex items-center justify-center shrink-0 border transition-all ${L?"bg-cyan-500 border-cyan-400":"border-white/20 bg-surface-2/60"}`,children:L&&e.jsx(Se,{size:8,className:"text-white"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-mono font-medium truncate",children:C.name}),C.description&&e.jsx("div",{className:"text-gray-500 truncate mt-0.5",children:C.description})]})]},C.name)})]},u)})]}),$.size>0&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:["Selected (",$.size,"):"]}),e.jsx("button",{onClick:()=>s("tool",void 0),className:"text-xs text-gray-600 hover:text-red-400 transition-all",children:"Clear all"})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Array.from($).map(u=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-cyan-500/15 text-cyan-300 text-xs font-mono font-medium border border-cyan-500/20",children:[e.jsx(Ze,{size:9}),u,e.jsx("button",{onClick:()=>M(u),className:"ml-0.5 hover:text-red-400 transition-all",children:e.jsx(he,{size:10})})]},u))})]})]})]}),e.jsx(Le,{label:"Command / Arguments",value:t.command||"",onChange:u=>s("command",u),code:!0,placeholder:'e.g. "npx playwright test" or tool arguments'}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wider text-cyan-400 block mb-1.5",children:[e.jsx(_e,{size:10,className:"inline mr-1"}),"Prompt (AI-Powered)"]}),e.jsx("textarea",{value:t.action||"",onChange:u=>s("action",u.target.value||void 0),placeholder:`Describe what you want the AI to do with the selected tools...
13
+
14
+ e.g. 'Launch browser, navigate to the app, take a screenshot and save it'`,className:"w-full px-3 py-2 bg-surface-2/60 border border-white/10 rounded-xl text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:border-cyan-500/30 transition-all resize-y min-h-[60px]",rows:3}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:t.action?$.size>1?`AI mode: The LLM will use ${$.size} tools to accomplish this task.`:"AI mode: The LLM will reason about how to use the selected tool.":$.size>1?"Add a prompt to let the AI chain multiple tools intelligently.":"Direct mode: The tool will be called with the command/arguments above."})]})]})}function ps(t){return t?new Set(t.split(",").map(s=>s.trim()).filter(Boolean)):new Set}function pa(t){const s=t.split("__");return s.length===3&&s[0]==="mcp"?s[2]||t:s.length===2&&s[1]||t}function Zs(t){const s=t.split("__");return s.length===3&&s[0]==="mcp"?s[1]||"":s.length===2&&s[0]||""}function Ur({editData:t,updateField:s,resources:n}){const[o,w]=r.useState(""),j=r.useMemo(()=>ps(t.mcp),[t.mcp]),[d,$]=r.useState(()=>{const c=new Set;for(const z of ps(t.mcp)){const C=Zs(z);C&&c.add(C)}return c}),[I,E]=r.useState(()=>{const c=new Set;for(const z of ps(t.mcp)){const C=Zs(z);C&&c.add(C)}return c}),k=r.useMemo(()=>{const c=new Map;for(const z of n.mcpServers)c.set(z.id,{id:z.id,name:z.name,status:z.status,toolCount:z.toolCount,tools:[]});for(const z of n.mcpTools)c.has(z.serverId)||c.set(z.serverId,{id:z.serverId,name:z.serverName,status:"connected",toolCount:0,tools:[]}),c.get(z.serverId).tools.push(z),c.get(z.serverId).toolCount=c.get(z.serverId).tools.length;return Array.from(c.values())},[n.mcpServers,n.mcpTools]),l=r.useMemo(()=>{const c={};for(const z of n.mcpTools)d.size>0&&!d.has(z.serverId)||o&&!z.name.toLowerCase().includes(o.toLowerCase())&&!z.description.toLowerCase().includes(o.toLowerCase())&&!z.serverName.toLowerCase().includes(o.toLowerCase())||(c[z.serverId]||(c[z.serverId]={serverName:z.serverName,tools:[]}),c[z.serverId].tools.push(z));return c},[n.mcpTools,d,o]),M=c=>{const z=new Set(j);z.has(c)?z.delete(c):z.add(c),s("mcp",Array.from(z).join(",")||void 0)},h=c=>{const z=k.find(g=>g.id===c);if(!z)return;const C=z.tools.map(g=>`${g.serverId}__${g.name}`),L=C.every(g=>j.has(g)),m=new Set(j);L?(C.forEach(g=>m.delete(g)),$(g=>{const F=new Set(g);return F.delete(c),F})):(C.forEach(g=>m.add(g)),$(g=>new Set(g).add(c)),E(g=>new Set(g).add(c))),s("mcp",Array.from(m).join(",")||void 0)},u=c=>{E(z=>{const C=new Set(z);return C.has(c)?C.delete(c):C.add(c),C})},D=c=>{const z=new Set(j);z.delete(c),s("mcp",Array.from(z).join(",")||void 0)},O=Object.values(l).reduce((c,z)=>c+z.tools.length,0);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wider text-emerald-400 block mb-1.5",children:[e.jsx(Yt,{size:10,className:"inline mr-1"}),"MCP Servers"]}),n.loading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 py-2",children:[e.jsx(be,{size:12,className:"animate-spin"})," Loading MCP servers..."]}):k.length===0?e.jsxs("div",{className:"text-xs text-gray-500 bg-surface-2/60 rounded-xl p-3 border border-white/5 text-center",children:[e.jsx(Yt,{size:16,className:"mx-auto mb-1 text-gray-600"}),e.jsx("p",{children:"No MCP servers configured"}),e.jsx("p",{className:"text-xs text-gray-600 mt-0.5",children:"Add MCP servers in Settings → MCP Servers"})]}):e.jsx("div",{className:"space-y-1",children:k.map(c=>{const z=c.tools.map(g=>`${g.serverId}__${g.name}`),C=z.length>0&&z.every(g=>j.has(g)),L=z.some(g=>j.has(g)),m=c.status==="connected";return e.jsxs("button",{onClick:()=>h(c.id),className:`w-full text-left px-2.5 py-1.5 rounded-xl text-xs flex items-center gap-2 transition-all border ${C?"bg-emerald-500/15 text-emerald-300 border-emerald-500/30":L?"bg-emerald-500/10 text-emerald-300/70 border-emerald-500/20":"bg-surface-2/40 text-gray-400 hover:text-gray-200 border-white/5 hover:border-white/10"}`,children:[e.jsxs("div",{className:`w-4 h-4 rounded flex items-center justify-center shrink-0 border transition-all ${C?"bg-emerald-500 border-emerald-400":L?"bg-emerald-500/50 border-emerald-400/50":"border-white/20 bg-surface-2/60"}`,children:[C&&e.jsx(Se,{size:10,className:"text-white"}),L&&!C&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-sm bg-white"})]}),e.jsx(Yt,{size:12,className:m?"text-emerald-400":"text-gray-600"}),e.jsx("span",{className:"flex-1 truncate font-medium",children:c.name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-lg ${m?"bg-emerald-500/10 text-emerald-400":"bg-gray-500/10 text-gray-500"}`,children:m?`${c.toolCount} tools`:c.status})]},c.id)})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wider text-emerald-400 block mb-1.5",children:[e.jsx(Je,{size:10,className:"inline mr-1"}),"Select Tools",O>0&&e.jsxs("span",{className:"text-gray-500 normal-case font-normal ml-1",children:["(",O,")"]})]}),n.mcpTools.length>0&&e.jsxs("div",{className:"relative mb-1.5",children:[e.jsx(ot,{size:12,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:o,onChange:c=>w(c.target.value),placeholder:"Search tools...",className:"w-full pl-7 pr-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-xl text-xs text-gray-200 placeholder-gray-500 focus:outline-none focus:border-emerald-500/30 transition-all"})]}),Object.keys(l).length===0?e.jsx("p",{className:"text-xs text-gray-600 bg-surface-2/60 rounded-xl p-2 text-center border border-white/5",children:d.size>0?"No tools from selected servers":"No MCP tools available"}):e.jsx("div",{className:"max-h-[250px] overflow-y-auto space-y-0.5 rounded-xl border border-white/5 bg-surface-2/40 p-1",children:Object.entries(l).map(([c,{serverName:z,tools:C}])=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>u(c),className:"w-full text-left px-2 py-1.5 flex items-center gap-1.5 text-xs hover:bg-surface-2/60 rounded-lg transition-all",children:[I.has(c)?e.jsx(Ee,{size:10,className:"text-gray-500"}):e.jsx(Ce,{size:10,className:"text-gray-500"}),e.jsx(Yt,{size:10,className:"text-emerald-500"}),e.jsx("span",{className:"font-semibold text-emerald-400 uppercase tracking-wider",children:z}),e.jsxs("span",{className:"text-gray-600 normal-case font-normal",children:["(",C.length,")"]})]}),I.has(c)&&C.map(L=>{const m=`${L.serverId}__${L.name}`,g=j.has(m);return e.jsxs("button",{onClick:()=>M(m),className:`w-full text-left px-2 py-1.5 ml-3 rounded-lg text-xs flex items-center gap-2 transition-all border ${g?"bg-emerald-500/15 text-emerald-300 border-emerald-500/30":"hover:bg-surface-2/60 text-gray-300 border-transparent"}`,style:{width:"calc(100% - 12px)"},children:[e.jsx("div",{className:`w-3.5 h-3.5 rounded flex items-center justify-center shrink-0 border transition-all ${g?"bg-emerald-500 border-emerald-400":"border-white/20 bg-surface-2/60"}`,children:g&&e.jsx(Se,{size:8,className:"text-white"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-mono font-medium truncate",children:L.name}),L.description&&e.jsx("div",{className:"text-gray-500 truncate mt-0.5",children:L.description})]})]},m)})]},c))}),j.size>0&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:["Selected (",j.size,"):"]}),e.jsx("button",{onClick:()=>s("mcp",void 0),className:"text-xs text-gray-600 hover:text-red-400 transition-all",children:"Clear all"})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Array.from(j).map(c=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-emerald-500/15 text-emerald-300 text-xs font-mono font-medium border border-emerald-500/20",children:[e.jsx(Je,{size:9}),pa(c),e.jsx("button",{onClick:()=>D(c),className:"ml-0.5 hover:text-red-400 transition-all",children:e.jsx(he,{size:10})})]},c))})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-semibold uppercase tracking-wider text-emerald-400 block mb-1.5",children:[e.jsx(_e,{size:10,className:"inline mr-1"}),"Prompt (AI-Powered)"]}),e.jsx("textarea",{value:t.action||"",onChange:c=>s("action",c.target.value||void 0),placeholder:`Describe what you want the AI to do with the selected MCP tools...
15
+
16
+ e.g. 'List all files in the project directory and summarize the structure'`,className:"w-full px-3 py-2 bg-surface-2/60 border border-white/10 rounded-xl text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:border-emerald-500/30 transition-all resize-y min-h-[60px]",rows:3}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:t.action?"AI mode: The LLM will reason about how to use the selected tools to accomplish this task.":"Direct mode: Without a prompt, tools will be called directly with the inputs below."})]})]})}function Gr({editData:t,updateField:s}){var n,o;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-amber-500/5 border border-amber-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-amber-400/80",children:[e.jsx(Et,{size:10,className:"inline mr-1"}),'Define a condition expression. Steps in "then" run when true, "else" when false.']})}),e.jsx(Le,{label:"Condition Expression (if)",value:t.if||"",onChange:w=>s("if",w),code:!0,placeholder:'e.g. steps.login.status === "completed"'}),e.jsx(Le,{label:"Then Steps (comma-separated IDs)",value:((n=t.then)==null?void 0:n.join(", "))||"",onChange:w=>s("then",w.split(",").map(j=>j.trim()).filter(Boolean)),placeholder:"step-1, step-2"}),e.jsx(Le,{label:"Else Steps (comma-separated IDs)",value:((o=t.else)==null?void 0:o.join(", "))||"",onChange:w=>s("else",w.split(",").map(j=>j.trim()).filter(Boolean)),placeholder:"step-3"})]})}function Vr({editData:t,updateField:s}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-blue-500/5 border border-blue-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-blue-400/80",children:[e.jsx($t,{size:10,className:"inline mr-1"}),"Iterate over a list. Each iteration receives the current item as context."]})}),e.jsx(Le,{label:"For Each Expression",value:t.forEach||"",onChange:n=>s("forEach",n),code:!0,placeholder:'e.g. variables.testFiles or ["a","b","c"]'}),e.jsx(Le,{label:"Action per iteration",value:t.action||"",onChange:n=>s("action",n),multiline:!0,placeholder:"What to do for each item"})]})}function Kr({editData:t,updateField:s}){var n;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-yellow-500/5 border border-yellow-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-yellow-400/80",children:[e.jsx(Re,{size:10,className:"inline mr-1"}),"Run multiple steps in parallel. All listed steps start simultaneously."]})}),e.jsx(Le,{label:"Parallel Step IDs (comma-separated)",value:((n=t.parallelSteps)==null?void 0:n.join(", "))||"",onChange:o=>s("parallelSteps",o.split(",").map(w=>w.trim()).filter(Boolean)),placeholder:"step-a, step-b, step-c"})]})}function Jr({editData:t,updateField:s}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-orange-500/5 border border-orange-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-orange-400/80",children:[e.jsx(zt,{size:10,className:"inline mr-1"}),"Pause workflow execution and wait for human approval before continuing."]})}),e.jsx(Le,{label:"Approval Message",value:t.message||"",onChange:n=>s("message",n),multiline:!0,placeholder:"Message shown to the reviewer..."})]})}function Zr({editData:t,updateField:s}){const n=[5,10,30,60,300];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-gray-500/5 border border-gray-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-gray-400/80",children:[e.jsx(St,{size:10,className:"inline mr-1"}),"Pause execution for a specified duration."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Wait Duration"}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:n.map(o=>e.jsx("button",{onClick:()=>s("waitSeconds",o),className:`px-2 py-1 rounded-lg text-xs border transition-all
17
+ ${t.waitSeconds===o?"bg-cyan-500/15 border-cyan-500/30 text-cyan-400":"border-white/5 text-gray-400 hover:bg-surface-2"}`,children:o<60?`${o}s`:`${o/60}m`},o))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,className:"flex-1 px-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-lg text-xs text-gray-200",value:t.waitSeconds??"",onChange:o=>s("waitSeconds",o.target.value?Number(o.target.value):void 0),placeholder:"Custom seconds"}),e.jsx("span",{className:"text-xs text-gray-500",children:"seconds"})]})]})]})}function qr({editData:t,updateField:s,resources:n}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-pink-500/5 border border-pink-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-pink-400/80",children:[e.jsx(He,{size:10,className:"inline mr-1"}),"Embed and execute another workflow as a sub-step."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-pink-400 block mb-1",children:"Select Workflow"}),n.loading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 py-2",children:[e.jsx(be,{size:12,className:"animate-spin"})," Loading workflows..."]}):n.workflows.length===0?e.jsx("p",{className:"text-xs text-gray-600 italic",children:"No other workflows available"}):e.jsx("div",{className:"max-h-[150px] overflow-y-auto space-y-0.5 rounded-lg border border-white/5 bg-surface-2/60 p-1",children:n.workflows.map(o=>e.jsxs("button",{onClick:()=>s("workflowId",o.id),className:`w-full text-left px-2 py-1.5 rounded-lg text-xs flex items-center gap-2 transition-colors
18
+ ${t.workflowId===o.id?"bg-pink-500/15 text-pink-300 border border-pink-500/30":"hover:bg-surface-2/40 text-gray-300 border border-transparent"}`,children:[e.jsx(He,{size:12,className:"text-pink-400 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:o.id}),e.jsxs("div",{className:"text-xs text-gray-500",children:[o.definition.steps.length," steps"]})]})]},o.id))})]})]})}function Qr({editData:t,updateField:s}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-teal-500/5 border border-teal-500/10 rounded-lg p-2",children:e.jsxs("p",{className:"text-xs text-teal-400/80",children:[e.jsx(Ct,{size:10,className:"inline mr-1"}),"Execute custom JavaScript. Has access to workflow context and variables."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-teal-400 block mb-1",children:"Script Code"}),e.jsx("textarea",{className:"w-full px-2.5 py-2 bg-surface-2/60 border border-white/10 rounded-lg text-xs font-mono text-teal-300 resize-y min-h-[120px] max-h-[300px] leading-5",value:t.script||"",onChange:n=>s("script",n.target.value),placeholder:`// Access context via 'ctx'
19
+ const results = ctx.steps;
20
+ console.log('Running script...');`,spellCheck:!1})]})]})}function en({step:t,stepType:s}){switch(s){case"skill":return e.jsxs("div",{className:"space-y-2",children:[t.skill?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-0.5",children:"Skill"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-lg bg-purple-500/15 text-purple-300 text-xs font-medium",children:[e.jsx(qe,{size:11}),t.skill]})]}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No skill selected"}),t.action&&e.jsx(De,{label:"Action",value:t.action,multiline:!0})]});case"tool":return e.jsxs("div",{className:"space-y-2",children:[t.tool?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-0.5",children:"Tools"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.tool.split(",").map(n=>n.trim()).filter(Boolean).map(n=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-lg bg-cyan-500/15 text-cyan-300 text-xs font-mono font-medium border border-cyan-500/20",children:[e.jsx(Ze,{size:11}),n]},n))})]}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No tool selected"}),t.command&&e.jsx(De,{label:"Command",value:t.command,code:!0}),t.action&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-0.5",children:"Prompt"}),e.jsx("p",{className:"text-xs text-gray-300 bg-surface-2/60 rounded-xl p-2.5 border border-white/5",children:t.action}),e.jsx("span",{className:"text-xs text-cyan-500/70 mt-0.5 inline-block",children:"AI-powered execution"})]})]});case"mcp":return e.jsxs("div",{className:"space-y-2",children:[t.mcp?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-0.5",children:"MCP Tools"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.mcp.split(",").map(n=>n.trim()).filter(Boolean).map(n=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-lg bg-emerald-500/15 text-emerald-300 text-xs font-mono font-medium border border-emerald-500/20",children:[e.jsx(Je,{size:11}),pa(n)]},n))})]}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No MCP tools selected"}),t.action&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-0.5",children:"Prompt"}),e.jsx("p",{className:"text-xs text-gray-300 bg-surface-2/60 rounded-xl p-2.5 border border-white/5",children:t.action}),e.jsx("span",{className:"text-xs text-emerald-500/70 mt-0.5 inline-block",children:"AI-powered execution"})]})]});case"condition":return e.jsx("div",{className:"space-y-2",children:t.if?e.jsx(De,{label:"Condition (if)",value:t.if,code:!0}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No condition set"})});case"loop":return e.jsxs("div",{className:"space-y-2",children:[t.forEach?e.jsx(De,{label:"For Each",value:t.forEach,code:!0}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No loop expression"}),t.action&&e.jsx(De,{label:"Action",value:t.action,multiline:!0})]});case"checkpoint":return t.message?e.jsx(De,{label:"Approval Message",value:t.message,multiline:!0}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No message set"});case"delay":return t.waitSeconds!==void 0?e.jsx(De,{label:"Wait Duration",value:`${t.waitSeconds} seconds`}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No duration set"});case"subworkflow":return t.workflowId?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase text-gray-500 block mb-0.5",children:"Sub-Workflow"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-lg bg-pink-500/15 text-pink-300 text-xs font-medium",children:[e.jsx(He,{size:11}),t.workflowId]})]}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No workflow selected"});case"script":return t.script?e.jsx(De,{label:"Script",value:t.script,code:!0,multiline:!0}):e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No script defined"});default:return e.jsx("span",{className:"text-xs text-gray-600 italic",children:"No configuration"})}}function at({title:t,expanded:s,onToggle:n,children:o,accentColor:w}){return e.jsxs("div",{className:"border border-white/[0.04] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:n,className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-surface-2/50 transition-colors",children:[s?e.jsx(Ee,{size:12,className:"text-gray-500"}):e.jsx(Ce,{size:12,className:"text-gray-500"}),e.jsx("span",{className:`text-xs font-semibold ${w||"text-gray-300"}`,children:t})]}),s&&e.jsx("div",{className:"px-3 pb-3 pt-1",children:o})]})}function De({label:t,value:s,code:n,multiline:o}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 block mb-0.5",children:t}),n?e.jsx("pre",{className:`text-xs text-cyan-300 bg-surface-2/60 rounded-lg px-2 py-1.5 border border-white/5 ${o?"whitespace-pre-wrap max-h-32 overflow-y-auto":"truncate"}`,children:s}):e.jsx("p",{className:`text-xs text-gray-300 ${o?"":"truncate"}`,children:s})]})}function Le({label:t,value:s,onChange:n,code:o,multiline:w,placeholder:j}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 block mb-0.5",children:t}),w?e.jsx("textarea",{className:`w-full px-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-lg text-xs resize-y min-h-[60px] max-h-[200px] placeholder-gray-600 ${o?"font-mono text-cyan-300":"text-gray-200"}`,value:s,onChange:d=>n(d.target.value),placeholder:j}):e.jsx("input",{type:"text",className:`w-full px-2 py-1.5 bg-surface-2/60 border border-white/10 rounded-lg text-xs placeholder-gray-600 ${o?"font-mono text-cyan-300":"text-gray-200"}`,value:s,onChange:d=>n(d.target.value),placeholder:j})]})}function qs({label:t,data:s,onChange:n,keyColor:o}){const w=Object.entries(s),j=()=>{const E=`key${w.length+1}`;n({...s,[E]:""})},d=E=>{const k={...s};delete k[E],n(k)},$=(E,k)=>{if(E===k)return;const l={};for(const[M,h]of Object.entries(s))l[M===E?k:M]=h;n(l)},I=(E,k)=>{n({...s,[E]:k})};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500",children:t}),e.jsx("button",{onClick:j,className:"text-gray-500 hover:text-cyan-400 transition-colors",children:e.jsx(Ie,{size:12})})]}),e.jsxs("div",{className:"bg-surface-2/60 rounded-lg p-2 space-y-1.5 border border-white/5",children:[w.length===0&&e.jsx("p",{className:"text-xs text-gray-600 italic",children:"No entries"}),w.map(([E,k],l)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"text",className:`w-24 px-1.5 py-0.5 bg-surface-1 border border-white/5 rounded-lg text-xs ${o}`,value:E,onChange:M=>$(E,M.target.value)}),e.jsx("span",{className:"text-gray-600 text-xs",children:":"}),e.jsx("input",{type:"text",className:"flex-1 px-1.5 py-0.5 bg-surface-1 border border-white/5 rounded-lg text-xs text-gray-300",value:typeof k=="string"?k:JSON.stringify(k),onChange:M=>I(E,M.target.value)}),e.jsx("button",{onClick:()=>d(E),className:"text-gray-600 hover:text-red-400 transition-colors",children:e.jsx(lt,{size:10})})]},l))]})]})}const Qs={Brain:qe,Wrench:Ze,Plug:Je,GitBranch:Et,Repeat:$t,Zap:Re,ShieldCheck:zt,Timer:St,Workflow:He,FileCode:Ct},ea={completed:{bg:"bg-emerald-500/10",text:"text-emerald-400",border:"border-emerald-500/20",icon:js},failed:{bg:"bg-red-500/10",text:"text-red-400",border:"border-red-500/20",icon:Ne},aborted:{bg:"bg-gray-500/10",text:"text-gray-400",border:"border-gray-500/20",icon:he},running:{bg:"bg-cyan-500/10",text:"text-cyan-400",border:"border-cyan-500/20",icon:be},paused:{bg:"bg-amber-500/10",text:"text-amber-400",border:"border-amber-500/20",icon:Qt},pending:{bg:"bg-gray-500/10",text:"text-gray-400",border:"border-gray-500/20",icon:ke},waiting:{bg:"bg-amber-500/10",text:"text-amber-400",border:"border-amber-500/20",icon:Qt},skipped:{bg:"bg-gray-500/10",text:"text-gray-500",border:"border-gray-500/20",icon:oa}};function Nt(t){return ea[t]??ea.pending}function tn({workflow:t,activeRun:s,stepOutputs:n={},stepProgress:o={},onRunStarted:w,onRefresh:j}){const[d,$]=r.useState(!1),[I,E]=r.useState(null),[k,l]=r.useState(!1),[M,h]=r.useState([]),[u,D]=r.useState(null),[O,c]=r.useState(new Set),[z,C]=r.useState(!1),[L,m]=r.useState({}),g=r.useRef(null),F=!s||s.status==="completed"||s.status==="failed"||s.status==="aborted",V=(s==null?void 0:s.status)==="running",N=(s==null?void 0:s.status)==="paused",B=(s==null?void 0:s.status)==="completed"||(s==null?void 0:s.status)==="failed"||(s==null?void 0:s.status)==="aborted";r.useEffect(()=>{var S;(S=g.current)==null||S.scrollIntoView({behavior:"smooth"})},[n]);const{completedSteps:v,failedSteps:A,totalSteps:J,progressPercent:ne,currentStepId:ue}=r.useMemo(()=>{var U;const S=t.definition.steps,T=(s==null?void 0:s.stepResults)||{},G=S.filter(Z=>!Z.disabled).length,re=Object.values(T).filter(Z=>Z.status==="completed").length,y=Object.values(T).filter(Z=>Z.status==="failed").length,_=((U=S.find(Z=>{var f;return((f=T[Z.id])==null?void 0:f.status)==="running"}))==null?void 0:U.id)||null,X=G>0?Math.round((re+y)/G*100):0;return{completedSteps:re,failedSteps:y,totalSteps:G,progressPercent:X,currentStepId:_}},[t.definition.steps,s==null?void 0:s.stepResults]);async function b(){$(!0),E(null);try{const S={};for(const[G,re]of Object.entries(L))if(re!=="")try{S[G]=JSON.parse(re)}catch{S[G]=re}const{run:T}=await ys(t.id,Object.keys(S).length>0?S:void 0);w(T),C(!1)}catch(S){E(S instanceof Error?S.message:String(S))}finally{$(!1)}}async function H(){if(s)try{await La(t.id,s.runId)}catch{}}async function le(){if(s)try{await Wa(t.id,s.runId)}catch{}}async function me(){if(s)try{await Ra(t.id,s.runId)}catch{}}async function ye(){try{const{runs:S}=await bs(t.id,10);h(S)}catch{}}r.useEffect(()=>{k&&ye()},[k,t.id]);const we=S=>{c(T=>{const G=new Set(T);return G.has(S)?G.delete(S):G.add(S),G})};return e.jsxs("div",{className:"border-t border-white/5 bg-surface-1",children:[e.jsxs("div",{className:"flex items-center gap-2 px-5 py-3 bg-surface-2/30 border-b border-white/5",children:[F?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{onClick:b,disabled:d,className:"flex items-center gap-1.5 px-4 py-1.5 text-sm font-medium rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white disabled:opacity-50 transition-all shadow-lg shadow-emerald-600/20",children:[d?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(kt,{size:14}),"Run"]}),t.definition.variables&&Object.keys(t.definition.variables).length>0&&e.jsx("button",{onClick:()=>C(S=>!S),className:`p-2 rounded-xl text-xs transition-all ${z?"bg-cyan-500/15 text-cyan-400":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50"}`,title:"Variable Overrides",children:e.jsx(xa,{size:14})})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[V&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:H,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-xl bg-amber-600/90 hover:bg-amber-500 text-white transition-all",children:[e.jsx(ca,{size:13})," Pause"]}),e.jsxs("button",{onClick:me,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-xl bg-red-600/90 hover:bg-red-500 text-white transition-all",children:[e.jsx(os,{size:13})," Abort"]})]}),N&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:le,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-xl bg-cyan-600 hover:bg-cyan-500 text-white transition-all",children:[e.jsx(kt,{size:13})," Resume"]}),e.jsxs("button",{onClick:me,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-xl bg-red-600/90 hover:bg-red-500 text-white transition-all",children:[e.jsx(os,{size:13})," Abort"]})]})]}),e.jsx("button",{onClick:j,className:"p-2 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-gray-300 transition-all",title:"Refresh",children:e.jsx(ur,{size:14})}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(an,{status:s.status}),(V||N)&&e.jsxs("span",{className:"text-xs text-gray-500 font-mono",children:[v+A,"/",J]}),s.duration!==void 0&&e.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1 font-mono",children:[e.jsx(ke,{size:12})," ",je(s.duration)]})]}),e.jsxs("button",{onClick:()=>l(S=>!S),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-xl transition-all border
21
+ ${k?"bg-cyan-500/15 text-cyan-400 border-cyan-500/20":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50 border-transparent"}`,children:[e.jsx(fs,{size:13})," History"]})]}),I&&e.jsxs("div",{className:"mx-5 mt-3 px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/15 text-sm text-red-400 flex items-start gap-2",children:[e.jsx(Ne,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"flex-1",children:I}),e.jsx("button",{onClick:()=>E(null),className:"text-red-500 hover:text-red-300",children:e.jsx(he,{size:14})})]}),z&&t.definition.variables&&F&&e.jsxs("div",{className:"mx-5 mt-3 p-4 rounded-xl bg-surface-2/40 border border-white/5",children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-3 flex items-center gap-1.5",children:[e.jsx(Re,{size:12})," Variable Overrides"]}),e.jsx("div",{className:"space-y-2",children:Object.entries(t.definition.variables).map(([S,T])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-violet-400 font-mono font-medium w-28 truncate shrink-0",title:S,children:S}),e.jsx("input",{type:"text",className:"flex-1 px-3 py-1.5 bg-surface-2/60 border border-white/5 rounded-lg text-sm text-gray-200 placeholder-gray-600",value:L[S]||"",onChange:G=>m(re=>({...re,[S]:G.target.value})),placeholder:typeof T=="string"?T:JSON.stringify(T)})]},S))})]}),s&&(V||N)&&e.jsx("div",{className:"mx-5 mt-3",children:e.jsx("div",{className:"h-1.5 bg-surface-2/40 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${A>0?"bg-gradient-to-r from-emerald-500 to-red-500":"bg-gradient-to-r from-emerald-500 to-cyan-500"}`,style:{width:`${ne}%`}})})}),s&&B&&e.jsxs("div",{className:`mx-5 mt-3 p-4 rounded-xl border ${s.status==="completed"?"bg-emerald-500/5 border-emerald-500/20":s.status==="failed"?"bg-red-500/5 border-red-500/20":"bg-gray-500/5 border-gray-500/20"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[s.status==="completed"&&e.jsx(js,{size:16,className:"text-emerald-400"}),s.status==="failed"&&e.jsx(mr,{size:16,className:"text-red-400"}),s.status==="aborted"&&e.jsx(os,{size:16,className:"text-gray-400"}),e.jsx("span",{className:`text-sm font-semibold capitalize ${s.status==="completed"?"text-emerald-400":s.status==="failed"?"text-red-400":"text-gray-400"}`,children:s.status==="completed"?"Workflow Completed":s.status==="failed"?"Workflow Failed":"Workflow Aborted"})]}),s.duration!==void 0&&e.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1 font-mono",children:[e.jsx(ke,{size:12})," ",je(s.duration)]})]}),e.jsxs("div",{className:"flex gap-3 text-xs",children:[e.jsxs("span",{className:"text-emerald-400 font-medium",children:[v," passed"]}),A>0&&e.jsxs("span",{className:"text-red-400 font-medium",children:[A," failed"]}),e.jsxs("span",{className:"text-gray-500",children:[J," total"]})]}),s.error&&e.jsxs("div",{className:"mt-3 flex items-start gap-2 px-3.5 py-2.5 rounded-xl bg-red-500/10 border border-red-500/15",children:[e.jsx(Ne,{size:14,className:"text-red-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-red-300/90 break-all",children:s.error})]})]}),s&&!B&&e.jsxs("div",{className:"mx-5 mt-3 mb-4",children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2 flex items-center gap-1.5",children:[e.jsx(qt,{size:12})," Step Progress"]}),e.jsx("div",{className:"rounded-xl border border-white/5 overflow-hidden bg-surface-2/40",children:e.jsxs("div",{className:"divide-y divide-white/5 max-h-[300px] overflow-y-auto",children:[t.definition.steps.map(S=>{if(S.disabled)return null;const T=s.stepResults[S.id],G=(T==null?void 0:T.status)||"pending",re=it(S),y=Me[re],_=Qs[y.iconName],X=o[S.id],U=n[S.id],Z=O.has(S.id),f=G==="waiting",P=Nt(G);return P.icon,e.jsxs("div",{children:[e.jsxs("div",{onClick:()=>(U||(T==null?void 0:T.outputs))&&we(S.id),className:`flex items-center gap-3 px-4 py-2.5 text-sm transition-all ${U||T!=null&&T.outputs?"cursor-pointer hover:bg-surface-3/30":""} ${G==="running"?"bg-cyan-500/5":G==="waiting"?"bg-amber-500/5":""}`,children:[U||T!=null&&T.outputs?Z?e.jsx(Ee,{size:14,className:"text-gray-400 shrink-0"}):e.jsx(Ce,{size:14,className:"text-gray-500 shrink-0"}):e.jsx("span",{className:"w-[14px] shrink-0"}),_&&e.jsx(_,{size:14,className:y.textClass}),e.jsx("span",{className:"text-gray-200 font-medium flex-1 text-left truncate",children:S.id}),X&&e.jsx("span",{className:"text-xs text-gray-500 truncate max-w-[140px]",children:X.message}),e.jsxs("span",{className:`text-xs capitalize px-2 py-0.5 rounded-md ${P.bg} ${P.text} border ${P.border} font-medium`,children:[G==="running"&&e.jsx(be,{size:11,className:"inline animate-spin mr-1"}),G]}),(T==null?void 0:T.duration)!==void 0&&e.jsx("span",{className:"text-xs text-gray-500 font-mono",children:je(T.duration)})]}),f&&e.jsxs("div",{className:"px-5 py-3 bg-amber-500/10 border-t border-amber-500/10",children:[e.jsxs("p",{className:"text-sm text-amber-300 mb-2",children:[e.jsx(Qt,{size:13,className:"inline mr-1"}),"Waiting for approval",S.message?`: ${S.message}`:""]}),e.jsxs("button",{onClick:le,className:"flex items-center gap-1.5 px-4 py-1.5 rounded-xl bg-amber-600 hover:bg-amber-500 text-white text-xs font-medium transition-all",children:[e.jsx(Se,{size:13})," Approve & Continue"]})]}),Z&&e.jsxs("div",{className:"px-5 pb-4 ml-8 space-y-3 bg-surface-2/20 border-t border-white/5",children:[(T==null?void 0:T.error)&&e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-3 rounded-xl bg-red-500/10 border border-red-500/15 mt-2",children:[e.jsx(Ne,{size:14,className:"text-red-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-red-300/90 break-all",children:T.error})]}),U&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-1.5 flex items-center gap-1.5",children:[e.jsx(qt,{size:12})," Output"]}),e.jsx("div",{className:"bg-surface-2/60 rounded-xl p-4 max-h-[300px] overflow-y-auto text-sm text-gray-200 leading-relaxed border border-white/5",children:e.jsx(Ns,{text:U.slice(-4e3)})})]}),(T==null?void 0:T.outputs)&&Object.keys(T.outputs).length>0&&e.jsx(hs,{outputs:T.outputs}),!U&&(!(T!=null&&T.outputs)||Object.keys(T.outputs).length===0)&&!(T!=null&&T.error)&&e.jsx("p",{className:"text-xs text-gray-500 italic mt-2",children:"No output data"})]})]},S.id)}),e.jsx("div",{ref:g})]})})]}),s&&B&&e.jsxs("div",{className:"mx-5 mt-3 mb-4",children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2 flex items-center gap-1.5",children:[e.jsx(qt,{size:12})," Step Results"]}),e.jsx("div",{className:"rounded-xl border border-white/5 overflow-hidden bg-surface-2/40",children:e.jsx("div",{className:"divide-y divide-white/5 max-h-[400px] overflow-y-auto",children:t.definition.steps.map(S=>{if(S.disabled)return null;const T=s.stepResults[S.id],G=(T==null?void 0:T.status)||"skipped",re=it(S),y=Me[re],_=Qs[y.iconName],X=(T==null?void 0:T.outputs)&&Object.keys(T.outputs).length>0,U=!!(T!=null&&T.error),Z=X||U,f=O.has(S.id),P=Nt(G),K=P.icon;return e.jsxs("div",{children:[e.jsxs("div",{onClick:()=>Z&&we(S.id),className:`flex items-center gap-3 px-4 py-2.5 text-sm transition-all ${Z?"cursor-pointer hover:bg-surface-3/30":""}`,children:[Z?f?e.jsx(Ee,{size:14,className:"text-gray-400 shrink-0"}):e.jsx(Ce,{size:14,className:"text-gray-500 shrink-0"}):e.jsx("span",{className:"w-[14px] shrink-0"}),e.jsx(K,{size:14,className:`${P.text} shrink-0`}),_&&e.jsx(_,{size:14,className:y.textClass}),e.jsx("span",{className:"text-gray-200 font-medium flex-1 text-left truncate",children:S.id}),e.jsx("span",{className:`text-xs capitalize px-2 py-0.5 rounded-md ${P.bg} ${P.text} border ${P.border} font-medium`,children:G}),(T==null?void 0:T.duration)!==void 0&&e.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1 font-mono",children:[e.jsx(ke,{size:11})," ",je(T.duration)]})]}),f&&Z&&e.jsxs("div",{className:"px-5 pb-4 ml-8 space-y-3 bg-surface-2/20 border-t border-white/5",children:[U&&e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-3 rounded-xl bg-red-500/10 border border-red-500/15 mt-2",children:[e.jsx(Ne,{size:14,className:"text-red-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-red-300/90 break-all font-mono",children:T.error})]}),X&&e.jsx(hs,{outputs:T.outputs})]})]},S.id)})})})]}),k&&e.jsxs("div",{className:"mx-5 mt-3 mb-4",children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2 flex items-center gap-1.5",children:[e.jsx(fs,{size:12})," Recent Runs"]}),M.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 gap-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-surface-2/50 flex items-center justify-center",children:e.jsx(ke,{size:20,className:"text-gray-500"})}),e.jsx("p",{className:"text-sm text-gray-500",children:"No runs yet"})]}):e.jsx("div",{className:"rounded-xl border border-white/5 overflow-hidden bg-surface-2/40",children:e.jsx("div",{className:"divide-y divide-white/5 max-h-[250px] overflow-y-auto",children:M.map(S=>{const T=Nt(S.status),G=T.icon;return e.jsxs("div",{children:[e.jsxs("div",{onClick:()=>D(u===S.runId?null:S.runId),className:`flex items-center gap-3 px-4 py-2.5 text-sm transition-all cursor-pointer
22
+ ${u===S.runId?"bg-surface-2/30":"hover:bg-surface-3/30"}`,children:[u===S.runId?e.jsx(Ee,{size:14,className:"text-gray-400 shrink-0"}):e.jsx(Ce,{size:14,className:"text-gray-500 shrink-0"}),e.jsxs("div",{className:`flex items-center gap-1.5 shrink-0 px-2 py-0.5 rounded-md ${T.bg} border ${T.border}`,children:[e.jsx(G,{size:12,className:`${T.text} ${S.status==="running"?"animate-spin":""}`}),e.jsx("span",{className:`text-xs font-semibold capitalize ${T.text}`,children:S.status})]}),e.jsx("span",{className:"text-xs text-gray-400 capitalize bg-surface-3/50 px-2 py-0.5 rounded-md shrink-0",children:S.trigger}),e.jsx("span",{className:"text-xs text-gray-400 flex-1 text-left truncate font-mono",children:S.runId.slice(0,12)}),S.duration!==void 0&&e.jsxs("span",{className:"text-xs text-gray-500 font-mono flex items-center gap-1",children:[e.jsx(ke,{size:11})," ",je(S.duration)]}),e.jsx("span",{className:"text-xs text-gray-500",children:wt(S.startedAt)})]}),u===S.runId&&e.jsxs("div",{className:"px-5 pb-4 ml-8 space-y-2 bg-surface-2/20 border-t border-white/5",children:[e.jsx("div",{className:"divide-y divide-white/5 mt-2 rounded-xl border border-white/5 overflow-hidden bg-surface-2/40",children:Object.values(S.stepResults).map(re=>{const y=re.outputs&&Object.keys(re.outputs).length>0,_=`hist-${S.runId}-${re.stepId}`,X=O.has(_),U=Nt(re.status),Z=U.icon;return e.jsxs("div",{children:[e.jsxs("div",{onClick:()=>y&&we(_),className:`flex items-center gap-3 px-4 py-2 text-sm transition-all ${y?"cursor-pointer hover:bg-surface-3/30":""}`,children:[y?X?e.jsx(Ee,{size:12,className:"text-gray-400 shrink-0"}):e.jsx(Ce,{size:12,className:"text-gray-500 shrink-0"}):e.jsx("span",{className:"w-3 shrink-0"}),e.jsx(Z,{size:12,className:`${U.text} shrink-0`}),e.jsx("span",{className:"text-gray-300 font-medium font-mono flex-1 text-left truncate",children:re.stepId}),e.jsx("span",{className:`text-xs capitalize px-2 py-0.5 rounded-md ${U.bg} ${U.text} border ${U.border} font-medium`,children:re.status}),re.duration!==void 0&&e.jsx("span",{className:"text-xs text-gray-500 font-mono",children:je(re.duration)})]}),X&&y&&e.jsx("div",{className:"px-5 pb-3 ml-6 bg-surface-2/20 border-t border-white/5",children:e.jsx("div",{className:"mt-2",children:e.jsx(hs,{outputs:re.outputs})})})]},re.stepId)})}),S.error&&e.jsxs("div",{className:"flex items-start gap-2 px-3.5 py-2.5 rounded-xl bg-red-500/10 border border-red-500/15",children:[e.jsx(Ne,{size:13,className:"text-red-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-red-300/90 break-all",children:S.error})]})]})]},S.runId)})})})]})]})}const sn=new Set(["response","result","output","stdout"]);function hs({outputs:t}){const s=Object.entries(t);if(s.length===0)return null;const n=s.find(([j,d])=>sn.has(j)&&typeof d=="string"&&d.length>40),w=s.filter(([j])=>!(n&&j===n[0])).filter(([,j])=>!(j==null||j===""||Array.isArray(j)&&j.length===0));return e.jsxs("div",{className:"space-y-2",children:[w.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:w.map(([j,d])=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-lg bg-surface-3/50 border border-white/5",children:[e.jsx("span",{className:"text-cyan-400 font-mono font-medium",children:j}),e.jsx("span",{className:"text-gray-400 max-w-[250px] truncate",children:typeof d=="string"?d:typeof d=="number"?String(d):JSON.stringify(d).slice(0,100)})]},j))}),n&&e.jsx("div",{className:"bg-surface-2/60 rounded-xl p-4 border border-white/5 max-h-[400px] overflow-y-auto text-sm text-gray-200 leading-relaxed",children:e.jsx(Ns,{text:n[1]})}),!n&&w.length===0&&s.length>0&&e.jsx("div",{className:"bg-surface-2/60 rounded-xl p-3 border border-white/5 max-h-[200px] overflow-y-auto",children:s.map(([j,d])=>e.jsxs("div",{className:"text-sm flex gap-2 mb-1",children:[e.jsxs("span",{className:"text-cyan-400 font-mono font-medium shrink-0",children:[j,":"]}),e.jsx("span",{className:"text-gray-300 break-all",children:typeof d=="string"?d:JSON.stringify(d,null,2)})]},j))})]})}function an({status:t}){const s=Nt(t),n=s.icon;return e.jsxs("span",{className:`flex items-center gap-1.5 text-xs font-semibold capitalize px-2.5 py-1 rounded-lg ${s.bg} ${s.text} border ${s.border}`,children:[e.jsx(n,{size:12,className:t==="running"?"animate-spin":""}),t]})}function rn({open:t,onClose:s,onCreated:n}){const[o,w]=r.useState([]),[j,d]=r.useState(!1),[$,I]=r.useState(null),[E,k]=r.useState({}),[l,M]=r.useState(""),[h,u]=r.useState(!1),[D,O]=r.useState(null),[c,z]=r.useState(""),[C,L]=r.useState(null);r.useEffect(()=>{t&&(d(!0),I(null),z(""),L(null),Ya().then(({templates:N})=>w(N)).catch(()=>{}).finally(()=>d(!1)))},[t]);const m=r.useMemo(()=>[...new Set(o.map(B=>B.category))].sort(),[o]),g=r.useMemo(()=>{let N=o;if(C&&(N=N.filter(B=>B.category===C)),c.trim()){const B=c.toLowerCase();N=N.filter(v=>v.name.toLowerCase().includes(B)||v.description.toLowerCase().includes(B)||v.category.toLowerCase().includes(B))}return N},[o,C,c]);function F(N){I(N),M(N.id);const B={};for(const v of N.parameters)v.default!==void 0&&(B[v.name]=v.default);k(B),O(null)}async function V(){if($){u(!0),O(null);try{const{workflow:N}=await Fa($.id,E,l||void 0);n(N.id),s()}catch(N){O(N instanceof Error?N.message:String(N))}finally{u(!1)}}}return t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:s}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[720px] max-h-[85vh] flex flex-col animate-fade-in shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/5 bg-surface-2/30 rounded-t-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nt,{size:18,className:"text-cyan-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:$?"Configure Template":"Workflow Templates"})]}),e.jsx("button",{onClick:s,className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-400 hover:text-gray-200 transition-all",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-5",children:[j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(be,{size:24,className:"animate-spin text-cyan-400"})}):$?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-surface-2/40",children:[e.jsx("span",{className:"text-2xl",children:$.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-100",children:$.name}),e.jsx("p",{className:"text-xs text-gray-400",children:$.description})]}),e.jsx("button",{onClick:()=>I(null),className:"ml-auto text-xs text-cyan-400 hover:text-cyan-300",children:"Change"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-300 block mb-1",children:"Workflow ID"}),e.jsx("input",{type:"text",value:l,onChange:N=>M(N.target.value),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-cyan-500/30 transition-all",placeholder:"e.g., my-regression-pipeline"})]}),$.parameters.map(N=>{var B;return e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-medium text-gray-300 block mb-1",children:[N.label,N.required&&e.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),N.description&&e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:N.description}),N.type==="boolean"?e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:!!E[N.name],onChange:v=>k(A=>({...A,[N.name]:v.target.checked})),className:"rounded border-white/10 bg-surface-2 text-cyan-500 focus:ring-cyan-500/30"}),e.jsx("span",{className:"text-sm text-gray-300",children:N.label})]}):N.type==="select"||N.type==="multiselect"?e.jsxs("select",{value:String(E[N.name]??""),onChange:v=>k(A=>({...A,[N.name]:v.target.value})),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 focus:outline-none focus:border-cyan-500/30 transition-all",children:[e.jsx("option",{value:"",children:"Select..."}),(B=N.options)==null?void 0:B.map(v=>e.jsx("option",{value:v,children:v},v))]}):N.type==="number"?e.jsx("input",{type:"number",value:E[N.name]!==void 0?String(E[N.name]):"",onChange:v=>k(A=>({...A,[N.name]:v.target.value?Number(v.target.value):void 0})),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-cyan-500/30 transition-all",placeholder:N.default!==void 0?String(N.default):""}):e.jsx("input",{type:"text",value:String(E[N.name]??""),onChange:v=>k(A=>({...A,[N.name]:v.target.value})),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-cyan-500/30 transition-all",placeholder:N.default!==void 0?String(N.default):""})]},N.name)})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ot,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:c,onChange:N=>z(N.target.value),className:"w-full pl-9 pr-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-cyan-500/30 transition-all",placeholder:"Search templates..."})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs("button",{onClick:()=>L(null),className:`text-xs px-2.5 py-1 rounded-xl transition-all ${C?"bg-surface-2/40 text-gray-400 hover:text-gray-200 border border-transparent":"bg-cyan-500/15 text-cyan-300 border border-cyan-500/30"}`,children:["All (",o.length,")"]}),m.map(N=>{const B=o.filter(v=>v.category===N).length;return e.jsxs("button",{onClick:()=>L(C===N?null:N),className:`text-xs px-2.5 py-1 rounded-xl capitalize transition-all ${C===N?"bg-cyan-500/15 text-cyan-300 border border-cyan-500/30":"bg-surface-2/40 text-gray-400 hover:text-gray-200 border border-transparent"}`,children:[N," (",B,")"]},N)})]})]}),g.length===0?e.jsx("div",{className:"text-center py-8 text-xs text-gray-500",children:"No templates match your filter"}):e.jsx("div",{className:"grid grid-cols-2 gap-3",children:g.map(N=>e.jsxs("button",{onClick:()=>F(N),className:"text-left p-4 rounded-xl border border-white/5 bg-surface-2/40 hover:bg-surface-2/60 hover:border-cyan-500/20 transition-all",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-xl",children:N.icon}),e.jsx("span",{className:"text-sm font-semibold text-gray-100",children:N.name})]}),e.jsx("p",{className:"text-xs text-gray-400 line-clamp-2",children:N.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-surface-3/50 text-gray-500 capitalize",children:N.category}),e.jsxs("span",{className:"text-xs text-gray-600",children:[N.parameters.length," parameter",N.parameters.length!==1?"s":""]})]})]},N.id))})]}),D&&e.jsx("div",{className:"mt-3 px-3 py-2 rounded-xl bg-red-500/10 border border-red-500/20 text-xs text-red-400",children:D})]}),$&&e.jsxs("div",{className:"flex justify-end gap-2 px-5 py-4 border-t border-white/5 bg-surface-2/30 rounded-b-2xl",children:[e.jsx("button",{onClick:s,className:"px-4 py-2 text-sm rounded-xl bg-surface-2/40 hover:bg-surface-3/50 text-gray-300 transition-all",children:"Cancel"}),e.jsxs("button",{onClick:V,disabled:h,className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-xl bg-cyan-600 hover:bg-cyan-500 text-white disabled:opacity-50 transition-all",children:[h?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(nt,{size:14}),"Create Workflow"]})]})]})]}):null}function nn({workflowId:t,onClose:s}){const[n,o]=la("whtab",["webhooks","events"],"webhooks"),[w,j]=r.useState([]),[d,$]=r.useState([]),[I,E]=r.useState([]),[k,l]=r.useState(!1),[M,h]=r.useState(null),[u,D]=r.useState(null),[O,c]=r.useState(!1),[z,C]=r.useState(""),[L,m]=r.useState([]),[g,F]=r.useState(null),[V,N]=r.useState(!1),[B,v]=r.useState(!1),[A,J]=r.useState(""),[ne,ue]=r.useState([]),[b,H]=r.useState(!1),[le,me]=r.useState(null),ye=r.useCallback(async()=>{l(!0);try{const{webhooks:f}=await _a(t);j(f)}catch(f){h(f instanceof Error?f.message:String(f))}finally{l(!1)}},[t]),we=r.useCallback(async()=>{try{const{subscriptions:f}=await Xa(t);$(f)}catch{}},[t]),S=r.useCallback(async()=>{try{const{workflows:f}=await gs();E(f)}catch{}},[]);r.useEffect(()=>{ye(),we(),S()},[ye,we,S]);async function T(){N(!0),h(null);try{const f={};for(const P of L)P.key.trim()&&P.value.trim()&&(f[P.key.trim()]=P.value.trim());await Ua(t,{name:z.trim()||void 0,variableMapping:Object.keys(f).length>0?f:void 0,filter:g||void 0}),c(!1),C(""),m([]),F(null),await ye()}catch(f){h(f instanceof Error?f.message:String(f))}finally{N(!1)}}async function G(f){try{await Ba(t,f),await ye()}catch(P){h(P instanceof Error?P.message:String(P))}}async function re(f,P){try{await Ha(t,f,{enabled:P}),await ye()}catch(K){h(K instanceof Error?K.message:String(K))}}async function y(){if(A.trim()){H(!0);try{const f={};for(const K of ne)K.key.trim()&&K.value.trim()&&(f[K.key.trim()]=K.value.trim());const P=[...d,{eventPattern:A.trim(),enabled:!0,variableMapping:Object.keys(f).length>0?f:void 0}];await is(t,P),$(P),v(!1),J(""),ue([])}catch(f){h(f instanceof Error?f.message:String(f))}finally{H(!1)}}}async function _(f){const P=d.filter((K,ie)=>ie!==f);try{await is(t,P),$(P)}catch(K){h(K instanceof Error?K.message:String(K))}}async function X(f){const P=d.map((K,ie)=>ie===f?{...K,enabled:!K.enabled}:K);try{await is(t,P),$(P)}catch(K){h(K instanceof Error?K.message:String(K))}}function U(f,P){navigator.clipboard.writeText(f),D(P),setTimeout(()=>D(null),2e3)}const Z=`${window.location.origin}/api/webhooks/`;return e.jsxs("div",{className:"w-80 flex-shrink-0 border-l border-white/5 bg-surface-1 overflow-y-auto flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vt,{size:16,className:"text-cyan-400"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-100",children:"Triggers"})]}),e.jsx("button",{onClick:s,className:"p-1 rounded hover:bg-surface-3 text-gray-500",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"flex items-center gap-1 p-2 bg-surface-0 border-b border-white/5",children:[e.jsxs("button",{onClick:()=>o("webhooks"),className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs rounded-md transition-colors ${n==="webhooks"?"bg-surface-3 text-cyan-300":"text-gray-500 hover:text-gray-300"}`,children:[e.jsx(vt,{size:12})," Webhooks",w.length>0&&e.jsx("span",{className:"ml-1 text-[10px] px-1.5 py-0.5 rounded-full bg-cyan-500/15 text-cyan-400",children:w.length})]}),e.jsxs("button",{onClick:()=>o("events"),className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs rounded-md transition-colors ${n==="events"?"bg-surface-3 text-cyan-300":"text-gray-500 hover:text-gray-300"}`,children:[e.jsx(Re,{size:12})," Events",d.length>0&&e.jsx("span",{className:"ml-1 text-[10px] px-1.5 py-0.5 rounded-full bg-purple-500/15 text-purple-400",children:d.length})]})]}),M&&e.jsxs("div",{className:"mx-3 mt-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/20 text-[11px] text-red-400",children:[M,e.jsx("button",{onClick:()=>h(null),className:"ml-2 text-red-500 hover:text-red-300",children:e.jsx(he,{size:10})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:k?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(be,{size:20,className:"animate-spin text-cyan-400"})}):n==="webhooks"?e.jsxs(e.Fragment,{children:[w.length===0&&!O&&e.jsxs("div",{className:"text-center py-6 text-xs text-gray-600",children:[e.jsx(vt,{size:24,className:"mx-auto mb-2 text-gray-700"}),e.jsx("p",{children:"No webhooks configured"}),e.jsx("p",{className:"text-[10px] text-gray-700 mt-1",children:"Add one to trigger this workflow from external systems"})]}),w.map(f=>e.jsxs("div",{className:"rounded-lg border border-white/5 bg-surface-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-surface-2 transition-colors",onClick:()=>me(le===f.webhookId?null:f.webhookId),children:[le===f.webhookId?e.jsx(Ee,{size:12,className:"text-gray-500"}):e.jsx(Ce,{size:12,className:"text-gray-500"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs font-medium text-gray-200 truncate block",children:f.name||"Unnamed Webhook"}),f.lastTriggeredAt&&e.jsxs("span",{className:"text-[10px] text-gray-600",children:["Last: ",wt(f.lastTriggeredAt)]})]}),e.jsx("button",{onClick:P=>{P.stopPropagation(),re(f.webhookId,!f.enabled)},className:`flex-shrink-0 ${f.enabled?"text-cyan-400":"text-gray-600"}`,title:f.enabled?"Disable":"Enable",children:f.enabled?e.jsx(Ys,{size:16}):e.jsx(Fs,{size:16})})]}),le===f.webhookId&&e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 border-t border-white/5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"URL"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("code",{className:"flex-1 text-[10px] text-cyan-300 bg-surface-2 px-2 py-1 rounded font-mono truncate",children:[Z,f.webhookId]}),e.jsx("button",{onClick:()=>U(`${Z}${f.webhookId}`,`url-${f.webhookId}`),className:"p-1 rounded hover:bg-surface-3 text-gray-500",title:"Copy URL",children:u===`url-${f.webhookId}`?e.jsx(Se,{size:11,className:"text-emerald-400"}):e.jsx(Xe,{size:11})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Secret"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("code",{className:"flex-1 text-[10px] text-gray-400 bg-surface-2 px-2 py-1 rounded font-mono truncate",children:f.secret}),e.jsx("button",{onClick:()=>U(f.secret,`secret-${f.webhookId}`),className:"p-1 rounded hover:bg-surface-3 text-gray-500",title:"Copy Secret",children:u===`secret-${f.webhookId}`?e.jsx(Se,{size:11,className:"text-emerald-400"}):e.jsx(Xe,{size:11})})]})]}),f.filter&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Filter"}),e.jsxs("div",{className:"text-[10px] text-gray-400 bg-surface-2 px-2 py-1 rounded font-mono",children:[f.filter.field," ",f.filter.operator,' "',f.filter.value,'"']})]}),f.variableMapping&&Object.keys(f.variableMapping).length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Variable Mapping"}),Object.entries(f.variableMapping).map(([P,K])=>e.jsxs("div",{className:"text-[10px] text-gray-400 font-mono",children:[e.jsx("span",{className:"text-amber-400",children:P})," ← ",e.jsx("span",{className:"text-cyan-400",children:K})]},P))]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Example"}),e.jsxs("div",{className:"relative",children:[e.jsx("code",{className:"block text-[9px] text-gray-500 bg-surface-2 px-2 py-1.5 rounded font-mono whitespace-pre-wrap break-all leading-relaxed",children:`curl -X POST ${Z}${f.webhookId} \\
23
+ -H "X-Webhook-Token: <secret>" \\
24
+ -H "Content-Type: application/json" \\
25
+ -d '{"ref":"main"}'`}),e.jsx("button",{onClick:()=>U(`curl -X POST ${Z}${f.webhookId} -H "X-Webhook-Token: ${f.secret}" -H "Content-Type: application/json" -d '{"ref":"main"}'`,`curl-${f.webhookId}`),className:"absolute top-1 right-1 p-0.5 rounded hover:bg-surface-3 text-gray-600",title:"Copy curl command",children:u===`curl-${f.webhookId}`?e.jsx(Se,{size:9,className:"text-emerald-400"}):e.jsx(Xe,{size:9})})]})]}),e.jsxs("button",{onClick:()=>G(f.webhookId),className:"flex items-center gap-1 text-[10px] text-red-400 hover:text-red-300 mt-1",children:[e.jsx(lt,{size:10})," Delete webhook"]})]})]},f.webhookId)),O?e.jsxs("div",{className:"rounded-lg border border-cyan-500/20 bg-surface-0 p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-gray-300 block mb-1",children:"Name (optional)"}),e.jsx("input",{type:"text",value:z,onChange:f=>C(f.target.value),className:"w-full px-2 py-1.5 bg-surface-2 border border-white/10 rounded text-xs text-gray-100 placeholder-gray-500 focus:outline-none focus:border-cyan-500/50",placeholder:"e.g., GitHub Push"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-[10px] font-medium text-gray-300",children:"Variable Mapping"}),e.jsx("button",{onClick:()=>m([...L,{key:"",value:""}]),className:"text-[10px] text-cyan-400 hover:text-cyan-300",children:"+ Add"})]}),L.map((f,P)=>e.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[e.jsx("input",{type:"text",value:f.key,onChange:K=>{const ie=[...L];ie[P]={...ie[P],key:K.target.value},m(ie)},className:"flex-1 px-2 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-100 font-mono placeholder-gray-600 focus:outline-none",placeholder:"workflowVar"}),e.jsx("span",{className:"text-gray-600 text-[10px]",children:"←"}),e.jsx("input",{type:"text",value:f.value,onChange:K=>{const ie=[...L];ie[P]={...ie[P],value:K.target.value},m(ie)},className:"flex-1 px-2 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-100 font-mono placeholder-gray-600 focus:outline-none",placeholder:"payload.path"}),e.jsx("button",{onClick:()=>m(L.filter((K,ie)=>ie!==P)),className:"p-0.5 text-gray-600 hover:text-red-400",children:e.jsx(he,{size:10})})]},P))]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-[10px] font-medium text-gray-300",children:"Filter (optional)"}),g?e.jsx("button",{onClick:()=>F(null),className:"text-[10px] text-red-400 hover:text-red-300",children:"Remove"}):e.jsx("button",{onClick:()=>F({field:"",operator:"eq",value:""}),className:"text-[10px] text-cyan-400 hover:text-cyan-300",children:"+ Add"})]}),g&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"text",value:g.field,onChange:f=>F({...g,field:f.target.value}),className:"flex-1 px-2 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-100 font-mono placeholder-gray-600 focus:outline-none",placeholder:"action"}),e.jsxs("select",{value:g.operator,onChange:f=>F({...g,operator:f.target.value}),className:"px-1.5 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-300 focus:outline-none",children:[e.jsx("option",{value:"eq",children:"="}),e.jsx("option",{value:"neq",children:"≠"}),e.jsx("option",{value:"contains",children:"contains"}),e.jsx("option",{value:"matches",children:"matches"})]}),e.jsx("input",{type:"text",value:g.value,onChange:f=>F({...g,value:f.target.value}),className:"flex-1 px-2 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-100 font-mono placeholder-gray-600 focus:outline-none",placeholder:"push"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("button",{onClick:()=>{c(!1),C(""),m([]),F(null)},className:"flex-1 px-2 py-1.5 text-[10px] rounded bg-surface-2 hover:bg-surface-3 text-gray-400",children:"Cancel"}),e.jsxs("button",{onClick:T,disabled:V,className:"flex-1 flex items-center justify-center gap-1 px-2 py-1.5 text-[10px] font-medium rounded bg-cyan-600 hover:bg-cyan-500 text-white disabled:opacity-50",children:[V?e.jsx(be,{size:10,className:"animate-spin"}):e.jsx(Ie,{size:10}),"Create"]})]})]}):e.jsxs("button",{onClick:()=>c(!0),className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg border border-dashed border-white/10 hover:border-cyan-500/30 text-xs text-gray-500 hover:text-cyan-400 transition-colors",children:[e.jsx(Ie,{size:12})," Add Webhook"]})]}):e.jsxs(e.Fragment,{children:[d.length===0&&!B&&e.jsxs("div",{className:"text-center py-6 text-xs text-gray-600",children:[e.jsx(Re,{size:24,className:"mx-auto mb-2 text-gray-700"}),e.jsx("p",{children:"No event subscriptions"}),e.jsx("p",{className:"text-[10px] text-gray-700 mt-1",children:"Chain workflows by subscribing to completion/failure events"})]}),d.map((f,P)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg border border-white/5 bg-surface-0",children:[e.jsx("button",{onClick:()=>X(P),className:`flex-shrink-0 ${f.enabled?"text-purple-400":"text-gray-600"}`,children:f.enabled?e.jsx(Ys,{size:16}):e.jsx(Fs,{size:16})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("code",{className:"text-[10px] text-purple-300 font-mono block truncate",children:f.eventPattern}),f.variableMapping&&Object.keys(f.variableMapping).length>0&&e.jsxs("span",{className:"text-[9px] text-gray-600",children:[Object.keys(f.variableMapping).length," var mapping",Object.keys(f.variableMapping).length!==1?"s":""]})]}),e.jsx("button",{onClick:()=>_(P),className:"p-1 rounded hover:bg-red-500/20 text-gray-600 hover:text-red-400",children:e.jsx(lt,{size:11})})]},P)),B?e.jsxs("div",{className:"rounded-lg border border-purple-500/20 bg-surface-0 p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-gray-300 block mb-1",children:"Event Pattern"}),e.jsx("input",{type:"text",value:A,onChange:f=>J(f.target.value),className:"w-full px-2 py-1.5 bg-surface-2 border border-white/10 rounded text-xs text-gray-100 font-mono placeholder-gray-500 focus:outline-none focus:border-purple-500/50",placeholder:"workflow:completed:smoke-tests"}),e.jsx("p",{className:"text-[9px] text-gray-600 mt-1",children:"Use * as wildcard: workflow:completed:* matches all"})]}),I.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-500 block mb-1",children:"Quick patterns"}),e.jsx("div",{className:"flex flex-wrap gap-1 max-h-20 overflow-y-auto",children:I.filter(f=>f.id!==t).slice(0,10).map(f=>e.jsx("button",{onClick:()=>J(`workflow:completed:${f.id}`),className:`text-[9px] px-1.5 py-0.5 rounded transition-colors ${A===`workflow:completed:${f.id}`?"bg-purple-500/15 text-purple-300 border border-purple-500/30":"bg-surface-2 text-gray-500 hover:text-gray-300 border border-transparent"}`,children:f.id},f.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-[10px] font-medium text-gray-300",children:"Variable Mapping"}),e.jsx("button",{onClick:()=>ue([...ne,{key:"",value:""}]),className:"text-[10px] text-purple-400 hover:text-purple-300",children:"+ Add"})]}),ne.map((f,P)=>e.jsxs("div",{className:"flex items-center gap-1 mb-1",children:[e.jsx("input",{type:"text",value:f.key,onChange:K=>{const ie=[...ne];ie[P]={...ie[P],key:K.target.value},ue(ie)},className:"flex-1 px-2 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-100 font-mono placeholder-gray-600 focus:outline-none",placeholder:"targetVar"}),e.jsx("span",{className:"text-gray-600 text-[10px]",children:"←"}),e.jsx("input",{type:"text",value:f.value,onChange:K=>{const ie=[...ne];ie[P]={...ie[P],value:K.target.value},ue(ie)},className:"flex-1 px-2 py-1 bg-surface-2 border border-white/10 rounded text-[10px] text-gray-100 font-mono placeholder-gray-600 focus:outline-none",placeholder:"source.path"}),e.jsx("button",{onClick:()=>ue(ne.filter((K,ie)=>ie!==P)),className:"p-0.5 text-gray-600 hover:text-red-400",children:e.jsx(he,{size:10})})]},P))]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("button",{onClick:()=>{v(!1),J(""),ue([])},className:"flex-1 px-2 py-1.5 text-[10px] rounded bg-surface-2 hover:bg-surface-3 text-gray-400",children:"Cancel"}),e.jsxs("button",{onClick:y,disabled:!A.trim()||b,className:"flex-1 flex items-center justify-center gap-1 px-2 py-1.5 text-[10px] font-medium rounded bg-purple-600 hover:bg-purple-500 text-white disabled:opacity-50",children:[b?e.jsx(be,{size:10,className:"animate-spin"}):e.jsx(Ie,{size:10}),"Add"]})]})]}):e.jsxs("button",{onClick:()=>v(!0),className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg border border-dashed border-white/10 hover:border-purple-500/30 text-xs text-gray-500 hover:text-purple-400 transition-colors",children:[e.jsx(Ie,{size:12})," Add Event Subscription"]})]})})]})}var ta={};function ln({workflowVariables:t,stepResults:s,show:n,onClose:o}){const[w,j]=r.useState(""),[d,$]=r.useState(new Set(["workflow","steps","runtime","env"])),[I,E]=r.useState(new Set),[k,l]=r.useState(null),[M,h]=r.useState(new Set),u=r.useRef("");r.useEffect(()=>{if(!s)return;const m=JSON.stringify(s);if(u.current&&u.current!==m){const g=JSON.parse(u.current),F=new Set;for(const[V,N]of Object.entries(s)){const B=g[V];if(!B||JSON.stringify(B)!==JSON.stringify(N))for(const v of Object.keys(N.outputs))F.add(`steps.${V}.outputs.${v}`)}if(F.size>0){h(F);const V=setTimeout(()=>h(new Set),3e3);return()=>clearTimeout(V)}}u.current=m},[s]);const D=r.useCallback(m=>{$(g=>{const F=new Set(g);return F.has(m)?F.delete(m):F.add(m),F})},[]),O=r.useCallback(m=>{E(g=>{const F=new Set(g);return F.has(m)?F.delete(m):F.add(m),F})},[]),c=r.useCallback(async m=>{try{await navigator.clipboard.writeText(`{{${m}}}`),l(m),setTimeout(()=>l(null),2e3)}catch{}},[]),z=xn(t,s),C=w.toLowerCase(),L=C?z.map(m=>({...m,entries:m.entries.filter(g=>g.key.toLowerCase().includes(C)||g.path.toLowerCase().includes(C)||String(g.value).toLowerCase().includes(C))})).filter(m=>m.entries.length>0||m.id==="env"):z;return n?e.jsxs("div",{className:"w-80 flex-shrink-0 border-l border-white/5 bg-surface-1 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ua,{size:16,className:"text-cyan-400"}),e.jsx("h3",{className:"text-sm font-semibold text-gray-100",children:"Variable Inspector"})]}),e.jsx("button",{onClick:o,className:"p-1 rounded hover:bg-surface-3 text-gray-500",children:e.jsx(he,{size:16})})]}),e.jsx("div",{className:"px-3 py-2 border-b border-white/5",children:e.jsxs("div",{className:"relative",children:[e.jsx(ot,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:w,onChange:m=>j(m.target.value),placeholder:"Filter variables...",className:"w-full pl-8 pr-3 py-1.5 text-xs bg-surface-0 border border-white/5 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-cyan-500/40"})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[L.map(m=>e.jsx(on,{id:m.id,label:m.label,count:m.entries.length,isExpanded:d.has(m.id),onToggle:()=>D(m.id),color:m.color,children:m.id==="env"?e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("span",{className:"text-[11px] text-gray-500",children:[m.envCount??0," environment variable",(m.envCount??0)!==1?"s":""," available"]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1",children:"Values hidden for security"})]}):m.entries.length===0?e.jsx("p",{className:"text-[11px] text-gray-600 text-center py-2",children:"No variables"}):e.jsx("div",{className:"space-y-px",children:m.entries.map(g=>e.jsx(cn,{entry:g,isRecentlyUpdated:M.has(g.path),isValueExpanded:I.has(g.path),isCopied:k===g.path,onCopy:()=>c(g.path),onToggleExpand:()=>O(g.path)},g.path))})},m.id)),L.length===0&&e.jsx("p",{className:"text-xs text-gray-600 text-center py-6",children:"No matching variables"})]})]}):null}function on({label:t,count:s,isExpanded:n,onToggle:o,color:w,children:j}){return e.jsxs("div",{className:"border-b border-white/5",children:[e.jsxs("button",{onClick:o,className:"w-full flex items-center gap-2 px-3 py-2 hover:bg-surface-2 transition-colors",children:[n?e.jsx(Ee,{size:14,className:"text-gray-500"}):e.jsx(Ce,{size:14,className:"text-gray-500"}),e.jsx("span",{className:`text-[11px] font-semibold uppercase tracking-wider ${w}`,children:t}),e.jsx("span",{className:"text-[10px] text-gray-600 ml-auto",children:s})]}),n&&j]})}function cn({entry:t,isRecentlyUpdated:s,isValueExpanded:n,isCopied:o,onCopy:w,onToggleExpand:j}){const d=typeof t.value=="object"&&t.value!==null;return e.jsxs("div",{className:`group px-3 py-1.5 hover:bg-surface-2 transition-colors ${s?"bg-cyan-500/5 ring-1 ring-inset ring-cyan-500/20":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[d?e.jsx("button",{onClick:j,className:"flex-shrink-0 p-0.5 -ml-1",children:n?e.jsx(Ee,{size:12,className:"text-gray-500"}):e.jsx(Ce,{size:12,className:"text-gray-500"})}):e.jsx("span",{className:"w-4 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-medium text-cyan-400 truncate flex-shrink-0 max-w-[100px]",title:t.key,children:t.key}),e.jsx("span",{className:"text-gray-600 text-[11px] flex-shrink-0",children:":"}),e.jsx("span",{className:"flex-1 min-w-0",children:e.jsx(dn,{value:t.value,truncate:!n})}),e.jsx("button",{onClick:w,className:"flex-shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-surface-3 transition-opacity",title:`Copy {{${t.path}}}`,children:o?e.jsx(Se,{size:12,className:"text-emerald-400"}):e.jsx(Xe,{size:12,className:"text-gray-500"})})]}),d&&n&&e.jsx("pre",{className:"mt-1 ml-4 text-[10px] text-gray-400 bg-surface-0 rounded p-2 max-h-40 overflow-auto whitespace-pre-wrap break-all",children:JSON.stringify(t.value,null,2)}),e.jsx("div",{className:"hidden group-hover:block ml-4 mt-0.5",children:e.jsx("span",{className:"text-[9px] text-gray-600 font-mono",children:`{{${t.path}}}`})})]})}function dn({value:t,truncate:s}){if(t==null)return e.jsx("span",{className:"text-[11px] text-gray-600 italic",children:"null"});if(typeof t=="boolean")return e.jsx("span",{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded ${t?"bg-emerald-500/10 text-emerald-400":"bg-red-500/10 text-red-400"}`,children:String(t)});if(typeof t=="number")return e.jsx("span",{className:"text-[11px] text-amber-300",children:t});if(typeof t=="string"){const n=s&&t.length>40?t.slice(0,40)+"...":t;return e.jsx("span",{className:"text-[11px] text-gray-300 truncate block",title:t,children:n})}if(Array.isArray(t))return e.jsxs("span",{className:"text-[11px] text-gray-500",children:["Array[",t.length,"]"]});if(typeof t=="object"){const n=Object.keys(t);return e.jsx("span",{className:"text-[11px] text-gray-500",children:`{${n.length} key${n.length!==1?"s":""}}`})}return e.jsx("span",{className:"text-[11px] text-gray-400",children:String(t)})}function xn(t,s){const n=[],o=[];if(t)for(const[$,I]of Object.entries(t))o.push({key:$,value:I,path:`variables.${$}`,scope:"workflow"});n.push({id:"workflow",label:"Workflow Variables",color:"text-purple-400",entries:o});const w=[];if(s)for(const[$,I]of Object.entries(s)){if(I.outputs)for(const[E,k]of Object.entries(I.outputs))w.push({key:`${$}.${E}`,value:k,path:`steps.${$}.outputs.${E}`,scope:"steps"});w.push({key:`${$}.status`,value:I.status,path:`steps.${$}.status`,scope:"steps"})}n.push({id:"steps",label:"Step Outputs",color:"text-cyan-400",entries:w});const j=[];if(s){const $=Object.values(s).filter(k=>k.status==="completed").length,I=Object.values(s).filter(k=>k.status==="failed").length,E=Object.keys(s).length;j.push({key:"completedSteps",value:$,path:"runtime.completedSteps",scope:"runtime"},{key:"failedSteps",value:I,path:"runtime.failedSteps",scope:"runtime"},{key:"totalSteps",value:E,path:"runtime.totalSteps",scope:"runtime"})}n.push({id:"runtime",label:"Runtime Variables",color:"text-amber-400",entries:j});let d=0;try{d=typeof process<"u"&&ta?Object.keys(ta).length:0}catch{d=0}return n.push({id:"env",label:"Environment Variables",color:"text-gray-400",entries:[],envCount:d}),n}const sa=10,un=["All","Completed","Failed","Aborted","Running","Paused"],mn=["All","Manual","Schedule","Webhook","Event","API"],aa={completed:{bg:"bg-emerald-500/10",text:"text-emerald-400",border:"border-emerald-500/20",icon:js},failed:{bg:"bg-red-500/10",text:"text-red-400",border:"border-red-500/20",icon:Ne},aborted:{bg:"bg-gray-500/10",text:"text-gray-400",border:"border-gray-500/20",icon:he},running:{bg:"bg-cyan-500/10",text:"text-cyan-400",border:"border-cyan-500/20",icon:be},paused:{bg:"bg-amber-500/10",text:"text-amber-400",border:"border-amber-500/20",icon:Qt},pending:{bg:"bg-gray-500/10",text:"text-gray-400",border:"border-gray-500/20",icon:ke}};function vs(t){return aa[t]??aa.pending}const pn=new Set(["response","result","output","stdout"]);function hn({workflowId:t,show:s,onClose:n}){const[o,w]=r.useState([]),[j,d]=r.useState(0),[$,I]=r.useState(!1),[E,k]=r.useState(null),[l,M]=r.useState("All"),[h,u]=r.useState("All"),[D,O]=r.useState(null),[c,z]=r.useState({}),[C,L]=r.useState(new Set),[m,g]=r.useState(new Set),[F,V]=r.useState(!1),[N,B]=r.useState(null),[v,A]=r.useState(null),J=r.useCallback(async(y=!1)=>{I(!0),k(null);try{const _=y?o.length:0,{runs:X}=await bs(t,_+sa);w(X),d(X.length)}catch(_){k(_ instanceof Error?_.message:String(_))}finally{I(!1)}},[t,o.length]);r.useEffect(()=>{s&&(J(!1),O(null),L(new Set),g(new Set),V(!1))},[s,t]);const ne=r.useMemo(()=>o.filter(y=>!(l!=="All"&&y.status.toLowerCase()!==l.toLowerCase()||h!=="All"&&y.trigger.toLowerCase()!==h.toLowerCase())),[o,l,h]),ue=r.useCallback(async y=>{if(D===y){O(null);return}if(O(y),!c[y])try{const{run:_}=await Ga(t,y);z(X=>({...X,[y]:_}))}catch{}},[D,c,t]),b=y=>{L(_=>{const X=new Set(_);return X.has(y)?X.delete(y):X.add(y),X})},H=r.useCallback(async y=>{B(y.runId);try{await ys(t,y.variables),await J(!1)}catch(_){k(_ instanceof Error?_.message:String(_))}finally{B(null)}},[t,J]),le=r.useCallback(y=>{const _=c[y.runId]??y,X=new Blob([JSON.stringify(_,null,2)],{type:"application/json"}),U=URL.createObjectURL(X),Z=document.createElement("a");Z.href=U,Z.download=`workflow-run-${y.runId}.json`,Z.click(),URL.revokeObjectURL(U)},[c]),me=y=>{navigator.clipboard.writeText(y).then(()=>{A(y),setTimeout(()=>A(null),1500)}).catch(()=>{})},ye=r.useCallback(y=>{g(_=>{const X=new Set(_);return X.has(y)?X.delete(y):X.size<2&&X.add(y),X})},[]);function we(y){const _=Object.values(y.stepResults);return{total:_.length,completed:_.filter(X=>X.status==="completed").length,failed:_.filter(X=>X.status==="failed").length}}function S(y){try{const _=new Date(y);return _.toLocaleDateString(void 0,{month:"short",day:"numeric"})+" "+_.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return y}}function T(y){const _=Date.now()-new Date(y).getTime(),X=Math.floor(_/6e4);if(X<1)return"just now";if(X<60)return`${X}m ago`;const U=Math.floor(X/60);return U<24?`${U}h ago`:`${Math.floor(U/24)}d ago`}const G=r.useMemo(()=>{const y=Array.from(m);if(y.length!==2)return null;const _=c[y[0]]??o.find(U=>U.runId===y[0]),X=c[y[1]]??o.find(U=>U.runId===y[1]);return!_||!X?null:[_,X]},[m,c,o]),re=r.useMemo(()=>{if(!G)return[];const y=new Set;for(const _ of G)for(const X of Object.keys(_.stepResults))y.add(X);return Array.from(y)},[G]);return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-6",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:n}),e.jsxs("div",{className:"relative w-full max-w-5xl max-h-[90vh] flex flex-col rounded-2xl border border-white/10 bg-surface-1 shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-b border-white/5 bg-surface-2/30 shrink-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-cyan-500/15 flex items-center justify-center",children:e.jsx(ke,{size:18,className:"text-cyan-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-200",children:"Run History"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:[ne.length," run",ne.length!==1?"s":"",l!=="All"&&` (${l.toLowerCase()})`]})]}),e.jsx("button",{onClick:()=>J(!1),disabled:$,className:"p-2 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-gray-300 transition-all disabled:opacity-50",title:"Refresh",children:e.jsx(pr,{size:16,className:$?"animate-spin":""})}),e.jsxs("button",{onClick:()=>{V(y=>!y),F&&g(new Set)},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-xl transition-all border
26
+ ${F?"bg-cyan-500/15 text-cyan-400 border-cyan-500/20":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50 border-transparent"}`,children:[e.jsx(_s,{size:14})," Compare"]}),e.jsx("button",{onClick:n,className:"p-2 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-gray-300 transition-all",children:e.jsx(he,{size:18})})]}),e.jsxs("div",{className:"flex items-center gap-3 px-6 py-3 border-b border-white/5 bg-surface-2/30 shrink-0",children:[e.jsx(hr,{size:14,className:"text-gray-500"}),e.jsx("div",{className:"flex items-center gap-1",children:un.map(y=>e.jsx("button",{onClick:()=>M(y),className:`px-2.5 py-1 text-xs rounded-lg transition-all ${l===y?"bg-cyan-500/15 text-cyan-400 font-medium":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50"}`,children:y==="All"?"All":y},y))}),e.jsx("div",{className:"w-px h-5 bg-white/10"}),e.jsx("div",{className:"flex items-center gap-1",children:mn.map(y=>e.jsx("button",{onClick:()=>u(y),className:`px-2.5 py-1 text-xs rounded-lg transition-all ${h===y?"bg-violet-500/15 text-violet-400 font-medium":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50"}`,children:y==="All"?"All":y},y))}),e.jsx("div",{className:"flex-1"}),F&&m.size<2&&e.jsxs("span",{className:"text-xs text-amber-400/80",children:["Select ",2-m.size," run",m.size===1?"":"s"," to compare"]})]}),E&&e.jsxs("div",{className:"mx-6 mt-4 px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/15 text-sm text-red-400 flex items-start gap-2 shrink-0",children:[e.jsx(Ne,{size:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:E})]}),F&&G&&e.jsxs("div",{className:"mx-6 mt-4 mb-2 rounded-xl border border-white/5 bg-surface-2/30 overflow-hidden shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-white/5 bg-surface-2/40",children:[e.jsx(_s,{size:14,className:"text-cyan-400"}),e.jsx("span",{className:"text-sm font-medium text-gray-200",children:"Run Comparison"}),e.jsx("button",{onClick:()=>{g(new Set),V(!1)},className:"ml-auto p-1.5 rounded-lg hover:bg-surface-3/50 text-gray-500 transition-all",children:e.jsx(he,{size:14})})]}),e.jsxs("div",{className:"grid grid-cols-[200px_1fr_1fr] text-xs font-semibold uppercase tracking-wider text-gray-500 px-4 py-2 border-b border-white/5",children:[e.jsx("span",{children:"Step"}),e.jsx("span",{className:"text-center font-mono",children:G[0].runId.slice(0,8)}),e.jsx("span",{className:"text-center font-mono",children:G[1].runId.slice(0,8)})]}),e.jsx("div",{className:"max-h-60 overflow-y-auto",children:re.map(y=>{const _=G[0].stepResults[y],X=G[1].stepResults[y],U=(_==null?void 0:_.status)!==(X==null?void 0:X.status);return e.jsxs("div",{className:`grid grid-cols-[200px_1fr_1fr] text-sm px-4 py-2 border-b border-white/5 ${U?"bg-amber-500/5":""}`,children:[e.jsx("span",{className:"text-gray-400 truncate",children:y}),e.jsx(ra,{result:_}),e.jsx(ra,{result:X})]},y)})}),e.jsxs("div",{className:"grid grid-cols-[200px_1fr_1fr] text-xs px-4 py-2.5 bg-surface-2/40 border-t border-white/5",children:[e.jsx("span",{className:"text-gray-500 font-semibold",children:"Duration"}),e.jsx("span",{className:"text-center text-gray-400",children:G[0].duration!==void 0?je(G[0].duration):"-"}),e.jsx("span",{className:"text-center text-gray-400",children:G[1].duration!==void 0?je(G[1].duration):"-"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:$&&o.length===0?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(be,{size:24,className:"animate-spin text-cyan-400"})}):ne.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-surface-2/50 flex items-center justify-center",children:e.jsx(ke,{size:24,className:"text-gray-500"})}),e.jsx("p",{className:"text-sm text-gray-500",children:"No runs found"}),e.jsx("p",{className:"text-xs text-gray-500/70",children:"Execute a workflow to see run history here"})]}):e.jsx("div",{className:"divide-y divide-white/5",children:ne.map(y=>{const _=we(y),X=D===y.runId,U=c[y.runId]??y,Z=vs(y.status),f=Z.icon;return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:`flex items-center gap-3 px-6 py-3.5 transition-all cursor-pointer
27
+ ${X?"bg-surface-2/30":"hover:bg-surface-2/20"}`,onClick:()=>ue(y.runId),children:[F&&e.jsx("input",{type:"checkbox",checked:m.has(y.runId),onChange:P=>{P.stopPropagation(),ye(y.runId)},onClick:P=>P.stopPropagation(),disabled:!m.has(y.runId)&&m.size>=2,className:"w-4 h-4 rounded border-white/20 bg-surface-2 text-cyan-500 focus:ring-cyan-500/30 shrink-0"}),e.jsx("div",{className:"shrink-0",children:X?e.jsx(Ee,{size:16,className:"text-gray-400"}):e.jsx(Ce,{size:16,className:"text-gray-500"})}),e.jsxs("div",{className:`flex items-center gap-2 shrink-0 px-2.5 py-1 rounded-lg ${Z.bg} border ${Z.border}`,children:[e.jsx(f,{size:13,className:`${Z.text} ${y.status==="running"?"animate-spin":""}`}),e.jsx("span",{className:`text-xs font-semibold capitalize ${Z.text}`,children:y.status})]}),e.jsx("span",{className:"text-xs text-gray-400 capitalize bg-surface-3/50 px-2 py-0.5 rounded-md shrink-0",children:y.trigger}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0",children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[_.completed>0&&e.jsx("span",{className:"text-xs text-emerald-400 font-medium",children:_.completed}),_.completed>0&&_.failed>0&&e.jsx("span",{className:"text-xs text-gray-500",children:"/"}),_.failed>0&&e.jsx("span",{className:"text-xs text-red-400 font-medium",children:_.failed}),(_.completed>0||_.failed>0)&&e.jsx("span",{className:"text-xs text-gray-500",children:"of"}),e.jsxs("span",{className:"text-xs text-gray-500",children:[_.total," steps"]})]})}),e.jsx("div",{className:"flex-1 min-w-0"}),y.duration!==void 0&&e.jsxs("span",{className:"text-xs text-gray-400 flex items-center gap-1.5 shrink-0 font-mono",children:[e.jsx(ke,{size:12,className:"text-gray-500"})," ",je(y.duration)]}),e.jsx("span",{className:"text-xs text-gray-500 shrink-0 min-w-[60px] text-right",title:S(y.startedAt),children:T(y.startedAt)}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",onClick:P=>P.stopPropagation(),children:[e.jsx("button",{onClick:()=>H(y),disabled:N===y.runId,className:"p-1.5 rounded-lg hover:bg-surface-3/50 text-gray-500 hover:text-cyan-400 transition-all disabled:opacity-50",title:"Re-run",children:e.jsx(kt,{size:13,className:N===y.runId?"animate-pulse":""})}),e.jsx("button",{onClick:()=>me(y.runId),className:"p-1.5 rounded-lg hover:bg-surface-3/50 text-gray-500 hover:text-gray-300 transition-all",title:"Copy Run ID",children:v===y.runId?e.jsx(Se,{size:13,className:"text-emerald-400"}):e.jsx(Xe,{size:13})}),e.jsx("button",{onClick:()=>le(y),className:"p-1.5 rounded-lg hover:bg-surface-3/50 text-gray-500 hover:text-gray-300 transition-all",title:"Download JSON",children:e.jsx(fr,{size:13})})]})]}),X&&e.jsx("div",{className:"px-6 pb-5 pt-3 bg-surface-2/20 border-t border-white/5",children:e.jsxs("div",{className:"ml-7 space-y-4",children:[U.error&&e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/15",children:[e.jsx(Ne,{size:16,className:"text-red-400 mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-red-400 mb-0.5",children:"Workflow Failed"}),e.jsx("p",{className:"text-sm text-red-300/80 break-all",children:U.error})]})]}),Object.keys(U.variables).length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2 flex items-center gap-1.5",children:[e.jsx(Re,{size:12})," Variables"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Object.entries(U.variables).map(([P,K])=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-lg bg-surface-3/50 border border-white/5",children:[e.jsx("span",{className:"text-violet-400 font-mono font-medium",children:P}),e.jsx("span",{className:"text-gray-500",children:"="}),e.jsx("span",{className:"text-gray-300 max-w-[200px] truncate",children:typeof K=="string"?K:JSON.stringify(K)})]},P))})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2 flex items-center gap-1.5",children:[e.jsx(qt,{size:12})," Step Results"]}),e.jsx("div",{className:"rounded-xl border border-white/5 overflow-hidden bg-surface-2/40",children:Object.values(U.stepResults).length===0?e.jsx("p",{className:"text-sm text-gray-500 text-center py-6",children:"No step results recorded"}):e.jsx("div",{className:"divide-y divide-white/5",children:Object.values(U.stepResults).map(P=>e.jsx(fn,{result:P,expanded:C.has(`${y.runId}-${P.stepId}`),onToggle:()=>b(`${y.runId}-${P.stepId}`)},P.stepId))})})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-gray-500 pt-1",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(gr,{size:11})," ",U.runId]}),e.jsxs("span",{children:["Started: ",S(U.startedAt)]}),U.completedAt&&e.jsxs("span",{children:["Completed: ",S(U.completedAt)]})]})]})})]},y.runId)})})}),e.jsxs("div",{className:"flex items-center justify-center gap-4 px-6 py-3 border-t border-white/5 bg-surface-2/30 shrink-0",children:[o.length>0&&o.length>=sa&&e.jsx("button",{onClick:()=>J(!0),disabled:$,className:"text-xs px-5 py-2 rounded-xl bg-surface-3/50 hover:bg-surface-3 text-gray-400 hover:text-gray-200 transition-all disabled:opacity-50 border border-white/5",children:$?"Loading...":"Load More"}),e.jsxs("span",{className:"text-xs text-gray-500",children:["Showing ",ne.length," of ",j," runs"]})]})]})]}):null}function fn({result:t,expanded:s,onToggle:n}){const o=Object.keys(t.outputs).length>0,w=!!t.error,j=o||w,d=vs(t.status),$=d.icon;return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 text-sm transition-all ${j?"cursor-pointer hover:bg-surface-3/30":""}`,onClick:()=>j&&n(),children:[j?s?e.jsx(Ee,{size:14,className:"text-gray-400 shrink-0"}):e.jsx(Ce,{size:14,className:"text-gray-500 shrink-0"}):e.jsx("span",{className:"w-[14px] shrink-0"}),e.jsx($,{size:14,className:`${d.text} shrink-0 ${t.status==="running"?"animate-spin":""}`}),e.jsx("span",{className:"text-gray-200 font-medium flex-1 truncate",children:t.stepId}),e.jsx("span",{className:`text-xs capitalize px-2 py-0.5 rounded-md ${d.bg} ${d.text} border ${d.border} font-medium`,children:t.status}),t.retryCount!==void 0&&t.retryCount>0&&e.jsxs("span",{className:"text-xs text-amber-400 bg-amber-500/10 px-1.5 py-0.5 rounded",children:[t.retryCount," retr",t.retryCount===1?"y":"ies"]}),t.duration!==void 0&&e.jsxs("span",{className:"text-xs text-gray-500 flex items-center gap-1 font-mono",children:[e.jsx(ke,{size:11})," ",je(t.duration)]})]}),s&&e.jsxs("div",{className:"px-5 pb-4 ml-8 space-y-3 bg-surface-2/20",children:[w&&e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-3 rounded-xl bg-red-500/10 border border-red-500/15 mt-2",children:[e.jsx(Ne,{size:14,className:"text-red-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-red-300/90 break-all",children:t.error})]}),o&&e.jsx(gn,{outputs:t.outputs}),t.startedAt&&e.jsxs("div",{className:"text-xs text-gray-500 flex items-center gap-3",children:[e.jsxs("span",{children:["Started: ",wt(t.startedAt)]}),t.completedAt&&e.jsxs("span",{children:["Completed: ",wt(t.completedAt)]})]})]})]})}function gn({outputs:t}){const s=Object.entries(t);if(s.length===0)return null;const n=s.find(([j,d])=>pn.has(j)&&typeof d=="string"&&d.length>40),w=s.filter(([j])=>!(n&&j===n[0])).filter(([,j])=>!(j==null||j===""||Array.isArray(j)&&j.length===0));return e.jsxs("div",{className:"space-y-2",children:[w.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:w.map(([j,d])=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-lg bg-surface-3/50 border border-white/5",children:[e.jsx("span",{className:"text-cyan-400 font-mono font-medium",children:j}),e.jsx("span",{className:"text-gray-400 max-w-[250px] truncate",children:typeof d=="string"?d:typeof d=="number"?String(d):JSON.stringify(d).slice(0,100)})]},j))}),n&&e.jsx("div",{className:"bg-surface-2/60 rounded-xl p-4 border border-white/5 max-h-[500px] overflow-y-auto text-sm text-gray-200 leading-relaxed",children:e.jsx(Ns,{text:n[1]})}),!n&&w.length===0&&s.length>0&&e.jsx("div",{className:"bg-surface-2/60 rounded-xl p-3 border border-white/5 max-h-[200px] overflow-y-auto",children:s.map(([j,d])=>e.jsxs("div",{className:"text-sm flex gap-2 mb-1",children:[e.jsxs("span",{className:"text-cyan-400 font-mono font-medium shrink-0",children:[j,":"]}),e.jsx("span",{className:"text-gray-300 break-all",children:typeof d=="string"?d:JSON.stringify(d,null,2)})]},j))})]})}function ra({result:t}){if(!t)return e.jsx("span",{className:"text-center text-xs text-gray-500",children:"-"});const s=vs(t.status);return e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:`text-xs capitalize px-2 py-0.5 rounded-md ${s.bg} ${s.text} border ${s.border} font-medium`,children:t.status}),t.duration!==void 0&&e.jsx("span",{className:"text-xs text-gray-500 font-mono",children:je(t.duration)}),t.error&&e.jsx("span",{title:t.error,children:e.jsx(Ne,{size:12,className:"text-red-400"})})]})}function bn({value:t,onChange:s,onValidate:n,readOnly:o,validationResult:w}){var h,u,D;const j=r.useRef(null),d=r.useRef(null),[$,I]=r.useState(!1),E=r.useMemo(()=>t.split(`
28
+ `).length,[t]),k=r.useCallback(()=>{j.current&&d.current&&(d.current.scrollTop=j.current.scrollTop)},[]),l=r.useCallback(()=>{navigator.clipboard.writeText(t),I(!0),setTimeout(()=>I(!1),2e3)},[t]),M=r.useCallback(O=>{if(O.key==="Tab"){O.preventDefault();const c=O.currentTarget,z=c.selectionStart,C=c.selectionEnd,L=t.substring(0,z)+" "+t.substring(C);s(L),requestAnimationFrame(()=>{c.selectionStart=c.selectionEnd=z+2})}},[t,s]);return e.jsxs("div",{className:"flex-1 flex flex-col bg-surface-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-surface-1 border-b border-white/5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[10px] font-medium text-gray-400 uppercase tracking-wider",children:"YAML Editor"}),e.jsxs("span",{className:"text-[10px] text-gray-600",children:[E," lines"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[n&&e.jsxs("button",{onClick:()=>n(t),className:"px-2 py-1 text-[10px] rounded bg-surface-2 hover:bg-surface-3 text-gray-300 flex items-center gap-1",children:[e.jsx(Se,{size:10})," Validate"]}),e.jsxs("button",{onClick:l,className:"px-2 py-1 text-[10px] rounded bg-surface-2 hover:bg-surface-3 text-gray-300 flex items-center gap-1",children:[$?e.jsx(Se,{size:10,className:"text-emerald-400"}):e.jsx(Xe,{size:10}),$?"Copied":"Copy"]})]})]}),w&&e.jsxs("div",{className:`px-3 py-2 text-xs border-b shrink-0 ${w.valid?"bg-emerald-500/5 border-emerald-500/20":"bg-red-500/5 border-red-500/20"}`,children:[w.valid&&!((h=w.warnings)!=null&&h.length)&&e.jsxs("span",{className:"text-emerald-400 flex items-center gap-1",children:[e.jsx(Se,{size:12})," Valid workflow YAML"]}),(u=w.errors)==null?void 0:u.map((O,c)=>e.jsxs("p",{className:"text-red-400 flex items-center gap-1",children:[e.jsx(Ne,{size:12})," ",O]},c)),(D=w.warnings)==null?void 0:D.map((O,c)=>e.jsxs("p",{className:"text-amber-400 flex items-center gap-1",children:[e.jsx(Ne,{size:12})," ",O]},c))]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden relative",children:[e.jsx("div",{ref:d,className:"w-12 shrink-0 bg-surface-1 text-right pr-2 pt-2 pb-2 overflow-hidden select-none border-r border-white/5",style:{lineHeight:"1.5rem"},children:Array.from({length:E},(O,c)=>e.jsx("div",{className:"text-[11px] text-gray-600 h-6 leading-6",children:c+1},c))}),e.jsx("textarea",{ref:j,value:t,onChange:O=>s(O.target.value),onScroll:k,onKeyDown:M,readOnly:o,className:"flex-1 w-full p-2 bg-surface-0 text-gray-200 text-[13px] font-mono resize-none focus:outline-none border-none",style:{lineHeight:"1.5rem",tabSize:2},spellCheck:!1,placeholder:`name: My Workflow
29
+ description: Describe your workflow
30
+ steps:
31
+ - id: step-1
32
+ skill: playwright
33
+ action: Run tests`})]})]})}const Pe={success:"#10b981",failure:"#ef4444",aborted:"#6b7280",manual:"#06b6d4",schedule:"#8b5cf6",webhook:"#f59e0b",event:"#ec4899"},yn={manual:Pe.manual,schedule:Pe.schedule,webhook:Pe.webhook,event:Pe.event,api:"#6b7280"},jt={background:"#1e1e2e",border:"1px solid rgba(255,255,255,0.08)",borderRadius:8,fontSize:13};function jn(t){return t.slice(0,10)}function Nn(t){return t.startsWith("webhook:")?"webhook":t.startsWith("event:")?"event":t}function Kt(t){const s=new Date(t+"T00:00:00");return`${s.getMonth()+1}/${s.getDate()}`}function vn({workflowId:t,show:s,onClose:n}){const[o,w]=r.useState([]),[j,d]=r.useState(!0),[$,I]=r.useState(null);r.useEffect(()=>{if(!s)return;let k=!1;return d(!0),I(null),bs(t,50).then(l=>{k||w(l.runs)}).catch(l=>{k||I(l instanceof Error?l.message:"Failed to load runs")}).finally(()=>{k||d(!1)}),()=>{k=!0}},[t,s]);const E=r.useMemo(()=>{if(o.length===0)return null;const k=new Date,l=new Date(k);l.setDate(l.getDate()-30);const M=new Map;for(let v=0;v<30;v++){const A=new Date(l);A.setDate(A.getDate()+v);const J=A.toISOString().slice(0,10);M.set(J,{total:0,passed:0,failed:0,aborted:0,durations:[]})}for(const v of o){const A=jn(v.startedAt);let J=M.get(A);J||(J={total:0,passed:0,failed:0,aborted:0,durations:[]},M.set(A,J)),J.total++,v.status==="completed"?J.passed++:v.status==="failed"?J.failed++:v.status==="aborted"&&J.aborted++,v.duration!=null&&J.durations.push(v.duration)}const h=[],D=[...M.keys()].sort().slice(-30);for(const v of D){const A=M.get(v);h.push({date:v,total:A.total,passed:A.passed,failed:A.failed,aborted:A.aborted,passRate:A.total>0?Math.round(A.passed/A.total*100):0,avgDuration:A.durations.length>0?Math.round(A.durations.reduce((J,ne)=>J+ne,0)/A.durations.length):0})}const O=new Map,c=new Map;for(const v of o)for(const[A,J]of Object.entries(v.stepResults))J.status==="failed"&&O.set(A,(O.get(A)||0)+1),J.duration!=null&&(c.has(A)||c.set(A,[]),c.get(A).push(J.duration));const z=[...O.entries()].sort((v,A)=>A[1]-v[1]).slice(0,5).map(([v,A])=>({stepId:v,failures:A})),C=[...c.entries()].map(([v,A])=>({stepId:v,avgDuration:Math.round(A.reduce((J,ne)=>J+ne,0)/A.length)})).sort((v,A)=>A.avgDuration-v.avgDuration).slice(0,5),L=new Map;for(const v of o){const A=Nn(v.trigger);L.set(A,(L.get(A)||0)+1)}const m=[...L.entries()].map(([v,A])=>({name:v,value:A,color:yn[v]||"#6b7280"})),g=o.length,F=o.filter(v=>v.status==="completed").length,V=g>0?Math.round(F/g*100):0,N=o.filter(v=>v.duration!=null).length>0?Math.round(o.filter(v=>v.duration!=null).reduce((v,A)=>v+A.duration,0)/o.filter(v=>v.duration!=null).length):0,B=o.length>0?o[0].startedAt:null;return{dayBuckets:h,mostFailedSteps:z,slowestSteps:C,triggerSlices:m,summary:{totalRuns:g,successRate:V,avgDuration:N,lastRunAt:B}}},[o]);return s?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-surface-0 border border-white/5 rounded-2xl shadow-2xl w-[90vw] max-w-5xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ma,{className:"w-5 h-5 text-cyan-400"}),e.jsx("h2",{className:"text-lg font-semibold text-gray-100",children:"Workflow Analytics"})]}),e.jsx("button",{onClick:n,className:"p-1.5 rounded-lg hover:bg-white/5 text-gray-400 hover:text-gray-200 transition-colors",children:e.jsx(he,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[j&&e.jsx("div",{className:"flex items-center justify-center h-64 text-gray-500 text-sm",children:"Loading analytics..."}),$&&e.jsx("div",{className:"flex items-center justify-center h-64 text-red-400 text-sm",children:$}),!j&&!$&&!E&&e.jsx("div",{className:"flex items-center justify-center h-64 text-gray-500 text-sm",children:"No run data available. Execute this workflow to see analytics."}),!j&&!$&&E&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(Jt,{icon:e.jsx(xa,{className:"w-4 h-4 text-cyan-400"}),label:"Total Runs",value:String(E.summary.totalRuns)}),e.jsx(Jt,{icon:e.jsx(br,{className:"w-4 h-4 text-emerald-400"}),label:"Success Rate",value:`${E.summary.successRate}%`,valueColor:E.summary.successRate>=80?"text-emerald-400":E.summary.successRate>=50?"text-amber-400":"text-red-400"}),e.jsx(Jt,{icon:e.jsx(ke,{className:"w-4 h-4 text-purple-400"}),label:"Avg Duration",value:E.summary.avgDuration>0?je(E.summary.avgDuration):"--"}),e.jsx(Jt,{icon:e.jsx(Ne,{className:"w-4 h-4 text-amber-400"}),label:"Last Run",value:E.summary.lastRunAt?Oa(E.summary.lastRunAt):"--"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(rt,{title:"Pass Rate Over Time",children:e.jsx(bt,{width:"100%",height:220,children:e.jsxs(kr,{data:E.dayBuckets,children:[e.jsx(_t,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.06)"}),e.jsx(Xt,{dataKey:"date",tickFormatter:Kt,tick:{fontSize:11,fill:"#6b7280"}}),e.jsx(Ht,{domain:[0,100],tick:{fontSize:11,fill:"#6b7280"},tickFormatter:k=>`${k}%`}),e.jsx(yt,{contentStyle:jt,labelStyle:{color:"#9ca3af"},labelFormatter:Kt,formatter:k=>[`${k}%`,"Pass Rate"]}),e.jsx(Cr,{type:"monotone",dataKey:"passRate",stroke:Pe.success,strokeWidth:2,dot:{r:3,fill:Pe.success},activeDot:{r:5}})]})})}),e.jsx(rt,{title:"Average Duration Trend",children:e.jsx(bt,{width:"100%",height:220,children:e.jsxs(Sr,{data:E.dayBuckets,children:[e.jsx(_t,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.06)"}),e.jsx(Xt,{dataKey:"date",tickFormatter:Kt,tick:{fontSize:11,fill:"#6b7280"}}),e.jsx(Ht,{tick:{fontSize:11,fill:"#6b7280"},tickFormatter:k=>je(k)}),e.jsx(yt,{contentStyle:jt,labelStyle:{color:"#9ca3af"},labelFormatter:Kt,formatter:k=>[je(k),"Avg Duration"]}),e.jsx("defs",{children:e.jsxs("linearGradient",{id:"durationGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#8b5cf6",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"#8b5cf6",stopOpacity:0})]})}),e.jsx(zr,{type:"monotone",dataKey:"avgDuration",stroke:"#8b5cf6",strokeWidth:2,fill:"url(#durationGrad)"})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(rt,{title:"Most Failed Steps",children:E.mostFailedSteps.length===0?e.jsx("div",{className:"h-[220px] flex items-center justify-center text-gray-600 text-sm",children:"No step failures recorded."}):e.jsx(bt,{width:"100%",height:220,children:e.jsxs(Hs,{data:E.mostFailedSteps,layout:"vertical",margin:{left:10},children:[e.jsx(_t,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.06)",horizontal:!1}),e.jsx(Xt,{type:"number",tick:{fontSize:11,fill:"#6b7280"},allowDecimals:!1}),e.jsx(Ht,{type:"category",dataKey:"stepId",tick:{fontSize:11,fill:"#9ca3af"},width:100}),e.jsx(yt,{contentStyle:jt,labelStyle:{color:"#9ca3af"},formatter:k=>[k,"Failures"]}),e.jsx(Bs,{dataKey:"failures",fill:Pe.failure,radius:[0,4,4,0],barSize:20})]})})}),e.jsx(rt,{title:"Slowest Steps",children:E.slowestSteps.length===0?e.jsx("div",{className:"h-[220px] flex items-center justify-center text-gray-600 text-sm",children:"No step duration data available."}):e.jsx(bt,{width:"100%",height:220,children:e.jsxs(Hs,{data:E.slowestSteps,layout:"vertical",margin:{left:10},children:[e.jsx(_t,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.06)",horizontal:!1}),e.jsx(Xt,{type:"number",tick:{fontSize:11,fill:"#6b7280"},tickFormatter:k=>je(k)}),e.jsx(Ht,{type:"category",dataKey:"stepId",tick:{fontSize:11,fill:"#9ca3af"},width:100}),e.jsx(yt,{contentStyle:jt,labelStyle:{color:"#9ca3af"},formatter:k=>[je(k),"Avg Duration"]}),e.jsx(Bs,{dataKey:"avgDuration",fill:"#f59e0b",radius:[0,4,4,0],barSize:20})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(rt,{title:"Trigger Distribution",children:E.triggerSlices.length===0?e.jsx("div",{className:"h-[220px] flex items-center justify-center text-gray-600 text-sm",children:"No trigger data."}):e.jsxs("div",{className:"flex items-center",children:[e.jsx(bt,{width:"60%",height:220,children:e.jsxs($r,{children:[e.jsx(Er,{data:E.triggerSlices,cx:"50%",cy:"50%",innerRadius:55,outerRadius:85,paddingAngle:3,dataKey:"value",children:E.triggerSlices.map((k,l)=>e.jsx(Ir,{fill:k.color},l))}),e.jsx(yt,{contentStyle:jt,labelStyle:{color:"#9ca3af"},formatter:(k,l)=>[k,l]})]})}),e.jsx("div",{className:"flex-1 space-y-2 pl-2",children:E.triggerSlices.map(k=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:k.color}}),e.jsx("span",{className:"text-gray-400 capitalize",children:k.name}),e.jsx("span",{className:"text-gray-300 font-medium ml-auto",children:k.value})]},k.name))})]})}),e.jsx(rt,{title:"Run Status Breakdown",children:e.jsxs("div",{className:"h-[220px] flex flex-col justify-center space-y-3 px-4",children:[e.jsx(Zt,{label:"Completed",count:o.filter(k=>k.status==="completed").length,total:o.length,color:Pe.success}),e.jsx(Zt,{label:"Failed",count:o.filter(k=>k.status==="failed").length,total:o.length,color:Pe.failure}),e.jsx(Zt,{label:"Aborted",count:o.filter(k=>k.status==="aborted").length,total:o.length,color:Pe.aborted}),e.jsx(Zt,{label:"Running",count:o.filter(k=>k.status==="running").length,total:o.length,color:"#06b6d4"})]})})]})]})]})]})}):null}function Jt({icon:t,label:s,value:n,valueColor:o}){return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t,e.jsx("span",{className:"text-xs text-gray-500 uppercase tracking-wider",children:s})]}),e.jsx("div",{className:`text-2xl font-bold ${o||"text-gray-100"}`,children:n})]})}function rt({title:t,children:s}){return e.jsxs("div",{className:"bg-surface-1 rounded-xl border border-white/5 p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-300 mb-3",children:t}),s]})}function Zt({label:t,count:s,total:n,color:o}){const w=n>0?s/n*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-gray-400",children:t}),e.jsxs("span",{className:"text-gray-300 font-medium",children:[s," ",e.jsxs("span",{className:"text-gray-600",children:["(",Math.round(w),"%)"]})]})]}),e.jsx("div",{className:"h-2 bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${w}%`,backgroundColor:o}})})]})}function Tn(){var $s,Es,Is,Ms,Os,Ts,As,Ds,Ps,Ls;const t=Ma(),[s,n]=r.useState([]),[o,w]=r.useState(!0),[j,d]=r.useState(!1),[$,I]=r.useState(!1),[E,k]=r.useState(""),[l,M]=r.useState(null),[h,u]=r.useState(null),[D,O]=r.useState(null),[c,z]=la("view",["canvas","yaml"],"canvas"),[C,L]=r.useState(""),[m,g]=r.useState(!1),[F,V]=r.useState(!1),[N,B]=r.useState(null),[v,A]=r.useState(null),[J,ne]=r.useState(!1),[ue,b]=r.useState(!1),[H,le]=r.useState(""),[me,ye]=r.useState(""),[we,S]=r.useState(!1),[T,G]=r.useState(""),[re,y]=r.useState(!1),[_,X]=r.useState(null),[U,Z]=r.useState(!1),[f,P]=r.useState(""),[K,ie]=r.useState(""),[ct,It]=r.useState(""),[Be,Mt]=r.useState("yaml"),[es,Fe]=r.useState(!1),[Ue,Qe]=r.useState(""),[et,Ge]=r.useState(!1),[Ve,dt]=r.useState(!1),[ts,xt]=r.useState(!1),[ss,Ot]=r.useState(!1),[Tt,At]=r.useState(!1),[ze,tt]=r.useState(null),[ut,oe]=r.useState(null),{toast:mt}=Va();r.useEffect(()=>{ut&&(mt("error",ut),oe(null))},[ut,mt]);const[p,q]=r.useState({}),[Q,fe]=r.useState({}),[pe,ce]=r.useState(null);r.useRef(null);const ve=r.useRef(null);r.useEffect(()=>{ve.current=v},[v]);const Oe=r.useRef([]),pt=r.useRef(!1),ht=r.useRef(0),ws=400,Te=r.useCallback(a=>{Oe.current.push(a),pt.current||(pt.current=!0,Dt())},[]);function Dt(){if(Oe.current.length===0){pt.current=!1;return}const i=Date.now()-ht.current,W=Math.max(0,ws-i);setTimeout(()=>{const R=Oe.current.shift();R&&(ht.current=Date.now(),R()),Dt()},W)}const xe=r.useCallback(async()=>{try{const{workflows:a}=await gs();n(a)}catch(a){oe(a instanceof Error?a.message:String(a))}finally{w(!1)}},[]);r.useEffect(()=>{xe()},[xe]),r.useEffect(()=>{if(!l){u(null),L(""),g(!1),B(null),O(null),A(null),Ge(!1);return}Wt(l).then(({workflow:a})=>{u(a),L(a.yaml||""),g(!1),B(null)}).catch(()=>{})},[l]),r.useEffect(()=>{if(!(t!=null&&t.subscribe))return;let a=null;return t.subscribe(i=>{if(!i.type)return;const W=ve.current,R=i.runId&&(W&&i.runId===W.runId||a&&i.runId===a);i.type==="workflow:started"&&i.workflowId===l&&(a=i.runId||null,A(x=>x?{...x,status:"running"}:i.runId?{runId:i.runId,workflowId:i.workflowId,status:"running",trigger:"manual",variables:{},stepResults:{},startedAt:new Date().toISOString()}:x),q({}),fe({})),i.type==="step:output"&&R&&q(x=>({...x,[i.stepId]:(x[i.stepId]||"")+(i.chunk||"")})),i.type==="step:progress"&&R&&fe(x=>({...x,[i.stepId]:{message:i.message,percent:i.percent}})),(i.type==="step:started"||i.type==="step:completed"||i.type==="step:failed"||i.type==="step:skipped"||i.type==="step:waiting")&&R&&Te(()=>{A(Y=>{if(!Y)return null;const ae={...Y,stepResults:{...Y.stepResults}};return i.type==="step:started"?ae.stepResults[i.stepId]={stepId:i.stepId,status:"running",outputs:{},startedAt:new Date().toISOString()}:i.type==="step:completed"?ae.stepResults[i.stepId]={...ae.stepResults[i.stepId]||{stepId:i.stepId,outputs:{}},status:"completed",outputs:i.outputs||{},duration:i.duration,completedAt:new Date().toISOString()}:i.type==="step:failed"?ae.stepResults[i.stepId]={...ae.stepResults[i.stepId]||{stepId:i.stepId,outputs:{}},status:"failed",error:i.error,completedAt:new Date().toISOString()}:i.type==="step:skipped"?ae.stepResults[i.stepId]={stepId:i.stepId,status:"skipped",outputs:{}}:i.type==="step:waiting"&&(ae.stepResults[i.stepId]={stepId:i.stepId,status:"waiting",outputs:{}},ae.status="paused",ae.pausedAtStep=i.stepId),ae})}),i.type==="workflow:completed"&&R&&Te(()=>{A(x=>{var Y;return x?{...x,status:"completed",duration:(Y=i.summary)==null?void 0:Y.duration,completedAt:new Date().toISOString()}:null}),xe()}),i.type==="workflow:failed"&&R&&Te(()=>{A(x=>x?{...x,status:"failed",error:i.error,completedAt:new Date().toISOString()}:null),xe()}),i.type==="workflow:aborted"&&R&&Te(()=>{A(x=>x?{...x,status:"aborted",completedAt:new Date().toISOString()}:null)}),i.type==="workflow:paused"&&R&&Te(()=>{A(x=>x?{...x,status:"paused",pausedAtStep:i.stepId}:null)}),i.type==="workflow:resumed"&&R&&Te(()=>{A(x=>x?{...x,status:"running",pausedAtStep:void 0}:null)}),(i.type==="webhook:triggered"||i.type==="event:triggered")&&(xe(),i.workflowId===l&&Wt(i.workflowId).then(({workflow:x})=>u(x)).catch(()=>{}))})},[t==null?void 0:t.subscribe,l]);async function Pt(){if(!(!l||!m)){V(!0),oe(null);try{const{workflow:a,warnings:i}=await Ae(l,{yaml:C});u(a),g(!1),i!=null&&i.length?B({valid:!0,warnings:i}):B(null),xe()}catch(a){oe(a instanceof Error?a.message:String(a))}finally{V(!1)}}}async function Lt(){try{const a=await Rs(C);B(a)}catch(a){B({valid:!1,errors:[String(a)]})}}async function ft(){V(!0),oe(null);try{const i=`name: "Untitled Workflow ${Math.random().toString(36).slice(2,6)}"
34
+ description: ""
35
+ version: "1.0"
36
+ triggers:
37
+ - manual
38
+ steps:
39
+ - id: step-1
40
+ tool: run_command
41
+ command: "echo Hello"
42
+ description: "First step"`,{workflow:W}=await Za(i);b(!1),await xe(),M(W.id),z("canvas")}catch(a){oe(a instanceof Error?a.message:String(a))}finally{V(!1)}}async function Rt(){if(!h||!l||!E.trim()){I(!1);return}const a=E.trim();if(a===h.definition.name){I(!1);return}const i=C.replace(/^name:\s*["']?.*["']?\s*$/m,`name: "${a}"`);L(i);try{const{workflow:W}=await Ae(l,{yaml:i});u(W),g(!1),xe()}catch(W){oe(W instanceof Error?W.message:String(W))}I(!1)}async function ha(a){try{await sr(a),l===a&&M(null),X(null),xe()}catch(i){oe(i instanceof Error?i.message:String(i))}}async function fa(){if(T.trim()){y(!0),oe(null);try{const{yaml:a,valid:i,errors:W}=await qa(T);i?(le(a),S(!1),b(!0)):(oe(`Generated YAML has errors: ${W==null?void 0:W.join(", ")}`),le(a),S(!1),b(!0))}catch(a){oe(a instanceof Error?a.message:String(a))}finally{y(!1)}}}async function ga(a){try{const{workflow:i}=await Ka(a);await xe(),M(i.id)}catch(i){oe(i instanceof Error?i.message:String(i))}}async function ba(a,i){try{await Ae(a,{enabled:i}),xe(),l===a&&h&&u({...h,enabled:i})}catch(W){oe(W instanceof Error?W.message:String(W))}}async function ya(){V(!0),oe(null);try{const a=Be==="yaml"?{yaml:f,id:ct||void 0}:{url:K,id:ct||void 0},{workflow:i}=await Qa(a);Z(!1),P(""),ie(""),It(""),await xe(),M(i.id)}catch(a){oe(a instanceof Error?a.message:String(a))}finally{V(!1)}}async function ja(){if(!(!l||!Ue.trim()))try{await tr(l,Ue,!0),Fe(!1),Qe("");const{workflow:a}=await Wt(l);u(a),xe()}catch(a){oe(a instanceof Error?a.message:String(a))}}async function Na(){if(l)try{await er(l),Fe(!1);const{workflow:a}=await Wt(l);u(a),xe()}catch(a){oe(a instanceof Error?a.message:String(a))}}async function va(){if(l){At(!0),tt(null);try{const{plan:a}=await Ja(l);tt(a)}catch(a){oe(a instanceof Error?a.message:String(a))}finally{At(!1)}}}function wa(a,i,W){const R=" ",x=[` - id: ${i}`];switch(W&&(x.push(`${R}dependsOn:`),x.push(`${R} - ${W}`)),a){case"skill":x.push(`${R}skill: playwright`),x.push(`${R}action: "Run tests"`);break;case"tool":x.push(`${R}tool: run_command`),x.push(`${R}command: "echo New step"`);break;case"mcp":x.push(`${R}mcp: server_name`);break;case"condition":x.push(`${R}if: "outputs.previous.status === 'passed'"`),x.push(`${R}then: []`),x.push(`${R}else: []`);break;case"loop":x.push(`${R}forEach: "outputs.previous.items"`),x.push(`${R}itemVar: item`),x.push(`${R}loopSteps: []`);break;case"parallel":x.push(`${R}parallelSteps: []`);break;case"checkpoint":x.push(`${R}message: "Checkpoint reached"`);break;case"delay":x.push(`${R}waitSeconds: 5`);break;case"subworkflow":x.push(`${R}workflowId: ""`);break;case"script":x.push(`${R}script: "console.log('hello')"`);break;default:x.push(`${R}tool: run_command`),x.push(`${R}command: "echo TODO"`);break}return x.push(`${R}description: "New ${a} step"`),x.join(`
43
+ `)}async function ks(a,i){if(!h||!l||!C)return;const W=`step-${Date.now().toString(36)}`,R=wa(a,W,i),x=C.trimEnd()+`
44
+ `+R+`
45
+ `;L(x);try{const{workflow:Y}=await Ae(l,{yaml:x});u(Y),g(!1),O(W),xe()}catch(Y){g(!0),oe(Y instanceof Error?Y.message:String(Y))}}function ka(a){var Y;if(!h)return{dependents:[],dependsOn:[]};const i=h.definition.steps,W=i.find(ae=>ae.id===a),R=i.filter(ae=>{var ee;return ae.id!==a&&((ee=ae.dependsOn)==null?void 0:ee.includes(a))}).map(ae=>ae.id),x=((Y=W==null?void 0:W.dependsOn)==null?void 0:Y.filter(ae=>i.some(ee=>ee.id===ae)))||[];return{dependents:R,dependsOn:x}}function Cs(a,i){if(a==="disable"){const x=h==null?void 0:h.definition.steps.find(Y=>Y.id===i);if(x!=null&&x.disabled){as(i);return}}const{dependents:W,dependsOn:R}=ka(i);W.length>0||R.length>0?ce({type:a,stepId:i,dependents:W,dependsOn:R}):a==="delete"?Ss(i):as(i)}async function Ss(a){var ae,ee;if(!h||!l||!C)return;D===a&&O(null);const i=C.split(`
46
+ `),W=[];let R=!1,x=-1;for(let te=0;te<i.length;te++){const se=i[te],ge=se.match(/^(\s*)- id:\s*(\S+)/);if(ge)if(ge[2]===a){R=!0,x=ge[1].length;continue}else R=!1;else if(R){const We=((ee=(ae=se.match(/^(\s*)/))==null?void 0:ae[1])==null?void 0:ee.length)??0;if(se.trim()===""||We>x)continue;R=!1}R||W.push(se)}let Y=W.join(`
47
+ `);Y=Y.replace(new RegExp(`^\\s*- ${a}\\s*$`,"gm"),""),Y=Y.replace(/dependsOn:\s*\n(\s*\n)+/gm,""),L(Y);try{const{workflow:te}=await Ae(l,{yaml:Y});u(te),g(!1),xe()}catch(te){g(!0),oe(te instanceof Error?te.message:String(te))}}async function Ca(a){var ge,We;if(!h||!l||!C)return;D===a&&O(null);const i=h.definition.steps,W=i.find(de=>de.id===a);if(!W)return;const R=W.dependsOn||[],x=i.filter(de=>{var $e;return($e=de.dependsOn)==null?void 0:$e.includes(a)}).map(de=>de.id),Y=C.split(`
48
+ `),ae=[];let ee=!1,te=-1;for(let de=0;de<Y.length;de++){const $e=Y[de],Ye=$e.match(/^(\s*)- id:\s*(\S+)/);if(Ye)if(Ye[2]===a){ee=!0,te=Ye[1].length;continue}else ee=!1;else if(ee){const gt=((We=(ge=$e.match(/^(\s*)/))==null?void 0:ge[1])==null?void 0:We.length)??0;if($e.trim()===""||gt>te)continue;ee=!1}ee||ae.push($e)}let se=ae.join(`
49
+ `);for(const de of x)if(se=se.replace(new RegExp(`^(\\s*)- ${a}(\\s*)$`,"gm"),""),R.length>0){const $e=se.match(new RegExp(`^(\\s*)- id:\\s*${de}`,"m"));if($e){const Ye=$e[1]+" ",gt=i.find(Ke=>Ke.id===de),Ia=(gt==null?void 0:gt.dependsOn)||[],rs=R.filter(Ke=>Ke!==de&&!Ia.includes(Ke));if(rs.length>0){const Ke=new RegExp(`(- id:\\s*${de}[\\s\\S]*?dependsOn:\\s*\\n)(([\\s\\S]*?))(\\n\\s*(?:- id:|$)|$)`,"m");if(se.match(Ke)){const ns=rs.map(ls=>`${Ye} - ${ls}`).join(`
50
+ `);se=se.replace(Ke,`$1$2${ns}
51
+ $4`)}else{const ns=`${Ye}dependsOn:
52
+ `+rs.map(ls=>`${Ye} - ${ls}`).join(`
53
+ `);se=se.replace(new RegExp(`(^\\s*- id:\\s*${de}\\s*$)`,"m"),`$1
54
+ ${ns}`)}}}}se=se.replace(/dependsOn:\s*\n(\s*\n)+/gm,""),se=se.replace(/\n{3,}/g,`
55
+
56
+ `),L(se);try{const{workflow:de}=await Ae(l,{yaml:se});u(de),g(!1),xe()}catch(de){g(!0),oe(de instanceof Error?de.message:String(de))}}async function as(a){if(!h||!l||!C)return;const i=h.definition.steps.find(te=>te.id===a);if(!i)return;const W=!i.disabled,R=C.split(`
57
+ `),x=[];let Y=!1,ae=!1;for(let te=0;te<R.length;te++){const se=R[te],ge=se.match(/^(\s*)- id:\s*(\S+)/);if(ge&&(Y=ge[2]===a,ae=!1),Y){if(/^\s*disabled:\s*(true|false)\s*$/.test(se)){W&&(x.push(se.replace(/disabled:\s*(true|false)/,"disabled: true")),ae=!0);continue}if(x.push(se),W&&!ae&&ge&&ge[2]===a){const We=ge[1]+" ";x.push(`${We}disabled: true`),ae=!0}}else x.push(se)}const ee=x.join(`
58
+ `);L(ee);try{const{workflow:te}=await Ae(l,{yaml:ee});u(te),g(!1),xe()}catch(te){g(!0),oe(te instanceof Error?te.message:String(te))}}async function Sa(a,i){if(!h||!l||!C)return;const W=h.definition.steps.find(ee=>ee.id===i);if(!W||(W.dependsOn||[]).includes(a))return;let x=C;const Y=new RegExp(`(- id: ${i}\\b[^]*?)(?=\\n\\s*- id:|$)`),ae=x.match(Y);ae&&(ae[1].includes("dependsOn:")?x=x.replace(new RegExp(`(- id: ${i}\\b[^]*?dependsOn:\\s*\\n(?:\\s*- [^\\n]+\\n)*)`),`$1 - ${a}
59
+ `):x=x.replace(`- id: ${i}`,`- id: ${i}
60
+ dependsOn:
61
+ - ${a}`)),L(x);try{const{workflow:ee}=await Ae(l,{yaml:x});u(ee),g(!1),xe()}catch(ee){g(!0),oe(ee instanceof Error?ee.message:String(ee))}}async function za(a,i){if(!h||!l||!C)return;const W=C.split(`
62
+ `),R=[];let x=!1,Y=!1,ae=0;const ee=[];for(let se=0;se<W.length;se++){const ge=W[se],We=ge.match(/^(\s*)-\s*id:\s*(\S+)/);if(We){x&&Y&&(ee.length>0&&(R.push(" ".repeat(ae)+"dependsOn:"),ee.forEach(de=>R.push(de))),Y=!1,ee.length=0),x=We[2]===i,Y=!1,R.push(ge);continue}if(x){const de=ge.match(/^(\s*)dependsOn:\s*$/);if(de){Y=!0,ae=de[1].length,ee.length=0;continue}if(Y){const $e=ge.match(/^\s*-\s*(\S+)\s*$/);if($e){$e[1]!==a&&ee.push(ge);continue}ee.length>0&&(R.push(" ".repeat(ae)+"dependsOn:"),ee.forEach(Ye=>R.push(Ye))),Y=!1,ee.length=0,R.push(ge);continue}}R.push(ge)}x&&Y&&ee.length>0&&(R.push(" ".repeat(ae)+"dependsOn:"),ee.forEach(se=>R.push(se)));const te=R.join(`
63
+ `);L(te);try{const{workflow:se}=await Ae(l,{yaml:te});u(se),g(!1),xe()}catch(se){g(!0),oe(se instanceof Error?se.message:String(se))}}async function $a(a,i){if(!h||!l||!C)return;const W=h.definition.steps.find(te=>te.id===a);if(!W)return;const R=i.id||a,x={...W,...i},Y=[` - id: ${R}`];x.description&&Y.push(` description: "${x.description}"`),x.skill&&Y.push(` skill: ${x.skill}`),x.action&&Y.push(` action: "${x.action}"`),x.tool&&Y.push(` tool: ${x.tool}`),x.command&&Y.push(` command: "${x.command}"`),x.mcp&&Y.push(` mcp: ${x.mcp}`),x.if&&Y.push(` if: "${x.if}"`),x.forEach&&Y.push(` forEach: "${x.forEach}"`),x.message&&Y.push(` message: "${x.message}"`),x.waitSeconds!==void 0&&Y.push(` waitSeconds: ${x.waitSeconds}`),x.workflowId&&Y.push(` workflowId: ${x.workflowId}`),x.script&&Y.push(` script: "${x.script}"`),x.disabled&&Y.push(" disabled: true"),x.continueOnError&&Y.push(" continueOnError: true"),x.timeout!==void 0&&Y.push(` timeout: ${x.timeout}`),x.dependsOn&&x.dependsOn.length>0&&(Y.push(" dependsOn:"),x.dependsOn.forEach(te=>Y.push(` - ${te}`))),x.inputs&&Object.keys(x.inputs).length>0&&(Y.push(" inputs:"),Object.entries(x.inputs).forEach(([te,se])=>Y.push(` ${te}: "${se}"`))),x.outputs&&Object.keys(x.outputs).length>0&&(Y.push(" outputs:"),Object.entries(x.outputs).forEach(([te,se])=>Y.push(` ${te}: "${se}"`))),x.onError&&(Y.push(" onError:"),Y.push(` strategy: ${x.onError.strategy||"abort"}`),x.onError.maxRetries!==void 0&&Y.push(` maxRetries: ${x.onError.maxRetries}`),x.onError.retryDelay!==void 0&&Y.push(` retryDelay: ${x.onError.retryDelay}`),x.onError.backoff&&Y.push(` backoff: ${x.onError.backoff}`));const ae=Y.join(`
64
+ `);let ee=C.replace(new RegExp(`\\s*- id: ${a}\\b[\\s\\S]*?(?=\\n\\s*- id:|$)`),`
65
+ `+ae);R!==a&&(ee=ee.replace(new RegExp(`(- )${a}\\b`,"g"),`$1${R}`)),L(ee);try{const{workflow:te}=await Ae(l,{yaml:ee});u(te),g(!1),R!==a&&O(R),xe()}catch(te){g(!0),oe(te instanceof Error?te.message:String(te))}}function Ea(){if(!h)return;const a=new Blob([h.yaml||C],{type:"text/yaml"}),i=URL.createObjectURL(a),W=document.createElement("a");W.href=i,W.download=`${h.id}.workflow.yaml`,W.click(),URL.revokeObjectURL(i)}const zs=(h==null?void 0:h.definition.steps.find(a=>a.id===D))||null;return e.jsxs("div",{className:"flex-1 flex overflow-hidden h-full",children:[e.jsx("div",{className:`flex-shrink-0 border-r border-white/5 bg-surface-1 flex flex-col transition-all duration-200 ${j?"w-10":"w-64"}`,children:j?e.jsxs("div",{className:"flex flex-col items-center py-3 gap-2",children:[e.jsx("button",{onClick:()=>d(!1),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-gray-200 transition-all",title:"Expand sidebar",children:e.jsx(yr,{size:14})}),e.jsx("button",{onClick:()=>Z(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-amber-400 transition-all",title:"Import",children:e.jsx(Ft,{size:14})}),e.jsx("button",{onClick:()=>S(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-purple-400 transition-all",title:"AI Generate",children:e.jsx(_e,{size:14})}),e.jsx("button",{onClick:()=>ne(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-cyan-400 transition-all",title:"From Template",children:e.jsx(nt,{size:14})}),e.jsx("button",{onClick:()=>{b(!0),le(na),ye("")},className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-emerald-400 transition-all",title:"New Workflow",children:e.jsx(Ie,{size:14})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-3 border-b border-white/5",children:e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-200",children:"Workflows"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>Z(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-amber-400 transition-all",title:"Import",children:e.jsx(Ft,{size:14})}),e.jsx("button",{onClick:()=>S(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-purple-400 transition-all",title:"AI Generate",children:e.jsx(_e,{size:14})}),e.jsx("button",{onClick:()=>ne(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-cyan-400 transition-all",title:"From Template",children:e.jsx(nt,{size:14})}),e.jsx("button",{onClick:()=>{b(!0),le(na),ye("")},className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-emerald-400 transition-all",title:"New Workflow",children:e.jsx(Ie,{size:14})}),e.jsx("button",{onClick:()=>d(!0),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-gray-200 transition-all",title:"Collapse sidebar",children:e.jsx(jr,{size:14})})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:o?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(be,{size:20,className:"animate-spin text-cyan-400"})}):s.length===0?e.jsxs("div",{className:"text-center py-8 text-xs text-gray-600",children:[e.jsx("p",{className:"mb-2",children:"No workflows yet"}),e.jsx("p",{children:"Create one from a template or YAML"})]}):s.map(a=>{var i;return e.jsxs("button",{onClick:()=>M(a.id),className:`w-full text-left px-3 py-2.5 rounded-lg transition-all text-xs group relative
66
+ ${l===a.id?"bg-cyan-500/10 border border-cyan-500/20 text-cyan-300":"hover:bg-surface-2 text-gray-300 border border-transparent"}
67
+ ${a.enabled?"":"opacity-50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate flex-1",children:a.definition.name}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[a.webhooks&&a.webhooks.length>0&&e.jsx("span",{title:`${a.webhooks.length} webhook(s)`,children:e.jsx(vt,{size:10,className:"text-cyan-400"})}),a.eventSubscriptions&&a.eventSubscriptions.length>0&&e.jsx("span",{title:`${a.eventSubscriptions.length} event subscription(s)`,children:e.jsx(Re,{size:10,className:"text-purple-400"})}),((i=a.schedule)==null?void 0:i.cron)&&e.jsx("span",{title:`Scheduled: ${a.schedule.cron}`,children:e.jsx(ke,{size:10,className:"text-amber-400"})}),e.jsx(Ce,{size:12,className:`text-gray-600 ${l===a.id?"text-cyan-500":""}`})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:[a.definition.steps.length," step",a.definition.steps.length!==1?"s":""]}),a.runCount>0&&e.jsxs("span",{className:"text-xs text-gray-600",children:[a.runCount," runs"]}),a.stats&&a.stats.totalRuns>0&&e.jsxs("span",{className:`text-xs ${a.stats.successRate>=80?"text-emerald-500":a.stats.successRate>=50?"text-amber-500":"text-red-500"}`,children:[a.stats.successRate,"%"]}),!a.enabled&&e.jsx("span",{className:"text-xs text-gray-600",children:"Disabled"})]}),e.jsxs("div",{className:"absolute right-1 top-1 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all",children:[e.jsx("button",{onClick:W=>{W.stopPropagation(),ba(a.id,!a.enabled)},className:`p-1 rounded ${a.enabled?"hover:bg-amber-500/20 text-gray-600 hover:text-amber-400":"hover:bg-emerald-500/20 text-gray-600 hover:text-emerald-400"}`,title:a.enabled?"Disable":"Enable",children:e.jsx(ia,{size:11})}),e.jsx("button",{onClick:W=>{W.stopPropagation(),ga(a.id)},className:"p-1 rounded hover:bg-cyan-500/20 text-gray-600 hover:text-cyan-400",title:"Duplicate",children:e.jsx(Xe,{size:11})}),e.jsx("button",{onClick:W=>{W.stopPropagation(),X(a.id)},className:"p-1 rounded hover:bg-red-500/20 text-gray-600 hover:text-red-400",title:"Delete",children:e.jsx(lt,{size:11})})]})]},a.id)})})]})}),e.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 py-3 border-b border-white/5 bg-surface-2/30",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 group/name",children:[$?e.jsx("input",{autoFocus:!0,value:E,onChange:a=>k(a.target.value),onBlur:Rt,onKeyDown:a=>{a.key==="Enter"&&Rt(),a.key==="Escape"&&I(!1)},className:"text-sm font-semibold text-gray-200 bg-surface-2/60 border border-cyan-500/30 rounded-lg px-2 py-0.5 focus:outline-none focus:border-cyan-500/50 transition-all"}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-200 truncate",children:h.definition.name}),e.jsx("button",{onClick:()=>{k(h.definition.name),I(!0)},className:"p-1 rounded-lg hover:bg-surface-3/50 text-gray-600 hover:text-gray-300 opacity-0 group-hover/name:opacity-100 transition-all",title:"Edit workflow name",children:e.jsx(da,{size:12})})]}),!h.enabled&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-gray-500/10 text-gray-500 border border-gray-500/20 shrink-0",children:"Disabled"}),(($s=h.schedule)==null?void 0:$s.cron)&&e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-amber-500/10 text-amber-400 border border-amber-500/20 flex items-center gap-1 shrink-0",children:[e.jsx(ke,{size:11})," ",h.schedule.cron]})]}),e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsxs("div",{className:"flex items-center bg-surface-2/40 rounded-xl p-0.5 border border-white/5",children:[e.jsxs("button",{onClick:()=>z("canvas"),className:`px-3.5 py-1.5 text-xs rounded-lg transition-all duration-200 flex items-center gap-1.5 font-medium
68
+ ${c==="canvas"?"bg-cyan-500/15 text-cyan-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:[e.jsx(cs,{size:13})," Canvas"]}),e.jsxs("button",{onClick:()=>z("yaml"),className:`px-3.5 py-1.5 text-xs rounded-lg transition-all duration-200 flex items-center gap-1.5 font-medium
69
+ ${c==="yaml"?"bg-cyan-500/15 text-cyan-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:[e.jsx(Nr,{size:13})," YAML"]})]})}),e.jsxs("div",{className:"flex items-center gap-1",children:[c==="yaml"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:Lt,className:"px-2.5 py-1.5 text-xs rounded-xl bg-surface-3/50 hover:bg-surface-3 text-gray-400 hover:text-gray-300 transition-all border border-white/5",children:[e.jsx(vr,{size:12,className:"inline mr-1"})," Validate"]}),e.jsxs("button",{onClick:Pt,disabled:!m||F,className:"flex items-center gap-1 px-3 py-1.5 text-xs font-medium rounded-xl bg-cyan-600 hover:bg-cyan-500 text-white disabled:opacity-40 transition-all",children:[F?e.jsx(be,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),"Save"]}),e.jsx("div",{className:"w-px h-5 bg-white/10 mx-1"})]}),e.jsxs("button",{onClick:va,disabled:Tt,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-xl border transition-all
70
+ ${Tt?"border-cyan-500/30 text-cyan-400 bg-cyan-500/5":"border-white/5 text-gray-400 hover:text-emerald-400 hover:border-emerald-500/20 hover:bg-emerald-500/5"}`,title:"Dry Run",children:[e.jsx(Xs,{size:13}),e.jsx("span",{className:"hidden lg:inline",children:"Dry Run"})]}),e.jsx("div",{className:"w-px h-5 bg-white/10 mx-1"}),e.jsxs("div",{className:"flex items-center bg-surface-2/40 rounded-xl p-0.5 border border-white/5",children:[e.jsx("button",{onClick:()=>{dt(!Ve),Ge(!1)},className:`p-1.5 rounded-lg transition-all ${Ve?"text-cyan-400 bg-cyan-500/15":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50"}`,title:"Variable Inspector",children:e.jsx(ua,{size:14})}),e.jsx("button",{onClick:()=>xt(!0),className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-surface-3/50 transition-all",title:"Run History",children:e.jsx(fs,{size:14})}),e.jsx("button",{onClick:()=>Ot(!0),className:"p-1.5 rounded-lg text-gray-500 hover:text-purple-400 hover:bg-surface-3/50 transition-all",title:"Analytics",children:e.jsx(ma,{size:14})}),e.jsxs("button",{onClick:()=>Ge(!et),className:`p-1.5 rounded-lg transition-all relative ${et?"text-cyan-400 bg-cyan-500/15":"text-gray-500 hover:text-gray-300 hover:bg-surface-3/50"}`,title:"Webhooks & Events",children:[e.jsx(vt,{size:14}),(((Es=h.webhooks)==null?void 0:Es.length)||0)+(((Is=h.eventSubscriptions)==null?void 0:Is.length)||0)>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-3 h-3 rounded-full bg-cyan-500 text-[8px] text-white flex items-center justify-center",children:(((Ms=h.webhooks)==null?void 0:Ms.length)||0)+(((Os=h.eventSubscriptions)==null?void 0:Os.length)||0)})]})]}),e.jsx("div",{className:"w-px h-5 bg-white/10 mx-1"}),e.jsx("button",{onClick:()=>{var a;Fe(!0),Qe(((a=h.schedule)==null?void 0:a.cron)||"")},className:"p-1.5 rounded-xl text-gray-500 hover:text-amber-400 hover:bg-surface-3/50 transition-all",title:"Schedule",children:e.jsx(ds,{size:14})}),e.jsx("button",{onClick:Ea,className:"p-1.5 rounded-xl text-gray-500 hover:text-gray-300 hover:bg-surface-3/50 transition-all",title:"Export YAML",children:e.jsx(wr,{size:14})})]})]}),N&&e.jsxs("div",{className:`px-4 py-2 text-xs border-b border-white/5 ${N.valid?"bg-emerald-500/5 text-emerald-400":"bg-red-500/5 text-red-400"}`,children:[N.valid?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Se,{size:12})," Valid workflow"]}):e.jsxs("div",{className:"flex items-start gap-1",children:[e.jsx(Ne,{size:12,className:"flex-shrink-0 mt-0.5"}),e.jsx("div",{children:(Ts=N.errors)==null?void 0:Ts.map((a,i)=>e.jsx("p",{children:a},i))})]}),(As=N.warnings)==null?void 0:As.map((a,i)=>e.jsxs("p",{className:"text-amber-400 mt-0.5",children:["Warning: ",a]},i))]}),ze&&e.jsxs("div",{className:"px-5 py-3 border-b border-white/5 bg-surface-2/30",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-emerald-500/15 flex items-center justify-center",children:e.jsx(Xs,{size:14,className:"text-emerald-400"})}),e.jsx("span",{className:"text-sm font-semibold text-emerald-400",children:"Execution Plan"}),e.jsx("span",{className:"text-xs text-gray-500",children:"·"}),e.jsxs("span",{className:"text-sm text-gray-300",children:[ze.runnableSteps,"/",ze.totalSteps," steps will execute"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:async()=>{if(tt(null),!!l)try{const{run:a}=await ys(l);A(a)}catch(a){oe(a instanceof Error?a.message:String(a))}},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-medium transition-all shadow-lg shadow-emerald-600/20",children:[e.jsx(kt,{size:12})," Run Now"]}),e.jsx("button",{onClick:()=>tt(null),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-500 hover:text-gray-300 transition-all",children:e.jsx(he,{size:14})})]})]}),e.jsx("div",{className:"rounded-xl border border-white/5 overflow-hidden bg-surface-2/40",children:e.jsx("div",{className:"divide-y divide-white/5 max-h-[200px] overflow-y-auto",children:(Ds=ze.plan)==null?void 0:Ds.map((a,i)=>{const W=Me[a.type];return e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2 text-sm transition-all ${a.wouldRun?"":"opacity-50"}`,children:[e.jsx("span",{className:"text-xs text-gray-500 w-5 text-right font-mono",children:i+1}),e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${a.wouldRun?"bg-emerald-400":"bg-gray-600"}`}),e.jsx("span",{className:`font-medium flex-1 ${a.wouldRun?"text-gray-200":"text-gray-600 line-through"}`,children:a.stepId}),W&&e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-lg ${W.bgClass} ${W.textClass} border border-white/5`,children:W.label}),a.reason&&e.jsx("span",{className:"text-xs text-amber-400/80 ml-auto",children:a.reason})]},i)})})})]}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[c==="canvas"?e.jsx(Lr,{steps:h.definition.steps,selectedStepId:D,activeRun:v,onSelectStep:O,onAddStep:ks,onDeleteStep:a=>Cs("delete",a),onToggleDisable:a=>Cs("disable",a),onDuplicateStep:a=>{const i=h.definition.steps.find(W=>W.id===a);i&&ks(it(i))},onAddConnection:Sa,onRemoveConnection:za,onRemoveAndReconnect:Ca}):e.jsx(bn,{value:C,onChange:a=>{L(a),g(!0)},onValidate:async a=>{const i=await Rs(a);return B(i),i},validationResult:N}),zs&&c==="canvas"&&!et&&!Ve&&e.jsx(_r,{step:zs,allStepIds:h.definition.steps.map(a=>a.id),activeRun:v,onClose:()=>O(null),onUpdateStep:$a}),et&&l&&e.jsx(nn,{workflowId:l,onClose:()=>Ge(!1)}),e.jsx(ln,{workflowVariables:h.definition.variables,stepResults:v==null?void 0:v.stepResults,show:Ve,onClose:()=>dt(!1)})]}),e.jsx(tn,{workflow:h,activeRun:v,stepOutputs:p,stepProgress:Q,onRunStarted:a=>{A(a),q({}),fe({})},onRefresh:xe})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500",children:e.jsxs("div",{className:"text-center",children:[e.jsx(cs,{size:48,className:"mx-auto mb-3 text-gray-700"}),e.jsx("p",{className:"text-base font-medium text-gray-400 mb-1",children:"Select a workflow"}),e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"or create one from a template"}),e.jsxs("div",{className:"flex items-center gap-2 justify-center",children:[e.jsxs("button",{onClick:()=>ne(!0),className:"flex items-center gap-1.5 px-4 py-2 text-sm rounded-lg bg-cyan-600 hover:bg-cyan-500 text-white transition-colors",children:[e.jsx(nt,{size:14})," From Template"]}),e.jsxs("button",{onClick:()=>S(!0),className:"flex items-center gap-1.5 px-4 py-2 text-sm rounded-lg bg-purple-600 hover:bg-purple-500 text-white transition-colors",children:[e.jsx(_e,{size:14})," AI Generate"]})]})]})})}),e.jsx(rn,{open:J,onClose:()=>ne(!1),onCreated:async a=>{await xe(),M(a)}}),ue&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>b(!1)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[480px] flex flex-col animate-fade-in shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/5 bg-surface-2/30 rounded-t-2xl",children:[e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"New Workflow"}),e.jsx("button",{onClick:()=>b(!1),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-400 hover:text-gray-200 transition-all",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-xs text-gray-500 mb-1",children:"Choose how to create your workflow"}),e.jsxs("button",{onClick:()=>{b(!1),ne(!0)},className:"w-full flex items-center gap-4 px-4 py-3.5 rounded-xl bg-surface-2/40 border border-white/5 hover:bg-surface-2/60 hover:border-cyan-500/20 transition-all group",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-cyan-500/10 flex items-center justify-center shrink-0",children:e.jsx(nt,{size:20,className:"text-cyan-400"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200 block",children:"From Template"}),e.jsx("span",{className:"text-xs text-gray-500",children:"Start with a pre-built workflow template"})]}),e.jsx(Ce,{size:16,className:"ml-auto text-gray-600 group-hover:text-gray-400 transition-all"})]}),e.jsxs("button",{onClick:()=>{b(!1),S(!0)},className:"w-full flex items-center gap-4 px-4 py-3.5 rounded-xl bg-surface-2/40 border border-white/5 hover:bg-surface-2/60 hover:border-purple-500/20 transition-all group",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-purple-500/10 flex items-center justify-center shrink-0",children:e.jsx(_e,{size:20,className:"text-purple-400"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200 block",children:"AI Generate"}),e.jsx("span",{className:"text-xs text-gray-500",children:"Describe what you need and let AI build it"})]}),e.jsx(Ce,{size:16,className:"ml-auto text-gray-600 group-hover:text-gray-400 transition-all"})]}),e.jsxs("button",{onClick:ft,disabled:F,className:"w-full flex items-center gap-4 px-4 py-3.5 rounded-xl bg-surface-2/40 border border-white/5 hover:bg-surface-2/60 hover:border-emerald-500/20 transition-all group",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-emerald-500/10 flex items-center justify-center shrink-0",children:e.jsx(cs,{size:20,className:"text-emerald-400"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200 block",children:"Using Canvas"}),e.jsx("span",{className:"text-xs text-gray-500",children:"Design your workflow visually from scratch"})]}),F?e.jsx(be,{size:16,className:"ml-auto animate-spin text-gray-400"}):e.jsx(Ce,{size:16,className:"ml-auto text-gray-600 group-hover:text-gray-400 transition-all"})]})]})]})]}),we&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>S(!1)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[560px] flex flex-col animate-fade-in shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/5 bg-surface-2/30 rounded-t-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{size:18,className:"text-purple-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"AI Generate Workflow"})]}),e.jsx("button",{onClick:()=>S(!1),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-400 hover:text-gray-200 transition-all",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Describe what you want the workflow to do in plain English. The AI will generate the YAML workflow for you."}),e.jsx("textarea",{value:T,onChange:a=>G(a.target.value),className:"w-full h-32 px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-200 resize-none focus:outline-none focus:border-purple-500/30 transition-all",placeholder:"e.g., Run Playwright tests on staging every morning, heal broken selectors, retry failures, and post results to Slack"})]}),e.jsxs("div",{className:"flex justify-end gap-2 px-5 py-4 border-t border-white/5 bg-surface-2/30 rounded-b-2xl",children:[e.jsx("button",{onClick:()=>S(!1),className:"px-4 py-2 text-sm rounded-xl bg-surface-2/40 hover:bg-surface-3/50 text-gray-300 transition-all",children:"Cancel"}),e.jsxs("button",{onClick:fa,disabled:!T.trim()||re,className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-xl bg-purple-600 hover:bg-purple-500 text-white disabled:opacity-40 transition-all",children:[re?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(_e,{size:14}),re?"Generating...":"Generate"]})]})]})]}),U&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>Z(!1)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[600px] flex flex-col animate-fade-in shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/5 bg-surface-2/30 rounded-t-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ft,{size:18,className:"text-amber-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"Import Workflow"})]}),e.jsx("button",{onClick:()=>Z(!1),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-400 hover:text-gray-200 transition-all",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-surface-2/40 rounded-xl p-0.5 border border-white/5",children:[e.jsx("button",{onClick:()=>Mt("yaml"),className:`flex-1 px-3 py-1.5 text-xs rounded-lg transition-all ${Be==="yaml"?"bg-surface-3/50 text-amber-300 border border-amber-500/30":"text-gray-500 hover:text-gray-300 border border-transparent"}`,children:"Paste YAML"}),e.jsx("button",{onClick:()=>Mt("url"),className:`flex-1 px-3 py-1.5 text-xs rounded-lg transition-all ${Be==="url"?"bg-surface-3/50 text-amber-300 border border-amber-500/30":"text-gray-500 hover:text-gray-300 border border-transparent"}`,children:"From URL"})]}),Be==="yaml"?e.jsx("textarea",{value:f,onChange:a=>P(a.target.value),className:"w-full h-48 px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm font-mono text-gray-200 resize-none focus:outline-none focus:border-amber-500/30 transition-all",spellCheck:!1,placeholder:"Paste workflow YAML content..."}):e.jsx("input",{type:"text",value:K,onChange:a=>ie(a.target.value),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-amber-500/30 transition-all",placeholder:"https://github.com/.../workflow.yaml or raw URL"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-300 block mb-1",children:"Workflow ID (optional)"}),e.jsx("input",{type:"text",value:ct,onChange:a=>It(a.target.value),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 placeholder-gray-500 focus:outline-none focus:border-amber-500/30 transition-all",placeholder:"Auto-generated from workflow name if empty"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 px-5 py-4 border-t border-white/5 bg-surface-2/30 rounded-b-2xl",children:[e.jsx("button",{onClick:()=>Z(!1),className:"px-4 py-2 text-sm rounded-xl bg-surface-2/40 hover:bg-surface-3/50 text-gray-300 transition-all",children:"Cancel"}),e.jsxs("button",{onClick:ya,disabled:F||(Be==="yaml"?!f.trim():!K.trim()),className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-xl bg-amber-600 hover:bg-amber-500 text-white disabled:opacity-40 transition-all",children:[F?e.jsx(be,{size:14,className:"animate-spin"}):e.jsx(Ft,{size:14}),"Import"]})]})]})]}),es&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>Fe(!1)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[480px] flex flex-col animate-fade-in shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/5 bg-surface-2/30 rounded-t-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ds,{size:18,className:"text-amber-400"}),e.jsx("h2",{className:"text-base font-semibold text-gray-100",children:"Schedule Workflow"})]}),e.jsx("button",{onClick:()=>Fe(!1),className:"p-1.5 rounded-xl hover:bg-surface-3/50 text-gray-400 hover:text-gray-200 transition-all",children:e.jsx(he,{size:16})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-300 block mb-1",children:"Cron Expression"}),e.jsx("input",{type:"text",value:Ue,onChange:a=>Qe(a.target.value),className:"w-full px-3 py-2 bg-surface-2/60 border border-white/5 rounded-xl text-sm text-gray-100 font-mono placeholder-gray-500 focus:outline-none focus:border-amber-500/30 transition-all",placeholder:"0 8 * * 1-5"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Format: minute hour dayOfMonth month dayOfWeek"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-gray-500 block mb-1.5",children:"Quick Presets"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:wn.map(a=>e.jsx("button",{onClick:()=>Qe(a.cron),className:`text-xs px-2.5 py-1 rounded-xl transition-all ${Ue===a.cron?"bg-amber-500/15 text-amber-300 border border-amber-500/30":"bg-surface-2/40 text-gray-400 hover:text-gray-200 border border-white/10"}`,children:a.label},a.cron))})]}),((Ps=h==null?void 0:h.schedule)==null?void 0:Ps.cron)&&e.jsxs("div",{className:"px-3 py-2 rounded-xl bg-amber-500/5 border border-amber-500/10 text-xs text-amber-300",children:["Current schedule: ",e.jsx("code",{className:"font-mono",children:h.schedule.cron}),h.schedule.lastRunTime&&e.jsxs("span",{className:"text-gray-500 ml-2",children:["Last run: ",wt(h.schedule.lastRunTime)]})]})]}),e.jsxs("div",{className:"flex justify-between px-5 py-4 border-t border-white/5 bg-surface-2/30 rounded-b-2xl",children:[e.jsx("div",{children:((Ls=h==null?void 0:h.schedule)==null?void 0:Ls.cron)&&e.jsx("button",{onClick:Na,className:"px-3 py-2 text-sm rounded-xl text-red-400 hover:bg-red-500/10 transition-all",children:"Remove Schedule"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>Fe(!1),className:"px-4 py-2 text-sm rounded-xl bg-surface-2/40 hover:bg-surface-3/50 text-gray-300 transition-all",children:"Cancel"}),e.jsxs("button",{onClick:ja,disabled:!Ue.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-xl bg-amber-600 hover:bg-amber-500 text-white disabled:opacity-40 transition-all",children:[e.jsx(ds,{size:14}),"Set Schedule"]})]})]})]})]}),_&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>X(null)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-96 animate-fade-in shadow-2xl overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 bg-surface-2/30",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-red-500/15 flex items-center justify-center shrink-0",children:e.jsx(Ne,{size:20,className:"text-red-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-100",children:"Delete Workflow"}),e.jsxs("p",{className:"text-sm text-gray-400 mt-1",children:["Delete ",e.jsx("span",{className:"text-gray-200 font-medium",children:_})," and all its run history?"]})]})]})}),e.jsxs("div",{className:"flex gap-2 justify-end px-5 py-4 border-t border-white/5 bg-surface-2/30",children:[e.jsx("button",{onClick:()=>X(null),className:"px-4 py-2 text-sm rounded-xl bg-surface-2/40 hover:bg-surface-3/50 text-gray-300 transition-all",children:"Cancel"}),e.jsx("button",{onClick:()=>ha(_),className:"px-4 py-2 text-sm rounded-xl bg-red-600 hover:bg-red-500 text-white font-medium transition-all",children:"Delete"})]})]})]}),pe&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>ce(null)}),e.jsxs("div",{className:"relative bg-surface-1 rounded-2xl border border-white/10 w-[420px] animate-fade-in shadow-2xl overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 bg-surface-2/30 rounded-t-2xl",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center shrink-0 ${pe.type==="delete"?"bg-red-500/15":"bg-amber-500/15"}`,children:e.jsx(Ne,{size:20,className:pe.type==="delete"?"text-red-400":"text-amber-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-100",children:pe.type==="delete"?"Delete Step":"Disable Step"}),e.jsxs("p",{className:"text-sm text-gray-400 mt-1",children:[pe.type==="delete"?"Delete":"Disable"," step ",e.jsx("span",{className:"text-gray-200 font-mono font-medium",children:pe.stepId}),"?"]})]})]})}),e.jsxs("div",{className:"space-y-2 p-5",children:[pe.dependents.length>0&&e.jsxs("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-xl p-3",children:[e.jsxs("p",{className:"text-xs font-semibold text-amber-400 mb-1",children:['⚠ These steps depend on "',pe.stepId,'":']}),e.jsx("div",{className:"flex flex-wrap gap-1",children:pe.dependents.map(a=>e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-amber-500/15 text-amber-300 font-mono",children:a},a))}),pe.type==="delete"&&e.jsx("p",{className:"text-xs text-amber-400/70 mt-1.5",children:"Their dependency on this step will be automatically removed."})]}),pe.dependsOn.length>0&&e.jsxs("div",{className:"bg-blue-500/10 border border-blue-500/20 rounded-xl p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-blue-400 mb-1",children:"ℹ This step depends on:"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:pe.dependsOn.map(a=>e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-lg bg-blue-500/15 text-blue-300 font-mono",children:a},a))})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end px-5 py-4 border-t border-white/5 bg-surface-2/30 rounded-b-2xl",children:[e.jsx("button",{onClick:()=>ce(null),className:"px-4 py-2 text-sm rounded-xl bg-surface-2/40 hover:bg-surface-3/50 text-gray-300 transition-all",children:"Cancel"}),e.jsx("button",{onClick:()=>{const{type:a,stepId:i}=pe;ce(null),a==="delete"?Ss(i):as(i)},className:`px-4 py-2 text-sm rounded-xl font-medium transition-all ${pe.type==="delete"?"bg-red-600 hover:bg-red-500 text-white":"bg-amber-600 hover:bg-amber-500 text-white"}`,children:pe.type==="delete"?"Delete Step":"Disable Step"})]})]})]}),l&&e.jsx(hn,{workflowId:l,show:ts,onClose:()=>xt(!1)}),l&&e.jsx(vn,{workflowId:l,show:ss,onClose:()=>Ot(!1)})]})}const wn=[{label:"Every 15 min",cron:"*/15 * * * *"},{label:"Hourly",cron:"0 * * * *"},{label:"Daily 8 AM",cron:"0 8 * * *"},{label:"Daily 9 AM",cron:"0 9 * * *"},{label:"Weekdays 8 AM",cron:"0 8 * * 1-5"},{label:"Monday 9 AM",cron:"0 9 * * 1"},{label:"Nightly 2 AM",cron:"0 2 * * *"},{label:"Weekly Sunday",cron:"0 0 * * 0"}],na=`name: "My Workflow"
71
+ description: "Describe what this workflow does"
72
+ version: "1.0"
73
+ triggers:
74
+ - manual
75
+ variables:
76
+ baseUrl: "https://example.com"
77
+
78
+ steps:
79
+ - id: step-1
80
+ tool: run_command
81
+ command: "echo Hello from workflow"
82
+ description: "First step"
83
+ `;export{Tn as WorkflowsPage};