@w6w/ui 0.2.60 → 0.2.62

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.
package/dist/flow.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use client";"use strict";var io=Object.defineProperty;var ro=(e,t,o)=>t in e?io(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var it=(e,t,o)=>ro(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),oe=require("@xyflow/react"),d=require("react"),i=require("./connection-app-meta-BXCIgekK.cjs"),Ee=require("./CodeBlock-BSX1pi6W.cjs"),Ae=require("@w6w/expr");function ao({x:e,y:t,items:o,onAction:n,onClose:a}){const u=d.useRef(null),[c,f]=d.useState({left:e,top:t});d.useLayoutEffect(()=>{const x=u.current,b=x==null?void 0:x.offsetParent;if(!x||!b)return;const w=x.offsetWidth,v=x.offsetHeight;f({left:e+w>b.clientWidth?Math.max(0,e-w):e,top:t+v>b.clientHeight?Math.max(0,t-v):t})},[e,t]),d.useEffect(()=>{var x,b;(b=(x=u.current)==null?void 0:x.querySelector("[role=menuitem]"))==null||b.focus({preventScroll:!0})},[]),d.useEffect(()=>{const x=v=>{var C;(C=u.current)!=null&&C.contains(v.target)||a(!1)},b=v=>{var C;(C=u.current)!=null&&C.contains(v.target)||a(!1)},w=()=>a(!1);return document.addEventListener("pointerdown",x,!0),document.addEventListener("scroll",b,!0),document.addEventListener("wheel",b,{capture:!0,passive:!0}),window.addEventListener("blur",w),window.addEventListener("resize",w),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("scroll",b,!0),document.removeEventListener("wheel",b,!0),window.removeEventListener("blur",w),window.removeEventListener("resize",w)}},[a]);const p=x=>{x.disabled||(a(!1),n(x.action))};return s.jsx("div",{ref:u,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:c.left,top:c.top},onContextMenu:x=>x.preventDefault(),onKeyDown:x=>{var C;x.stopPropagation();const b=[...((C=u.current)==null?void 0:C.querySelectorAll("[role=menuitem]"))??[]],w=b.indexOf(document.activeElement),v=L=>{var T;return(T=b[(L+b.length)%b.length])==null?void 0:T.focus()};if(x.key==="ArrowDown")v(w+1);else if(x.key==="ArrowUp")v(w<0?-1:w-1);else if(x.key==="Home")v(0);else if(x.key==="End")v(-1);else if(x.key==="Escape"||x.key==="Tab")a(!0);else if(x.key==="Enter"||x.key===" ")w>=0&&p(o[w]);else return;x.preventDefault()},children:o.map(x=>s.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":x.disabled||void 0,className:`w6w-note-menu-item${x.danger?" danger":""}${x.separated?" separated":""}`,"data-action":x.action,onClick:()=>p(x),children:x.label},x.action))})}function co(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function lo({app:e,trigger:t,onUse:o}){const n=i.useW6WApi(),[a,u]=d.useState(null);return d.useEffect(()=>{var f;let c=!1;return u(null),(f=n.getAppTriggers)==null||f.call(n,e).then(p=>{var x;c||u(co((x=p.find(b=>b.key===t))==null?void 0:x.sample))}).catch(()=>{}),()=>{c=!0}},[n,e,t]),a?s.jsx("div",{children:s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>o(a),children:"Use sample event"})}):null}function uo(e,t){return t===void 0?[...e]:e.includes(t)?[...e]:[t]}function po(e,t,o={}){const n=[],a=e.length;if(a>0){const u=a>1?` ${a} nodes`:"";n.push({action:"duplicate",label:`Duplicate${u}`,disabled:t}),a===1&&o.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:t}),n.push({action:"delete",label:`Delete${u}`,disabled:t,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:t,separated:a>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:t}),n}const gn=200,mn=200,wn=10240;function Zt(e){const t={};for(const[o,n]of Object.entries(e))t[o]=Math.round(n);return t}const fo=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),ho=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Ys(e,t,o){return e&&e.map(n=>{const a=t==null?void 0:t[n.id],u=fo(a==null?void 0:a.position)?a.position:n.position,c=ho(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Zt(u),size:Zt(c)}})}function xn(e,t,o){if(!t)return e;const n={...e};return e.notes&&(n.notes=Ys(e.notes,o)),e.sections&&(n.sections=Ys(e.sections,o)),n}function rs(e,t){return e.sections?{...e,sections:e.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==t)}))}:e}function Qt(e,t,o){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===t?o:a)}))}:e}function es(e,t,o){if(!e.sections)return e;const n=new Set(o);return{...e,sections:e.sections.map(a=>{const u=a.nodes.filter(c=>!n.has(c));return a.id===t?{...a,nodes:[...new Set([...u,...o])]}:{...a,nodes:u}})}}function bn(e,t){return(e.sections??[]).filter(o=>o.nodes.includes(t)).map(o=>o.id)}function go(e,t){const o=new TextEncoder;if(o.encode(e).length<=t)return e;let n="",a=0;for(const u of e){const c=o.encode(u).length;if(a+c>t)break;n+=u,a+=c}return n}function ts(e){const t={...e};return e.notes&&(t.notes=e.notes.slice(0,gn).map(o=>({...o,content:go(o.content,wn)}))),e.sections&&(t.sections=e.sections.slice(0,mn)),t}function mo(e,t,o){const n={};for(const c of[...e.notes??[],...e.sections??[]])n[c.id]={position:c.position,size:c.size};const a=(c,f)=>c==null?void 0:c.map(p=>{const x=f==null?void 0:f.find(b=>b.id===p.id);return x?{...p,position:x.position,size:x.size}:p}),u=o?e:{...e,...e.notes?{notes:a(e.notes,t==null?void 0:t.notes)}:{},...e.sections?{sections:a(e.sections,t==null?void 0:t.sections)}:{}};return xn(u,o,n)}const Zs=220;function wo(e){return e.length<=Zs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Zs).trimEnd(),clipped:!0,length:e.length}}function xo({params:e,values:t,testStartState:o,view:n="props",literalKeys:a}){const{sampleValues:u,nodeConfig:c,nodeMeta:f}=i.useExpressionOptions(),p=d.useMemo(()=>i.buildResolveScope(u,o,c,f),[u,o,c,f]),x=i.flattenParams(e),b=C=>{var L;return t[C]!==void 0?t[C]:(L=x.find(T=>T.key===C))==null?void 0:L.default},w=x.filter(C=>C.type!=="section"&&i.isParamVisible(C,b)).map(C=>Ae.effectiveParam(C,b));if(i.hasParamCustomization(t)){const C=i.previewCustomization(t.$merge,p,a),L=C!==null&&typeof C=="object"&&!Array.isArray(C),T=Qs(w,t,p,a);for(const[h,I]of Object.entries(t))h!=="$merge"&&(T[h]=a!=null&&a.includes(h)?I:i.previewCustomization(I,p));const D=L?{...T,...C}:T;return s.jsxs("div",{className:"w6w-resolved-params",children:[s.jsx("p",{className:"w6w-muted w6w-small",children:L?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(C)}). Test the step to validate it.`}),n==="code"?s.jsx(i.JsonEditor,{value:JSON.stringify(D,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):s.jsx("div",{className:"w6w-resolved-table",children:Object.entries(D).map(([h,I])=>{var O;return s.jsx(ss,{label:((O=x.find(U=>U.key===h))==null?void 0:O.label)??h,segments:[{status:"resolved",value:I}]},h)})})]})}if(n==="code"){const C=Qs(w,t,p,a);return s.jsx("div",{className:"w6w-resolved-params",children:s.jsx(i.JsonEditor,{value:JSON.stringify(C,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const v=w.filter(C=>!i.deepEqual(b(C.key),C.default));return w.length===0?s.jsx("div",{className:"w6w-resolved-params",children:s.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):v.length===0?s.jsx("div",{className:"w6w-resolved-params",children:s.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):s.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:v.map(C=>C.type==="vars"?s.jsx(bo,{param:C,value:t[C.key],scope:p},C.key):s.jsx(ss,{label:C.label??C.key,segments:a!=null&&a.includes(C.key)?[{status:"resolved",value:b(C.key)}]:i.resolveParamValue(b(C.key),p)},C.key))})}function Qs(e,t,o,n){const a={};for(const u of e)if(n!=null&&n.includes(u.key))a[u.key]=t[u.key]!==void 0?t[u.key]:u.default;else if(u.type==="vars"){const c=t[u.key]??u.default??[],f=i.dataVarRows(c);a[u.key]=f?i.resolveVarsJson(f,o):i.resolveParamJson(c,o)}else a[u.key]=i.resolveParamJson(t[u.key]!==void 0?t[u.key]:u.default,o);return a}function ss({label:e,segments:t}){return s.jsxs("div",{className:"w6w-resolved-row",children:[s.jsx("span",{className:"w6w-resolved-label",children:e}),s.jsx("div",{className:"w6w-resolved-value",children:s.jsx(yn,{segments:t})})]})}function bo({param:e,value:t,scope:o}){const n=t??e.default??[],a=i.dataVarRows(n);return a===null?s.jsx(ss,{label:e.label??e.key,segments:i.resolveParamValue(n,o)}):s.jsxs("div",{className:"w6w-resolved-row",children:[s.jsx("span",{className:"w6w-resolved-label",children:e.label??e.key}),a.length===0?s.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):s.jsx("div",{className:"w6w-stack",children:a.map((u,c)=>s.jsxs("div",{className:"w6w-resolved-value",children:[s.jsx("code",{children:u.key||"(no key)"})," → ",s.jsx(yn,{segments:i.resolveParamValue(u.value,o)})]},c))})]})}function yn({segments:e}){return s.jsx(s.Fragment,{children:e.map((t,o)=>s.jsx(yo,{segment:t},o))})}function yo({segment:e}){switch(e.status){case"resolved":return e.ref?s.jsxs(s.Fragment,{children:[s.jsx(ft,{kind:"var",refName:e.ref}),s.jsx(en,{value:e.value})]}):s.jsx(en,{value:e.value});case"unresolved":return s.jsxs(s.Fragment,{children:[s.jsx(ft,{kind:"var",refName:e.ref}),s.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return s.jsxs(s.Fragment,{children:[s.jsx(ft,{kind:"var",refName:e.ref}),s.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return s.jsxs(s.Fragment,{children:[s.jsx(ft,{kind:"expr"}),s.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return s.jsx(ft,{kind:"secret",refName:e.ref})}}function en({value:e}){const[t,o]=d.useState(!1),n=vo(e),a=wo(n);return a.clipped?s.jsxs(s.Fragment,{children:[t?s.jsx(Ee.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:s.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):s.jsxs("span",{children:[a.text,"…"]}),s.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":t,onClick:()=>o(u=>!u),children:t?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):s.jsx("span",{children:n})}const jo={var:"◆",secret:"🔒",expr:"ƒ"};function ft({kind:e,refName:t}){const o=e==="expr"?"expr":i.varLabel(t??"");return s.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[s.jsx("span",{className:"w6w-expr-chip-sigil",children:jo[e]}),s.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function vo(e){if(e===null)return"null";if(e===void 0)return"(not set)";if(e==="")return'""';if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function jn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function So({enabled:e,values:t,onChange:o}){const[n,a]=d.useState(null),u=d.useRef(!1),c=typeof t.code=="string"?t.code:"";return d.useEffect(()=>{if(!e||u.current)return;u.current=!0;const f=i.convertCodeBindingsToReads(c,jn(t));f.converted!==0&&(a({original:c,converted:f.converted}),o({...t,code:f.code}))},[e,c,t,o]),n?{converted:n.converted,undo:()=>{o({...t,code:n.original}),a(null)}}:null}function Co({values:e,conversion:t,readOnly:o}){const n=typeof e.code=="string"?e.code:"",a=t,u=i.findCodeBindings(n,jn(e)).length;return!a&&u===0?null:s.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[a&&s.jsxs(s.Fragment,{children:["Converted ",a.converted," reference",a.converted===1?"":"s"," to code reads",!o&&s.jsxs(s.Fragment,{children:[" · ",s.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),u>0&&" · "]}),u>0&&s.jsxs(s.Fragment,{children:[u," ",s.jsx("code",{children:"{{ }}"})," left in the code stay",u===1?"s":""," literal text — read ",u===1?"it":"them"," from"," ",s.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function tn(e,t){return{nodeIds:e.filter(o=>o.selected).map(o=>o.id),edgeIds:t.filter(o=>o.selected).map(o=>o.id)}}function No(e,t,o,n){const a=new Set(e.nodeIds),u=new Set(e.edgeIds),c=t.filter(w=>a.has(w.id)),f=[...c.filter(w=>i.isForeachStep(w.data.step)),...c.filter(w=>!i.isForeachStep(w.data.step))];let p=t,x=o,b=n;for(const w of f)x=i.bridgeDeletedBodyStep(w.id,p,x),p=p.filter(v=>v.id!==w.id),b=rs(b,w.id);return{nodes:p,edges:x.filter(w=>!u.has(w.id)),canvas:b}}function ko(e,t,o){var f;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),u=o.filter(p=>a.has(p.id)&&!n.has(p.source)&&!n.has(p.target)),c=[];if(n.size===1)c.push(i.deleteStepMessage(e.nodeIds[0],t,o));else if(n.size>1){c.push(`Delete nodes ${[...n].map(x=>`"${x}"`).join(", ")}? Their connections are removed too.`);const p=new Set;for(const x of n)if(i.isForeachStep((f=t.find(b=>b.id===x))==null?void 0:f.data.step))for(const b of i.loopBody(x,t,o))n.has(b)||p.add(b);p.size&&c.push(`Loop body steps ${[...p].map(x=>`"${x}"`).join(", ")} stay as standalone steps.`)}return u.length&&c.push(`Delete ${u.length===1?"connection":"connections"} ${u.map(p=>`"${p.source} → ${p.target}"`).join(", ")}?`),c.join(" ")}function Lt(e,t,o,n,a){const u=i.flowToWorkflow({...e,connections:n},t,o);return{nodes:u.nodes.map(({with:c,...f})=>c&&Object.keys(c).length?{...f,with:c}:f),edges:u.edges??[],connections:u.connections??{},canvas:a,positions:Object.fromEntries(t.map(c=>[c.id,c.position]))}}function Eo(e,t){const o=i.workflowToFlow({...e,...t});return{...o,nodes:o.nodes.map(n=>({...n,position:t.positions[n.id]??n.position}))}}class To{constructor(t,o=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(this,"limit");this.limit=o,this.present=JSON.stringify(t)}reset(t){this.present=JSON.stringify(t),this.past=[],this.future=[],this.group=void 0}record(t,o){const n=JSON.stringify(t);n!==this.present&&((!o||o!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=o,this.future=[])}mark(){return this.present}rollbackTo(t){if(this.present===t)return;const o=this.past.lastIndexOf(t);return o>=0&&(this.past.length=o),this.present=t,this.future=[],this.group=void 0,JSON.parse(t)}undo(){const t=this.past.pop();if(t!==void 0)return this.future.push(this.present),this.present=t,this.group=void 0,JSON.parse(t)}redo(){const t=this.future.pop();if(t!==void 0)return this.past.push(this.present),this.present=t,this.group=void 0,JSON.parse(t)}}function Gt(e){var o;const t=e;return!!(t!=null&&t.isContentEditable||(o=t==null?void 0:t.closest)!=null&&o.call(t,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Ao=64,ht=24,Ze=32;function Ft(e){var t,o;return{width:((t=e.measured)==null?void 0:t.width)??e.width??200,height:((o=e.measured)==null?void 0:o.height)??e.height??64}}function Io(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Po(e){const t=(a,u)=>{const c=new Map;for(const x of e){const b=x.position[a];c.set(b,Math.max(c.get(b)??0,Ft(x)[u]))}const f=new Map;let p=Number.NEGATIVE_INFINITY;for(const[x,b]of[...c].sort(([w],[v])=>w-v)){const w=Math.max(x,p);f.set(x,w),p=w+b+Ao}return f},o=t("x","width"),n=t("y","height");return e.map(a=>({...a,position:{x:o.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Ro(e,t,o){var f;const n=Po(i.relayoutNodes(e,t));if(!((f=o.sections)!=null&&f.length))return{nodes:n,canvas:o};const a=new Map(n.map(p=>[p.id,p])),u=(o.notes??[]).map(p=>({...p.position,...p.size}));for(const p of o.sections)p.nodes.some(x=>a.has(x))||u.push({...p.position,...p.size,y:p.position.y-Ze,height:p.size.height+Ze});const c=o.sections.map(p=>{const x=new Set(p.nodes),b=n.filter(I=>x.has(I.id));if(!b.length)return p;const w=Math.min(...b.map(I=>I.position.x))-ht,v=Math.min(...b.map(I=>I.position.y))-ht,C=Math.max(...b.map(I=>I.position.x+Ft(I).width)),L=Math.max(...b.map(I=>I.position.y+Ft(I).height)),T={x:w,y:v,width:C+ht-w,height:L+ht-v},D=[...u,...[...a.values()].filter(I=>!x.has(I.id)).map(I=>({...I.position,...Ft(I)}))].sort((I,O)=>I.y-O.y);for(const I of D){const O={...T,y:T.y-Ze,height:T.height+Ze};Io(O,I)&&(T.y=I.y+I.height+ht+Ze)}const h=T.y-v;for(const I of b)a.set(I.id,{...I,position:{x:I.position.x,y:I.position.y+h}});return u.push({...T,y:T.y-Ze,height:T.height+Ze}),{...p,position:{x:T.x,y:T.y},size:{width:T.width,height:T.height}}});return{nodes:n.map(p=>a.get(p.id)??p),canvas:{...o,sections:c}}}const Kt=6;function Mo(e){let t=2166136261;for(let o=0;o<e.length;o++)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return t>>>0}function Lo(e){const t=new Map;let o=new Set;for(const n of[...new Set(e)].sort()){o.size===Kt&&(o=new Set);let a=Mo(n)%Kt;for(;o.has(a);)a=(a+1)%Kt;o.add(a),t.set(n,a+1)}return t}function as(e){return`var(--w6w-loop-${e})`}function vn(e,t){const o=[],n=new Set([e]);for(let a=t.get(e);a&&!n.has(a);a=t.get(a))n.add(a),o.unshift(a);return o}function Fo(e,t,o){return t.size===0?e:e.map(n=>{var c;if(((c=n.data)==null?void 0:c.when)!=="each")return n;const a=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),u=a?t.get(a):void 0;return u===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":as(u)}}})}function Do(e,t){const o=t.get(e);return o===void 0?void 0:{"--w6w-loop-color":as(o)}}function Oo(e){const t=[];for(const o of e){const n=i.isForeachStep(o.data.step);(n||o.data.loopOf)&&t.push([o.id,n?1:0,o.data.loopOf])}return JSON.stringify(t)}function _o(e){const t=JSON.parse(e);return{tones:Lo(t.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(t.map(o=>[o[0],o[2]]))}}const sn="Paused — test runs stop before this node",nn="Disabled — skipped in every run";function Qe(e){var t;return((t=e.ui)==null?void 0:t.paused)===!0}function We(e){return e.disabled===!0}function Sn(e,t){const{ui:o,...n}=e,{paused:a,...u}=o??{},c=t?{...u,paused:!0}:u;return Object.keys(c).length>0?{...n,ui:c}:n}function Cn(e,t){const{disabled:o,...n}=e;return t?{...n,disabled:!0}:n}function ns(e,t){return e.filter(o=>o.id!==t&&Qe(o)).map(o=>o.id)}const Wo=["nodes","steps"];function on(e,t){for(const o of Wo){const n=`${o}.${t}.output`;if(!e.startsWith(n))continue;const a=e.slice(n.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function Dt(e,t,o){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=i.parseRootAnchoredTemplate(e);let a=!1;const u=n.map(c=>{if(c.kind!=="var"||c.ref===void 0)return c;const f=on(c.ref,t);return f===null?c:(a=!0,o.includes(c.ref)||o.push(c.ref),{...c,ref:f})});return a?Ae.serializeTemplate(u):e}if(i.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=on(n,t);return a===null?e:(o.includes(n)||o.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(u=>{const c=Dt(u,t,o);return c!==u&&(n=!0),c});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[u,c]of Object.entries(e)){const f=Dt(c,t,o);f!==c&&(n=!0),a[u]=f}return n?a:e}return e}function $o(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const t=i.parseRootAnchoredTemplate(e);return t.length===1&&t[0].kind==="var"}return i.isDollarPath(e)&&typeof e.$=="string"}function Nn(e){return Array.isArray(e)&&e.length===1&&$o(e[0])}function Bo(e){var t;try{const o=i.normalizeInput(e);if(!Array.isArray(o.nodes))return{};const n={},a=(c,f)=>{const p=Object.hasOwn(n,c)?n[c]:[];p.push(f),n[c]=p},u=new Map(o.nodes.map(c=>[c.id,c]));for(const[c,f]of Object.entries(i.definitionLoops(o))){const p=u.get(c);if(p&&Nn((t=p.with)==null?void 0:t.items)&&a(c,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){a(c,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const x of f.body){const b=u.get(x);if(!(b!=null&&b.with))continue;const w=[];Dt(b.with,c,w),w.length>0&&a(x,{code:"foreach_body_refs_output",foreachId:c,refs:w,fix:{kind:"use_current_item",foreachId:c,label:"Use Current item"}})}}return n}catch{return{}}}function Vo(e){const t=new Set,o=n=>{if(typeof n=="string")t.add(n);else if(Array.isArray(n))for(const a of n)o(a)};return o(e),t}function zo(e){var t,o;try{const n=i.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(P=>typeof P=="object"&&P!==null&&typeof P.id=="string"),u=i.effectiveEdges({...n,nodes:a}).filter(P=>typeof(P==null?void 0:P.from)=="string"&&typeof(P==null?void 0:P.to)=="string"),c=[];for(const P of a)try{const R=Ae.staticWritePaths(Ae.effectiveStateConfig((t=P.uses)==null?void 0:t.app,(o=P.uses)==null?void 0:o.action,P.state));R.length>0&&c.push({id:P.id,paths:R})}catch{}if(c.length<2)return[];const f=new Map;for(const P of a)for(const R of i.controlOwnedIds(P))f.has(R)||f.set(R,P.id);const p=P=>{const R=[P];let S=P;for(;f.has(S)&&(S=f.get(S),!R.includes(S));)R.push(S);return R},x=P=>{const R=p(P);return R[R.length-1]},b=new Map;for(const P of u){const R=b.get(P.from)??[];R.push(P.to),b.set(P.from,R)}const w=new Map,v=P=>{const R=w.get(P);if(R)return R;const S=new Set,$=[...b.get(P)??[]];for(;$.length>0;){const K=$.pop();if(!S.has(K)){S.add(K);for(const V of b.get(K)??[])$.push(V)}}return w.set(P,S),S},C=(P,R)=>P===R||v(P).has(R),L=a.filter(P=>{var R;return((R=P.uses)==null?void 0:R.app)===i.CONTROL_APP&&P.uses.action==="parallel"}).map(P=>{var S;const R=(S=P.with)==null?void 0:S.branches;return Array.isArray(R)?R.map(Vo):[]}),T=(P,R)=>{for(const S of p(R)){const $=P.findIndex(K=>K.has(S));if($>=0)return $}return-1},D=[];for(const P of a){if(P.fanOut!=="parallel")continue;const R=new Map;for(const S of u){if(S.from!==P.id||i.isEachLink(S))continue;const $=S.when??"success",K=R.get($)??[];K.push(S.to),R.set($,K)}for(const S of R.values())S.length>=2&&D.push(S)}const h=(P,R)=>{for(const K of L){const V=T(K,P),m=T(K,R);if(V>=0&&m>=0&&V!==m)return!0}const S=x(P),$=x(R);return S===$||v(S).has($)||v($).has(S)?!1:D.some(K=>K.some((V,m)=>K.some((_,de)=>m!==de&&C(V,S)&&C(_,$))))},I=new Set,O=[];for(let P=0;P<c.length;P++)for(let R=P+1;R<c.length;R++){const S=c[P],$=c[R];if(!(S.id===$.id||!h(S.id,$.id)))for(const K of S.paths)for(const V of $.paths){if(!Ae.statePathsOverlap(K,V))continue;const m={code:"state_parallel_write",nodes:[S.id,$.id].sort(),path:[...K.length<=V.length?K:V]},_=JSON.stringify([m.nodes,m.path]);I.has(_)||(I.add(_),O.push(m))}}const U=(P,R)=>P<R?-1:P>R?1:0;return O.sort((P,R)=>U(P.code,R.code)||U(P.nodes.join(","),R.nodes.join(","))||U(P.path.join("."),R.path.join(".")))}catch{return[]}}function Ho(e){try{const t={};for(const o of zo(e))for(const n of o.nodes){const a=Object.hasOwn(t,n)?t[n]:[];a.push({code:o.code,path:[...o.path],with:o.nodes.filter(u=>u!==n)}),t[n]=a}return t}catch{return{}}}function kn(e,t){var o;if(t.code==="foreach_wrapped_items"){const n=(o=e.with)==null?void 0:o.items;return!e.with||!Nn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(t.code==="foreach_body_refs_output"){if(!e.with)return e;const n=Dt(e.with,t.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function rn(e,t,o){return e&&e.nodeId===t&&e.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(e.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function Jo(e,t,o,n,a){var p;const u=(p=n.find(x=>x.id===e))==null?void 0:p.data.step,c=i.loopMembership(n,a)[e]!==void 0,f=o==="success"&&c?"each":o;return f==="each"&&!c&&!i.isForeachStep(u)?null:i.loopRefusal(e,t,f,n,a)}function Ot(e,t){var o;return(o=e.nodes??e.steps)==null?void 0:o[t]}function os(e,t){const o=Ot(e,t);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const Uo=new Set(["succeeded","failed","canceled"]);function qo(e,t,o=[]){var u,c;if(!e||[...o,t].some(f=>os(e,f)))return"no-run";const n=Ot(e,t);if(n)return n.status;const a=new Set;for(const f of Object.values(e.nodes??e.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const p of f.iterations){const x=(c=(u=p==null?void 0:p.nodes)==null?void 0:u[t])==null?void 0:c.status;x&&a.add(x)}for(const f of["failed","running","succeeded","skipped"])if(a.has(f))return f;return"pending"}const an={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function En(e,t){const o=t!==void 0&&Uo.has(t);switch(e){case"no-run":return an;case"pending":return o?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return an}}function Go(e,t,o,n,a){var c;if(!e||os(e,t)||a!==void 0&&os(e,a))return;const u=Ko(e,t,o,n);return u==="taken"&&a!==void 0&&((c=Ot(e,a))==null?void 0:c.status)==="skipped"?"skipped":u}function Ko(e,t,o,n){const a=Ot(e,t);if(!a)return;if(o==="each")return a.status==="skipped"?"skipped":void 0;const u=o??"success",c=a.output,f=n===i.FOREACH_DONE_ROUTE&&!(c&&typeof c=="object"&&"route"in c);if(n!==void 0&&!f&&a.status==="succeeded")return c&&typeof c=="object"&&"matched"in c?n==="false"!=(c.matched===!0)?"taken":"skipped":c&&typeof c=="object"&&"route"in c&&c.route===n?"taken":"skipped";if(a.status==="succeeded")return u==="success"?"taken":"skipped";if(a.status==="failed")return u==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const cn={fields:[],sampleValues:{}};function cs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Xo(e,t){var x;const o=e.map(b=>b.id),n=new Set(o),a=new Map(o.map(b=>[b,0])),u=new Map(o.map(b=>[b,[]]));for(const b of t)!n.has(b.source)||!n.has(b.target)||((x=u.get(b.source))==null||x.push(b.target),a.set(b.target,(a.get(b.target)??0)+1));const c=[],f=o.filter(b=>a.get(b)===0);for(;f.length>0;){const b=f.shift();c.push(b);for(const w of u.get(b)??[]){const v=(a.get(w)??0)-1;a.set(w,v),v===0&&f.push(w)}}const p=new Set(c);for(const b of o)p.has(b)||c.push(b);return c}const Yo=new Set(["string","number","boolean","object","array"]);function gt(e){if(!Array.isArray(e))return;const t={type:"object",fields:{}};let o=!1;for(const n of e){if(!cs(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let u=t;for(const p of a.slice(0,-1)){const x=u.fields[p];(x==null?void 0:x.type)!=="object"&&(u.fields[p]={type:"object",fields:{}}),u=u.fields[p]}const c=typeof n.type=="string"&&Yo.has(n.type)?n.type:"string";let f;if(c==="array"){const p=gt(n.items);f=p?{type:"array",items:p}:{type:"array"}}else c==="object"?f=gt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:c};u.fields[a[a.length-1]]=f,o=!0}return o?t:void 0}function Zo(e,t){var x,b,w,v,C,L,T;const o=e.data.step,n=((x=t.testOutputs)==null?void 0:x[o.id])??((b=t.persistedOutputs)==null?void 0:b[o.id]);if(n!=null)return n;const{app:a,action:u}=o.uses;if(a===i.TRIGGER_APP&&((w=i.internalNodeDef(a,u))==null?void 0:w.group)==="trigger"){const D=i.fieldsToParams(i.asFieldDefs((v=o.with)==null?void 0:v.fields)).map(h=>({key:h.key}));return i.shapeToSkeleton(gt(D))}const c=(C=i.internalNodeDef(a,u))==null?void 0:C.output;if(c&&c.length>0)return i.shapeToSkeleton(gt(c));const f=o.uses.trigger===!0?(L=t.triggerDef)==null?void 0:L.call(t,a,u):(T=t.actionDef)==null?void 0:T.call(t,a,u),p=gt(f==null?void 0:f.output);return p?i.shapeToSkeleton(p):f==null?void 0:f.sample}function Qo(e,t){var f,p,x,b,w;const o=e.data.step,n=(f=t.previewOutputs)==null?void 0:f[o.id];if(n!=null)return n;const{app:a,action:u}=o.uses,c=o.uses.trigger===!0?(x=(p=t.shapes)==null?void 0:p.triggerDef)==null?void 0:x.call(p,a,u):(w=(b=t.shapes)==null?void 0:b.actionDef)==null?void 0:w.call(b,a,u);return c==null?void 0:c.sample}function ei(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function ln(e,t){const o=cs(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:t||(o[n.key]=ei(n.type)));return o}function Xt(e){return(i.inferOutputFields(e)??[]).map(t=>t.key)}function ti(e){const{anchorId:t,nodes:o,edges:n}=e;if(!t)return cn;const a=e.shapes??{},u=e.floating?new Set(o.map(S=>S.id)):i.ancestorIds(t,n);u.delete(t);const c=new Map(o.map(S=>[S.id,S])),f=[],p=[],x=new Map;for(const S of Xo(o,n)){if(!u.has(S))continue;const $=c.get(S);if(!$)continue;const{app:K,action:V}=$.data.step.uses,m=Ae.effectiveStateConfig(K,V,$.data.step.state);if(m.mode==="off")continue;const _=Zo($,a);if(_!==void 0){const{ops:ue}=Ae.computeStateWrites(m,_);f.push(...ue);for(const je of Xt(Ae.foldState({},ue))){const ie=x.get(je)??new Set;ie.add(S),x.set(je,ie)}}const de=Qo($,e);de!==void 0&&p.push(...Ae.computeStateWrites(m,de).ops)}const b=ln(e,!1),w=Ae.foldState(b,f),v=Xt(w);if(v.length===0)return cn;const C=new Set(Xt(b)),L=new Map,T=new Map;for(const S of n)u.has(S.source)&&(!u.has(S.target)&&S.target!==t||(L.set(S.target,[...L.get(S.target)??[],S.source]),T.set(S.source,[...T.get(S.source)??[],S.target])));const D=[...u].filter(S=>!(L.get(S)??[]).length),h=S=>{const $=new Set,K=D.filter(V=>!S.has(V));for(;K.length>0;){const V=K.pop();if(V===t)return!1;if(!$.has(V)){$.add(V);for(const m of T.get(V)??[])S.has(m)||K.push(m)}}return!0},I=Ae.foldState(ln(e,!0),p),O=p.length>0?Ae.foldState({},p):void 0,U=cs(O)&&Object.keys(O).length>0?O:void 0,P=[],R={};for(const S of v){const $=x.get(S)??new Set,K=C.has(S)||$.size>0&&h($);P.push({key:S,path:!0,paths:K?"all":"some"});const V=i.valueAtPath(I,S);V!==void 0&&(R[`state.${S}`]=V)}return{fields:P,sampleValues:R,...U?{written:U}:{}}}const si={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},dn="Never fired";function ni(e){if(!e)return dn;const t=new Date(e);return Number.isNaN(t.getTime())?dn:`Last fired ${t.toISOString().slice(0,16).replace("T"," ")} UTC`}function oi(e,t){var a;if(!(e!=null&&e.status))return null;const o=si[e.status];if(!o)return null;const n=e.status==="failed";return{label:o.label,tone:o.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:ni(e.lastFireAt),retryVisible:n&&t}}function ii(e){const t=new Map;for(const o of e)o.nodeId&&t.set(o.nodeId,o);return t}function ri(e){return(e??[]).filter(t=>{var o;return((o=t.uses)==null?void 0:o.trigger)===!0})}function ai(e,t){const[o,n]=d.useState({}),a=d.useRef(new Set),u=JSON.stringify([...new Set(t.map(c=>c.data.step.uses.app))].filter(c=>c&&!i.isInternalApp(c)).sort());return d.useEffect(()=>{const c=JSON.parse(u).filter(f=>!a.current.has(f));if(c.length!==0){for(const f of c)a.current.add(f);Promise.all(c.map(async f=>{try{return[f,await e.getAppActions(f)]}catch{return a.current.delete(f),null}})).then(f=>{const p=f.filter(x=>x!==null);p.length!==0&&n(x=>({...x,...Object.fromEntries(p)}))})}},[e,u]),o}function ci(e,t){const[o,n]=d.useState({}),a=d.useRef(new Set),u=JSON.stringify([...new Set(t.filter(c=>c.data.step.uses.trigger===!0).map(c=>c.data.step.uses.app))].filter(c=>c&&!i.isInternalApp(c)).sort());return d.useEffect(()=>{const c=e.getAppTriggers;if(typeof c!="function")return;const f=JSON.parse(u).filter(p=>!a.current.has(p));if(f.length!==0){for(const p of f)a.current.add(p);Promise.all(f.map(async p=>{try{return[p,await c.call(e,p)]}catch{return a.current.delete(p),null}})).then(p=>{const x=p.filter(b=>b!==null);x.length!==0&&n(b=>({...b,...Object.fromEntries(x)}))})}},[e,u]),o}function li(e){return(t,o)=>{var n,a;return(a=(n=e[t])==null?void 0:n.find(u=>u.key===o))==null?void 0:a.ports}}const di="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function un(e,t,o,n){const a=e.find(u=>u.id===t);return[o,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ls=d.createContext(void 0),ds=d.createContext(new Map),us=d.createContext({tones:new Map,loopOf:new Map});function pn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const ps=d.createContext(new Map),Tn=d.createContext({byNode:new Map,subs:[]});function ui({apps:e,registration:t,children:o}){return s.jsx(ps.Provider,{value:e,children:s.jsx(Tn.Provider,{value:t,children:o})})}const fs=d.createContext(null);function pi(e){return s.jsx(oe.ReactFlowProvider,{children:s.jsx(fi,{...e})})}function fn(e,t){let o=t.length+1;for(;t.includes(`${e}-${o}`);)o++;return`${e}-${o}`}function Yt(e){var t,o;return{x:e.position.x,y:e.position.y,w:((t=e.measured)==null?void 0:t.width)??e.width??200,h:((o=e.measured)==null?void 0:o.height)??e.height??64}}function fi({onConnectionResourcesChange:e,value:t,onChange:o,readOnly:n,height:a=480,apps:u,exprOptions:c,project:f,runState:p,stepProblems:x,onTestRun:b,fitViewKey:w,onRunFromNode:v}){var Hs,Js,Us,qs,Gs,Ks,Xs;const C=i.useW6WApi(),L=d.useMemo(()=>new Map((u??[]).map(r=>[r.id,r])),[u]),T=yi(t),[D,h]=d.useState(null),I=d.useMemo(()=>i.centralizeConnections(t),[t.id]),O=d.useMemo(()=>i.workflowToFlow(I),[I]),[U,P]=d.useState(I.connections??{}),R=d.useRef(U),S=d.useCallback(r=>{R.current=r,P(r)},[]),$=d.useCallback(r=>{const l=i.centralizeConnections({nodes:[r],connections:R.current});return l.connections!==R.current&&S(l.connections),l.nodes[0]},[S]),K=d.useMemo(()=>i.storedViewport(t),[t.id]),V=((Hs=t.settings)==null?void 0:Hs.savePosition)!==!1,[m,_,de]=oe.useNodesState(O.nodes),ue=ai(C,m),je=ci(C,m),ie=d.useMemo(()=>li(ue),[ue]),[k,X,E]=oe.useEdgesState(O.edges),[W,B]=d.useState(null),ee=d.useMemo(()=>t.canvas??{},[t.id]),[H,z]=d.useState(ee),[J]=d.useState(()=>new To(Lt(I,O.nodes,O.edges,U,ee))),Z=d.useRef(),[pe,Je]=d.useState(0),[De,rt]=d.useState(!1),[ve,Ue]=d.useState(null),[Ie,me]=d.useState(null),[ae,Ne]=d.useState(null),[$e,te]=d.useState(!1),mt=d.useRef({});d.useEffect(()=>{$e||(mt.current={})},[$e]);const[re,Pe]=d.useState(null),[Oe,ke]=d.useState("props"),[we,qe]=d.useState(null),[ye,Be]=d.useState(null),[Re,Me]=d.useState(null),at=d.useRef(!1),Se=d.useRef(null),[xe,_e]=d.useState(null),{screenToFlowPosition:Le,fitView:Fe}=oe.useReactFlow(),ct=i.useEffectiveTheme();d.useEffect(()=>{_(O.nodes),X(O.edges),B(null),Ne(null),Me(null),Pe(null),qe(null),z(ee),S(I.connections??{}),J.reset(Lt(I,O.nodes,O.edges,I.connections??{},ee)),Z.current=void 0},[O,ee,I,_,X,S,J]),d.useEffect(()=>{_(r=>{const l=new Map(i.stampLoopOf(r,k).map(g=>[g.id,g.data.loopOf]));return r.map(g=>{const y=qo(p,g.id,vn(g.id,l));return g.data.stepStatus===y&&g.data.runStatus===(p==null?void 0:p.status)?g:{...g,data:{...g.data,stepStatus:y,runStatus:p==null?void 0:p.status}}})}),X(r=>r.map(l=>{var A;const g=i.edgeLane(l),y=Go(p,l.source,g,typeof((A=l.data)==null?void 0:A.route)=="string"?l.data.route:void 0,l.target),j=i.edgeVisuals(g,y);return l.className===j.className&&l.label===j.label?l:{...l,className:j.className,label:j.label}}))},[p,O,pe,_,X]),d.useEffect(()=>{_(r=>i.applyStepProblems(r,x))},[x,O,pe,_]);const et=d.useCallback((r,l)=>{var j,A;const{canvas:g,...y}=r;return!((j=l.notes)!=null&&j.length)&&!((A=l.sections)!=null&&A.length)?y:{...y,canvas:mo(l,t.canvas,V)}},[t.canvas,V]),Y=d.useCallback((r,l,g)=>{J.record(Lt(t,r,l,R.current,g??H),$e?mt.current:Z.current),o(et(i.flowToWorkflow({...t,connections:R.current},r,l),g??H))},[t,o,H,et,J,$e]),tt=d.useRef(()=>{});tt.current=r=>{if(n)return;const l=i.editConnectionResources(m.map(y=>y.data.step),R.current,r),g=m.map((y,j)=>({...y,data:{...y.data,step:l.nodes[j]}}));S(l.connections),_(g),Y(g,k)};const Ge=d.useCallback(r=>tt.current(r),[]),wt=d.useCallback(r=>{B(r),Ne(null),_(l=>l.map(g=>({...g,selected:g.id===r}))),X(l=>l.map(g=>({...g,selected:!1}))),Fe({nodes:[{id:r}],duration:300,maxZoom:1})},[_,X,Fe]),[lt,ce]=d.useState(null),xt=d.useMemo(()=>lt?m.map(r=>r.id===lt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):m,[m,lt]),bt=m.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),yt=JSON.stringify(bt),jt=JSON.stringify([...L]);d.useEffect(()=>{e==null||e({workflowId:t.id,nodes:bt,apps:L,connections:U,readOnly:n,edit:Ge,focusNode:wt,highlightNode:ce})},[e,t.id,yt,jt,U,n,Ge,wt]),d.useEffect(()=>()=>e==null?void 0:e(null),[e]);const vt=d.useCallback(r=>i.canConnect(r.source,r.target,m,k,ie,i.routeFromHandle(r.sourceHandle)),[m,k,ie]),[N,G]=d.useState(null),se=d.useRef(null),he=d.useRef(null);d.useEffect(()=>{_(r=>i.stampLoopOf(r,k))},[k,_]);const st=d.useCallback(r=>{if(n)return;const l=i.applyConnect(r.source,r.target,m,k,i.laneForSourceHandle(r.sourceHandle),ie,i.routeFromHandle(r.sourceHandle));if(!l){const g=i.laneForSourceHandle(r.sourceHandle),y=i.connectRefusal(r.source,r.target,m,k,g,ie,i.routeFromHandle(r.sourceHandle));if(y&&y.refused==="loop"){G({nodeId:r.source,reason:y.reason});return}if(y){const A=k.find(F=>F.source===r.source&&i.edgeLane(F)===g);A&&(X(k.map(F=>({...F,selected:F.id===A.id}))),Ne(A.id),Ke({edgeId:A.id,message:pn(y.cap)}));return}const j=i.connectConflict(r.source,r.target,m,k,i.laneForSourceHandle(r.sourceHandle));if(!j)return;X(k.map(A=>({...A,selected:A.id===j}))),Ne(j),Ke({edgeId:j,message:i.idClashMessage("Can’t draw that edge",j,un(k,j,r.source,r.target))});return}Ke(null),G(null),X(l),Y(m,l)},[k,m,X,Y,n,ie]),Wn=d.useCallback((r,l)=>{var q,Q,le;if(n||l.isValid)return;const g=l.fromNode;if(!g)return;const y=((q=l.fromHandle)==null?void 0:q.type)==="target"?"target":"source",j=l.toNode;if(j&&y==="source"){const ne=Jo(g.id,j.id,rn(he.current,g.id,l.fromHandle),m,k);if(ne){G({nodeId:g.id,reason:ne});return}}const A=(Q=m.find(ne=>ne.id===g.id))==null?void 0:Q.data.step;if(A){const ne=i.nodePortsForStep(A,ie);if((y==="source"?ne.out:ne.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,M=Le({x:F.clientX,y:F.clientY});_e({nodeId:g.id,handleType:y,position:M,lane:rn(he.current,g.id,l.fromHandle),route:i.routeFromHandle((le=l.fromHandle)==null?void 0:le.id)}),te(!0)},[n,Le,m,k,ie]),gs=d.useCallback((r,l,g)=>{if(n)return;const y=m.find(q=>q.id===r);if(!y)return;const j=Yt(y),A=i.laneForSourceHandle(g),F=120,M=l==="target"?{x:j.x-j.w-F,y:j.y}:A==="error"?{x:j.x,y:j.y+j.h+F}:A==="each"?{x:j.x+j.w+F,y:j.y-j.h-F/2}:{x:j.x+j.w+F,y:j.y};_e({nodeId:r,handleType:l,position:M,lane:A,route:i.routeFromHandle(g)}),te(!0)},[n,m]),ms=d.useCallback(r=>{n||Me({nodeIds:[r],edgeIds:[]})},[n]),$n=d.useCallback(r=>{if(n)return;const l=No(r,m,k,H);_(l.nodes),X(l.edges),z(l.canvas),l.nodes.some(g=>g.id===W)||B(null),l.nodes.some(g=>g.id===re)||Pe(null),l.edges.some(g=>g.id===ae)||Ne(null),Y(l.nodes,l.edges,l.canvas)},[m,k,H,_,X,Y,n,W,re,ae]),ws=d.useCallback(()=>{if(n)return;const r=Ro(m,k,H);_(r.nodes),z(r.canvas),at.current=!0,Y(r.nodes,k,r.canvas)},[m,k,H,_,Y,n]),Bn=d.useCallback(()=>{n||ws()},[n,ws]);d.useEffect(()=>{at.current&&(at.current=!1,Fe({duration:300}))},[m,Fe]);const xs=d.useRef(w);d.useEffect(()=>{Object.is(xs.current,w)||(xs.current=w,Fe({duration:300}))},[w,Fe]);const[St,Ke]=d.useState(null),nt=d.useMemo(()=>k.find(r=>r.id===ae)??null,[k,ae]),Vn=d.useCallback(r=>{if(n||!ae)return;const l=k.find(F=>F.id===ae);if(!l||i.edgeLane(l)===r)return;const g=i.edgeWhenConflict(k,ae,r,m),y=i.relaneRefusal(k,ae,r,m,ie),j=g||y?null:i.setEdgeWhen(k,ae,r,m,ie);if(!j){if(y){Ke({edgeId:ae,message:pn(y.cap)});return}Ke({edgeId:ae,message:g?i.idClashMessage("Can’t switch this edge",g,un(k,g,l.source,l.target)):"This edge can’t be switched right now."});return}Ke(null),X(j);const A=j.find(F=>F.source===l.source&&F.target===l.target&&i.edgeLane(F)===r);Ne((A==null?void 0:A.id)??null),Y(m,j)},[k,m,X,Y,n,ae,ie]),zn=d.useCallback(r=>{if(n)return;const l=k.filter(g=>g.id!==r);l.length!==k.length&&(X(l),ae===r&&Ne(null),Y(m,l))},[m,k,X,Y,n,ae]),Wt=d.useCallback(r=>{if(n)return;const l=r.map(A=>m.find(F=>F.id===A)).filter(A=>A!==void 0);if(l.length===0)return;const g=m.map(A=>A.id),y=l.map(A=>{const F=i.suggestStepId(g,`${A.data.step.id}_copy`);g.push(F);const M={...i.stripBody(structuredClone(A.data.step)),id:F};return{id:F,type:A.type,position:{x:A.position.x+40,y:A.position.y+60},data:{step:M,isInternal:A.data.isInternal},...l.length>1?{selected:!0}:{}}}),j=[...l.length>1?m.map(A=>A.selected?{...A,selected:!1}:A):m,...y];_(j),B(y[0].id),Y(j,k)},[m,k,_,Y,n]),bs=d.useCallback(r=>Wt([r]),[Wt]),Hn=d.useCallback(r=>{if(n)return;const l=i.isInternalApp(r.uses.app),g=m.map(ne=>ne.id),y=r.id&&!i.stepNameError(r.id,g)?r.id:i.suggestStepId(g,i.slugifyLabel(i.internalNodeLabel(r.uses.app,r.uses.action))),j=$({id:y,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),A={id:y,type:l?"control":"step",position:(xe==null?void 0:xe.position)??(ye==null?void 0:ye.position)??{x:80,y:80+m.length*24},data:{step:j,isInternal:l}},F=ye!=null&&ye.replaces?m.find(ne=>ne.id===ye.replaces):void 0;if(F&&i.isTriggerStep(r.uses)){const ne={...A,position:F.position},fe=[...m.filter(pt=>pt.id!==F.id),ne],ge=i.renameStepInEdges(k,F.id,y),Te=Qt(H,F.id,y);return _(fe),X(ge),z(Te),G(null),B(y),Y(fe,ge,Te),y}const M=[...m,A];let q=k,Q=null;const le=(ne,fe,ge,Te)=>{const pt=i.connectRefusal(ne,fe,M,k,ge,ie);pt&&pt.refused==="loop"&&(Q={nodeId:Te,reason:pt.reason})};if(xe){const[ne,fe]=xe.handleType==="target"?[y,xe.nodeId]:[xe.nodeId,y],ge=i.applyConnect(ne,fe,M,k,xe.lane,ie,xe.route);ge||le(ne,fe,xe.lane,xe.nodeId),q=ge??k}else{const ne=m.find(fe=>i.isTriggerStep(fe.data.step.uses));if(i.isTriggerStep(r.uses)){if(!ne){const fe=i.findChainRoot(m,k);if(fe){const ge=i.applyConnect(y,fe.id,M,k,"success",ie);ge||le(y,fe.id,"success",fe.id),q=ge??k}}}else{const ge=(ne&&!k.some(Te=>Te.source===ne.id)?ne:void 0)??i.findChainTail(m,k);if(ge){const Te=i.applyConnect(ge.id,y,M,k,"success",ie);Te||le(ge.id,y,"success",ge.id),q=Te??k}}}return _(M),q!==k&&X(q),G(Q),B(y),Y(M,q),y},[m,k,_,X,Y,n,xe,ye,ie,$,H]),ys=d.useCallback((r,l)=>{var q;let g=l;const y=(q=m.find(Q=>Q.id===r))==null?void 0:q.data.step;if(l.uses.connection&&!l.uses.connectionRef&&(y!=null&&y.uses.connectionRef)&&y.uses.app===l.uses.app){const Q=i.selectNodeConnection(i.withConnectionRef(l,y.uses.connectionRef),l.uses.connection,m.map(le=>le.data.step),R.current);S(Q.connections),g=Q.step}else g=$(l);const j=g.id!==r;if(j&&m.some(Q=>Q.id===g.id))return;const A=m.map(Q=>Q.id===r?{...Q,id:g.id,data:{step:g,isInternal:i.isInternalApp(g.uses.app)}}:Q);if(j){const Q=i.renameStepInEdges(k,r,g.id),le=Qt(H,r,g.id);_(A),X(Q),z(le),W===r&&B(g.id),re===r&&Pe(g.id),Y(A,Q,le);return}_(A);const F=new Set(i.routesForStep(g).map(Q=>Q.id)),M=k.filter(Q=>{var le;return Q.source!==g.id||((le=Q.data)==null?void 0:le.route)===void 0||F.has(String(Q.data.route))});M.length!==k.length&&X(M),Y(A,M)},[m,k,H,_,X,W,re,Y,$,S]),Xe=d.useCallback(r=>{n||(z(r),Y(m,k,r))},[n,m,k,Y]),Jn=d.useCallback(()=>{var j;if(n)return;const r=(j=Se.current)==null?void 0:j.getBoundingClientRect(),l=r?Le({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},g=H.notes??[],y={id:fn("note",g.map(A=>A.id)),color:"#facc15",position:{x:Math.round(l.x-100),y:Math.round(l.y-60)},size:{width:200,height:120},content:""};Xe(ts({...H,notes:[...g,y]}))},[n,H,Le,Xe]),Un=d.useCallback((r,l)=>{if(n)return;const g=l?Math.min(r.x,l.x):r.x,y=l?Math.min(r.y,l.y):r.y,j=l?Math.abs(l.x-r.x):360,A=l?Math.abs(l.y-r.y):240,F=m.filter(ne=>{const fe=Yt(ne),ge=fe.x+fe.w/2,Te=fe.y+fe.h/2;return ge>=g&&ge<=g+j&&Te>=y&&Te<=y+A}).map(ne=>ne.id),M=H.sections??[],q=fn("section",M.map(ne=>ne.id)),Q={id:q,title:"Section",color:"#6366f1",position:{x:Math.round(g),y:Math.round(y)},size:{width:Math.round(j),height:Math.round(A)},nodes:[]},le={...H,sections:[...M,Q]};Xe(ts(es(le,q,F)))},[n,m,H,Xe]);d.useEffect(()=>{if(!De)return;const r=l=>{l.key==="Escape"&&(rt(!1),Ue(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[De]);const qn=d.useCallback((r,l)=>{var F;if(n)return;const g=(F=H.sections)==null?void 0:F.find(M=>M.id===r);if(!g)return;const y=new Set(g.nodes),j=m.map(M=>y.has(M.id)?{...M,position:{x:M.position.x+l.dx,y:M.position.y+l.dy}}:M),A={...H,sections:(H.sections??[]).map(M=>M.id===r?{...M,position:{x:M.position.x+l.dx,y:M.position.y+l.dy}}:M)};_(j),z(A),Y(j,k,A)},[n,H,m,k,_,Y]),Gn=d.useCallback((r,l)=>{if(n)return;const g=r==="note"?{...H,notes:(H.notes??[]).filter(y=>y.id!==l)}:{...H,sections:(H.sections??[]).filter(y=>y.id!==l)};Xe(g)},[n,H,Xe]),Kn=r=>{let l=H;for(const g of r){const y=Yt(g),j=y.x+y.w/2,A=y.y+y.h/2,F=(l.sections??[]).find(q=>j>=q.position.x&&j<=q.position.x+q.size.width&&A>=q.position.y&&A<=q.position.y+q.size.height),M=bn(l,g.id);F?(M.length!==1||M[0]!==F.id)&&(l=es(l,F.id,[g.id])):M.length>0&&(l=rs(l,g.id))}return l},$t=d.useCallback((r,l,g)=>{(async()=>{const y=await C.saveStepTest(t.id,r,l).catch(j=>(console.error("step run fixture save failed",j),null));await C.recordStepTestRun(t.id,r,{stepTestId:(y==null?void 0:y.id)??null,status:g.status,input:l.input,output:g.output,error:g.error,...g.meta?{meta:g.meta}:{}})})().catch(y=>{console.error("step run persist failed",y)})},[C,t.id]),js=d.useCallback(r=>{const l=m.find(g=>g.id===r);!l||!v&&i.isControlApp(l.data.step.uses.app)||h({stepId:r,status:"collect"})},[m,v]),Xn=d.useCallback(async(r,l,g)=>{if(!v)return;const y=m.find(F=>F.id===r);if(!y)return;const j=i.isTriggerStep(y.data.step.uses),A={stopAt:ns(m.map(F=>F.data.step),r),...g?{state:g}:{},...j?{input:l}:{}};h({stepId:r,status:"running"});try{await v(r,A),h(null)}catch(F){const M=F;h({stepId:r,status:"error",error:M.message??String(F),errorCode:M.code})}},[m,v]),Ct=d.useCallback((r,l)=>{if(n)return;const g=m.map(y=>y.id===r?{...y,data:{...y.data,step:l(y.data.step)}}:y);_(g),Y(g,k)},[m,k,_,Y,n]),vs=d.useCallback(r=>Ct(r,l=>Sn(l,!Qe(l))),[Ct]),Ss=d.useCallback(r=>Ct(r,l=>Cn(l,!We(l))),[Ct]),Yn=d.useCallback(async(r,l,g)=>{b==null||b();const y=m.find(q=>q.id===r);if(!y)return;const j=y.data.step,A=i.isTriggerStep(j.uses),F=A?{input:l}:{...j.with??{},...l},M=A?{input:l,with:l}:{input:l,with:F};h({stepId:r,status:"running"});try{const q=await C.invokeAction(j.uses.app,j.uses.action,F,{connectionId:i.connectionIdFor(j,R.current),project:f,...g?{state:g}:{},workflowId:t.id}),Q=q.logs,le=q.meta;h({stepId:r,status:"done",value:q.value,logs:Q,...le?{meta:le}:{}}),$t(r,M,{status:"succeeded",output:q.value,...le?{meta:le}:{}})}catch(q){const Q=q;h({stepId:r,status:"error",error:Q.message??String(q),errorCode:Q.code}),$t(r,M,{status:"failed",error:Q.message??String(q)})}},[m,C,$t,f,b,t.id]),Bt=d.useMemo(()=>({onEdit:r=>{ke("props"),Pe(r)},onEditJson:r=>{ke("json"),Pe(r)},onRun:js,onDuplicate:bs,onDelete:ms,onTogglePause:vs,onToggleDisable:Ss,runsFromNode:!!v,onAddFromPort:gs,readOnly:n}),[js,bs,ms,vs,Ss,v,gs,n]);d.useEffect(()=>{const r=Se.current;if(!r)return;const l=g=>{const y=g.target.closest(".react-flow__node");if(!y)return;const j=y.getAttribute("data-id");j&&(g.stopPropagation(),Bt.onEdit(j))};return r.addEventListener("dblclick",l,!0),()=>r.removeEventListener("dblclick",l,!0)},[Bt]);const ot=m.find(r=>r.id===re),Nt=(ot==null?void 0:ot.data.step)??null,Vt=D?((Js=m.find(r=>r.id===D.stepId))==null?void 0:Js.data.step)??null:null,zt=(D==null?void 0:D.status)==="collect"&&!!Vt,Cs=d.useMemo(()=>{const r=new Map;for(const l of m)r.set(l.id,i.fanOutState(l.id,k).count);return r},[m,k]),Ns=Oo(m),kt=d.useMemo(()=>_o(Ns),[Ns]),Zn=d.useMemo(()=>Fo(k,kt.tones,kt.loopOf),[k,kt]),Qn=d.useMemo(()=>({step:vi,control:Si}),[]),[Et,ks]=d.useState({}),[Tt,Es]=d.useState({}),[Ts,As]=d.useState({}),[At,Is]=d.useState({}),[Ve,It]=d.useState(null),[Ps,Rs]=d.useState([]),eo=re??Ve??"";d.useEffect(()=>{const r=C.loadNodeSamples;if(typeof r!="function"||!t.id){Rs([]);return}let l=!1;return r(t.id).then(g=>{l||Rs(Array.isArray(g)?g:[])},()=>{}),()=>{l=!0}},[C,t.id,eo]);const Pt=d.useMemo(()=>i.indexNodeSamples(Ps),[Ps]),Ht=d.useMemo(()=>i.splitNodeOutputs(Et,Pt,At),[Et,Pt,At]),ze=d.useMemo(()=>i.splitPreviewOutputs(Et,Pt,At),[Et,Pt,At]),Ce=d.useMemo(()=>({actionDef:(r,l)=>{var g;return(g=ue[r])==null?void 0:g.find(y=>y.key===l)},triggerDef:(r,l)=>{var g;return(g=je[r])==null?void 0:g.find(y=>y.key===l)},testOutputs:Ht.fresh,persistedOutputs:Ht.persisted,loopSamples:Ts}),[ue,je,Ht,Ts]),Ye=d.useMemo(()=>D?i.upstreamStateSources(D.stepId,m,k,Ce):void 0,[D,m,k,Ce]),to=d.useMemo(()=>(Ye==null?void 0:Ye.steps)??[],[Ye]),be=d.useMemo(()=>{const r=i.upstreamStateSources(re,m,k,Ce,Ve);return{...r,steps:i.excludeSelfStep(r.steps,re??Ve)}},[re,Ve,m,k,Ce]),dt=d.useMemo(()=>ti({anchorId:re??Ve,nodes:m,edges:k,floating:i.isFloatingDraft(re,Ve,m,k),initialState:t.initialState,variables:t.variables,shapes:Ce,previewOutputs:{...ze.persisted,...ze.fresh}}),[re,Ve,m,k,t.initialState,t.variables,Ce,ze]),Ms=JSON.stringify([...be.steps.map(r=>r.id),...be.extraSampleIds??[]]);d.useEffect(()=>{const r=JSON.parse(Ms);if(!re&&!Ve||r.length===0){ks({}),Es({}),As({}),Is({});return}let l=!1;return Promise.all(r.map(async g=>{try{const y=await C.listStepTests(t.id,g),j=y.length?y[y.length-1]:null;return j?{id:g,output:j.lastRunOutput,runAt:j.lastRunAt,meta:j.lastRunMeta,loopSample:i.foreachTestSample(j)}:null}catch{return null}})).then(g=>{if(l)return;const y={},j={},A={},F={};for(const M of g)M!=null&&M.meta&&(j[M.id]=M.meta),M!=null&&M.loopSample&&(A[M.id]=M.loopSample),!(!M||M.output===void 0||M.output===null)&&(y[M.id]=M.output,F[M.id]=M.runAt);ks(y),Is(F),Es(j),As(A)}),()=>{l=!0}},[C,t.id,re,Ve,Ms]);const Jt=d.useMemo(()=>i.declaredSamples(m,Ce),[m,Ce]),Rt=d.useMemo(()=>({persisted:ze.persisted,samples:Jt.samples,event:Jt.event}),[ze.persisted,Jt]),Ls=d.useMemo(()=>i.upstreamSampleValues(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Fs=d.useMemo(()=>i.upstreamSampleValueSources(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Ds=i.useExpressionOptions(),Os=d.useMemo(()=>i.nodeConfigSources(m),[m]),_s=d.useMemo(()=>i.nodeConfigValues(m,T.subs),[m,T.subs]),Ut=d.useMemo(()=>i.nodeMetaValues(m,T.subs,L,U),[m,T.subs,L,U]),qt=d.useMemo(()=>({...c??{},steps:be.steps,hasTrigger:be.hasTrigger,eventOutputs:be.eventOutputs,eventOutputsFrom:be.eventOutputsFrom,loop:be.loop,stateShape:{fields:dt.fields,...dt.written?{written:dt.written}:{}},nodeConfigs:Os,nodeConfig:_s,nodeMeta:Ut,valueSources:Fs,sampleValues:{...Ds.sampleValues??{},...(c==null?void 0:c.sampleValues)??{},...i.nodeMetaSampleValues(Ut),...Ls,...dt.sampleValues}}),[c,Ds.sampleValues,be,dt,Ls,Fs,Os,_s,Ut]),ut=d.useRef(null);$e||re?ut.current===null&&(ut.current=J.mark()):ut.current=null;const Ws=()=>{te(!1),_e(null),Be(null),It(null)},$s=()=>{const r=ut.current;if(ut.current=null,n||r===null)return;const l=J.rollbackTo(r);l&&Vs(l)},Bs=r=>{if(n)return;const l=J[r]();l&&Vs(l)},Vs=r=>{var y;const l=Eo(t,r);_(l.nodes.map(j=>({...j,selected:j.id===W}))),X(l.edges.map(j=>({...j,selected:j.id===ae}))),z(r.canvas),S(r.connections),l.nodes.some(j=>j.id===W)||B(null),l.edges.some(j=>j.id===ae)||Ne(null);const g=l.nodes.some(j=>j.id===re);g||Pe(null),te(!1),It(null),_e(null),Me(null),me(null),Be(null),qe(null),G(null),Ke(null),Z.current=void 0,Je(j=>j+1),o(et(i.flowToWorkflow({...t,nodes:r.nodes,connections:r.connections},l.nodes,l.edges),r.canvas)),!g&&!D&&((y=Se.current)==null||y.focus({preventScroll:!0}))},zs=d.useRef(Bs);zs.current=Bs,d.useEffect(()=>{const r=Se.current;if(!r)return;let l=r.contains(document.activeElement);const g=j=>{j.type==="focusin"&&j.target===document.body||(l=r.contains(j.target))},y=j=>{if(n||j.defaultPrevented||Gt(j.target)||!r.contains(j.target)&&!(l&&j.target===document.body))return;const A=j.key.toLowerCase();!(j.ctrlKey||j.metaKey)||j.altKey||A!=="z"&&!(A==="y"&&!j.shiftKey)||(j.preventDefault(),zs.current(A==="y"||j.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",g),document.addEventListener("focusin",g),document.addEventListener("keydown",y),()=>{document.removeEventListener("pointerdown",g),document.removeEventListener("focusin",g),document.removeEventListener("keydown",y)}},[n]);const Mt=d.useCallback((r,l)=>{var M;if(Gt(r.target))return;const g=(M=Se.current)==null?void 0:M.getBoundingClientRect();if(!g)return;r.preventDefault();const y=tn(m,k),j=y.nodeIds,A=uo(j,l),F=l!==void 0&&!j.includes(l);F&&_(m.map(q=>q.selected!==(q.id===l)?{...q,selected:q.id===l}:q)),qe({x:r.clientX-g.left,y:r.clientY-g.top,flow:Le({x:r.clientX,y:r.clientY}),nodeIds:A,edgeIds:F?[]:y.edgeIds})},[m,k,_,Le]),so=d.useCallback(r=>{var l;qe(null),r&&((l=Se.current)==null||l.focus({preventScroll:!0}))},[]),no=r=>{const l=we;if(!(!l||n))if(r==="duplicate")Wt(l.nodeIds);else if(r==="delete")Me({nodeIds:l.nodeIds,edgeIds:l.edgeIds});else if(r==="replace-trigger"){const g=m.find(y=>y.id===l.nodeIds[0]);if(!g)return;_e(null),Be({position:g.position,tab:"triggers",replaces:g.id}),te(!0)}else _e(null),Be({position:l.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),te(!0)},oo=s.jsx(fs.Provider,{value:Bt,children:s.jsx(ls.Provider,{value:ie,children:s.jsx(ds.Provider,{value:Cs,children:s.jsx(us.Provider,{value:kt,children:s.jsx(ui,{apps:L,registration:T,children:s.jsx(i.WorkflowProjectProvider,{project:f,workflowId:t.id,children:s.jsx(i.ExpressionOptionsProvider,{value:qt,children:s.jsxs("section",{ref:Se,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{Z.current=Gt(r.target)?{}:void 0},onBlurCapture:()=>{Z.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||re||$e||Re)return;const l=r.target;if(l.isContentEditable||l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.tagName==="SELECT"||l.closest("dialog, .w6w-modal")!==null)return;const g=tn(m,k);!g.nodeIds.length&&!g.edgeIds.length||(r.preventDefault(),!g.nodeIds.length&&g.edgeIds.length===1?zn(g.edgeIds[0]):Me(g))},children:[s.jsxs(oe.ReactFlow,{nodes:xt,edges:Zn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:de,onEdgesChange:E,onConnect:st,onConnectStart:(r,l)=>{he.current=l},onConnectEnd:Wn,onPaneClick:()=>G(null),onPaneContextMenu:r=>Mt(r),onNodeContextMenu:(r,l)=>Mt(r,l.id),onEdgeContextMenu:r=>Mt(r),onSelectionContextMenu:r=>Mt(r),onMoveStart:()=>qe(null),isValidConnection:vt,onNodeDragStop:(r,l,g)=>{const y=Kn(g),j=y!==H;if(j&&z(y),!V&&!j){J.record(Lt(t,m,k,R.current,y));return}Y(m,k,y)},onMoveEnd:(r,l)=>{if(!r||n)return;const g=i.flowToWorkflow(t,m,k),y=i.withViewport(g,l);y!==g&&o(y,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:l})=>{var g,y,j,A;B(((g=r[0])==null?void 0:g.id)??null),Ne(((y=l[0])==null?void 0:y.id)??null),se.current!==(((j=r[0])==null?void 0:j.id)??null)&&(se.current=((A=r[0])==null?void 0:A.id)??null,G(null))},nodeTypes:Qn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:ct,proOptions:{hideAttribution:!0},children:[s.jsx(oe.Background,{gap:16}),s.jsx(oe.Controls,{showInteractive:!1,children:!n&&s.jsx(oe.ControlButton,{onClick:Bn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:s.jsx(Ee.Icon,{name:"layout"})})}),s.jsx(oe.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&s.jsxs(oe.Panel,{position:"top-left",className:"w6w-flow-tools",children:[s.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>te(!0),children:"+ Node"}),s.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Jn}),s.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${De?" active":""}`,"aria-pressed":De,"data-testid":"draw-section",onClick:()=>{rt(!De),Ue(null)}})]}),!n&&De&&s.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:r=>{if(r.button!==0)return;r.currentTarget.setPointerCapture(r.pointerId);const{clientX:l,clientY:g}=r;Ue({sx:l,sy:g,ex:l,ey:g})},onPointerMove:r=>{const{clientX:l,clientY:g}=r;Ue(y=>y&&{...y,ex:l,ey:g})},onPointerUp:()=>{const r=ve;if(Ue(null),rt(!1),!r)return;const l=Le({x:r.sx,y:r.sy}),g=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Un(l,g?Le({x:r.ex,y:r.ey}):null)},children:ve&&(()=>{var y;const r=(y=Se.current)==null?void 0:y.getBoundingClientRect(),l=(r==null?void 0:r.left)??0,g=(r==null?void 0:r.top)??0;return s.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ve.sx,ve.ex)-l,top:Math.min(ve.sy,ve.ey)-g,width:Math.abs(ve.ex-ve.sx),height:Math.abs(ve.ey-ve.sy)}})})()}),!n&&nt&&i.edgeLane(nt)!=="each"&&((Us=m.find(r=>r.id===nt.source))==null?void 0:Us.data.step.uses.app)!==i.ROUTER_APP&&s.jsx(oe.Panel,{position:"top-right",children:s.jsxs("div",{className:"w6w-edge-lane",children:[s.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(r=>s.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${i.edgeLane(nt)===r?" active":""}`,"aria-pressed":i.edgeLane(nt)===r,title:di,onClick:()=>Vn(r),children:r==="success"?"Success":"Error"},r)),(St==null?void 0:St.edgeId)===nt.id&&s.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:St.message})]})}),N&&s.jsx(oe.NodeToolbar,{nodeId:N.nodeId,position:oe.Position.Bottom,isVisible:!0,children:s.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(N.reason)})}),s.jsx(i.CanvasLayer,{canvas:H,readOnly:n,savePosition:V,onChange:Xe,onSectionDrop:qn,onRequestDelete:(r,l)=>!n&&me({kind:r,id:l})})]}),Ie&&s.jsx(i.ConfirmModal,{title:Ie.kind==="note"?"Delete note":"Delete section",message:Ie.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Gn(Ie.kind,Ie.id),me(null)},onClose:()=>me(null)}),$e&&s.jsx(i.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{$s(),Ws()},onDone:Ws,onAdd:r=>{const l=Hn(r);return l&&It(l),l},onDraftChange:(r,l)=>ys(r,{id:r,...l}),stepIds:m.map(r=>r.id),onOpenStep:r=>{te(!1),_e(null),Be(null),It(null),ke("props"),Pe(r)},workflowId:t.id,upstreamSteps:i.stepBuilderUpstreamSteps(xe,m,k),loop:i.stepBuilderLoop(xe,m,k,Ce)}),Nt&&re&&s.jsx(Ni,{workflowId:t.id,step:Nt,restoreVersion:pe,upstreamSteps:qt.steps??[],loop:qt.loop,readOnly:n,fanOutCount:Cs.get(re)??0,stateOutputFields:(Xs=i.resolveOutputShape((qs=Ce.actionDef)==null?void 0:qs.call(Ce,Nt.uses.app,Nt.uses.action),(Gs=Ce.testOutputs)==null?void 0:Gs[re],(Ks=Ce.persistedOutputs)==null?void 0:Ks[re]))==null?void 0:Xs.fields.map(r=>r.key),initialView:Oe,stepProblems:ot==null?void 0:ot.data.stepProblems,otherStepIds:m.filter(r=>r.id!==re).map(r=>r.id),onChange:r=>ys(re,r),onClose:()=>Pe(null),onCancel:()=>{$s(),Pe(null)},onTestRun:b}),D&&s.jsxs(i.Modal,{title:`${zt?"Run node":"Test run"}: ${D.stepId}`,onClose:()=>h(null),children:[zt&&Vt&&s.jsx(wi,{workflowId:t.id,step:Vt,upstreamSteps:to,loop:Ye==null?void 0:Ye.loop,continues:v?{stopAt:ns(m.map(r=>r.data.step),D.stepId)}:void 0,onCancel:()=>h(null),onRun:(r,l)=>v?Xn(D.stepId,r,l):Yn(D.stepId,r,l)},D.stepId),!zt&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"w6w-modal-body",children:[D.status==="running"&&s.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),D.status==="error"&&s.jsxs("div",{className:"w6w-result w6w-error",children:[D.errorCode&&s.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:s.jsx("code",{children:D.errorCode})}),D.error||"The node failed with no error message."]}),D.status==="done"&&s.jsxs("div",{children:[s.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),s.jsx(i.ResultViewer,{value:D.value,maxHeight:360}),D.meta&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),s.jsx(i.ResultViewer,{value:D.meta,maxHeight:360})]})]}),D.logs&&D.logs.length>0&&s.jsxs("div",{children:[s.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),s.jsx(Ee.Copyable,{value:D.logs.join(`
2
- `),label:"Copy console output",children:s.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:D.logs.join(`
3
- `)})})]})]}),s.jsx("div",{className:"w6w-modal-actions",children:s.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>h(null),children:"Close"})})]})]}),Re!==null&&s.jsx(i.ConfirmModal,{title:Re.nodeIds.length===1?"Delete node":Re.nodeIds.length>1?`Delete ${Re.nodeIds.length} nodes`:`Delete ${Re.edgeIds.length} connections`,message:ko(Re,m,k),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{$n(Re),Me(null)},onClose:()=>Me(null)}),we&&s.jsx(ao,{x:we.x,y:we.y,items:po(we.nodeIds,!!n,{replaceableTrigger:we.nodeIds.length===1&&m.some(r=>r.id===we.nodeIds[0]&&i.isTriggerStep(r.data.step.uses))}),onAction:no,onClose:so})]})})})})})})})});return s.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:m.map(r=>r.data.step),connections:U,setConnections:S,readOnly:n},children:oo})}const hi=["code"];function _t(e){try{const t=JSON.parse(e);return t&&typeof t=="object"&&!Array.isArray(t)?t:null}catch{return null}}function gi(e){try{const t=JSON.parse(e);if(Array.isArray(t))return{items:t}}catch{return null}return _t(e)}function mi({items:e,save:t}){if(!e)return s.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[s.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",s.jsx("strong",{children:"Override the incoming state"})," below."]});const o=e[0],n=o!==void 0?(i.inferOutputFields(o)??[]).map(a=>a.key):[];return s.jsxs("div",{className:"w6w-testout",children:[s.jsxs("div",{className:"w6w-testout-label",children:[e.length," ",e.length===1?"item":"items"]}),e.length===0?s.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"w6w-testout-label",children:"First item"}),s.jsx(i.ResultViewer,{value:o,maxHeight:220})]}),t==="saved"&&s.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&s.jsxs(s.Fragment,{children:[" ","Steps on ",s.jsx("strong",{children:"Each item"})," now offer ",s.jsx("strong",{children:"Current item"})," ›"," ",n.map((a,u)=>s.jsxs("span",{children:[u>0&&", ",s.jsx("code",{children:a})]},a)),"."]})]}),t==="failed"&&s.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function An(e){const[t,o]=d.useState(null),[n,a]=d.useState("0"),u=t??i.loopItemText(e),c=e?i.parseLoopSeed(u,n):void 0;return{active:!!e,itemText:u,indexText:n,setItemText:o,setIndexText:a,parsed:c}}function In(e){var t;return(t=e.parsed)!=null&&t.ok?e.parsed.value:void 0}function hs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function Pn({seed:e,readOnly:t}){if(!e.active)return null;const o=hs(e);return s.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[s.jsx("span",{children:"Current item"}),s.jsx("textarea",{rows:3,value:e.itemText,readOnly:t,spellCheck:!1,"aria-label":"Current item",onChange:n=>e.setItemText(n.target.value)}),s.jsx("span",{children:"Index"}),s.jsx("input",{type:"text",inputMode:"numeric",value:e.indexText,readOnly:t,"aria-label":"Index",onChange:n=>e.setIndexText(n.target.value)}),s.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),o&&s.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function is({text:e,onChange:t,seeds:o,readOnly:n,expand:a,hint:u}){const c=_t(e),f=c?Object.keys(c).length:0,p=f>0,[x,b]=d.useState(p);d.useEffect(()=>{(p||a)&&b(!0)},[p,a]);const w=v=>{t(JSON.stringify(v.lastRunOutput??v.input??{},null,2)),b(!0)};return s.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[s.jsx("span",{children:"Incoming state"}),o.length>0&&s.jsx("div",{className:"w6w-seed-picker",children:s.jsx("div",{className:"w6w-seed-chips",children:o.map(v=>s.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${v.label}'s saved test as the incoming state`,disabled:n,onClick:()=>w(v.test),children:[s.jsx("code",{children:v.label}),v.test.lastRunStatus?s.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",v.test.lastRunStatus]}):null]},v.stepId))})}),s.jsxs("details",{className:"w6w-state-override",open:x,onToggle:v=>b(v.currentTarget.open),children:[s.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),s.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:v=>t(v.target.value)}),s.jsx("span",{className:"w6w-hint",children:u??s.jsxs(s.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",s.jsx("code",{children:"input"}),": ",s.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",s.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function wi({workflowId:e,step:t,upstreamSteps:o,loop:n,onRun:a,onCancel:u,continues:c}){var H;const f=i.useW6WApi(),p=i.isTriggerStep(t.uses),x=i.isInternalApp(t.uses.app),b=d.useMemo(()=>{var z;return p?i.asFieldDefs((z=t.with)==null?void 0:z.fields):[]},[p,t.with]),w=d.useMemo(()=>p?i.fieldsToParams(b):x?i.internalNodeParams(t.uses.app,t.uses.action):null,[p,x,b,t.uses.app,t.uses.action]),[v,C]=d.useState(null),L=w??v;d.useEffect(()=>{if(w)return;if(!t.uses.app||!t.uses.action){C([]);return}let z=!1;return C(null),f.getAppActions(t.uses.app).then(J=>{var Z;z||C(((Z=J.find(pe=>pe.key===t.uses.action))==null?void 0:Z.params)??[])}).catch(()=>!z&&C([])),()=>{z=!0}},[f,w,t.uses.app,t.uses.action]);const[T,D]=d.useState(()=>{var z;return p?i.seedValues(i.asFieldDefs((z=t.with)==null?void 0:z.fields)):{}}),[h,I]=d.useState("{}"),O=i.useSeedSources(e,o,!p),U=An(n),P=(H=i.useExpressionOptions().stateShape)==null?void 0:H.written,R=i.startStateFromSeeds(O,In(U),P),S=i.useRememberedTestInput(e,t.id),[$,K]=d.useState(!1),[V,m]=d.useState(!1);d.useEffect(()=>{if(!S.loaded)return;let z=!1;const J=(Z,pe)=>{Z&&Object.keys(Z).length>0&&(p?D(Je=>({...Je,...Z})):I(JSON.stringify(Z,null,2)),pe&&m(!0)),K(!0)};if(S.input!==void 0){J(S.input,!0);return}return f.listStepTests(e,t.id).then(Z=>{if(z)return;const pe=Z.length?Z[Z.length-1]:null;J(p?pe==null?void 0:pe.with:pe==null?void 0:pe.input,!1)}).catch(()=>{z||K(!0)}),()=>{z=!0}},[f,e,t.id,p,S.loaded]);const[_,de]=d.useState(0),ue=()=>{S.clear(),m(!1),p?D(i.seedValues(b)):I("{}"),de(z=>z+1)},je=z=>{D(z),k(!0),m(!1),de(J=>J+1)},[ie,k]=d.useState(!0),X=_t(h),E=p?ie:X!==null,W=p?T:{...t.with??{},...X??{}},B=p?null:hs(U),ee=!!L&&$&&E&&!B&&i.requiredParamsFilled(L,W);return s.jsxs("div",{className:"w6w-stepconfig",children:[s.jsx("div",{className:"w6w-modal-body",children:s.jsxs("div",{className:"w6w-stack",children:[c&&s.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",c.stopAt.length>0?s.jsxs(s.Fragment,{children:[" ","and stops before"," ",c.stopAt.length===1?"the paused node":"paused nodes"," ",c.stopAt.map((z,J)=>s.jsxs("span",{children:[J>0?", ":"",s.jsx("code",{children:z})]},z))]}):null,". Disabled nodes are skipped."]}),V&&L!==null&&$&&s.jsx(i.LastUsedNote,{onClear:ue}),L===null||!$?s.jsx("p",{className:"w6w-muted w6w-small",children:L===null?"Loading parameters…":"Loading saved values…"}):p?s.jsxs(s.Fragment,{children:[s.jsx(i.PropertyEntryForm,{params:L,values:T,onChange:D,onValidityChange:k},_),t.uses.trigger===!0&&s.jsx(lo,{app:t.uses.app,trigger:t.uses.action,onUse:je}),L.length===0&&s.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",s.jsx("code",{children:"input"}),")."]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",s.jsx("code",{children:t.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),s.jsx(Pn,{seed:U}),s.jsx(is,{text:h,onChange:I,seeds:O})]})]})}),s.jsxs("div",{className:"w6w-modal-actions",children:[s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:u,children:"Cancel"}),!ee&&L!==null&&$&&s.jsx("span",{className:"w6w-muted w6w-small",children:B?`${B} Fix it to run.`:E?p?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":p?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),s.jsx("button",{type:"button",className:"w6w-btn",disabled:!ee,onClick:()=>{S.save(p?T:X??{},L??[]),a(p?T:X??{},p?void 0:R)},children:"▶ Run"})]})]})}function xi(e){return e.uses.app===i.CONTROL_APP&&e.uses.action==="foreach"}function Rn({id:e}){const{tones:t,loopOf:o}=d.useContext(us),n=vn(e,o);return n.length===0?null:s.jsx("span",{className:"w6w-loop-dots",children:n.map(a=>s.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${a}`,title:`In loop · ${a}`,style:{background:as(t.get(a)??1)}},a))})}function Mn(e){return Do(e,d.useContext(us).tones)}function He({type:e,position:t,multiple:o,id:n,variant:a,top:u,routeLabel:c}){const f=oe.useNodeId(),p=d.useContext(fs),x=!!f&&!!p&&!p.readOnly,b=()=>{x&&f&&p.onAddFromPort(f,e,n)},w=a==="error"?"a step that handles this step's failure":a==="each"?"the first step of this loop's body":e==="target"?"a step before this one":"the next step";return s.jsx(oe.Handle,{type:e,position:t,id:n,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...u?{top:u}:{}},onClick:x?b:void 0,title:c?`${c} — drag or click to connect`:x?`Drag to empty canvas (or click) to add ${w} · drag to a port to connect`:a==="error"?"On error — drag to route this step's failure separately":a==="each"?"Each item — drag to the first step to repeat for every item":o?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Ln({id:e,step:t,runnable:o}){const n=d.useContext(fs);if(!n||n.readOnly)return null;const a=o||n.runsFromNode,u=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",c=Qe(t),f=We(t);return s.jsxs(oe.NodeToolbar,{position:oe.Position.Top,className:"w6w-node-toolbar",children:[a&&s.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:u,"aria-label":u,onClick:()=>n.onRun(e),children:s.jsx(Ee.Icon,{name:"run",size:15})}),s.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":c,title:c?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":c?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(e),children:s.jsx(Ee.Icon,{name:"pause",size:15})}),s.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:s.jsx(Ee.Icon,{name:"ban",size:15})}),s.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),s.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(e),children:s.jsx(Ee.Icon,{name:"edit",size:15})}),s.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(e),children:s.jsx(Ee.Icon,{name:"copy",size:15})}),s.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(e),children:s.jsx(Ee.Icon,{name:"trash",size:15})})]})}function Fn({step:e,count:t}){if(t<2)return null;const o=e.fanOut==="parallel",n=i.fanOutLabel(t,o?"parallel":"sequential");return s.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[s.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",t]})}function Dn({step:e}){const t=Qe(e),o=We(e);return!t&&!o?null:s.jsxs("div",{children:[o&&s.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":nn,title:nn,children:[s.jsx(Ee.Icon,{name:"ban",size:11})," Disabled"]}),t&&s.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":sn,title:sn,children:[s.jsx(Ee.Icon,{name:"pause",size:11})," Paused"]})]})}function On(e){return!e||e.length===0?{}:{"data-step-problem":e.map(t=>t.code).join(" "),title:e.map(i.stepProblemTooltip).join(`
4
- `)}}function _n({problems:e}){if(!e||e.length===0)return null;const t=e.map(i.stepProblemTooltip).join(`
5
- `);return s.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":t,title:t,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:s.jsx(Ee.Icon,{name:"warning",size:12})})}function bi(e){const t=i.useW6WApi(),o=e.uses.action,[n,a]=d.useState(null),u=e.uses.trigger===!0,c=e.uses.app;return d.useEffect(()=>{if(!u||!t.getAppTriggers)return;let f=!1;return t.getAppTriggers(c).then(p=>{var x;return!f&&a(((x=p.find(b=>b.key===o))==null?void 0:x.title)??null)}).catch(()=>{}),()=>{f=!0}},[t,c,o,u]),n||o}function yi(e){const t=i.useW6WApi(),o=t.listSubscriptionsForWorkflow,n=t.retrySubscriptionRegistration,a=e.id,u=[...ri(e.nodes),...(e.nodes??[]).filter(L=>{var T;return((T=L.uses)==null?void 0:T.app)===i.WEBHOOK_APP&&L.uses.trigger!==!0})],c=u.length>0,f=u.map(L=>`${L.id}:${L.uses.app}:${L.uses.action}:${i.connectionIdFor(L,e.connections)??""}`).join("|"),[p,x]=d.useState([]),b=d.useMemo(()=>ii(p),[p]),[w,v]=d.useState(0);d.useEffect(()=>{if(!o||!c){x([]);return}let L=!1;return o.call(t,a).then(T=>!L&&x(T)).catch(()=>{}),()=>{L=!0}},[t,o,a,c,f,w]);const C=d.useMemo(()=>n?async L=>{try{await n.call(t,L)}finally{v(T=>T+1)}}:void 0,[t,n]);return d.useMemo(()=>({byNode:b,subs:p,retry:C}),[b,p,C])}function ji({nodeId:e}){const{byNode:t,retry:o}=d.useContext(Tn),[n,a]=d.useState(!1),u=t.get(e),c=oi(u,o!==void 0);return!u||!c?null:s.jsxs("div",{className:"w6w-small","data-trigger-registration":u.status,"data-tone":c.tone,style:{marginTop:3,paddingLeft:2},children:[s.jsx("span",{style:c.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:c.label}),s.jsxs("span",{className:"w6w-muted",children:[" · ",c.lastFire]}),c.error&&s.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:c.error}),c.retryVisible&&o&&s.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),o(u.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function vi({id:e,data:t,selected:o}){const n=t.step,u=d.useContext(ps).get(n.uses.app),c=(u==null?void 0:u.displayName)||n.uses.app||"—",f=i.isTriggerStep(n.uses),p=bi(n),x=n.uses.trigger?`${c} · ${p}`:c,b=i.nodePortsForStep(n,d.useContext(ls)),w=En(t.stepStatus??"no-run",t.runStatus),v=s.jsx(Fn,{step:n,count:d.useContext(ds).get(e)??0}),C=Mn(e);return s.jsxs("div",{className:[t.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":t.loopOf,style:C,"data-disabled":We(n)||void 0,"data-paused":Qe(n)||void 0,children:[s.jsx(Ln,{id:e,step:n,runnable:!0}),s.jsxs("div",{className:f?"w6w-node-trigger":void 0,"data-node-kind":f?"trigger":void 0,"data-run-status":t.stepStatus??"no-run",...On(t.stepProblems),style:{position:"relative",...t.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${w.borderWidth}px ${w.borderStyle} ${o?"var(--w6w-accent)":w.borderColor}`,opacity:We(n)?.45:o?1:w.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...f?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[s.jsx(_n,{problems:t.stepProblems}),b.in>0&&s.jsx(He,{type:"target",position:oe.Position.Left,multiple:b.in>1}),s.jsx(i.AppIcon,{src:u==null?void 0:u.iconSvg,srcDark:u==null?void 0:u.iconSvgDark,brandColor:u==null?void 0:u.brandColor,name:c,size:28}),s.jsxs("div",{style:{minWidth:0},children:[s.jsx("div",{style:{fontWeight:600},children:x}),s.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:s.jsx("code",{children:n.uses.action||"—"})})]}),b.out>0&&s.jsxs(s.Fragment,{children:[s.jsx(He,{type:"source",position:oe.Position.Right,multiple:b.out>1}),!f&&s.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),v,s.jsx(Dn,{step:n}),f&&n.uses.trigger===!0&&s.jsx(ji,{nodeId:e}),t.loopOf&&s.jsx(Rn,{id:e}),s.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,u!=null&&u.version?` - v${u.version}`:""]}),n.notes&&s.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Si({id:e,data:t,selected:o}){const n=t.step,a=i.routesForStep(n),u=n.uses.app===i.ROUTER_APP,c=i.isIfStep(n),f=a.length?i.routerPortLayout(a):c?i.ifPortLayout():void 0,p=JSON.stringify(a.map(I=>I.id)),x=oe.useUpdateNodeInternals();d.useEffect(()=>{x(e)},[e,p,x]);const b=i.internalNodeLabel(n.uses.app,n.uses.action),w=i.internalNodeIcon(n.uses.app,n.uses.action),v=i.nodePortsForStep(n,d.useContext(ls)),C=i.isTriggerStep(n.uses),L=xi(n),T=En(t.stepStatus??"no-run",t.runStatus),D=s.jsx(Fn,{step:n,count:d.useContext(ds).get(e)??0}),h=Mn(e);return s.jsxs("div",{className:[L?"w6w-node-foreach":"",t.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":t.loopOf,style:h,"data-disabled":We(n)||void 0,"data-paused":Qe(n)||void 0,children:[s.jsx(Ln,{id:e,step:n,runnable:!i.isControlApp(n.uses.app)}),s.jsxs("div",{className:C?"w6w-node-trigger":u?"w6w-node-router":void 0,"data-node-kind":C?"trigger":void 0,"data-run-status":t.stepStatus??"no-run",...On(t.stepProblems),style:{position:"relative",...t.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${T.borderWidth}px ${T.borderStyle} ${o?"var(--w6w-accent)":T.borderColor}`,opacity:We(n)?.45:o?1:T.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...C?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...f!=null&&f.minHeight?{minHeight:f.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[s.jsx(_n,{problems:t.stepProblems}),v.in>0&&s.jsx(He,{type:"target",position:oe.Position.Left,multiple:v.in>1}),w&&s.jsx(i.InternalIcon,{icon:w}),s.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[s.jsx("div",{style:{fontWeight:600},children:b}),s.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:s.jsx("code",{children:n.uses.action||"—"})})]}),L&&s.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[s.jsx("span",{children:"Each item"}),s.jsx("span",{children:"Done"})]}),c&&(f==null?void 0:f.right[0])&&s.jsx("span",{className:"w6w-if-true-label w6w-small","aria-hidden":"true",children:f.right[0].label}),!c&&!!(f!=null&&f.right.length)&&s.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${f.right.length}, 1fr)`},"aria-hidden":"true",children:f.right.map(I=>s.jsx("span",{title:I.label,children:I.label},I.id))}),v.out>0&&s.jsxs(s.Fragment,{children:[L&&s.jsx(He,{type:"source",position:oe.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),f?s.jsxs(s.Fragment,{children:[f.right.map(I=>s.jsx(He,{type:"source",position:oe.Position.Right,multiple:!1,id:I.handleId,top:I.top,routeLabel:I.label},I.id)),f.bottom&&s.jsxs(s.Fragment,{children:[s.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:f.bottom.handleId,routeLabel:f.bottom.label}),s.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:f.bottom.label})]})]}):s.jsx(He,{type:"source",position:oe.Position.Right,multiple:v.out>1,id:L?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!C&&!u&&!c&&n.uses.app!==i.RACE_APP&&s.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),D,s.jsx(Dn,{step:n}),t.loopOf&&s.jsx(Rn,{id:e}),t.legacyLoop&&s.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),s.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&s.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ci(e,t){var c,f;if(!t)return e;const o={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[p,x]of Object.entries(t)){const b=/^nodes\.([^.]+)\.output$/.exec(p);!b||((c=o[b[1]])==null?void 0:c.output)!==void 0||(o[b[1]]={...o[b[1]]??{},output:x},n=!0)}const a=t["trigger.event"],u=a!==void 0&&((f=e==null?void 0:e.trigger)==null?void 0:f.event)===void 0;return!n&&!u?e:{...e??{},...n?{steps:o}:{},...u?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Ni(e){return s.jsx(ki,{...e})}function ki({workflowId:e,step:t,restoreVersion:o,upstreamSteps:n,loop:a,onChange:u,onClose:c,onCancel:f,readOnly:p,initialView:x="props",fanOutCount:b=0,stateOutputFields:w,onTestRun:v,stepProblems:C,otherStepIds:L}){var yt,jt,vt;const T=i.useW6WApi(),D=d.useContext(ps),[h,I]=d.useState(t),O=i.useWorkflowConnections(),U=i.connectionIdFor(h,O==null?void 0:O.connections),P={...h,uses:{...h.uses,connection:U}},S=h.uses.connectionRef!==void 0&&!U||i.isConnectionBlocked(P,C),$=C==null?void 0:C.find(N=>N.code==="unknown_connection"&&N.connection===U),K=(C??[]).filter(N=>"fix"in N),[V,m]=d.useState(S?"setup":"configure"),[_,de]=d.useState(x==="json"?"code":x==="settings"?"config":"props"),[ue,je]=d.useState("props"),[ie,k]=d.useState(()=>i.stepToJson(t)),[X,E]=d.useState("{}"),W=d.useRef(null),[B,ee]=d.useState(!1),H=d.useRef(o);d.useEffect(()=>{H.current!==o&&(H.current=o,I(t),k(i.stepToJson(t)))},[o,t]);const[z,J]=d.useState(!1),[Z,pe]=d.useState(null),[Je,De]=d.useState(null),[rt,ve]=d.useState(null),[Ue,Ie]=d.useState(!1),me=i.isInternalApp(h.uses.app),ae=h.uses.trigger===!0;d.useEffect(()=>{if(me){pe(i.internalNodeParams(h.uses.app,h.uses.action));const G=i.INTERNAL_NODES.filter(se=>se.app===h.uses.app&&se.groupActions&&!se.hidden);De(G.length?G.map(se=>({key:se.action,title:se.label,params:se.params})):null);return}if(!h.uses.app){De(null),pe([]);return}let N=!1;return pe(null),(ae?i.getTriggerDefs(T,h.uses.app):T.getAppActions(h.uses.app)).then(G=>{var se;N||(De(G),pe(h.uses.action?((se=G.find(he=>he.key===h.uses.action))==null?void 0:se.params)??[]:[]))}).catch(()=>!N&&pe([])),()=>{N=!0}},[T,h.uses.app,h.uses.action,me,ae]);const Ne=d.useRef(0);d.useEffect(()=>()=>{Ne.current++},[]);const $e=d.useCallback(()=>{me||!h.uses.app||T.listConnectionsForApp(h.uses.app).then(N=>{ve(N),Ie(!1)}).catch(()=>Ie(!0))},[T,h.uses.app,me]);d.useEffect(()=>{if(me||!h.uses.app)return;let N=!1;return ve(null),Ie(!1),T.listConnectionsForApp(h.uses.app).then(G=>{N||(ve(G),Ie(!1))}).catch(()=>!N&&Ie(!0)),()=>{N=!0}},[T,h.uses.app,me]);const te=d.useCallback(N=>{I(N),u(N)},[u]),mt=So({enabled:h.uses.app===i.SCRIPT_APP&&!p,values:h.with??{},onChange:N=>te({...h,with:N})}),re=N=>{N==="code"&&k(i.stepToJson(h)),de(N)},Pe=N=>{const G=i.stepNameError(N,L??[]);return G||te({...h,id:N}),G},Oe=!!h.uses.app&&!!h.uses.action&&!i.isControlApp(h.uses.app),ke=i.isForeachStep(h),we=i.isTriggerStep(h.uses),qe=V==="test"&&Oe&&!we,ye=i.useSeedSources(e,n,Oe&&!we||ke),Be=An(Oe&&!we?a:void 0),Re=i.useExpressionOptions(),Me=i.startStateFromSeeds(ye,In(Be),(yt=Re.stateShape)==null?void 0:yt.written),at=Ci(Me,Re.sampleValues),Se=i.useRememberedTestInput(Oe&&!we||ke?e:void 0,h.id),[xe,_e]=d.useState(!1);d.useEffect(()=>{if((!Oe||we)&&!ke||!Se.loaded)return;if(!ke&&Se.input!==void 0){const G=Se.input;if(Object.keys(G).length===0)return;const se=JSON.stringify(G,null,2);E(he=>he.trim()==="{}"?se:he),_e(!0);return}let N=!1;return T.listStepTests(e,h.id).then(G=>{if(N)return;const se=G.length?G[G.length-1]:null;if(!(se!=null&&se.input)||Object.keys(se.input).length===0)return;const he=JSON.stringify(se.input,null,2);E(st=>st.trim()==="{}"?he:st)}).catch(()=>{}),()=>{N=!0}},[T,e,h.id,Oe,we,ke,Se.loaded]);const Le=ke?gi(X):_t(X),Fe={...h.with??{},...Le??{}},ct=Le??{},et=!!Z&&!hs(Be)&&i.requiredParamsFilled(Z,Fe)&&(h.uses.app!==i.CALL_APP||z),Y=ke?i.resolveLoopItemsInState(Fe.items,Me):void 0,[tt,Ge]=d.useState("idle"),wt=N=>{E(N),Ge("idle")},lt=async()=>{if(Y){Ge("saving");try{await T.saveStepTest(e,h.id,i.foreachTestFixture(Y,ct)),Ge("saved")}catch{Ge("failed")}}},ce=D.get(h.uses.app),xt=me?i.internalNodeIcon(h.uses.app,h.uses.action):null,bt=me?xt?s.jsx(i.InternalIcon,{icon:xt}):null:s.jsx(i.AppIcon,{src:ce==null?void 0:ce.iconSvg,srcDark:ce==null?void 0:ce.iconSvgDark,brandColor:ce==null?void 0:ce.brandColor,name:ce==null?void 0:ce.displayName});return s.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:bt,title:s.jsx(i.StepNameEditor,{value:h.id,onCommit:Pe,readOnly:p}),onClose:f??c,size:"wide",children:s.jsxs("div",{className:"w6w-stepconfig",children:[s.jsxs("div",{className:"w6w-tabsbar",children:[s.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(N=>h.uses.app!==i.RACE_APP||N!=="test").map(N=>s.jsx("button",{type:"button",className:`w6w-subtab${V===N?" active":""}`,disabled:S&&N!=="setup",onClick:()=>m(N),children:N==="setup"?"Setup":N==="configure"?"Configure":"Test"},N))}),qe?s.jsx(i.ConfigViewToggle,{view:ue,views:["props","code"],onChange:N=>je(N)}):s.jsx(i.ConfigViewToggle,{view:_,customized:i.hasParamCustomization(h.with??{}),onChange:re,disabled:V!=="configure"})]}),S&&$&&s.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",$.connection," no longer exists — choose another to continue."]}),K.length>0&&s.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:K.map(N=>s.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[s.jsx("span",{children:i.stepProblemTooltip(N)}),s.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":N.code,disabled:p,onClick:()=>{const G=kn(h,N);te(G),k(i.stepToJson(G))},children:"fix"in N?N.fix.label:""})]},N.code))}),s.jsxs("div",{className:"w6w-stepconfig-body",children:[V==="setup"&&h.uses.app===i.CALL_APP&&s.jsx(i.CallTargetForm,{values:h.with??{},onChange:N=>te({...h,with:N}),readOnly:p,onValidityChange:J,setupOnly:!0}),V==="setup"&&h.uses.app!==i.CALL_APP&&s.jsx(Ai,{step:h,app:ce,actions:Je,conns:rt,connsFailed:Ue,isInternal:me,actionLabel:ae?"Trigger":"Action",readOnly:p,onChangeAction:N=>{var se;const G=me?i.internalNodeDefaults(h.uses.app,N):{};if(me)for(const he of i.internalNodeParams(h.uses.app,N))he.key in(h.with??{})&&(G[he.key]=(se=h.with)==null?void 0:se[he.key]);te({...h,uses:{...h.uses,action:N},with:G})},onChangeTriggerEvents:(N,G)=>te({...h,uses:{...h.uses,action:N},with:{...h.with,actions:G}}),onChangeConnection:N=>{if(!O){const{connectionRef:se,...he}=h.uses;te({...h,uses:{...he,connection:N}});return}const G=i.selectNodeConnection(h,N,(O==null?void 0:O.nodes)??[h],(O==null?void 0:O.connections)??{});O==null||O.setConnections(G.connections),te(G.step)},onChangeConnectionRef:N=>te(i.withConnectionRef(h,N)),onConnectionCreated:$e,onChangeApp:N=>{const G=++Ne.current;if(N===h.uses.app){te(h);return}const se={...h,uses:{app:N,action:"",...ae?{trigger:!0}:{}},with:{}};(i.isInternalApp(N)?Promise.resolve([]):T.listConnectionsForApp(N)).catch(()=>[]).then(he=>{if(G!==Ne.current)return;const st=i.defaultConnectionFor(se,he,(O==null?void 0:O.nodes)??[],(O==null?void 0:O.connections)??{});te({...se,uses:{...se.uses,...st}})})}}),V==="configure"&&s.jsxs(s.Fragment,{children:[h.uses.app===i.WEBHOOK_APP&&T.listSubscriptionsForWorkflow&&T.createSubscription&&s.jsx(Ti,{workflowId:e,step:h,readOnly:p}),Z===null?s.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):_==="props"?h.uses.app===i.CALL_APP?s.jsx(i.CallTargetForm,{values:h.with??{},onChange:N=>te({...h,with:N}),readOnly:p,onValidityChange:J}):h.uses.app===i.RACE_APP?s.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):h.uses.action==="wait"&&i.isControlApp(h.uses.app)?s.jsx(i.WaitEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):h.uses.action==="if"&&i.isControlApp(h.uses.app)?s.jsx(i.ConditionEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):h.uses.app==="@w6w/stop"?s.jsx(i.StopEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):h.uses.app===i.ROUTER_APP?s.jsx(i.RouterEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):s.jsxs(s.Fragment,{children:[h.uses.app===i.SCRIPT_APP&&s.jsx(Co,{values:h.with??{},conversion:mt,readOnly:p}),s.jsx(i.ParamsForm,{params:Z,values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N}),dynamic:me||!h.uses.action?void 0:{appId:h.uses.app,actionKey:h.uses.action,connectionId:S?void 0:U,appName:ce==null?void 0:ce.displayName}})]}):_==="code"?s.jsx(i.JsonEditor,{value:ie,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${h.id} JSON`,copyable:!0}):_==="params-code"?s.jsx(i.ParamCustomization,{values:h.with??{},onChange:N=>te({...h,with:N}),readOnly:p}):s.jsxs("div",{className:"w6w-stack",children:[s.jsx(i.NodeConfigForm,{config:{retry:h.retry,onError:h.onError,notes:h.notes},onChange:N=>te({...h,...N}),readOnly:p,failureHandling:!we,retryControls:!i.isControlApp(h.uses.app)&&h.uses.app!==i.CALL_APP}),Ei,s.jsx(i.StepFanOutControl,{step:h,count:b,readOnly:p,onChange:te}),i.stateWriteVisible(h)&&s.jsx(i.StepStateControl,{step:h,inLoop:a!==void 0,outputFields:w,readOnly:p,onChange:te})]})]}),V==="test"&&s.jsx("div",{className:"w6w-stack",children:Oe?ae?s.jsx(i.AppTriggerTestNote,{title:((jt=Je==null?void 0:Je.find(N=>N.key===h.uses.action))==null?void 0:jt.title)??h.uses.action,app:(ce==null?void 0:ce.displayName)??h.uses.app}):we?s.jsx(i.TriggerFillForm,{app:h.uses.app,action:h.uses.action,fields:(vt=h.with)==null?void 0:vt.fields,persist:{workflowId:e,stepId:h.id,input:ct},listen:h.uses.app===i.WEBHOOK_APP&&T.listSubscriptionsForWorkflow&&T.startWebhookListen?{stepWith:h.with,readOnly:p}:void 0}):s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",s.jsx("code",{children:h.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),s.jsx(Pn,{seed:Be,readOnly:p}),xe&&!p&&s.jsx(i.LastUsedNote,{onClear:()=>{Se.clear(),_e(!1),E("{}")}}),s.jsx(is,{text:X,onChange:E,seeds:ye,readOnly:p}),Z===null?s.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):s.jsx(xo,{params:Z,values:Fe,testStartState:at,view:ue,literalKeys:h.uses.app===i.SCRIPT_APP?hi:void 0}),s.jsx(i.StepTestRun,{ref:W,app:h.uses.app,action:h.uses.action,connectionId:U,values:Fe,state:Me,canRun:et,hideRunButton:!0,persist:{workflowId:e,stepId:h.id,input:ct},onBusyChange:ee})]}):ke?s.jsxs(s.Fragment,{children:[s.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",s.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",s.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",s.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",s.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),s.jsx(is,{text:X,onChange:wt,seeds:ye,readOnly:p,expand:!Y,hint:s.jsxs(s.Fragment,{children:["Paste a sample list — ",s.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",s.jsx("code",{children:'{"items": […]}'}),". It replaces what ",s.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),s.jsx(mi,{items:Y,save:tt})]}):s.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),s.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[f&&!p&&s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:f,children:"Cancel"}),h.uses.app===i.RACE_APP&&V==="configure"?s.jsx("button",{type:"button",className:"w6w-btn",onClick:c,children:"Done"}):V!=="test"?s.jsxs(s.Fragment,{children:[f&&!p&&s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Done"}),s.jsx("button",{type:"button",className:"w6w-btn",disabled:S,onClick:()=>m(V==="setup"?"configure":"test"),children:"Next →"})]}):s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Done"}),Oe&&!we&&s.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!et||B,onClick:()=>{var N;v==null||v(),(N=W.current)==null||N.run()},children:B?"Testing…":"Test"}),ke&&s.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(Y!=null&&Y.length)||tt==="saving",onClick:()=>void lt(),children:tt==="saving"?"Testing…":"Test"})]})]})]})})}const Ei=!1;function Ti({workflowId:e,step:t,readOnly:o}){const n=i.useW6WApi(),[a,u]=d.useState(void 0),[c,f]=d.useState(null),[p,x]=d.useState(!1);d.useEffect(()=>{const w=n.listSubscriptionsForWorkflow;if(!w)return;let v=!1;return w(e).then(C=>{v||u(i.pickWebhookSubscription(C,t.id))}).catch(C=>!v&&f(C.message)),()=>{v=!0}},[n,e,t.id]);const b=()=>{const w=n.createSubscription;w&&(f(null),x(!0),w(i.WEBHOOK_APP,t.uses.action,{workflowId:e,connectionId:null,params:t.with??{}}).then(v=>{x(!1),u(v)}).catch(v=>{x(!1),f(v instanceof Error?v.message:String(v))}))};return s.jsxs("div",{className:"w6w-stack",children:[s.jsxs("p",{className:"w6w-muted w6w-small",children:[s.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]}),c&&s.jsx("div",{className:"w6w-result w6w-error",children:c}),a!=null&&a.webhookUrl?s.jsx(Ee.Copyable,{value:a.webhookUrl,readOnly:!0,children:s.jsx("input",{type:"text",readOnly:!0,value:a.webhookUrl,"aria-label":"Webhook URL"})}):a===void 0?s.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&s.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:b,children:p?"Creating…":"Create webhook URL"})]})}function Ai({step:e,app:t,actions:o,conns:n,connsFailed:a,isInternal:u,actionLabel:c="Action",readOnly:f,onChangeAction:p,onChangeTriggerEvents:x,onChangeConnection:b,onChangeConnectionRef:w,onChangeApp:v,onConnectionCreated:C}){const L=e.uses.trigger?i.eventbriteTriggerChoices(e.uses.app,o,e.uses.action,e.with??{}):null,[T,D]=d.useState(null),h=d.useRef(null),I=i.useWorkflowConnections(),O=i.connectionIdFor(e,I==null?void 0:I.connections);return s.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!O&&s.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),s.jsxs("div",{className:"w6w-field",children:[s.jsx("span",{children:"App"}),s.jsxs("div",{className:"w6w-app-conn-row",ref:h,children:[s.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":T==="app",disabled:f,onClick:()=>D(U=>U==="app"?null:"app"),children:[!u&&t&&s.jsx(i.AppIcon,{src:t.iconSvg,srcDark:t.iconSvgDark,brandColor:t.brandColor,name:t.displayName,size:20}),s.jsx("span",{className:"w6w-conn-label-name",children:u?e.uses.app:(t==null?void 0:t.displayName)??e.uses.app})]}),!u&&s.jsx(i.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:f,open:T==="conn",onOpenChange:U=>D(U?"conn":null),anchorRef:h,onChangeConnection:b,onChangeConnectionRef:w,onConnectionCreated:C})]}),T==="app"&&s.jsx(i.AnchoredFlyout,{anchorRef:h,onClose:()=>D(null),children:s.jsx(i.AppPicker,{onSelectApp:U=>{const P=U.id===e.uses.app;v(U.id),D(P?"conn":null)}})})]}),u&&!(o!=null&&o.length)?s.jsxs("div",{className:"w6w-field",children:[s.jsx("span",{children:"Action"}),s.jsx("div",{className:"w6w-muted w6w-small",children:s.jsx("code",{children:e.uses.action})})]}):L?s.jsx(i.EventbriteTriggerPicker,{choices:L,readOnly:f,onChange:U=>x(L.triggerKey,U)}):s.jsxs("label",{className:"w6w-field",children:[s.jsx("span",{children:c}),s.jsx(i.Combobox,{value:e.uses.action,disabled:f||o===null,onChange:p,options:o===null?[{value:e.uses.action,label:e.uses.action}]:o.map(U=>({value:U.key,label:U.title??U.key}))})]})]})}function hn({trigger:e}){return s.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":e?"Trigger":"Node",children:s.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e?s.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),s.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function Ii({resources:e}){const t=i.useW6WApi(),o=e.highlightNode;d.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,a]=d.useState([]),[u,c]=d.useState(!0),[f,p]=d.useState(),[x,b]=d.useState(),[w,v]=d.useState(null),[C,L]=d.useState(!1),[T,D]=d.useState(!1),h=d.useRef(0),I=d.useCallback(async()=>{const E=++h.current;c(!0),p(void 0);try{const W=await t.listConnections();return E!==h.current?void 0:(a(W),W)}catch(W){E===h.current&&p(W.message)}finally{E===h.current&&c(!1)}},[t]);d.useEffect(()=>(I(),()=>{h.current++}),[I]);const[O,U]=d.useState(new Map),P=JSON.stringify([...new Set([...Object.values(e.connections).map(E=>E.app),...n.map(E=>E.appId)])].filter(E=>{var W;return!((W=e.apps)!=null&&W.has(E))&&!n.some(B=>B.appId===E&&B.app!==void 0)}).sort());d.useEffect(()=>{var H,z;let E=!1;const W=JSON.parse(P);if(u||!W.length)return;const B=(H=t.listAppsByIds)==null?void 0:H.bind(t),ee=B?Promise.all(Array.from({length:Math.ceil(W.length/50)},(J,Z)=>B(W.slice(Z*50,(Z+1)*50)))).then(J=>J.flat()):(z=t.listApps)==null?void 0:z.call(t);return ee==null||ee.then(J=>{E||U(new Map(J.map(Z=>[Z.id,Z])))}).catch(()=>{}),()=>{E=!0}},[t,P,u]);const R=E=>{var H;const W=n.find(z=>z.appId===E&&z.app)??n.find(z=>z.appId===E&&z.app!==void 0),B=W?i.resolveConnectionAppMeta(W,O):O.get(E),ee=(H=e.apps)==null?void 0:H.get(E);return ee?{...B,...ee}:B},S=E=>{var W;return((W=R(E))==null?void 0:W.displayName)||E},$=E=>{if(e.readOnly)return!1;try{return e.edit(E),b(void 0),!0}catch(W){return b(W.message),!1}},K=E=>i.nextWorkflowConnectionName(E.appId,e.connections),V=()=>{v(null),b(void 0),L(!1)},m=w!=null&&w.ref?e.connections[w.ref]:void 0,_=n.find(E=>E.id===(w==null?void 0:w.connection)),de=(m==null?void 0:m.app)??(_==null?void 0:_.appId),ue=e.nodes.filter(E=>E.uses.app===de),je=e.nodes.filter(E=>(w==null?void 0:w.ref)!==void 0&&E.uses.connectionRef===w.ref),ie=n.filter(E=>!m||E.appId===m.app).map(E=>({value:E.id,label:m?E.displayName||E.id:`${S(E.appId)} · ${E.displayName||E.id}`}));w!=null&&w.connection&&!ie.some(E=>E.value===w.connection)&&ie.unshift({value:w.connection,label:w.connection.startsWith("zerocred:")?"Built-in":w.connection});const k=(E,W=28)=>{const B=R(E);return s.jsx(i.AppIcon,{src:B==null?void 0:B.iconSvg,srcDark:B==null?void 0:B.iconSvgDark,brandColor:B==null?void 0:B.brandColor,name:S(E),size:W})},X=()=>{if(!w||!w.name.trim()||!w.connection||!de)return;const E=w.ref!==void 0?{type:"update",ref:w.ref,name:w.name,connection:w.connection,nodeIds:w.allNodes?ue.map(W=>W.id):void 0}:{type:"add",name:w.name,app:de,connection:w.connection};$(E)&&V()};return s.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[s.jsxs("div",{className:"w6w-workflow-connections-heading",children:[s.jsx("h3",{children:"Connections"}),s.jsx(i.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{b(void 0),v({name:"",connection:"",allNodes:!1})},children:s.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:s.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),f&&s.jsxs("div",{role:"alert",className:"w6w-stack",children:[s.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",f]}),s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void I(),children:"Retry"})]}),Object.entries(e.connections).map(([E,W])=>{var z;const B=e.nodes.filter(J=>J.uses.connectionRef===E),ee=n.find(J=>J.id===W.connection),H=(ee==null?void 0:ee.displayName)||((z=W.connection)!=null&&z.startsWith("zerocred:")?"Built-in":W.connection)||"No credentials selected";return s.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":E,children:[s.jsxs("div",{className:"w6w-connection-app-heading",children:[k(W.app),s.jsxs("div",{className:"w6w-connection-summary",children:[s.jsx("strong",{children:S(W.app)}),s.jsx("span",{className:"w6w-small",children:H}),s.jsxs("span",{className:"w6w-muted w6w-small",children:[E,ee!=null&&ee.state?` · ${ee.state}`:""]})]}),s.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${E}`,disabled:e.readOnly,onClick:()=>{b(void 0),v({ref:E,name:E,connection:W.connection??"",allNodes:!1})}})]}),B.length>0?s.jsxs("details",{className:"w6w-connection-consumers",onToggle:J=>{J.currentTarget.open||o==null||o(null)},children:[s.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",B.length," ",B.length===1?"node":"nodes"]}),s.jsx("ul",{className:"w6w-connection-node-list",children:B.map(J=>s.jsx("li",{children:e.focusNode?s.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${J.id} on canvas`,onClick:()=>{var Z;return(Z=e.focusNode)==null?void 0:Z.call(e,J.id)},onMouseEnter:()=>o==null?void 0:o(J.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(J.id),onBlur:()=>o==null?void 0:o(null),children:[s.jsx(hn,{trigger:i.isTriggerStep(J.uses)}),s.jsxs("span",{className:"w6w-connection-node-label",children:[s.jsx("strong",{children:J.uses.action}),s.jsx("span",{className:"w6w-muted w6w-small",children:J.id})]})]}):s.jsxs("span",{className:"w6w-connection-app-heading",children:[s.jsx(hn,{trigger:i.isTriggerStep(J.uses)}),s.jsxs("span",{className:"w6w-connection-node-label",children:[s.jsx("strong",{children:J.uses.action}),s.jsx("span",{className:"w6w-muted w6w-small",children:J.id})]})]})},J.id))})]}):s.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},E)}),!Object.keys(e.connections).length&&s.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),w&&!T&&!C&&s.jsxs(i.Modal,{title:w.ref!==void 0?"Edit connection":"Add connection",titleIcon:de?k(de):void 0,subtitle:de?S(de):void 0,onClose:V,children:[s.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[x&&s.jsx("p",{role:"alert",className:"w6w-field-error",children:x}),f&&s.jsxs("div",{role:"alert",className:"w6w-stack",children:[s.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",f]}),s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void I(),children:"Retry"})]}),w.ref!==void 0&&!m&&s.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),s.jsxs("label",{className:"w6w-field",children:[s.jsx("span",{children:"Workflow connection name"}),s.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:w.name,disabled:e.readOnly,onChange:E=>v({...w,name:E.target.value})})]}),s.jsxs("div",{className:"w6w-field",children:[s.jsx("span",{children:m?"Credentials":"Existing connection"}),s.jsx(i.Combobox,{"aria-label":m?"Credentials":"Connection to add",options:ie,value:w.connection,placeholder:u?"Loading connections…":"Choose a connection…",disabled:e.readOnly||u||!!f,onChange:E=>{const W=n.find(B=>B.id===E);v({...w,connection:E,name:!w.name&&W?K(W):w.name})}})]}),s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>D(!0),children:"Create new credentials"}),m&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"w6w-muted w6w-small",children:w.allNodes?`Saving applies these credentials to all ${ue.length} ${S(m.app)} nodes.`:`Saving updates credentials for ${je.length} linked ${je.length===1?"node":"nodes"}.`}),ue.length>0&&s.jsxs("label",{className:"w6w-connection-scope",children:[s.jsx("input",{type:"checkbox",checked:w.allNodes||ue.every(E=>E.uses.connectionRef===w.ref),disabled:e.readOnly||ue.every(E=>E.uses.connectionRef===w.ref),onChange:E=>v({...w,allNodes:E.target.checked})}),"Use for all ",ue.length," ",S(m.app)," ",ue.length===1?"node":"nodes"," in this workflow"]}),s.jsxs("div",{className:"w6w-connection-remove",children:[s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly||je.length>0,onClick:()=>L(!0),children:"Remove from workflow"}),je.length>0&&s.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),s.jsxs("div",{className:"w6w-modal-actions",children:[s.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:V,children:"Cancel"}),s.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||u||!!f||!w.name.trim()||!w.connection||!de||w.ref!==void 0&&!m,onClick:X,children:w.ref!==void 0?"Save changes":"Add to workflow"})]})]}),w&&C&&s.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${w.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>L(!1),onConfirm:()=>{w.ref&&$({type:"remove",ref:w.ref})?V():L(!1)}}),w&&T&&s.jsx(i.AddConnectionModal,{initialAppId:m==null?void 0:m.app,onClose:()=>D(!1),onCreated:({connectionId:E})=>{D(!1),I().then(W=>{const B=W==null?void 0:W.find(ee=>ee.id===E);B&&v(ee=>ee?{...ee,connection:B.id,name:ee.name||K(B)}:null)})}})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.RACE_APP=i.RACE_APP;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.centralizeConnections=i.centralizeConnections;exports.coerceDefault=i.coerceDefault;exports.connectionIdFor=i.connectionIdFor;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.isTriggerStep=i.isTriggerStep;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=gn;exports.MAX_NOTE_BYTES=wn;exports.MAX_SECTIONS=mn;exports.WorkflowConnectionsPanel=Ii;exports.WorkflowFlowEditor=pi;exports.applyStepProblemFix=kn;exports.assignMembership=es;exports.clampCanvas=ts;exports.findLoopProblems=Bo;exports.findStateWriteProblems=Ho;exports.isDisabledStep=We;exports.isPausedStep=Qe;exports.pausedStopAt=ns;exports.pruneSectionMembers=rs;exports.renameSectionMember=Qt;exports.roundGeometry=Zt;exports.sectionsContaining=bn;exports.withCanvasGeometry=xn;exports.withDisabled=Cn;exports.withPaused=Sn;
1
+ "use client";"use strict";var io=Object.defineProperty;var ro=(e,s,i)=>s in e?io(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var it=(e,s,i)=>ro(e,typeof s!="symbol"?s+"":s,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),oe=require("@xyflow/react"),c=require("react"),o=require("./connection-app-meta-Cn39S3ED.cjs"),Ee=require("./CodeBlock-BSX1pi6W.cjs"),Ie=require("@w6w/expr");function ao({x:e,y:s,items:i,onAction:n,onClose:a}){const u=c.useRef(null),[l,f]=c.useState({left:e,top:s});c.useLayoutEffect(()=>{const w=u.current,x=w==null?void 0:w.offsetParent;if(!w||!x)return;const g=w.offsetWidth,S=w.offsetHeight;f({left:e+g>x.clientWidth?Math.max(0,e-g):e,top:s+S>x.clientHeight?Math.max(0,s-S):s})},[e,s]),c.useEffect(()=>{var w,x;(x=(w=u.current)==null?void 0:w.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),c.useEffect(()=>{const w=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},x=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},g=()=>a(!1);return document.addEventListener("pointerdown",w,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",g),window.addEventListener("resize",g),()=>{document.removeEventListener("pointerdown",w,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",g),window.removeEventListener("resize",g)}},[a]);const p=w=>{w.disabled||(a(!1),n(w.action))};return t.jsx("div",{ref:u,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:w=>w.preventDefault(),onKeyDown:w=>{var v;w.stopPropagation();const x=[...((v=u.current)==null?void 0:v.querySelectorAll("[role=menuitem]"))??[]],g=x.indexOf(document.activeElement),S=R=>{var E;return(E=x[(R+x.length)%x.length])==null?void 0:E.focus()};if(w.key==="ArrowDown")S(g+1);else if(w.key==="ArrowUp")S(g<0?-1:g-1);else if(w.key==="Home")S(0);else if(w.key==="End")S(-1);else if(w.key==="Escape"||w.key==="Tab")a(!0);else if(w.key==="Enter"||w.key===" ")g>=0&&p(i[g]);else return;w.preventDefault()},children:i.map(w=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":w.disabled||void 0,className:`w6w-note-menu-item${w.danger?" danger":""}${w.separated?" separated":""}`,"data-action":w.action,onClick:()=>p(w),children:w.label},w.action))})}function co(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function lo({app:e,trigger:s,onUse:i}){const n=o.useW6WApi(),[a,u]=c.useState(null);return c.useEffect(()=>{var f;let l=!1;return u(null),(f=n.getAppTriggers)==null||f.call(n,e).then(p=>{var w;l||u(co((w=p.find(x=>x.key===s))==null?void 0:w.sample))}).catch(()=>{}),()=>{l=!0}},[n,e,s]),a?t.jsx("div",{children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>i(a),children:"Use sample event"})}):null}function uo(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function po(e,s,i={}){const n=[],a=e.length;if(a>0){const u=a>1?` ${a} nodes`:"";n.push({action:"duplicate",label:`Duplicate${u}`,disabled:s}),a===1&&i.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${u}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:a>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const mn=200,gn=200,wn=10240;function Zt(e){const s={};for(const[i,n]of Object.entries(e))s[i]=Math.round(n);return s}const fo=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),ho=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Ys(e,s,i){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],u=fo(a==null?void 0:a.position)?a.position:n.position,l=ho(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Zt(u),size:Zt(l)}})}function xn(e,s,i){if(!s)return e;const n={...e};return e.notes&&(n.notes=Ys(e.notes,i)),e.sections&&(n.sections=Ys(e.sections,i)),n}function rs(e,s){return e.sections?{...e,sections:e.sections.map(i=>({...i,nodes:i.nodes.filter(n=>n!==s)}))}:e}function Qt(e,s,i){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?i:a)}))}:e}function es(e,s,i){if(!e.sections)return e;const n=new Set(i);return{...e,sections:e.sections.map(a=>{const u=a.nodes.filter(l=>!n.has(l));return a.id===s?{...a,nodes:[...new Set([...u,...i])]}:{...a,nodes:u}})}}function bn(e,s){return(e.sections??[]).filter(i=>i.nodes.includes(s)).map(i=>i.id)}function mo(e,s){const i=new TextEncoder;if(i.encode(e).length<=s)return e;let n="",a=0;for(const u of e){const l=i.encode(u).length;if(a+l>s)break;n+=u,a+=l}return n}function ts(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,mn).map(i=>({...i,content:mo(i.content,wn)}))),e.sections&&(s.sections=e.sections.slice(0,gn)),s}function go(e,s,i){const n={};for(const l of[...e.notes??[],...e.sections??[]])n[l.id]={position:l.position,size:l.size};const a=(l,f)=>l==null?void 0:l.map(p=>{const w=f==null?void 0:f.find(x=>x.id===p.id);return w?{...p,position:w.position,size:w.size}:p}),u=i?e:{...e,...e.notes?{notes:a(e.notes,s==null?void 0:s.notes)}:{},...e.sections?{sections:a(e.sections,s==null?void 0:s.sections)}:{}};return xn(u,i,n)}const Zs=220;function wo(e){return e.length<=Zs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Zs).trimEnd(),clipped:!0,length:e.length}}function xo({params:e,values:s,testStartState:i,view:n="props",literalKeys:a}){const{sampleValues:u,nodeConfig:l,nodeMeta:f}=o.useExpressionOptions(),p=c.useMemo(()=>o.buildResolveScope(u,i,l,f),[u,i,l,f]),w=o.flattenParams(e),x=v=>{var R;return s[v]!==void 0?s[v]:(R=w.find(E=>E.key===v))==null?void 0:R.default},g=w.filter(v=>v.type!=="section"&&o.isParamVisible(v,x)).map(v=>Ie.effectiveParam(v,x));if(o.hasParamCustomization(s)){const v=o.previewCustomization(s.$merge,p,a),R=v!==null&&typeof v=="object"&&!Array.isArray(v),E=Qs(g,s,p,a);for(const[h,A]of Object.entries(s))h!=="$merge"&&(E[h]=a!=null&&a.includes(h)?A:o.previewCustomization(A,p));const D=R?{...E,...v}:E;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:R?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(v)}). Test the step to validate it.`}),n==="code"?t.jsx(o.JsonEditor,{value:JSON.stringify(D,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):t.jsx("div",{className:"w6w-resolved-table",children:Object.entries(D).map(([h,A])=>{var O;return t.jsx(ss,{label:((O=w.find(U=>U.key===h))==null?void 0:O.label)??h,segments:[{status:"resolved",value:A}]},h)})})]})}if(n==="code"){const v=Qs(g,s,p,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(o.JsonEditor,{value:JSON.stringify(v,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=g.filter(v=>!o.deepEqual(x(v.key),v.default));return g.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):S.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):t.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:S.map(v=>v.type==="vars"?t.jsx(bo,{param:v,value:s[v.key],scope:p},v.key):t.jsx(ss,{label:v.label??v.key,segments:a!=null&&a.includes(v.key)?[{status:"resolved",value:x(v.key)}]:o.resolveParamValue(x(v.key),p)},v.key))})}function Qs(e,s,i,n){const a={};for(const u of e)if(n!=null&&n.includes(u.key))a[u.key]=s[u.key]!==void 0?s[u.key]:u.default;else if(u.type==="vars"){const l=s[u.key]??u.default??[],f=o.dataVarRows(l);a[u.key]=f?o.resolveVarsJson(f,i):o.resolveParamJson(l,i)}else a[u.key]=o.resolveParamJson(s[u.key]!==void 0?s[u.key]:u.default,i);return a}function ss({label:e,segments:s}){return t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e}),t.jsx("div",{className:"w6w-resolved-value",children:t.jsx(yn,{segments:s})})]})}function bo({param:e,value:s,scope:i}){const n=s??e.default??[],a=o.dataVarRows(n);return a===null?t.jsx(ss,{label:e.label??e.key,segments:o.resolveParamValue(n,i)}):t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e.label??e.key}),a.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):t.jsx("div",{className:"w6w-stack",children:a.map((u,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:u.key||"(no key)"})," → ",t.jsx(yn,{segments:o.resolveParamValue(u.value,i)})]},l))})]})}function yn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,i)=>t.jsx(yo,{segment:s},i))})}function yo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx(en,{value:e.value})]}):t.jsx(en,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(ft,{kind:"secret",refName:e.ref})}}function en({value:e}){const[s,i]=c.useState(!1),n=vo(e),a=wo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(Ee.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:t.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):t.jsxs("span",{children:[a.text,"…"]}),t.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>i(u=>!u),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const jo={var:"◆",secret:"🔒",expr:"ƒ"};function ft({kind:e,refName:s}){const i=e==="expr"?"expr":o.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:jo[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:i})]})}function vo(e){if(e===null)return"null";if(e===void 0)return"(not set)";if(e==="")return'""';if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function jn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function So({enabled:e,values:s,onChange:i}){const[n,a]=c.useState(null),u=c.useRef(!1),l=typeof s.code=="string"?s.code:"";return c.useEffect(()=>{if(!e||u.current)return;u.current=!0;const f=o.convertCodeBindingsToReads(l,jn(s));f.converted!==0&&(a({original:l,converted:f.converted}),i({...s,code:f.code}))},[e,l,s,i]),n?{converted:n.converted,undo:()=>{i({...s,code:n.original}),a(null)}}:null}function Co({values:e,conversion:s,readOnly:i}){const n=typeof e.code=="string"?e.code:"",a=s,u=o.findCodeBindings(n,jn(e)).length;return!a&&u===0?null:t.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[a&&t.jsxs(t.Fragment,{children:["Converted ",a.converted," reference",a.converted===1?"":"s"," to code reads",!i&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),u>0&&" · "]}),u>0&&t.jsxs(t.Fragment,{children:[u," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",u===1?"s":""," literal text — read ",u===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function tn(e,s){return{nodeIds:e.filter(i=>i.selected).map(i=>i.id),edgeIds:s.filter(i=>i.selected).map(i=>i.id)}}function No(e,s,i,n){const a=new Set(e.nodeIds),u=new Set(e.edgeIds),l=s.filter(g=>a.has(g.id)),f=[...l.filter(g=>o.isForeachStep(g.data.step)),...l.filter(g=>!o.isForeachStep(g.data.step))];let p=s,w=i,x=n;for(const g of f)w=o.bridgeDeletedBodyStep(g.id,p,w),p=p.filter(S=>S.id!==g.id),x=rs(x,g.id);return{nodes:p,edges:w.filter(g=>!u.has(g.id)),canvas:x}}function ko(e,s,i){var f;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),u=i.filter(p=>a.has(p.id)&&!n.has(p.source)&&!n.has(p.target)),l=[];if(n.size===1)l.push(o.deleteStepMessage(e.nodeIds[0],s,i));else if(n.size>1){l.push(`Delete nodes ${[...n].map(w=>`"${w}"`).join(", ")}? Their connections are removed too.`);const p=new Set;for(const w of n)if(o.isForeachStep((f=s.find(x=>x.id===w))==null?void 0:f.data.step))for(const x of o.loopBody(w,s,i))n.has(x)||p.add(x);p.size&&l.push(`Loop body steps ${[...p].map(w=>`"${w}"`).join(", ")} stay as standalone steps.`)}return u.length&&l.push(`Delete ${u.length===1?"connection":"connections"} ${u.map(p=>`"${p.source} → ${p.target}"`).join(", ")}?`),l.join(" ")}function Lt(e,s,i,n,a){const u=o.flowToWorkflow({...e,connections:n},s,i);return{nodes:u.nodes.map(({with:l,...f})=>l&&Object.keys(l).length?{...f,with:l}:f),edges:u.edges??[],connections:u.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Eo(e,s){const i=o.workflowToFlow({...e,...s});return{...i,nodes:i.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class To{constructor(s,i=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(this,"limit");this.limit=i,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,i){const n=JSON.stringify(s);n!==this.present&&((!i||i!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=i,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const i=this.past.lastIndexOf(s);return i>=0&&(this.past.length=i),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Gt(e){var i;const s=e;return!!(s!=null&&s.isContentEditable||(i=s==null?void 0:s.closest)!=null&&i.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Io=64,ht=24,Ze=32;function Ft(e){var s,i;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((i=e.measured)==null?void 0:i.height)??e.height??64}}function Ao(e,s){return e.x<s.x+s.width&&e.x+e.width>s.x&&e.y<s.y+s.height&&e.y+e.height>s.y}function Po(e){const s=(a,u)=>{const l=new Map;for(const w of e){const x=w.position[a];l.set(x,Math.max(l.get(x)??0,Ft(w)[u]))}const f=new Map;let p=Number.NEGATIVE_INFINITY;for(const[w,x]of[...l].sort(([g],[S])=>g-S)){const g=Math.max(w,p);f.set(w,g),p=g+x+Io}return f},i=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:i.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Ro(e,s,i){var f;const n=Po(o.relayoutNodes(e,s));if(!((f=i.sections)!=null&&f.length))return{nodes:n,canvas:i};const a=new Map(n.map(p=>[p.id,p])),u=(i.notes??[]).map(p=>({...p.position,...p.size}));for(const p of i.sections)p.nodes.some(w=>a.has(w))||u.push({...p.position,...p.size,y:p.position.y-Ze,height:p.size.height+Ze});const l=i.sections.map(p=>{const w=new Set(p.nodes),x=n.filter(A=>w.has(A.id));if(!x.length)return p;const g=Math.min(...x.map(A=>A.position.x))-ht,S=Math.min(...x.map(A=>A.position.y))-ht,v=Math.max(...x.map(A=>A.position.x+Ft(A).width)),R=Math.max(...x.map(A=>A.position.y+Ft(A).height)),E={x:g,y:S,width:v+ht-g,height:R+ht-S},D=[...u,...[...a.values()].filter(A=>!w.has(A.id)).map(A=>({...A.position,...Ft(A)}))].sort((A,O)=>A.y-O.y);for(const A of D){const O={...E,y:E.y-Ze,height:E.height+Ze};Ao(O,A)&&(E.y=A.y+A.height+ht+Ze)}const h=E.y-S;for(const A of x)a.set(A.id,{...A,position:{x:A.position.x,y:A.position.y+h}});return u.push({...E,y:E.y-Ze,height:E.height+Ze}),{...p,position:{x:E.x,y:E.y},size:{width:E.width,height:E.height}}});return{nodes:n.map(p=>a.get(p.id)??p),canvas:{...i,sections:l}}}const Kt=6;function Mo(e){let s=2166136261;for(let i=0;i<e.length;i++)s^=e.charCodeAt(i),s=Math.imul(s,16777619);return s>>>0}function Lo(e){const s=new Map;let i=new Set;for(const n of[...new Set(e)].sort()){i.size===Kt&&(i=new Set);let a=Mo(n)%Kt;for(;i.has(a);)a=(a+1)%Kt;i.add(a),s.set(n,a+1)}return s}function as(e){return`var(--w6w-loop-${e})`}function vn(e,s){const i=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),i.unshift(a);return i}function Fo(e,s,i){return s.size===0?e:e.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const a=n.sourceHandle===o.EACH_SOURCE_HANDLE?n.source:i.get(n.source),u=a?s.get(a):void 0;return u===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":as(u)}}})}function Do(e,s){const i=s.get(e);return i===void 0?void 0:{"--w6w-loop-color":as(i)}}function Oo(e){const s=[];for(const i of e){const n=o.isForeachStep(i.data.step);(n||i.data.loopOf)&&s.push([i.id,n?1:0,i.data.loopOf])}return JSON.stringify(s)}function _o(e){const s=JSON.parse(e);return{tones:Lo(s.filter(i=>i[1]===1).map(i=>i[0])),loopOf:new Map(s.map(i=>[i[0],i[2]]))}}const sn="Paused — test runs stop before this node",nn="Disabled — skipped in every run";function Qe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function We(e){return e.disabled===!0}function Sn(e,s){const{ui:i,...n}=e,{paused:a,...u}=i??{},l=s?{...u,paused:!0}:u;return Object.keys(l).length>0?{...n,ui:l}:n}function Cn(e,s){const{disabled:i,...n}=e;return s?{...n,disabled:!0}:n}function ns(e,s){return e.filter(i=>i.id!==s&&Qe(i)).map(i=>i.id)}const Wo=["nodes","steps"];function on(e,s){for(const i of Wo){const n=`${i}.${s}.output`;if(!e.startsWith(n))continue;const a=e.slice(n.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function Dt(e,s,i){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=o.parseRootAnchoredTemplate(e);let a=!1;const u=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const f=on(l.ref,s);return f===null?l:(a=!0,i.includes(l.ref)||i.push(l.ref),{...l,ref:f})});return a?Ie.serializeTemplate(u):e}if(o.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=on(n,s);return a===null?e:(i.includes(n)||i.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(u=>{const l=Dt(u,s,i);return l!==u&&(n=!0),l});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[u,l]of Object.entries(e)){const f=Dt(l,s,i);f!==l&&(n=!0),a[u]=f}return n?a:e}return e}function $o(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=o.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return o.isDollarPath(e)&&typeof e.$=="string"}function Nn(e){return Array.isArray(e)&&e.length===1&&$o(e[0])}function Bo(e){var s;try{const i=o.normalizeInput(e);if(!Array.isArray(i.nodes))return{};const n={},a=(l,f)=>{const p=Object.hasOwn(n,l)?n[l]:[];p.push(f),n[l]=p},u=new Map(i.nodes.map(l=>[l.id,l]));for(const[l,f]of Object.entries(o.definitionLoops(i))){const p=u.get(l);if(p&&Nn((s=p.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){a(l,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const w of f.body){const x=u.get(w);if(!(x!=null&&x.with))continue;const g=[];Dt(x.with,l,g),g.length>0&&a(w,{code:"foreach_body_refs_output",foreachId:l,refs:g,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function Vo(e){const s=new Set,i=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)i(a)};return i(e),s}function zo(e){var s,i;try{const n=o.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(P=>typeof P=="object"&&P!==null&&typeof P.id=="string"),u=o.effectiveEdges({...n,nodes:a}).filter(P=>typeof(P==null?void 0:P.from)=="string"&&typeof(P==null?void 0:P.to)=="string"),l=[];for(const P of a)try{const M=Ie.staticWritePaths(Ie.effectiveStateConfig((s=P.uses)==null?void 0:s.app,(i=P.uses)==null?void 0:i.action,P.state));M.length>0&&l.push({id:P.id,paths:M})}catch{}if(l.length<2)return[];const f=new Map;for(const P of a)for(const M of o.controlOwnedIds(P))f.has(M)||f.set(M,P.id);const p=P=>{const M=[P];let C=P;for(;f.has(C)&&(C=f.get(C),!M.includes(C));)M.push(C);return M},w=P=>{const M=p(P);return M[M.length-1]},x=new Map;for(const P of u){const M=x.get(P.from)??[];M.push(P.to),x.set(P.from,M)}const g=new Map,S=P=>{const M=g.get(P);if(M)return M;const C=new Set,$=[...x.get(P)??[]];for(;$.length>0;){const K=$.pop();if(!C.has(K)){C.add(K);for(const V of x.get(K)??[])$.push(V)}}return g.set(P,C),C},v=(P,M)=>P===M||S(P).has(M),R=a.filter(P=>{var M;return((M=P.uses)==null?void 0:M.app)===o.CONTROL_APP&&P.uses.action==="parallel"}).map(P=>{var C;const M=(C=P.with)==null?void 0:C.branches;return Array.isArray(M)?M.map(Vo):[]}),E=(P,M)=>{for(const C of p(M)){const $=P.findIndex(K=>K.has(C));if($>=0)return $}return-1},D=[];for(const P of a){if(P.fanOut!=="parallel")continue;const M=new Map;for(const C of u){if(C.from!==P.id||o.isEachLink(C))continue;const $=C.when??"success",K=M.get($)??[];K.push(C.to),M.set($,K)}for(const C of M.values())C.length>=2&&D.push(C)}const h=(P,M)=>{for(const K of R){const V=E(K,P),b=E(K,M);if(V>=0&&b>=0&&V!==b)return!0}const C=w(P),$=w(M);return C===$||S(C).has($)||S($).has(C)?!1:D.some(K=>K.some((V,b)=>K.some((_,de)=>b!==de&&v(V,C)&&v(_,$))))},A=new Set,O=[];for(let P=0;P<l.length;P++)for(let M=P+1;M<l.length;M++){const C=l[P],$=l[M];if(!(C.id===$.id||!h(C.id,$.id)))for(const K of C.paths)for(const V of $.paths){if(!Ie.statePathsOverlap(K,V))continue;const b={code:"state_parallel_write",nodes:[C.id,$.id].sort(),path:[...K.length<=V.length?K:V]},_=JSON.stringify([b.nodes,b.path]);A.has(_)||(A.add(_),O.push(b))}}const U=(P,M)=>P<M?-1:P>M?1:0;return O.sort((P,M)=>U(P.code,M.code)||U(P.nodes.join(","),M.nodes.join(","))||U(P.path.join("."),M.path.join(".")))}catch{return[]}}function Ho(e){try{const s={};for(const i of zo(e))for(const n of i.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:i.code,path:[...i.path],with:i.nodes.filter(u=>u!==n)}),s[n]=a}return s}catch{return{}}}function kn(e,s){var i;if(s.code==="foreach_wrapped_items"){const n=(i=e.with)==null?void 0:i.items;return!e.with||!Nn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=Dt(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function rn(e,s,i){return e&&e.nodeId===s&&e.handleType===((i==null?void 0:i.type)??"source")?o.laneForSourceHandle(e.handleId):o.laneForSourceHandle(i==null?void 0:i.id)}function Jo(e,s,i,n,a){var w;const u=(w=n.find(x=>x.id===e))==null?void 0:w.data.step,l=o.loopMembership(n,a)[e]!==void 0,f=i==="success"&&l?"each":i;if(f==="each"&&!l&&!o.isForeachStep(u))return null;const p=i==="success"&&o.isForeachStep(u)?o.FOREACH_DONE_ROUTE:void 0;return o.loopRefusal(e,s,f,n,a,p)}function Ot(e,s){var i;return(i=e.nodes??e.steps)==null?void 0:i[s]}function os(e,s){const i=Ot(e,s);return(i==null?void 0:i.status)==="skipped"&&i.skipReason==="not_on_path"}const Uo=new Set(["succeeded","failed","canceled"]);function qo(e,s,i=[]){var u,l;if(!e||[...i,s].some(f=>os(e,f)))return"no-run";const n=Ot(e,s);if(n)return n.status;const a=new Set;for(const f of Object.values(e.nodes??e.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const p of f.iterations){const w=(l=(u=p==null?void 0:p.nodes)==null?void 0:u[s])==null?void 0:l.status;w&&a.add(w)}for(const f of["failed","running","succeeded","skipped"])if(a.has(f))return f;return"pending"}const an={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function En(e,s){const i=s!==void 0&&Uo.has(s);switch(e){case"no-run":return an;case"pending":return i?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return an}}function Go(e,s,i,n,a){var l;if(!e||os(e,s)||a!==void 0&&os(e,a))return;const u=Ko(e,s,i,n);return u==="taken"&&a!==void 0&&((l=Ot(e,a))==null?void 0:l.status)==="skipped"?"skipped":u}function Ko(e,s,i,n){const a=Ot(e,s);if(!a)return;if(i==="each")return a.status==="skipped"?"skipped":void 0;const u=i??"success",l=a.output,f=n===o.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!f&&a.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(a.status==="succeeded")return u==="success"?"taken":"skipped";if(a.status==="failed")return u==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const cn={fields:[],sampleValues:{}};function cs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Xo(e,s){var w;const i=e.map(x=>x.id),n=new Set(i),a=new Map(i.map(x=>[x,0])),u=new Map(i.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((w=u.get(x.source))==null||w.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const l=[],f=i.filter(x=>a.get(x)===0);for(;f.length>0;){const x=f.shift();l.push(x);for(const g of u.get(x)??[]){const S=(a.get(g)??0)-1;a.set(g,S),S===0&&f.push(g)}}const p=new Set(l);for(const x of i)p.has(x)||l.push(x);return l}const Yo=new Set(["string","number","boolean","object","array"]);function mt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let i=!1;for(const n of e){if(!cs(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let u=s;for(const p of a.slice(0,-1)){const w=u.fields[p];(w==null?void 0:w.type)!=="object"&&(u.fields[p]={type:"object",fields:{}}),u=u.fields[p]}const l=typeof n.type=="string"&&Yo.has(n.type)?n.type:"string";let f;if(l==="array"){const p=mt(n.items);f=p?{type:"array",items:p}:{type:"array"}}else l==="object"?f=mt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:l};u.fields[a[a.length-1]]=f,i=!0}return i?s:void 0}function Zo(e,s){var w,x,g,S,v,R,E;const i=e.data.step,n=((w=s.testOutputs)==null?void 0:w[i.id])??((x=s.persistedOutputs)==null?void 0:x[i.id]);if(n!=null)return n;const{app:a,action:u}=i.uses;if(a===o.TRIGGER_APP&&((g=o.internalNodeDef(a,u))==null?void 0:g.group)==="trigger"){const D=o.fieldsToParams(o.asFieldDefs((S=i.with)==null?void 0:S.fields)).map(h=>({key:h.key}));return o.shapeToSkeleton(mt(D))}const l=(v=o.internalNodeDef(a,u))==null?void 0:v.output;if(l&&l.length>0)return o.shapeToSkeleton(mt(l));const f=i.uses.trigger===!0?(R=s.triggerDef)==null?void 0:R.call(s,a,u):(E=s.actionDef)==null?void 0:E.call(s,a,u),p=mt(f==null?void 0:f.output);return p?o.shapeToSkeleton(p):f==null?void 0:f.sample}function Qo(e,s){var f,p,w,x,g;const i=e.data.step,n=(f=s.previewOutputs)==null?void 0:f[i.id];if(n!=null)return n;const{app:a,action:u}=i.uses,l=i.uses.trigger===!0?(w=(p=s.shapes)==null?void 0:p.triggerDef)==null?void 0:w.call(p,a,u):(g=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:g.call(x,a,u);return l==null?void 0:l.sample}function ei(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function ln(e,s){const i=cs(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?i[n.key]=n.default:s||(i[n.key]=ei(n.type)));return i}function Xt(e){return(o.inferOutputFields(e)??[]).map(s=>s.key)}function ti(e){const{anchorId:s,nodes:i,edges:n}=e;if(!s)return cn;const a=e.shapes??{},u=e.floating?new Set(i.map(C=>C.id)):o.ancestorIds(s,n);u.delete(s);const l=new Map(i.map(C=>[C.id,C])),f=[],p=[],w=new Map;for(const C of Xo(i,n)){if(!u.has(C))continue;const $=l.get(C);if(!$)continue;const{app:K,action:V}=$.data.step.uses,b=Ie.effectiveStateConfig(K,V,$.data.step.state);if(b.mode==="off")continue;const _=Zo($,a);if(_!==void 0){const{ops:ue}=Ie.computeStateWrites(b,_);f.push(...ue);for(const je of Xt(Ie.foldState({},ue))){const ie=w.get(je)??new Set;ie.add(C),w.set(je,ie)}}const de=Qo($,e);de!==void 0&&p.push(...Ie.computeStateWrites(b,de).ops)}const x=ln(e,!1),g=Ie.foldState(x,f),S=Xt(g);if(S.length===0)return cn;const v=new Set(Xt(x)),R=new Map,E=new Map;for(const C of n)u.has(C.source)&&(!u.has(C.target)&&C.target!==s||(R.set(C.target,[...R.get(C.target)??[],C.source]),E.set(C.source,[...E.get(C.source)??[],C.target])));const D=[...u].filter(C=>!(R.get(C)??[]).length),h=C=>{const $=new Set,K=D.filter(V=>!C.has(V));for(;K.length>0;){const V=K.pop();if(V===s)return!1;if(!$.has(V)){$.add(V);for(const b of E.get(V)??[])C.has(b)||K.push(b)}}return!0},A=Ie.foldState(ln(e,!0),p),O=p.length>0?Ie.foldState({},p):void 0,U=cs(O)&&Object.keys(O).length>0?O:void 0,P=[],M={};for(const C of S){const $=w.get(C)??new Set,K=v.has(C)||$.size>0&&h($);P.push({key:C,path:!0,paths:K?"all":"some"});const V=o.valueAtPath(A,C);V!==void 0&&(M[`state.${C}`]=V)}return{fields:P,sampleValues:M,...U?{written:U}:{}}}const si={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},dn="Never fired";function ni(e){if(!e)return dn;const s=new Date(e);return Number.isNaN(s.getTime())?dn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function oi(e,s){var a;if(!(e!=null&&e.status))return null;const i=si[e.status];if(!i)return null;const n=e.status==="failed";return{label:i.label,tone:i.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:ni(e.lastFireAt),retryVisible:n&&s}}function ii(e){const s=new Map;for(const i of e)i.nodeId&&s.set(i.nodeId,i);return s}function ri(e){return(e??[]).filter(s=>{var i;return((i=s.uses)==null?void 0:i.trigger)===!0})}function ai(e,s){const[i,n]=c.useState({}),a=c.useRef(new Set),u=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!o.isInternalApp(l)).sort());return c.useEffect(()=>{const l=JSON.parse(u).filter(f=>!a.current.has(f));if(l.length!==0){for(const f of l)a.current.add(f);Promise.all(l.map(async f=>{try{return[f,await e.getAppActions(f)]}catch{return a.current.delete(f),null}})).then(f=>{const p=f.filter(w=>w!==null);p.length!==0&&n(w=>({...w,...Object.fromEntries(p)}))})}},[e,u]),i}function ci(e,s){const[i,n]=c.useState({}),a=c.useRef(new Set),u=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!o.isInternalApp(l)).sort());return c.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const f=JSON.parse(u).filter(p=>!a.current.has(p));if(f.length!==0){for(const p of f)a.current.add(p);Promise.all(f.map(async p=>{try{return[p,await l.call(e,p)]}catch{return a.current.delete(p),null}})).then(p=>{const w=p.filter(x=>x!==null);w.length!==0&&n(x=>({...x,...Object.fromEntries(w)}))})}},[e,u]),i}function li(e){return(s,i)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(u=>u.key===i))==null?void 0:a.ports}}const di="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function un(e,s,i,n){const a=e.find(u=>u.id===s);return[i,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ls=c.createContext(void 0),ds=c.createContext(new Map),us=c.createContext({tones:new Map,loopOf:new Map});function pn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const ps=c.createContext(new Map),Tn=c.createContext({byNode:new Map,subs:[]});function ui({apps:e,registration:s,children:i}){return t.jsx(ps.Provider,{value:e,children:t.jsx(Tn.Provider,{value:s,children:i})})}const fs=c.createContext(null);function pi(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(fi,{...e})})}function fn(e,s){let i=s.length+1;for(;s.includes(`${e}-${i}`);)i++;return`${e}-${i}`}function Yt(e){var s,i;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((i=e.measured)==null?void 0:i.height)??e.height??64}}function fi({onConnectionResourcesChange:e,value:s,onChange:i,readOnly:n,height:a=480,apps:u,exprOptions:l,project:f,runState:p,stepProblems:w,onTestRun:x,fitViewKey:g,onRunFromNode:S}){var Hs,Js,Us,qs,Gs,Ks,Xs;const v=o.useW6WApi(),R=c.useMemo(()=>new Map((u??[]).map(r=>[r.id,r])),[u]),E=yi(s),[D,h]=c.useState(null),A=c.useMemo(()=>o.centralizeConnections(s),[s.id]),O=c.useMemo(()=>o.workflowToFlow(A),[A]),[U,P]=c.useState(A.connections??{}),M=c.useRef(U),C=c.useCallback(r=>{M.current=r,P(r)},[]),$=c.useCallback(r=>{const d=o.centralizeConnections({nodes:[r],connections:M.current});return d.connections!==M.current&&C(d.connections),d.nodes[0]},[C]),K=c.useMemo(()=>o.storedViewport(s),[s.id]),V=((Hs=s.settings)==null?void 0:Hs.savePosition)!==!1,[b,_,de]=oe.useNodesState(O.nodes),ue=ai(v,b),je=ci(v,b),ie=c.useMemo(()=>li(ue),[ue]),[k,X,T]=oe.useEdgesState(O.edges),[W,B]=c.useState(null),ee=c.useMemo(()=>s.canvas??{},[s.id]),[H,z]=c.useState(ee),[J]=c.useState(()=>new To(Lt(A,O.nodes,O.edges,U,ee))),Z=c.useRef(),[pe,Je]=c.useState(0),[De,rt]=c.useState(!1),[ve,Ue]=c.useState(null),[Ae,ge]=c.useState(null),[ae,Ne]=c.useState(null),[$e,te]=c.useState(!1),gt=c.useRef({});c.useEffect(()=>{$e||(gt.current={})},[$e]);const[re,Pe]=c.useState(null),[Oe,ke]=c.useState("props"),[we,qe]=c.useState(null),[ye,Be]=c.useState(null),[Re,Me]=c.useState(null),at=c.useRef(!1),Se=c.useRef(null),[xe,_e]=c.useState(null),{screenToFlowPosition:Le,fitView:Fe}=oe.useReactFlow(),ct=o.useEffectiveTheme();c.useEffect(()=>{_(O.nodes),X(O.edges),B(null),Ne(null),Me(null),Pe(null),qe(null),z(ee),C(A.connections??{}),J.reset(Lt(A,O.nodes,O.edges,A.connections??{},ee)),Z.current=void 0},[O,ee,A,_,X,C,J]),c.useEffect(()=>{_(r=>{const d=new Map(o.stampLoopOf(r,k).map(m=>[m.id,m.data.loopOf]));return r.map(m=>{const y=qo(p,m.id,vn(m.id,d));return m.data.stepStatus===y&&m.data.runStatus===(p==null?void 0:p.status)?m:{...m,data:{...m.data,stepStatus:y,runStatus:p==null?void 0:p.status}}})}),X(r=>r.map(d=>{var I;const m=o.edgeLane(d),y=Go(p,d.source,m,typeof((I=d.data)==null?void 0:I.route)=="string"?d.data.route:void 0,d.target),j=o.edgeVisuals(m,y);return d.className===j.className&&d.label===j.label?d:{...d,className:j.className,label:j.label}}))},[p,O,pe,_,X]),c.useEffect(()=>{_(r=>o.applyStepProblems(r,w))},[w,O,pe,_]);const et=c.useCallback((r,d)=>{var j,I;const{canvas:m,...y}=r;return!((j=d.notes)!=null&&j.length)&&!((I=d.sections)!=null&&I.length)?y:{...y,canvas:go(d,s.canvas,V)}},[s.canvas,V]),Y=c.useCallback((r,d,m)=>{J.record(Lt(s,r,d,M.current,m??H),$e?gt.current:Z.current),i(et(o.flowToWorkflow({...s,connections:M.current},r,d),m??H))},[s,i,H,et,J,$e]),tt=c.useRef(()=>{});tt.current=r=>{if(n)return;const d=o.editConnectionResources(b.map(y=>y.data.step),M.current,r),m=b.map((y,j)=>({...y,data:{...y.data,step:d.nodes[j]}}));C(d.connections),_(m),Y(m,k)};const Ge=c.useCallback(r=>tt.current(r),[]),wt=c.useCallback(r=>{B(r),Ne(null),_(d=>d.map(m=>({...m,selected:m.id===r}))),X(d=>d.map(m=>({...m,selected:!1}))),Fe({nodes:[{id:r}],duration:300,maxZoom:1})},[_,X,Fe]),[lt,ce]=c.useState(null),xt=c.useMemo(()=>lt?b.map(r=>r.id===lt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,lt]),bt=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),yt=JSON.stringify(bt),jt=JSON.stringify([...R]);c.useEffect(()=>{e==null||e({workflowId:s.id,nodes:bt,apps:R,connections:U,readOnly:n,edit:Ge,focusNode:wt,highlightNode:ce})},[e,s.id,yt,jt,U,n,Ge,wt]),c.useEffect(()=>()=>e==null?void 0:e(null),[e]);const vt=c.useCallback(r=>o.canConnect(r.source,r.target,b,k,ie,o.routeFromHandle(r.sourceHandle)),[b,k,ie]),[N,G]=c.useState(null),se=c.useRef(null),he=c.useRef(null);c.useEffect(()=>{_(r=>o.stampLoopOf(r,k))},[k,_]);const st=c.useCallback(r=>{if(n)return;const d=o.applyConnect(r.source,r.target,b,k,o.laneForSourceHandle(r.sourceHandle),ie,o.routeFromHandle(r.sourceHandle));if(!d){const m=o.laneForSourceHandle(r.sourceHandle),y=o.connectRefusal(r.source,r.target,b,k,m,ie,o.routeFromHandle(r.sourceHandle));if(y&&y.refused==="loop"){G({nodeId:r.source,reason:y.reason});return}if(y){const I=k.find(F=>F.source===r.source&&o.edgeLane(F)===m);I&&(X(k.map(F=>({...F,selected:F.id===I.id}))),Ne(I.id),Ke({edgeId:I.id,message:pn(y.cap)}));return}const j=o.connectConflict(r.source,r.target,b,k,o.laneForSourceHandle(r.sourceHandle));if(!j)return;X(k.map(I=>({...I,selected:I.id===j}))),Ne(j),Ke({edgeId:j,message:o.idClashMessage("Can’t draw that edge",j,un(k,j,r.source,r.target))});return}Ke(null),G(null),X(d),Y(b,d)},[k,b,X,Y,n,ie]),Wn=c.useCallback((r,d)=>{var q,Q,le;if(n||d.isValid)return;const m=d.fromNode;if(!m)return;const y=((q=d.fromHandle)==null?void 0:q.type)==="target"?"target":"source",j=d.toNode;if(j&&y==="source"){const ne=Jo(m.id,j.id,rn(he.current,m.id,d.fromHandle),b,k);if(ne){G({nodeId:m.id,reason:ne});return}}const I=(Q=b.find(ne=>ne.id===m.id))==null?void 0:Q.data.step;if(I){const ne=o.nodePortsForStep(I,ie);if((y==="source"?ne.out:ne.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,L=Le({x:F.clientX,y:F.clientY});_e({nodeId:m.id,handleType:y,position:L,lane:rn(he.current,m.id,d.fromHandle),route:o.routeFromHandle((le=d.fromHandle)==null?void 0:le.id)}),te(!0)},[n,Le,b,k,ie]),ms=c.useCallback((r,d,m)=>{if(n)return;const y=b.find(q=>q.id===r);if(!y)return;const j=Yt(y),I=o.laneForSourceHandle(m),F=120,L=d==="target"?{x:j.x-j.w-F,y:j.y}:I==="error"?{x:j.x,y:j.y+j.h+F}:I==="each"?{x:j.x+j.w+F,y:j.y-j.h-F/2}:{x:j.x+j.w+F,y:j.y};_e({nodeId:r,handleType:d,position:L,lane:I,route:o.routeFromHandle(m)}),te(!0)},[n,b]),gs=c.useCallback(r=>{n||Me({nodeIds:[r],edgeIds:[]})},[n]),$n=c.useCallback(r=>{if(n)return;const d=No(r,b,k,H);_(d.nodes),X(d.edges),z(d.canvas),d.nodes.some(m=>m.id===W)||B(null),d.nodes.some(m=>m.id===re)||Pe(null),d.edges.some(m=>m.id===ae)||Ne(null),Y(d.nodes,d.edges,d.canvas)},[b,k,H,_,X,Y,n,W,re,ae]),ws=c.useCallback(()=>{if(n)return;const r=Ro(b,k,H);_(r.nodes),z(r.canvas),at.current=!0,Y(r.nodes,k,r.canvas)},[b,k,H,_,Y,n]),Bn=c.useCallback(()=>{n||ws()},[n,ws]);c.useEffect(()=>{at.current&&(at.current=!1,Fe({duration:300}))},[b,Fe]);const xs=c.useRef(g);c.useEffect(()=>{Object.is(xs.current,g)||(xs.current=g,Fe({duration:300}))},[g,Fe]);const[St,Ke]=c.useState(null),nt=c.useMemo(()=>k.find(r=>r.id===ae)??null,[k,ae]),Vn=c.useCallback(r=>{if(n||!ae)return;const d=k.find(F=>F.id===ae);if(!d||o.edgeLane(d)===r)return;const m=o.edgeWhenConflict(k,ae,r,b),y=o.relaneRefusal(k,ae,r,b,ie),j=m||y?null:o.setEdgeWhen(k,ae,r,b,ie);if(!j){if(y){Ke({edgeId:ae,message:pn(y.cap)});return}Ke({edgeId:ae,message:m?o.idClashMessage("Can’t switch this edge",m,un(k,m,d.source,d.target)):"This edge can’t be switched right now."});return}Ke(null),X(j);const I=j.find(F=>F.source===d.source&&F.target===d.target&&o.edgeLane(F)===r);Ne((I==null?void 0:I.id)??null),Y(b,j)},[k,b,X,Y,n,ae,ie]),zn=c.useCallback(r=>{if(n)return;const d=k.filter(m=>m.id!==r);d.length!==k.length&&(X(d),ae===r&&Ne(null),Y(b,d))},[b,k,X,Y,n,ae]),Wt=c.useCallback(r=>{if(n)return;const d=r.map(I=>b.find(F=>F.id===I)).filter(I=>I!==void 0);if(d.length===0)return;const m=b.map(I=>I.id),y=d.map(I=>{const F=o.suggestStepId(m,`${I.data.step.id}_copy`);m.push(F);const L={...o.stripBody(structuredClone(I.data.step)),id:F};return{id:F,type:I.type,position:{x:I.position.x+40,y:I.position.y+60},data:{step:L,isInternal:I.data.isInternal},...d.length>1?{selected:!0}:{}}}),j=[...d.length>1?b.map(I=>I.selected?{...I,selected:!1}:I):b,...y];_(j),B(y[0].id),Y(j,k)},[b,k,_,Y,n]),bs=c.useCallback(r=>Wt([r]),[Wt]),Hn=c.useCallback(r=>{if(n)return;const d=o.isInternalApp(r.uses.app),m=b.map(ne=>ne.id),y=r.id&&!o.stepNameError(r.id,m)?r.id:o.suggestStepId(m,o.slugifyLabel(o.internalNodeLabel(r.uses.app,r.uses.action))),j=$({id:y,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),I={id:y,type:d?"control":"step",position:(xe==null?void 0:xe.position)??(ye==null?void 0:ye.position)??{x:80,y:80+b.length*24},data:{step:j,isInternal:d}},F=ye!=null&&ye.replaces?b.find(ne=>ne.id===ye.replaces):void 0;if(F&&o.isTriggerStep(r.uses)){const ne={...I,position:F.position},fe=[...b.filter(pt=>pt.id!==F.id),ne],me=o.renameStepInEdges(k,F.id,y),Te=Qt(H,F.id,y);return _(fe),X(me),z(Te),G(null),B(y),Y(fe,me,Te),y}const L=[...b,I];let q=k,Q=null;const le=(ne,fe,me,Te)=>{const pt=o.connectRefusal(ne,fe,L,k,me,ie);pt&&pt.refused==="loop"&&(Q={nodeId:Te,reason:pt.reason})};if(xe){const[ne,fe]=xe.handleType==="target"?[y,xe.nodeId]:[xe.nodeId,y],me=o.applyConnect(ne,fe,L,k,xe.lane,ie,xe.route);me||le(ne,fe,xe.lane,xe.nodeId),q=me??k}else{const ne=b.find(fe=>o.isTriggerStep(fe.data.step.uses));if(o.isTriggerStep(r.uses)){if(!ne){const fe=o.findChainRoot(b,k);if(fe){const me=o.applyConnect(y,fe.id,L,k,"success",ie);me||le(y,fe.id,"success",fe.id),q=me??k}}}else{const me=(ne&&!k.some(Te=>Te.source===ne.id)?ne:void 0)??o.findChainTail(b,k);if(me){const Te=o.applyConnect(me.id,y,L,k,"success",ie);Te||le(me.id,y,"success",me.id),q=Te??k}}}return _(L),q!==k&&X(q),G(Q),B(y),Y(L,q),y},[b,k,_,X,Y,n,xe,ye,ie,$,H]),ys=c.useCallback((r,d)=>{var q;let m=d;const y=(q=b.find(Q=>Q.id===r))==null?void 0:q.data.step;if(d.uses.connection&&!d.uses.connectionRef&&(y!=null&&y.uses.connectionRef)&&y.uses.app===d.uses.app){const Q=o.selectNodeConnection(o.withConnectionRef(d,y.uses.connectionRef),d.uses.connection,b.map(le=>le.data.step),M.current);C(Q.connections),m=Q.step}else m=$(d);const j=m.id!==r;if(j&&b.some(Q=>Q.id===m.id))return;const I=b.map(Q=>Q.id===r?{...Q,id:m.id,data:{step:m,isInternal:o.isInternalApp(m.uses.app)}}:Q);if(j){const Q=o.renameStepInEdges(k,r,m.id),le=Qt(H,r,m.id);_(I),X(Q),z(le),W===r&&B(m.id),re===r&&Pe(m.id),Y(I,Q,le);return}_(I);const F=new Set(o.routesForStep(m).map(Q=>Q.id)),L=k.filter(Q=>{var le;return Q.source!==m.id||((le=Q.data)==null?void 0:le.route)===void 0||F.has(String(Q.data.route))});L.length!==k.length&&X(L),Y(I,L)},[b,k,H,_,X,W,re,Y,$,C]),Xe=c.useCallback(r=>{n||(z(r),Y(b,k,r))},[n,b,k,Y]),Jn=c.useCallback(()=>{var j;if(n)return;const r=(j=Se.current)==null?void 0:j.getBoundingClientRect(),d=r?Le({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},m=H.notes??[],y={id:fn("note",m.map(I=>I.id)),color:"#facc15",position:{x:Math.round(d.x-100),y:Math.round(d.y-60)},size:{width:200,height:120},content:""};Xe(ts({...H,notes:[...m,y]}))},[n,H,Le,Xe]),Un=c.useCallback((r,d)=>{if(n)return;const m=d?Math.min(r.x,d.x):r.x,y=d?Math.min(r.y,d.y):r.y,j=d?Math.abs(d.x-r.x):360,I=d?Math.abs(d.y-r.y):240,F=b.filter(ne=>{const fe=Yt(ne),me=fe.x+fe.w/2,Te=fe.y+fe.h/2;return me>=m&&me<=m+j&&Te>=y&&Te<=y+I}).map(ne=>ne.id),L=H.sections??[],q=fn("section",L.map(ne=>ne.id)),Q={id:q,title:"Section",color:"#6366f1",position:{x:Math.round(m),y:Math.round(y)},size:{width:Math.round(j),height:Math.round(I)},nodes:[]},le={...H,sections:[...L,Q]};Xe(ts(es(le,q,F)))},[n,b,H,Xe]);c.useEffect(()=>{if(!De)return;const r=d=>{d.key==="Escape"&&(rt(!1),Ue(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[De]);const qn=c.useCallback((r,d)=>{var F;if(n)return;const m=(F=H.sections)==null?void 0:F.find(L=>L.id===r);if(!m)return;const y=new Set(m.nodes),j=b.map(L=>y.has(L.id)?{...L,position:{x:L.position.x+d.dx,y:L.position.y+d.dy}}:L),I={...H,sections:(H.sections??[]).map(L=>L.id===r?{...L,position:{x:L.position.x+d.dx,y:L.position.y+d.dy}}:L)};_(j),z(I),Y(j,k,I)},[n,H,b,k,_,Y]),Gn=c.useCallback((r,d)=>{if(n)return;const m=r==="note"?{...H,notes:(H.notes??[]).filter(y=>y.id!==d)}:{...H,sections:(H.sections??[]).filter(y=>y.id!==d)};Xe(m)},[n,H,Xe]),Kn=r=>{let d=H;for(const m of r){const y=Yt(m),j=y.x+y.w/2,I=y.y+y.h/2,F=(d.sections??[]).find(q=>j>=q.position.x&&j<=q.position.x+q.size.width&&I>=q.position.y&&I<=q.position.y+q.size.height),L=bn(d,m.id);F?(L.length!==1||L[0]!==F.id)&&(d=es(d,F.id,[m.id])):L.length>0&&(d=rs(d,m.id))}return d},$t=c.useCallback((r,d,m)=>{(async()=>{const y=await v.saveStepTest(s.id,r,d).catch(j=>(console.error("step run fixture save failed",j),null));await v.recordStepTestRun(s.id,r,{stepTestId:(y==null?void 0:y.id)??null,status:m.status,input:d.input,output:m.output,error:m.error,...m.meta?{meta:m.meta}:{}})})().catch(y=>{console.error("step run persist failed",y)})},[v,s.id]),js=c.useCallback(r=>{const d=b.find(m=>m.id===r);!d||!S&&o.isControlApp(d.data.step.uses.app)||h({stepId:r,status:"collect"})},[b,S]),Xn=c.useCallback(async(r,d,m)=>{if(!S)return;const y=b.find(F=>F.id===r);if(!y)return;const j=o.isTriggerStep(y.data.step.uses),I={stopAt:ns(b.map(F=>F.data.step),r),...m?{state:m}:{},...j?{input:d}:{}};h({stepId:r,status:"running"});try{await S(r,I),h(null)}catch(F){const L=F;h({stepId:r,status:"error",error:L.message??String(F),errorCode:L.code})}},[b,S]),Ct=c.useCallback((r,d)=>{if(n)return;const m=b.map(y=>y.id===r?{...y,data:{...y.data,step:d(y.data.step)}}:y);_(m),Y(m,k)},[b,k,_,Y,n]),vs=c.useCallback(r=>Ct(r,d=>Sn(d,!Qe(d))),[Ct]),Ss=c.useCallback(r=>Ct(r,d=>Cn(d,!We(d))),[Ct]),Yn=c.useCallback(async(r,d,m)=>{x==null||x();const y=b.find(q=>q.id===r);if(!y)return;const j=y.data.step,I=o.isTriggerStep(j.uses),F=I?{input:d}:{...j.with??{},...d},L=I?{input:d,with:d}:{input:d,with:F};h({stepId:r,status:"running"});try{const q=await v.invokeAction(j.uses.app,j.uses.action,F,{connectionId:o.connectionIdFor(j,M.current),project:f,...m?{state:m}:{},workflowId:s.id}),Q=q.logs,le=q.meta;h({stepId:r,status:"done",value:q.value,logs:Q,...le?{meta:le}:{}}),$t(r,L,{status:"succeeded",output:q.value,...le?{meta:le}:{}})}catch(q){const Q=q;h({stepId:r,status:"error",error:Q.message??String(q),errorCode:Q.code}),$t(r,L,{status:"failed",error:Q.message??String(q)})}},[b,v,$t,f,x,s.id]),Bt=c.useMemo(()=>({onEdit:r=>{ke("props"),Pe(r)},onEditJson:r=>{ke("json"),Pe(r)},onRun:js,onDuplicate:bs,onDelete:gs,onTogglePause:vs,onToggleDisable:Ss,runsFromNode:!!S,onAddFromPort:ms,readOnly:n}),[js,bs,gs,vs,Ss,S,ms,n]);c.useEffect(()=>{const r=Se.current;if(!r)return;const d=m=>{const y=m.target.closest(".react-flow__node");if(!y)return;const j=y.getAttribute("data-id");j&&(m.stopPropagation(),Bt.onEdit(j))};return r.addEventListener("dblclick",d,!0),()=>r.removeEventListener("dblclick",d,!0)},[Bt]);const ot=b.find(r=>r.id===re),Nt=(ot==null?void 0:ot.data.step)??null,Vt=D?((Js=b.find(r=>r.id===D.stepId))==null?void 0:Js.data.step)??null:null,zt=(D==null?void 0:D.status)==="collect"&&!!Vt,Cs=c.useMemo(()=>{const r=new Map;for(const d of b)r.set(d.id,o.fanOutState(d.id,k).count);return r},[b,k]),Ns=Oo(b),kt=c.useMemo(()=>_o(Ns),[Ns]),Zn=c.useMemo(()=>Fo(k,kt.tones,kt.loopOf),[k,kt]),Qn=c.useMemo(()=>({step:vi,control:Si}),[]),[Et,ks]=c.useState({}),[Tt,Es]=c.useState({}),[Ts,Is]=c.useState({}),[It,As]=c.useState({}),[Ve,At]=c.useState(null),[Ps,Rs]=c.useState([]),eo=re??Ve??"";c.useEffect(()=>{const r=v.loadNodeSamples;if(typeof r!="function"||!s.id){Rs([]);return}let d=!1;return r(s.id).then(m=>{d||Rs(Array.isArray(m)?m:[])},()=>{}),()=>{d=!0}},[v,s.id,eo]);const Pt=c.useMemo(()=>o.indexNodeSamples(Ps),[Ps]),Ht=c.useMemo(()=>o.splitNodeOutputs(Et,Pt,It),[Et,Pt,It]),ze=c.useMemo(()=>o.splitPreviewOutputs(Et,Pt,It),[Et,Pt,It]),Ce=c.useMemo(()=>({actionDef:(r,d)=>{var m;return(m=ue[r])==null?void 0:m.find(y=>y.key===d)},triggerDef:(r,d)=>{var m;return(m=je[r])==null?void 0:m.find(y=>y.key===d)},testOutputs:Ht.fresh,persistedOutputs:Ht.persisted,loopSamples:Ts}),[ue,je,Ht,Ts]),Ye=c.useMemo(()=>D?o.upstreamStateSources(D.stepId,b,k,Ce):void 0,[D,b,k,Ce]),to=c.useMemo(()=>(Ye==null?void 0:Ye.steps)??[],[Ye]),be=c.useMemo(()=>{const r=o.upstreamStateSources(re,b,k,Ce,Ve);return{...r,steps:o.excludeSelfStep(r.steps,re??Ve)}},[re,Ve,b,k,Ce]),dt=c.useMemo(()=>ti({anchorId:re??Ve,nodes:b,edges:k,floating:o.isFloatingDraft(re,Ve,b,k),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...ze.persisted,...ze.fresh}}),[re,Ve,b,k,s.initialState,s.variables,Ce,ze]),Ms=JSON.stringify([...be.steps.map(r=>r.id),...be.extraSampleIds??[]]);c.useEffect(()=>{const r=JSON.parse(Ms);if(!re&&!Ve||r.length===0){ks({}),Es({}),Is({}),As({});return}let d=!1;return Promise.all(r.map(async m=>{try{const y=await v.listStepTests(s.id,m),j=y.length?y[y.length-1]:null;return j?{id:m,output:j.lastRunOutput,runAt:j.lastRunAt,meta:j.lastRunMeta,loopSample:o.foreachTestSample(j)}:null}catch{return null}})).then(m=>{if(d)return;const y={},j={},I={},F={};for(const L of m)L!=null&&L.meta&&(j[L.id]=L.meta),L!=null&&L.loopSample&&(I[L.id]=L.loopSample),!(!L||L.output===void 0||L.output===null)&&(y[L.id]=L.output,F[L.id]=L.runAt);ks(y),As(F),Es(j),Is(I)}),()=>{d=!0}},[v,s.id,re,Ve,Ms]);const Jt=c.useMemo(()=>o.declaredSamples(b,Ce),[b,Ce]),Rt=c.useMemo(()=>({persisted:ze.persisted,samples:Jt.samples,event:Jt.event}),[ze.persisted,Jt]),Ls=c.useMemo(()=>o.upstreamSampleValues(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Fs=c.useMemo(()=>o.upstreamSampleValueSources(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Ds=o.useExpressionOptions(),Os=c.useMemo(()=>o.nodeConfigSources(b),[b]),_s=c.useMemo(()=>o.nodeConfigValues(b,E.subs),[b,E.subs]),Ut=c.useMemo(()=>o.nodeMetaValues(b,E.subs,R,U),[b,E.subs,R,U]),qt=c.useMemo(()=>({...l??{},steps:be.steps,hasTrigger:be.hasTrigger,eventOutputs:be.eventOutputs,eventOutputsFrom:be.eventOutputsFrom,loop:be.loop,stateShape:{fields:dt.fields,...dt.written?{written:dt.written}:{}},nodeConfigs:Os,nodeConfig:_s,nodeMeta:Ut,valueSources:Fs,sampleValues:{...Ds.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...o.nodeMetaSampleValues(Ut),...Ls,...dt.sampleValues}}),[l,Ds.sampleValues,be,dt,Ls,Fs,Os,_s,Ut]),ut=c.useRef(null);$e||re?ut.current===null&&(ut.current=J.mark()):ut.current=null;const Ws=()=>{te(!1),_e(null),Be(null),At(null)},$s=()=>{const r=ut.current;if(ut.current=null,n||r===null)return;const d=J.rollbackTo(r);d&&Vs(d)},Bs=r=>{if(n)return;const d=J[r]();d&&Vs(d)},Vs=r=>{var y;const d=Eo(s,r);_(d.nodes.map(j=>({...j,selected:j.id===W}))),X(d.edges.map(j=>({...j,selected:j.id===ae}))),z(r.canvas),C(r.connections),d.nodes.some(j=>j.id===W)||B(null),d.edges.some(j=>j.id===ae)||Ne(null);const m=d.nodes.some(j=>j.id===re);m||Pe(null),te(!1),At(null),_e(null),Me(null),ge(null),Be(null),qe(null),G(null),Ke(null),Z.current=void 0,Je(j=>j+1),i(et(o.flowToWorkflow({...s,nodes:r.nodes,connections:r.connections},d.nodes,d.edges),r.canvas)),!m&&!D&&((y=Se.current)==null||y.focus({preventScroll:!0}))},zs=c.useRef(Bs);zs.current=Bs,c.useEffect(()=>{const r=Se.current;if(!r)return;let d=r.contains(document.activeElement);const m=j=>{j.type==="focusin"&&j.target===document.body||(d=r.contains(j.target))},y=j=>{if(n||j.defaultPrevented||Gt(j.target)||!r.contains(j.target)&&!(d&&j.target===document.body))return;const I=j.key.toLowerCase();!(j.ctrlKey||j.metaKey)||j.altKey||I!=="z"&&!(I==="y"&&!j.shiftKey)||(j.preventDefault(),zs.current(I==="y"||j.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",m),document.addEventListener("focusin",m),document.addEventListener("keydown",y),()=>{document.removeEventListener("pointerdown",m),document.removeEventListener("focusin",m),document.removeEventListener("keydown",y)}},[n]);const Mt=c.useCallback((r,d)=>{var L;if(Gt(r.target))return;const m=(L=Se.current)==null?void 0:L.getBoundingClientRect();if(!m)return;r.preventDefault();const y=tn(b,k),j=y.nodeIds,I=uo(j,d),F=d!==void 0&&!j.includes(d);F&&_(b.map(q=>q.selected!==(q.id===d)?{...q,selected:q.id===d}:q)),qe({x:r.clientX-m.left,y:r.clientY-m.top,flow:Le({x:r.clientX,y:r.clientY}),nodeIds:I,edgeIds:F?[]:y.edgeIds})},[b,k,_,Le]),so=c.useCallback(r=>{var d;qe(null),r&&((d=Se.current)==null||d.focus({preventScroll:!0}))},[]),no=r=>{const d=we;if(!(!d||n))if(r==="duplicate")Wt(d.nodeIds);else if(r==="delete")Me({nodeIds:d.nodeIds,edgeIds:d.edgeIds});else if(r==="replace-trigger"){const m=b.find(y=>y.id===d.nodeIds[0]);if(!m)return;_e(null),Be({position:m.position,tab:"triggers",replaces:m.id}),te(!0)}else _e(null),Be({position:d.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),te(!0)},oo=t.jsx(fs.Provider,{value:Bt,children:t.jsx(ls.Provider,{value:ie,children:t.jsx(ds.Provider,{value:Cs,children:t.jsx(us.Provider,{value:kt,children:t.jsx(ui,{apps:R,registration:E,children:t.jsx(o.WorkflowProjectProvider,{project:f,workflowId:s.id,children:t.jsx(o.ExpressionOptionsProvider,{value:qt,children:t.jsxs("section",{ref:Se,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{Z.current=Gt(r.target)?{}:void 0},onBlurCapture:()=>{Z.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||re||$e||Re)return;const d=r.target;if(d.isContentEditable||d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.tagName==="SELECT"||d.closest("dialog, .w6w-modal")!==null)return;const m=tn(b,k);!m.nodeIds.length&&!m.edgeIds.length||(r.preventDefault(),!m.nodeIds.length&&m.edgeIds.length===1?zn(m.edgeIds[0]):Me(m))},children:[t.jsxs(oe.ReactFlow,{nodes:xt,edges:Zn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:de,onEdgesChange:T,onConnect:st,onConnectStart:(r,d)=>{he.current=d},onConnectEnd:Wn,onPaneClick:()=>G(null),onPaneContextMenu:r=>Mt(r),onNodeContextMenu:(r,d)=>Mt(r,d.id),onEdgeContextMenu:r=>Mt(r),onSelectionContextMenu:r=>Mt(r),onMoveStart:()=>qe(null),isValidConnection:vt,onNodeDragStop:(r,d,m)=>{const y=Kn(m),j=y!==H;if(j&&z(y),!V&&!j){J.record(Lt(s,b,k,M.current,y));return}Y(b,k,y)},onMoveEnd:(r,d)=>{if(!r||n)return;const m=o.flowToWorkflow(s,b,k),y=o.withViewport(m,d);y!==m&&i(y,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:d})=>{var m,y,j,I;B(((m=r[0])==null?void 0:m.id)??null),Ne(((y=d[0])==null?void 0:y.id)??null),se.current!==(((j=r[0])==null?void 0:j.id)??null)&&(se.current=((I=r[0])==null?void 0:I.id)??null,G(null))},nodeTypes:Qn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:ct,proOptions:{hideAttribution:!0},children:[t.jsx(oe.Background,{gap:16}),t.jsx(oe.Controls,{showInteractive:!1,children:!n&&t.jsx(oe.ControlButton,{onClick:Bn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(Ee.Icon,{name:"layout"})})}),t.jsx(oe.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(oe.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>te(!0),children:"+ Node"}),t.jsx(o.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Jn}),t.jsx(o.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${De?" active":""}`,"aria-pressed":De,"data-testid":"draw-section",onClick:()=>{rt(!De),Ue(null)}})]}),!n&&De&&t.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:r=>{if(r.button!==0)return;r.currentTarget.setPointerCapture(r.pointerId);const{clientX:d,clientY:m}=r;Ue({sx:d,sy:m,ex:d,ey:m})},onPointerMove:r=>{const{clientX:d,clientY:m}=r;Ue(y=>y&&{...y,ex:d,ey:m})},onPointerUp:()=>{const r=ve;if(Ue(null),rt(!1),!r)return;const d=Le({x:r.sx,y:r.sy}),m=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Un(d,m?Le({x:r.ex,y:r.ey}):null)},children:ve&&(()=>{var y;const r=(y=Se.current)==null?void 0:y.getBoundingClientRect(),d=(r==null?void 0:r.left)??0,m=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ve.sx,ve.ex)-d,top:Math.min(ve.sy,ve.ey)-m,width:Math.abs(ve.ex-ve.sx),height:Math.abs(ve.ey-ve.sy)}})})()}),!n&&nt&&o.edgeLane(nt)!=="each"&&((Us=b.find(r=>r.id===nt.source))==null?void 0:Us.data.step.uses.app)!==o.ROUTER_APP&&t.jsx(oe.Panel,{position:"top-right",children:t.jsxs("div",{className:"w6w-edge-lane",children:[t.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(r=>t.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${o.edgeLane(nt)===r?" active":""}`,"aria-pressed":o.edgeLane(nt)===r,title:di,onClick:()=>Vn(r),children:r==="success"?"Success":"Error"},r)),(St==null?void 0:St.edgeId)===nt.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:St.message})]})}),N&&t.jsx(oe.NodeToolbar,{nodeId:N.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:o.loopRefusalMessage(N.reason)})}),t.jsx(o.CanvasLayer,{canvas:H,readOnly:n,savePosition:V,onChange:Xe,onSectionDrop:qn,onRequestDelete:(r,d)=>!n&&ge({kind:r,id:d})})]}),Ae&&t.jsx(o.ConfirmModal,{title:Ae.kind==="note"?"Delete note":"Delete section",message:Ae.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Gn(Ae.kind,Ae.id),ge(null)},onClose:()=>ge(null)}),$e&&t.jsx(o.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{$s(),Ws()},onDone:Ws,onAdd:r=>{const d=Hn(r);return d&&At(d),d},onDraftChange:(r,d)=>ys(r,{id:r,...d}),stepIds:b.map(r=>r.id),onOpenStep:r=>{te(!1),_e(null),Be(null),At(null),ke("props"),Pe(r)},workflowId:s.id,upstreamSteps:o.stepBuilderUpstreamSteps(xe,b,k),loop:o.stepBuilderLoop(xe,b,k,Ce)}),Nt&&re&&t.jsx(Ni,{workflowId:s.id,step:Nt,restoreVersion:pe,upstreamSteps:qt.steps??[],loop:qt.loop,readOnly:n,fanOutCount:Cs.get(re)??0,stateOutputFields:(Xs=o.resolveOutputShape((qs=Ce.actionDef)==null?void 0:qs.call(Ce,Nt.uses.app,Nt.uses.action),(Gs=Ce.testOutputs)==null?void 0:Gs[re],(Ks=Ce.persistedOutputs)==null?void 0:Ks[re]))==null?void 0:Xs.fields.map(r=>r.key),initialView:Oe,stepProblems:ot==null?void 0:ot.data.stepProblems,otherStepIds:b.filter(r=>r.id!==re).map(r=>r.id),onChange:r=>ys(re,r),onClose:()=>Pe(null),onCancel:()=>{$s(),Pe(null)},onTestRun:x}),D&&t.jsxs(o.Modal,{title:`${zt?"Run node":"Test run"}: ${D.stepId}`,onClose:()=>h(null),children:[zt&&Vt&&t.jsx(wi,{workflowId:s.id,step:Vt,upstreamSteps:to,loop:Ye==null?void 0:Ye.loop,continues:S?{stopAt:ns(b.map(r=>r.data.step),D.stepId)}:void 0,onCancel:()=>h(null),onRun:(r,d)=>S?Xn(D.stepId,r,d):Yn(D.stepId,r,d)},D.stepId),!zt&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[D.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),D.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[D.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:D.errorCode})}),D.error||"The node failed with no error message."]}),D.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(o.ResultViewer,{value:D.value,maxHeight:360}),D.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(o.ResultViewer,{value:D.meta,maxHeight:360})]})]}),D.logs&&D.logs.length>0&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),t.jsx(Ee.Copyable,{value:D.logs.join(`
2
+ `),label:"Copy console output",children:t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:D.logs.join(`
3
+ `)})})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>h(null),children:"Close"})})]})]}),Re!==null&&t.jsx(o.ConfirmModal,{title:Re.nodeIds.length===1?"Delete node":Re.nodeIds.length>1?`Delete ${Re.nodeIds.length} nodes`:`Delete ${Re.edgeIds.length} connections`,message:ko(Re,b,k),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{$n(Re),Me(null)},onClose:()=>Me(null)}),we&&t.jsx(ao,{x:we.x,y:we.y,items:po(we.nodeIds,!!n,{replaceableTrigger:we.nodeIds.length===1&&b.some(r=>r.id===we.nodeIds[0]&&o.isTriggerStep(r.data.step.uses))}),onAction:no,onClose:so})]})})})})})})})});return t.jsx(o.WorkflowConnectionsContext.Provider,{value:{nodes:b.map(r=>r.data.step),connections:U,setConnections:C,readOnly:n},children:oo})}const hi=["code"];function _t(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function mi(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return _t(e)}function gi({items:e,save:s}){if(!e)return t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[t.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",t.jsx("strong",{children:"Override the incoming state"})," below."]});const i=e[0],n=i!==void 0?(o.inferOutputFields(i)??[]).map(a=>a.key):[];return t.jsxs("div",{className:"w6w-testout",children:[t.jsxs("div",{className:"w6w-testout-label",children:[e.length," ",e.length===1?"item":"items"]}),e.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-testout-label",children:"First item"}),t.jsx(o.ResultViewer,{value:i,maxHeight:220})]}),s==="saved"&&t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&t.jsxs(t.Fragment,{children:[" ","Steps on ",t.jsx("strong",{children:"Each item"})," now offer ",t.jsx("strong",{children:"Current item"})," ›"," ",n.map((a,u)=>t.jsxs("span",{children:[u>0&&", ",t.jsx("code",{children:a})]},a)),"."]})]}),s==="failed"&&t.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function In(e){const[s,i]=c.useState(null),[n,a]=c.useState("0"),[u,l]=c.useState({}),[f,p]=c.useState({}),w=s??o.loopItemText(e),x=((e==null?void 0:e.outer)??[]).map(v=>({foreachId:v.foreachId,name:v.name??v.foreachId,itemText:u[v.foreachId]??o.loopItemText(v),indexText:f[v.foreachId]??"0",setItemText:R=>l(E=>({...E,[v.foreachId]:R})),setIndexText:R=>p(E=>({...E,[v.foreachId]:R}))})),g=e?o.parseLoopSeed(w,n):void 0;let S=g!=null&&g.ok?{ok:!0,value:g.value}:g;if(e&&(g!=null&&g.ok)){const v={};for(const R of x){const E=o.parseLoopSeed(R.itemText,R.indexText);if(!E.ok){S={ok:!1,error:`${R.name}: ${E.error}`};break}v[R.foreachId]=E.value}S!=null&&S.ok&&(v[e.foreachId]=g.value,S={ok:!0,value:{...g.value,loops:v}})}return{active:!!e,itemText:w,indexText:n,setItemText:i,setIndexText:a,outers:x,parsed:S}}function An(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function hs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function Pn({seed:e,readOnly:s}){if(!e.active)return null;const i=hs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[e.outers.map(n=>t.jsxs("div",{"data-testid":`loop-seed-outer-${n.foreachId}`,children:[t.jsxs("span",{children:[n.name," item"]}),t.jsx("textarea",{rows:3,value:n.itemText,readOnly:s,spellCheck:!1,"aria-label":`${n.name} item`,onChange:a=>n.setItemText(a.target.value)}),t.jsxs("span",{children:[n.name," index"]}),t.jsx("input",{type:"text",inputMode:"numeric",value:n.indexText,readOnly:s,"aria-label":`${n.name} index`,onChange:a=>n.setIndexText(a.target.value)})]},n.foreachId)),t.jsx("span",{children:"Current item"}),t.jsx("textarea",{rows:3,value:e.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>e.setItemText(n.target.value)}),t.jsx("span",{children:"Index"}),t.jsx("input",{type:"text",inputMode:"numeric",value:e.indexText,readOnly:s,"aria-label":"Index",onChange:n=>e.setIndexText(n.target.value)}),t.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),i&&t.jsx("span",{className:"w6w-hint",role:"alert",children:i})]})}function is({text:e,onChange:s,seeds:i,readOnly:n,expand:a,hint:u}){const l=_t(e),f=l?Object.keys(l).length:0,p=f>0,[w,x]=c.useState(p);c.useEffect(()=>{(p||a)&&x(!0)},[p,a]);const g=S=>{s(JSON.stringify(S.lastRunOutput??S.input??{},null,2)),x(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),i.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:i.map(S=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${S.label}'s saved test as the incoming state`,disabled:n,onClick:()=>g(S.test),children:[t.jsx("code",{children:S.label}),S.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",S.test.lastRunStatus]}):null]},S.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:w,onToggle:S=>x(S.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:S=>s(S.target.value)}),t.jsx("span",{className:"w6w-hint",children:u??t.jsxs(t.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",t.jsx("code",{children:"input"}),": ",t.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",t.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function wi({workflowId:e,step:s,upstreamSteps:i,loop:n,onRun:a,onCancel:u,continues:l}){var H;const f=o.useW6WApi(),p=o.isTriggerStep(s.uses),w=o.isInternalApp(s.uses.app),x=c.useMemo(()=>{var z;return p?o.asFieldDefs((z=s.with)==null?void 0:z.fields):[]},[p,s.with]),g=c.useMemo(()=>p?o.fieldsToParams(x):w?o.internalNodeParams(s.uses.app,s.uses.action):null,[p,w,x,s.uses.app,s.uses.action]),[S,v]=c.useState(null),R=g??S;c.useEffect(()=>{if(g)return;if(!s.uses.app||!s.uses.action){v([]);return}let z=!1;return v(null),f.getAppActions(s.uses.app).then(J=>{var Z;z||v(((Z=J.find(pe=>pe.key===s.uses.action))==null?void 0:Z.params)??[])}).catch(()=>!z&&v([])),()=>{z=!0}},[f,g,s.uses.app,s.uses.action]);const[E,D]=c.useState(()=>{var z;return p?o.seedValues(o.asFieldDefs((z=s.with)==null?void 0:z.fields)):{}}),[h,A]=c.useState("{}"),O=o.useSeedSources(e,i,!p),U=In(n),P=(H=o.useExpressionOptions().stateShape)==null?void 0:H.written,M=o.startStateFromSeeds(O,An(U),P),C=o.useRememberedTestInput(e,s.id),[$,K]=c.useState(!1),[V,b]=c.useState(!1);c.useEffect(()=>{if(!C.loaded)return;let z=!1;const J=(Z,pe)=>{Z&&Object.keys(Z).length>0&&(p?D(Je=>({...Je,...Z})):A(JSON.stringify(Z,null,2)),pe&&b(!0)),K(!0)};if(C.input!==void 0){J(C.input,!0);return}return f.listStepTests(e,s.id).then(Z=>{if(z)return;const pe=Z.length?Z[Z.length-1]:null;J(p?pe==null?void 0:pe.with:pe==null?void 0:pe.input,!1)}).catch(()=>{z||K(!0)}),()=>{z=!0}},[f,e,s.id,p,C.loaded]);const[_,de]=c.useState(0),ue=()=>{C.clear(),b(!1),p?D(o.seedValues(x)):A("{}"),de(z=>z+1)},je=z=>{D(z),k(!0),b(!1),de(J=>J+1)},[ie,k]=c.useState(!0),X=_t(h),T=p?ie:X!==null,W=p?E:{...s.with??{},...X??{}},B=p?null:hs(U),ee=!!R&&$&&T&&!B&&o.requiredParamsFilled(R,W);return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[l&&t.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",l.stopAt.length>0?t.jsxs(t.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((z,J)=>t.jsxs("span",{children:[J>0?", ":"",t.jsx("code",{children:z})]},z))]}):null,". Disabled nodes are skipped."]}),V&&R!==null&&$&&t.jsx(o.LastUsedNote,{onClear:ue}),R===null||!$?t.jsx("p",{className:"w6w-muted w6w-small",children:R===null?"Loading parameters…":"Loading saved values…"}):p?t.jsxs(t.Fragment,{children:[t.jsx(o.PropertyEntryForm,{params:R,values:E,onChange:D,onValidityChange:k},_),s.uses.trigger===!0&&t.jsx(lo,{app:s.uses.app,trigger:s.uses.action,onUse:je}),R.length===0&&t.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",t.jsx("code",{children:"input"}),")."]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",t.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),t.jsx(Pn,{seed:U}),t.jsx(is,{text:h,onChange:A,seeds:O})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:u,children:"Cancel"}),!ee&&R!==null&&$&&t.jsx("span",{className:"w6w-muted w6w-small",children:B?`${B} Fix it to run.`:T?p?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":p?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:!ee,onClick:()=>{C.save(p?E:X??{},R??[]),a(p?E:X??{},p?void 0:M)},children:"▶ Run"})]})]})}function xi(e){return e.uses.app===o.CONTROL_APP&&e.uses.action==="foreach"}function Rn({id:e}){const{tones:s,loopOf:i}=c.useContext(us),n=vn(e,i);return n.length===0?null:t.jsx("span",{className:"w6w-loop-dots",children:n.map(a=>t.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${a}`,title:`In loop · ${a}`,style:{background:as(s.get(a)??1)}},a))})}function Mn(e){return Do(e,c.useContext(us).tones)}function He({type:e,position:s,multiple:i,id:n,variant:a,top:u,routeLabel:l}){const f=oe.useNodeId(),p=c.useContext(fs),w=!!f&&!!p&&!p.readOnly,x=()=>{w&&f&&p.onAddFromPort(f,e,n)},g=a==="error"?"a step that handles this step's failure":a==="each"?"the first step of this loop's body":e==="target"?"a step before this one":"the next step";return t.jsx(oe.Handle,{type:e,position:s,id:n,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":i?"w6w-handle-multi":void 0,style:{...i?{height:22,borderRadius:3,width:8}:{},...u?{top:u}:{}},onClick:w?x:void 0,title:l?`${l} — drag or click to connect`:w?`Drag to empty canvas (or click) to add ${g} · drag to a port to connect`:a==="error"?"On error — drag to route this step's failure separately":a==="each"?"Each item — drag to the first step to repeat for every item":i?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Ln({id:e,step:s,runnable:i}){const n=c.useContext(fs);if(!n||n.readOnly)return null;const a=i||n.runsFromNode,u=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=Qe(s),f=We(s);return t.jsxs(oe.NodeToolbar,{position:oe.Position.Top,className:"w6w-node-toolbar",children:[a&&t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:u,"aria-label":u,onClick:()=>n.onRun(e),children:t.jsx(Ee.Icon,{name:"run",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":l,title:l?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":l?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(e),children:t.jsx(Ee.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:t.jsx(Ee.Icon,{name:"ban",size:15})}),t.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(e),children:t.jsx(Ee.Icon,{name:"edit",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(e),children:t.jsx(Ee.Icon,{name:"copy",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(e),children:t.jsx(Ee.Icon,{name:"trash",size:15})})]})}function Fn({step:e,count:s}){if(s<2)return null;const i=e.fanOut==="parallel",n=o.fanOutLabel(s,i?"parallel":"sequential");return t.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[t.jsx("span",{"aria-hidden":"true",children:i?"⇉":"→"})," ",s]})}function Dn({step:e}){const s=Qe(e),i=We(e);return!s&&!i?null:t.jsxs("div",{children:[i&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":nn,title:nn,children:[t.jsx(Ee.Icon,{name:"ban",size:11})," Disabled"]}),s&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":sn,title:sn,children:[t.jsx(Ee.Icon,{name:"pause",size:11})," Paused"]})]})}function On(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(o.stepProblemTooltip).join(`
4
+ `)}}function _n({problems:e}){if(!e||e.length===0)return null;const s=e.map(o.stepProblemTooltip).join(`
5
+ `);return t.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":s,title:s,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:t.jsx(Ee.Icon,{name:"warning",size:12})})}function bi(e){const s=o.useW6WApi(),i=e.uses.action,[n,a]=c.useState(null),u=e.uses.trigger===!0,l=e.uses.app;return c.useEffect(()=>{if(!u||!s.getAppTriggers)return;let f=!1;return s.getAppTriggers(l).then(p=>{var w;return!f&&a(((w=p.find(x=>x.key===i))==null?void 0:w.title)??null)}).catch(()=>{}),()=>{f=!0}},[s,l,i,u]),n||i}function yi(e){const s=o.useW6WApi(),i=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,a=e.id,u=[...ri(e.nodes),...(e.nodes??[]).filter(R=>{var E;return((E=R.uses)==null?void 0:E.app)===o.WEBHOOK_APP&&R.uses.trigger!==!0})],l=u.length>0,f=u.map(R=>`${R.id}:${R.uses.app}:${R.uses.action}:${o.connectionIdFor(R,e.connections)??""}`).join("|"),[p,w]=c.useState([]),x=c.useMemo(()=>ii(p),[p]),[g,S]=c.useState(0);c.useEffect(()=>{if(!i||!l){w([]);return}let R=!1;return i.call(s,a).then(E=>!R&&w(E)).catch(()=>{}),()=>{R=!0}},[s,i,a,l,f,g]);const v=c.useMemo(()=>n?async R=>{try{await n.call(s,R)}finally{S(E=>E+1)}}:void 0,[s,n]);return c.useMemo(()=>({byNode:x,subs:p,retry:v}),[x,p,v])}function ji({nodeId:e}){const{byNode:s,retry:i}=c.useContext(Tn),[n,a]=c.useState(!1),u=s.get(e),l=oi(u,i!==void 0);return!u||!l?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":u.status,"data-tone":l.tone,style:{marginTop:3,paddingLeft:2},children:[t.jsx("span",{style:l.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:l.label}),t.jsxs("span",{className:"w6w-muted",children:[" · ",l.lastFire]}),l.error&&t.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:l.error}),l.retryVisible&&i&&t.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),i(u.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function vi({id:e,data:s,selected:i}){const n=s.step,u=c.useContext(ps).get(n.uses.app),l=(u==null?void 0:u.displayName)||n.uses.app||"—",f=o.isTriggerStep(n.uses),p=bi(n),w=n.uses.trigger?`${l} · ${p}`:l,x=o.nodePortsForStep(n,c.useContext(ls)),g=En(s.stepStatus??"no-run",s.runStatus),S=t.jsx(Fn,{step:n,count:c.useContext(ds).get(e)??0}),v=Mn(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:v,"data-disabled":We(n)||void 0,"data-paused":Qe(n)||void 0,children:[t.jsx(Ln,{id:e,step:n,runnable:!0}),t.jsxs("div",{className:f?"w6w-node-trigger":void 0,"data-node-kind":f?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...On(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${g.borderWidth}px ${g.borderStyle} ${i?"var(--w6w-accent)":g.borderColor}`,opacity:We(n)?.45:i?1:g.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...f?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(_n,{problems:s.stepProblems}),x.in>0&&t.jsx(He,{type:"target",position:oe.Position.Left,multiple:x.in>1}),t.jsx(o.AppIcon,{src:u==null?void 0:u.iconSvg,srcDark:u==null?void 0:u.iconSvgDark,brandColor:u==null?void 0:u.brandColor,name:l,size:28}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:w}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),x.out>0&&t.jsxs(t.Fragment,{children:[t.jsx(He,{type:"source",position:oe.Position.Right,multiple:x.out>1}),!f&&t.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:o.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,t.jsx(Dn,{step:n}),f&&n.uses.trigger===!0&&t.jsx(ji,{nodeId:e}),s.loopOf&&t.jsx(Rn,{id:e}),t.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,u!=null&&u.version?` - v${u.version}`:""]}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Si({id:e,data:s,selected:i}){const n=s.step,a=o.routesForStep(n),u=n.uses.app===o.ROUTER_APP,l=o.isIfStep(n),f=a.length?o.routerPortLayout(a):l?o.ifPortLayout():void 0,p=JSON.stringify(a.map(A=>A.id)),w=oe.useUpdateNodeInternals();c.useEffect(()=>{w(e)},[e,p,w]);const x=o.internalNodeLabel(n.uses.app,n.uses.action),g=o.internalNodeIcon(n.uses.app,n.uses.action),S=o.nodePortsForStep(n,c.useContext(ls)),v=o.isTriggerStep(n.uses),R=xi(n),E=En(s.stepStatus??"no-run",s.runStatus),D=t.jsx(Fn,{step:n,count:c.useContext(ds).get(e)??0}),h=Mn(e);return t.jsxs("div",{className:[R?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",We(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:h,"data-disabled":We(n)||void 0,"data-paused":Qe(n)||void 0,children:[t.jsx(Ln,{id:e,step:n,runnable:!o.isControlApp(n.uses.app)}),t.jsxs("div",{className:v?"w6w-node-trigger":u?"w6w-node-router":void 0,"data-node-kind":v?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...On(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${E.borderWidth}px ${E.borderStyle} ${i?"var(--w6w-accent)":E.borderColor}`,opacity:We(n)?.45:i?1:E.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...v?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...f!=null&&f.minHeight?{minHeight:f.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(_n,{problems:s.stepProblems}),S.in>0&&t.jsx(He,{type:"target",position:oe.Position.Left,multiple:S.in>1}),g&&t.jsx(o.InternalIcon,{icon:g}),t.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[t.jsx("div",{style:{fontWeight:600},children:x}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),R&&t.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[t.jsx("span",{children:"Each item"}),t.jsx("span",{children:"Done"})]}),l&&(f==null?void 0:f.right[0])&&t.jsx("span",{className:"w6w-if-true-label w6w-small","aria-hidden":"true",children:f.right[0].label}),!l&&!!(f!=null&&f.right.length)&&t.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${f.right.length}, 1fr)`},"aria-hidden":"true",children:f.right.map(A=>t.jsx("span",{title:A.label,children:A.label},A.id))}),S.out>0&&t.jsxs(t.Fragment,{children:[R&&t.jsx(He,{type:"source",position:oe.Position.Right,multiple:!1,id:o.EACH_SOURCE_HANDLE,variant:"each"}),f?t.jsxs(t.Fragment,{children:[f.right.map(A=>t.jsx(He,{type:"source",position:oe.Position.Right,multiple:!1,id:A.handleId,top:A.top,routeLabel:A.label},A.id)),f.bottom&&t.jsxs(t.Fragment,{children:[t.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:f.bottom.handleId,routeLabel:f.bottom.label}),t.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:f.bottom.label})]})]}):t.jsx(He,{type:"source",position:oe.Position.Right,multiple:S.out>1,id:R?o.routeHandle(o.FOREACH_DONE_ROUTE):void 0}),!v&&!u&&!l&&n.uses.app!==o.RACE_APP&&t.jsx(He,{type:"source",position:oe.Position.Bottom,multiple:!1,id:o.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),D,t.jsx(Dn,{step:n}),s.loopOf&&t.jsx(Rn,{id:e}),s.legacyLoop&&t.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),t.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ci(e,s){var l,f;if(!s)return e;const i={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[p,w]of Object.entries(s)){const x=/^nodes\.([^.]+)\.output$/.exec(p);!x||((l=i[x[1]])==null?void 0:l.output)!==void 0||(i[x[1]]={...i[x[1]]??{},output:w},n=!0)}const a=s["trigger.event"],u=a!==void 0&&((f=e==null?void 0:e.trigger)==null?void 0:f.event)===void 0;return!n&&!u?e:{...e??{},...n?{steps:i}:{},...u?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Ni(e){return t.jsx(ki,{...e})}function ki({workflowId:e,step:s,restoreVersion:i,upstreamSteps:n,loop:a,onChange:u,onClose:l,onCancel:f,readOnly:p,initialView:w="props",fanOutCount:x=0,stateOutputFields:g,onTestRun:S,stepProblems:v,otherStepIds:R}){var yt,jt,vt;const E=o.useW6WApi(),D=c.useContext(ps),[h,A]=c.useState(s),O=o.useWorkflowConnections(),U=o.connectionIdFor(h,O==null?void 0:O.connections),P={...h,uses:{...h.uses,connection:U}},C=h.uses.connectionRef!==void 0&&!U||o.isConnectionBlocked(P,v),$=v==null?void 0:v.find(N=>N.code==="unknown_connection"&&N.connection===U),K=(v??[]).filter(N=>"fix"in N),[V,b]=c.useState(C?"setup":"configure"),[_,de]=c.useState(w==="json"?"code":w==="settings"?"config":"props"),[ue,je]=c.useState("props"),[ie,k]=c.useState(()=>o.stepToJson(s)),[X,T]=c.useState("{}"),W=c.useRef(null),[B,ee]=c.useState(!1),H=c.useRef(i);c.useEffect(()=>{H.current!==i&&(H.current=i,A(s),k(o.stepToJson(s)))},[i,s]);const[z,J]=c.useState(!1),[Z,pe]=c.useState(null),[Je,De]=c.useState(null),[rt,ve]=c.useState(null),[Ue,Ae]=c.useState(!1),ge=o.isInternalApp(h.uses.app),ae=h.uses.trigger===!0;c.useEffect(()=>{if(ge){pe(o.internalNodeParams(h.uses.app,h.uses.action));const G=o.INTERNAL_NODES.filter(se=>se.app===h.uses.app&&se.groupActions&&!se.hidden);De(G.length?G.map(se=>({key:se.action,title:se.label,params:se.params})):null);return}if(!h.uses.app){De(null),pe([]);return}let N=!1;return pe(null),(ae?o.getTriggerDefs(E,h.uses.app):E.getAppActions(h.uses.app)).then(G=>{var se;N||(De(G),pe(h.uses.action?((se=G.find(he=>he.key===h.uses.action))==null?void 0:se.params)??[]:[]))}).catch(()=>!N&&pe([])),()=>{N=!0}},[E,h.uses.app,h.uses.action,ge,ae]);const Ne=c.useRef(0);c.useEffect(()=>()=>{Ne.current++},[]);const $e=c.useCallback(()=>{ge||!h.uses.app||E.listConnectionsForApp(h.uses.app).then(N=>{ve(N),Ae(!1)}).catch(()=>Ae(!0))},[E,h.uses.app,ge]);c.useEffect(()=>{if(ge||!h.uses.app)return;let N=!1;return ve(null),Ae(!1),E.listConnectionsForApp(h.uses.app).then(G=>{N||(ve(G),Ae(!1))}).catch(()=>!N&&Ae(!0)),()=>{N=!0}},[E,h.uses.app,ge]);const te=c.useCallback(N=>{A(N),u(N)},[u]),gt=So({enabled:h.uses.app===o.SCRIPT_APP&&!p,values:h.with??{},onChange:N=>te({...h,with:N})}),re=N=>{N==="code"&&k(o.stepToJson(h)),de(N)},Pe=N=>{const G=o.stepNameError(N,R??[]);return G||te({...h,id:N}),G},Oe=!!h.uses.app&&!!h.uses.action&&!o.isControlApp(h.uses.app),ke=o.isForeachStep(h),we=o.isTriggerStep(h.uses),qe=V==="test"&&Oe&&!we,ye=o.useSeedSources(e,n,Oe&&!we||ke),Be=In(Oe&&!we?a:void 0),Re=o.useExpressionOptions(),Me=o.startStateFromSeeds(ye,An(Be),(yt=Re.stateShape)==null?void 0:yt.written),at=Ci(Me,Re.sampleValues),Se=o.useRememberedTestInput(Oe&&!we||ke?e:void 0,h.id),[xe,_e]=c.useState(!1);c.useEffect(()=>{if((!Oe||we)&&!ke||!Se.loaded)return;if(!ke&&Se.input!==void 0){const G=Se.input;if(Object.keys(G).length===0)return;const se=JSON.stringify(G,null,2);T(he=>he.trim()==="{}"?se:he),_e(!0);return}let N=!1;return E.listStepTests(e,h.id).then(G=>{if(N)return;const se=G.length?G[G.length-1]:null;if(!(se!=null&&se.input)||Object.keys(se.input).length===0)return;const he=JSON.stringify(se.input,null,2);T(st=>st.trim()==="{}"?he:st)}).catch(()=>{}),()=>{N=!0}},[E,e,h.id,Oe,we,ke,Se.loaded]);const Le=ke?mi(X):_t(X),Fe={...h.with??{},...Le??{}},ct=Le??{},et=!!Z&&!hs(Be)&&o.requiredParamsFilled(Z,Fe)&&(h.uses.app!==o.CALL_APP||z),Y=ke?o.resolveLoopItemsInState(Fe.items,Me):void 0,[tt,Ge]=c.useState("idle"),wt=N=>{T(N),Ge("idle")},lt=async()=>{if(Y){Ge("saving");try{await E.saveStepTest(e,h.id,o.foreachTestFixture(Y,ct)),Ge("saved")}catch{Ge("failed")}}},ce=D.get(h.uses.app),xt=ge?o.internalNodeIcon(h.uses.app,h.uses.action):null,bt=ge?xt?t.jsx(o.InternalIcon,{icon:xt}):null:t.jsx(o.AppIcon,{src:ce==null?void 0:ce.iconSvg,srcDark:ce==null?void 0:ce.iconSvgDark,brandColor:ce==null?void 0:ce.brandColor,name:ce==null?void 0:ce.displayName});return t.jsx(o.Modal,{ariaLabel:"Edit step",titleIcon:bt,title:t.jsx(o.StepNameEditor,{value:h.id,onCommit:Pe,readOnly:p}),onClose:f??l,size:"wide",children:t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(N=>h.uses.app!==o.RACE_APP||N!=="test").map(N=>t.jsx("button",{type:"button",className:`w6w-subtab${V===N?" active":""}`,disabled:C&&N!=="setup",onClick:()=>b(N),children:N==="setup"?"Setup":N==="configure"?"Configure":"Test"},N))}),qe?t.jsx(o.ConfigViewToggle,{view:ue,views:["props","code"],onChange:N=>je(N)}):t.jsx(o.ConfigViewToggle,{view:_,customized:o.hasParamCustomization(h.with??{}),onChange:re,disabled:V!=="configure"})]}),C&&$&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",$.connection," no longer exists — choose another to continue."]}),K.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:K.map(N=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:o.stepProblemTooltip(N)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":N.code,disabled:p,onClick:()=>{const G=kn(h,N);te(G),k(o.stepToJson(G))},children:"fix"in N?N.fix.label:""})]},N.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[V==="setup"&&h.uses.app===o.CALL_APP&&t.jsx(o.CallTargetForm,{values:h.with??{},onChange:N=>te({...h,with:N}),readOnly:p,onValidityChange:J,setupOnly:!0}),V==="setup"&&h.uses.app!==o.CALL_APP&&t.jsx(Ii,{step:h,app:ce,actions:Je,conns:rt,connsFailed:Ue,isInternal:ge,actionLabel:ae?"Trigger":"Action",readOnly:p,onChangeAction:N=>{var se;const G=ge?o.internalNodeDefaults(h.uses.app,N):{};if(ge)for(const he of o.internalNodeParams(h.uses.app,N))he.key in(h.with??{})&&(G[he.key]=(se=h.with)==null?void 0:se[he.key]);te({...h,uses:{...h.uses,action:N},with:G})},onChangeTriggerEvents:(N,G)=>te({...h,uses:{...h.uses,action:N},with:{...h.with,actions:G}}),onChangeConnection:N=>{if(!O){const{connectionRef:se,...he}=h.uses;te({...h,uses:{...he,connection:N}});return}const G=o.selectNodeConnection(h,N,(O==null?void 0:O.nodes)??[h],(O==null?void 0:O.connections)??{});O==null||O.setConnections(G.connections),te(G.step)},onChangeConnectionRef:N=>te(o.withConnectionRef(h,N)),onConnectionCreated:$e,onChangeApp:N=>{const G=++Ne.current;if(N===h.uses.app){te(h);return}const se={...h,uses:{app:N,action:"",...ae?{trigger:!0}:{}},with:{}};(o.isInternalApp(N)?Promise.resolve([]):E.listConnectionsForApp(N)).catch(()=>[]).then(he=>{if(G!==Ne.current)return;const st=o.defaultConnectionFor(se,he,(O==null?void 0:O.nodes)??[],(O==null?void 0:O.connections)??{});te({...se,uses:{...se.uses,...st}})})}}),V==="configure"&&t.jsxs(t.Fragment,{children:[h.uses.app===o.WEBHOOK_APP&&E.listSubscriptionsForWorkflow&&E.createSubscription&&t.jsx(Ti,{workflowId:e,step:h,readOnly:p}),Z===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):_==="props"?h.uses.app===o.CALL_APP?t.jsx(o.CallTargetForm,{values:h.with??{},onChange:N=>te({...h,with:N}),readOnly:p,onValidityChange:J}):h.uses.app===o.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:o.RACE_DESCRIPTION}):h.uses.action==="wait"&&o.isControlApp(h.uses.app)?t.jsx(o.WaitEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):h.uses.action==="if"&&o.isControlApp(h.uses.app)?t.jsx(o.ConditionEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):h.uses.app==="@w6w/stop"?t.jsx(o.StopEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):h.uses.app===o.ROUTER_APP?t.jsx(o.RouterEditor,{values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N})}):t.jsxs(t.Fragment,{children:[h.uses.app===o.SCRIPT_APP&&t.jsx(Co,{values:h.with??{},conversion:gt,readOnly:p}),t.jsx(o.ParamsForm,{params:Z,values:h.with??{},readOnly:p,onChange:N=>te({...h,with:N}),dynamic:ge||!h.uses.action?void 0:{appId:h.uses.app,actionKey:h.uses.action,connectionId:C?void 0:U,appName:ce==null?void 0:ce.displayName}})]}):_==="code"?t.jsx(o.JsonEditor,{value:ie,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${h.id} JSON`,copyable:!0}):_==="params-code"?t.jsx(o.ParamCustomization,{values:h.with??{},onChange:N=>te({...h,with:N}),readOnly:p}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(o.NodeConfigForm,{config:{retry:h.retry,onError:h.onError,notes:h.notes},onChange:N=>te({...h,...N}),readOnly:p,failureHandling:!we,retryControls:!o.isControlApp(h.uses.app)&&h.uses.app!==o.CALL_APP}),Ei,t.jsx(o.StepFanOutControl,{step:h,count:x,readOnly:p,onChange:te}),o.stateWriteVisible(h)&&t.jsx(o.StepStateControl,{step:h,inLoop:a!==void 0,outputFields:g,readOnly:p,onChange:te})]})]}),V==="test"&&t.jsx("div",{className:"w6w-stack",children:Oe?ae?t.jsx(o.AppTriggerTestNote,{title:((jt=Je==null?void 0:Je.find(N=>N.key===h.uses.action))==null?void 0:jt.title)??h.uses.action,app:(ce==null?void 0:ce.displayName)??h.uses.app}):we?t.jsx(o.TriggerFillForm,{app:h.uses.app,action:h.uses.action,fields:(vt=h.with)==null?void 0:vt.fields,persist:{workflowId:e,stepId:h.id,input:ct},listen:h.uses.app===o.WEBHOOK_APP&&E.listSubscriptionsForWorkflow&&E.startWebhookListen?{stepWith:h.with,readOnly:p}:void 0}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",t.jsx("code",{children:h.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),t.jsx(Pn,{seed:Be,readOnly:p}),xe&&!p&&t.jsx(o.LastUsedNote,{onClear:()=>{Se.clear(),_e(!1),T("{}")}}),t.jsx(is,{text:X,onChange:T,seeds:ye,readOnly:p}),Z===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(xo,{params:Z,values:Fe,testStartState:at,view:ue,literalKeys:h.uses.app===o.SCRIPT_APP?hi:void 0}),t.jsx(o.StepTestRun,{ref:W,app:h.uses.app,action:h.uses.action,connectionId:U,values:Fe,state:Me,canRun:et,hideRunButton:!0,persist:{workflowId:e,stepId:h.id,input:ct},onBusyChange:ee})]}):ke?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",t.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",t.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",t.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",t.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),t.jsx(is,{text:X,onChange:wt,seeds:ye,readOnly:p,expand:!Y,hint:t.jsxs(t.Fragment,{children:["Paste a sample list — ",t.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",t.jsx("code",{children:'{"items": […]}'}),". It replaces what ",t.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),t.jsx(gi,{items:Y,save:tt})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[f&&!p&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:f,children:"Cancel"}),h.uses.app===o.RACE_APP&&V==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):V!=="test"?t.jsxs(t.Fragment,{children:[f&&!p&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:C,onClick:()=>b(V==="setup"?"configure":"test"),children:"Next →"})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),Oe&&!we&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!et||B,onClick:()=>{var N;S==null||S(),(N=W.current)==null||N.run()},children:B?"Testing…":"Test"}),ke&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(Y!=null&&Y.length)||tt==="saving",onClick:()=>void lt(),children:tt==="saving"?"Testing…":"Test"})]})]})]})})}const Ei=!1;function Ti({workflowId:e,step:s,readOnly:i}){const n=o.useW6WApi(),[a,u]=c.useState(void 0),[l,f]=c.useState(null),[p,w]=c.useState(!1);c.useEffect(()=>{const g=n.listSubscriptionsForWorkflow;if(!g)return;let S=!1;return g(e).then(v=>{S||u(o.pickWebhookSubscription(v,s.id))}).catch(v=>!S&&f(v.message)),()=>{S=!0}},[n,e,s.id]);const x=()=>{const g=n.createSubscription;g&&(f(null),w(!0),g(o.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(S=>{w(!1),u(S)}).catch(S=>{w(!1),f(S instanceof Error?S.message:String(S))}))};return t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:[t.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]}),l&&t.jsx("div",{className:"w6w-result w6w-error",children:l}),a!=null&&a.webhookUrl?t.jsx(Ee.Copyable,{value:a.webhookUrl,readOnly:!0,children:t.jsx("input",{type:"text",readOnly:!0,value:a.webhookUrl,"aria-label":"Webhook URL"})}):a===void 0?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!i&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:x,children:p?"Creating…":"Create webhook URL"})]})}function Ii({step:e,app:s,actions:i,conns:n,connsFailed:a,isInternal:u,actionLabel:l="Action",readOnly:f,onChangeAction:p,onChangeTriggerEvents:w,onChangeConnection:x,onChangeConnectionRef:g,onChangeApp:S,onConnectionCreated:v}){const R=e.uses.trigger?o.eventbriteTriggerChoices(e.uses.app,i,e.uses.action,e.with??{}):null,[E,D]=c.useState(null),h=c.useRef(null),A=o.useWorkflowConnections(),O=o.connectionIdFor(e,A==null?void 0:A.connections);return t.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!O&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-app-conn-row",ref:h,children:[t.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":E==="app",disabled:f,onClick:()=>D(U=>U==="app"?null:"app"),children:[!u&&s&&t.jsx(o.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:u?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!u&&t.jsx(o.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:f,open:E==="conn",onOpenChange:U=>D(U?"conn":null),anchorRef:h,onChangeConnection:x,onChangeConnectionRef:g,onConnectionCreated:v})]}),E==="app"&&t.jsx(o.AnchoredFlyout,{anchorRef:h,onClose:()=>D(null),children:t.jsx(o.AppPicker,{onSelectApp:U=>{const P=U.id===e.uses.app;S(U.id),D(P?"conn":null)}})})]}),u&&!(i!=null&&i.length)?t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Action"}),t.jsx("div",{className:"w6w-muted w6w-small",children:t.jsx("code",{children:e.uses.action})})]}):R?t.jsx(o.EventbriteTriggerPicker,{choices:R,readOnly:f,onChange:U=>w(R.triggerKey,U)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:l}),t.jsx(o.Combobox,{value:e.uses.action,disabled:f||i===null,onChange:p,options:i===null?[{value:e.uses.action,label:e.uses.action}]:i.map(U=>({value:U.key,label:U.title??U.key}))})]})]})}function hn({trigger:e}){return t.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":e?"Trigger":"Node",children:t.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e?t.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),t.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function Ai({resources:e}){const s=o.useW6WApi(),i=e.highlightNode;c.useEffect(()=>()=>i==null?void 0:i(null),[i]);const[n,a]=c.useState([]),[u,l]=c.useState(!0),[f,p]=c.useState(),[w,x]=c.useState(),[g,S]=c.useState(null),[v,R]=c.useState(!1),[E,D]=c.useState(!1),h=c.useRef(0),A=c.useCallback(async()=>{const T=++h.current;l(!0),p(void 0);try{const W=await s.listConnections();return T!==h.current?void 0:(a(W),W)}catch(W){T===h.current&&p(W.message)}finally{T===h.current&&l(!1)}},[s]);c.useEffect(()=>(A(),()=>{h.current++}),[A]);const[O,U]=c.useState(new Map),P=JSON.stringify([...new Set([...Object.values(e.connections).map(T=>T.app),...n.map(T=>T.appId)])].filter(T=>{var W;return!((W=e.apps)!=null&&W.has(T))&&!n.some(B=>B.appId===T&&B.app!==void 0)}).sort());c.useEffect(()=>{var H,z;let T=!1;const W=JSON.parse(P);if(u||!W.length)return;const B=(H=s.listAppsByIds)==null?void 0:H.bind(s),ee=B?Promise.all(Array.from({length:Math.ceil(W.length/50)},(J,Z)=>B(W.slice(Z*50,(Z+1)*50)))).then(J=>J.flat()):(z=s.listApps)==null?void 0:z.call(s);return ee==null||ee.then(J=>{T||U(new Map(J.map(Z=>[Z.id,Z])))}).catch(()=>{}),()=>{T=!0}},[s,P,u]);const M=T=>{var H;const W=n.find(z=>z.appId===T&&z.app)??n.find(z=>z.appId===T&&z.app!==void 0),B=W?o.resolveConnectionAppMeta(W,O):O.get(T),ee=(H=e.apps)==null?void 0:H.get(T);return ee?{...B,...ee}:B},C=T=>{var W;return((W=M(T))==null?void 0:W.displayName)||T},$=T=>{if(e.readOnly)return!1;try{return e.edit(T),x(void 0),!0}catch(W){return x(W.message),!1}},K=T=>o.nextWorkflowConnectionName(T.appId,e.connections),V=()=>{S(null),x(void 0),R(!1)},b=g!=null&&g.ref?e.connections[g.ref]:void 0,_=n.find(T=>T.id===(g==null?void 0:g.connection)),de=(b==null?void 0:b.app)??(_==null?void 0:_.appId),ue=e.nodes.filter(T=>T.uses.app===de),je=e.nodes.filter(T=>(g==null?void 0:g.ref)!==void 0&&T.uses.connectionRef===g.ref),ie=n.filter(T=>!b||T.appId===b.app).map(T=>({value:T.id,label:b?T.displayName||T.id:`${C(T.appId)} · ${T.displayName||T.id}`}));g!=null&&g.connection&&!ie.some(T=>T.value===g.connection)&&ie.unshift({value:g.connection,label:g.connection.startsWith("zerocred:")?"Built-in":g.connection});const k=(T,W=28)=>{const B=M(T);return t.jsx(o.AppIcon,{src:B==null?void 0:B.iconSvg,srcDark:B==null?void 0:B.iconSvgDark,brandColor:B==null?void 0:B.brandColor,name:C(T),size:W})},X=()=>{if(!g||!g.name.trim()||!g.connection||!de)return;const T=g.ref!==void 0?{type:"update",ref:g.ref,name:g.name,connection:g.connection,nodeIds:g.allNodes?ue.map(W=>W.id):void 0}:{type:"add",name:g.name,app:de,connection:g.connection};$(T)&&V()};return t.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[t.jsxs("div",{className:"w6w-workflow-connections-heading",children:[t.jsx("h3",{children:"Connections"}),t.jsx(o.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{x(void 0),S({name:"",connection:"",allNodes:!1})},children:t.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),f&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",f]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void A(),children:"Retry"})]}),Object.entries(e.connections).map(([T,W])=>{var z;const B=e.nodes.filter(J=>J.uses.connectionRef===T),ee=n.find(J=>J.id===W.connection),H=(ee==null?void 0:ee.displayName)||((z=W.connection)!=null&&z.startsWith("zerocred:")?"Built-in":W.connection)||"No credentials selected";return t.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":T,children:[t.jsxs("div",{className:"w6w-connection-app-heading",children:[k(W.app),t.jsxs("div",{className:"w6w-connection-summary",children:[t.jsx("strong",{children:C(W.app)}),t.jsx("span",{className:"w6w-small",children:H}),t.jsxs("span",{className:"w6w-muted w6w-small",children:[T,ee!=null&&ee.state?` · ${ee.state}`:""]})]}),t.jsx(o.IconButton,{icon:"edit",label:`Edit connection ${T}`,disabled:e.readOnly,onClick:()=>{x(void 0),S({ref:T,name:T,connection:W.connection??"",allNodes:!1})}})]}),B.length>0?t.jsxs("details",{className:"w6w-connection-consumers",onToggle:J=>{J.currentTarget.open||i==null||i(null)},children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",B.length," ",B.length===1?"node":"nodes"]}),t.jsx("ul",{className:"w6w-connection-node-list",children:B.map(J=>t.jsx("li",{children:e.focusNode?t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${J.id} on canvas`,onClick:()=>{var Z;return(Z=e.focusNode)==null?void 0:Z.call(e,J.id)},onMouseEnter:()=>i==null?void 0:i(J.id),onMouseLeave:()=>i==null?void 0:i(null),onFocus:()=>i==null?void 0:i(J.id),onBlur:()=>i==null?void 0:i(null),children:[t.jsx(hn,{trigger:o.isTriggerStep(J.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:J.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:J.id})]})]}):t.jsxs("span",{className:"w6w-connection-app-heading",children:[t.jsx(hn,{trigger:o.isTriggerStep(J.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:J.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:J.id})]})]})},J.id))})]}):t.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},T)}),!Object.keys(e.connections).length&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),g&&!E&&!v&&t.jsxs(o.Modal,{title:g.ref!==void 0?"Edit connection":"Add connection",titleIcon:de?k(de):void 0,subtitle:de?C(de):void 0,onClose:V,children:[t.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[w&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:w}),f&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",f]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void A(),children:"Retry"})]}),g.ref!==void 0&&!b&&t.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Workflow connection name"}),t.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:g.name,disabled:e.readOnly,onChange:T=>S({...g,name:T.target.value})})]}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:b?"Credentials":"Existing connection"}),t.jsx(o.Combobox,{"aria-label":b?"Credentials":"Connection to add",options:ie,value:g.connection,placeholder:u?"Loading connections…":"Choose a connection…",disabled:e.readOnly||u||!!f,onChange:T=>{const W=n.find(B=>B.id===T);S({...g,connection:T,name:!g.name&&W?K(W):g.name})}})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>D(!0),children:"Create new credentials"}),b&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"w6w-muted w6w-small",children:g.allNodes?`Saving applies these credentials to all ${ue.length} ${C(b.app)} nodes.`:`Saving updates credentials for ${je.length} linked ${je.length===1?"node":"nodes"}.`}),ue.length>0&&t.jsxs("label",{className:"w6w-connection-scope",children:[t.jsx("input",{type:"checkbox",checked:g.allNodes||ue.every(T=>T.uses.connectionRef===g.ref),disabled:e.readOnly||ue.every(T=>T.uses.connectionRef===g.ref),onChange:T=>S({...g,allNodes:T.target.checked})}),"Use for all ",ue.length," ",C(b.app)," ",ue.length===1?"node":"nodes"," in this workflow"]}),t.jsxs("div",{className:"w6w-connection-remove",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly||je.length>0,onClick:()=>R(!0),children:"Remove from workflow"}),je.length>0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:V,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||u||!!f||!g.name.trim()||!g.connection||!de||g.ref!==void 0&&!b,onClick:X,children:g.ref!==void 0?"Save changes":"Add to workflow"})]})]}),g&&v&&t.jsx(o.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${g.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>R(!1),onConfirm:()=>{g.ref&&$({type:"remove",ref:g.ref})?V():R(!1)}}),g&&E&&t.jsx(o.AddConnectionModal,{initialAppId:b==null?void 0:b.app,onClose:()=>D(!1),onCreated:({connectionId:T})=>{D(!1),A().then(W=>{const B=W==null?void 0:W.find(ee=>ee.id===T);B&&S(ee=>ee?{...ee,connection:B.id,name:ee.name||K(B)}:null)})}})]})}exports.CALL_APP=o.CALL_APP;exports.CONTROL_APP=o.CONTROL_APP;exports.CanvasLayer=o.CanvasLayer;exports.DATA_APP=o.DATA_APP;exports.ExpressionOptionsProvider=o.ExpressionOptionsProvider;exports.INTERNAL_NODES=o.INTERNAL_NODES;exports.Markdown=o.Markdown;exports.RACE_APP=o.RACE_APP;exports.SCHEDULER_APP=o.SCHEDULER_APP;exports.SCRIPT_APP=o.SCRIPT_APP;exports.TRIGGER_APP=o.TRIGGER_APP;exports.WEBHOOK_APP=o.WEBHOOK_APP;exports.asFieldDefs=o.asFieldDefs;exports.centralizeConnections=o.centralizeConnections;exports.coerceDefault=o.coerceDefault;exports.connectionIdFor=o.connectionIdFor;exports.fieldWidget=o.fieldWidget;exports.fieldsToParams=o.fieldsToParams;exports.flowToWorkflow=o.flowToWorkflow;exports.internalNodeDefaults=o.internalNodeDefaults;exports.internalNodeIcon=o.internalNodeIcon;exports.internalNodeLabel=o.internalNodeLabel;exports.internalNodeParams=o.internalNodeParams;exports.isControlApp=o.isControlApp;exports.isInternalApp=o.isInternalApp;exports.isTriggerApp=o.isTriggerApp;exports.isTriggerStep=o.isTriggerStep;exports.seedValues=o.seedValues;exports.workflowToFlow=o.workflowToFlow;exports.MAX_NOTES=mn;exports.MAX_NOTE_BYTES=wn;exports.MAX_SECTIONS=gn;exports.WorkflowConnectionsPanel=Ai;exports.WorkflowFlowEditor=pi;exports.applyStepProblemFix=kn;exports.assignMembership=es;exports.clampCanvas=ts;exports.findLoopProblems=Bo;exports.findStateWriteProblems=Ho;exports.isDisabledStep=We;exports.isPausedStep=Qe;exports.pausedStopAt=ns;exports.pruneSectionMembers=rs;exports.renameSectionMember=Qt;exports.roundGeometry=Zt;exports.sectionsContaining=bn;exports.withCanvasGeometry=xn;exports.withDisabled=Cn;exports.withPaused=Sn;
6
6
  //# sourceMappingURL=flow.cjs.map