tide-commander 1.45.0 → 1.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/assets/{BossLogsModal-N4CnX-0x.js → BossLogsModal-BEZSJWBV.js} +1 -1
  2. package/dist/assets/BossSpawnModal-BknVJp2f.js +1 -0
  3. package/dist/assets/{ControlsModal-Cr5klRxS.js → ControlsModal-BZKmtLz7.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-D6U9obTe.js → DockerLogsModal-DD8gRVu6.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-Bnm-9Q73.js → EmbeddedEditor-DMcKiZ5q.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-GoKvyYWS.js → GmailOAuthSetup-CO2LqLvU.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-D3sAGlZq.js → GoogleOAuthSetup-OVzavssB.js} +1 -1
  8. package/dist/assets/{IframeModal-DQqev6_V.js → IframeModal-DJn-dNqr.js} +1 -1
  9. package/dist/assets/IntegrationsPanel-C0JSiDOw.js +2 -0
  10. package/dist/assets/{LogViewerModal-DB0xx-oB.js → LogViewerModal-BgIfdR-l.js} +1 -1
  11. package/dist/assets/{MonitoringModal-BspW74kP.js → MonitoringModal-Dm8wbcHY.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-Cz4GZtyl.js → PM2LogsModal-CDULU4yk.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-KCCSJy3B.js → RestoreArchivedAreaModal-DLuiZj6S.js} +1 -1
  14. package/dist/assets/{SaveSnapshotModal-DqZ1JedM.js → SaveSnapshotModal-CbfjHVJz.js} +1 -1
  15. package/dist/assets/Scene2DCanvas-Dw9o4Fk8.js +1 -0
  16. package/dist/assets/{SceneManager-DggU0iAh.js → SceneManager-KAhHYpUf.js} +1 -1
  17. package/dist/assets/SkillsPanel-BYy3W8hd.js +28 -0
  18. package/dist/assets/SnapshotManager-LxlHIjaa.js +1 -0
  19. package/dist/assets/SpawnModal-Ch7yKsdS.js +1 -0
  20. package/dist/assets/SubordinateAssignmentModal-zuSTZAqj.js +1 -0
  21. package/dist/assets/{SupervisorPanel-CxId5lI7.js → SupervisorPanel-tTfMa-0x.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-BCzGGCPD.js → TriggerManagerPanel-BoHdbpqk.js} +2 -2
  23. package/dist/assets/{WorkflowEditorPanel-BmNCGmxP.js → WorkflowEditorPanel-Cusd-51G.js} +2 -2
  24. package/dist/assets/{index-8WVMR823.js → index-BPn1NjZ5.js} +1 -1
  25. package/dist/assets/{index-CvJuv-ho.js → index-BoFICHSl.js} +2 -2
  26. package/dist/assets/{index-Sej69v19.js → index-C_3LXJYS.js} +3 -3
  27. package/dist/assets/{index-Bhb-rse9.js → index-CeMGJMtZ.js} +3 -3
  28. package/dist/assets/{index-COBkxsEU.js → index-ChZ1qMl3.js} +1 -1
  29. package/dist/assets/{index-C9B8kaWK.js → index-Cxx3kFoj.js} +1 -1
  30. package/dist/assets/{index-CcYTUJp1.js → index-D3KwWKEv.js} +4 -4
  31. package/dist/assets/index-ifiZ65Cu.js +1 -0
  32. package/dist/assets/main-3GpIvzEr.css +1 -0
  33. package/dist/assets/main-BsOvZp5M.js +153 -0
  34. package/dist/assets/{web-RTEsf66y.js → web-B5moyGVG.js} +1 -1
  35. package/dist/assets/{web-CrUhsC9T.js → web-BYzo_b4X.js} +1 -1
  36. package/dist/index.html +2 -2
  37. package/dist/src/packages/server/data/index.js +25 -0
  38. package/dist/src/packages/server/routes/config.js +7 -0
  39. package/dist/src/packages/server/routes/custom-class-icons.js +138 -0
  40. package/dist/src/packages/server/routes/index.js +2 -0
  41. package/dist/src/packages/server/services/custom-class-service.js +7 -2
  42. package/package.json +1 -1
  43. package/dist/assets/BossSpawnModal-4CPjS2xn.js +0 -1
  44. package/dist/assets/IntegrationsPanel-C9hWD7mO.js +0 -2
  45. package/dist/assets/Scene2DCanvas-MRhWT6EA.js +0 -1
  46. package/dist/assets/SkillsPanel-DZC0Im2z.js +0 -28
  47. package/dist/assets/SnapshotManager-3LQMRFLh.js +0 -1
  48. package/dist/assets/SpawnModal-C_e6q2uv.js +0 -1
  49. package/dist/assets/SubordinateAssignmentModal-BZdSk9WL.js +0 -1
  50. package/dist/assets/index-B8SWRPUd.js +0 -1
  51. package/dist/assets/main-6CnCKW13.js +0 -153
  52. package/dist/assets/main-DjGrMNoB.css +0 -1
@@ -1,3 +1,3 @@
1
- import{H as ce,r as n,V as h,w as p,j as e}from"./main-6CnCKW13.js";import"./modulepreload-polyfill-B5Qt9EMX.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const pe=[{value:"webhook",label:"Webhook"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"}],xe=[{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)"}],he=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}],w=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function me({isOpen:C,onClose:E}){var H,U,_,W,J,V,$,G,X,q,Y,K;const T=ce(),[R,Q]=n.useState([]),[y,j]=n.useState("list"),[s,u]=n.useState(w()),[d,S]=n.useState(!1),[F,z]=n.useState(!1),[L,c]=n.useState(null),[O,Z]=n.useState([]),[g,ee]=n.useState(null),[k,te]=n.useState(`{
1
+ import{I as ce,r as n,W as h,l as p,j as e}from"./main-BsOvZp5M.js";import"./modulepreload-polyfill-B5Qt9EMX.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const pe=[{value:"webhook",label:"Webhook"},{value:"cron",label:"Cron"},{value:"slack",label:"Slack"},{value:"email",label:"Email"},{value:"jira",label:"Jira"}],xe=[{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)"}],he=[{value:"structural",label:"Structural"},{value:"llm",label:"LLM"}],w=()=>({name:"",description:"",type:"webhook",agentId:"",promptTemplate:"",enabled:!0,matchMode:"structural",extractionMode:"structural",config:{method:"POST"}});function me({isOpen:C,onClose:E}){var H,U,W,_,J,$,V,G,X,q,Y,K;const T=ce(),[R,Q]=n.useState([]),[y,j]=n.useState("list"),[s,u]=n.useState(w()),[d,S]=n.useState(!1),[F,z]=n.useState(!1),[L,c]=n.useState(null),[O,Z]=n.useState([]),[g,ee]=n.useState(null),[k,te]=n.useState(`{
2
2
 
3
- }`),[r,f]=n.useState(null),[B,I]=n.useState(!1),[N,P]=n.useState([]),x=n.useCallback(async()=>{try{const t=await h(p("/api/triggers"));if(t.ok){const a=await t.json();Q(a)}}catch(t){console.error("Failed to load triggers:",t)}},[]),v=n.useCallback(async t=>{try{const a=await h(p(`/api/triggers/${t}/events?limit=20`));if(a.ok){const i=await a.json();Z(i)}}catch(a){console.error("Failed to load trigger history:",a)}},[]);n.useEffect(()=>{C&&x()},[C,x]),n.useEffect(()=>{g&&v(g)},[g,v]);const le=n.useCallback(async()=>{z(!0),c(null);try{const t=d?p(`/api/triggers/${s.id}`):p("/api/triggers"),b=await h(t,{method:d?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!b.ok){const de=await b.json();throw new Error(de.error||"Failed to save trigger")}await x(),j("list"),u(w()),S(!1)}catch(t){c(t instanceof Error?t.message:"Save failed")}finally{z(!1)}},[s,d,x]),ae=n.useCallback(async t=>{try{await h(p(`/api/triggers/${t}`),{method:"DELETE"}),await x()}catch(a){console.error("Failed to delete trigger:",a)}},[x]),se=n.useCallback(async t=>{try{await h(p(`/api/triggers/${t.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!t.enabled})}),await x()}catch(a){console.error("Failed to toggle trigger:",a)}},[x]),ie=n.useCallback(async t=>{try{await h(p(`/api/triggers/${t}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),g===t&&await v(t)}catch(a){console.error("Failed to test fire trigger:",a)}},[g,v]),ne=n.useCallback(async()=>{if(s.id){I(!0),f(null);try{let t;try{t=JSON.parse(k)}catch{f({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),c("Invalid JSON payload");return}const a=await h(p(`/api/triggers/${s.id}/test-match`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:t})});if(a.ok){const i=await a.json();f(i),c(null)}else{const i=await a.json();c(i.error||"Test match failed")}}catch(t){c(t instanceof Error?t.message:"Test match failed")}finally{I(!1)}}},[s.id,k]),re=n.useCallback(async t=>{var a;try{const i=await h(p("/api/triggers/validate-cron"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expression:t,timezone:((a=s.config)==null?void 0:a.timezone)||"UTC"})});if(i.ok){const b=await i.json();P(b.valid?b.nextFires:[])}}catch{P([])}},[s]),D=n.useCallback(t=>{t?(u({...t}),S(!0)):(u(w()),S(!1)),f(null),c(null),j("edit")},[]),o=n.useCallback((t,a)=>{u(i=>({...i,[t]:a}))},[]),m=n.useCallback((t,a)=>{u(i=>({...i,config:{...i.config,[t]:a}}))},[]),M=n.useCallback((t,a)=>{u(i=>({...i,llmMatch:{...i.llmMatch||{prompt:""},[t]:a}}))},[]),A=n.useCallback((t,a)=>{u(i=>({...i,llmExtract:{...i.llmExtract||{prompt:"",variables:[]},[t]:a}}))},[]),oe=n.useMemo(()=>Array.from(T.values()).map(t=>({id:t.id,name:t.name})),[T]);return C?e.jsx("div",{style:l.overlay,onClick:E,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:y==="list"?"Triggers":d?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:l.headerActions,children:[y==="list"&&e.jsx("button",{style:l.addBtn,onClick:()=>D(),children:"+ New Trigger"}),y==="edit"&&e.jsx("button",{style:l.backBtn,onClick:()=>{j("list"),f(null),c(null)},children:"Back"}),e.jsx("button",{style:l.closeBtn,onClick:E,children:"X"})]})]}),L&&e.jsx("div",{style:l.error,children:L}),y==="list"&&e.jsx("div",{style:l.content,children:R.length===0?e.jsx("div",{style:l.empty,children:"No triggers configured. Create one to get started."}):R.map(t=>{var a;return e.jsxs("div",{style:{...l.triggerCard,borderLeftColor:t.status==="error"?"#e74c3c":t.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{ee(t.id),D(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.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:i=>{i.stopPropagation(),se(t)},children:t.enabled?"Disable":"Enable"}),e.jsx("button",{style:l.smallBtn,onClick:i=>{i.stopPropagation(),ie(t.id)},children:"Test Fire"}),e.jsx("button",{style:{...l.smallBtn,color:"#e74c3c"},onClick:i=>{i.stopPropagation(),ae(t.id)},children:"Delete"})]})]}),e.jsxs("div",{style:l.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((a=T.get(t.agentId))==null?void 0:a.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)})}),y==="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:s.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:s.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:s.type||"webhook",onChange:t=>{const a=t.target.value;o("type",a),a==="webhook"?o("config",{method:"POST"}):a==="cron"?o("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):o("config",{})},children:pe.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:s.agentId||"",onChange:t=>o("agentId",t.target.value),children:[e.jsx("option",{value:"",children:"Select agent..."}),oe.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:s.promptTemplate||"",onChange:t=>o("promptTemplate",t.target.value),placeholder:"Message sent to agent. Use {{variable}} for interpolation.",rows:4})]}),s.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:((H=s.config)==null?void 0:H.method)||"POST",onChange:t=>m("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:((U=s.config)==null?void 0:U.secret)||"",onChange:t=>m("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:((W=(_=s.config)==null?void 0:_.extractFields)==null?void 0:W.join(", "))||"",onChange:t=>m("extractFields",t.target.value.split(",").map(a=>a.trim()).filter(Boolean)),placeholder:"body.release_name, body.version"})]}),d&&s.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/${s.id}`})]})]}),s.type==="cron"&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Cron Config"}),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:((J=s.config)==null?void 0:J.expression)||"",onChange:t=>{m("expression",t.target.value),t.target.value&&re(t.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:((V=s.config)==null?void 0:V.timezone)||"UTC",onChange:t=>m("timezone",t.target.value),placeholder:"America/Mexico_City"})]})]}),N.length>0&&e.jsxs("div",{style:l.nextFires,children:[e.jsx("label",{style:l.label,children:"Next fires:"}),N.map((t,a)=>e.jsx("div",{style:l.nextFireItem,children:new Date(t).toLocaleString()},a))]})]}),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Match Mode"}),e.jsx("div",{style:l.modeSelector,children:xe.map(t=>e.jsxs("button",{style:{...l.modeBtn,...s.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))}),(s.matchMode==="llm"||s.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:(($=s.llmMatch)==null?void 0:$.prompt)||"",onChange:t=>M("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:((G=s.llmMatch)==null?void 0:G.model)||"haiku",onChange:t=>M("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:((X=s.llmMatch)==null?void 0:X.minConfidence)??0,onChange:t=>M("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:he.map(t=>e.jsx("button",{style:{...l.modeBtn,...s.extractionMode===t.value?l.modeBtnActive:{}},onClick:()=>o("extractionMode",t.value),children:t.label},t.value))}),s.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=s.llmExtract)==null?void 0:q.prompt)||"",onChange:t=>A("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:((K=(Y=s.llmExtract)==null?void 0:Y.variables)==null?void 0:K.join(", "))||"",onChange:t=>A("variables",t.target.value.split(",").map(a=>a.trim()).filter(Boolean)),placeholder:"release_name, affected_systems, urgency"})]})]})]}),d&&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:k,onChange:t=>te(t.target.value),rows:4})]}),e.jsx("button",{style:l.testBtn,onClick:ne,disabled:B,children:B?"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,a])=>e.jsxs("div",{style:l.varRow,children:[e.jsx("code",{children:t}),": ",a]},t))]})]})]}),d&&O.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:O.map((t,a)=>{const i=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}),i&&e.jsxs("div",{style:l.llmMeta,children:["LLM: ",i.match?"match":"no match"," (",(i.confidence*100).toFixed(0),"%) - ",i.reason]})]},t.id||a)})})]}),e.jsxs("div",{style:l.actions,children:[e.jsx("button",{style:l.cancelBtn,onClick:()=>{j("list"),c(null)},children:"Cancel"}),e.jsx("button",{style:l.saveBtn,onClick:le,disabled:F||!s.name||!s.agentId,children:F?"Saving...":d?"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{me as TriggerManagerPanel,me as default};
3
+ }`),[r,f]=n.useState(null),[B,I]=n.useState(!1),[N,P]=n.useState([]),x=n.useCallback(async()=>{try{const t=await h(p("/api/triggers"));if(t.ok){const a=await t.json();Q(a)}}catch(t){console.error("Failed to load triggers:",t)}},[]),v=n.useCallback(async t=>{try{const a=await h(p(`/api/triggers/${t}/events?limit=20`));if(a.ok){const i=await a.json();Z(i)}}catch(a){console.error("Failed to load trigger history:",a)}},[]);n.useEffect(()=>{C&&x()},[C,x]),n.useEffect(()=>{g&&v(g)},[g,v]);const le=n.useCallback(async()=>{z(!0),c(null);try{const t=d?p(`/api/triggers/${s.id}`):p("/api/triggers"),b=await h(t,{method:d?"PATCH":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!b.ok){const de=await b.json();throw new Error(de.error||"Failed to save trigger")}await x(),j("list"),u(w()),S(!1)}catch(t){c(t instanceof Error?t.message:"Save failed")}finally{z(!1)}},[s,d,x]),ae=n.useCallback(async t=>{try{await h(p(`/api/triggers/${t}`),{method:"DELETE"}),await x()}catch(a){console.error("Failed to delete trigger:",a)}},[x]),se=n.useCallback(async t=>{try{await h(p(`/api/triggers/${t.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!t.enabled})}),await x()}catch(a){console.error("Failed to toggle trigger:",a)}},[x]),ie=n.useCallback(async t=>{try{await h(p(`/api/triggers/${t}/fire`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variables:{}})}),g===t&&await v(t)}catch(a){console.error("Failed to test fire trigger:",a)}},[g,v]),ne=n.useCallback(async()=>{if(s.id){I(!0),f(null);try{let t;try{t=JSON.parse(k)}catch{f({structuralMatch:void 0,extractedVariables:{},wouldFire:!1}),c("Invalid JSON payload");return}const a=await h(p(`/api/triggers/${s.id}/test-match`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payload:t})});if(a.ok){const i=await a.json();f(i),c(null)}else{const i=await a.json();c(i.error||"Test match failed")}}catch(t){c(t instanceof Error?t.message:"Test match failed")}finally{I(!1)}}},[s.id,k]),re=n.useCallback(async t=>{var a;try{const i=await h(p("/api/triggers/validate-cron"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expression:t,timezone:((a=s.config)==null?void 0:a.timezone)||"UTC"})});if(i.ok){const b=await i.json();P(b.valid?b.nextFires:[])}}catch{P([])}},[s]),D=n.useCallback(t=>{t?(u({...t}),S(!0)):(u(w()),S(!1)),f(null),c(null),j("edit")},[]),o=n.useCallback((t,a)=>{u(i=>({...i,[t]:a}))},[]),m=n.useCallback((t,a)=>{u(i=>({...i,config:{...i.config,[t]:a}}))},[]),M=n.useCallback((t,a)=>{u(i=>({...i,llmMatch:{...i.llmMatch||{prompt:""},[t]:a}}))},[]),A=n.useCallback((t,a)=>{u(i=>({...i,llmExtract:{...i.llmExtract||{prompt:"",variables:[]},[t]:a}}))},[]),oe=n.useMemo(()=>Array.from(T.values()).map(t=>({id:t.id,name:t.name})),[T]);return C?e.jsx("div",{style:l.overlay,onClick:E,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:y==="list"?"Triggers":d?"Edit Trigger":"New Trigger"}),e.jsxs("div",{style:l.headerActions,children:[y==="list"&&e.jsx("button",{style:l.addBtn,onClick:()=>D(),children:"+ New Trigger"}),y==="edit"&&e.jsx("button",{style:l.backBtn,onClick:()=>{j("list"),f(null),c(null)},children:"Back"}),e.jsx("button",{style:l.closeBtn,onClick:E,children:"X"})]})]}),L&&e.jsx("div",{style:l.error,children:L}),y==="list"&&e.jsx("div",{style:l.content,children:R.length===0?e.jsx("div",{style:l.empty,children:"No triggers configured. Create one to get started."}):R.map(t=>{var a;return e.jsxs("div",{style:{...l.triggerCard,borderLeftColor:t.status==="error"?"#e74c3c":t.enabled?"#2ecc71":"#95a5a6"},onClick:()=>{ee(t.id),D(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.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:i=>{i.stopPropagation(),se(t)},children:t.enabled?"Disable":"Enable"}),e.jsx("button",{style:l.smallBtn,onClick:i=>{i.stopPropagation(),ie(t.id)},children:"Test Fire"}),e.jsx("button",{style:{...l.smallBtn,color:"#e74c3c"},onClick:i=>{i.stopPropagation(),ae(t.id)},children:"Delete"})]})]}),e.jsxs("div",{style:l.cardMeta,children:[e.jsxs("span",{children:["Agent: ",((a=T.get(t.agentId))==null?void 0:a.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)})}),y==="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:s.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:s.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:s.type||"webhook",onChange:t=>{const a=t.target.value;o("type",a),a==="webhook"?o("config",{method:"POST"}):a==="cron"?o("config",{expression:"0 9 * * MON-FRI",timezone:"UTC"}):o("config",{})},children:pe.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:s.agentId||"",onChange:t=>o("agentId",t.target.value),children:[e.jsx("option",{value:"",children:"Select agent..."}),oe.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:s.promptTemplate||"",onChange:t=>o("promptTemplate",t.target.value),placeholder:"Message sent to agent. Use {{variable}} for interpolation.",rows:4})]}),s.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:((H=s.config)==null?void 0:H.method)||"POST",onChange:t=>m("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:((U=s.config)==null?void 0:U.secret)||"",onChange:t=>m("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:((_=(W=s.config)==null?void 0:W.extractFields)==null?void 0:_.join(", "))||"",onChange:t=>m("extractFields",t.target.value.split(",").map(a=>a.trim()).filter(Boolean)),placeholder:"body.release_name, body.version"})]}),d&&s.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/${s.id}`})]})]}),s.type==="cron"&&e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Cron Config"}),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:((J=s.config)==null?void 0:J.expression)||"",onChange:t=>{m("expression",t.target.value),t.target.value&&re(t.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:(($=s.config)==null?void 0:$.timezone)||"UTC",onChange:t=>m("timezone",t.target.value),placeholder:"America/Mexico_City"})]})]}),N.length>0&&e.jsxs("div",{style:l.nextFires,children:[e.jsx("label",{style:l.label,children:"Next fires:"}),N.map((t,a)=>e.jsx("div",{style:l.nextFireItem,children:new Date(t).toLocaleString()},a))]})]}),e.jsxs("div",{style:l.section,children:[e.jsx("h4",{style:l.sectionTitle,children:"Match Mode"}),e.jsx("div",{style:l.modeSelector,children:xe.map(t=>e.jsxs("button",{style:{...l.modeBtn,...s.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))}),(s.matchMode==="llm"||s.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:((V=s.llmMatch)==null?void 0:V.prompt)||"",onChange:t=>M("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:((G=s.llmMatch)==null?void 0:G.model)||"haiku",onChange:t=>M("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:((X=s.llmMatch)==null?void 0:X.minConfidence)??0,onChange:t=>M("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:he.map(t=>e.jsx("button",{style:{...l.modeBtn,...s.extractionMode===t.value?l.modeBtnActive:{}},onClick:()=>o("extractionMode",t.value),children:t.label},t.value))}),s.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=s.llmExtract)==null?void 0:q.prompt)||"",onChange:t=>A("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:((K=(Y=s.llmExtract)==null?void 0:Y.variables)==null?void 0:K.join(", "))||"",onChange:t=>A("variables",t.target.value.split(",").map(a=>a.trim()).filter(Boolean)),placeholder:"release_name, affected_systems, urgency"})]})]})]}),d&&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:k,onChange:t=>te(t.target.value),rows:4})]}),e.jsx("button",{style:l.testBtn,onClick:ne,disabled:B,children:B?"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,a])=>e.jsxs("div",{style:l.varRow,children:[e.jsx("code",{children:t}),": ",a]},t))]})]})]}),d&&O.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:O.map((t,a)=>{const i=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}),i&&e.jsxs("div",{style:l.llmMeta,children:["LLM: ",i.match?"match":"no match"," (",(i.confidence*100).toFixed(0),"%) - ",i.reason]})]},t.id||a)})})]}),e.jsxs("div",{style:l.actions,children:[e.jsx("button",{style:l.cancelBtn,onClick:()=>{j("list"),c(null)},children:"Cancel"}),e.jsx("button",{style:l.saveBtn,onClick:le,disabled:F||!s.name||!s.agentId,children:F?"Saving...":d?"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{me as TriggerManagerPanel,me as default};
@@ -1,4 +1,4 @@
1
- import{r as x,V as M,w as P,j as e,H as J}from"./main-6CnCKW13.js";import"./modulepreload-polyfill-B5Qt9EMX.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,W as M,l as P,j as e,I as J}from"./main-BsOvZp5M.js";import"./modulepreload-polyfill-B5Qt9EMX.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 le({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{le 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 le({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 W=()=>{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:W,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),W=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(R=>R.id===f?{...R,...h}:R)}))},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,R=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:R,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:W,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,W=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:W,minWidth:"100%",minHeight:"100%"},children:[e.jsxs("svg",{style:{position:"absolute",top:0,left:0,width:T,height:W,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{le as WorkflowEditorPanel};