tide-commander 1.84.2 → 1.84.4

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 (39) hide show
  1. package/dist/assets/{BossLogsModal-CbPseg-c.js → BossLogsModal-RKUS5he3.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-CXcaXAij.js → BossSpawnModal-Z-KIzG1l.js} +1 -1
  3. package/dist/assets/{ControlsModal-BYUbRQcz.js → ControlsModal-sWKF7juv.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BxlBxk13.js → DockerLogsModal-Chv6wO7i.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor--JOJfC7s.js → EmbeddedEditor-BnJunhJ5.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-DF8Frc6X.js → GmailOAuthSetup-CD24tWFR.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-DxZLW8IT.js → GoogleOAuthSetup-D7lmU7_z.js} +1 -1
  8. package/dist/assets/{IframeModal-DmnSRljV.js → IframeModal-B7M2Iclq.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-iiKDU2g_.js → IntegrationsPanel-BXniP3m6.js} +2 -2
  10. package/dist/assets/{LogViewerModal-DoxVD2wb.js → LogViewerModal-BkbO5Lcx.js} +1 -1
  11. package/dist/assets/{MonitoringModal-HwuPAK8z.js → MonitoringModal-BLwOrxXn.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-Chx1wmpC.js → PM2LogsModal-Cc5muLh8.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-DGTRZ7H7.js → RestoreArchivedAreaModal-C2kLOEom.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-NCptTu5l.js → Scene2DCanvas-B_ILFcMh.js} +1 -1
  15. package/dist/assets/{SceneManager-CwvQOFBU.js → SceneManager-C24V9ffc.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CNbLb0Fu.js → SkillsPanel-B7M9i9GP.js} +2 -2
  17. package/dist/assets/{SpawnModal-DAjrIVss.js → SpawnModal-C47v5dNY.js} +1 -1
  18. package/dist/assets/{SubordinateAssignmentModal-5HP1CzQT.js → SubordinateAssignmentModal-KRP5mXby.js} +1 -1
  19. package/dist/assets/{TriggerManagerPanel-VSxCT-cD.js → TriggerManagerPanel-CLmwH7fs.js} +2 -2
  20. package/dist/assets/{WorkflowEditorPanel-DfXfdv46.js → WorkflowEditorPanel-CFubZORK.js} +2 -2
  21. package/dist/assets/{index-CdSYWPJD.js → index-5oP0HT38.js} +3 -3
  22. package/dist/assets/index-7TgA90RK.js +1 -0
  23. package/dist/assets/index-BEc3pZNf.js +1 -0
  24. package/dist/assets/{index-BEmul9y0.js → index-C0L5LEWi.js} +4 -4
  25. package/dist/assets/{index-DYml8LTk.js → index-CO5NGvTa.js} +1 -1
  26. package/dist/assets/index-CmE9RJAK.css +1 -0
  27. package/dist/assets/index-CztWNLcY.js +2 -0
  28. package/dist/assets/{index-0eWL2WB3.js → index-D3lbWfGO.js} +2 -2
  29. package/dist/assets/{index-BiAN1sxE.js → index-D94lnP2P.js} +5 -5
  30. package/dist/assets/{index-BfWMRkdP.js → index-DQVaH0CS.js} +1 -1
  31. package/dist/assets/{main-BlnQCHb9.js → main-DFVcOIIz.js} +4 -4
  32. package/dist/assets/{web-W5mpcw2a.js → web-BRpVSwLu.js} +1 -1
  33. package/dist/assets/{web-C-VeqfnM.js → web-DskROW-O.js} +1 -1
  34. package/dist/index.html +1 -1
  35. package/package.json +1 -1
  36. package/dist/assets/index-BR9_mEVJ.css +0 -1
  37. package/dist/assets/index-Bwtfr8vQ.js +0 -1
  38. package/dist/assets/index-DRsHxeh_.js +0 -1
  39. package/dist/assets/index-PmiCO3k8.js +0 -2
@@ -1 +1 @@
1
- import{u as Ze,aA as es,aB as ss,aC as as,aD as ns,r as t,E as Ee,S as ne,aE as te,A as Ae,l as le,aF as ts,s as S,h as ls,j as s,aG as os,W as De,aH as x,aI as is,aJ as oe,I as ie,am as T,ak as K,aK as cs,al as ce,aL as re,aM as rs,G as ds}from"./main-BlnQCHb9.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Ie(r,j){const b=j.filter(C=>!r.has(C));return b.length===0?`${j[Math.floor(Math.random()*j.length)]}-${Date.now()%1e3}`:b[Math.floor(Math.random()*b.length)]}function hs({isOpen:r,onClose:j,onSpawnStart:b,onSpawnEnd:C,spawnPosition:_e,spawnAreaId:N}){const{t:a}=Ze(["terminal","common"]),P=es(),p=ss(),de=as(),H=de.length>0?de:ns,[m,v]=t.useState(""),[M,F]=t.useState(()=>Ee(ne.LAST_CWD)),[i,k]=t.useState("scout"),[pe,I]=t.useState(!1),[Le,R]=t.useState(!1),[me,J]=t.useState(!1),[ue,he]=t.useState(""),[y,X]=t.useState([]),[E,U]=t.useState(null),[$e,we]=t.useState(!1),[_,xe]=t.useState(""),[h,Te]=t.useState(""),[z,Pe]=t.useState(!1),[O,Fe]=t.useState("bypass"),[o,Y]=t.useState("claude"),[f,A]=t.useState({fullAuto:!0,sandbox:"workspace-write",approvalMode:"on-request",search:!1}),[fe,Q]=t.useState(new Set),[V,ge]=t.useState("opus[1m]"),[Z,je]=t.useState("xHigh"),[ee,Re]=t.useState("gpt-5.3-codex"),[se,Ue]=t.useState("minimax/MiniMax-M1-80k"),[Ne,ze]=t.useState(""),[D,Oe]=t.useState(""),q=t.useRef(null),ve=t.useRef(!1),L=t.useCallback(()=>{window.__spawnModalAreaContext=null},[]),w=t.useMemo(()=>P.filter(e=>e.enabled),[P]),qe=["full-notifications","streaming-exec","task-label","report-task-to-boss","agent-tracking","send-message-to-agent"];t.useEffect(()=>{if(r&&!ve.current){if(w.length>0){const l=w.filter(c=>qe.includes(c.slug)).map(c=>c.id);l.length>0&&Q(new Set(l))}const n=Ee(ne.DEFAULT_AGENT_CLASS);if(n==="random"){const c=[...Object.keys(rs),...p.map(u=>u.id)];k(c[Math.floor(Math.random()*c.length)])}else k(n||"scout")}ve.current=r},[r,w,p]);const Se=t.useMemo(()=>{if(!D.trim())return w;const e=D.toLowerCase();return w.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.slug.toLowerCase().includes(e))},[w,D]),Ge=t.useCallback(e=>{Q(n=>{const l=new Set(n);return l.has(e)?l.delete(e):l.add(e),l})},[]);t.useMemo(()=>w.filter(e=>e.assignedAgentClasses.includes(i)),[w,i]);const We=t.useMemo(()=>{var n;const e=p.find(l=>l.id===i);return(n=e==null?void 0:e.defaultSkillIds)!=null&&n.length?P.filter(l=>e.defaultSkillIds.includes(l.id)):[]},[p,i,P]),be=t.useMemo(()=>{if(!_.trim())return y;const e=_.toLowerCase();return y.filter(n=>n.sessionId.toLowerCase().includes(e)||n.projectPath.toLowerCase().includes(e)||n.firstMessage&&n.firstMessage.toLowerCase().includes(e))},[y,_]),G=t.useMemo(()=>{if(!h.trim())return p;const e=h.toLowerCase();return p.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.id.toLowerCase().includes(e))},[p,h]),W=t.useMemo(()=>{if(!h.trim())return te;const e=h.toLowerCase();return te.filter(n=>{const l=Ae[n.id];return n.name.toLowerCase().includes(e)||n.id.toLowerCase().includes(e)||l.description.toLowerCase().includes(e)})},[h]);t.useEffect(()=>{if(!r||!h.trim())return;const e=[...G.map(n=>n.id),...W.map(n=>n.id)];e.length===1&&e[0]!==i&&k(e[0])},[r,h,G,W,i]);const d=t.useMemo(()=>p.find(e=>e.id===i),[p,i]),Be=t.useMemo(()=>{if(d!=null&&d.model)return d.model},[d]),Ke=t.useMemo(()=>{if(d!=null&&d.customModelPath)return le(`/api/custom-models/${d.id}`)},[d]),He=d==null?void 0:d.modelScale,Je=t.useMemo(()=>d?"scout":i,[i,d]),B=t.useCallback(async e=>{we(!0);try{const n=e?le(`/api/agents/claude-sessions?cwd=${encodeURIComponent(e)}`):le("/api/agents/claude-sessions"),c=await(await ts(n)).json();X(c.sessions||[])}catch(n){console.error("Failed to fetch sessions:",n),X([])}finally{we(!1)}},[]);t.useEffect(()=>{r?B(M||void 0):(X([]),U(null),xe(""))},[r,B]),t.useEffect(()=>{if(!r)return;const e=setTimeout(()=>{B(M||void 0),U(null)},300);return()=>clearTimeout(e)},[M,r,B]),t.useEffect(()=>{if(!r||!N)return;const e=S.getState().areas.get(N);if(e!=null&&e.directories&&e.directories.length>0){F(e.directories[0]);return}const n=Array.from(S.getState().agents.values()).filter(g=>{var $;return(($=S.getAreaForAgent(g.id))==null?void 0:$.id)===N&&g.cwd});if(n.length===0)return;const l=new Map;for(const g of n)l.set(g.cwd,(l.get(g.cwd)||0)+1);let c="",u=0;for(const[g,$]of l)$>u&&(c=g,u=$);c&&F(c)},[r,N]),t.useEffect(()=>{if(r){const e=new Set(Array.from(S.getState().agents.values()).map(u=>u.name)),n=Ie(e,H),l=p.find(u=>u.id===i),c=l?`${l.name} ${n}`:n;v(c),q.current&&(q.current.focus(),q.current.select())}},[r,H]),t.useEffect(()=>{if(!r)return;const e=p.find(n=>n.id===i);if(e){const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(`${e.name} ${l}`)}else v(`${e.name} ${m}`)}else{const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(l)}}},[i]),t.useEffect(()=>{i==="boss"&&ge("claude-opus-4-7")},[i]);const Xe=()=>{var c;console.log("[SpawnModal] handleSpawn called"),R(!1);const e=E&&((c=y.find(u=>u.sessionId===E))==null?void 0:c.projectPath)||M;if(console.log("[SpawnModal] Effective CWD:",e),console.log("[SpawnModal] Agent name:",m),console.log("[SpawnModal] Agent class:",i),console.log("[SpawnModal] Permission mode:",O),console.log("[SpawnModal] Provider:",o),console.log("[SpawnModal] Use Chrome:",z),console.log("[SpawnModal] Session ID:",E||"none"),!e.trim()){console.error("[SpawnModal] Empty CWD, showing error"),R(!0);return}if(!m.trim()){console.log("[SpawnModal] Empty name, regenerating");const u=new Set(Array.from(S.getState().agents.values()).map(g=>g.name));v(Ie(u,H));return}ds(ne.LAST_CWD,e),I(!0),b();const n=Array.from(fe),l=Ne.trim()||void 0;console.log("[SpawnModal] Calling store.spawnAgent with:",{name:m.trim(),class:i,cwd:e.trim(),sessionId:E||void 0,useChrome:o==="claude"?z:!1,permissionMode:O,provider:o,codexConfig:o==="codex"?f:void 0,codexModel:o==="codex"?ee:void 0,opencodeModel:o==="opencode"?se:void 0,initialSkillIds:n,model:o==="claude"?V:void 0,customInstructions:l?`${l.length} chars`:void 0,spawnAreaId:N||void 0}),window.__spawnModalAreaContext=N?{areaId:N}:null,S.spawnAgent(m.trim(),i,e.trim(),_e||void 0,E||void 0,o==="claude"?z:!1,O,n,o,o==="codex"?f:void 0,o==="codex"?ee:void 0,o==="claude"?V:void 0,l,o==="claude"?Z:void 0,o==="opencode"?se:void 0)},Ce=()=>{console.log("[SpawnModal] Agent creation successful"),I(!1),v(""),Q(new Set),L(),C(),j()},Me=()=>{console.error("[SpawnModal] Agent creation failed"),I(!1),R(!0),L(),C()},ke=e=>{console.log("[SpawnModal] Directory not found:",e),I(!1),he(e),J(!0),C()},ye=()=>{J(!1),I(!0),b(),S.createDirectoryAndSpawn(ue,m.trim(),i)},ae=()=>{J(!1),he(""),L()};t.useEffect(()=>(window.__spawnModalSuccess=Ce,window.__spawnModalError=Me,window.__spawnModalDirNotFound=ke,()=>{L(),delete window.__spawnModalSuccess,delete window.__spawnModalError,delete window.__spawnModalDirNotFound}),[m,i,Ce,Me,ke,L]);const{handleMouseDown:Ye,handleClick:Qe}=ls(j),Ve=e=>{e.key==="Escape"&&j()};return!r&&!me?null:me?s.jsx("div",{className:"modal-overlay visible",onClick:ae,onKeyDown:e=>{e.key==="Escape"&&ae(),e.key==="Enter"&&ye()},children:s.jsxs("div",{className:"modal confirm-modal",onClick:e=>e.stopPropagation(),children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.directoryNotFound")}),s.jsxs("div",{className:"modal-body confirm-modal-body",children:[s.jsx("p",{children:a("terminal:spawn.directoryNotExist")}),s.jsx("code",{className:"confirm-modal-path",children:ue}),s.jsx("p",{children:a("terminal:spawn.wouldYouCreate")})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:ae,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:ye,autoFocus:!0,children:a("terminal:spawn.createDirectory")})]})]})}):s.jsx("div",{className:`modal-overlay ${r?"visible":""}`,onMouseDown:Ye,onClick:Qe,onKeyDown:Ve,children:s.jsxs("div",{className:"modal spawn-modal",children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.deployTitle")}),s.jsxs("div",{className:"modal-body spawn-modal-body",children:[s.jsxs("div",{className:"spawn-top-section",children:[s.jsx("div",{className:"spawn-preview-compact",children:s.jsx(os,{agentClass:Je,modelFile:Be,customModelUrl:Ke,modelScale:He,width:100,height:120})}),s.jsxs("div",{className:"spawn-class-section",children:[s.jsx("div",{className:"spawn-class-label",children:a("terminal:spawn.agentClass")}),p.length+te.length>6&&s.jsx("input",{type:"text",className:"spawn-input class-search-input",placeholder:a("terminal:spawn.filterClasses"),value:h,onChange:e=>Te(e.target.value)}),s.jsxs("div",{className:"class-selector-inline",children:[G.map(e=>s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:e.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)),W.map(e=>{const n=Ae[e.id];return s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:n.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)}),h&&G.length===0&&W.length===0&&s.jsx("div",{className:"class-search-empty",children:a("terminal:spawn.noClassesMatch",{query:h})})]})]})]}),s.jsxs("div",{className:"spawn-form-section",children:[s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("common:labels.name")}),s.jsx("input",{ref:q,type:"text",className:"spawn-input",placeholder:a("terminal:spawn.agentNamePlaceholder"),value:m,onChange:e=>v(e.target.value)})]}),s.jsxs("div",{className:"spawn-field spawn-field-wide",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.workingDir"),s.jsx(x,{text:a("terminal:spawn.helpWorkingDir"),title:a("terminal:spawn.workingDir"),position:"top",size:"sm"})]}),s.jsx(is,{value:M,onChange:e=>{F(e),R(!1)},placeholder:a("terminal:spawn.workingDirPlaceholder"),className:`spawn-input ${Le?"error":""}`,directoriesOnly:!0})]})]}),s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.selectRuntime"),s.jsx(x,{text:a("terminal:spawn.helpRuntime"),title:a("terminal:spawn.runtimeTitle"),position:"top",size:"sm"})]}),s.jsxs("div",{className:"spawn-select-row",children:[s.jsxs("button",{className:`spawn-select-btn ${o==="claude"?"selected":""}`,onClick:()=>Y("claude"),title:a("terminal:spawn.useClaudeCli"),children:[s.jsx("img",{src:"/assets/claude.ico",alt:"Claude",className:"spawn-provider-icon"}),s.jsx("span",{children:"Claude"})]}),s.jsxs("button",{className:`spawn-select-btn ${o==="codex"?"selected":""}`,onClick:()=>Y("codex"),title:a("terminal:spawn.useCodexCli"),children:[s.jsx("img",{src:"/assets/codex.ico",alt:"Codex",className:"spawn-provider-icon"}),s.jsx("span",{children:"Codex"})]}),s.jsxs("button",{className:`spawn-select-btn spawn-select-btn--opencode ${o==="opencode"?"selected":""}`,onClick:()=>Y("opencode"),title:"Use OpenCode CLI (multi-provider)",children:[s.jsx("img",{src:"/assets/opencode.svg",alt:"OpenCode",className:"spawn-provider-icon"}),s.jsx("span",{children:"OpenCode"})]})]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.permissions"),s.jsx(x,{text:a("terminal:spawn.helpPermission"),title:a("terminal:spawn.permissionMode"),position:"top",size:"sm"})]}),s.jsx("div",{className:"spawn-select-row",children:Object.keys(oe).map(e=>s.jsxs("button",{className:`spawn-select-btn ${O===e?"selected":""}`,onClick:()=>Fe(e),title:oe[e].description,children:[s.jsx("span",{children:s.jsx(ie,{name:e==="bypass"?"bolt":"lock",size:12})}),s.jsx("span",{children:oe[e].label})]},e))})]})]}),s.jsx("div",{className:"spawn-form-row",children:s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.model"),s.jsx(x,{text:a("terminal:spawn.helpModel"),title:a("terminal:spawn.modelTitle"),position:"top",size:"sm"})]}),o==="claude"?s.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(T).filter(e=>!T[e].deprecated).map(e=>s.jsxs("button",{className:`spawn-select-btn ${V===e?"selected":""}`,onClick:()=>ge(e),title:T[e].description,children:[s.jsx("span",{children:T[e].icon}),s.jsx("span",{children:T[e].label})]},e))}):o==="codex"?s.jsx("div",{className:"spawn-select-row spawn-select-row--codex-models",children:Object.keys(K).map(e=>s.jsxs("button",{className:`spawn-select-btn ${ee===e?"selected":""}`,onClick:()=>Re(e),title:K[e].description,children:[s.jsx("span",{children:K[e].icon}),s.jsx("span",{children:K[e].label})]},e))}):o==="opencode"?s.jsx(cs,{value:se,onChange:Ue,inputId:"spawn-opencode-model"}):s.jsx("div",{className:"spawn-inline-hint",children:a("terminal:spawn.chooseCodexModel")})]})}),s.jsxs("div",{className:"spawn-form-row",children:[o==="claude"&&s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:"Effort"}),s.jsxs("div",{className:"spawn-select-row spawn-select-row--effort",children:[s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===void 0?"selected":""}`,onClick:()=>je(void 0),title:"Use default effort level",children:s.jsx("span",{children:"Default"})}),Object.keys(ce).map(e=>s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===e?"selected":""}`,onClick:()=>je(e),title:ce[e].description,children:s.jsx("span",{children:ce[e].label})},e))]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("terminal:spawn.browser")}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:z,onChange:e=>Pe(e.target.checked),disabled:o!=="claude"}),s.jsxs("span",{children:[s.jsx(ie,{name:"globe",size:12})," ",a("terminal:spawn.chromeBrowser")]}),s.jsx(x,{text:a(o==="claude"?"terminal:spawn.helpChrome":"terminal:spawn.helpChromeDisabled"),title:a("terminal:spawn.chromeBrowser"),position:"top",size:"sm"})]})]})]}),o==="codex"&&s.jsxs("div",{className:"codex-config-section",children:[s.jsx("div",{className:"codex-config-title",children:a("terminal:spawn.codex.configuration")}),s.jsxs("div",{className:"codex-config-options",children:[s.jsxs("div",{className:"codex-option-group",children:[s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:f.fullAuto!==!1,onChange:e=>A(n=>({...n,fullAuto:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.fullAuto")}),s.jsx(x,{text:a("terminal:spawn.helpFullAuto"),title:a("terminal:spawn.fullAutoTitle"),position:"top",size:"sm"})]}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:!!f.search,onChange:e=>A(n=>({...n,search:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.search")}),s.jsx(x,{text:a("terminal:spawn.helpSearch"),title:a("terminal:spawn.searchTitle"),position:"top",size:"sm"})]})]}),f.fullAuto===!1&&s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.restrictions")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.sandbox||"workspace-write",onChange:e=>A(n=>({...n,sandbox:e.target.value})),children:[s.jsxs("option",{value:"read-only",children:["📖 ",a("terminal:spawn.codex.sandboxReadOnly")]}),s.jsxs("option",{value:"workspace-write",children:["✏️ ",a("terminal:spawn.codex.sandboxWorkspaceWrite")]}),s.jsxs("option",{value:"danger-full-access",children:["⚡ ",a("terminal:spawn.codex.sandboxDangerFullAccess")]})]}),s.jsxs("select",{className:"spawn-input codex-select",value:f.approvalMode||"on-request",onChange:e=>A(n=>({...n,approvalMode:e.target.value})),children:[s.jsxs("option",{value:"untrusted",children:["🔒 ",a("terminal:spawn.codex.approvalsUntrusted")]}),s.jsxs("option",{value:"on-failure",children:["⚠️ ",a("terminal:spawn.codex.approvalsOnFailure")]}),s.jsxs("option",{value:"on-request",children:["🤔 ",a("terminal:spawn.codex.approvalsOnRequest")]}),s.jsxs("option",{value:"never",children:["✅ ",a("terminal:spawn.codex.approvalsNever")]})]})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.profile")}),s.jsx("input",{type:"text",className:"spawn-input codex-profile-input",placeholder:a("terminal:spawn.codex.profilePlaceholder"),value:f.profile||"",onChange:e=>A(n=>({...n,profile:e.target.value||void 0}))})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.reasoningEffort")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.reasoningEffort||"",onChange:e=>A(n=>({...n,reasoningEffort:e.target.value||void 0})),children:[s.jsx("option",{value:"",children:a("terminal:spawn.codex.reasoningEffortDefault")}),Object.keys(re).map(e=>s.jsxs("option",{value:e,children:[re[e].icon," ",re[e].label]},e))]})]})]})]}),w.length>0&&s.jsxs("div",{className:"spawn-skills-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.skills")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpSkills"),title:a("terminal:spawn.skillsTitle"),position:"top",size:"sm"})]}),w.length>6&&s.jsx("input",{type:"text",className:"spawn-input skill-search-input",placeholder:a("terminal:spawn.filterSkills"),value:D,onChange:e=>Oe(e.target.value)}),s.jsxs("div",{className:"spawn-skills-inline",children:[Se.map(e=>{const n=fe.has(e.id);return We.some(c=>c.id===e.id)?null:s.jsxs("button",{className:`spawn-skill-chip ${n?"selected":""}`,onClick:()=>Ge(e.id),title:e.description,children:[n&&s.jsx("span",{className:"spawn-skill-check",children:s.jsx(ie,{name:"check",size:10})}),s.jsx("span",{children:e.name}),e.builtin&&s.jsx("span",{className:"spawn-skill-builtin",children:"TC"})]},e.id)}),D&&Se.length===0&&s.jsx("div",{className:"skill-search-empty",children:a("terminal:spawn.noSkillsMatch",{query:D})})]})]}),s.jsxs("div",{className:"spawn-custom-instructions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.customInstructions")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpCustomInstructions"),title:a("terminal:spawn.customInstructions"),position:"top",size:"sm"})]}),s.jsx("textarea",{className:"spawn-input spawn-textarea",placeholder:a("terminal:spawn.customInstructionsPlaceholder"),value:Ne,onChange:e=>ze(e.target.value),rows:3})]}),s.jsxs("div",{className:"spawn-sessions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.linkSession")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpLinkSession"),title:a("terminal:spawn.linkSessionTitle"),position:"top",size:"sm"})]}),y.length>0&&s.jsx("input",{type:"text",className:"spawn-input session-search-input",placeholder:a("terminal:spawn.searchSessions"),value:_,onChange:e=>xe(e.target.value)}),s.jsx("div",{className:"sessions-list",children:$e?s.jsx("div",{className:"sessions-loading",children:a("terminal:spawn.loadingSessions")}):y.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessions")}):be.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessionsMatch",{query:_})}):be.map(e=>{const n=E===e.sessionId,l=Date.now()-new Date(e.lastModified).getTime(),c=l<6e4?a("common:time.justNow"):l<36e5?a("common:time.minutesAgo",{count:Math.floor(l/6e4)}):l<864e5?a("common:time.hoursAgo",{count:Math.floor(l/36e5)}):a("common:time.daysAgo",{count:Math.floor(l/864e5)});return s.jsxs("div",{className:`session-item ${n?"selected":""}`,onClick:()=>{n?U(null):(U(e.sessionId),F(e.projectPath))},children:[s.jsxs("div",{className:"session-item-header",children:[s.jsx("span",{className:"session-item-path",children:e.projectPath}),s.jsx("span",{className:"session-item-age",children:c})]}),s.jsx("div",{className:"session-item-preview",children:e.firstMessage||a("terminal:spawn.messagesCount",{count:e.messageCount})})]},e.sessionId)})})]})]})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:j,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:Xe,disabled:pe,children:a(pe?"common:buttons.deploying":"common:buttons2.deploy")})]})]})})}export{hs as SpawnModal};
1
+ import{u as Ze,aC as es,aD as ss,aE as as,aF as ns,r as t,G as Ee,S as ne,aG as te,A as Ae,l as le,aH as ts,s as S,h as ls,j as s,aI as os,Y as De,aJ as x,aK as is,aL as oe,I as ie,ao as T,am as H,aM as cs,an as ce,aN as re,aO as rs,H as ds}from"./main-DFVcOIIz.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Ie(r,j){const b=j.filter(C=>!r.has(C));return b.length===0?`${j[Math.floor(Math.random()*j.length)]}-${Date.now()%1e3}`:b[Math.floor(Math.random()*b.length)]}function hs({isOpen:r,onClose:j,onSpawnStart:b,onSpawnEnd:C,spawnPosition:_e,spawnAreaId:N}){const{t:a}=Ze(["terminal","common"]),P=es(),p=ss(),de=as(),K=de.length>0?de:ns,[m,v]=t.useState(""),[M,F]=t.useState(()=>Ee(ne.LAST_CWD)),[i,k]=t.useState("scout"),[pe,I]=t.useState(!1),[Le,R]=t.useState(!1),[me,J]=t.useState(!1),[ue,he]=t.useState(""),[y,Y]=t.useState([]),[E,O]=t.useState(null),[$e,we]=t.useState(!1),[_,xe]=t.useState(""),[h,Te]=t.useState(""),[U,Pe]=t.useState(!1),[z,Fe]=t.useState("bypass"),[o,X]=t.useState("claude"),[f,A]=t.useState({fullAuto:!0,sandbox:"workspace-write",approvalMode:"on-request",search:!1}),[fe,Q]=t.useState(new Set),[V,ge]=t.useState("opus[1m]"),[Z,je]=t.useState("xHigh"),[ee,Re]=t.useState("gpt-5.3-codex"),[se,Oe]=t.useState("minimax/MiniMax-M1-80k"),[Ne,Ue]=t.useState(""),[D,ze]=t.useState(""),q=t.useRef(null),ve=t.useRef(!1),L=t.useCallback(()=>{window.__spawnModalAreaContext=null},[]),w=t.useMemo(()=>P.filter(e=>e.enabled),[P]),qe=["full-notifications","streaming-exec","task-label","report-task-to-boss","agent-tracking","send-message-to-agent"];t.useEffect(()=>{if(r&&!ve.current){if(w.length>0){const l=w.filter(c=>qe.includes(c.slug)).map(c=>c.id);l.length>0&&Q(new Set(l))}const n=Ee(ne.DEFAULT_AGENT_CLASS);if(n==="random"){const c=[...Object.keys(rs),...p.map(u=>u.id)];k(c[Math.floor(Math.random()*c.length)])}else k(n||"scout")}ve.current=r},[r,w,p]);const Se=t.useMemo(()=>{if(!D.trim())return w;const e=D.toLowerCase();return w.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.slug.toLowerCase().includes(e))},[w,D]),Ge=t.useCallback(e=>{Q(n=>{const l=new Set(n);return l.has(e)?l.delete(e):l.add(e),l})},[]);t.useMemo(()=>w.filter(e=>e.assignedAgentClasses.includes(i)),[w,i]);const We=t.useMemo(()=>{var n;const e=p.find(l=>l.id===i);return(n=e==null?void 0:e.defaultSkillIds)!=null&&n.length?P.filter(l=>e.defaultSkillIds.includes(l.id)):[]},[p,i,P]),be=t.useMemo(()=>{if(!_.trim())return y;const e=_.toLowerCase();return y.filter(n=>n.sessionId.toLowerCase().includes(e)||n.projectPath.toLowerCase().includes(e)||n.firstMessage&&n.firstMessage.toLowerCase().includes(e))},[y,_]),G=t.useMemo(()=>{if(!h.trim())return p;const e=h.toLowerCase();return p.filter(n=>n.name.toLowerCase().includes(e)||n.description.toLowerCase().includes(e)||n.id.toLowerCase().includes(e))},[p,h]),W=t.useMemo(()=>{if(!h.trim())return te;const e=h.toLowerCase();return te.filter(n=>{const l=Ae[n.id];return n.name.toLowerCase().includes(e)||n.id.toLowerCase().includes(e)||l.description.toLowerCase().includes(e)})},[h]);t.useEffect(()=>{if(!r||!h.trim())return;const e=[...G.map(n=>n.id),...W.map(n=>n.id)];e.length===1&&e[0]!==i&&k(e[0])},[r,h,G,W,i]);const d=t.useMemo(()=>p.find(e=>e.id===i),[p,i]),Be=t.useMemo(()=>{if(d!=null&&d.model)return d.model},[d]),He=t.useMemo(()=>{if(d!=null&&d.customModelPath)return le(`/api/custom-models/${d.id}`)},[d]),Ke=d==null?void 0:d.modelScale,Je=t.useMemo(()=>d?"scout":i,[i,d]),B=t.useCallback(async e=>{we(!0);try{const n=e?le(`/api/agents/claude-sessions?cwd=${encodeURIComponent(e)}`):le("/api/agents/claude-sessions"),c=await(await ts(n)).json();Y(c.sessions||[])}catch(n){console.error("Failed to fetch sessions:",n),Y([])}finally{we(!1)}},[]);t.useEffect(()=>{r?B(M||void 0):(Y([]),O(null),xe(""))},[r,B]),t.useEffect(()=>{if(!r)return;const e=setTimeout(()=>{B(M||void 0),O(null)},300);return()=>clearTimeout(e)},[M,r,B]),t.useEffect(()=>{if(!r||!N)return;const e=S.getState().areas.get(N);if(e!=null&&e.directories&&e.directories.length>0){F(e.directories[0]);return}const n=Array.from(S.getState().agents.values()).filter(g=>{var $;return(($=S.getAreaForAgent(g.id))==null?void 0:$.id)===N&&g.cwd});if(n.length===0)return;const l=new Map;for(const g of n)l.set(g.cwd,(l.get(g.cwd)||0)+1);let c="",u=0;for(const[g,$]of l)$>u&&(c=g,u=$);c&&F(c)},[r,N]),t.useEffect(()=>{if(r){const e=new Set(Array.from(S.getState().agents.values()).map(u=>u.name)),n=Ie(e,K),l=p.find(u=>u.id===i),c=l?`${l.name} ${n}`:n;v(c),q.current&&(q.current.focus(),q.current.select())}},[r,K]),t.useEffect(()=>{if(!r)return;const e=p.find(n=>n.id===i);if(e){const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(`${e.name} ${l}`)}else v(`${e.name} ${m}`)}else{const n=p.find(l=>m.startsWith(l.name+" "));if(n){const l=m.substring(n.name.length+1);v(l)}}},[i]),t.useEffect(()=>{i==="boss"&&ge("claude-opus-4-7")},[i]);const Ye=()=>{var c;console.log("[SpawnModal] handleSpawn called"),R(!1);const e=E&&((c=y.find(u=>u.sessionId===E))==null?void 0:c.projectPath)||M;if(console.log("[SpawnModal] Effective CWD:",e),console.log("[SpawnModal] Agent name:",m),console.log("[SpawnModal] Agent class:",i),console.log("[SpawnModal] Permission mode:",z),console.log("[SpawnModal] Provider:",o),console.log("[SpawnModal] Use Chrome:",U),console.log("[SpawnModal] Session ID:",E||"none"),!e.trim()){console.error("[SpawnModal] Empty CWD, showing error"),R(!0);return}if(!m.trim()){console.log("[SpawnModal] Empty name, regenerating");const u=new Set(Array.from(S.getState().agents.values()).map(g=>g.name));v(Ie(u,K));return}ds(ne.LAST_CWD,e),I(!0),b();const n=Array.from(fe),l=Ne.trim()||void 0;console.log("[SpawnModal] Calling store.spawnAgent with:",{name:m.trim(),class:i,cwd:e.trim(),sessionId:E||void 0,useChrome:o==="claude"?U:!1,permissionMode:z,provider:o,codexConfig:o==="codex"?f:void 0,codexModel:o==="codex"?ee:void 0,opencodeModel:o==="opencode"?se:void 0,initialSkillIds:n,model:o==="claude"?V:void 0,customInstructions:l?`${l.length} chars`:void 0,spawnAreaId:N||void 0}),window.__spawnModalAreaContext=N?{areaId:N}:null,S.spawnAgent(m.trim(),i,e.trim(),_e||void 0,E||void 0,o==="claude"?U:!1,z,n,o,o==="codex"?f:void 0,o==="codex"?ee:void 0,o==="claude"?V:void 0,l,o==="claude"?Z:void 0,o==="opencode"?se:void 0)},Ce=()=>{console.log("[SpawnModal] Agent creation successful"),I(!1),v(""),Q(new Set),L(),C(),j()},Me=()=>{console.error("[SpawnModal] Agent creation failed"),I(!1),R(!0),L(),C()},ke=e=>{console.log("[SpawnModal] Directory not found:",e),I(!1),he(e),J(!0),C()},ye=()=>{J(!1),I(!0),b(),S.createDirectoryAndSpawn(ue,m.trim(),i)},ae=()=>{J(!1),he(""),L()};t.useEffect(()=>(window.__spawnModalSuccess=Ce,window.__spawnModalError=Me,window.__spawnModalDirNotFound=ke,()=>{L(),delete window.__spawnModalSuccess,delete window.__spawnModalError,delete window.__spawnModalDirNotFound}),[m,i,Ce,Me,ke,L]);const{handleMouseDown:Xe,handleClick:Qe}=ls(j),Ve=e=>{e.key==="Escape"&&j()};return!r&&!me?null:me?s.jsx("div",{className:"modal-overlay visible",onClick:ae,onKeyDown:e=>{e.key==="Escape"&&ae(),e.key==="Enter"&&ye()},children:s.jsxs("div",{className:"modal confirm-modal",onClick:e=>e.stopPropagation(),children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.directoryNotFound")}),s.jsxs("div",{className:"modal-body confirm-modal-body",children:[s.jsx("p",{children:a("terminal:spawn.directoryNotExist")}),s.jsx("code",{className:"confirm-modal-path",children:ue}),s.jsx("p",{children:a("terminal:spawn.wouldYouCreate")})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:ae,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:ye,autoFocus:!0,children:a("terminal:spawn.createDirectory")})]})]})}):s.jsx("div",{className:`modal-overlay ${r?"visible":""}`,onMouseDown:Xe,onClick:Qe,onKeyDown:Ve,children:s.jsxs("div",{className:"modal spawn-modal",children:[s.jsx("div",{className:"modal-header",children:a("terminal:spawn.deployTitle")}),s.jsxs("div",{className:"modal-body spawn-modal-body",children:[s.jsxs("div",{className:"spawn-top-section",children:[s.jsx("div",{className:"spawn-preview-compact",children:s.jsx(os,{agentClass:Je,modelFile:Be,customModelUrl:He,modelScale:Ke,width:100,height:120})}),s.jsxs("div",{className:"spawn-class-section",children:[s.jsx("div",{className:"spawn-class-label",children:a("terminal:spawn.agentClass")}),p.length+te.length>6&&s.jsx("input",{type:"text",className:"spawn-input class-search-input",placeholder:a("terminal:spawn.filterClasses"),value:h,onChange:e=>Te(e.target.value)}),s.jsxs("div",{className:"class-selector-inline",children:[G.map(e=>s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:e.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)),W.map(e=>{const n=Ae[e.id];return s.jsxs("button",{className:`class-chip ${i===e.id?"selected":""}`,onClick:()=>k(e.id),title:n.description,children:[s.jsx(De,{classId:e.id,size:18,className:"class-chip-icon"}),s.jsx("span",{className:"class-chip-name",children:e.name})]},e.id)}),h&&G.length===0&&W.length===0&&s.jsx("div",{className:"class-search-empty",children:a("terminal:spawn.noClassesMatch",{query:h})})]})]})]}),s.jsxs("div",{className:"spawn-form-section",children:[s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("common:labels.name")}),s.jsx("input",{ref:q,type:"text",className:"spawn-input",placeholder:a("terminal:spawn.agentNamePlaceholder"),value:m,onChange:e=>v(e.target.value)})]}),s.jsxs("div",{className:"spawn-field spawn-field-wide",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.workingDir"),s.jsx(x,{text:a("terminal:spawn.helpWorkingDir"),title:a("terminal:spawn.workingDir"),position:"top",size:"sm"})]}),s.jsx(is,{value:M,onChange:e=>{F(e),R(!1)},placeholder:a("terminal:spawn.workingDirPlaceholder"),className:`spawn-input ${Le?"error":""}`,directoriesOnly:!0})]})]}),s.jsxs("div",{className:"spawn-form-row",children:[s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.selectRuntime"),s.jsx(x,{text:a("terminal:spawn.helpRuntime"),title:a("terminal:spawn.runtimeTitle"),position:"top",size:"sm"})]}),s.jsxs("div",{className:"spawn-select-row",children:[s.jsxs("button",{className:`spawn-select-btn ${o==="claude"?"selected":""}`,onClick:()=>X("claude"),title:a("terminal:spawn.useClaudeCli"),children:[s.jsx("img",{src:"/assets/claude.ico",alt:"Claude",className:"spawn-provider-icon"}),s.jsx("span",{children:"Claude"})]}),s.jsxs("button",{className:`spawn-select-btn ${o==="codex"?"selected":""}`,onClick:()=>X("codex"),title:a("terminal:spawn.useCodexCli"),children:[s.jsx("img",{src:"/assets/codex.ico",alt:"Codex",className:"spawn-provider-icon"}),s.jsx("span",{children:"Codex"})]}),s.jsxs("button",{className:`spawn-select-btn spawn-select-btn--opencode ${o==="opencode"?"selected":""}`,onClick:()=>X("opencode"),title:"Use OpenCode CLI (multi-provider)",children:[s.jsx("img",{src:"/assets/opencode.svg",alt:"OpenCode",className:"spawn-provider-icon"}),s.jsx("span",{children:"OpenCode"})]})]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.permissions"),s.jsx(x,{text:a("terminal:spawn.helpPermission"),title:a("terminal:spawn.permissionMode"),position:"top",size:"sm"})]}),s.jsx("div",{className:"spawn-select-row",children:Object.keys(oe).map(e=>s.jsxs("button",{className:`spawn-select-btn ${z===e?"selected":""}`,onClick:()=>Fe(e),title:oe[e].description,children:[s.jsx("span",{children:s.jsx(ie,{name:e==="bypass"?"bolt":"lock",size:12})}),s.jsx("span",{children:oe[e].label})]},e))})]})]}),s.jsx("div",{className:"spawn-form-row",children:s.jsxs("div",{className:"spawn-field",children:[s.jsxs("label",{className:"spawn-label",children:[a("common:labels.model"),s.jsx(x,{text:a("terminal:spawn.helpModel"),title:a("terminal:spawn.modelTitle"),position:"top",size:"sm"})]}),o==="claude"?s.jsx("div",{className:"spawn-select-row spawn-select-row--wrap",children:Object.keys(T).filter(e=>!T[e].deprecated).map(e=>s.jsxs("button",{className:`spawn-select-btn ${V===e?"selected":""}`,onClick:()=>ge(e),title:T[e].description,children:[s.jsx("span",{children:T[e].icon}),s.jsx("span",{children:T[e].label})]},e))}):o==="codex"?s.jsx("div",{className:"spawn-select-row spawn-select-row--codex-models",children:Object.keys(H).map(e=>s.jsxs("button",{className:`spawn-select-btn ${ee===e?"selected":""}`,onClick:()=>Re(e),title:H[e].description,children:[s.jsx("span",{children:H[e].icon}),s.jsx("span",{children:H[e].label})]},e))}):o==="opencode"?s.jsx(cs,{value:se,onChange:Oe,inputId:"spawn-opencode-model"}):s.jsx("div",{className:"spawn-inline-hint",children:a("terminal:spawn.chooseCodexModel")})]})}),s.jsxs("div",{className:"spawn-form-row",children:[o==="claude"&&s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:"Effort"}),s.jsxs("div",{className:"spawn-select-row spawn-select-row--effort",children:[s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===void 0?"selected":""}`,onClick:()=>je(void 0),title:"Use default effort level",children:s.jsx("span",{children:"Default"})}),Object.keys(ce).map(e=>s.jsx("button",{className:`spawn-select-btn spawn-select-btn--compact ${Z===e?"selected":""}`,onClick:()=>je(e),title:ce[e].description,children:s.jsx("span",{children:ce[e].label})},e))]})]}),s.jsxs("div",{className:"spawn-field",children:[s.jsx("label",{className:"spawn-label",children:a("terminal:spawn.browser")}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:U,onChange:e=>Pe(e.target.checked),disabled:o!=="claude"}),s.jsxs("span",{children:[s.jsx(ie,{name:"globe",size:12})," ",a("terminal:spawn.chromeBrowser")]}),s.jsx(x,{text:a(o==="claude"?"terminal:spawn.helpChrome":"terminal:spawn.helpChromeDisabled"),title:a("terminal:spawn.chromeBrowser"),position:"top",size:"sm"})]})]})]}),o==="codex"&&s.jsxs("div",{className:"codex-config-section",children:[s.jsx("div",{className:"codex-config-title",children:a("terminal:spawn.codex.configuration")}),s.jsxs("div",{className:"codex-config-options",children:[s.jsxs("div",{className:"codex-option-group",children:[s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:f.fullAuto!==!1,onChange:e=>A(n=>({...n,fullAuto:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.fullAuto")}),s.jsx(x,{text:a("terminal:spawn.helpFullAuto"),title:a("terminal:spawn.fullAutoTitle"),position:"top",size:"sm"})]}),s.jsxs("label",{className:"spawn-checkbox",children:[s.jsx("input",{type:"checkbox",checked:!!f.search,onChange:e=>A(n=>({...n,search:e.target.checked}))}),s.jsx("span",{children:a("terminal:spawn.codex.search")}),s.jsx(x,{text:a("terminal:spawn.helpSearch"),title:a("terminal:spawn.searchTitle"),position:"top",size:"sm"})]})]}),f.fullAuto===!1&&s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.restrictions")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.sandbox||"workspace-write",onChange:e=>A(n=>({...n,sandbox:e.target.value})),children:[s.jsxs("option",{value:"read-only",children:["📖 ",a("terminal:spawn.codex.sandboxReadOnly")]}),s.jsxs("option",{value:"workspace-write",children:["✏️ ",a("terminal:spawn.codex.sandboxWorkspaceWrite")]}),s.jsxs("option",{value:"danger-full-access",children:["⚡ ",a("terminal:spawn.codex.sandboxDangerFullAccess")]})]}),s.jsxs("select",{className:"spawn-input codex-select",value:f.approvalMode||"on-request",onChange:e=>A(n=>({...n,approvalMode:e.target.value})),children:[s.jsxs("option",{value:"untrusted",children:["🔒 ",a("terminal:spawn.codex.approvalsUntrusted")]}),s.jsxs("option",{value:"on-failure",children:["⚠️ ",a("terminal:spawn.codex.approvalsOnFailure")]}),s.jsxs("option",{value:"on-request",children:["🤔 ",a("terminal:spawn.codex.approvalsOnRequest")]}),s.jsxs("option",{value:"never",children:["✅ ",a("terminal:spawn.codex.approvalsNever")]})]})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.profile")}),s.jsx("input",{type:"text",className:"spawn-input codex-profile-input",placeholder:a("terminal:spawn.codex.profilePlaceholder"),value:f.profile||"",onChange:e=>A(n=>({...n,profile:e.target.value||void 0}))})]}),s.jsxs("div",{className:"codex-option-group",children:[s.jsx("div",{className:"codex-option-header",children:a("terminal:spawn.codex.reasoningEffort")}),s.jsxs("select",{className:"spawn-input codex-select",value:f.reasoningEffort||"",onChange:e=>A(n=>({...n,reasoningEffort:e.target.value||void 0})),children:[s.jsx("option",{value:"",children:a("terminal:spawn.codex.reasoningEffortDefault")}),Object.keys(re).map(e=>s.jsxs("option",{value:e,children:[re[e].icon," ",re[e].label]},e))]})]})]})]}),w.length>0&&s.jsxs("div",{className:"spawn-skills-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.skills")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpSkills"),title:a("terminal:spawn.skillsTitle"),position:"top",size:"sm"})]}),w.length>6&&s.jsx("input",{type:"text",className:"spawn-input skill-search-input",placeholder:a("terminal:spawn.filterSkills"),value:D,onChange:e=>ze(e.target.value)}),s.jsxs("div",{className:"spawn-skills-inline",children:[Se.map(e=>{const n=fe.has(e.id);return We.some(c=>c.id===e.id)?null:s.jsxs("button",{className:`spawn-skill-chip ${n?"selected":""}`,onClick:()=>Ge(e.id),title:e.description,children:[n&&s.jsx("span",{className:"spawn-skill-check",children:s.jsx(ie,{name:"check",size:10})}),s.jsx("span",{children:e.name}),e.builtin&&s.jsx("span",{className:"spawn-skill-builtin",children:"TC"})]},e.id)}),D&&Se.length===0&&s.jsx("div",{className:"skill-search-empty",children:a("terminal:spawn.noSkillsMatch",{query:D})})]})]}),s.jsxs("div",{className:"spawn-custom-instructions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.customInstructions")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpCustomInstructions"),title:a("terminal:spawn.customInstructions"),position:"top",size:"sm"})]}),s.jsx("textarea",{className:"spawn-input spawn-textarea",placeholder:a("terminal:spawn.customInstructionsPlaceholder"),value:Ne,onChange:e=>Ue(e.target.value),rows:3})]}),s.jsxs("div",{className:"spawn-sessions-section",children:[s.jsxs("label",{className:"spawn-label",children:[a("terminal:spawn.linkSession")," ",s.jsxs("span",{className:"spawn-label-hint",children:["(",a("common:labels.optional"),")"]}),s.jsx(x,{text:a("terminal:spawn.helpLinkSession"),title:a("terminal:spawn.linkSessionTitle"),position:"top",size:"sm"})]}),y.length>0&&s.jsx("input",{type:"text",className:"spawn-input session-search-input",placeholder:a("terminal:spawn.searchSessions"),value:_,onChange:e=>xe(e.target.value)}),s.jsx("div",{className:"sessions-list",children:$e?s.jsx("div",{className:"sessions-loading",children:a("terminal:spawn.loadingSessions")}):y.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessions")}):be.length===0?s.jsx("div",{className:"sessions-empty",children:a("terminal:spawn.noSessionsMatch",{query:_})}):be.map(e=>{const n=E===e.sessionId,l=Date.now()-new Date(e.lastModified).getTime(),c=l<6e4?a("common:time.justNow"):l<36e5?a("common:time.minutesAgo",{count:Math.floor(l/6e4)}):l<864e5?a("common:time.hoursAgo",{count:Math.floor(l/36e5)}):a("common:time.daysAgo",{count:Math.floor(l/864e5)});return s.jsxs("div",{className:`session-item ${n?"selected":""}`,onClick:()=>{n?O(null):(O(e.sessionId),F(e.projectPath))},children:[s.jsxs("div",{className:"session-item-header",children:[s.jsx("span",{className:"session-item-path",children:e.projectPath}),s.jsx("span",{className:"session-item-age",children:c})]}),s.jsx("div",{className:"session-item-preview",children:e.firstMessage||a("terminal:spawn.messagesCount",{count:e.messageCount})})]},e.sessionId)})})]})]})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:j,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-primary",onClick:Ye,disabled:pe,children:a(pe?"common:buttons.deploying":"common:buttons2.deploy")})]})]})})}export{hs as SpawnModal};
@@ -1 +1 @@
1
- import{u as L,ad as $,a8 as D,r as m,j as s,aN as v,W as S,I as g,s as J}from"./main-BlnQCHb9.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function M({isOpen:l,bossId:r,onClose:o}){var j;const{t:a}=L(["terminal","common"]),f=$(),n=D(r),[i,c]=m.useState(new Set),[u,b]=m.useState(!1),d=Array.from(f.values()).filter(e=>e.class!=="boss"&&(!e.bossId||e.bossId===r));m.useEffect(()=>{l&&n&&c(new Set(n.subordinateIds||[]))},[l,n]);const y=()=>{b(!0),J.assignSubordinates(r,Array.from(i)),setTimeout(()=>{b(!1),o()},300)},A=e=>{const t=new Set(i);t.has(e)?t.delete(e):t.add(e),c(t)},C=()=>{c(new Set(d.map(e=>e.id)))},p=()=>{c(new Set)},w=e=>{e.target===e.currentTarget&&o()},k=e=>{e.key==="Escape"&&o()};if(!l||!n)return null;const E=v.boss,h=((j=n.subordinateIds)==null?void 0:j.length)||0,I=i.size,x=JSON.stringify([...n.subordinateIds||[]].sort())!==JSON.stringify([...i].sort());return s.jsx("div",{className:`modal-overlay ${l?"visible":""}`,onClick:w,onKeyDown:k,children:s.jsxs("div",{className:"modal subordinate-assignment-modal",children:[s.jsxs("div",{className:"modal-header",children:[s.jsx("span",{className:"boss-header-icon",style:{color:E.color},children:s.jsx(S,{agent:n,size:22})}),a("terminal:team.manageTeam"),": ",n.name]}),s.jsxs("div",{className:"modal-body subordinate-assignment-body",children:[s.jsxs("div",{className:"subordinate-assignment-info",children:[s.jsx("p",{children:a("terminal:team.selectAgents")}),s.jsxs("div",{className:"subordinate-assignment-actions",children:[s.jsx("button",{className:"btn btn-small",onClick:C,children:a("common:buttons.selectAll")}),s.jsx("button",{className:"btn btn-small",onClick:p,children:a("common:buttons.clearAll")})]})]}),s.jsx("div",{className:"subordinates-list",children:d.length===0?s.jsx("div",{className:"subordinates-empty",children:a("terminal:team.noAgentsAvailable")}):d.map(e=>{var N;const t=i.has(e.id),T=v[e.class],z=(N=n.subordinateIds)==null?void 0:N.includes(e.id);return s.jsxs("div",{className:`subordinate-item ${t?"selected":""}`,onClick:()=>A(e.id),children:[s.jsx("div",{className:"subordinate-checkbox",children:t?s.jsx(g,{name:"check",size:12}):null}),s.jsx("div",{className:"subordinate-icon",style:{color:T.color},children:s.jsx(S,{agent:e,size:18})}),s.jsxs("div",{className:"subordinate-info",children:[s.jsx("div",{className:"subordinate-name",children:e.name}),s.jsx("div",{className:"subordinate-class",children:e.class})]}),s.jsx("div",{className:`subordinate-status status-${e.status}`,children:e.status}),z&&s.jsx("div",{className:"subordinate-badge",children:a("common:status.current")})]},e.id)})}),s.jsx("div",{className:"subordinate-assignment-summary",children:x?s.jsxs("span",{className:"summary-changed",children:[h," ",s.jsx(g,{name:"arrow-right",size:11})," ",I," ",a("terminal:team.subordinates").toLowerCase()]}):s.jsxs("span",{className:"summary-unchanged",children:[h," ",a("terminal:team.subordinates").toLowerCase()]})})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:o,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-boss",onClick:y,disabled:u||!x,children:a(u?"common:status.saving":"terminal:team.saveTeam")})]})]})})}export{M as SubordinateAssignmentModal};
1
+ import{u as L,af as $,aa as D,r as m,j as s,aP as N,Y as S,I as f,s as J}from"./main-DFVcOIIz.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function M({isOpen:l,bossId:r,onClose:o}){var j;const{t:a}=L(["terminal","common"]),g=$(),n=D(r),[i,c]=m.useState(new Set),[u,b]=m.useState(!1),d=Array.from(g.values()).filter(e=>e.class!=="boss"&&(!e.bossId||e.bossId===r));m.useEffect(()=>{l&&n&&c(new Set(n.subordinateIds||[]))},[l,n]);const y=()=>{b(!0),J.assignSubordinates(r,Array.from(i)),setTimeout(()=>{b(!1),o()},300)},A=e=>{const t=new Set(i);t.has(e)?t.delete(e):t.add(e),c(t)},C=()=>{c(new Set(d.map(e=>e.id)))},p=()=>{c(new Set)},w=e=>{e.target===e.currentTarget&&o()},k=e=>{e.key==="Escape"&&o()};if(!l||!n)return null;const E=N.boss,h=((j=n.subordinateIds)==null?void 0:j.length)||0,I=i.size,x=JSON.stringify([...n.subordinateIds||[]].sort())!==JSON.stringify([...i].sort());return s.jsx("div",{className:`modal-overlay ${l?"visible":""}`,onClick:w,onKeyDown:k,children:s.jsxs("div",{className:"modal subordinate-assignment-modal",children:[s.jsxs("div",{className:"modal-header",children:[s.jsx("span",{className:"boss-header-icon",style:{color:E.color},children:s.jsx(S,{agent:n,size:22})}),a("terminal:team.manageTeam"),": ",n.name]}),s.jsxs("div",{className:"modal-body subordinate-assignment-body",children:[s.jsxs("div",{className:"subordinate-assignment-info",children:[s.jsx("p",{children:a("terminal:team.selectAgents")}),s.jsxs("div",{className:"subordinate-assignment-actions",children:[s.jsx("button",{className:"btn btn-small",onClick:C,children:a("common:buttons.selectAll")}),s.jsx("button",{className:"btn btn-small",onClick:p,children:a("common:buttons.clearAll")})]})]}),s.jsx("div",{className:"subordinates-list",children:d.length===0?s.jsx("div",{className:"subordinates-empty",children:a("terminal:team.noAgentsAvailable")}):d.map(e=>{var v;const t=i.has(e.id),T=N[e.class],z=(v=n.subordinateIds)==null?void 0:v.includes(e.id);return s.jsxs("div",{className:`subordinate-item ${t?"selected":""}`,onClick:()=>A(e.id),children:[s.jsx("div",{className:"subordinate-checkbox",children:t?s.jsx(f,{name:"check",size:12}):null}),s.jsx("div",{className:"subordinate-icon",style:{color:T.color},children:s.jsx(S,{agent:e,size:18})}),s.jsxs("div",{className:"subordinate-info",children:[s.jsx("div",{className:"subordinate-name",children:e.name}),s.jsx("div",{className:"subordinate-class",children:e.class})]}),s.jsx("div",{className:`subordinate-status status-${e.status}`,children:e.status}),z&&s.jsx("div",{className:"subordinate-badge",children:a("common:status.current")})]},e.id)})}),s.jsx("div",{className:"subordinate-assignment-summary",children:x?s.jsxs("span",{className:"summary-changed",children:[h," ",s.jsx(f,{name:"arrow-right",size:11})," ",I," ",a("terminal:team.subordinates").toLowerCase()]}):s.jsxs("span",{className:"summary-unchanged",children:[h," ",a("terminal:team.subordinates").toLowerCase()]})})]}),s.jsxs("div",{className:"modal-footer",children:[s.jsx("button",{className:"btn btn-secondary",onClick:o,children:a("common:buttons.cancel")}),s.jsx("button",{className:"btn btn-boss",onClick:y,disabled:u||!x,children:a(u?"common:status.saving":"terminal:team.saveTeam")})]})]})})}export{M as SubordinateAssignmentModal};
@@ -1,3 +1,3 @@
1
- import{ad as ue,r as i,aF as f,l as h,j as e}from"./main-BlnQCHb9.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const he=[{value:"webhook",label:"Webhook"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"}],ye=[{value:"structural",label:"Structural",desc:"Field-based matching (fast, free)"},{value:"llm",label:"LLM",desc:"Semantic matching via LLM (flexible, costs tokens)"},{value:"hybrid",label:"Hybrid",desc:"Structural pre-filter + LLM (recommended)"}],ge=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}];function me(v){if(!v)return"";const d=new Date(v);if(Number.isNaN(d.getTime()))return"";const y=k=>String(k).padStart(2,"0");return`${d.getFullYear()}-${y(d.getMonth()+1)}-${y(d.getDate())}T${y(d.getHours())}:${y(d.getMinutes())}`}const z=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function ve({isOpen:v,onClose:d}){var W,$,J,V,G,X,Y,q,K,Q,Z,ee;const y=ue(),[k,te]=i.useState([]),[C,M]=i.useState("list"),[n,b]=i.useState(z()),[c,F]=i.useState(!1),[L,A]=i.useState(!1),[B,p]=i.useState(null),[D,le]=i.useState([]),[T,se]=i.useState(null),[E,ae]=i.useState(`{
1
+ import{af as ue,r as i,aH as f,l as h,j as e}from"./main-DFVcOIIz.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const he=[{value:"webhook",label:"Webhook"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"}],ye=[{value:"structural",label:"Structural",desc:"Field-based matching (fast, free)"},{value:"llm",label:"LLM",desc:"Semantic matching via LLM (flexible, costs tokens)"},{value:"hybrid",label:"Hybrid",desc:"Structural pre-filter + LLM (recommended)"}],ge=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}];function me(v){if(!v)return"";const d=new Date(v);if(Number.isNaN(d.getTime()))return"";const y=k=>String(k).padStart(2,"0");return`${d.getFullYear()}-${y(d.getMonth()+1)}-${y(d.getDate())}T${y(d.getHours())}:${y(d.getMinutes())}`}const z=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function ve({isOpen:v,onClose:d}){var W,$,J,V,G,X,Y,q,K,Q,Z,ee;const y=ue(),[k,te]=i.useState([]),[C,M]=i.useState("list"),[n,b]=i.useState(z()),[c,E]=i.useState(!1),[L,A]=i.useState(!1),[B,p]=i.useState(null),[D,le]=i.useState([]),[T,se]=i.useState(null),[F,ae]=i.useState(`{
2
2
 
3
- }`),[r,S]=i.useState(null),[I,N]=i.useState(!1),[P,H]=i.useState([]),g=i.useCallback(async()=>{try{const t=await f(h("/api/triggers"));if(t.ok){const s=await t.json();te(s)}}catch(t){console.error("Failed to load triggers:",t)}},[]),w=i.useCallback(async t=>{try{const s=await f(h(`/api/triggers/${t}/events?limit=20`));if(s.ok){const a=await s.json();le(a)}}catch(s){console.error("Failed to load trigger history:",s)}},[]);i.useEffect(()=>{v&&g()},[v,g]),i.useEffect(()=>{T&&w(T)},[T,w]);const ne=i.useCallback(async()=>{A(!0),p(null);try{const t=c?h(`/api/triggers/${n.id}`):h("/api/triggers"),m=await f(t,{method:c?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!m.ok){const j=await m.json();throw new Error(j.error||"Failed to save trigger")}await g(),M("list"),b(z()),F(!1)}catch(t){p(t instanceof Error?t.message:"Save failed")}finally{A(!1)}},[n,c,g]),ie=i.useCallback(async t=>{try{await f(h(`/api/triggers/${t}`),{method:"DELETE"}),await g()}catch(s){console.error("Failed to delete trigger:",s)}},[g]),re=i.useCallback(async t=>{try{await f(h(`/api/triggers/${t.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!t.enabled})}),await g()}catch(s){console.error("Failed to toggle trigger:",s)}},[g]),oe=i.useCallback(async t=>{try{await f(h(`/api/triggers/${t}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),T===t&&await w(t)}catch(s){console.error("Failed to test fire trigger:",s)}},[T,w]),de=i.useCallback(async()=>{if(n.id){N(!0),S(null);try{let t;try{t=JSON.parse(E)}catch{S({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),p("Invalid JSON payload");return}const s=await f(h(`/api/triggers/${n.id}/test-match`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:t})});if(s.ok){const a=await s.json();S(a),p(null)}else{const a=await s.json();p(a.error||"Test match failed")}}catch(t){p(t instanceof Error?t.message:"Test match failed")}finally{N(!1)}}},[n.id,E]),ce=i.useCallback(async t=>{var s;try{const a=await f(h("/api/triggers/validate-cron"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expression:t,timezone:((s=n.config)==null?void 0:s.timezone)||"UTC"})});if(a.ok){const m=await a.json();H(m.valid?m.nextFires:[])}}catch{H([])}},[n]),U=i.useCallback(t=>{t?(b({...t}),F(!0)):(b(z()),F(!1)),S(null),p(null),M("edit")},[]),o=i.useCallback((t,s)=>{b(a=>({...a,[t]:s}))},[]),x=i.useCallback((t,s)=>{b(a=>({...a,config:{...a.config,[t]:s}}))},[]),O=i.useCallback((t,s)=>{b(a=>({...a,llmMatch:{...a.llmMatch||{prompt:""},[t]:s}}))},[]),_=i.useCallback((t,s)=>{b(a=>({...a,llmExtract:{...a.llmExtract||{prompt:"",variables:[]},[t]:s}}))},[]),pe=i.useMemo(()=>Array.from(y.values()).map(t=>({id:t.id,name:t.name})),[y]);return v?e.jsx("div",{style:l.overlay,onClick:d,children:e.jsxs("div",{style:l.panel,onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{style:l.header,children:[e.jsx("h2",{style:l.title,children:C==="list"?"Triggers":c?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:l.headerActions,children:[C==="list"&&e.jsx("button",{style:l.addBtn,onClick:()=>U(),children:"+ New Trigger"}),C==="edit"&&e.jsx("button",{style:l.backBtn,onClick:()=>{M("list"),S(null),p(null)},children:"Back"}),e.jsx("button",{style:l.closeBtn,onClick:d,children:"X"})]})]}),B&&e.jsx("div",{style:l.error,children:B}),C==="list"&&e.jsx("div",{style:l.content,children:k.length===0?e.jsx("div",{style:l.empty,children:"No triggers configured. Create one to get started."}):k.map(t=>{var s;return e.jsxs("div",{style:{...l.triggerCard,borderLeftColor:t.status==="error"?"#e74c3c":t.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{se(t.id),U(t)},children:[e.jsxs("div",{style:l.cardHeader,children:[e.jsxs("div",{style:l.cardTitle,children:[e.jsx("span",{style:l.typeTag,children:t.type}),e.jsx("span",{children:t.name}),t.type==="cron"&&(()=>{const a=t.config||{};return a.runOnce?a.completedAt?e.jsx("span",{style:{...l.matchTag,color:"#a6e3a1"},children:"Once · completed"}):a.missedAt?e.jsx("span",{style:{...l.matchTag,color:"#f38ba8"},children:"Once · missed"}):e.jsx("span",{style:{...l.matchTag,color:"#f9e2af"},children:"Once · pending"}):e.jsx("span",{style:l.matchTag,children:"Recurring"})})(),t.matchMode!=="structural"&&e.jsx("span",{style:l.matchTag,children:t.matchMode})]}),e.jsxs("div",{style:l.cardActions,children:[e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),re(t)},children:t.enabled?"Disable":"Enable"}),e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),oe(t.id)},children:"Test Fire"}),e.jsx("button",{style:{...l.smallBtn,color:"#e74c3c"},onClick:a=>{a.stopPropagation(),ie(t.id)},children:"Delete"})]})]}),e.jsxs("div",{style:l.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((s=y.get(t.agentId))==null?void 0:s.name)||t.agentId]}),e.jsxs("span",{children:["Fires: ",t.fireCount]}),t.lastFiredAt&&e.jsxs("span",{children:["Last: ",new Date(t.lastFiredAt).toLocaleString()]}),t.status==="error"&&t.lastError&&e.jsxs("span",{style:{color:"#e74c3c"},children:["Error: ",t.lastError]})]})]},t.id)})}),C==="edit"&&e.jsx("div",{style:l.content,children:e.jsxs("div",{style:l.form,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Name"}),e.jsx("input",{style:l.input,value:n.name||"",onChange:t=>o("name",t.target.value),placeholder:"My Trigger"})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Description"}),e.jsx("input",{style:l.input,value:n.description||"",onChange:t=>o("description",t.target.value),placeholder:"Optional description"})]}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Type"}),e.jsx("select",{style:l.select,value:n.type||"webhook",onChange:t=>{const s=t.target.value;o("type",s),s==="webhook"?o("config",{method:"POST"}):s==="cron"?o("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):o("config",{})},children:he.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Agent"}),e.jsxs("select",{style:l.select,value:n.agentId||"",onChange:t=>o("agentId",t.target.value),children:[e.jsx("option",{value:"",children:"Select agent..."}),pe.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Prompt Template"}),e.jsx("textarea",{style:l.textarea,value:n.promptTemplate||"",onChange:t=>o("promptTemplate",t.target.value),placeholder:"Message sent to agent. Use {{variable}} for interpolation.",rows:4})]}),n.type==="webhook"&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Webhook Config"}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Method"}),e.jsxs("select",{style:l.select,value:((W=n.config)==null?void 0:W.method)||"POST",onChange:t=>x("method",t.target.value),children:[e.jsx("option",{value:"POST",children:"POST"}),e.jsx("option",{value:"PUT",children:"PUT"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Secret (HMAC)"}),e.jsx("input",{style:l.input,type:"password",value:(($=n.config)==null?void 0:$.secret)||"",onChange:t=>x("secret",t.target.value||void 0),placeholder:"Optional HMAC secret"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Extract Fields (comma-separated JSON paths)"}),e.jsx("input",{style:l.input,value:((V=(J=n.config)==null?void 0:J.extractFields)==null?void 0:V.join(", "))||"",onChange:t=>x("extractFields",t.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"body.release_name, body.version"})]}),c&&n.id&&e.jsxs("div",{style:l.webhookUrl,children:[e.jsx("label",{style:l.label,children:"Webhook URL"}),e.jsx("code",{style:l.code,children:`${window.location.origin}/api/triggers/webhook/${n.id}`})]})]}),n.type==="cron"&&(()=>{const t=n.config||{},s=!!t.runOnce,a=t.completedAt,m=t.missedAt,j=!!a;return e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Cron Config"}),e.jsxs("div",{style:l.modeSelector,children:[e.jsxs("button",{type:"button",style:{...l.modeBtn,...s?{}:l.modeBtnActive},onClick:()=>x("runOnce",!1),disabled:j,children:[e.jsx("strong",{children:"Repeats"}),e.jsx("span",{style:l.modeDesc,children:"Fires on a cron schedule"})]}),e.jsxs("button",{type:"button",style:{...l.modeBtn,...s?l.modeBtnActive:{}},onClick:()=>x("runOnce",!0),disabled:j,children:[e.jsx("strong",{children:"Run once"}),e.jsx("span",{style:l.modeDesc,children:"Fires exactly once at a specific time"})]})]}),j&&e.jsxs("div",{style:{...l.testResult,borderLeft:"3px solid #a6e3a1"},children:[e.jsx("strong",{style:{color:"#a6e3a1"},children:"Completed"}),e.jsxs("span",{style:l.llmMeta,children:["Fired at ",new Date(a).toLocaleString()]})]}),!j&&m&&e.jsxs("div",{style:{...l.testResult,borderLeft:"3px solid #f38ba8"},children:[e.jsx("strong",{style:{color:"#f38ba8"},children:"Missed"}),e.jsxs("span",{style:l.llmMeta,children:["Marked missed at ",new Date(m).toLocaleString()," (server was down at runAt)"]})]}),s?e.jsx("div",{style:l.row,children:e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Run at"}),e.jsx("input",{style:l.input,type:"datetime-local",value:me(t.runAt),onChange:u=>{const R=u.target.value;if(!R){x("runAt",void 0);return}const xe=new Date(R).toISOString();x("runAt",xe)},disabled:j}),e.jsx("span",{style:l.llmMeta,children:"Interpreted in your browser's local timezone"})]})}):e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Expression"}),e.jsx("input",{style:l.input,value:t.expression||"",onChange:u=>{x("expression",u.target.value),u.target.value&&ce(u.target.value)},placeholder:"0 9 * * MON-FRI"})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Timezone"}),e.jsx("input",{style:l.input,value:t.timezone||"UTC",onChange:u=>x("timezone",u.target.value),placeholder:"America/Mexico_City"})]})]}),!s&&P.length>0&&e.jsxs("div",{style:l.nextFires,children:[e.jsx("label",{style:l.label,children:"Next fires:"}),P.map((u,R)=>e.jsx("div",{style:l.nextFireItem,children:new Date(u).toLocaleString()},R))]})]})})(),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Match Mode"}),e.jsx("div",{style:l.modeSelector,children:ye.map(t=>e.jsxs("button",{style:{...l.modeBtn,...n.matchMode===t.value?l.modeBtnActive:{}},onClick:()=>o("matchMode",t.value),children:[e.jsx("strong",{children:t.label}),e.jsx("span",{style:l.modeDesc,children:t.desc})]},t.value))}),(n.matchMode==="llm"||n.matchMode==="hybrid")&&e.jsxs("div",{style:l.llmConfig,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"LLM Match Prompt"}),e.jsx("textarea",{style:l.textarea,value:((G=n.llmMatch)==null?void 0:G.prompt)||"",onChange:t=>O("prompt",t.target.value),placeholder:"Does this message request a release deployment?",rows:3})]}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Model"}),e.jsxs("select",{style:l.select,value:((X=n.llmMatch)==null?void 0:X.model)||"haiku",onChange:t=>O("model",t.target.value),children:[e.jsx("option",{value:"haiku",children:"Haiku (fast, cheap)"}),e.jsx("option",{value:"sonnet",children:"Sonnet (balanced)"}),e.jsx("option",{value:"opus",children:"Opus (powerful)"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Min Confidence"}),e.jsx("input",{style:l.input,type:"number",min:"0",max:"1",step:"0.1",value:((Y=n.llmMatch)==null?void 0:Y.minConfidence)??0,onChange:t=>O("minConfidence",parseFloat(t.target.value))})]})]})]})]}),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Extraction Mode"}),e.jsx("div",{style:l.row,children:ge.map(t=>e.jsx("button",{style:{...l.modeBtn,...n.extractionMode===t.value?l.modeBtnActive:{}},onClick:()=>o("extractionMode",t.value),children:t.label},t.value))}),n.extractionMode==="llm"&&e.jsxs("div",{style:l.llmConfig,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Extraction Instructions"}),e.jsx("textarea",{style:l.textarea,value:((q=n.llmExtract)==null?void 0:q.prompt)||"",onChange:t=>_("prompt",t.target.value),placeholder:"Extract: release version, affected systems, urgency",rows:3})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Variable Names (comma-separated)"}),e.jsx("input",{style:l.input,value:((Q=(K=n.llmExtract)==null?void 0:K.variables)==null?void 0:Q.join(", "))||"",onChange:t=>_("variables",t.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"release_name, affected_systems, urgency"})]})]})]}),c&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Test Match"}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Sample Event Payload (JSON)"}),e.jsx("textarea",{style:l.textarea,value:E,onChange:t=>ae(t.target.value),rows:4})]}),e.jsx("button",{style:l.testBtn,onClick:de,disabled:I,children:I?"Testing...":"Test Match"}),r&&e.jsxs("div",{style:l.testResult,children:[e.jsx("div",{style:{...l.testResultHeader,color:r.wouldFire?"#2ecc71":"#e74c3c"},children:r.wouldFire?"WOULD FIRE":"WOULD NOT FIRE"}),r.structuralMatch!==void 0&&e.jsxs("div",{children:["Structural: ",r.structuralMatch?"Match":"No match"]}),r.llmMatch&&e.jsxs("div",{style:l.llmResult,children:[e.jsxs("div",{children:["LLM: ",r.llmMatch.match?"Match":"No match"]}),e.jsxs("div",{children:["Confidence: ",(r.llmMatch.confidence*100).toFixed(0),"%"]}),e.jsxs("div",{children:["Reason: ",r.llmMatch.reason]}),e.jsxs("div",{style:l.llmMeta,children:["Model: ",r.llmMatch.model," | Tokens: ",r.llmMatch.tokensUsed," | Latency: ",r.llmMatch.durationMs,"ms"]})]}),Object.keys(r.extractedVariables).length>0&&e.jsxs("div",{children:[e.jsx("div",{style:l.label,children:"Extracted Variables:"}),Object.entries(r.extractedVariables).map(([t,s])=>e.jsxs("div",{style:l.varRow,children:[e.jsx("code",{children:t}),": ",s]},t))]})]})]}),c&&D.length>0&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Recent Fires"}),e.jsx("div",{style:l.historyList,children:D.map((t,s)=>{const a=t.llm_match_result?JSON.parse(t.llm_match_result):null;return e.jsxs("div",{style:l.historyItem,children:[e.jsxs("div",{style:l.historyHeader,children:[e.jsx("span",{style:{color:t.status==="delivered"?"#2ecc71":t.status==="failed"?"#e74c3c":"#f39c12"},children:t.status}),e.jsx("span",{children:new Date(t.fired_at).toLocaleString()}),t.duration_ms&&e.jsxs("span",{children:[t.duration_ms,"ms"]})]}),t.error&&e.jsx("div",{style:{color:"#e74c3c",fontSize:"12px"},children:t.error}),a&&e.jsxs("div",{style:l.llmMeta,children:["LLM: ",a.match?"match":"no match"," (",(a.confidence*100).toFixed(0),"%) - ",a.reason]})]},t.id||s)})})]}),e.jsxs("div",{style:l.actions,children:[e.jsx("button",{style:l.cancelBtn,onClick:()=>{M("list"),p(null)},children:"Cancel"}),e.jsx("button",{style:l.saveBtn,onClick:ne,disabled:L||!n.name||!n.agentId||n.type==="cron"&&!!((Z=n.config)!=null&&Z.runOnce)&&!((ee=n.config)!=null&&ee.runAt),children:L?"Saving...":c?"Update":"Create"})]})]})})]})}):null}const l={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},panel:{background:"#1e1e2e",borderRadius:"12px",width:"680px",maxHeight:"85vh",display:"flex",flexDirection:"column",color:"#cdd6f4",boxShadow:"0 8px 32px rgba(0,0,0,0.4)"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid #313244"},title:{margin:0,fontSize:"18px",fontWeight:600},headerActions:{display:"flex",gap:"8px"},content:{overflow:"auto",padding:"16px 20px",flex:1},empty:{textAlign:"center",padding:"40px",color:"#6c7086"},error:{background:"#45252a",color:"#f38ba8",padding:"8px 20px",fontSize:"13px"},triggerCard:{background:"#181825",borderRadius:"8px",padding:"12px 16px",marginBottom:"8px",borderLeft:"3px solid",cursor:"pointer",transition:"background 0.15s"},cardHeader:{display:"flex",justifyContent:"space-between",alignItems:"center"},cardTitle:{display:"flex",alignItems:"center",gap:"8px",fontWeight:500},typeTag:{background:"#313244",padding:"2px 6px",borderRadius:"4px",fontSize:"11px",textTransform:"uppercase"},matchTag:{background:"#45475a",padding:"2px 6px",borderRadius:"4px",fontSize:"10px",color:"#a6e3a1"},cardActions:{display:"flex",gap:"6px"},cardMeta:{display:"flex",gap:"16px",marginTop:"8px",fontSize:"12px",color:"#6c7086"},form:{display:"flex",flexDirection:"column",gap:"12px"},field:{display:"flex",flexDirection:"column",gap:"4px",flex:1},row:{display:"flex",gap:"12px"},label:{fontSize:"12px",color:"#a6adc8",fontWeight:500},input:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none"},select:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none"},textarea:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none",fontFamily:"monospace",resize:"vertical"},section:{borderTop:"1px solid #313244",paddingTop:"12px"},sectionTitle:{margin:"0 0 8px",fontSize:"14px",fontWeight:600,color:"#a6adc8"},modeSelector:{display:"flex",gap:"8px",marginBottom:"8px"},modeBtn:{flex:1,background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px",color:"#cdd6f4",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",fontSize:"12px"},modeBtnActive:{borderColor:"#89b4fa",background:"#1e3a5f"},modeDesc:{fontSize:"10px",color:"#6c7086"},llmConfig:{background:"#181825",borderRadius:"6px",padding:"12px",display:"flex",flexDirection:"column",gap:"8px"},webhookUrl:{marginTop:"8px"},code:{background:"#313244",padding:"6px 10px",borderRadius:"4px",fontSize:"12px",display:"block",wordBreak:"break-all",color:"#89b4fa"},nextFires:{marginTop:"8px"},nextFireItem:{fontSize:"12px",color:"#a6e3a1",padding:"2px 0"},testBtn:{background:"#89b4fa",border:"none",borderRadius:"6px",padding:"8px 16px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},testResult:{background:"#181825",borderRadius:"6px",padding:"12px",marginTop:"8px",fontSize:"13px",display:"flex",flexDirection:"column",gap:"6px"},testResultHeader:{fontWeight:700,fontSize:"14px"},llmResult:{display:"flex",flexDirection:"column",gap:"2px"},llmMeta:{fontSize:"11px",color:"#6c7086",marginTop:"2px"},varRow:{fontSize:"12px",padding:"2px 0"},historyList:{display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflow:"auto"},historyItem:{background:"#181825",borderRadius:"4px",padding:"8px 10px",fontSize:"12px"},historyHeader:{display:"flex",justifyContent:"space-between",alignItems:"center"},actions:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"16px",paddingTop:"12px",borderTop:"1px solid #313244"},addBtn:{background:"#89b4fa",border:"none",borderRadius:"6px",padding:"6px 14px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},backBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"6px",padding:"6px 14px",color:"#cdd6f4",cursor:"pointer",fontSize:"13px"},closeBtn:{background:"transparent",border:"none",color:"#6c7086",cursor:"pointer",fontSize:"16px",padding:"4px 8px"},smallBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"4px",padding:"3px 8px",color:"#cdd6f4",cursor:"pointer",fontSize:"11px"},saveBtn:{background:"#a6e3a1",border:"none",borderRadius:"6px",padding:"8px 20px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},cancelBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 20px",color:"#cdd6f4",cursor:"pointer",fontSize:"13px"}};export{ve as TriggerManagerPanel,ve as default};
3
+ }`),[r,S]=i.useState(null),[I,N]=i.useState(!1),[P,H]=i.useState([]),g=i.useCallback(async()=>{try{const t=await f(h("/api/triggers"));if(t.ok){const s=await t.json();te(s)}}catch(t){console.error("Failed to load triggers:",t)}},[]),w=i.useCallback(async t=>{try{const s=await f(h(`/api/triggers/${t}/events?limit=20`));if(s.ok){const a=await s.json();le(a)}}catch(s){console.error("Failed to load trigger history:",s)}},[]);i.useEffect(()=>{v&&g()},[v,g]),i.useEffect(()=>{T&&w(T)},[T,w]);const ne=i.useCallback(async()=>{A(!0),p(null);try{const t=c?h(`/api/triggers/${n.id}`):h("/api/triggers"),m=await f(t,{method:c?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!m.ok){const j=await m.json();throw new Error(j.error||"Failed to save trigger")}await g(),M("list"),b(z()),E(!1)}catch(t){p(t instanceof Error?t.message:"Save failed")}finally{A(!1)}},[n,c,g]),ie=i.useCallback(async t=>{try{await f(h(`/api/triggers/${t}`),{method:"DELETE"}),await g()}catch(s){console.error("Failed to delete trigger:",s)}},[g]),re=i.useCallback(async t=>{try{await f(h(`/api/triggers/${t.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!t.enabled})}),await g()}catch(s){console.error("Failed to toggle trigger:",s)}},[g]),oe=i.useCallback(async t=>{try{await f(h(`/api/triggers/${t}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),T===t&&await w(t)}catch(s){console.error("Failed to test fire trigger:",s)}},[T,w]),de=i.useCallback(async()=>{if(n.id){N(!0),S(null);try{let t;try{t=JSON.parse(F)}catch{S({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),p("Invalid JSON payload");return}const s=await f(h(`/api/triggers/${n.id}/test-match`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:t})});if(s.ok){const a=await s.json();S(a),p(null)}else{const a=await s.json();p(a.error||"Test match failed")}}catch(t){p(t instanceof Error?t.message:"Test match failed")}finally{N(!1)}}},[n.id,F]),ce=i.useCallback(async t=>{var s;try{const a=await f(h("/api/triggers/validate-cron"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expression:t,timezone:((s=n.config)==null?void 0:s.timezone)||"UTC"})});if(a.ok){const m=await a.json();H(m.valid?m.nextFires:[])}}catch{H([])}},[n]),U=i.useCallback(t=>{t?(b({...t}),E(!0)):(b(z()),E(!1)),S(null),p(null),M("edit")},[]),o=i.useCallback((t,s)=>{b(a=>({...a,[t]:s}))},[]),x=i.useCallback((t,s)=>{b(a=>({...a,config:{...a.config,[t]:s}}))},[]),O=i.useCallback((t,s)=>{b(a=>({...a,llmMatch:{...a.llmMatch||{prompt:""},[t]:s}}))},[]),_=i.useCallback((t,s)=>{b(a=>({...a,llmExtract:{...a.llmExtract||{prompt:"",variables:[]},[t]:s}}))},[]),pe=i.useMemo(()=>Array.from(y.values()).map(t=>({id:t.id,name:t.name})),[y]);return v?e.jsx("div",{style:l.overlay,onClick:d,children:e.jsxs("div",{style:l.panel,onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{style:l.header,children:[e.jsx("h2",{style:l.title,children:C==="list"?"Triggers":c?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:l.headerActions,children:[C==="list"&&e.jsx("button",{style:l.addBtn,onClick:()=>U(),children:"+ New Trigger"}),C==="edit"&&e.jsx("button",{style:l.backBtn,onClick:()=>{M("list"),S(null),p(null)},children:"Back"}),e.jsx("button",{style:l.closeBtn,onClick:d,children:"X"})]})]}),B&&e.jsx("div",{style:l.error,children:B}),C==="list"&&e.jsx("div",{style:l.content,children:k.length===0?e.jsx("div",{style:l.empty,children:"No triggers configured. Create one to get started."}):k.map(t=>{var s;return e.jsxs("div",{style:{...l.triggerCard,borderLeftColor:t.status==="error"?"#e74c3c":t.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{se(t.id),U(t)},children:[e.jsxs("div",{style:l.cardHeader,children:[e.jsxs("div",{style:l.cardTitle,children:[e.jsx("span",{style:l.typeTag,children:t.type}),e.jsx("span",{children:t.name}),t.type==="cron"&&(()=>{const a=t.config||{};return a.runOnce?a.completedAt?e.jsx("span",{style:{...l.matchTag,color:"#a6e3a1"},children:"Once · completed"}):a.missedAt?e.jsx("span",{style:{...l.matchTag,color:"#f38ba8"},children:"Once · missed"}):e.jsx("span",{style:{...l.matchTag,color:"#f9e2af"},children:"Once · pending"}):e.jsx("span",{style:l.matchTag,children:"Recurring"})})(),t.matchMode!=="structural"&&e.jsx("span",{style:l.matchTag,children:t.matchMode})]}),e.jsxs("div",{style:l.cardActions,children:[e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),re(t)},children:t.enabled?"Disable":"Enable"}),e.jsx("button",{style:l.smallBtn,onClick:a=>{a.stopPropagation(),oe(t.id)},children:"Test Fire"}),e.jsx("button",{style:{...l.smallBtn,color:"#e74c3c"},onClick:a=>{a.stopPropagation(),ie(t.id)},children:"Delete"})]})]}),e.jsxs("div",{style:l.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((s=y.get(t.agentId))==null?void 0:s.name)||t.agentId]}),e.jsxs("span",{children:["Fires: ",t.fireCount]}),t.lastFiredAt&&e.jsxs("span",{children:["Last: ",new Date(t.lastFiredAt).toLocaleString()]}),t.status==="error"&&t.lastError&&e.jsxs("span",{style:{color:"#e74c3c"},children:["Error: ",t.lastError]})]})]},t.id)})}),C==="edit"&&e.jsx("div",{style:l.content,children:e.jsxs("div",{style:l.form,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Name"}),e.jsx("input",{style:l.input,value:n.name||"",onChange:t=>o("name",t.target.value),placeholder:"My Trigger"})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Description"}),e.jsx("input",{style:l.input,value:n.description||"",onChange:t=>o("description",t.target.value),placeholder:"Optional description"})]}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Type"}),e.jsx("select",{style:l.select,value:n.type||"webhook",onChange:t=>{const s=t.target.value;o("type",s),s==="webhook"?o("config",{method:"POST"}):s==="cron"?o("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):o("config",{})},children:he.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Agent"}),e.jsxs("select",{style:l.select,value:n.agentId||"",onChange:t=>o("agentId",t.target.value),children:[e.jsx("option",{value:"",children:"Select agent..."}),pe.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Prompt Template"}),e.jsx("textarea",{style:l.textarea,value:n.promptTemplate||"",onChange:t=>o("promptTemplate",t.target.value),placeholder:"Message sent to agent. Use {{variable}} for interpolation.",rows:4})]}),n.type==="webhook"&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Webhook Config"}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Method"}),e.jsxs("select",{style:l.select,value:((W=n.config)==null?void 0:W.method)||"POST",onChange:t=>x("method",t.target.value),children:[e.jsx("option",{value:"POST",children:"POST"}),e.jsx("option",{value:"PUT",children:"PUT"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Secret (HMAC)"}),e.jsx("input",{style:l.input,type:"password",value:(($=n.config)==null?void 0:$.secret)||"",onChange:t=>x("secret",t.target.value||void 0),placeholder:"Optional HMAC secret"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Extract Fields (comma-separated JSON paths)"}),e.jsx("input",{style:l.input,value:((V=(J=n.config)==null?void 0:J.extractFields)==null?void 0:V.join(", "))||"",onChange:t=>x("extractFields",t.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"body.release_name, body.version"})]}),c&&n.id&&e.jsxs("div",{style:l.webhookUrl,children:[e.jsx("label",{style:l.label,children:"Webhook URL"}),e.jsx("code",{style:l.code,children:`${window.location.origin}/api/triggers/webhook/${n.id}`})]})]}),n.type==="cron"&&(()=>{const t=n.config||{},s=!!t.runOnce,a=t.completedAt,m=t.missedAt,j=!!a;return e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Cron Config"}),e.jsxs("div",{style:l.modeSelector,children:[e.jsxs("button",{type:"button",style:{...l.modeBtn,...s?{}:l.modeBtnActive},onClick:()=>x("runOnce",!1),disabled:j,children:[e.jsx("strong",{children:"Repeats"}),e.jsx("span",{style:l.modeDesc,children:"Fires on a cron schedule"})]}),e.jsxs("button",{type:"button",style:{...l.modeBtn,...s?l.modeBtnActive:{}},onClick:()=>x("runOnce",!0),disabled:j,children:[e.jsx("strong",{children:"Run once"}),e.jsx("span",{style:l.modeDesc,children:"Fires exactly once at a specific time"})]})]}),j&&e.jsxs("div",{style:{...l.testResult,borderLeft:"3px solid #a6e3a1"},children:[e.jsx("strong",{style:{color:"#a6e3a1"},children:"Completed"}),e.jsxs("span",{style:l.llmMeta,children:["Fired at ",new Date(a).toLocaleString()]})]}),!j&&m&&e.jsxs("div",{style:{...l.testResult,borderLeft:"3px solid #f38ba8"},children:[e.jsx("strong",{style:{color:"#f38ba8"},children:"Missed"}),e.jsxs("span",{style:l.llmMeta,children:["Marked missed at ",new Date(m).toLocaleString()," (server was down at runAt)"]})]}),s?e.jsx("div",{style:l.row,children:e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Run at"}),e.jsx("input",{style:l.input,type:"datetime-local",value:me(t.runAt),onChange:u=>{const R=u.target.value;if(!R){x("runAt",void 0);return}const xe=new Date(R).toISOString();x("runAt",xe)},disabled:j}),e.jsx("span",{style:l.llmMeta,children:"Interpreted in your browser's local timezone"})]})}):e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Expression"}),e.jsx("input",{style:l.input,value:t.expression||"",onChange:u=>{x("expression",u.target.value),u.target.value&&ce(u.target.value)},placeholder:"0 9 * * MON-FRI"})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Timezone"}),e.jsx("input",{style:l.input,value:t.timezone||"UTC",onChange:u=>x("timezone",u.target.value),placeholder:"America/Mexico_City"})]})]}),!s&&P.length>0&&e.jsxs("div",{style:l.nextFires,children:[e.jsx("label",{style:l.label,children:"Next fires:"}),P.map((u,R)=>e.jsx("div",{style:l.nextFireItem,children:new Date(u).toLocaleString()},R))]})]})})(),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Match Mode"}),e.jsx("div",{style:l.modeSelector,children:ye.map(t=>e.jsxs("button",{style:{...l.modeBtn,...n.matchMode===t.value?l.modeBtnActive:{}},onClick:()=>o("matchMode",t.value),children:[e.jsx("strong",{children:t.label}),e.jsx("span",{style:l.modeDesc,children:t.desc})]},t.value))}),(n.matchMode==="llm"||n.matchMode==="hybrid")&&e.jsxs("div",{style:l.llmConfig,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"LLM Match Prompt"}),e.jsx("textarea",{style:l.textarea,value:((G=n.llmMatch)==null?void 0:G.prompt)||"",onChange:t=>O("prompt",t.target.value),placeholder:"Does this message request a release deployment?",rows:3})]}),e.jsxs("div",{style:l.row,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Model"}),e.jsxs("select",{style:l.select,value:((X=n.llmMatch)==null?void 0:X.model)||"haiku",onChange:t=>O("model",t.target.value),children:[e.jsx("option",{value:"haiku",children:"Haiku (fast, cheap)"}),e.jsx("option",{value:"sonnet",children:"Sonnet (balanced)"}),e.jsx("option",{value:"opus",children:"Opus (powerful)"})]})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Min Confidence"}),e.jsx("input",{style:l.input,type:"number",min:"0",max:"1",step:"0.1",value:((Y=n.llmMatch)==null?void 0:Y.minConfidence)??0,onChange:t=>O("minConfidence",parseFloat(t.target.value))})]})]})]})]}),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Extraction Mode"}),e.jsx("div",{style:l.row,children:ge.map(t=>e.jsx("button",{style:{...l.modeBtn,...n.extractionMode===t.value?l.modeBtnActive:{}},onClick:()=>o("extractionMode",t.value),children:t.label},t.value))}),n.extractionMode==="llm"&&e.jsxs("div",{style:l.llmConfig,children:[e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Extraction Instructions"}),e.jsx("textarea",{style:l.textarea,value:((q=n.llmExtract)==null?void 0:q.prompt)||"",onChange:t=>_("prompt",t.target.value),placeholder:"Extract: release version, affected systems, urgency",rows:3})]}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Variable Names (comma-separated)"}),e.jsx("input",{style:l.input,value:((Q=(K=n.llmExtract)==null?void 0:K.variables)==null?void 0:Q.join(", "))||"",onChange:t=>_("variables",t.target.value.split(",").map(s=>s.trim()).filter(Boolean)),placeholder:"release_name, affected_systems, urgency"})]})]})]}),c&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Test Match"}),e.jsxs("div",{style:l.field,children:[e.jsx("label",{style:l.label,children:"Sample Event Payload (JSON)"}),e.jsx("textarea",{style:l.textarea,value:F,onChange:t=>ae(t.target.value),rows:4})]}),e.jsx("button",{style:l.testBtn,onClick:de,disabled:I,children:I?"Testing...":"Test Match"}),r&&e.jsxs("div",{style:l.testResult,children:[e.jsx("div",{style:{...l.testResultHeader,color:r.wouldFire?"#2ecc71":"#e74c3c"},children:r.wouldFire?"WOULD FIRE":"WOULD NOT FIRE"}),r.structuralMatch!==void 0&&e.jsxs("div",{children:["Structural: ",r.structuralMatch?"Match":"No match"]}),r.llmMatch&&e.jsxs("div",{style:l.llmResult,children:[e.jsxs("div",{children:["LLM: ",r.llmMatch.match?"Match":"No match"]}),e.jsxs("div",{children:["Confidence: ",(r.llmMatch.confidence*100).toFixed(0),"%"]}),e.jsxs("div",{children:["Reason: ",r.llmMatch.reason]}),e.jsxs("div",{style:l.llmMeta,children:["Model: ",r.llmMatch.model," | Tokens: ",r.llmMatch.tokensUsed," | Latency: ",r.llmMatch.durationMs,"ms"]})]}),Object.keys(r.extractedVariables).length>0&&e.jsxs("div",{children:[e.jsx("div",{style:l.label,children:"Extracted Variables:"}),Object.entries(r.extractedVariables).map(([t,s])=>e.jsxs("div",{style:l.varRow,children:[e.jsx("code",{children:t}),": ",s]},t))]})]})]}),c&&D.length>0&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Recent Fires"}),e.jsx("div",{style:l.historyList,children:D.map((t,s)=>{const a=t.llm_match_result?JSON.parse(t.llm_match_result):null;return e.jsxs("div",{style:l.historyItem,children:[e.jsxs("div",{style:l.historyHeader,children:[e.jsx("span",{style:{color:t.status==="delivered"?"#2ecc71":t.status==="failed"?"#e74c3c":"#f39c12"},children:t.status}),e.jsx("span",{children:new Date(t.fired_at).toLocaleString()}),t.duration_ms&&e.jsxs("span",{children:[t.duration_ms,"ms"]})]}),t.error&&e.jsx("div",{style:{color:"#e74c3c",fontSize:"12px"},children:t.error}),a&&e.jsxs("div",{style:l.llmMeta,children:["LLM: ",a.match?"match":"no match"," (",(a.confidence*100).toFixed(0),"%) - ",a.reason]})]},t.id||s)})})]}),e.jsxs("div",{style:l.actions,children:[e.jsx("button",{style:l.cancelBtn,onClick:()=>{M("list"),p(null)},children:"Cancel"}),e.jsx("button",{style:l.saveBtn,onClick:ne,disabled:L||!n.name||!n.agentId||n.type==="cron"&&!!((Z=n.config)!=null&&Z.runOnce)&&!((ee=n.config)!=null&&ee.runAt),children:L?"Saving...":c?"Update":"Create"})]})]})})]})}):null}const l={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},panel:{background:"#1e1e2e",borderRadius:"12px",width:"680px",maxHeight:"85vh",display:"flex",flexDirection:"column",color:"#cdd6f4",boxShadow:"0 8px 32px rgba(0,0,0,0.4)"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid #313244"},title:{margin:0,fontSize:"18px",fontWeight:600},headerActions:{display:"flex",gap:"8px"},content:{overflow:"auto",padding:"16px 20px",flex:1},empty:{textAlign:"center",padding:"40px",color:"#6c7086"},error:{background:"#45252a",color:"#f38ba8",padding:"8px 20px",fontSize:"13px"},triggerCard:{background:"#181825",borderRadius:"8px",padding:"12px 16px",marginBottom:"8px",borderLeft:"3px solid",cursor:"pointer",transition:"background 0.15s"},cardHeader:{display:"flex",justifyContent:"space-between",alignItems:"center"},cardTitle:{display:"flex",alignItems:"center",gap:"8px",fontWeight:500},typeTag:{background:"#313244",padding:"2px 6px",borderRadius:"4px",fontSize:"11px",textTransform:"uppercase"},matchTag:{background:"#45475a",padding:"2px 6px",borderRadius:"4px",fontSize:"10px",color:"#a6e3a1"},cardActions:{display:"flex",gap:"6px"},cardMeta:{display:"flex",gap:"16px",marginTop:"8px",fontSize:"12px",color:"#6c7086"},form:{display:"flex",flexDirection:"column",gap:"12px"},field:{display:"flex",flexDirection:"column",gap:"4px",flex:1},row:{display:"flex",gap:"12px"},label:{fontSize:"12px",color:"#a6adc8",fontWeight:500},input:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none"},select:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none"},textarea:{background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 10px",color:"#cdd6f4",fontSize:"13px",outline:"none",fontFamily:"monospace",resize:"vertical"},section:{borderTop:"1px solid #313244",paddingTop:"12px"},sectionTitle:{margin:"0 0 8px",fontSize:"14px",fontWeight:600,color:"#a6adc8"},modeSelector:{display:"flex",gap:"8px",marginBottom:"8px"},modeBtn:{flex:1,background:"#313244",border:"1px solid #45475a",borderRadius:"6px",padding:"8px",color:"#cdd6f4",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",fontSize:"12px"},modeBtnActive:{borderColor:"#89b4fa",background:"#1e3a5f"},modeDesc:{fontSize:"10px",color:"#6c7086"},llmConfig:{background:"#181825",borderRadius:"6px",padding:"12px",display:"flex",flexDirection:"column",gap:"8px"},webhookUrl:{marginTop:"8px"},code:{background:"#313244",padding:"6px 10px",borderRadius:"4px",fontSize:"12px",display:"block",wordBreak:"break-all",color:"#89b4fa"},nextFires:{marginTop:"8px"},nextFireItem:{fontSize:"12px",color:"#a6e3a1",padding:"2px 0"},testBtn:{background:"#89b4fa",border:"none",borderRadius:"6px",padding:"8px 16px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},testResult:{background:"#181825",borderRadius:"6px",padding:"12px",marginTop:"8px",fontSize:"13px",display:"flex",flexDirection:"column",gap:"6px"},testResultHeader:{fontWeight:700,fontSize:"14px"},llmResult:{display:"flex",flexDirection:"column",gap:"2px"},llmMeta:{fontSize:"11px",color:"#6c7086",marginTop:"2px"},varRow:{fontSize:"12px",padding:"2px 0"},historyList:{display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflow:"auto"},historyItem:{background:"#181825",borderRadius:"4px",padding:"8px 10px",fontSize:"12px"},historyHeader:{display:"flex",justifyContent:"space-between",alignItems:"center"},actions:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"16px",paddingTop:"12px",borderTop:"1px solid #313244"},addBtn:{background:"#89b4fa",border:"none",borderRadius:"6px",padding:"6px 14px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},backBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"6px",padding:"6px 14px",color:"#cdd6f4",cursor:"pointer",fontSize:"13px"},closeBtn:{background:"transparent",border:"none",color:"#6c7086",cursor:"pointer",fontSize:"16px",padding:"4px 8px"},smallBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"4px",padding:"3px 8px",color:"#cdd6f4",cursor:"pointer",fontSize:"11px"},saveBtn:{background:"#a6e3a1",border:"none",borderRadius:"6px",padding:"8px 20px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:"13px"},cancelBtn:{background:"transparent",border:"1px solid #45475a",borderRadius:"6px",padding:"8px 20px",color:"#cdd6f4",cursor:"pointer",fontSize:"13px"}};export{ve as TriggerManagerPanel,ve as default};
@@ -1,4 +1,4 @@
1
- import{r as x,aF as M,l as P,j as e,ad as J}from"./main-BlnQCHb9.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const H=[{id:"intake",name:"Intake",type:"action",description:"Gather CC details from the developer via Slack",action:{type:"agent_task",agentId:"",promptTemplate:`A developer has requested a new CC (Control de Cambios). Here is their message:
1
+ import{r as x,aH as M,l as P,j as e,af as J}from"./main-DFVcOIIz.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const H=[{id:"intake",name:"Intake",type:"action",description:"Gather CC details from the developer via Slack",action:{type:"agent_task",agentId:"",promptTemplate:`A developer has requested a new CC (Control de Cambios). Here is their message:
2
2
  {{trigger.slack.message}}
3
3
  From: {{trigger.slack.user}} (Slack ID: {{trigger.slack.userId}})
4
4
 
@@ -39,4 +39,4 @@ Send a Slack reminder and ask {{requester_name}} to confirm they are ready.
39
39
  Wait for their confirmation reply.`,skills:["slack-messaging"]},transitions:[{id:"t-confirmed",name:"Dev Confirmed",targetStateId:"release-started",condition:{type:"agent_complete"}}],position:{x:100,y:960}},{id:"release-started",name:"Release Started",type:"action",description:"Announce release start via email, Slack, and Jira",action:{type:"agent_task",agentId:"",promptTemplate:`The developer has confirmed ready.
40
40
  1. Reply in approval email thread: release is starting now.
41
41
  2. Send Slack message confirming release started.
42
- 3. Update Jira ticket status to "In Progress" or "Done".`,skills:["email-gmail","slack-messaging","jira-service-desk"]},transitions:[{id:"t-done",name:"Release Complete",targetStateId:"end",condition:{type:"agent_complete"}}],position:{x:100,y:1060}},{id:"end",name:"End",type:"end",description:"CC process complete",transitions:[],position:{x:100,y:1160}}],Y=[{name:"requester_name",type:"string",description:"Developer requesting the release",required:!0},{name:"requester_email",type:"email",description:"Requester email",required:!0},{name:"requester_slack_id",type:"string",description:"Requester Slack user ID"},{name:"release_name",type:"string",description:"Release version/name",required:!0},{name:"release_description",type:"string",description:"What is being released"},{name:"affected_systems",type:"string",description:"Systems impacted"},{name:"release_date",type:"date",description:"Scheduled release date",required:!0},{name:"release_time",type:"string",description:"Scheduled release time",required:!0},{name:"is_urgent",type:"boolean",description:"Whether this is an urgent release"},{name:"additional_attendees",type:"string",description:"Other people to invite (comma-separated emails)"},{name:"jira_ticket_key",type:"string",description:"Jira ticket key (e.g. SD-1234)"},{name:"jira_ticket_url",type:"string",description:"Full Jira ticket URL"},{name:"cc_file_path",type:"string",description:"Path to generated CC document"},{name:"email_thread_id",type:"string",description:"Gmail thread ID for approval chain"},{name:"calendar_event_id",type:"string",description:"Google Calendar event ID"},{name:"approval_status",type:"json",description:"Current approval status"}],G=200,N=60,B=20,V={action:"#89b4fa",decision:"#f9e2af",wait:"#cba6f7",end:"#a6e3a1"},E={action:"Action",decision:"Decision",wait:"Wait",end:"End"},X={agent_complete:"Agent Complete",trigger_fired:"Trigger Fired",variable_check:"Variable Check",timeout:"Timeout",manual:"Manual",cron:"Cron"};function re({isOpen:n,onClose:g}){const[v,r]=x.useState([]),[l,y]=x.useState(null),[p,s]=x.useState("list"),[i,u]=x.useState(!0),[c,b]=x.useState(null),T=x.useCallback(async()=>{u(!0);try{const o=await M(P("/api/workflows/definitions"));o.ok&&r(await o.json())}catch{b("Failed to load workflows")}finally{u(!1)}},[]);x.useEffect(()=>{n&&T()},[n,T]);const R=()=>{const o={id:`wf-${Date.now()}`,name:"New Workflow",description:"",version:1,variables:[],states:[{id:"start",name:"Start",type:"action",transitions:[],position:{x:300,y:60}},{id:"end",name:"End",type:"end",transitions:[],position:{x:300,y:260}}],initialStateId:"start",createdAt:Date.now(),updatedAt:Date.now()};y(o),s("editor")},D=()=>{const o={id:`wf-cc-${Date.now()}`,name:"CC (Control de Cambios)",description:"Full CC process: intake, Jira ticket, document, approval, release",version:1,variables:[...Y],states:H.map(m=>({...m,transitions:[...m.transitions]})),initialStateId:"intake",createdAt:Date.now(),updatedAt:Date.now()};y(o),s("editor")},d=async o=>{try{v.find(I=>I.id===o.id)?await M(P(`/api/workflows/definitions/${o.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}):await M(P("/api/workflows/definitions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}),await T()}catch{b("Failed to save workflow")}};return n?e.jsx("div",{style:t.overlay,children:e.jsxs("div",{style:t.panel,children:[e.jsxs("div",{style:t.header,children:[e.jsx("h2",{style:t.title,children:p==="list"?"Workflow Definitions":(l==null?void 0:l.name)||"Editor"}),e.jsxs("div",{style:{display:"flex",gap:8},children:[p==="editor"&&e.jsx("button",{style:t.btnSecondary,onClick:()=>s("list"),children:"Back to List"}),e.jsx("button",{style:t.btnClose,onClick:g,children:"Close"})]})]}),p==="list"&&e.jsx(K,{workflows:v,loading:i,error:c,onSelect:o=>{y(o),s("editor")},onCreate:R,onLoadCC:D}),p==="editor"&&l&&e.jsx(Q,{workflow:l,onChange:y,onSave:d})]})}):null}function K({workflows:n,loading:g,error:v,onSelect:r,onCreate:l,onLoadCC:y}){return e.jsxs("div",{style:t.content,children:[e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:16},children:[e.jsx("button",{style:t.btnPrimary,onClick:l,children:"New Workflow"}),e.jsx("button",{style:t.btnSecondary,onClick:y,children:"Load CC Template"})]}),g&&e.jsx("div",{style:{color:"#a6adc8"},children:"Loading..."}),v&&e.jsx("div",{style:{color:"#f38ba8"},children:v}),n.map(p=>e.jsxs("div",{style:t.card,onClick:()=>r(p),children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{style:{color:"#cdd6f4",fontWeight:600,fontSize:14},children:p.name}),e.jsxs("span",{style:{color:"#a6adc8",fontSize:11},children:["v",p.version," | ",p.states.length," states"]})]}),p.description&&e.jsx("div",{style:{color:"#a6adc8",fontSize:12,marginTop:4},children:p.description})]},p.id)),!g&&n.length===0&&e.jsx("div",{style:{color:"#6c7086",textAlign:"center",padding:40},children:"No workflows yet. Create one or load the CC template."})]})}function Q({workflow:n,onChange:g,onSave:v}){const[r,l]=x.useState(null),[y,p]=x.useState(null),[s,i]=x.useState("none"),[u,c]=x.useState(null),[b,T]=x.useState(!1),R=x.useRef(null),D=x.useRef(n);D.current=n;const d=J(),o=x.useMemo(()=>Array.from(d.values()).map(a=>({id:a.id,name:a.name})),[d]),m=n.states.find(a=>a.id===r),I=x.useCallback(()=>{for(const a of n.states){const f=a.transitions.find(h=>h.id===y);if(f)return{state:a,transition:f}}return null},[n,y]),C=a=>{g({...n,states:a,updatedAt:Date.now()})},k=(a,f)=>{C(n.states.map(h=>h.id===a?{...h,...f}:h))},_=a=>{const f=`state-${Date.now()}`,h={id:f,name:`New ${E[a]}`,type:a,transitions:[],position:{x:300,y:n.states.length*100+60}};C([...n.states,h]),l(f),i("state")},S=a=>{const f=n.states.filter(h=>h.id!==a).map(h=>({...h,transitions:h.transitions.filter(j=>j.targetStateId!==a)}));C(f),l(null),i("none")},w=(a,f)=>{const h=`t-${Date.now()}`;C(n.states.map(j=>j.id!==a?j:{...j,transitions:[...j.transitions,{id:h,name:"New Transition",targetStateId:f,condition:{type:"agent_complete"}}]})),p(h),i("transition")},L=(a,f,h)=>{C(n.states.map(j=>j.id!==a?j:{...j,transitions:j.transitions.map(W=>W.id===f?{...W,...h}:W)}))},A=(a,f)=>{C(n.states.map(h=>h.id!==a?h:{...h,transitions:h.transitions.filter(j=>j.id!==f)})),p(null),i("none")},q=x.useCallback((a,f,h)=>{const j=D.current,W=j.states.map(z=>{if(z.id!==a)return z;const $=z.position||{x:0,y:0};return{...z,position:{x:Math.round(($.x+f)/B)*B,y:Math.round(($.y+h)/B)*B}}});g({...j,states:W,updatedAt:Date.now()})},[g]),F=a=>{u?(u!==a&&w(u,a),c(null)):(l(a),p(null),i("state"))},O=async()=>{T(!0);try{await v(n)}finally{T(!1)}};return e.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[e.jsxs("div",{style:t.toolbar,children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{color:"#a6adc8",fontSize:10,textTransform:"uppercase",marginBottom:6,letterSpacing:1},children:"Add State"}),["action","decision","wait","end"].map(a=>e.jsx("button",{style:{...t.toolBtn,borderLeft:`3px solid ${V[a]}`},onClick:()=>_(a),children:E[a]},a))]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{color:"#a6adc8",fontSize:10,textTransform:"uppercase",marginBottom:6,letterSpacing:1},children:"Tools"}),e.jsx("button",{style:{...t.toolBtn,background:u?"#45475a":"transparent"},onClick:()=>c(u?null:r||null),title:"Click a source state, then click a target state",children:u?"Drawing... (click target)":"Draw Transition"})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{color:"#a6adc8",fontSize:10,textTransform:"uppercase",marginBottom:6,letterSpacing:1},children:"Panels"}),e.jsxs("button",{style:t.toolBtn,onClick:()=>i(s==="variables"?"none":"variables"),children:["Variables (",n.variables.length,")"]}),e.jsx("button",{style:t.toolBtn,onClick:()=>i(s==="settings"?"none":"settings"),children:"Settings"})]}),e.jsx("div",{style:{marginTop:"auto"},children:e.jsx("button",{style:t.btnPrimary,onClick:O,disabled:b,children:b?"Saving...":"Save"})})]}),e.jsx("div",{style:t.canvas,ref:R,children:e.jsx(Z,{states:n.states,initialStateId:n.initialStateId,selectedStateId:r,drawingFrom:u,onStateClick:F,onStateDrag:q,onTransitionClick:a=>{p(a),i("transition")},selectedTransitionId:y})}),s!=="none"&&e.jsxs("div",{style:t.sidePanel,children:[s==="state"&&m&&e.jsx(U,{state:m,agents:o,isInitial:n.initialStateId===m.id,onUpdate:a=>k(m.id,a),onDelete:()=>S(m.id),onSetInitial:()=>g({...n,initialStateId:m.id}),onStartDrawing:()=>c(m.id),onClose:()=>i("none")}),s==="transition"&&y&&(()=>{const a=I();return a?e.jsx(ee,{transition:a.transition,parentState:a.state,allStates:n.states,variables:n.variables,onUpdate:f=>L(a.state.id,a.transition.id,f),onDelete:()=>A(a.state.id,a.transition.id),onClose:()=>i("none")}):null})(),s==="variables"&&e.jsx(te,{variables:n.variables,onChange:a=>g({...n,variables:a}),onClose:()=>i("none")}),s==="settings"&&e.jsx(ie,{workflow:n,onChange:g,onClose:()=>i("none")})]})]})}function Z({states:n,initialStateId:g,selectedStateId:v,drawingFrom:r,onStateClick:l,onStateDrag:y,onTransitionClick:p,selectedTransitionId:s}){const i=x.useRef(y);i.current=y;const u=x.useRef(!1),c=(d,o)=>{if(d.button!==0)return;d.stopPropagation();const m=d.currentTarget,I=d.clientX,C=d.clientY;let k=0,_=0,S=!1;const w=A=>{k=A.clientX-I,_=A.clientY-C,!S&&(Math.abs(k)>3||Math.abs(_)>3)&&(S=!0,m.style.zIndex="100",m.style.cursor="grabbing"),S&&(m.style.transform=`translate(${k}px, ${_}px)`)},L=()=>{window.removeEventListener("mousemove",w),window.removeEventListener("mouseup",L),m.style.transform="",m.style.zIndex="",m.style.cursor="",S&&(u.current=!0,i.current(o,k,_))};window.addEventListener("mousemove",w),window.addEventListener("mouseup",L)},b=(d,o)=>{if(d.stopPropagation(),u.current){u.current=!1;return}l(o)},T=Math.max(...n.map(d=>{var o;return(((o=d.position)==null?void 0:o.x)??0)+G}),600)+100,R=Math.max(...n.map(d=>{var o;return(((o=d.position)==null?void 0:o.y)??0)+N}),400)+100,D=d=>{var o;return(((o=d.position)==null?void 0:o.x)??0)+G/2};return e.jsxs("div",{style:{position:"relative",width:T,height:R,minWidth:"100%",minHeight:"100%"},children:[e.jsxs("svg",{style:{position:"absolute",top:0,left:0,width:T,height:R,pointerEvents:"none"},children:[e.jsxs("defs",{children:[e.jsx("marker",{id:"arrow",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#6c7086"})}),e.jsx("marker",{id:"arrow-selected",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#89b4fa"})})]}),n.flatMap(d=>d.transitions.map(o=>{var L,A;const m=n.find(q=>q.id===o.targetStateId);if(!m)return null;const I=D(d),C=(((L=d.position)==null?void 0:L.y)??0)+N,k=D(m),_=((A=m.position)==null?void 0:A.y)??0,S=o.id===s,w=(C+_)/2;return e.jsxs("g",{style:{pointerEvents:"stroke",cursor:"pointer"},onClick:()=>p(o.id),children:[e.jsx("path",{d:`M ${I} ${C} C ${I} ${w}, ${k} ${w}, ${k} ${_}`,fill:"none",stroke:S?"#89b4fa":"#6c7086",strokeWidth:S?2.5:1.5,markerEnd:`url(#${S?"arrow-selected":"arrow"})`}),e.jsx("text",{x:(I+k)/2+8,y:w,fill:S?"#89b4fa":"#6c7086",fontSize:10,dominantBaseline:"middle",children:o.name})]},o.id)}))]}),n.map(d=>{var k,_;const o=d.id===v,m=d.id===g,I=r&&r!==d.id,C=V[d.type];return e.jsxs("div",{style:{position:"absolute",left:((k=d.position)==null?void 0:k.x)??0,top:((_=d.position)==null?void 0:_.y)??0,width:G,height:N,borderRadius:d.type==="decision"?8:d.type==="end"?30:8,background:o?"rgba(137,180,250,0.12)":"#313244",border:`2px solid ${o?"#89b4fa":I?"#a6e3a1":C}`,cursor:r?"crosshair":"grab",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",userSelect:"none",boxShadow:o?"0 0 12px rgba(137,180,250,0.2)":"none",transition:"box-shadow 0.15s"},onMouseDown:S=>c(S,d.id),onClick:S=>b(S,d.id),children:[m&&e.jsx("div",{style:{position:"absolute",top:-8,left:8,fontSize:9,color:"#a6e3a1",fontWeight:600,background:"#1e1e2e",padding:"0 4px",borderRadius:3},children:"START"}),e.jsx("div",{style:{color:C,fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:E[d.type]}),e.jsx("div",{style:{color:"#cdd6f4",fontSize:12,fontWeight:600,textAlign:"center",padding:"0 8px",overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",maxWidth:G-16},children:d.name})]},d.id)})]})}function U({state:n,agents:g,isInitial:v,onUpdate:r,onDelete:l,onSetInitial:y,onStartDrawing:p,onClose:s}){const i=n.action,u=c=>{r({action:{...i,...c}})};return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsxs("span",{style:{color:V[n.type],fontWeight:600},children:[E[n.type]," State"]}),e.jsx("button",{style:t.btnClose,onClick:s,children:"x"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Name"}),e.jsx("input",{style:t.fieldInput,value:n.name,onChange:c=>r({name:c.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Description"}),e.jsx("textarea",{style:{...t.fieldInput,height:60,resize:"vertical"},value:n.description||"",onChange:c=>r({description:c.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Type"}),e.jsx("select",{style:t.fieldInput,value:n.type,onChange:c=>r({type:c.target.value}),children:Object.entries(E).map(([c,b])=>e.jsx("option",{value:c,children:b},c))})]}),n.type!=="end"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{...t.fieldLabel,marginTop:12,marginBottom:8,fontSize:11,color:"#a6adc8",textTransform:"uppercase",letterSpacing:1},children:"Action"}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Action Type"}),e.jsxs("select",{style:t.fieldInput,value:(i==null?void 0:i.type)||"agent_task",onChange:c=>{const b=c.target.value;b==="agent_task"?r({action:{type:"agent_task",agentId:"",promptTemplate:"",skills:[]}}):b==="wait_for_trigger"?r({action:{type:"wait_for_trigger",timeoutMs:36e5}}):b==="set_variables"?r({action:{type:"set_variables",assignments:{}}}):b==="trigger_setup"&&r({action:{type:"trigger_setup",triggerConfig:{}}})},children:[e.jsx("option",{value:"agent_task",children:"Agent Task"}),e.jsx("option",{value:"wait_for_trigger",children:"Wait for Trigger"}),e.jsx("option",{value:"set_variables",children:"Set Variables"}),e.jsx("option",{value:"trigger_setup",children:"Trigger Setup"})]})]}),(i==null?void 0:i.type)==="agent_task"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Agent"}),e.jsxs("select",{style:t.fieldInput,value:i.agentId,onChange:c=>u({agentId:c.target.value}),children:[e.jsx("option",{value:"",children:"Select agent..."}),g.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Prompt Template"}),e.jsx("textarea",{style:{...t.fieldInput,height:120,fontFamily:"monospace",fontSize:11,resize:"vertical"},value:i.promptTemplate,onChange:c=>u({promptTemplate:c.target.value}),placeholder:"Use {{variable}} for interpolation"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Skills (comma-separated)"}),e.jsx("input",{style:t.fieldInput,value:(i.skills||[]).join(", "),onChange:c=>u({skills:c.target.value.split(",").map(b=>b.trim()).filter(Boolean)}),placeholder:"slack-messaging, jira-service-desk"})]})]}),(i==null?void 0:i.type)==="wait_for_trigger"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Timeout (ms)"}),e.jsx("input",{type:"number",style:t.fieldInput,value:i.timeoutMs||"",onChange:c=>u({timeoutMs:c.target.value?Number(c.target.value):void 0})})]}),(i==null?void 0:i.type)==="set_variables"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Assignments (JSON)"}),e.jsx("textarea",{style:{...t.fieldInput,height:80,fontFamily:"monospace",fontSize:11},value:JSON.stringify(i.assignments||{},null,2),onChange:c=>{try{u({assignments:JSON.parse(c.target.value)})}catch{}}})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16,flexWrap:"wrap"},children:[!v&&e.jsx("button",{style:t.btnSecondary,onClick:y,children:"Set as Start"}),e.jsx("button",{style:t.btnSecondary,onClick:p,children:"Add Transition From Here"}),n.type!=="end"&&!v&&e.jsx("button",{style:{...t.btnSecondary,color:"#f38ba8",borderColor:"#f38ba8"},onClick:l,children:"Delete"})]})]})}function ee({transition:n,parentState:g,allStates:v,variables:r,onUpdate:l,onDelete:y,onClose:p}){const s=n.condition;return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsx("span",{style:{color:"#89b4fa",fontWeight:600},children:"Transition"}),e.jsx("button",{style:t.btnClose,onClick:p,children:"x"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Name"}),e.jsx("input",{style:t.fieldInput,value:n.name,onChange:i=>l({name:i.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"From"}),e.jsx("div",{style:{color:"#cdd6f4",fontSize:12,padding:"6px 0"},children:g.name})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Target State"}),e.jsx("select",{style:t.fieldInput,value:n.targetStateId,onChange:i=>l({targetStateId:i.target.value}),children:v.filter(i=>i.id!==g.id).map(i=>e.jsx("option",{value:i.id,children:i.name},i.id))})]}),e.jsx("div",{style:{...t.fieldLabel,marginTop:12,marginBottom:8,fontSize:11,color:"#a6adc8",textTransform:"uppercase",letterSpacing:1},children:"Condition"}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Condition Type"}),e.jsx("select",{style:t.fieldInput,value:s.type,onChange:i=>{const u=i.target.value;u==="agent_complete"?l({condition:{type:"agent_complete"}}):u==="trigger_fired"?l({condition:{type:"trigger_fired"}}):u==="variable_check"?l({condition:{type:"variable_check",variable:"",operator:"equals",value:""}}):u==="timeout"?l({condition:{type:"timeout",afterMs:36e5}}):u==="manual"?l({condition:{type:"manual"}}):u==="cron"&&l({condition:{type:"cron",expression:"* * * * *"}})},children:Object.entries(X).map(([i,u])=>e.jsx("option",{value:i,children:u},i))})]}),s.type==="variable_check"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Variable"}),e.jsxs("select",{style:t.fieldInput,value:s.variable,onChange:i=>l({condition:{...s,variable:i.target.value}}),children:[e.jsx("option",{value:"",children:"Select..."}),r.map(i=>e.jsx("option",{value:i.name,children:i.name},i.name))]})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Operator"}),e.jsxs("select",{style:t.fieldInput,value:s.operator,onChange:i=>l({condition:{...s,operator:i.target.value}}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"not_equals",children:"Not Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"greater_than",children:"Greater Than"}),e.jsx("option",{value:"less_than",children:"Less Than"}),e.jsx("option",{value:"is_true",children:"Is True"})]})]}),s.operator!=="is_true"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Value"}),e.jsx("input",{style:t.fieldInput,value:String(s.value??""),onChange:i=>l({condition:{...s,value:i.target.value}})})]})]}),s.type==="timeout"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Timeout (ms)"}),e.jsx("input",{type:"number",style:t.fieldInput,value:s.afterMs,onChange:i=>l({condition:{...s,afterMs:Number(i.target.value)}})})]}),s.type==="cron"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Cron Expression"}),e.jsx("input",{style:t.fieldInput,value:s.expression,onChange:i=>l({condition:{...s,expression:i.target.value}}),placeholder:"*/5 * * * *"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Timezone"}),e.jsx("input",{style:t.fieldInput,value:s.timezone||"",onChange:i=>l({condition:{...s,timezone:i.target.value}}),placeholder:"UTC"})]})]}),s.type==="trigger_fired"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Trigger ID (optional)"}),e.jsx("input",{style:t.fieldInput,value:s.triggerId||"",onChange:i=>l({condition:{...s,triggerId:i.target.value||void 0}})})]}),e.jsx("div",{style:{marginTop:16},children:e.jsx("button",{style:{...t.btnSecondary,color:"#f38ba8",borderColor:"#f38ba8"},onClick:y,children:"Delete Transition"})})]})}function te({variables:n,onChange:g,onClose:v}){const r=()=>{g([...n,{name:"",type:"string",description:""}])},l=(p,s)=>{g(n.map((i,u)=>u===p?{...i,...s}:i))},y=p=>{g(n.filter((s,i)=>i!==p))};return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsxs("span",{style:{color:"#cba6f7",fontWeight:600},children:["Variables (",n.length,")"]}),e.jsx("button",{style:t.btnClose,onClick:v,children:"x"})]}),n.map((p,s)=>e.jsxs("div",{style:{marginBottom:12,padding:8,background:"#313244",borderRadius:6},children:[e.jsxs("div",{style:{display:"flex",gap:6,marginBottom:4},children:[e.jsx("input",{style:{...t.fieldInput,flex:1},value:p.name,onChange:i=>l(s,{name:i.target.value}),placeholder:"Variable name"}),e.jsxs("select",{style:{...t.fieldInput,width:80},value:p.type,onChange:i=>l(s,{type:i.target.value}),children:[e.jsx("option",{value:"string",children:"string"}),e.jsx("option",{value:"number",children:"number"}),e.jsx("option",{value:"boolean",children:"boolean"}),e.jsx("option",{value:"date",children:"date"}),e.jsx("option",{value:"email",children:"email"}),e.jsx("option",{value:"json",children:"json"})]}),e.jsx("button",{style:{...t.btnClose,padding:"2px 6px"},onClick:()=>y(s),children:"x"})]}),e.jsx("input",{style:{...t.fieldInput,fontSize:11},value:p.description||"",onChange:i=>l(s,{description:i.target.value}),placeholder:"Description"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4,color:"#a6adc8",fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:!!p.required,onChange:i=>l(s,{required:i.target.checked})}),"Required"]})]},s)),e.jsx("button",{style:t.btnSecondary,onClick:r,children:"Add Variable"})]})}function ie({workflow:n,onChange:g,onClose:v}){return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsx("span",{style:{color:"#cdd6f4",fontWeight:600},children:"Settings"}),e.jsx("button",{style:t.btnClose,onClick:v,children:"x"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Name"}),e.jsx("input",{style:t.fieldInput,value:n.name,onChange:r=>g({...n,name:r.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Description"}),e.jsx("textarea",{style:{...t.fieldInput,height:60,resize:"vertical"},value:n.description||"",onChange:r=>g({...n,description:r.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Initial State"}),e.jsx("select",{style:t.fieldInput,value:n.initialStateId,onChange:r=>g({...n,initialStateId:r.target.value}),children:n.states.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Color"}),e.jsx("input",{type:"color",value:n.color||"#89b4fa",onChange:r=>g({...n,color:r.target.value}),style:{width:40,height:30,padding:0,border:"none",cursor:"pointer"}})]}),e.jsxs("div",{style:{color:"#6c7086",fontSize:11,marginTop:16},children:["Version: ",n.version," | States: ",n.states.length," | Transitions: ",n.states.reduce((r,l)=>r+l.transitions.length,0)]})]})}const t={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.6)",zIndex:1e3,display:"flex",justifyContent:"center",alignItems:"center"},panel:{background:"#1e1e2e",borderRadius:12,border:"1px solid #313244",width:"95vw",height:"90vh",display:"flex",flexDirection:"column",overflow:"hidden"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 20px",borderBottom:"1px solid #313244",flexShrink:0},title:{color:"#cdd6f4",fontSize:16,fontWeight:600,margin:0},content:{padding:20,flex:1,overflow:"auto"},card:{background:"#313244",borderRadius:8,padding:"12px 16px",marginBottom:8,cursor:"pointer",border:"1px solid transparent",transition:"border-color 0.15s"},toolbar:{width:180,borderRight:"1px solid #313244",padding:12,display:"flex",flexDirection:"column",flexShrink:0,overflow:"auto"},toolBtn:{display:"block",width:"100%",background:"transparent",border:"1px solid #45475a",borderRadius:6,padding:"6px 10px",color:"#cdd6f4",fontSize:11,cursor:"pointer",textAlign:"left",marginBottom:4},canvas:{flex:1,overflow:"auto",background:"#181825",position:"relative",backgroundImage:"radial-gradient(circle, #313244 1px, transparent 1px)",backgroundSize:"20px 20px"},sidePanel:{width:300,borderLeft:"1px solid #313244",padding:12,overflow:"auto",flexShrink:0},sidePanelHeader:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12,paddingBottom:8,borderBottom:"1px solid #313244"},fieldGroup:{marginBottom:10},fieldLabel:{display:"block",color:"#a6adc8",fontSize:11,marginBottom:4},fieldInput:{display:"block",width:"100%",background:"#313244",border:"1px solid #45475a",borderRadius:6,padding:"6px 8px",color:"#cdd6f4",fontSize:12,outline:"none",boxSizing:"border-box"},btnPrimary:{background:"#89b4fa",border:"none",borderRadius:6,padding:"8px 16px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:12,width:"100%"},btnSecondary:{background:"transparent",border:"1px solid #45475a",borderRadius:6,padding:"6px 12px",color:"#cdd6f4",cursor:"pointer",fontSize:11},btnClose:{background:"transparent",border:"none",color:"#6c7086",cursor:"pointer",fontSize:14,padding:"4px 8px"}};export{re as WorkflowEditorPanel};
42
+ 3. Update Jira ticket status to "In Progress" or "Done".`,skills:["email-gmail","slack-messaging","jira-service-desk"]},transitions:[{id:"t-done",name:"Release Complete",targetStateId:"end",condition:{type:"agent_complete"}}],position:{x:100,y:1060}},{id:"end",name:"End",type:"end",description:"CC process complete",transitions:[],position:{x:100,y:1160}}],Y=[{name:"requester_name",type:"string",description:"Developer requesting the release",required:!0},{name:"requester_email",type:"email",description:"Requester email",required:!0},{name:"requester_slack_id",type:"string",description:"Requester Slack user ID"},{name:"release_name",type:"string",description:"Release version/name",required:!0},{name:"release_description",type:"string",description:"What is being released"},{name:"affected_systems",type:"string",description:"Systems impacted"},{name:"release_date",type:"date",description:"Scheduled release date",required:!0},{name:"release_time",type:"string",description:"Scheduled release time",required:!0},{name:"is_urgent",type:"boolean",description:"Whether this is an urgent release"},{name:"additional_attendees",type:"string",description:"Other people to invite (comma-separated emails)"},{name:"jira_ticket_key",type:"string",description:"Jira ticket key (e.g. SD-1234)"},{name:"jira_ticket_url",type:"string",description:"Full Jira ticket URL"},{name:"cc_file_path",type:"string",description:"Path to generated CC document"},{name:"email_thread_id",type:"string",description:"Gmail thread ID for approval chain"},{name:"calendar_event_id",type:"string",description:"Google Calendar event ID"},{name:"approval_status",type:"json",description:"Current approval status"}],G=200,N=60,B=20,V={action:"#89b4fa",decision:"#f9e2af",wait:"#cba6f7",end:"#a6e3a1"},E={action:"Action",decision:"Decision",wait:"Wait",end:"End"},X={agent_complete:"Agent Complete",trigger_fired:"Trigger Fired",variable_check:"Variable Check",timeout:"Timeout",manual:"Manual",cron:"Cron"};function re({isOpen:n,onClose:g}){const[v,r]=x.useState([]),[l,y]=x.useState(null),[p,s]=x.useState("list"),[i,u]=x.useState(!0),[c,b]=x.useState(null),T=x.useCallback(async()=>{u(!0);try{const o=await M(P("/api/workflows/definitions"));o.ok&&r(await o.json())}catch{b("Failed to load workflows")}finally{u(!1)}},[]);x.useEffect(()=>{n&&T()},[n,T]);const R=()=>{const o={id:`wf-${Date.now()}`,name:"New Workflow",description:"",version:1,variables:[],states:[{id:"start",name:"Start",type:"action",transitions:[],position:{x:300,y:60}},{id:"end",name:"End",type:"end",transitions:[],position:{x:300,y:260}}],initialStateId:"start",createdAt:Date.now(),updatedAt:Date.now()};y(o),s("editor")},D=()=>{const o={id:`wf-cc-${Date.now()}`,name:"CC (Control de Cambios)",description:"Full CC process: intake, Jira ticket, document, approval, release",version:1,variables:[...Y],states:H.map(m=>({...m,transitions:[...m.transitions]})),initialStateId:"intake",createdAt:Date.now(),updatedAt:Date.now()};y(o),s("editor")},d=async o=>{try{v.find(I=>I.id===o.id)?await M(P(`/api/workflows/definitions/${o.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}):await M(P("/api/workflows/definitions"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}),await T()}catch{b("Failed to save workflow")}};return n?e.jsx("div",{style:t.overlay,children:e.jsxs("div",{style:t.panel,children:[e.jsxs("div",{style:t.header,children:[e.jsx("h2",{style:t.title,children:p==="list"?"Workflow Definitions":(l==null?void 0:l.name)||"Editor"}),e.jsxs("div",{style:{display:"flex",gap:8},children:[p==="editor"&&e.jsx("button",{style:t.btnSecondary,onClick:()=>s("list"),children:"Back to List"}),e.jsx("button",{style:t.btnClose,onClick:g,children:"Close"})]})]}),p==="list"&&e.jsx(K,{workflows:v,loading:i,error:c,onSelect:o=>{y(o),s("editor")},onCreate:R,onLoadCC:D}),p==="editor"&&l&&e.jsx(Q,{workflow:l,onChange:y,onSave:d})]})}):null}function K({workflows:n,loading:g,error:v,onSelect:r,onCreate:l,onLoadCC:y}){return e.jsxs("div",{style:t.content,children:[e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:16},children:[e.jsx("button",{style:t.btnPrimary,onClick:l,children:"New Workflow"}),e.jsx("button",{style:t.btnSecondary,onClick:y,children:"Load CC Template"})]}),g&&e.jsx("div",{style:{color:"#a6adc8"},children:"Loading..."}),v&&e.jsx("div",{style:{color:"#f38ba8"},children:v}),n.map(p=>e.jsxs("div",{style:t.card,onClick:()=>r(p),children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{style:{color:"#cdd6f4",fontWeight:600,fontSize:14},children:p.name}),e.jsxs("span",{style:{color:"#a6adc8",fontSize:11},children:["v",p.version," | ",p.states.length," states"]})]}),p.description&&e.jsx("div",{style:{color:"#a6adc8",fontSize:12,marginTop:4},children:p.description})]},p.id)),!g&&n.length===0&&e.jsx("div",{style:{color:"#6c7086",textAlign:"center",padding:40},children:"No workflows yet. Create one or load the CC template."})]})}function Q({workflow:n,onChange:g,onSave:v}){const[r,l]=x.useState(null),[y,p]=x.useState(null),[s,i]=x.useState("none"),[u,c]=x.useState(null),[b,T]=x.useState(!1),R=x.useRef(null),D=x.useRef(n);D.current=n;const d=J(),o=x.useMemo(()=>Array.from(d.values()).map(a=>({id:a.id,name:a.name})),[d]),m=n.states.find(a=>a.id===r),I=x.useCallback(()=>{for(const a of n.states){const f=a.transitions.find(h=>h.id===y);if(f)return{state:a,transition:f}}return null},[n,y]),C=a=>{g({...n,states:a,updatedAt:Date.now()})},k=(a,f)=>{C(n.states.map(h=>h.id===a?{...h,...f}:h))},_=a=>{const f=`state-${Date.now()}`,h={id:f,name:`New ${E[a]}`,type:a,transitions:[],position:{x:300,y:n.states.length*100+60}};C([...n.states,h]),l(f),i("state")},S=a=>{const f=n.states.filter(h=>h.id!==a).map(h=>({...h,transitions:h.transitions.filter(j=>j.targetStateId!==a)}));C(f),l(null),i("none")},w=(a,f)=>{const h=`t-${Date.now()}`;C(n.states.map(j=>j.id!==a?j:{...j,transitions:[...j.transitions,{id:h,name:"New Transition",targetStateId:f,condition:{type:"agent_complete"}}]})),p(h),i("transition")},L=(a,f,h)=>{C(n.states.map(j=>j.id!==a?j:{...j,transitions:j.transitions.map(W=>W.id===f?{...W,...h}:W)}))},A=(a,f)=>{C(n.states.map(h=>h.id!==a?h:{...h,transitions:h.transitions.filter(j=>j.id!==f)})),p(null),i("none")},q=x.useCallback((a,f,h)=>{const j=D.current,W=j.states.map(z=>{if(z.id!==a)return z;const $=z.position||{x:0,y:0};return{...z,position:{x:Math.round(($.x+f)/B)*B,y:Math.round(($.y+h)/B)*B}}});g({...j,states:W,updatedAt:Date.now()})},[g]),O=a=>{u?(u!==a&&w(u,a),c(null)):(l(a),p(null),i("state"))},F=async()=>{T(!0);try{await v(n)}finally{T(!1)}};return e.jsxs("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[e.jsxs("div",{style:t.toolbar,children:[e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{color:"#a6adc8",fontSize:10,textTransform:"uppercase",marginBottom:6,letterSpacing:1},children:"Add State"}),["action","decision","wait","end"].map(a=>e.jsx("button",{style:{...t.toolBtn,borderLeft:`3px solid ${V[a]}`},onClick:()=>_(a),children:E[a]},a))]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{color:"#a6adc8",fontSize:10,textTransform:"uppercase",marginBottom:6,letterSpacing:1},children:"Tools"}),e.jsx("button",{style:{...t.toolBtn,background:u?"#45475a":"transparent"},onClick:()=>c(u?null:r||null),title:"Click a source state, then click a target state",children:u?"Drawing... (click target)":"Draw Transition"})]}),e.jsxs("div",{style:{marginBottom:16},children:[e.jsx("div",{style:{color:"#a6adc8",fontSize:10,textTransform:"uppercase",marginBottom:6,letterSpacing:1},children:"Panels"}),e.jsxs("button",{style:t.toolBtn,onClick:()=>i(s==="variables"?"none":"variables"),children:["Variables (",n.variables.length,")"]}),e.jsx("button",{style:t.toolBtn,onClick:()=>i(s==="settings"?"none":"settings"),children:"Settings"})]}),e.jsx("div",{style:{marginTop:"auto"},children:e.jsx("button",{style:t.btnPrimary,onClick:F,disabled:b,children:b?"Saving...":"Save"})})]}),e.jsx("div",{style:t.canvas,ref:R,children:e.jsx(Z,{states:n.states,initialStateId:n.initialStateId,selectedStateId:r,drawingFrom:u,onStateClick:O,onStateDrag:q,onTransitionClick:a=>{p(a),i("transition")},selectedTransitionId:y})}),s!=="none"&&e.jsxs("div",{style:t.sidePanel,children:[s==="state"&&m&&e.jsx(U,{state:m,agents:o,isInitial:n.initialStateId===m.id,onUpdate:a=>k(m.id,a),onDelete:()=>S(m.id),onSetInitial:()=>g({...n,initialStateId:m.id}),onStartDrawing:()=>c(m.id),onClose:()=>i("none")}),s==="transition"&&y&&(()=>{const a=I();return a?e.jsx(ee,{transition:a.transition,parentState:a.state,allStates:n.states,variables:n.variables,onUpdate:f=>L(a.state.id,a.transition.id,f),onDelete:()=>A(a.state.id,a.transition.id),onClose:()=>i("none")}):null})(),s==="variables"&&e.jsx(te,{variables:n.variables,onChange:a=>g({...n,variables:a}),onClose:()=>i("none")}),s==="settings"&&e.jsx(ie,{workflow:n,onChange:g,onClose:()=>i("none")})]})]})}function Z({states:n,initialStateId:g,selectedStateId:v,drawingFrom:r,onStateClick:l,onStateDrag:y,onTransitionClick:p,selectedTransitionId:s}){const i=x.useRef(y);i.current=y;const u=x.useRef(!1),c=(d,o)=>{if(d.button!==0)return;d.stopPropagation();const m=d.currentTarget,I=d.clientX,C=d.clientY;let k=0,_=0,S=!1;const w=A=>{k=A.clientX-I,_=A.clientY-C,!S&&(Math.abs(k)>3||Math.abs(_)>3)&&(S=!0,m.style.zIndex="100",m.style.cursor="grabbing"),S&&(m.style.transform=`translate(${k}px, ${_}px)`)},L=()=>{window.removeEventListener("mousemove",w),window.removeEventListener("mouseup",L),m.style.transform="",m.style.zIndex="",m.style.cursor="",S&&(u.current=!0,i.current(o,k,_))};window.addEventListener("mousemove",w),window.addEventListener("mouseup",L)},b=(d,o)=>{if(d.stopPropagation(),u.current){u.current=!1;return}l(o)},T=Math.max(...n.map(d=>{var o;return(((o=d.position)==null?void 0:o.x)??0)+G}),600)+100,R=Math.max(...n.map(d=>{var o;return(((o=d.position)==null?void 0:o.y)??0)+N}),400)+100,D=d=>{var o;return(((o=d.position)==null?void 0:o.x)??0)+G/2};return e.jsxs("div",{style:{position:"relative",width:T,height:R,minWidth:"100%",minHeight:"100%"},children:[e.jsxs("svg",{style:{position:"absolute",top:0,left:0,width:T,height:R,pointerEvents:"none"},children:[e.jsxs("defs",{children:[e.jsx("marker",{id:"arrow",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#6c7086"})}),e.jsx("marker",{id:"arrow-selected",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#89b4fa"})})]}),n.flatMap(d=>d.transitions.map(o=>{var L,A;const m=n.find(q=>q.id===o.targetStateId);if(!m)return null;const I=D(d),C=(((L=d.position)==null?void 0:L.y)??0)+N,k=D(m),_=((A=m.position)==null?void 0:A.y)??0,S=o.id===s,w=(C+_)/2;return e.jsxs("g",{style:{pointerEvents:"stroke",cursor:"pointer"},onClick:()=>p(o.id),children:[e.jsx("path",{d:`M ${I} ${C} C ${I} ${w}, ${k} ${w}, ${k} ${_}`,fill:"none",stroke:S?"#89b4fa":"#6c7086",strokeWidth:S?2.5:1.5,markerEnd:`url(#${S?"arrow-selected":"arrow"})`}),e.jsx("text",{x:(I+k)/2+8,y:w,fill:S?"#89b4fa":"#6c7086",fontSize:10,dominantBaseline:"middle",children:o.name})]},o.id)}))]}),n.map(d=>{var k,_;const o=d.id===v,m=d.id===g,I=r&&r!==d.id,C=V[d.type];return e.jsxs("div",{style:{position:"absolute",left:((k=d.position)==null?void 0:k.x)??0,top:((_=d.position)==null?void 0:_.y)??0,width:G,height:N,borderRadius:d.type==="decision"?8:d.type==="end"?30:8,background:o?"rgba(137,180,250,0.12)":"#313244",border:`2px solid ${o?"#89b4fa":I?"#a6e3a1":C}`,cursor:r?"crosshair":"grab",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",userSelect:"none",boxShadow:o?"0 0 12px rgba(137,180,250,0.2)":"none",transition:"box-shadow 0.15s"},onMouseDown:S=>c(S,d.id),onClick:S=>b(S,d.id),children:[m&&e.jsx("div",{style:{position:"absolute",top:-8,left:8,fontSize:9,color:"#a6e3a1",fontWeight:600,background:"#1e1e2e",padding:"0 4px",borderRadius:3},children:"START"}),e.jsx("div",{style:{color:C,fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:E[d.type]}),e.jsx("div",{style:{color:"#cdd6f4",fontSize:12,fontWeight:600,textAlign:"center",padding:"0 8px",overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",maxWidth:G-16},children:d.name})]},d.id)})]})}function U({state:n,agents:g,isInitial:v,onUpdate:r,onDelete:l,onSetInitial:y,onStartDrawing:p,onClose:s}){const i=n.action,u=c=>{r({action:{...i,...c}})};return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsxs("span",{style:{color:V[n.type],fontWeight:600},children:[E[n.type]," State"]}),e.jsx("button",{style:t.btnClose,onClick:s,children:"x"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Name"}),e.jsx("input",{style:t.fieldInput,value:n.name,onChange:c=>r({name:c.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Description"}),e.jsx("textarea",{style:{...t.fieldInput,height:60,resize:"vertical"},value:n.description||"",onChange:c=>r({description:c.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Type"}),e.jsx("select",{style:t.fieldInput,value:n.type,onChange:c=>r({type:c.target.value}),children:Object.entries(E).map(([c,b])=>e.jsx("option",{value:c,children:b},c))})]}),n.type!=="end"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{...t.fieldLabel,marginTop:12,marginBottom:8,fontSize:11,color:"#a6adc8",textTransform:"uppercase",letterSpacing:1},children:"Action"}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Action Type"}),e.jsxs("select",{style:t.fieldInput,value:(i==null?void 0:i.type)||"agent_task",onChange:c=>{const b=c.target.value;b==="agent_task"?r({action:{type:"agent_task",agentId:"",promptTemplate:"",skills:[]}}):b==="wait_for_trigger"?r({action:{type:"wait_for_trigger",timeoutMs:36e5}}):b==="set_variables"?r({action:{type:"set_variables",assignments:{}}}):b==="trigger_setup"&&r({action:{type:"trigger_setup",triggerConfig:{}}})},children:[e.jsx("option",{value:"agent_task",children:"Agent Task"}),e.jsx("option",{value:"wait_for_trigger",children:"Wait for Trigger"}),e.jsx("option",{value:"set_variables",children:"Set Variables"}),e.jsx("option",{value:"trigger_setup",children:"Trigger Setup"})]})]}),(i==null?void 0:i.type)==="agent_task"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Agent"}),e.jsxs("select",{style:t.fieldInput,value:i.agentId,onChange:c=>u({agentId:c.target.value}),children:[e.jsx("option",{value:"",children:"Select agent..."}),g.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Prompt Template"}),e.jsx("textarea",{style:{...t.fieldInput,height:120,fontFamily:"monospace",fontSize:11,resize:"vertical"},value:i.promptTemplate,onChange:c=>u({promptTemplate:c.target.value}),placeholder:"Use {{variable}} for interpolation"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Skills (comma-separated)"}),e.jsx("input",{style:t.fieldInput,value:(i.skills||[]).join(", "),onChange:c=>u({skills:c.target.value.split(",").map(b=>b.trim()).filter(Boolean)}),placeholder:"slack-messaging, jira-service-desk"})]})]}),(i==null?void 0:i.type)==="wait_for_trigger"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Timeout (ms)"}),e.jsx("input",{type:"number",style:t.fieldInput,value:i.timeoutMs||"",onChange:c=>u({timeoutMs:c.target.value?Number(c.target.value):void 0})})]}),(i==null?void 0:i.type)==="set_variables"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Assignments (JSON)"}),e.jsx("textarea",{style:{...t.fieldInput,height:80,fontFamily:"monospace",fontSize:11},value:JSON.stringify(i.assignments||{},null,2),onChange:c=>{try{u({assignments:JSON.parse(c.target.value)})}catch{}}})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16,flexWrap:"wrap"},children:[!v&&e.jsx("button",{style:t.btnSecondary,onClick:y,children:"Set as Start"}),e.jsx("button",{style:t.btnSecondary,onClick:p,children:"Add Transition From Here"}),n.type!=="end"&&!v&&e.jsx("button",{style:{...t.btnSecondary,color:"#f38ba8",borderColor:"#f38ba8"},onClick:l,children:"Delete"})]})]})}function ee({transition:n,parentState:g,allStates:v,variables:r,onUpdate:l,onDelete:y,onClose:p}){const s=n.condition;return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsx("span",{style:{color:"#89b4fa",fontWeight:600},children:"Transition"}),e.jsx("button",{style:t.btnClose,onClick:p,children:"x"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Name"}),e.jsx("input",{style:t.fieldInput,value:n.name,onChange:i=>l({name:i.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"From"}),e.jsx("div",{style:{color:"#cdd6f4",fontSize:12,padding:"6px 0"},children:g.name})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Target State"}),e.jsx("select",{style:t.fieldInput,value:n.targetStateId,onChange:i=>l({targetStateId:i.target.value}),children:v.filter(i=>i.id!==g.id).map(i=>e.jsx("option",{value:i.id,children:i.name},i.id))})]}),e.jsx("div",{style:{...t.fieldLabel,marginTop:12,marginBottom:8,fontSize:11,color:"#a6adc8",textTransform:"uppercase",letterSpacing:1},children:"Condition"}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Condition Type"}),e.jsx("select",{style:t.fieldInput,value:s.type,onChange:i=>{const u=i.target.value;u==="agent_complete"?l({condition:{type:"agent_complete"}}):u==="trigger_fired"?l({condition:{type:"trigger_fired"}}):u==="variable_check"?l({condition:{type:"variable_check",variable:"",operator:"equals",value:""}}):u==="timeout"?l({condition:{type:"timeout",afterMs:36e5}}):u==="manual"?l({condition:{type:"manual"}}):u==="cron"&&l({condition:{type:"cron",expression:"* * * * *"}})},children:Object.entries(X).map(([i,u])=>e.jsx("option",{value:i,children:u},i))})]}),s.type==="variable_check"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Variable"}),e.jsxs("select",{style:t.fieldInput,value:s.variable,onChange:i=>l({condition:{...s,variable:i.target.value}}),children:[e.jsx("option",{value:"",children:"Select..."}),r.map(i=>e.jsx("option",{value:i.name,children:i.name},i.name))]})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Operator"}),e.jsxs("select",{style:t.fieldInput,value:s.operator,onChange:i=>l({condition:{...s,operator:i.target.value}}),children:[e.jsx("option",{value:"equals",children:"Equals"}),e.jsx("option",{value:"not_equals",children:"Not Equals"}),e.jsx("option",{value:"contains",children:"Contains"}),e.jsx("option",{value:"greater_than",children:"Greater Than"}),e.jsx("option",{value:"less_than",children:"Less Than"}),e.jsx("option",{value:"is_true",children:"Is True"})]})]}),s.operator!=="is_true"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Value"}),e.jsx("input",{style:t.fieldInput,value:String(s.value??""),onChange:i=>l({condition:{...s,value:i.target.value}})})]})]}),s.type==="timeout"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Timeout (ms)"}),e.jsx("input",{type:"number",style:t.fieldInput,value:s.afterMs,onChange:i=>l({condition:{...s,afterMs:Number(i.target.value)}})})]}),s.type==="cron"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Cron Expression"}),e.jsx("input",{style:t.fieldInput,value:s.expression,onChange:i=>l({condition:{...s,expression:i.target.value}}),placeholder:"*/5 * * * *"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Timezone"}),e.jsx("input",{style:t.fieldInput,value:s.timezone||"",onChange:i=>l({condition:{...s,timezone:i.target.value}}),placeholder:"UTC"})]})]}),s.type==="trigger_fired"&&e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Trigger ID (optional)"}),e.jsx("input",{style:t.fieldInput,value:s.triggerId||"",onChange:i=>l({condition:{...s,triggerId:i.target.value||void 0}})})]}),e.jsx("div",{style:{marginTop:16},children:e.jsx("button",{style:{...t.btnSecondary,color:"#f38ba8",borderColor:"#f38ba8"},onClick:y,children:"Delete Transition"})})]})}function te({variables:n,onChange:g,onClose:v}){const r=()=>{g([...n,{name:"",type:"string",description:""}])},l=(p,s)=>{g(n.map((i,u)=>u===p?{...i,...s}:i))},y=p=>{g(n.filter((s,i)=>i!==p))};return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsxs("span",{style:{color:"#cba6f7",fontWeight:600},children:["Variables (",n.length,")"]}),e.jsx("button",{style:t.btnClose,onClick:v,children:"x"})]}),n.map((p,s)=>e.jsxs("div",{style:{marginBottom:12,padding:8,background:"#313244",borderRadius:6},children:[e.jsxs("div",{style:{display:"flex",gap:6,marginBottom:4},children:[e.jsx("input",{style:{...t.fieldInput,flex:1},value:p.name,onChange:i=>l(s,{name:i.target.value}),placeholder:"Variable name"}),e.jsxs("select",{style:{...t.fieldInput,width:80},value:p.type,onChange:i=>l(s,{type:i.target.value}),children:[e.jsx("option",{value:"string",children:"string"}),e.jsx("option",{value:"number",children:"number"}),e.jsx("option",{value:"boolean",children:"boolean"}),e.jsx("option",{value:"date",children:"date"}),e.jsx("option",{value:"email",children:"email"}),e.jsx("option",{value:"json",children:"json"})]}),e.jsx("button",{style:{...t.btnClose,padding:"2px 6px"},onClick:()=>y(s),children:"x"})]}),e.jsx("input",{style:{...t.fieldInput,fontSize:11},value:p.description||"",onChange:i=>l(s,{description:i.target.value}),placeholder:"Description"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,marginTop:4,color:"#a6adc8",fontSize:11},children:[e.jsx("input",{type:"checkbox",checked:!!p.required,onChange:i=>l(s,{required:i.target.checked})}),"Required"]})]},s)),e.jsx("button",{style:t.btnSecondary,onClick:r,children:"Add Variable"})]})}function ie({workflow:n,onChange:g,onClose:v}){return e.jsxs("div",{children:[e.jsxs("div",{style:t.sidePanelHeader,children:[e.jsx("span",{style:{color:"#cdd6f4",fontWeight:600},children:"Settings"}),e.jsx("button",{style:t.btnClose,onClick:v,children:"x"})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Name"}),e.jsx("input",{style:t.fieldInput,value:n.name,onChange:r=>g({...n,name:r.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Description"}),e.jsx("textarea",{style:{...t.fieldInput,height:60,resize:"vertical"},value:n.description||"",onChange:r=>g({...n,description:r.target.value})})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Initial State"}),e.jsx("select",{style:t.fieldInput,value:n.initialStateId,onChange:r=>g({...n,initialStateId:r.target.value}),children:n.states.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))})]}),e.jsxs("div",{style:t.fieldGroup,children:[e.jsx("label",{style:t.fieldLabel,children:"Color"}),e.jsx("input",{type:"color",value:n.color||"#89b4fa",onChange:r=>g({...n,color:r.target.value}),style:{width:40,height:30,padding:0,border:"none",cursor:"pointer"}})]}),e.jsxs("div",{style:{color:"#6c7086",fontSize:11,marginTop:16},children:["Version: ",n.version," | States: ",n.states.length," | Transitions: ",n.states.reduce((r,l)=>r+l.transitions.length,0)]})]})}const t={overlay:{position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.6)",zIndex:1e3,display:"flex",justifyContent:"center",alignItems:"center"},panel:{background:"#1e1e2e",borderRadius:12,border:"1px solid #313244",width:"95vw",height:"90vh",display:"flex",flexDirection:"column",overflow:"hidden"},header:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 20px",borderBottom:"1px solid #313244",flexShrink:0},title:{color:"#cdd6f4",fontSize:16,fontWeight:600,margin:0},content:{padding:20,flex:1,overflow:"auto"},card:{background:"#313244",borderRadius:8,padding:"12px 16px",marginBottom:8,cursor:"pointer",border:"1px solid transparent",transition:"border-color 0.15s"},toolbar:{width:180,borderRight:"1px solid #313244",padding:12,display:"flex",flexDirection:"column",flexShrink:0,overflow:"auto"},toolBtn:{display:"block",width:"100%",background:"transparent",border:"1px solid #45475a",borderRadius:6,padding:"6px 10px",color:"#cdd6f4",fontSize:11,cursor:"pointer",textAlign:"left",marginBottom:4},canvas:{flex:1,overflow:"auto",background:"#181825",position:"relative",backgroundImage:"radial-gradient(circle, #313244 1px, transparent 1px)",backgroundSize:"20px 20px"},sidePanel:{width:300,borderLeft:"1px solid #313244",padding:12,overflow:"auto",flexShrink:0},sidePanelHeader:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12,paddingBottom:8,borderBottom:"1px solid #313244"},fieldGroup:{marginBottom:10},fieldLabel:{display:"block",color:"#a6adc8",fontSize:11,marginBottom:4},fieldInput:{display:"block",width:"100%",background:"#313244",border:"1px solid #45475a",borderRadius:6,padding:"6px 8px",color:"#cdd6f4",fontSize:12,outline:"none",boxSizing:"border-box"},btnPrimary:{background:"#89b4fa",border:"none",borderRadius:6,padding:"8px 16px",color:"#1e1e2e",fontWeight:600,cursor:"pointer",fontSize:12,width:"100%"},btnSecondary:{background:"transparent",border:"1px solid #45475a",borderRadius:6,padding:"6px 12px",color:"#cdd6f4",cursor:"pointer",fontSize:11},btnClose:{background:"transparent",border:"none",color:"#6c7086",cursor:"pointer",fontSize:14,padding:"4px 8px"}};export{re as WorkflowEditorPanel};