@w6w/ui 0.2.54 → 0.2.56

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,5 +1,5 @@
1
- "use client";"use strict";var Un=Object.defineProperty;var qn=(e,s,n)=>s in e?Un(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n;var nt=(e,s,n)=>qn(e,typeof s!="symbol"?s+"":s,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),ge=require("@w6w/expr"),X=require("@xyflow/react"),p=require("react"),r=require("./node-samples-ChdyMBnJ.cjs"),je=require("./CodeBlock-CymlfyeA.cjs");function Gn({x:e,y:s,items:n,onAction:o,onClose:a}){const c=p.useRef(null),[l,u]=p.useState({left:e,top:s});p.useLayoutEffect(()=>{const m=c.current,w=m==null?void 0:m.offsetParent;if(!m||!w)return;const x=m.offsetWidth,S=m.offsetHeight;u({left:e+x>w.clientWidth?Math.max(0,e-x):e,top:s+S>w.clientHeight?Math.max(0,s-S):s})},[e,s]),p.useEffect(()=>{var m,w;(w=(m=c.current)==null?void 0:m.querySelector("[role=menuitem]"))==null||w.focus({preventScroll:!0})},[]),p.useEffect(()=>{const m=S=>{var k;(k=c.current)!=null&&k.contains(S.target)||a(!1)},w=S=>{var k;(k=c.current)!=null&&k.contains(S.target)||a(!1)},x=()=>a(!1);return document.addEventListener("pointerdown",m,!0),document.addEventListener("scroll",w,!0),document.addEventListener("wheel",w,{capture:!0,passive:!0}),window.addEventListener("blur",x),window.addEventListener("resize",x),()=>{document.removeEventListener("pointerdown",m,!0),document.removeEventListener("scroll",w,!0),document.removeEventListener("wheel",w,!0),window.removeEventListener("blur",x),window.removeEventListener("resize",x)}},[a]);const f=m=>{m.disabled||(a(!1),o(m.action))};return t.jsx("div",{ref:c,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:m=>m.preventDefault(),onKeyDown:m=>{var k;m.stopPropagation();const w=[...((k=c.current)==null?void 0:k.querySelectorAll("[role=menuitem]"))??[]],x=w.indexOf(document.activeElement),S=I=>{var A;return(A=w[(I+w.length)%w.length])==null?void 0:A.focus()};if(m.key==="ArrowDown")S(x+1);else if(m.key==="ArrowUp")S(x<0?-1:x-1);else if(m.key==="Home")S(0);else if(m.key==="End")S(-1);else if(m.key==="Escape"||m.key==="Tab")a(!0);else if(m.key==="Enter"||m.key===" ")x>=0&&f(n[x]);else return;m.preventDefault()},children:n.map(m=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":m.disabled||void 0,className:`w6w-note-menu-item${m.danger?" danger":""}${m.separated?" separated":""}`,"data-action":m.action,onClick:()=>f(m),children:m.label},m.action))})}function Kn(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function Xn(e,s){const n=[],o=e.length;if(o>0){const a=o>1?` ${o} nodes`:"";n.push({action:"duplicate",label:`Duplicate${a}`,disabled:s}),n.push({action:"delete",label:`Delete${a}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:o>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const tn=200,sn=200,nn=10240;function Jt(e){const s={};for(const[n,o]of Object.entries(e))s[n]=Math.round(o);return s}const Yn=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),Zn=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Ds(e,s,n){return e&&e.map(o=>{const a=s==null?void 0:s[o.id],c=Yn(a==null?void 0:a.position)?a.position:o.position,l=Zn(a==null?void 0:a.size)?a.size:o.size;return{...o,position:Jt(c),size:Jt(l)}})}function on(e,s,n){if(!s)return e;const o={...e};return e.notes&&(o.notes=Ds(e.notes,n)),e.sections&&(o.sections=Ds(e.sections,n)),o}function Zt(e,s){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.filter(o=>o!==s)}))}:e}function rn(e,s,n){return e.sections?{...e,sections:e.sections.map(o=>({...o,nodes:o.nodes.map(a=>a===s?n:a)}))}:e}function Ut(e,s,n){if(!e.sections)return e;const o=new Set(n);return{...e,sections:e.sections.map(a=>{const c=a.nodes.filter(l=>!o.has(l));return a.id===s?{...a,nodes:[...new Set([...c,...n])]}:{...a,nodes:c}})}}function an(e,s){return(e.sections??[]).filter(n=>n.nodes.includes(s)).map(n=>n.id)}function Qn(e,s){const n=new TextEncoder;if(n.encode(e).length<=s)return e;let o="",a=0;for(const c of e){const l=n.encode(c).length;if(a+l>s)break;o+=c,a+=l}return o}function qt(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,tn).map(n=>({...n,content:Qn(n.content,nn)}))),e.sections&&(s.sections=e.sections.slice(0,sn)),s}function eo(e,s,n){const o={};for(const l of[...e.notes??[],...e.sections??[]])o[l.id]={position:l.position,size:l.size};const a=(l,u)=>l==null?void 0:l.map(f=>{const m=u==null?void 0:u.find(w=>w.id===f.id);return m?{...f,position:m.position,size:m.size}:f}),c=n?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 on(c,n,o)}const Os=220;function to(e){return e.length<=Os?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Os).trimEnd(),clipped:!0,length:e.length}}function so({params:e,values:s,testStartState:n,view:o="props",literalKeys:a}){const{sampleValues:c,nodeConfig:l,nodeMeta:u}=r.useExpressionOptions(),f=p.useMemo(()=>r.buildResolveScope(c,n,l,u),[c,n,l,u]),m=r.flattenParams(e),w=k=>{var I;return s[k]!==void 0?s[k]:(I=m.find(A=>A.key===k))==null?void 0:I.default},x=m.filter(k=>k.type!=="section"&&r.isParamVisible(k,w)).map(k=>ge.effectiveParam(k,w));if(r.hasParamCustomization(s)){const k=r.previewCustomization(s.$merge,f,a),I=k!==null&&typeof k=="object"&&!Array.isArray(k),A=_s(x,s,f,a);for(const[$,N]of Object.entries(s))$!=="$merge"&&(A[$]=a!=null&&a.includes($)?N:r.previewCustomization(N,f));const g=I?{...A,...k}:A;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:I?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(k)}). Test the step to validate it.`}),o==="code"?t.jsx(r.JsonEditor,{value:JSON.stringify(g,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(g).map(([$,N])=>{var H;return t.jsx(Gt,{label:((H=m.find(J=>J.key===$))==null?void 0:H.label)??$,segments:[{status:"resolved",value:N}]},$)})})]})}if(o==="code"){const k=_s(x,s,f,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(r.JsonEditor,{value:JSON.stringify(k,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=x.filter(k=>!r.deepEqual(w(k.key),k.default));return x.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(k=>k.type==="vars"?t.jsx(no,{param:k,value:s[k.key],scope:f},k.key):t.jsx(Gt,{label:k.label??k.key,segments:a!=null&&a.includes(k.key)?[{status:"resolved",value:w(k.key)}]:r.resolveParamValue(w(k.key),f)},k.key))})}function _s(e,s,n,o){const a={};for(const c of e)if(o!=null&&o.includes(c.key))a[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],u=r.dataVarRows(l);a[c.key]=u?r.resolveVarsJson(u,n):r.resolveParamJson(l,n)}else a[c.key]=r.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,n);return a}function Gt({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(cn,{segments:s})})]})}function no({param:e,value:s,scope:n}){const o=s??e.default??[],a=r.dataVarRows(o);return a===null?t.jsx(Gt,{label:e.label??e.key,segments:r.resolveParamValue(o,n)}):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((c,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:c.key||"(no key)"})," → ",t.jsx(cn,{segments:r.resolveParamValue(c.value,n)})]},l))})]})}function cn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,n)=>t.jsx(oo,{segment:s},n))})}function oo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(at,{kind:"var",refName:e.ref}),t.jsx(Ws,{value:e.value})]}):t.jsx(Ws,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(at,{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(at,{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(at,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(at,{kind:"secret",refName:e.ref})}}function Ws({value:e}){const[s,n]=p.useState(!1),o=io(e),a=to(o);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(je.Copyable,{value:o,label:"Copy resolved value",className:"w6w-resolved-copy",children:t.jsx("pre",{className:"w6w-resolved-text-full",children:o})}):t.jsxs("span",{children:[a.text,"…"]}),t.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>n(c=>!c),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:o})}const ro={var:"◆",secret:"🔒",expr:"ƒ"};function at({kind:e,refName:s}){const n=e==="expr"?"expr":r.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:ro[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:n})]})}function io(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 ln(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function ao({enabled:e,values:s,onChange:n}){const[o,a]=p.useState(null),c=p.useRef(!1),l=typeof s.code=="string"?s.code:"";return p.useEffect(()=>{if(!e||c.current)return;c.current=!0;const u=r.convertCodeBindingsToReads(l,ln(s));u.converted!==0&&(a({original:l,converted:u.converted}),n({...s,code:u.code}))},[e,l,s,n]),o?{converted:o.converted,undo:()=>{n({...s,code:o.original}),a(null)}}:null}function co({values:e,conversion:s,readOnly:n}){const o=typeof e.code=="string"?e.code:"",a=s,c=r.findCodeBindings(o,ln(e)).length;return!a&&c===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",!n&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&t.jsxs(t.Fragment,{children:[c," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function $s(e,s){return{nodeIds:e.filter(n=>n.selected).map(n=>n.id),edgeIds:s.filter(n=>n.selected).map(n=>n.id)}}function lo(e,s,n,o){const a=new Set(e.nodeIds),c=new Set(e.edgeIds),l=s.filter(x=>a.has(x.id)),u=[...l.filter(x=>r.isForeachStep(x.data.step)),...l.filter(x=>!r.isForeachStep(x.data.step))];let f=s,m=n,w=o;for(const x of u)m=r.bridgeDeletedBodyStep(x.id,f,m),f=f.filter(S=>S.id!==x.id),w=Zt(w,x.id);return{nodes:f,edges:m.filter(x=>!c.has(x.id)),canvas:w}}function uo(e,s,n){var u;const o=new Set(e.nodeIds),a=new Set(e.edgeIds),c=n.filter(f=>a.has(f.id)&&!o.has(f.source)&&!o.has(f.target)),l=[];if(o.size===1)l.push(r.deleteStepMessage(e.nodeIds[0],s,n));else if(o.size>1){l.push(`Delete nodes ${[...o].map(m=>`"${m}"`).join(", ")}? Their connections are removed too.`);const f=new Set;for(const m of o)if(r.isForeachStep((u=s.find(w=>w.id===m))==null?void 0:u.data.step))for(const w of r.loopBody(m,s,n))o.has(w)||f.add(w);f.size&&l.push(`Loop body steps ${[...f].map(m=>`"${m}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(f=>`"${f.source} → ${f.target}"`).join(", ")}?`),l.join(" ")}function po(e,s){const n={success:0,error:0};for(const a of s){if(a.source!==e)continue;const c=r.edgeLane(a);c!=="each"&&n[c]++}const o=Math.max(n.success,n.error);return{enabled:o>=2,count:o}}function fo(e,s){const{fanOut:n,...o}=e;return s==="parallel"?{...o,fanOut:"parallel"}:o}function ho(e,s){return`Runs these ${e} nodes in ${s==="parallel"?"parallel":"sequence"}`}function Ct(e,s,n,o,a){const c=r.flowToWorkflow({...e,connections:o},s,n);return{nodes:c.nodes.map(({with:l,...u})=>l&&Object.keys(l).length?{...u,with:l}:u),edges:c.edges??[],connections:c.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function go(e,s){const n=r.workflowToFlow({...e,...s});return{...n,nodes:n.nodes.map(o=>({...o,position:s.positions[o.id]??o.position}))}}class mo{constructor(s,n=100){nt(this,"past",[]);nt(this,"future",[]);nt(this,"present");nt(this,"group");nt(this,"limit");this.limit=n,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,n){const o=JSON.stringify(s);o!==this.present&&((!n||n!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=o,this.group=n,this.future=[])}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 Vt(e){var n;const s=e;return!!(s!=null&&s.isContentEditable||(n=s==null?void 0:s.closest)!=null&&n.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const wo=64,ct=24,Ke=32;function Nt(e){var s,n;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((n=e.measured)==null?void 0:n.height)??e.height??64}}function xo(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 bo(e){const s=(a,c)=>{const l=new Map;for(const m of e){const w=m.position[a];l.set(w,Math.max(l.get(w)??0,Nt(m)[c]))}const u=new Map;let f=Number.NEGATIVE_INFINITY;for(const[m,w]of[...l].sort(([x],[S])=>x-S)){const x=Math.max(m,f);u.set(m,x),f=x+w+wo}return u},n=s("x","width"),o=s("y","height");return e.map(a=>({...a,position:{x:n.get(a.position.x)??a.position.x,y:o.get(a.position.y)??a.position.y}}))}function yo(e,s,n){var u;const o=bo(r.relayoutNodes(e,s));if(!((u=n.sections)!=null&&u.length))return{nodes:o,canvas:n};const a=new Map(o.map(f=>[f.id,f])),c=(n.notes??[]).map(f=>({...f.position,...f.size}));for(const f of n.sections)f.nodes.some(m=>a.has(m))||c.push({...f.position,...f.size,y:f.position.y-Ke,height:f.size.height+Ke});const l=n.sections.map(f=>{const m=new Set(f.nodes),w=o.filter(N=>m.has(N.id));if(!w.length)return f;const x=Math.min(...w.map(N=>N.position.x))-ct,S=Math.min(...w.map(N=>N.position.y))-ct,k=Math.max(...w.map(N=>N.position.x+Nt(N).width)),I=Math.max(...w.map(N=>N.position.y+Nt(N).height)),A={x,y:S,width:k+ct-x,height:I+ct-S},g=[...c,...[...a.values()].filter(N=>!m.has(N.id)).map(N=>({...N.position,...Nt(N)}))].sort((N,H)=>N.y-H.y);for(const N of g){const H={...A,y:A.y-Ke,height:A.height+Ke};xo(H,N)&&(A.y=N.y+N.height+ct+Ke)}const $=A.y-S;for(const N of w)a.set(N.id,{...N,position:{x:N.position.x,y:N.position.y+$}});return c.push({...A,y:A.y-Ke,height:A.height+Ke}),{...f,position:{x:A.x,y:A.y},size:{width:A.width,height:A.height}}});return{nodes:o.map(f=>a.get(f.id)??f),canvas:{...n,sections:l}}}const Bt=6;function jo(e){let s=2166136261;for(let n=0;n<e.length;n++)s^=e.charCodeAt(n),s=Math.imul(s,16777619);return s>>>0}function vo(e){const s=new Map;let n=new Set;for(const o of[...new Set(e)].sort()){n.size===Bt&&(n=new Set);let a=jo(o)%Bt;for(;n.has(a);)a=(a+1)%Bt;n.add(a),s.set(o,a+1)}return s}function Qt(e){return`var(--w6w-loop-${e})`}function dn(e,s){const n=[],o=new Set([e]);for(let a=s.get(e);a&&!o.has(a);a=s.get(a))o.add(a),n.unshift(a);return n}function So(e,s,n){return s.size===0?e:e.map(o=>{var l;if(((l=o.data)==null?void 0:l.when)!=="each")return o;const a=o.sourceHandle===r.EACH_SOURCE_HANDLE?o.source:n.get(o.source),c=a?s.get(a):void 0;return c===void 0?o:{...o,style:{...o.style,"--w6w-loop-color":Qt(c)}}})}function Co(e,s){const n=s.get(e);return n===void 0?void 0:{"--w6w-loop-color":Qt(n)}}function No(e){const s=[];for(const n of e){const o=r.isForeachStep(n.data.step);(o||n.data.loopOf)&&s.push([n.id,o?1:0,n.data.loopOf])}return JSON.stringify(s)}function ko(e){const s=JSON.parse(e);return{tones:vo(s.filter(n=>n[1]===1).map(n=>n[0])),loopOf:new Map(s.map(n=>[n[0],n[2]]))}}const Vs="Paused — test runs stop before this node",Bs="Disabled — skipped in every run";function Xe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function Pe(e){return e.disabled===!0}function un(e,s){const{ui:n,...o}=e,{paused:a,...c}=n??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...o,ui:l}:o}function pn(e,s){const{disabled:n,...o}=e;return s?{...o,disabled:!0}:o}function Kt(e,s){return e.filter(n=>n.id!==s&&Xe(n)).map(n=>n.id)}const Eo=["nodes","steps"];function zs(e,s){for(const n of Eo){const o=`${n}.${s}.output`;if(!e.startsWith(o))continue;const a=e.slice(o.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function kt(e,s,n){if(typeof e=="string"){if(!e.includes("{{"))return e;const o=r.parseRootAnchoredTemplate(e);let a=!1;const c=o.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const u=zs(l.ref,s);return u===null?l:(a=!0,n.includes(l.ref)||n.push(l.ref),{...l,ref:u})});return a?ge.serializeTemplate(c):e}if(r.isDollarPath(e)){const o=e.$;if(typeof o!="string")return e;const a=zs(o,s);return a===null?e:(n.includes(o)||n.push(o),{$:a})}if(Array.isArray(e)){let o=!1;const a=e.map(c=>{const l=kt(c,s,n);return l!==c&&(o=!0),l});return o?a:e}if(typeof e=="object"&&e!==null){let o=!1;const a={};for(const[c,l]of Object.entries(e)){const u=kt(l,s,n);u!==l&&(o=!0),a[c]=u}return o?a:e}return e}function To(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=r.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return r.isDollarPath(e)&&typeof e.$=="string"}function fn(e){return Array.isArray(e)&&e.length===1&&To(e[0])}function Ao(e){var s;try{const n=r.normalizeInput(e);if(!Array.isArray(n.nodes))return{};const o={},a=(l,u)=>{const f=Object.hasOwn(o,l)?o[l]:[];f.push(u),o[l]=f},c=new Map(n.nodes.map(l=>[l.id,l]));for(const[l,u]of Object.entries(r.definitionLoops(n))){const f=c.get(l);if(f&&fn((s=f.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in u){a(l,{code:"loop_body_invalid",reason:{...u.invalid}});continue}for(const m of u.body){const w=c.get(m);if(!(w!=null&&w.with))continue;const x=[];kt(w.with,l,x),x.length>0&&a(m,{code:"foreach_body_refs_output",foreachId:l,refs:x,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return o}catch{return{}}}function Po(e){const s=new Set,n=o=>{if(typeof o=="string")s.add(o);else if(Array.isArray(o))for(const a of o)n(a)};return n(e),s}function Io(e){var s,n;try{const o=r.normalizeInput(e);if(!Array.isArray(o.nodes))return[];const a=o.nodes.filter(v=>typeof v=="object"&&v!==null&&typeof v.id=="string"),c=r.effectiveEdges({...o,nodes:a}).filter(v=>typeof(v==null?void 0:v.from)=="string"&&typeof(v==null?void 0:v.to)=="string"),l=[];for(const v of a)try{const P=ge.staticWritePaths(ge.effectiveStateConfig((s=v.uses)==null?void 0:s.app,(n=v.uses)==null?void 0:n.action,v.state));P.length>0&&l.push({id:v.id,paths:P})}catch{}if(l.length<2)return[];const u=new Map;for(const v of a)for(const P of r.controlOwnedIds(v))u.has(P)||u.set(P,v.id);const f=v=>{const P=[v];let F=v;for(;u.has(F)&&(F=u.get(F),!P.includes(F));)P.push(F);return P},m=v=>{const P=f(v);return P[P.length-1]},w=new Map;for(const v of c){const P=w.get(v.from)??[];P.push(v.to),w.set(v.from,P)}const x=new Map,S=v=>{const P=x.get(v);if(P)return P;const F=new Set,O=[...w.get(v)??[]];for(;O.length>0;){const D=O.pop();if(!F.has(D)){F.add(D);for(const y of w.get(D)??[])O.push(y)}}return x.set(v,F),F},k=(v,P)=>v===P||S(v).has(P),I=a.filter(v=>{var P;return((P=v.uses)==null?void 0:P.app)===r.CONTROL_APP&&v.uses.action==="parallel"}).map(v=>{var F;const P=(F=v.with)==null?void 0:F.branches;return Array.isArray(P)?P.map(Po):[]}),A=(v,P)=>{for(const F of f(P)){const O=v.findIndex(D=>D.has(F));if(O>=0)return O}return-1},g=[];for(const v of a){if(v.fanOut!=="parallel")continue;const P=new Map;for(const F of c){if(F.from!==v.id||r.isEachLink(F))continue;const O=F.when??"success",D=P.get(O)??[];D.push(F.to),P.set(O,D)}for(const F of P.values())F.length>=2&&g.push(F)}const $=(v,P)=>{for(const D of I){const y=A(D,v),L=A(D,P);if(y>=0&&L>=0&&y!==L)return!0}const F=m(v),O=m(P);return F===O||S(F).has(O)||S(O).has(F)?!1:g.some(D=>D.some((y,L)=>D.some((me,pe)=>L!==pe&&k(y,F)&&k(me,O))))},N=new Set,H=[];for(let v=0;v<l.length;v++)for(let P=v+1;P<l.length;P++){const F=l[v],O=l[P];if(!(F.id===O.id||!$(F.id,O.id)))for(const D of F.paths)for(const y of O.paths){if(!ge.statePathsOverlap(D,y))continue;const L={code:"state_parallel_write",nodes:[F.id,O.id].sort(),path:[...D.length<=y.length?D:y]},me=JSON.stringify([L.nodes,L.path]);N.has(me)||(N.add(me),H.push(L))}}const J=(v,P)=>v<P?-1:v>P?1:0;return H.sort((v,P)=>J(v.code,P.code)||J(v.nodes.join(","),P.nodes.join(","))||J(v.path.join("."),P.path.join(".")))}catch{return[]}}function Ro(e){try{const s={};for(const n of Io(e))for(const o of n.nodes){const a=Object.hasOwn(s,o)?s[o]:[];a.push({code:n.code,path:[...n.path],with:n.nodes.filter(c=>c!==o)}),s[o]=a}return s}catch{return{}}}function hn(e,s){var n;if(s.code==="foreach_wrapped_items"){const o=(n=e.with)==null?void 0:n.items;return!e.with||!fn(o)?e:{...e,with:{...e.with,items:o[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const o=kt(e.with,s.foreachId,[]);return o===e.with?e:{...e,with:o}}return e}function Hs(e,s,n){return e&&e.nodeId===s&&e.handleType===((n==null?void 0:n.type)??"source")?r.laneForSourceHandle(e.handleId):r.laneForSourceHandle(n==null?void 0:n.id)}function Mo(e,s,n,o,a){var f;const c=(f=o.find(m=>m.id===e))==null?void 0:f.data.step,l=r.loopMembership(o,a)[e]!==void 0,u=n==="success"&&l?"each":n;return u==="each"&&!l&&!r.isForeachStep(c)?null:r.loopRefusal(e,s,u,o,a)}const Fo=["off","root","key","pick","append"],Lo={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function Do(e){return ge.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function Oo(e,s){return JSON.stringify(e)===JSON.stringify(s)}function _o(e,s){const{state:n,...o}=e,a=ge.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return Oo(s,a)?o:{...o,state:s}}function Wo(e,s){switch(s){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function $o(e){return!r.isControlApp(e.uses.app)}function Et(e,s){var n;return(n=e.nodes??e.steps)==null?void 0:n[s]}function Xt(e,s){const n=Et(e,s);return(n==null?void 0:n.status)==="skipped"&&n.skipReason==="not_on_path"}const Vo=new Set(["succeeded","failed","canceled"]);function Bo(e,s,n=[]){var c,l;if(!e||[...n,s].some(u=>Xt(e,u)))return"no-run";const o=Et(e,s);if(o)return o.status;const a=new Set;for(const u of Object.values(e.nodes??e.steps??{}))if(Array.isArray(u==null?void 0:u.iterations))for(const f of u.iterations){const m=(l=(c=f==null?void 0:f.nodes)==null?void 0:c[s])==null?void 0:l.status;m&&a.add(m)}for(const u of["failed","running","succeeded","skipped"])if(a.has(u))return u;return"pending"}const Js={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function gn(e,s){const n=s!==void 0&&Vo.has(s);switch(e){case"no-run":return Js;case"pending":return n?{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 Js}}function zo(e,s,n,o,a){var l;if(!e||Xt(e,s)||a!==void 0&&Xt(e,a))return;const c=Ho(e,s,n,o);return c==="taken"&&a!==void 0&&((l=Et(e,a))==null?void 0:l.status)==="skipped"?"skipped":c}function Ho(e,s,n,o){const a=Et(e,s);if(!a)return;if(n==="each")return a.status==="skipped"?"skipped":void 0;const c=n??"success",l=a.output,u=o===r.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(o!==void 0&&!u&&a.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?o==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===o?"taken":"skipped";if(a.status==="succeeded")return c==="success"?"taken":"skipped";if(a.status==="failed")return c==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const Us={fields:[],sampleValues:{}};function mn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Jo(e,s){var m;const n=e.map(w=>w.id),o=new Set(n),a=new Map(n.map(w=>[w,0])),c=new Map(n.map(w=>[w,[]]));for(const w of s)!o.has(w.source)||!o.has(w.target)||((m=c.get(w.source))==null||m.push(w.target),a.set(w.target,(a.get(w.target)??0)+1));const l=[],u=n.filter(w=>a.get(w)===0);for(;u.length>0;){const w=u.shift();l.push(w);for(const x of c.get(w)??[]){const S=(a.get(x)??0)-1;a.set(x,S),S===0&&u.push(x)}}const f=new Set(l);for(const w of n)f.has(w)||l.push(w);return l}const Uo=new Set(["string","number","boolean","object","array"]);function lt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let n=!1;for(const o of e){if(!mn(o)||typeof o.key!="string"||o.key==="")continue;const a=o.key.split(".");let c=s;for(const f of a.slice(0,-1)){const m=c.fields[f];(m==null?void 0:m.type)!=="object"&&(c.fields[f]={type:"object",fields:{}}),c=c.fields[f]}const l=typeof o.type=="string"&&Uo.has(o.type)?o.type:"string";let u;if(l==="array"){const f=lt(o.items);u=f?{type:"array",items:f}:{type:"array"}}else l==="object"?u=lt(o.fields??o.properties)??{type:"object",fields:{}}:u={type:l};c.fields[a[a.length-1]]=u,n=!0}return n?s:void 0}function qo(e,s){var m,w,x,S,k,I,A;const n=e.data.step,o=((m=s.testOutputs)==null?void 0:m[n.id])??((w=s.persistedOutputs)==null?void 0:w[n.id]);if(o!=null)return o;const{app:a,action:c}=n.uses;if(a===r.TRIGGER_APP&&((x=r.internalNodeDef(a,c))==null?void 0:x.group)==="trigger"){const g=r.fieldsToParams(r.asFieldDefs((S=n.with)==null?void 0:S.fields)).map($=>({key:$.key}));return r.shapeToSkeleton(lt(g))}const l=(k=r.internalNodeDef(a,c))==null?void 0:k.output;if(l&&l.length>0)return r.shapeToSkeleton(lt(l));const u=n.uses.trigger===!0?(I=s.triggerDef)==null?void 0:I.call(s,a,c):(A=s.actionDef)==null?void 0:A.call(s,a,c),f=lt(u==null?void 0:u.output);return f?r.shapeToSkeleton(f):u==null?void 0:u.sample}function Go(e,s){var u,f,m,w,x;const n=e.data.step,o=(u=s.previewOutputs)==null?void 0:u[n.id];if(o!=null)return o;const{app:a,action:c}=n.uses,l=n.uses.trigger===!0?(m=(f=s.shapes)==null?void 0:f.triggerDef)==null?void 0:m.call(f,a,c):(x=(w=s.shapes)==null?void 0:w.actionDef)==null?void 0:x.call(w,a,c);return l==null?void 0:l.sample}function Ko(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function qs(e,s){const n=mn(e.initialState)?{...e.initialState}:{};for(const o of e.variables??[])!o||typeof o.key!="string"||o.key===""||(o.default!==void 0?n[o.key]=o.default:s||(n[o.key]=Ko(o.type)));return n}function zt(e){return(r.inferOutputFields(e)??[]).map(s=>s.key)}function Xo(e){const{anchorId:s,nodes:n,edges:o}=e;if(!s)return Us;const a=e.shapes??{},c=r.ancestorIds(s,o);c.delete(s);const l=new Map(n.map(v=>[v.id,v])),u=[],f=[],m=new Map;for(const v of Jo(n,o)){if(!c.has(v))continue;const P=l.get(v);if(!P)continue;const{app:F,action:O}=P.data.step.uses,D=ge.effectiveStateConfig(F,O,P.data.step.state);if(D.mode==="off")continue;const y=qo(P,a);if(y!==void 0){const{ops:me}=ge.computeStateWrites(D,y);u.push(...me);for(const pe of zt(ge.foldState({},me))){const Ie=m.get(pe)??new Set;Ie.add(v),m.set(pe,Ie)}}const L=Go(P,e);L!==void 0&&f.push(...ge.computeStateWrites(D,L).ops)}const w=qs(e,!1),x=ge.foldState(w,u),S=zt(x);if(S.length===0)return Us;const k=new Set(zt(w)),I=new Map,A=new Map;for(const v of o)c.has(v.source)&&(!c.has(v.target)&&v.target!==s||(I.set(v.target,[...I.get(v.target)??[],v.source]),A.set(v.source,[...A.get(v.source)??[],v.target])));const g=[...c].filter(v=>!(I.get(v)??[]).length),$=v=>{const P=new Set,F=g.filter(O=>!v.has(O));for(;F.length>0;){const O=F.pop();if(O===s)return!1;if(!P.has(O)){P.add(O);for(const D of A.get(O)??[])v.has(D)||F.push(D)}}return!0},N=ge.foldState(qs(e,!0),f),H=[],J={};for(const v of S){const P=m.get(v)??new Set,F=k.has(v)||P.size>0&&$(P);H.push({key:v,path:!0,paths:F?"all":"some"});const O=r.valueAtPath(N,v);O!==void 0&&(J[`state.${v}`]=O)}return{fields:H,sampleValues:J}}const Yo={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"}},Gs="Never fired";function Zo(e){if(!e)return Gs;const s=new Date(e);return Number.isNaN(s.getTime())?Gs:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function Qo(e,s){var a;if(!(e!=null&&e.status))return null;const n=Yo[e.status];if(!n)return null;const o=e.status==="failed";return{label:n.label,tone:n.tone,error:o?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:Zo(e.lastFireAt),retryVisible:o&&s}}function er(e){const s=new Map;for(const n of e)n.nodeId&&s.set(n.nodeId,n);return s}function tr(e){return(e??[]).filter(s=>{var n;return((n=s.uses)==null?void 0:n.trigger)===!0})}function sr(e,s){const[n,o]=p.useState({}),a=p.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!r.isInternalApp(l)).sort());return p.useEffect(()=>{const l=JSON.parse(c).filter(u=>!a.current.has(u));if(l.length!==0){for(const u of l)a.current.add(u);Promise.all(l.map(async u=>{try{return[u,await e.getAppActions(u)]}catch{return a.current.delete(u),null}})).then(u=>{const f=u.filter(m=>m!==null);f.length!==0&&o(m=>({...m,...Object.fromEntries(f)}))})}},[e,c]),n}function nr(e,s){const[n,o]=p.useState({}),a=p.useRef(new Set),c=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!r.isInternalApp(l)).sort());return p.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const u=JSON.parse(c).filter(f=>!a.current.has(f));if(u.length!==0){for(const f of u)a.current.add(f);Promise.all(u.map(async f=>{try{return[f,await l.call(e,f)]}catch{return a.current.delete(f),null}})).then(f=>{const m=f.filter(w=>w!==null);m.length!==0&&o(w=>({...w,...Object.fromEntries(m)}))})}},[e,c]),n}function or(e){return(s,n)=>{var o,a;return(a=(o=e[s])==null?void 0:o.find(c=>c.key===n))==null?void 0:a.ports}}const rr="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 Ks(e,s,n,o){const a=e.find(c=>c.id===s);return[n,o,a==null?void 0:a.source,a==null?void 0:a.target]}const es=p.createContext(void 0),ts=p.createContext(new Map),ss=p.createContext({tones:new Map,loopOf:new Map});function Xs(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const ns=p.createContext(new Map),wn=p.createContext({byNode:new Map,subs:[]});function ir({apps:e,registration:s,children:n}){return t.jsx(ns.Provider,{value:e,children:t.jsx(wn.Provider,{value:s,children:n})})}const os=p.createContext(null);function ar(e){return t.jsx(X.ReactFlowProvider,{children:t.jsx(cr,{...e})})}function Ys(e,s){let n=s.length+1;for(;s.includes(`${e}-${n}`);)n++;return`${e}-${n}`}function Ht(e){var s,n;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((n=e.measured)==null?void 0:n.height)??e.height??64}}function cr({value:e,onChange:s,readOnly:n,height:o=480,apps:a,exprOptions:c,project:l,runState:u,stepProblems:f,onTestRun:m,fitViewKey:w,onRunFromNode:x}){var As,Ps,Is,Rs,Ms,Fs,Ls;const S=r.useW6WApi(),k=p.useMemo(()=>new Map((a??[]).map(i=>[i.id,i])),[a]),I=gr(e),[A,g]=p.useState(null),$=p.useMemo(()=>r.centralizeConnections(e),[e.id]),N=p.useMemo(()=>r.workflowToFlow($),[$]),[H,J]=p.useState($.connections??{}),v=p.useRef(H),P=p.useCallback(i=>{v.current=i,J(i)},[]),F=p.useCallback(i=>{const d=r.centralizeConnections({nodes:[i],connections:v.current});return d.connections!==v.current&&P(d.connections),d.nodes[0]},[P]),O=p.useMemo(()=>r.storedViewport(e),[e.id]),D=((As=e.settings)==null?void 0:As.savePosition)!==!1,[y,L,me]=X.useNodesState(N.nodes),pe=sr(S,y),Ie=nr(S,y),ne=p.useMemo(()=>or(pe),[pe]),[T,G,Re]=X.useEdgesState(N.edges),[we,xe]=p.useState(null),Z=p.useMemo(()=>e.canvas??{},[e.id]),[_,Y]=p.useState(Z),[te]=p.useState(()=>new mo(Ct($,N.nodes,N.edges,H,Z))),be=p.useRef(),[He,At]=p.useState(0),[Ee,ot]=p.useState(!1),[le,re]=p.useState(null),[ve,$e]=p.useState(null),[ie,K]=p.useState(null),[Ve,Me]=p.useState(!1),dt=p.useRef({});p.useEffect(()=>{Ve||(dt.current={})},[Ve]);const[z,ae]=p.useState(null),[Se,rt]=p.useState("props"),[Fe,Le]=p.useState(null),[Ce,Ye]=p.useState(null),[fe,De]=p.useState(null),Ze=p.useRef(!1),Ne=p.useRef(null),[oe,Te]=p.useState(null),{screenToFlowPosition:ke,fitView:ye}=X.useReactFlow(),it=r.useEffectiveTheme();p.useEffect(()=>{L(N.nodes),G(N.edges),xe(null),K(null),De(null),ae(null),Le(null),Y(Z),P($.connections??{}),te.reset(Ct($,N.nodes,N.edges,$.connections??{},Z)),be.current=void 0},[N,Z,$,L,G,P,te]),p.useEffect(()=>{L(i=>{const d=new Map(r.stampLoopOf(i,T).map(h=>[h.id,h.data.loopOf]));return i.map(h=>{const b=Bo(u,h.id,dn(h.id,d));return h.data.stepStatus===b&&h.data.runStatus===(u==null?void 0:u.status)?h:{...h,data:{...h.data,stepStatus:b,runStatus:u==null?void 0:u.status}}})}),G(i=>i.map(d=>{var C;const h=r.edgeLane(d),b=zo(u,d.source,h,typeof((C=d.data)==null?void 0:C.route)=="string"?d.data.route:void 0,d.target),j=r.edgeVisuals(h,b);return d.className===j.className&&d.label===j.label?d:{...d,className:j.className,label:j.label}}))},[u,N,He,L,G]),p.useEffect(()=>{L(i=>r.applyStepProblems(i,f))},[f,N,He,L]);const Be=p.useCallback((i,d)=>{var j,C;const{canvas:h,...b}=i;return!((j=d.notes)!=null&&j.length)&&!((C=d.sections)!=null&&C.length)?b:{...b,canvas:eo(d,e.canvas,D)}},[e.canvas,D]),Q=p.useCallback((i,d,h)=>{te.record(Ct(e,i,d,v.current,h??_),Ve?dt.current:be.current),s(Be(r.flowToWorkflow({...e,connections:v.current},i,d),h??_))},[e,s,_,Be,te,Ve]),Pt=p.useCallback(i=>r.canConnect(i.source,i.target,y,T,ne,r.routeFromHandle(i.sourceHandle)),[y,T,ne]),[se,Ae]=p.useState(null),ut=p.useRef(null),Qe=p.useRef(null);p.useEffect(()=>{L(i=>r.stampLoopOf(i,T))},[T,L]);const pt=p.useCallback(i=>{if(n)return;const d=r.applyConnect(i.source,i.target,y,T,r.laneForSourceHandle(i.sourceHandle),ne,r.routeFromHandle(i.sourceHandle));if(!d){const h=r.laneForSourceHandle(i.sourceHandle),b=r.connectRefusal(i.source,i.target,y,T,h,ne,r.routeFromHandle(i.sourceHandle));if(b&&b.refused==="loop"){Ae({nodeId:i.source,reason:b.reason});return}if(b){const C=T.find(M=>M.source===i.source&&r.edgeLane(M)===h);C&&(G(T.map(M=>({...M,selected:M.id===C.id}))),K(C.id),Ue({edgeId:C.id,message:Xs(b.cap)}));return}const j=r.connectConflict(i.source,i.target,y,T,r.laneForSourceHandle(i.sourceHandle));if(!j)return;G(T.map(C=>({...C,selected:C.id===j}))),K(j),Ue({edgeId:j,message:r.idClashMessage("Can’t draw that edge",j,Ks(T,j,i.source,i.target))});return}Ue(null),Ae(null),G(d),Q(y,d)},[T,y,G,Q,n,ne]),E=p.useCallback((i,d)=>{var W,V,q;if(n||d.isValid)return;const h=d.fromNode;if(!h)return;const b=((W=d.fromHandle)==null?void 0:W.type)==="target"?"target":"source",j=d.toNode;if(j&&b==="source"){const ee=Mo(h.id,j.id,Hs(Qe.current,h.id,d.fromHandle),y,T);if(ee){Ae({nodeId:h.id,reason:ee});return}}const C=(V=y.find(ee=>ee.id===h.id))==null?void 0:V.data.step;if(C){const ee=r.nodePortsForStep(C,ne);if((b==="source"?ee.out:ee.in)<1)return}const M="changedTouches"in i?i.changedTouches[0]:i,R=ke({x:M.clientX,y:M.clientY});Te({nodeId:h.id,handleType:b,position:R,lane:Hs(Qe.current,h.id,d.fromHandle),route:r.routeFromHandle((q=d.fromHandle)==null?void 0:q.id)}),Me(!0)},[n,ke,y,T,ne]),B=p.useCallback((i,d,h)=>{if(n)return;const b=y.find(W=>W.id===i);if(!b)return;const j=Ht(b),C=r.laneForSourceHandle(h),M=120,R=d==="target"?{x:j.x-j.w-M,y:j.y}:C==="error"?{x:j.x,y:j.y+j.h+M}:C==="each"?{x:j.x+j.w+M,y:j.y-j.h-M/2}:{x:j.x+j.w+M,y:j.y};Te({nodeId:i,handleType:d,position:R,lane:C,route:r.routeFromHandle(h)}),Me(!0)},[n,y]),U=p.useCallback(i=>{n||De({nodeIds:[i],edgeIds:[]})},[n]),de=p.useCallback(i=>{if(n)return;const d=lo(i,y,T,_);L(d.nodes),G(d.edges),Y(d.canvas),d.nodes.some(h=>h.id===we)||xe(null),d.nodes.some(h=>h.id===z)||ae(null),d.edges.some(h=>h.id===ie)||K(null),Q(d.nodes,d.edges,d.canvas)},[y,T,_,L,G,Q,n,we,z,ie]),Je=p.useCallback(()=>{if(n)return;const i=yo(y,T,_);L(i.nodes),Y(i.canvas),Ze.current=!0,Q(i.nodes,T,i.canvas)},[y,T,_,L,Q,n]),Tn=p.useCallback(()=>{n||Je()},[n,Je]);p.useEffect(()=>{Ze.current&&(Ze.current=!1,ye({duration:300}))},[y,ye]);const is=p.useRef(w);p.useEffect(()=>{Object.is(is.current,w)||(is.current=w,ye({duration:300}))},[w,ye]);const[ft,Ue]=p.useState(null),et=p.useMemo(()=>T.find(i=>i.id===ie)??null,[T,ie]),An=p.useCallback(i=>{if(n||!ie)return;const d=T.find(M=>M.id===ie);if(!d||r.edgeLane(d)===i)return;const h=r.edgeWhenConflict(T,ie,i,y),b=r.relaneRefusal(T,ie,i,y,ne),j=h||b?null:r.setEdgeWhen(T,ie,i,y,ne);if(!j){if(b){Ue({edgeId:ie,message:Xs(b.cap)});return}Ue({edgeId:ie,message:h?r.idClashMessage("Can’t switch this edge",h,Ks(T,h,d.source,d.target)):"This edge can’t be switched right now."});return}Ue(null),G(j);const C=j.find(M=>M.source===d.source&&M.target===d.target&&r.edgeLane(M)===i);K((C==null?void 0:C.id)??null),Q(y,j)},[T,y,G,Q,n,ie,ne]),Pn=p.useCallback(i=>{if(n)return;const d=T.filter(h=>h.id!==i);d.length!==T.length&&(G(d),ie===i&&K(null),Q(y,d))},[y,T,G,Q,n,ie]),It=p.useCallback(i=>{if(n)return;const d=i.map(C=>y.find(M=>M.id===C)).filter(C=>C!==void 0);if(d.length===0)return;const h=y.map(C=>C.id),b=d.map(C=>{const M=r.suggestStepId(h,`${C.data.step.id}_copy`);h.push(M);const R={...r.stripBody(structuredClone(C.data.step)),id:M};return{id:M,type:C.type,position:{x:C.position.x+40,y:C.position.y+60},data:{step:R,isInternal:C.data.isInternal},...d.length>1?{selected:!0}:{}}}),j=[...d.length>1?y.map(C=>C.selected?{...C,selected:!1}:C):y,...b];L(j),xe(b[0].id),Q(j,T)},[y,T,L,Q,n]),as=p.useCallback(i=>It([i]),[It]),In=p.useCallback(i=>{if(n)return;const d=r.isInternalApp(i.uses.app),h=y.map(q=>q.id),b=i.id&&!r.stepNameError(i.id,h)?i.id:r.suggestStepId(h,r.slugifyLabel(r.internalNodeLabel(i.uses.app,i.uses.action))),j=F({id:b,uses:i.uses,...i.with&&Object.keys(i.with).length>0?{with:i.with}:{}}),C={id:b,type:d?"control":"step",position:(oe==null?void 0:oe.position)??(Ce==null?void 0:Ce.position)??{x:80,y:80+y.length*24},data:{step:j,isInternal:d}},M=[...y,C];let R=T,W=null;const V=(q,ee,ce,_e)=>{const st=r.connectRefusal(q,ee,M,T,ce,ne);st&&st.refused==="loop"&&(W={nodeId:_e,reason:st.reason})};if(oe){const[q,ee]=oe.handleType==="target"?[b,oe.nodeId]:[oe.nodeId,b],ce=r.applyConnect(q,ee,M,T,oe.lane,ne,oe.route);ce||V(q,ee,oe.lane,oe.nodeId),R=ce??T}else{const q=y.find(ee=>r.isTriggerStep(ee.data.step.uses));if(r.isTriggerStep(i.uses)){if(!q){const ee=r.findChainRoot(y,T);if(ee){const ce=r.applyConnect(b,ee.id,M,T,"success",ne);ce||V(b,ee.id,"success",ee.id),R=ce??T}}}else{const ce=(q&&!T.some(_e=>_e.source===q.id)?q:void 0)??r.findChainTail(y,T);if(ce){const _e=r.applyConnect(ce.id,b,M,T,"success",ne);_e||V(ce.id,b,"success",ce.id),R=_e??T}}}return L(M),R!==T&&G(R),Ae(W),xe(b),Q(M,R),b},[y,T,L,G,Q,n,oe,Ce,ne,F]),cs=p.useCallback((i,d)=>{var W;let h=d;const b=(W=y.find(V=>V.id===i))==null?void 0:W.data.step;if(d.uses.connection&&!d.uses.connectionRef&&(b!=null&&b.uses.connectionRef)&&b.uses.app===d.uses.app){const V=r.selectNodeConnection(r.withConnectionRef(d,b.uses.connectionRef),d.uses.connection,y.map(q=>q.data.step),v.current);P(V.connections),h=V.step}else h=F(d);const j=h.id!==i;if(j&&y.some(V=>V.id===h.id))return;const C=y.map(V=>V.id===i?{...V,id:h.id,data:{step:h,isInternal:r.isInternalApp(h.uses.app)}}:V);if(j){const V=r.renameStepInEdges(T,i,h.id),q=rn(_,i,h.id);L(C),G(V),Y(q),we===i&&xe(h.id),z===i&&ae(h.id),Q(C,V,q);return}L(C);const M=new Set(r.routesForStep(h).map(V=>V.id)),R=T.filter(V=>{var q;return V.source!==h.id||((q=V.data)==null?void 0:q.route)===void 0||M.has(String(V.data.route))});R.length!==T.length&&G(R),Q(C,R)},[y,T,_,L,G,we,z,Q,F,P]),qe=p.useCallback(i=>{n||(Y(i),Q(y,T,i))},[n,y,T,Q]),Rn=p.useCallback(()=>{var j;if(n)return;const i=(j=Ne.current)==null?void 0:j.getBoundingClientRect(),d=i?ke({x:i.left+i.width/2,y:i.top+i.height/2}):{x:0,y:0},h=_.notes??[],b={id:Ys("note",h.map(C=>C.id)),color:"#facc15",position:{x:Math.round(d.x-100),y:Math.round(d.y-60)},size:{width:200,height:120},content:""};qe(qt({..._,notes:[...h,b]}))},[n,_,ke,qe]),Mn=p.useCallback((i,d)=>{if(n)return;const h=d?Math.min(i.x,d.x):i.x,b=d?Math.min(i.y,d.y):i.y,j=d?Math.abs(d.x-i.x):360,C=d?Math.abs(d.y-i.y):240,M=y.filter(ee=>{const ce=Ht(ee),_e=ce.x+ce.w/2,st=ce.y+ce.h/2;return _e>=h&&_e<=h+j&&st>=b&&st<=b+C}).map(ee=>ee.id),R=_.sections??[],W=Ys("section",R.map(ee=>ee.id)),V={id:W,title:"Section",color:"#6366f1",position:{x:Math.round(h),y:Math.round(b)},size:{width:Math.round(j),height:Math.round(C)},nodes:[]},q={..._,sections:[...R,V]};qe(qt(Ut(q,W,M)))},[n,y,_,qe]);p.useEffect(()=>{if(!Ee)return;const i=d=>{d.key==="Escape"&&(ot(!1),re(null))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[Ee]);const Fn=p.useCallback((i,d)=>{var M;if(n)return;const h=(M=_.sections)==null?void 0:M.find(R=>R.id===i);if(!h)return;const b=new Set(h.nodes),j=y.map(R=>b.has(R.id)?{...R,position:{x:R.position.x+d.dx,y:R.position.y+d.dy}}:R),C={..._,sections:(_.sections??[]).map(R=>R.id===i?{...R,position:{x:R.position.x+d.dx,y:R.position.y+d.dy}}:R)};L(j),Y(C),Q(j,T,C)},[n,_,y,T,L,Q]),Ln=p.useCallback((i,d)=>{if(n)return;const h=i==="note"?{..._,notes:(_.notes??[]).filter(b=>b.id!==d)}:{..._,sections:(_.sections??[]).filter(b=>b.id!==d)};qe(h)},[n,_,qe]),Dn=i=>{let d=_;for(const h of i){const b=Ht(h),j=b.x+b.w/2,C=b.y+b.h/2,M=(d.sections??[]).find(W=>j>=W.position.x&&j<=W.position.x+W.size.width&&C>=W.position.y&&C<=W.position.y+W.size.height),R=an(d,h.id);M?(R.length!==1||R[0]!==M.id)&&(d=Ut(d,M.id,[h.id])):R.length>0&&(d=Zt(d,h.id))}return d},Rt=p.useCallback((i,d,h)=>{(async()=>{const b=await S.saveStepTest(e.id,i,d).catch(j=>(console.error("step run fixture save failed",j),null));await S.recordStepTestRun(e.id,i,{stepTestId:(b==null?void 0:b.id)??null,status:h.status,input:d.input,output:h.output,error:h.error,...h.meta?{meta:h.meta}:{}})})().catch(b=>{console.error("step run persist failed",b)})},[S,e.id]),ls=p.useCallback(i=>{const d=y.find(h=>h.id===i);!d||!x&&r.isControlApp(d.data.step.uses.app)||g({stepId:i,status:"collect"})},[y,x]),On=p.useCallback(async(i,d,h)=>{if(!x)return;const b=y.find(M=>M.id===i);if(!b)return;const j=r.isTriggerStep(b.data.step.uses),C={stopAt:Kt(y.map(M=>M.data.step),i),...h?{state:h}:{},...j?{input:d}:{}};g({stepId:i,status:"running"});try{await x(i,C),g(null)}catch(M){const R=M;g({stepId:i,status:"error",error:R.message??String(M),errorCode:R.code})}},[y,x]),ht=p.useCallback((i,d)=>{if(n)return;const h=y.map(b=>b.id===i?{...b,data:{...b.data,step:d(b.data.step)}}:b);L(h),Q(h,T)},[y,T,L,Q,n]),ds=p.useCallback(i=>ht(i,d=>un(d,!Xe(d))),[ht]),us=p.useCallback(i=>ht(i,d=>pn(d,!Pe(d))),[ht]),_n=p.useCallback(async(i,d,h)=>{m==null||m();const b=y.find(W=>W.id===i);if(!b)return;const j=b.data.step,C=r.isTriggerStep(j.uses),M=C?{input:d}:{...j.with??{},...d},R=C?{input:d,with:d}:{input:d,with:M};g({stepId:i,status:"running"});try{const W=await S.invokeAction(j.uses.app,j.uses.action,M,{connectionId:r.connectionIdFor(j,v.current),project:l,...h?{state:h}:{},workflowId:e.id}),V=W.logs,q=W.meta;g({stepId:i,status:"done",value:W.value,logs:V,...q?{meta:q}:{}}),Rt(i,R,{status:"succeeded",output:W.value,...q?{meta:q}:{}})}catch(W){const V=W;g({stepId:i,status:"error",error:V.message??String(W),errorCode:V.code}),Rt(i,R,{status:"failed",error:V.message??String(W)})}},[y,S,Rt,l,m,e.id]),Mt=p.useMemo(()=>({onEdit:i=>{rt("props"),ae(i)},onEditJson:i=>{rt("json"),ae(i)},onRun:ls,onDuplicate:as,onDelete:U,onTogglePause:ds,onToggleDisable:us,runsFromNode:!!x,onAddFromPort:B,readOnly:n}),[ls,as,U,ds,us,x,B,n]);p.useEffect(()=>{const i=Ne.current;if(!i)return;const d=h=>{const b=h.target.closest(".react-flow__node");if(!b)return;const j=b.getAttribute("data-id");j&&(h.stopPropagation(),Mt.onEdit(j))};return i.addEventListener("dblclick",d,!0),()=>i.removeEventListener("dblclick",d,!0)},[Mt]);const tt=y.find(i=>i.id===z),gt=(tt==null?void 0:tt.data.step)??null,Ft=A?((Ps=y.find(i=>i.id===A.stepId))==null?void 0:Ps.data.step)??null:null,Lt=(A==null?void 0:A.status)==="collect"&&!!Ft,ps=p.useMemo(()=>{const i=new Map;for(const d of y)i.set(d.id,po(d.id,T).count);return i},[y,T]),fs=No(y),mt=p.useMemo(()=>ko(fs),[fs]),Wn=p.useMemo(()=>So(T,mt.tones,mt.loopOf),[T,mt]),$n=p.useMemo(()=>({step:wr,control:xr}),[]),[wt,hs]=p.useState({}),[xt,gs]=p.useState({}),[ms,ws]=p.useState({}),[bt,xs]=p.useState({}),[ze,yt]=p.useState(null),[bs,ys]=p.useState([]),Vn=z??ze??"";p.useEffect(()=>{const i=S.loadNodeSamples;if(typeof i!="function"||!e.id){ys([]);return}let d=!1;return i(e.id).then(h=>{d||ys(Array.isArray(h)?h:[])},()=>{}),()=>{d=!0}},[S,e.id,Vn]);const jt=p.useMemo(()=>r.indexNodeSamples(bs),[bs]),Dt=p.useMemo(()=>r.splitNodeOutputs(wt,jt,bt),[wt,jt,bt]),Oe=p.useMemo(()=>r.splitPreviewOutputs(wt,jt,bt),[wt,jt,bt]),he=p.useMemo(()=>({actionDef:(i,d)=>{var h;return(h=pe[i])==null?void 0:h.find(b=>b.key===d)},triggerDef:(i,d)=>{var h;return(h=Ie[i])==null?void 0:h.find(b=>b.key===d)},testOutputs:Dt.fresh,persistedOutputs:Dt.persisted,loopSamples:ms}),[pe,Ie,Dt,ms]),Ge=p.useMemo(()=>A?r.upstreamStateSources(A.stepId,y,T,he):void 0,[A,y,T,he]),Bn=p.useMemo(()=>(Ge==null?void 0:Ge.steps)??[],[Ge]),ue=p.useMemo(()=>{const i=r.upstreamStateSources(z,y,T,he,ze);return{...i,steps:r.excludeSelfStep(i.steps,z??ze)}},[z,ze,y,T,he]),Ot=p.useMemo(()=>Xo({anchorId:z??ze,nodes:y,edges:T,initialState:e.initialState,variables:e.variables,shapes:he,previewOutputs:{...Oe.persisted,...Oe.fresh}}),[z,ze,y,T,e.initialState,e.variables,he,Oe]),js=JSON.stringify([...ue.steps.map(i=>i.id),...ue.extraSampleIds??[]]);p.useEffect(()=>{const i=JSON.parse(js);if(!z&&!ze||i.length===0){hs({}),gs({}),ws({}),xs({});return}let d=!1;return Promise.all(i.map(async h=>{try{const b=await S.listStepTests(e.id,h),j=b.length?b[b.length-1]:null;return j?{id:h,output:j.lastRunOutput,runAt:j.lastRunAt,meta:j.lastRunMeta,loopSample:r.foreachTestSample(j)}:null}catch{return null}})).then(h=>{if(d)return;const b={},j={},C={},M={};for(const R of h)R!=null&&R.meta&&(j[R.id]=R.meta),R!=null&&R.loopSample&&(C[R.id]=R.loopSample),!(!R||R.output===void 0||R.output===null)&&(b[R.id]=R.output,M[R.id]=R.runAt);hs(b),xs(M),gs(j),ws(C)}),()=>{d=!0}},[S,e.id,z,ze,js]);const _t=p.useMemo(()=>r.declaredSamples(y,he),[y,he]),vt=p.useMemo(()=>({persisted:Oe.persisted,samples:_t.samples,event:_t.event}),[Oe.persisted,_t]),vs=p.useMemo(()=>r.upstreamSampleValues(ue.steps,Oe.fresh,xt,ue.loop,vt),[ue.steps,ue.loop,Oe.fresh,xt,vt]),Ss=p.useMemo(()=>r.upstreamSampleValueSources(ue.steps,Oe.fresh,xt,ue.loop,vt),[ue.steps,ue.loop,Oe.fresh,xt,vt]),Cs=r.useExpressionOptions(),Ns=p.useMemo(()=>r.nodeConfigSources(y),[y]),ks=p.useMemo(()=>r.nodeConfigValues(y,I.subs),[y,I.subs]),Wt=p.useMemo(()=>r.nodeMetaValues(y,I.subs,k,H),[y,I.subs,k,H]),$t=p.useMemo(()=>({...c??{},steps:ue.steps,hasTrigger:ue.hasTrigger,eventOutputs:ue.eventOutputs,eventOutputsFrom:ue.eventOutputsFrom,loop:ue.loop,stateShape:{fields:Ot.fields},nodeConfigs:Ns,nodeConfig:ks,nodeMeta:Wt,valueSources:Ss,sampleValues:{...Cs.sampleValues??{},...(c==null?void 0:c.sampleValues)??{},...r.nodeMetaSampleValues(Wt),...vs,...Ot.sampleValues}}),[c,Cs.sampleValues,ue,Ot,vs,Ss,Ns,ks,Wt]),Es=i=>{var j;if(n)return;const d=te[i]();if(!d)return;const h=go(e,d);L(h.nodes.map(C=>({...C,selected:C.id===we}))),G(h.edges.map(C=>({...C,selected:C.id===ie}))),Y(d.canvas),P(d.connections),h.nodes.some(C=>C.id===we)||xe(null),h.edges.some(C=>C.id===ie)||K(null);const b=h.nodes.some(C=>C.id===z);b||ae(null),Me(!1),yt(null),Te(null),De(null),$e(null),Ye(null),Le(null),Ae(null),Ue(null),be.current=void 0,At(C=>C+1),s(Be(r.flowToWorkflow({...e,nodes:d.nodes,connections:d.connections},h.nodes,h.edges),d.canvas)),!b&&!A&&((j=Ne.current)==null||j.focus({preventScroll:!0}))},Ts=p.useRef(Es);Ts.current=Es,p.useEffect(()=>{const i=Ne.current;if(!i)return;let d=i.contains(document.activeElement);const h=j=>{j.type==="focusin"&&j.target===document.body||(d=i.contains(j.target))},b=j=>{if(n||j.defaultPrevented||Vt(j.target)||!i.contains(j.target)&&!(d&&j.target===document.body))return;const C=j.key.toLowerCase();!(j.ctrlKey||j.metaKey)||j.altKey||C!=="z"&&!(C==="y"&&!j.shiftKey)||(j.preventDefault(),Ts.current(C==="y"||j.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",h),document.addEventListener("focusin",h),document.addEventListener("keydown",b),()=>{document.removeEventListener("pointerdown",h),document.removeEventListener("focusin",h),document.removeEventListener("keydown",b)}},[n]);const St=p.useCallback((i,d)=>{var R;if(Vt(i.target))return;const h=(R=Ne.current)==null?void 0:R.getBoundingClientRect();if(!h)return;i.preventDefault();const b=$s(y,T),j=b.nodeIds,C=Kn(j,d),M=d!==void 0&&!j.includes(d);M&&L(y.map(W=>W.selected!==(W.id===d)?{...W,selected:W.id===d}:W)),Le({x:i.clientX-h.left,y:i.clientY-h.top,flow:ke({x:i.clientX,y:i.clientY}),nodeIds:C,edgeIds:M?[]:b.edgeIds})},[y,T,L,ke]),zn=p.useCallback(i=>{var d;Le(null),i&&((d=Ne.current)==null||d.focus({preventScroll:!0}))},[]),Hn=i=>{const d=Fe;!d||n||(i==="duplicate"?It(d.nodeIds):i==="delete"?De({nodeIds:d.nodeIds,edgeIds:d.edgeIds}):(Te(null),Ye({position:d.flow,...i==="add-trigger"?{tab:"triggers"}:{}}),Me(!0)))},Jn=t.jsx(os.Provider,{value:Mt,children:t.jsx(es.Provider,{value:ne,children:t.jsx(ts.Provider,{value:ps,children:t.jsx(ss.Provider,{value:mt,children:t.jsx(ir,{apps:k,registration:I,children:t.jsx(r.WorkflowProjectProvider,{project:l,workflowId:e.id,children:t.jsx(r.ExpressionOptionsProvider,{value:$t,children:t.jsxs("section",{ref:Ne,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:o,position:"relative"},onFocusCapture:i=>{be.current=Vt(i.target)?{}:void 0},onBlurCapture:()=>{be.current=void 0},onKeyDown:i=>{if(i.defaultPrevented||i.key!=="Backspace"&&i.key!=="Delete"||n||z||Ve||fe)return;const d=i.target;if(d.isContentEditable||d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.tagName==="SELECT"||d.closest("dialog, .w6w-modal")!==null)return;const h=$s(y,T);!h.nodeIds.length&&!h.edgeIds.length||(i.preventDefault(),!h.nodeIds.length&&h.edgeIds.length===1?Pn(h.edgeIds[0]):De(h))},children:[t.jsxs(X.ReactFlow,{nodes:y,edges:Wn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:X.ConnectionLineType.SmoothStep,onNodesChange:me,onEdgesChange:Re,onConnect:pt,onConnectStart:(i,d)=>{Qe.current=d},onConnectEnd:E,onPaneClick:()=>Ae(null),onPaneContextMenu:i=>St(i),onNodeContextMenu:(i,d)=>St(i,d.id),onEdgeContextMenu:i=>St(i),onSelectionContextMenu:i=>St(i),onMoveStart:()=>Le(null),isValidConnection:Pt,onNodeDragStop:(i,d,h)=>{const b=Dn(h),j=b!==_;if(j&&Y(b),!D&&!j){te.record(Ct(e,y,T,v.current,b));return}Q(y,T,b)},onMoveEnd:(i,d)=>{if(!i||n)return;const h=r.flowToWorkflow(e,y,T),b=r.withViewport(h,d);b!==h&&s(b,{viewportOnly:!0})},onSelectionChange:({nodes:i,edges:d})=>{var h,b,j,C;xe(((h=i[0])==null?void 0:h.id)??null),K(((b=d[0])==null?void 0:b.id)??null),ut.current!==(((j=i[0])==null?void 0:j.id)??null)&&(ut.current=((C=i[0])==null?void 0:C.id)??null,Ae(null))},nodeTypes:$n,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...O?{defaultViewport:O}:{fitView:!0},deleteKeyCode:null,colorMode:it,proOptions:{hideAttribution:!0},children:[t.jsx(X.Background,{gap:16}),t.jsx(X.Controls,{showInteractive:!1,children:!n&&t.jsx(X.ControlButton,{onClick:Tn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(je.Icon,{name:"layout"})})}),t.jsx(X.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(X.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>Me(!0),children:"+ Node"}),t.jsx(r.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Rn}),t.jsx(r.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${Ee?" active":""}`,"aria-pressed":Ee,"data-testid":"draw-section",onClick:()=>{ot(!Ee),re(null)}})]}),!n&&Ee&&t.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:i=>{if(i.button!==0)return;i.currentTarget.setPointerCapture(i.pointerId);const{clientX:d,clientY:h}=i;re({sx:d,sy:h,ex:d,ey:h})},onPointerMove:i=>{const{clientX:d,clientY:h}=i;re(b=>b&&{...b,ex:d,ey:h})},onPointerUp:()=>{const i=le;if(re(null),ot(!1),!i)return;const d=ke({x:i.sx,y:i.sy}),h=Math.abs(i.ex-i.sx)>6||Math.abs(i.ey-i.sy)>6;Mn(d,h?ke({x:i.ex,y:i.ey}):null)},children:le&&(()=>{var b;const i=(b=Ne.current)==null?void 0:b.getBoundingClientRect(),d=(i==null?void 0:i.left)??0,h=(i==null?void 0:i.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(le.sx,le.ex)-d,top:Math.min(le.sy,le.ey)-h,width:Math.abs(le.ex-le.sx),height:Math.abs(le.ey-le.sy)}})})()}),!n&&et&&r.edgeLane(et)!=="each"&&((Is=y.find(i=>i.id===et.source))==null?void 0:Is.data.step.uses.app)!==r.ROUTER_APP&&t.jsx(X.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(i=>t.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${r.edgeLane(et)===i?" active":""}`,"aria-pressed":r.edgeLane(et)===i,title:rr,onClick:()=>An(i),children:i==="success"?"Success":"Error"},i)),(ft==null?void 0:ft.edgeId)===et.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:ft.message})]})}),se&&t.jsx(X.NodeToolbar,{nodeId:se.nodeId,position:X.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:r.loopRefusalMessage(se.reason)})}),t.jsx(r.CanvasLayer,{canvas:_,readOnly:n,savePosition:D,onChange:qe,onSectionDrop:Fn,onRequestDelete:(i,d)=>!n&&$e({kind:i,id:d})})]}),ve&&t.jsx(r.ConfirmModal,{title:ve.kind==="note"?"Delete note":"Delete section",message:ve.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Ln(ve.kind,ve.id),$e(null)},onClose:()=>$e(null)}),Ve&&t.jsx(r.StepBuilderModal,{initialTab:Ce==null?void 0:Ce.tab,onClose:()=>{Me(!1),Te(null),Ye(null),yt(null)},onAdd:i=>{const d=In(i);return d&&yt(d),d},onDraftChange:(i,d)=>cs(i,{id:i,...d}),stepIds:y.map(i=>i.id),onOpenStep:i=>{Me(!1),Te(null),Ye(null),yt(null),rt("props"),ae(i)},workflowId:e.id,upstreamSteps:r.stepBuilderUpstreamSteps(oe,y,T),loop:r.stepBuilderLoop(oe,y,T,he)}),gt&&z&&t.jsx(yr,{workflowId:e.id,step:gt,restoreVersion:He,upstreamSteps:$t.steps??[],loop:$t.loop,readOnly:n,fanOutCount:ps.get(z)??0,stateOutputFields:(Ls=r.resolveOutputShape((Rs=he.actionDef)==null?void 0:Rs.call(he,gt.uses.app,gt.uses.action),(Ms=he.testOutputs)==null?void 0:Ms[z],(Fs=he.persistedOutputs)==null?void 0:Fs[z]))==null?void 0:Ls.fields.map(i=>i.key),initialView:Se,stepProblems:tt==null?void 0:tt.data.stepProblems,otherStepIds:y.filter(i=>i.id!==z).map(i=>i.id),onChange:i=>cs(z,i),onClose:()=>ae(null),onTestRun:m}),A&&t.jsxs(r.Modal,{title:`${Lt?"Run node":"Test run"}: ${A.stepId}`,onClose:()=>g(null),children:[Lt&&Ft&&t.jsx(pr,{workflowId:e.id,step:Ft,upstreamSteps:Bn,loop:Ge==null?void 0:Ge.loop,continues:x?{stopAt:Kt(y.map(i=>i.data.step),A.stepId)}:void 0,onCancel:()=>g(null),onRun:(i,d)=>x?On(A.stepId,i,d):_n(A.stepId,i,d)},A.stepId),!Lt&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[A.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),A.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[A.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:A.errorCode})}),A.error||"The node failed with no error message."]}),A.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(r.ResultViewer,{value:A.value,maxHeight:360}),A.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(r.ResultViewer,{value:A.meta,maxHeight:360})]})]}),A.logs&&A.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("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:A.logs.join(`
2
- `)})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>g(null),children:"Close"})})]})]}),fe!==null&&t.jsx(r.ConfirmModal,{title:fe.nodeIds.length===1?"Delete node":fe.nodeIds.length>1?`Delete ${fe.nodeIds.length} nodes`:`Delete ${fe.edgeIds.length} connections`,message:uo(fe,y,T),confirmLabel:"Delete",onConfirm:()=>{de(fe),De(null)},onClose:()=>De(null)}),Fe&&t.jsx(Gn,{x:Fe.x,y:Fe.y,items:Xn(Fe.nodeIds,!!n),onAction:Hn,onClose:zn})]})})})})})})})});return t.jsx(r.WorkflowConnectionsContext.Provider,{value:{nodes:y.map(i=>i.data.step),connections:H,setConnections:P,readOnly:n},children:Jn})}const lr=["code"];function Tt(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function dr(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return Tt(e)}function ur({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 n=e[0],o=n!==void 0?(r.inferOutputFields(n)??[]).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(r.ResultViewer,{value:n,maxHeight:220})]}),s==="saved"&&t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",o.length>0&&t.jsxs(t.Fragment,{children:[" ","Steps on ",t.jsx("strong",{children:"Each item"})," now offer ",t.jsx("strong",{children:"Current item"})," ›"," ",o.map((a,c)=>t.jsxs("span",{children:[c>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 xn(e){const[s,n]=p.useState(null),[o,a]=p.useState("0"),c=s??r.loopItemText(e),l=e?r.parseLoopSeed(c,o):void 0;return{active:!!e,itemText:c,indexText:o,setItemText:n,setIndexText:a,parsed:l}}function bn(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function rs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function yn({seed:e,readOnly:s}){if(!e.active)return null;const n=rs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[t.jsx("span",{children:"Current item"}),t.jsx("textarea",{rows:3,value:e.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:o=>e.setItemText(o.target.value)}),t.jsx("span",{children:"Index"}),t.jsx("input",{type:"text",inputMode:"numeric",value:e.indexText,readOnly:s,"aria-label":"Index",onChange:o=>e.setIndexText(o.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."}),n&&t.jsx("span",{className:"w6w-hint",role:"alert",children:n})]})}function Yt({text:e,onChange:s,seeds:n,readOnly:o,expand:a,hint:c}){const l=Tt(e),u=l?Object.keys(l).length:0,f=u>0,[m,w]=p.useState(f);p.useEffect(()=>{(f||a)&&w(!0)},[f,a]);const x=S=>{s(JSON.stringify(S.lastRunOutput??S.input??{},null,2)),w(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),n.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:n.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:o,onClick:()=>x(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:m,onToggle:S=>w(S.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",u>0?` · ${u} key${u===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:o,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:S=>s(S.target.value)}),t.jsx("span",{className:"w6w-hint",children:c??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 pr({workflowId:e,step:s,upstreamSteps:n,loop:o,onRun:a,onCancel:c,continues:l}){const u=r.useW6WApi(),f=r.isTriggerStep(s.uses),m=r.isInternalApp(s.uses.app),w=p.useMemo(()=>{var Z;return f?r.asFieldDefs((Z=s.with)==null?void 0:Z.fields):[]},[f,s.with]),x=p.useMemo(()=>f?r.fieldsToParams(w):m?r.internalNodeParams(s.uses.app,s.uses.action):null,[f,m,w,s.uses.app,s.uses.action]),[S,k]=p.useState(null),I=x??S;p.useEffect(()=>{if(x)return;if(!s.uses.app||!s.uses.action){k([]);return}let Z=!1;return k(null),u.getAppActions(s.uses.app).then(_=>{var Y;Z||k(((Y=_.find(te=>te.key===s.uses.action))==null?void 0:Y.params)??[])}).catch(()=>!Z&&k([])),()=>{Z=!0}},[u,x,s.uses.app,s.uses.action]);const[A,g]=p.useState(()=>{var Z;return f?r.seedValues(r.asFieldDefs((Z=s.with)==null?void 0:Z.fields)):{}}),[$,N]=p.useState("{}"),H=r.useSeedSources(e,n,!f),J=xn(o),v=r.startStateFromSeeds(H,bn(J)),P=r.useRememberedTestInput(e,s.id),[F,O]=p.useState(!1),[D,y]=p.useState(!1);p.useEffect(()=>{if(!P.loaded)return;let Z=!1;const _=(Y,te)=>{Y&&Object.keys(Y).length>0&&(f?g(be=>({...be,...Y})):N(JSON.stringify(Y,null,2)),te&&y(!0)),O(!0)};if(P.input!==void 0){_(P.input,!0);return}return u.listStepTests(e,s.id).then(Y=>{if(Z)return;const te=Y.length?Y[Y.length-1]:null;_(f?te==null?void 0:te.with:te==null?void 0:te.input,!1)}).catch(()=>{Z||O(!0)}),()=>{Z=!0}},[u,e,s.id,f,P.loaded]);const[L,me]=p.useState(0),pe=()=>{P.clear(),y(!1),f?g(r.seedValues(w)):N("{}"),me(Z=>Z+1)},[Ie,ne]=p.useState(!0),T=Tt($),G=f?Ie:T!==null,Re=f?A:{...s.with??{},...T??{}},we=f?null:rs(J),xe=!!I&&F&&G&&!we&&r.requiredParamsFilled(I,Re);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,_)=>t.jsxs("span",{children:[_>0?", ":"",t.jsx("code",{children:Z})]},Z))]}):null,". Disabled nodes are skipped."]}),D&&I!==null&&F&&t.jsx(r.LastUsedNote,{onClear:pe}),I===null||!F?t.jsx("p",{className:"w6w-muted w6w-small",children:I===null?"Loading parameters…":"Loading saved values…"}):f?t.jsxs(t.Fragment,{children:[t.jsx(r.PropertyEntryForm,{params:I,values:A,onChange:g,onValidityChange:ne},L),I.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(yn,{seed:J}),t.jsx(Yt,{text:$,onChange:N,seeds:H})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!xe&&I!==null&&F&&t.jsx("span",{className:"w6w-muted w6w-small",children:we?`${we} Fix it to run.`:G?f?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":f?"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:!xe,onClick:()=>{P.save(f?A:T??{},I??[]),a(f?A:T??{},f?void 0:v)},children:"▶ Run"})]})]})}function fr(e){return e.uses.app===r.CONTROL_APP&&e.uses.action==="foreach"}function jn({id:e}){const{tones:s,loopOf:n}=p.useContext(ss),o=dn(e,n);return o.length===0?null:t.jsx("span",{className:"w6w-loop-dots",children:o.map(a=>t.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${a}`,title:`In loop · ${a}`,style:{background:Qt(s.get(a)??1)}},a))})}function vn(e){return Co(e,p.useContext(ss).tones)}function We({type:e,position:s,multiple:n,id:o,variant:a,top:c,routeLabel:l}){const u=X.useNodeId(),f=p.useContext(os),m=!!u&&!!f&&!f.readOnly,w=()=>{m&&u&&f.onAddFromPort(u,e,o)},x=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(X.Handle,{type:e,position:s,id:o,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":n?"w6w-handle-multi":void 0,style:{...n?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:m?w:void 0,title:l?`${l} — drag or click to connect`:m?`Drag to empty canvas (or click) to add ${x} · 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":n?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Sn({id:e,step:s,runnable:n}){const o=p.useContext(os);if(!o||o.readOnly)return null;const a=n||o.runsFromNode,c=o.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=Xe(s),u=Pe(s);return t.jsxs(X.NodeToolbar,{position:X.Position.Top,className:"w6w-node-toolbar",children:[a&&t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:c,"aria-label":c,onClick:()=>o.onRun(e),children:t.jsx(je.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:()=>o.onTogglePause(e),children:t.jsx(je.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":u,title:u?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":u?"Enable node":"Disable node",onClick:()=>o.onToggleDisable(e),children:t.jsx(je.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:()=>o.onEdit(e),children:t.jsx(je.Icon,{name:"edit",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>o.onDuplicate(e),children:t.jsx(je.Icon,{name:"copy",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>o.onDelete(e),children:t.jsx(je.Icon,{name:"trash",size:15})})]})}function Cn({step:e,count:s}){if(s<2)return null;const n=e.fanOut==="parallel",o=ho(s,n?"parallel":"sequential");return t.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":o,title:o,children:[t.jsx("span",{"aria-hidden":"true",children:n?"⇉":"→"})," ",s]})}function Nn({step:e}){const s=Xe(e),n=Pe(e);return!s&&!n?null:t.jsxs("div",{children:[n&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":Bs,title:Bs,children:[t.jsx(je.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":Vs,title:Vs,children:[t.jsx(je.Icon,{name:"pause",size:11})," Paused"]})]})}function kn(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(r.stepProblemTooltip).join(`
3
- `)}}function En({problems:e}){if(!e||e.length===0)return null;const s=e.map(r.stepProblemTooltip).join(`
4
- `);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(je.Icon,{name:"warning",size:12})})}function hr(e){const s=r.useW6WApi(),n=e.uses.action,[o,a]=p.useState(null),c=e.uses.trigger===!0,l=e.uses.app;return p.useEffect(()=>{if(!c||!s.getAppTriggers)return;let u=!1;return s.getAppTriggers(l).then(f=>{var m;return!u&&a(((m=f.find(w=>w.key===n))==null?void 0:m.title)??null)}).catch(()=>{}),()=>{u=!0}},[s,l,n,c]),o||n}function gr(e){const s=r.useW6WApi(),n=s.listSubscriptionsForWorkflow,o=s.retrySubscriptionRegistration,a=e.id,c=[...tr(e.nodes),...(e.nodes??[]).filter(I=>{var A;return((A=I.uses)==null?void 0:A.app)===r.WEBHOOK_APP&&I.uses.trigger!==!0})],l=c.length>0,u=c.map(I=>`${I.id}:${I.uses.app}:${I.uses.action}:${r.connectionIdFor(I,e.connections)??""}`).join("|"),[f,m]=p.useState([]),w=p.useMemo(()=>er(f),[f]),[x,S]=p.useState(0);p.useEffect(()=>{if(!n||!l){m([]);return}let I=!1;return n.call(s,a).then(A=>!I&&m(A)).catch(()=>{}),()=>{I=!0}},[s,n,a,l,u,x]);const k=p.useMemo(()=>o?async I=>{try{await o.call(s,I)}finally{S(A=>A+1)}}:void 0,[s,o]);return p.useMemo(()=>({byNode:w,subs:f,retry:k}),[w,f,k])}function mr({nodeId:e}){const{byNode:s,retry:n}=p.useContext(wn),[o,a]=p.useState(!1),c=s.get(e),l=Qo(c,n!==void 0);return!c||!l?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":c.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&&n&&t.jsx("button",{type:"button",className:"nodrag",disabled:o,onClick:()=>{a(!0),n(c.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function wr({id:e,data:s,selected:n}){const o=s.step,c=p.useContext(ns).get(o.uses.app),l=(c==null?void 0:c.displayName)||o.uses.app||"—",u=r.isTriggerStep(o.uses),f=hr(o),m=o.uses.trigger?`${l} · ${f}`:l,w=r.nodePortsForStep(o,p.useContext(es)),x=gn(s.stepStatus??"no-run",s.runStatus),S=t.jsx(Cn,{step:o,count:p.useContext(ts).get(e)??0}),k=vn(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",Pe(o)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:k,"data-disabled":Pe(o)||void 0,"data-paused":Xe(o)||void 0,children:[t.jsx(Sn,{id:e,step:o,runnable:!0}),t.jsxs("div",{className:u?"w6w-node-trigger":void 0,"data-node-kind":u?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...kn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${x.borderWidth}px ${x.borderStyle} ${n?"var(--w6w-accent)":x.borderColor}`,opacity:Pe(o)?.45:n?1:x.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...u?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(En,{problems:s.stepProblems}),w.in>0&&t.jsx(We,{type:"target",position:X.Position.Left,multiple:w.in>1}),t.jsx(r.AppIcon,{src:c==null?void 0:c.iconSvg,srcDark:c==null?void 0:c.iconSvgDark,brandColor:c==null?void 0:c.brandColor,name:l,size:28}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:m}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:o.uses.action||"—"})})]}),w.out>0&&t.jsxs(t.Fragment,{children:[t.jsx(We,{type:"source",position:X.Position.Right,multiple:w.out>1}),!u&&t.jsx(We,{type:"source",position:X.Position.Bottom,multiple:!1,id:r.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,t.jsx(Nn,{step:o}),u&&o.uses.trigger===!0&&t.jsx(mr,{nodeId:e}),s.loopOf&&t.jsx(jn,{id:e}),t.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[o.id,c!=null&&c.version?` - v${c.version}`:""]}),o.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:o.notes,children:o.notes})]})}function xr({id:e,data:s,selected:n}){const o=s.step,a=r.routesForStep(o),c=o.uses.app===r.ROUTER_APP,l=r.isIfStep(o),u=a.length?r.routerPortLayout(a):l?r.ifPortLayout():void 0,f=JSON.stringify(a.map(N=>N.id)),m=X.useUpdateNodeInternals();p.useEffect(()=>{m(e)},[e,f,m]);const w=r.internalNodeLabel(o.uses.app,o.uses.action),x=r.internalNodeIcon(o.uses.app,o.uses.action),S=r.nodePortsForStep(o,p.useContext(es)),k=r.isTriggerStep(o.uses),I=fr(o),A=gn(s.stepStatus??"no-run",s.runStatus),g=t.jsx(Cn,{step:o,count:p.useContext(ts).get(e)??0}),$=vn(e);return t.jsxs("div",{className:[I?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",Pe(o)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:$,"data-disabled":Pe(o)||void 0,"data-paused":Xe(o)||void 0,children:[t.jsx(Sn,{id:e,step:o,runnable:!r.isControlApp(o.uses.app)}),t.jsxs("div",{className:k?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":k?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...kn(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${A.borderWidth}px ${A.borderStyle} ${n?"var(--w6w-accent)":A.borderColor}`,opacity:Pe(o)?.45:n?1:A.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...k?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...u!=null&&u.minHeight?{minHeight:u.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(En,{problems:s.stepProblems}),S.in>0&&t.jsx(We,{type:"target",position:X.Position.Left,multiple:S.in>1}),x&&t.jsx(r.InternalIcon,{icon:x}),t.jsxs("div",{style:{minWidth:0,textAlign:"left"},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:o.uses.action||"—"})})]}),I&&t.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[t.jsx("span",{children:"Each item"}),t.jsx("span",{children:"Done"})]}),!!(u!=null&&u.right.length)&&t.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${u.right.length}, 1fr)`},"aria-hidden":"true",children:u.right.map(N=>t.jsx("span",{title:N.label,children:N.label},N.id))}),S.out>0&&t.jsxs(t.Fragment,{children:[I&&t.jsx(We,{type:"source",position:X.Position.Right,multiple:!1,id:r.EACH_SOURCE_HANDLE,variant:"each"}),u?t.jsxs(t.Fragment,{children:[u.right.map(N=>t.jsx(We,{type:"source",position:X.Position.Right,multiple:!1,id:N.handleId,top:N.top,routeLabel:N.label},N.id)),u.bottom&&t.jsxs(t.Fragment,{children:[t.jsx(We,{type:"source",position:X.Position.Bottom,multiple:!1,id:u.bottom.handleId,routeLabel:u.bottom.label}),t.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:u.bottom.label})]})]}):t.jsx(We,{type:"source",position:X.Position.Right,multiple:S.out>1,id:I?r.routeHandle(r.FOREACH_DONE_ROUTE):void 0}),!k&&!c&&!l&&o.uses.app!==r.RACE_APP&&t.jsx(We,{type:"source",position:X.Position.Bottom,multiple:!1,id:r.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),g,t.jsx(Nn,{step:o}),s.loopOf&&t.jsx(jn,{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:o.id}),o.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:o.notes,children:o.notes})]})}function br(e,s){var l,u;if(!s)return e;const n={...(e==null?void 0:e.steps)??{}};let o=!1;for(const[f,m]of Object.entries(s)){const w=/^nodes\.([^.]+)\.output$/.exec(f);!w||((l=n[w[1]])==null?void 0:l.output)!==void 0||(n[w[1]]={...n[w[1]]??{},output:m},o=!0)}const a=s["trigger.event"],c=a!==void 0&&((u=e==null?void 0:e.trigger)==null?void 0:u.event)===void 0;return!o&&!c?e:{...e??{},...o?{steps:n}:{},...c?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function yr(e){return t.jsx(jr,{...e})}function jr({workflowId:e,step:s,restoreVersion:n,upstreamSteps:o,loop:a,onChange:c,onClose:l,readOnly:u,initialView:f="props",fanOutCount:m=0,stateOutputFields:w,onTestRun:x,stepProblems:S,otherStepIds:k}){var Qe,pt;const I=r.useW6WApi(),A=p.useContext(ns),[g,$]=p.useState(s),N=r.useWorkflowConnections(),H=r.connectionIdFor(g,N==null?void 0:N.connections),J={...g,uses:{...g.uses,connection:H}},P=g.uses.connectionRef!==void 0&&!H||r.isConnectionBlocked(J,S),F=S==null?void 0:S.find(E=>E.code==="unknown_connection"&&E.connection===H),O=(S??[]).filter(E=>"fix"in E),[D,y]=p.useState(P?"setup":"configure"),[L,me]=p.useState(f==="json"?"code":f==="settings"?"config":"props"),[pe,Ie]=p.useState("props"),[ne,T]=p.useState(()=>r.stepToJson(s)),[G,Re]=p.useState("{}"),we=p.useRef(null),[xe,Z]=p.useState(!1),_=p.useRef(n);p.useEffect(()=>{_.current!==n&&(_.current=n,$(s),T(r.stepToJson(s)))},[n,s]);const[Y,te]=p.useState(null),[be,He]=p.useState(null),[At,Ee]=p.useState(null),[ot,le]=p.useState(!1),re=r.isInternalApp(g.uses.app),ve=g.uses.trigger===!0;p.useEffect(()=>{if(re){te(r.internalNodeParams(g.uses.app,g.uses.action));const B=r.INTERNAL_NODES.filter(U=>U.app===g.uses.app&&U.groupActions&&!U.hidden);He(B.length?B.map(U=>({key:U.action,title:U.label,params:U.params})):null);return}if(!g.uses.app){He(null),te([]);return}let E=!1;return te(null),(ve?r.getTriggerDefs(I,g.uses.app):I.getAppActions(g.uses.app)).then(B=>{var U;E||(He(B),te(g.uses.action?((U=B.find(de=>de.key===g.uses.action))==null?void 0:U.params)??[]:[]))}).catch(()=>!E&&te([])),()=>{E=!0}},[I,g.uses.app,g.uses.action,re,ve]);const $e=p.useRef(0);p.useEffect(()=>()=>{$e.current++},[]);const ie=p.useCallback(()=>{re||!g.uses.app||I.listConnectionsForApp(g.uses.app).then(E=>{Ee(E),le(!1)}).catch(()=>le(!0))},[I,g.uses.app,re]);p.useEffect(()=>{if(re||!g.uses.app)return;let E=!1;return Ee(null),le(!1),I.listConnectionsForApp(g.uses.app).then(B=>{E||(Ee(B),le(!1))}).catch(()=>!E&&le(!0)),()=>{E=!0}},[I,g.uses.app,re]);const K=p.useCallback(E=>{$(E),c(E)},[c]),Ve=ao({enabled:g.uses.app===r.SCRIPT_APP&&!u,values:g.with??{},onChange:E=>K({...g,with:E})}),Me=E=>{E==="code"&&T(r.stepToJson(g)),me(E)},dt=E=>{const B=r.stepNameError(E,k??[]);return B||K({...g,id:E}),B},z=!!g.uses.app&&!!g.uses.action&&!r.isControlApp(g.uses.app),ae=r.isForeachStep(g),Se=r.isTriggerStep(g.uses),rt=D==="test"&&z&&!Se,Fe=r.useSeedSources(e,o,z&&!Se||ae),Le=xn(z&&!Se?a:void 0),Ce=r.startStateFromSeeds(Fe,bn(Le)),Ye=br(Ce,r.useExpressionOptions().sampleValues),fe=r.useRememberedTestInput(z&&!Se||ae?e:void 0,g.id),[De,Ze]=p.useState(!1);p.useEffect(()=>{if((!z||Se)&&!ae||!fe.loaded)return;if(!ae&&fe.input!==void 0){const B=fe.input;if(Object.keys(B).length===0)return;const U=JSON.stringify(B,null,2);Re(de=>de.trim()==="{}"?U:de),Ze(!0);return}let E=!1;return I.listStepTests(e,g.id).then(B=>{if(E)return;const U=B.length?B[B.length-1]:null;if(!(U!=null&&U.input)||Object.keys(U.input).length===0)return;const de=JSON.stringify(U.input,null,2);Re(Je=>Je.trim()==="{}"?de:Je)}).catch(()=>{}),()=>{E=!0}},[I,e,g.id,z,Se,ae,fe.loaded]);const Ne=ae?dr(G):Tt(G),oe={...g.with??{},...Ne??{}},Te=Ne??{},ke=!!Y&&!rs(Le)&&r.requiredParamsFilled(Y,oe),ye=ae?r.resolveLoopItemsInState(oe.items,Ce):void 0,[it,Be]=p.useState("idle"),Q=E=>{Re(E),Be("idle")},Pt=async()=>{if(ye){Be("saving");try{await I.saveStepTest(e,g.id,r.foreachTestFixture(ye,Te)),Be("saved")}catch{Be("failed")}}},se=A.get(g.uses.app),Ae=re?r.internalNodeIcon(g.uses.app,g.uses.action):null,ut=re?Ae?t.jsx(r.InternalIcon,{icon:Ae}):null:t.jsx(r.AppIcon,{src:se==null?void 0:se.iconSvg,srcDark:se==null?void 0:se.iconSvgDark,brandColor:se==null?void 0:se.brandColor,name:se==null?void 0:se.displayName});return t.jsx(r.Modal,{ariaLabel:"Edit step",titleIcon:ut,title:t.jsx(r.StepNameEditor,{value:g.id,onCommit:dt,readOnly:u}),onClose: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(E=>g.uses.app!==r.RACE_APP||E!=="test").map(E=>t.jsx("button",{type:"button",className:`w6w-subtab${D===E?" active":""}`,disabled:P&&E!=="setup",onClick:()=>y(E),children:E==="setup"?"Setup":E==="configure"?"Configure":"Test"},E))}),rt?t.jsx(r.ConfigViewToggle,{view:pe,views:["props","code"],onChange:E=>Ie(E)}):t.jsx(r.ConfigViewToggle,{view:L,customized:r.hasParamCustomization(g.with??{}),onChange:Me,disabled:D!=="configure"})]}),P&&F&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",F.connection," no longer exists — choose another to continue."]}),O.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:O.map(E=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:r.stepProblemTooltip(E)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":E.code,disabled:u,onClick:()=>{const B=hn(g,E);K(B),T(r.stepToJson(B))},children:"fix"in E?E.fix.label:""})]},E.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[D==="setup"&&t.jsx(kr,{step:g,app:se,actions:be,conns:At,connsFailed:ot,isInternal:re,actionLabel:ve?"Trigger":"Action",readOnly:u,onChangeAction:E=>{var U;const B=re?r.internalNodeDefaults(g.uses.app,E):{};if(re)for(const de of r.internalNodeParams(g.uses.app,E))de.key in(g.with??{})&&(B[de.key]=(U=g.with)==null?void 0:U[de.key]);K({...g,uses:{...g.uses,action:E},with:B})},onChangeTriggerEvents:(E,B)=>K({...g,uses:{...g.uses,action:E},with:{...g.with,actions:B}}),onChangeConnection:E=>{if(!N){const{connectionRef:U,...de}=g.uses;K({...g,uses:{...de,connection:E}});return}const B=r.selectNodeConnection(g,E,(N==null?void 0:N.nodes)??[g],(N==null?void 0:N.connections)??{});N==null||N.setConnections(B.connections),K(B.step)},onChangeConnectionRef:E=>K(r.withConnectionRef(g,E)),onConnectionCreated:ie,onChangeApp:E=>{const B=++$e.current;if(E===g.uses.app){K(g);return}const U={...g,uses:{app:E,action:"",...ve?{trigger:!0}:{}},with:{}};(r.isInternalApp(E)?Promise.resolve([]):I.listConnectionsForApp(E)).catch(()=>[]).then(de=>{if(B!==$e.current)return;const Je=r.defaultConnectionFor(U,de,(N==null?void 0:N.nodes)??[],(N==null?void 0:N.connections)??{});K({...U,uses:{...U.uses,...Je}})})}}),D==="configure"&&t.jsxs(t.Fragment,{children:[g.uses.app===r.WEBHOOK_APP&&I.listSubscriptionsForWorkflow&&I.createSubscription&&t.jsx(Nr,{workflowId:e,step:g,readOnly:u}),Y===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):L==="props"?g.uses.app===r.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:r.RACE_DESCRIPTION}):g.uses.action==="wait"&&r.isControlApp(g.uses.app)?t.jsx(r.WaitEditor,{values:g.with??{},readOnly:u,onChange:E=>K({...g,with:E})}):g.uses.action==="if"&&r.isControlApp(g.uses.app)?t.jsx(r.ConditionEditor,{values:g.with??{},readOnly:u,onChange:E=>K({...g,with:E})}):g.uses.app==="@w6w/stop"?t.jsx(r.StopEditor,{values:g.with??{},readOnly:u,onChange:E=>K({...g,with:E})}):g.uses.app===r.ROUTER_APP?t.jsx(r.RouterEditor,{values:g.with??{},readOnly:u,onChange:E=>K({...g,with:E})}):t.jsxs(t.Fragment,{children:[g.uses.app===r.SCRIPT_APP&&t.jsx(co,{values:g.with??{},conversion:Ve,readOnly:u}),t.jsx(r.ParamsForm,{params:Y,values:g.with??{},readOnly:u,onChange:E=>K({...g,with:E}),dynamic:re||!g.uses.action?void 0:{appId:g.uses.app,actionKey:g.uses.action,connectionId:P?void 0:H,appName:se==null?void 0:se.displayName}})]}):L==="code"?t.jsx(r.JsonEditor,{value:ne,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${g.id} JSON`,copyable:!0}):L==="params-code"?t.jsx(r.ParamCustomization,{values:g.with??{},onChange:E=>K({...g,with:E}),readOnly:u}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(r.NodeConfigForm,{config:{retry:g.retry,onError:g.onError,notes:g.notes},onChange:E=>K({...g,...E}),readOnly:u,failureHandling:!Se,retryControls:!r.isControlApp(g.uses.app)&&g.uses.app!==r.CALL_APP}),vr,t.jsx(Sr,{step:g,count:m,readOnly:u,onChange:K}),$o(g)&&t.jsx(Cr,{step:g,inLoop:a!==void 0,outputFields:w,readOnly:u,onChange:K})]})]}),D==="test"&&t.jsx("div",{className:"w6w-stack",children:z?ve?t.jsx(r.AppTriggerTestNote,{title:((Qe=be==null?void 0:be.find(E=>E.key===g.uses.action))==null?void 0:Qe.title)??g.uses.action,app:(se==null?void 0:se.displayName)??g.uses.app}):Se?t.jsx(r.TriggerFillForm,{app:g.uses.app,action:g.uses.action,fields:(pt=g.with)==null?void 0:pt.fields,persist:{workflowId:e,stepId:g.id,input:Te},listen:g.uses.app===r.WEBHOOK_APP&&I.listSubscriptionsForWorkflow&&I.startWebhookListen?{stepWith:g.with,readOnly:u}:void 0}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",t.jsx("code",{children:g.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),t.jsx(yn,{seed:Le,readOnly:u}),De&&!u&&t.jsx(r.LastUsedNote,{onClear:()=>{fe.clear(),Ze(!1),Re("{}")}}),t.jsx(Yt,{text:G,onChange:Re,seeds:Fe,readOnly:u}),Y===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(so,{params:Y,values:oe,testStartState:Ye,view:pe,literalKeys:g.uses.app===r.SCRIPT_APP?lr:void 0}),t.jsx(r.StepTestRun,{ref:we,app:g.uses.app,action:g.uses.action,connectionId:H,values:oe,state:Ce,canRun:ke,hideRunButton:!0,persist:{workflowId:e,stepId:g.id,input:Te},onBusyChange:Z})]}):ae?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(Yt,{text:G,onChange:Q,seeds:Fe,readOnly:u,expand:!ye,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(ur,{items:ye,save:it})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),t.jsx("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:g.uses.app===r.RACE_APP&&D==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):D!=="test"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:P,onClick:()=>y(D==="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"}),z&&!Se&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:u||!ke||xe,onClick:()=>{var E;x==null||x(),(E=we.current)==null||E.run()},children:xe?"Testing…":"Test"}),ae&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:u||!(ye!=null&&ye.length)||it==="saving",onClick:()=>void Pt(),children:it==="saving"?"Testing…":"Test"})]})})]})})}const vr=!1;function Sr({step:e,count:s,readOnly:n,onChange:o}){const a=s>=2,c=e.fanOut==="parallel"?"parallel":"sequential";return t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Run next nodes"}),t.jsxs("select",{"aria-label":"Run next nodes",value:c,disabled:n||!a,onChange:l=>o(fo(e,l.target.value)),children:[t.jsx("option",{value:"sequential",children:"In sequence"}),t.jsx("option",{value:"parallel",children:"In parallel"})]}),!a&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function Zs({to:e}){return t.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[t.jsx("span",{children:"From this step output"}),t.jsx("span",{}),t.jsx("span",{children:e})]})}function Qs(){return t.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function en({label:e,fields:s,value:n,readOnly:o,onChange:a}){const c=p.useMemo(()=>(s??[]).map(l=>({value:l,label:l})),[s]);return t.jsx(r.Combobox,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:c,value:n,disabled:o,emptyText:c.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:a})}function Cr({step:e,inLoop:s,outputFields:n,readOnly:o,onChange:a}){const c=Do(e),l=ge.validateStateConfig(c),u=x=>a(_o(e,x)),f=c.mode==="pick"&&Array.isArray(c.map)?c.map:[],m=(x,S)=>u({mode:"pick",map:f.map((k,I)=>I===x?{...k,...S}:k)}),w=x=>{if(c.mode!=="append")return;const S=x.path??c.path,k="from"in x?x.from:c.from;u({mode:"append",path:S,...k?{from:k}:{}})};return t.jsxs("div",{className:"w6w-field w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Write to state"}),t.jsx("select",{"aria-label":"Write to state",value:c.mode,disabled:o,onChange:x=>u(Wo(e,x.target.value)),children:Fo.map(x=>t.jsx("option",{value:x,children:Lo[x]},x))})]}),c.mode==="key"&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"To state key"}),t.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:c.key,disabled:o,onChange:x=>u({mode:"key",key:x.target.value})}),t.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",t.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",t.jsx("code",{children:"order.id"})," nests."]})]}),c.mode==="pick"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(Zs,{to:"To state key"}),f.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),f.map((x,S)=>t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(en,{label:"From output field",fields:n,value:x.from,readOnly:o,onChange:k=>m(S,{from:k})}),t.jsx(Qs,{}),t.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:x.to,disabled:o,onChange:k=>m(S,{to:k.target.value})}),!o&&t.jsx(r.DeleteButton,{label:"Remove field",onClick:()=>u({mode:"pick",map:f.filter((k,I)=>I!==S)})})]},S)),!o&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>u({mode:"pick",map:[...f,{from:"",to:""}]}),children:"+ Add field"}),t.jsxs("span",{className:"w6w-hint",children:["Copies ",t.jsx("code",{children:"output.<path>"})," into ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),c.mode==="append"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(Zs,{to:"Append to state list"}),t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(en,{label:"Output field to append",fields:n,value:c.from??"",readOnly:o,onChange:x=>w({from:x})}),t.jsx(Qs,{}),t.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:c.path,disabled:o,onChange:x=>w({path:x.target.value})})]}),t.jsxs("span",{className:"w6w-hint",children:["Appends ",t.jsx("code",{children:"output.<path>"})," to the list at ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),l.length>0&&t.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:l.map(x=>t.jsx("div",{children:x.message},`${x.code}:${x.message}`))}),c.mode!=="off"&&t.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",t.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),s&&t.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function Nr({workflowId:e,step:s,readOnly:n}){const o=r.useW6WApi(),[a,c]=p.useState(void 0),[l,u]=p.useState(null),[f,m]=p.useState(!1);p.useEffect(()=>{const x=o.listSubscriptionsForWorkflow;if(!x)return;let S=!1;return x(e).then(k=>{S||c(r.pickWebhookSubscription(k,s.id))}).catch(k=>!S&&u(k.message)),()=>{S=!0}},[o,e,s.id]);const w=()=>{const x=o.createSubscription;x&&(u(null),m(!0),x(r.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(S=>{m(!1),c(S)}).catch(S=>{m(!1),u(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(je.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…"}):!n&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:w,children:f?"Creating…":"Create webhook URL"})]})}function kr({step:e,app:s,actions:n,conns:o,connsFailed:a,isInternal:c,actionLabel:l="Action",readOnly:u,onChangeAction:f,onChangeTriggerEvents:m,onChangeConnection:w,onChangeConnectionRef:x,onChangeApp:S,onConnectionCreated:k}){const I=e.uses.trigger?r.eventbriteTriggerChoices(e.uses.app,n,e.uses.action,e.with??{}):null,[A,g]=p.useState(null),$=p.useRef(null),N=r.useWorkflowConnections(),H=r.connectionIdFor(e,N==null?void 0:N.connections);return t.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!H&&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:$,children:[t.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":A==="app",disabled:u,onClick:()=>g(J=>J==="app"?null:"app"),children:[!c&&s&&t.jsx(r.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:c?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!c&&t.jsx(r.WorkflowConnectionPicker,{step:e,conns:o,failed:a,readOnly:u,open:A==="conn",onOpenChange:J=>g(J?"conn":null),anchorRef:$,onChangeConnection:w,onChangeConnectionRef:x,onConnectionCreated:k})]}),A==="app"&&t.jsx(r.AnchoredFlyout,{anchorRef:$,onClose:()=>g(null),children:t.jsx(r.AppPicker,{onSelectApp:J=>{const v=J.id===e.uses.app;S(J.id),g(v?"conn":null)}})})]}),c&&!(n!=null&&n.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})})]}):I?t.jsx(r.EventbriteTriggerPicker,{choices:I,readOnly:u,onChange:J=>m(I.triggerKey,J)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:l}),t.jsx(r.Combobox,{value:e.uses.action,disabled:u||n===null,onChange:f,options:n===null?[{value:e.uses.action,label:e.uses.action}]:n.map(J=>({value:J.key,label:J.title??J.key}))})]})]})}exports.CALL_APP=r.CALL_APP;exports.CONTROL_APP=r.CONTROL_APP;exports.CanvasLayer=r.CanvasLayer;exports.DATA_APP=r.DATA_APP;exports.ExpressionOptionsProvider=r.ExpressionOptionsProvider;exports.INTERNAL_NODES=r.INTERNAL_NODES;exports.Markdown=r.Markdown;exports.RACE_APP=r.RACE_APP;exports.SCHEDULER_APP=r.SCHEDULER_APP;exports.SCRIPT_APP=r.SCRIPT_APP;exports.TRIGGER_APP=r.TRIGGER_APP;exports.WEBHOOK_APP=r.WEBHOOK_APP;exports.asFieldDefs=r.asFieldDefs;exports.centralizeConnections=r.centralizeConnections;exports.coerceDefault=r.coerceDefault;exports.connectionIdFor=r.connectionIdFor;exports.fieldWidget=r.fieldWidget;exports.fieldsToParams=r.fieldsToParams;exports.flowToWorkflow=r.flowToWorkflow;exports.internalNodeDefaults=r.internalNodeDefaults;exports.internalNodeIcon=r.internalNodeIcon;exports.internalNodeLabel=r.internalNodeLabel;exports.internalNodeParams=r.internalNodeParams;exports.isControlApp=r.isControlApp;exports.isInternalApp=r.isInternalApp;exports.isTriggerApp=r.isTriggerApp;exports.isTriggerStep=r.isTriggerStep;exports.seedValues=r.seedValues;exports.workflowToFlow=r.workflowToFlow;exports.MAX_NOTES=tn;exports.MAX_NOTE_BYTES=nn;exports.MAX_SECTIONS=sn;exports.WorkflowFlowEditor=ar;exports.applyStepProblemFix=hn;exports.assignMembership=Ut;exports.clampCanvas=qt;exports.findLoopProblems=Ao;exports.findStateWriteProblems=Ro;exports.isDisabledStep=Pe;exports.isPausedStep=Xe;exports.pausedStopAt=Kt;exports.pruneSectionMembers=Zt;exports.renameSectionMember=rn;exports.roundGeometry=Jt;exports.sectionsContaining=an;exports.withCanvasGeometry=on;exports.withDisabled=pn;exports.withPaused=un;
1
+ "use client";"use strict";var no=Object.defineProperty;var oo=(e,s,o)=>s in e?no(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o;var it=(e,s,o)=>oo(e,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),be=require("@w6w/expr"),oe=require("@xyflow/react"),d=require("react"),i=require("./connection-app-meta-BEXlKBgV.cjs"),ye=require("./CodeBlock-CymlfyeA.cjs");function io({x:e,y:s,items:o,onAction:n,onClose:a}){const c=d.useRef(null),[l,p]=d.useState({left:e,top:s});d.useLayoutEffect(()=>{const g=c.current,x=g==null?void 0:g.offsetParent;if(!g||!x)return;const f=g.offsetWidth,v=g.offsetHeight;p({left:e+f>x.clientWidth?Math.max(0,e-f):e,top:s+v>x.clientHeight?Math.max(0,s-v):s})},[e,s]),d.useEffect(()=>{var g,x;(x=(g=c.current)==null?void 0:g.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),d.useEffect(()=>{const g=v=>{var S;(S=c.current)!=null&&S.contains(v.target)||a(!1)},x=v=>{var S;(S=c.current)!=null&&S.contains(v.target)||a(!1)},f=()=>a(!1);return document.addEventListener("pointerdown",g,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",f),window.addEventListener("resize",f),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",f),window.removeEventListener("resize",f)}},[a]);const h=g=>{g.disabled||(a(!1),n(g.action))};return t.jsx("div",{ref:c,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:g=>g.preventDefault(),onKeyDown:g=>{var S;g.stopPropagation();const x=[...((S=c.current)==null?void 0:S.querySelectorAll("[role=menuitem]"))??[]],f=x.indexOf(document.activeElement),v=I=>{var L;return(L=x[(I+x.length)%x.length])==null?void 0:L.focus()};if(g.key==="ArrowDown")v(f+1);else if(g.key==="ArrowUp")v(f<0?-1:f-1);else if(g.key==="Home")v(0);else if(g.key==="End")v(-1);else if(g.key==="Escape"||g.key==="Tab")a(!0);else if(g.key==="Enter"||g.key===" ")f>=0&&h(o[f]);else return;g.preventDefault()},children:o.map(g=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":g.disabled||void 0,className:`w6w-note-menu-item${g.danger?" danger":""}${g.separated?" separated":""}`,"data-action":g.action,onClick:()=>h(g),children:g.label},g.action))})}function ro(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function ao(e,s){const o=[],n=e.length;if(n>0){const a=n>1?` ${n} nodes`:"";o.push({action:"duplicate",label:`Duplicate${a}`,disabled:s}),o.push({action:"delete",label:`Delete${a}`,disabled:s,danger:!0})}return o.push({action:"add-node",label:"Add node",disabled:s,separated:n>0}),o.push({action:"add-trigger",label:"Add trigger",disabled:s}),o}const dn=200,un=200,pn=10240;function Gt(e){const s={};for(const[o,n]of Object.entries(e))s[o]=Math.round(n);return s}const co=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),lo=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function zs(e,s,o){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],c=co(a==null?void 0:a.position)?a.position:n.position,l=lo(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Gt(c),size:Gt(l)}})}function fn(e,s,o){if(!s)return e;const n={...e};return e.notes&&(n.notes=zs(e.notes,o)),e.sections&&(n.sections=zs(e.sections,o)),n}function ts(e,s){return e.sections?{...e,sections:e.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:e}function hn(e,s,o){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?o:a)}))}:e}function Kt(e,s,o){if(!e.sections)return e;const n=new Set(o);return{...e,sections:e.sections.map(a=>{const c=a.nodes.filter(l=>!n.has(l));return a.id===s?{...a,nodes:[...new Set([...c,...o])]}:{...a,nodes:c}})}}function mn(e,s){return(e.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function uo(e,s){const o=new TextEncoder;if(o.encode(e).length<=s)return e;let n="",a=0;for(const c of e){const l=o.encode(c).length;if(a+l>s)break;n+=c,a+=l}return n}function Xt(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,dn).map(o=>({...o,content:uo(o.content,pn)}))),e.sections&&(s.sections=e.sections.slice(0,un)),s}function po(e,s,o){const n={};for(const l of[...e.notes??[],...e.sections??[]])n[l.id]={position:l.position,size:l.size};const a=(l,p)=>l==null?void 0:l.map(h=>{const g=p==null?void 0:p.find(x=>x.id===h.id);return g?{...h,position:g.position,size:g.size}:h}),c=o?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 fn(c,o,n)}const Hs=220;function fo(e){return e.length<=Hs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Hs).trimEnd(),clipped:!0,length:e.length}}function ho({params:e,values:s,testStartState:o,view:n="props",literalKeys:a}){const{sampleValues:c,nodeConfig:l,nodeMeta:p}=i.useExpressionOptions(),h=d.useMemo(()=>i.buildResolveScope(c,o,l,p),[c,o,l,p]),g=i.flattenParams(e),x=S=>{var I;return s[S]!==void 0?s[S]:(I=g.find(L=>L.key===S))==null?void 0:I.default},f=g.filter(S=>S.type!=="section"&&i.isParamVisible(S,x)).map(S=>be.effectiveParam(S,x));if(i.hasParamCustomization(s)){const S=i.previewCustomization(s.$merge,h,a),I=S!==null&&typeof S=="object"&&!Array.isArray(S),L=Js(f,s,h,a);for(const[B,N]of Object.entries(s))B!=="$merge"&&(L[B]=a!=null&&a.includes(B)?N:i.previewCustomization(N,h));const m=I?{...L,...S}:L;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:I?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(S)}). Test the step to validate it.`}),n==="code"?t.jsx(i.JsonEditor,{value:JSON.stringify(m,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(m).map(([B,N])=>{var z;return t.jsx(Yt,{label:((z=g.find(H=>H.key===B))==null?void 0:z.label)??B,segments:[{status:"resolved",value:N}]},B)})})]})}if(n==="code"){const S=Js(f,s,h,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(i.JsonEditor,{value:JSON.stringify(S,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const v=f.filter(S=>!i.deepEqual(x(S.key),S.default));return f.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):v.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:v.map(S=>S.type==="vars"?t.jsx(mo,{param:S,value:s[S.key],scope:h},S.key):t.jsx(Yt,{label:S.label??S.key,segments:a!=null&&a.includes(S.key)?[{status:"resolved",value:x(S.key)}]:i.resolveParamValue(x(S.key),h)},S.key))})}function Js(e,s,o,n){const a={};for(const c of e)if(n!=null&&n.includes(c.key))a[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],p=i.dataVarRows(l);a[c.key]=p?i.resolveVarsJson(p,o):i.resolveParamJson(l,o)}else a[c.key]=i.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,o);return a}function Yt({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(wn,{segments:s})})]})}function mo({param:e,value:s,scope:o}){const n=s??e.default??[],a=i.dataVarRows(n);return a===null?t.jsx(Yt,{label:e.label??e.key,segments:i.resolveParamValue(n,o)}):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((c,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:c.key||"(no key)"})," → ",t.jsx(wn,{segments:i.resolveParamValue(c.value,o)})]},l))})]})}function wn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,o)=>t.jsx(wo,{segment:s},o))})}function wo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(dt,{kind:"var",refName:e.ref}),t.jsx(Us,{value:e.value})]}):t.jsx(Us,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(dt,{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(dt,{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(dt,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(dt,{kind:"secret",refName:e.ref})}}function Us({value:e}){const[s,o]=d.useState(!1),n=xo(e),a=fo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(ye.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:()=>o(c=>!c),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const go={var:"◆",secret:"🔒",expr:"ƒ"};function dt({kind:e,refName:s}){const o=e==="expr"?"expr":i.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:go[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function xo(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 gn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function bo({enabled:e,values:s,onChange:o}){const[n,a]=d.useState(null),c=d.useRef(!1),l=typeof s.code=="string"?s.code:"";return d.useEffect(()=>{if(!e||c.current)return;c.current=!0;const p=i.convertCodeBindingsToReads(l,gn(s));p.converted!==0&&(a({original:l,converted:p.converted}),o({...s,code:p.code}))},[e,l,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),a(null)}}:null}function jo({values:e,conversion:s,readOnly:o}){const n=typeof e.code=="string"?e.code:"",a=s,c=i.findCodeBindings(n,gn(e)).length;return!a&&c===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",!o&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&t.jsxs(t.Fragment,{children:[c," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function qs(e,s){return{nodeIds:e.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function yo(e,s,o,n){const a=new Set(e.nodeIds),c=new Set(e.edgeIds),l=s.filter(f=>a.has(f.id)),p=[...l.filter(f=>i.isForeachStep(f.data.step)),...l.filter(f=>!i.isForeachStep(f.data.step))];let h=s,g=o,x=n;for(const f of p)g=i.bridgeDeletedBodyStep(f.id,h,g),h=h.filter(v=>v.id!==f.id),x=ts(x,f.id);return{nodes:h,edges:g.filter(f=>!c.has(f.id)),canvas:x}}function vo(e,s,o){var p;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),c=o.filter(h=>a.has(h.id)&&!n.has(h.source)&&!n.has(h.target)),l=[];if(n.size===1)l.push(i.deleteStepMessage(e.nodeIds[0],s,o));else if(n.size>1){l.push(`Delete nodes ${[...n].map(g=>`"${g}"`).join(", ")}? Their connections are removed too.`);const h=new Set;for(const g of n)if(i.isForeachStep((p=s.find(x=>x.id===g))==null?void 0:p.data.step))for(const x of i.loopBody(g,s,o))n.has(x)||h.add(x);h.size&&l.push(`Loop body steps ${[...h].map(g=>`"${g}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(h=>`"${h.source} → ${h.target}"`).join(", ")}?`),l.join(" ")}function So(e,s){const o={success:0,error:0};for(const a of s){if(a.source!==e)continue;const c=i.edgeLane(a);c!=="each"&&o[c]++}const n=Math.max(o.success,o.error);return{enabled:n>=2,count:n}}function Co(e,s){const{fanOut:o,...n}=e;return s==="parallel"?{...n,fanOut:"parallel"}:n}function No(e,s){return`Runs these ${e} nodes in ${s==="parallel"?"parallel":"sequence"}`}function kt(e,s,o,n,a){const c=i.flowToWorkflow({...e,connections:n},s,o);return{nodes:c.nodes.map(({with:l,...p})=>l&&Object.keys(l).length?{...p,with:l}:p),edges:c.edges??[],connections:c.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function ko(e,s){const o=i.workflowToFlow({...e,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class Eo{constructor(s,o=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(this,"limit");this.limit=o,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,o){const n=JSON.stringify(s);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=[])}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 Ht(e){var o;const s=e;return!!(s!=null&&s.isContentEditable||(o=s==null?void 0:s.closest)!=null&&o.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Ao=64,ut=24,Ke=32;function Et(e){var s,o;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((o=e.measured)==null?void 0:o.height)??e.height??64}}function To(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 Io(e){const s=(a,c)=>{const l=new Map;for(const g of e){const x=g.position[a];l.set(x,Math.max(l.get(x)??0,Et(g)[c]))}const p=new Map;let h=Number.NEGATIVE_INFINITY;for(const[g,x]of[...l].sort(([f],[v])=>f-v)){const f=Math.max(g,h);p.set(g,f),h=f+x+Ao}return p},o=s("x","width"),n=s("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 Po(e,s,o){var p;const n=Io(i.relayoutNodes(e,s));if(!((p=o.sections)!=null&&p.length))return{nodes:n,canvas:o};const a=new Map(n.map(h=>[h.id,h])),c=(o.notes??[]).map(h=>({...h.position,...h.size}));for(const h of o.sections)h.nodes.some(g=>a.has(g))||c.push({...h.position,...h.size,y:h.position.y-Ke,height:h.size.height+Ke});const l=o.sections.map(h=>{const g=new Set(h.nodes),x=n.filter(N=>g.has(N.id));if(!x.length)return h;const f=Math.min(...x.map(N=>N.position.x))-ut,v=Math.min(...x.map(N=>N.position.y))-ut,S=Math.max(...x.map(N=>N.position.x+Et(N).width)),I=Math.max(...x.map(N=>N.position.y+Et(N).height)),L={x:f,y:v,width:S+ut-f,height:I+ut-v},m=[...c,...[...a.values()].filter(N=>!g.has(N.id)).map(N=>({...N.position,...Et(N)}))].sort((N,z)=>N.y-z.y);for(const N of m){const z={...L,y:L.y-Ke,height:L.height+Ke};To(z,N)&&(L.y=N.y+N.height+ut+Ke)}const B=L.y-v;for(const N of x)a.set(N.id,{...N,position:{x:N.position.x,y:N.position.y+B}});return c.push({...L,y:L.y-Ke,height:L.height+Ke}),{...h,position:{x:L.x,y:L.y},size:{width:L.width,height:L.height}}});return{nodes:n.map(h=>a.get(h.id)??h),canvas:{...o,sections:l}}}const Jt=6;function Ro(e){let s=2166136261;for(let o=0;o<e.length;o++)s^=e.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function Mo(e){const s=new Map;let o=new Set;for(const n of[...new Set(e)].sort()){o.size===Jt&&(o=new Set);let a=Ro(n)%Jt;for(;o.has(a);)a=(a+1)%Jt;o.add(a),s.set(n,a+1)}return s}function ss(e){return`var(--w6w-loop-${e})`}function xn(e,s){const o=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),o.unshift(a);return o}function Lo(e,s,o){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===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),c=a?s.get(a):void 0;return c===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":ss(c)}}})}function Fo(e,s){const o=s.get(e);return o===void 0?void 0:{"--w6w-loop-color":ss(o)}}function Do(e){const s=[];for(const o of e){const n=i.isForeachStep(o.data.step);(n||o.data.loopOf)&&s.push([o.id,n?1:0,o.data.loopOf])}return JSON.stringify(s)}function Oo(e){const s=JSON.parse(e);return{tones:Mo(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const Gs="Paused — test runs stop before this node",Ks="Disabled — skipped in every run";function Xe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function Ie(e){return e.disabled===!0}function bn(e,s){const{ui:o,...n}=e,{paused:a,...c}=o??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...n,ui:l}:n}function jn(e,s){const{disabled:o,...n}=e;return s?{...n,disabled:!0}:n}function Zt(e,s){return e.filter(o=>o.id!==s&&Xe(o)).map(o=>o.id)}const _o=["nodes","steps"];function Xs(e,s){for(const o of _o){const n=`${o}.${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 At(e,s,o){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=i.parseRootAnchoredTemplate(e);let a=!1;const c=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const p=Xs(l.ref,s);return p===null?l:(a=!0,o.includes(l.ref)||o.push(l.ref),{...l,ref:p})});return a?be.serializeTemplate(c):e}if(i.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=Xs(n,s);return a===null?e:(o.includes(n)||o.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(c=>{const l=At(c,s,o);return l!==c&&(n=!0),l});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[c,l]of Object.entries(e)){const p=At(l,s,o);p!==l&&(n=!0),a[c]=p}return n?a:e}return e}function Wo(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(e)&&typeof e.$=="string"}function yn(e){return Array.isArray(e)&&e.length===1&&Wo(e[0])}function $o(e){var s;try{const o=i.normalizeInput(e);if(!Array.isArray(o.nodes))return{};const n={},a=(l,p)=>{const h=Object.hasOwn(n,l)?n[l]:[];h.push(p),n[l]=h},c=new Map(o.nodes.map(l=>[l.id,l]));for(const[l,p]of Object.entries(i.definitionLoops(o))){const h=c.get(l);if(h&&yn((s=h.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in p){a(l,{code:"loop_body_invalid",reason:{...p.invalid}});continue}for(const g of p.body){const x=c.get(g);if(!(x!=null&&x.with))continue;const f=[];At(x.with,l,f),f.length>0&&a(g,{code:"foreach_body_refs_output",foreachId:l,refs:f,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function Bo(e){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)o(a)};return o(e),s}function Vo(e){var s,o;try{const n=i.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(C=>typeof C=="object"&&C!==null&&typeof C.id=="string"),c=i.effectiveEdges({...n,nodes:a}).filter(C=>typeof(C==null?void 0:C.from)=="string"&&typeof(C==null?void 0:C.to)=="string"),l=[];for(const C of a)try{const A=be.staticWritePaths(be.effectiveStateConfig((s=C.uses)==null?void 0:s.app,(o=C.uses)==null?void 0:o.action,C.state));A.length>0&&l.push({id:C.id,paths:A})}catch{}if(l.length<2)return[];const p=new Map;for(const C of a)for(const A of i.controlOwnedIds(C))p.has(A)||p.set(A,C.id);const h=C=>{const A=[C];let R=C;for(;p.has(R)&&(R=p.get(R),!A.includes(R));)A.push(R);return A},g=C=>{const A=h(C);return A[A.length-1]},x=new Map;for(const C of c){const A=x.get(C.from)??[];A.push(C.to),x.set(C.from,A)}const f=new Map,v=C=>{const A=f.get(C);if(A)return A;const R=new Set,W=[...x.get(C)??[]];for(;W.length>0;){const V=W.pop();if(!R.has(V)){R.add(V);for(const ee of x.get(V)??[])W.push(ee)}}return f.set(C,R),R},S=(C,A)=>C===A||v(C).has(A),I=a.filter(C=>{var A;return((A=C.uses)==null?void 0:A.app)===i.CONTROL_APP&&C.uses.action==="parallel"}).map(C=>{var R;const A=(R=C.with)==null?void 0:R.branches;return Array.isArray(A)?A.map(Bo):[]}),L=(C,A)=>{for(const R of h(A)){const W=C.findIndex(V=>V.has(R));if(W>=0)return W}return-1},m=[];for(const C of a){if(C.fanOut!=="parallel")continue;const A=new Map;for(const R of c){if(R.from!==C.id||i.isEachLink(R))continue;const W=R.when??"success",V=A.get(W)??[];V.push(R.to),A.set(W,V)}for(const R of A.values())R.length>=2&&m.push(R)}const B=(C,A)=>{for(const V of I){const ee=L(V,C),b=L(V,A);if(ee>=0&&b>=0&&ee!==b)return!0}const R=g(C),W=g(A);return R===W||v(R).has(W)||v(W).has(R)?!1:m.some(V=>V.some((ee,b)=>V.some(($,le)=>b!==le&&S(ee,R)&&S($,W))))},N=new Set,z=[];for(let C=0;C<l.length;C++)for(let A=C+1;A<l.length;A++){const R=l[C],W=l[A];if(!(R.id===W.id||!B(R.id,W.id)))for(const V of R.paths)for(const ee of W.paths){if(!be.statePathsOverlap(V,ee))continue;const b={code:"state_parallel_write",nodes:[R.id,W.id].sort(),path:[...V.length<=ee.length?V:ee]},$=JSON.stringify([b.nodes,b.path]);N.has($)||(N.add($),z.push(b))}}const H=(C,A)=>C<A?-1:C>A?1:0;return z.sort((C,A)=>H(C.code,A.code)||H(C.nodes.join(","),A.nodes.join(","))||H(C.path.join("."),A.path.join(".")))}catch{return[]}}function zo(e){try{const s={};for(const o of Vo(e))for(const n of o.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:o.code,path:[...o.path],with:o.nodes.filter(c=>c!==n)}),s[n]=a}return s}catch{return{}}}function vn(e,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=e.with)==null?void 0:o.items;return!e.with||!yn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=At(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function Ys(e,s,o){return e&&e.nodeId===s&&e.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(e.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function Ho(e,s,o,n,a){var h;const c=(h=n.find(g=>g.id===e))==null?void 0:h.data.step,l=i.loopMembership(n,a)[e]!==void 0,p=o==="success"&&l?"each":o;return p==="each"&&!l&&!i.isForeachStep(c)?null:i.loopRefusal(e,s,p,n,a)}const Jo=["off","root","key","pick","append"],Uo={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function qo(e){return be.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function Go(e,s){return JSON.stringify(e)===JSON.stringify(s)}function Ko(e,s){const{state:o,...n}=e,a=be.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return Go(s,a)?n:{...n,state:s}}function Xo(e,s){switch(s){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function Yo(e){return!i.isControlApp(e.uses.app)}function Tt(e,s){var o;return(o=e.nodes??e.steps)==null?void 0:o[s]}function Qt(e,s){const o=Tt(e,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const Zo=new Set(["succeeded","failed","canceled"]);function Qo(e,s,o=[]){var c,l;if(!e||[...o,s].some(p=>Qt(e,p)))return"no-run";const n=Tt(e,s);if(n)return n.status;const a=new Set;for(const p of Object.values(e.nodes??e.steps??{}))if(Array.isArray(p==null?void 0:p.iterations))for(const h of p.iterations){const g=(l=(c=h==null?void 0:h.nodes)==null?void 0:c[s])==null?void 0:l.status;g&&a.add(g)}for(const p of["failed","running","succeeded","skipped"])if(a.has(p))return p;return"pending"}const Zs={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function Sn(e,s){const o=s!==void 0&&Zo.has(s);switch(e){case"no-run":return Zs;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 Zs}}function ei(e,s,o,n,a){var l;if(!e||Qt(e,s)||a!==void 0&&Qt(e,a))return;const c=ti(e,s,o,n);return c==="taken"&&a!==void 0&&((l=Tt(e,a))==null?void 0:l.status)==="skipped"?"skipped":c}function ti(e,s,o,n){const a=Tt(e,s);if(!a)return;if(o==="each")return a.status==="skipped"?"skipped":void 0;const c=o??"success",l=a.output,p=n===i.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!p&&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 c==="success"?"taken":"skipped";if(a.status==="failed")return c==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const Qs={fields:[],sampleValues:{}};function Cn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function si(e,s){var g;const o=e.map(x=>x.id),n=new Set(o),a=new Map(o.map(x=>[x,0])),c=new Map(o.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((g=c.get(x.source))==null||g.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const l=[],p=o.filter(x=>a.get(x)===0);for(;p.length>0;){const x=p.shift();l.push(x);for(const f of c.get(x)??[]){const v=(a.get(f)??0)-1;a.set(f,v),v===0&&p.push(f)}}const h=new Set(l);for(const x of o)h.has(x)||l.push(x);return l}const ni=new Set(["string","number","boolean","object","array"]);function pt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let o=!1;for(const n of e){if(!Cn(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let c=s;for(const h of a.slice(0,-1)){const g=c.fields[h];(g==null?void 0:g.type)!=="object"&&(c.fields[h]={type:"object",fields:{}}),c=c.fields[h]}const l=typeof n.type=="string"&&ni.has(n.type)?n.type:"string";let p;if(l==="array"){const h=pt(n.items);p=h?{type:"array",items:h}:{type:"array"}}else l==="object"?p=pt(n.fields??n.properties)??{type:"object",fields:{}}:p={type:l};c.fields[a[a.length-1]]=p,o=!0}return o?s:void 0}function oi(e,s){var g,x,f,v,S,I,L;const o=e.data.step,n=((g=s.testOutputs)==null?void 0:g[o.id])??((x=s.persistedOutputs)==null?void 0:x[o.id]);if(n!=null)return n;const{app:a,action:c}=o.uses;if(a===i.TRIGGER_APP&&((f=i.internalNodeDef(a,c))==null?void 0:f.group)==="trigger"){const m=i.fieldsToParams(i.asFieldDefs((v=o.with)==null?void 0:v.fields)).map(B=>({key:B.key}));return i.shapeToSkeleton(pt(m))}const l=(S=i.internalNodeDef(a,c))==null?void 0:S.output;if(l&&l.length>0)return i.shapeToSkeleton(pt(l));const p=o.uses.trigger===!0?(I=s.triggerDef)==null?void 0:I.call(s,a,c):(L=s.actionDef)==null?void 0:L.call(s,a,c),h=pt(p==null?void 0:p.output);return h?i.shapeToSkeleton(h):p==null?void 0:p.sample}function ii(e,s){var p,h,g,x,f;const o=e.data.step,n=(p=s.previewOutputs)==null?void 0:p[o.id];if(n!=null)return n;const{app:a,action:c}=o.uses,l=o.uses.trigger===!0?(g=(h=s.shapes)==null?void 0:h.triggerDef)==null?void 0:g.call(h,a,c):(f=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:f.call(x,a,c);return l==null?void 0:l.sample}function ri(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function en(e,s){const o=Cn(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:s||(o[n.key]=ri(n.type)));return o}function Ut(e){return(i.inferOutputFields(e)??[]).map(s=>s.key)}function ai(e){const{anchorId:s,nodes:o,edges:n}=e;if(!s)return Qs;const a=e.shapes??{},c=i.ancestorIds(s,n);c.delete(s);const l=new Map(o.map(C=>[C.id,C])),p=[],h=[],g=new Map;for(const C of si(o,n)){if(!c.has(C))continue;const A=l.get(C);if(!A)continue;const{app:R,action:W}=A.data.step.uses,V=be.effectiveStateConfig(R,W,A.data.step.state);if(V.mode==="off")continue;const ee=oi(A,a);if(ee!==void 0){const{ops:$}=be.computeStateWrites(V,ee);p.push(...$);for(const le of Ut(be.foldState({},$))){const de=g.get(le)??new Set;de.add(C),g.set(le,de)}}const b=ii(A,e);b!==void 0&&h.push(...be.computeStateWrites(V,b).ops)}const x=en(e,!1),f=be.foldState(x,p),v=Ut(f);if(v.length===0)return Qs;const S=new Set(Ut(x)),I=new Map,L=new Map;for(const C of n)c.has(C.source)&&(!c.has(C.target)&&C.target!==s||(I.set(C.target,[...I.get(C.target)??[],C.source]),L.set(C.source,[...L.get(C.source)??[],C.target])));const m=[...c].filter(C=>!(I.get(C)??[]).length),B=C=>{const A=new Set,R=m.filter(W=>!C.has(W));for(;R.length>0;){const W=R.pop();if(W===s)return!1;if(!A.has(W)){A.add(W);for(const V of L.get(W)??[])C.has(V)||R.push(V)}}return!0},N=be.foldState(en(e,!0),h),z=[],H={};for(const C of v){const A=g.get(C)??new Set,R=S.has(C)||A.size>0&&B(A);z.push({key:C,path:!0,paths:R?"all":"some"});const W=i.valueAtPath(N,C);W!==void 0&&(H[`state.${C}`]=W)}return{fields:z,sampleValues:H}}const ci={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"}},tn="Never fired";function li(e){if(!e)return tn;const s=new Date(e);return Number.isNaN(s.getTime())?tn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function di(e,s){var a;if(!(e!=null&&e.status))return null;const o=ci[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:li(e.lastFireAt),retryVisible:n&&s}}function ui(e){const s=new Map;for(const o of e)o.nodeId&&s.set(o.nodeId,o);return s}function pi(e){return(e??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function fi(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return d.useEffect(()=>{const l=JSON.parse(c).filter(p=>!a.current.has(p));if(l.length!==0){for(const p of l)a.current.add(p);Promise.all(l.map(async p=>{try{return[p,await e.getAppActions(p)]}catch{return a.current.delete(p),null}})).then(p=>{const h=p.filter(g=>g!==null);h.length!==0&&n(g=>({...g,...Object.fromEntries(h)}))})}},[e,c]),o}function hi(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),c=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return d.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const p=JSON.parse(c).filter(h=>!a.current.has(h));if(p.length!==0){for(const h of p)a.current.add(h);Promise.all(p.map(async h=>{try{return[h,await l.call(e,h)]}catch{return a.current.delete(h),null}})).then(h=>{const g=h.filter(x=>x!==null);g.length!==0&&n(x=>({...x,...Object.fromEntries(g)}))})}},[e,c]),o}function mi(e){return(s,o)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(c=>c.key===o))==null?void 0:a.ports}}const wi="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 sn(e,s,o,n){const a=e.find(c=>c.id===s);return[o,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ns=d.createContext(void 0),os=d.createContext(new Map),is=d.createContext({tones:new Map,loopOf:new Map});function nn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const rs=d.createContext(new Map),Nn=d.createContext({byNode:new Map,subs:[]});function gi({apps:e,registration:s,children:o}){return t.jsx(rs.Provider,{value:e,children:t.jsx(Nn.Provider,{value:s,children:o})})}const as=d.createContext(null);function xi(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(bi,{...e})})}function on(e,s){let o=s.length+1;for(;s.includes(`${e}-${o}`);)o++;return`${e}-${o}`}function qt(e){var s,o;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((o=e.measured)==null?void 0:o.height)??e.height??64}}function bi({onConnectionResourcesChange:e,value:s,onChange:o,readOnly:n,height:a=480,apps:c,exprOptions:l,project:p,runState:h,stepProblems:g,onTestRun:x,fitViewKey:f,onRunFromNode:v}){var Ds,Os,_s,Ws,$s,Bs,Vs;const S=i.useW6WApi(),I=d.useMemo(()=>new Map((c??[]).map(r=>[r.id,r])),[c]),L=ki(s),[m,B]=d.useState(null),N=d.useMemo(()=>i.centralizeConnections(s),[s.id]),z=d.useMemo(()=>i.workflowToFlow(N),[N]),[H,C]=d.useState(N.connections??{}),A=d.useRef(H),R=d.useCallback(r=>{A.current=r,C(r)},[]),W=d.useCallback(r=>{const u=i.centralizeConnections({nodes:[r],connections:A.current});return u.connections!==A.current&&R(u.connections),u.nodes[0]},[R]),V=d.useMemo(()=>i.storedViewport(s),[s.id]),ee=((Ds=s.settings)==null?void 0:Ds.savePosition)!==!1,[b,$,le]=oe.useNodesState(z.nodes),de=fi(S,b),ve=hi(S,b),te=d.useMemo(()=>mi(de),[de]),[E,Z,P]=oe.useEdgesState(z.edges),[_,D]=d.useState(null),q=d.useMemo(()=>s.canvas??{},[s.id]),[O,J]=d.useState(q),[G]=d.useState(()=>new Eo(kt(N,z.nodes,z.edges,H,q))),ue=d.useRef(),[rt,at]=d.useState(0),[Be,Pe]=d.useState(!1),[ae,Se]=d.useState(null),[Re,Ye]=d.useState(null),[K,Ce]=d.useState(null),[Ve,Me]=d.useState(!1),Ne=d.useRef({});d.useEffect(()=>{Ve||(Ne.current={})},[Ve]);const[Q,pe]=d.useState(null),[Pt,He]=d.useState("props"),[Le,Fe]=d.useState(null),[De,ke]=d.useState(null),[Ee,Ae]=d.useState(null),Ze=d.useRef(!1),je=d.useRef(null),[fe,Oe]=d.useState(null),{screenToFlowPosition:me,fitView:Te}=oe.useReactFlow(),Qe=i.useEffectiveTheme();d.useEffect(()=>{$(z.nodes),Z(z.edges),D(null),Ce(null),Ae(null),pe(null),Fe(null),J(q),R(N.connections??{}),G.reset(kt(N,z.nodes,z.edges,N.connections??{},q)),ue.current=void 0},[z,q,N,$,Z,R,G]),d.useEffect(()=>{$(r=>{const u=new Map(i.stampLoopOf(r,E).map(w=>[w.id,w.data.loopOf]));return r.map(w=>{const j=Qo(h,w.id,xn(w.id,u));return w.data.stepStatus===j&&w.data.runStatus===(h==null?void 0:h.status)?w:{...w,data:{...w.data,stepStatus:j,runStatus:h==null?void 0:h.status}}})}),Z(r=>r.map(u=>{var k;const w=i.edgeLane(u),j=ei(h,u.source,w,typeof((k=u.data)==null?void 0:k.route)=="string"?u.data.route:void 0,u.target),y=i.edgeVisuals(w,j);return u.className===y.className&&u.label===y.label?u:{...u,className:y.className,label:y.label}}))},[h,z,rt,$,Z]),d.useEffect(()=>{$(r=>i.applyStepProblems(r,g))},[g,z,rt,$]);const ct=d.useCallback((r,u)=>{var y,k;const{canvas:w,...j}=r;return!((y=u.notes)!=null&&y.length)&&!((k=u.sections)!=null&&k.length)?j:{...j,canvas:po(u,s.canvas,ee)}},[s.canvas,ee]),ie=d.useCallback((r,u,w)=>{G.record(kt(s,r,u,A.current,w??O),Ve?Ne.current:ue.current),o(ct(i.flowToWorkflow({...s,connections:A.current},r,u),w??O))},[s,o,O,ct,G,Ve]),ce=d.useRef(()=>{});ce.current=r=>{if(n)return;const u=i.editConnectionResources(b.map(j=>j.data.step),A.current,r),w=b.map((j,y)=>({...j,data:{...j.data,step:u.nodes[y]}}));R(u.connections),$(w),ie(w,E)};const lt=d.useCallback(r=>ce.current(r),[]),ft=d.useCallback(r=>{D(r),Ce(null),$(u=>u.map(w=>({...w,selected:w.id===r}))),Z(u=>u.map(w=>({...w,selected:!1}))),Te({nodes:[{id:r}],duration:300,maxZoom:1})},[$,Z,Te]),[et,ht]=d.useState(null),T=d.useMemo(()=>et?b.map(r=>r.id===et?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,et]),Y=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),ne=JSON.stringify(Y),we=JSON.stringify([...I]);d.useEffect(()=>{e==null||e({workflowId:s.id,nodes:Y,apps:I,connections:H,readOnly:n,edit:lt,focusNode:ft,highlightNode:ht})},[e,s.id,ne,we,H,n,lt,ft]),d.useEffect(()=>()=>e==null?void 0:e(null),[e]);const tt=d.useCallback(r=>i.canConnect(r.source,r.target,b,E,te,i.routeFromHandle(r.sourceHandle)),[b,E,te]),[Rt,Je]=d.useState(null),ls=d.useRef(null),Mt=d.useRef(null);d.useEffect(()=>{$(r=>i.stampLoopOf(r,E))},[E,$]);const Dn=d.useCallback(r=>{if(n)return;const u=i.applyConnect(r.source,r.target,b,E,i.laneForSourceHandle(r.sourceHandle),te,i.routeFromHandle(r.sourceHandle));if(!u){const w=i.laneForSourceHandle(r.sourceHandle),j=i.connectRefusal(r.source,r.target,b,E,w,te,i.routeFromHandle(r.sourceHandle));if(j&&j.refused==="loop"){Je({nodeId:r.source,reason:j.reason});return}if(j){const k=E.find(F=>F.source===r.source&&i.edgeLane(F)===w);k&&(Z(E.map(F=>({...F,selected:F.id===k.id}))),Ce(k.id),Ue({edgeId:k.id,message:nn(j.cap)}));return}const y=i.connectConflict(r.source,r.target,b,E,i.laneForSourceHandle(r.sourceHandle));if(!y)return;Z(E.map(k=>({...k,selected:k.id===y}))),Ce(y),Ue({edgeId:y,message:i.idClashMessage("Can’t draw that edge",y,sn(E,y,r.source,r.target))});return}Ue(null),Je(null),Z(u),ie(b,u)},[E,b,Z,ie,n,te]),On=d.useCallback((r,u)=>{var U,X,se;if(n||u.isValid)return;const w=u.fromNode;if(!w)return;const j=((U=u.fromHandle)==null?void 0:U.type)==="target"?"target":"source",y=u.toNode;if(y&&j==="source"){const re=Ho(w.id,y.id,Ys(Mt.current,w.id,u.fromHandle),b,E);if(re){Je({nodeId:w.id,reason:re});return}}const k=(X=b.find(re=>re.id===w.id))==null?void 0:X.data.step;if(k){const re=i.nodePortsForStep(k,te);if((j==="source"?re.out:re.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,M=me({x:F.clientX,y:F.clientY});Oe({nodeId:w.id,handleType:j,position:M,lane:Ys(Mt.current,w.id,u.fromHandle),route:i.routeFromHandle((se=u.fromHandle)==null?void 0:se.id)}),Me(!0)},[n,me,b,E,te]),ds=d.useCallback((r,u,w)=>{if(n)return;const j=b.find(U=>U.id===r);if(!j)return;const y=qt(j),k=i.laneForSourceHandle(w),F=120,M=u==="target"?{x:y.x-y.w-F,y:y.y}:k==="error"?{x:y.x,y:y.y+y.h+F}:k==="each"?{x:y.x+y.w+F,y:y.y-y.h-F/2}:{x:y.x+y.w+F,y:y.y};Oe({nodeId:r,handleType:u,position:M,lane:k,route:i.routeFromHandle(w)}),Me(!0)},[n,b]),us=d.useCallback(r=>{n||Ae({nodeIds:[r],edgeIds:[]})},[n]),_n=d.useCallback(r=>{if(n)return;const u=yo(r,b,E,O);$(u.nodes),Z(u.edges),J(u.canvas),u.nodes.some(w=>w.id===_)||D(null),u.nodes.some(w=>w.id===Q)||pe(null),u.edges.some(w=>w.id===K)||Ce(null),ie(u.nodes,u.edges,u.canvas)},[b,E,O,$,Z,ie,n,_,Q,K]),ps=d.useCallback(()=>{if(n)return;const r=Po(b,E,O);$(r.nodes),J(r.canvas),Ze.current=!0,ie(r.nodes,E,r.canvas)},[b,E,O,$,ie,n]),Wn=d.useCallback(()=>{n||ps()},[n,ps]);d.useEffect(()=>{Ze.current&&(Ze.current=!1,Te({duration:300}))},[b,Te]);const fs=d.useRef(f);d.useEffect(()=>{Object.is(fs.current,f)||(fs.current=f,Te({duration:300}))},[f,Te]);const[mt,Ue]=d.useState(null),st=d.useMemo(()=>E.find(r=>r.id===K)??null,[E,K]),$n=d.useCallback(r=>{if(n||!K)return;const u=E.find(F=>F.id===K);if(!u||i.edgeLane(u)===r)return;const w=i.edgeWhenConflict(E,K,r,b),j=i.relaneRefusal(E,K,r,b,te),y=w||j?null:i.setEdgeWhen(E,K,r,b,te);if(!y){if(j){Ue({edgeId:K,message:nn(j.cap)});return}Ue({edgeId:K,message:w?i.idClashMessage("Can’t switch this edge",w,sn(E,w,u.source,u.target)):"This edge can’t be switched right now."});return}Ue(null),Z(y);const k=y.find(F=>F.source===u.source&&F.target===u.target&&i.edgeLane(F)===r);Ce((k==null?void 0:k.id)??null),ie(b,y)},[E,b,Z,ie,n,K,te]),Bn=d.useCallback(r=>{if(n)return;const u=E.filter(w=>w.id!==r);u.length!==E.length&&(Z(u),K===r&&Ce(null),ie(b,u))},[b,E,Z,ie,n,K]),Lt=d.useCallback(r=>{if(n)return;const u=r.map(k=>b.find(F=>F.id===k)).filter(k=>k!==void 0);if(u.length===0)return;const w=b.map(k=>k.id),j=u.map(k=>{const F=i.suggestStepId(w,`${k.data.step.id}_copy`);w.push(F);const M={...i.stripBody(structuredClone(k.data.step)),id:F};return{id:F,type:k.type,position:{x:k.position.x+40,y:k.position.y+60},data:{step:M,isInternal:k.data.isInternal},...u.length>1?{selected:!0}:{}}}),y=[...u.length>1?b.map(k=>k.selected?{...k,selected:!1}:k):b,...j];$(y),D(j[0].id),ie(y,E)},[b,E,$,ie,n]),hs=d.useCallback(r=>Lt([r]),[Lt]),Vn=d.useCallback(r=>{if(n)return;const u=i.isInternalApp(r.uses.app),w=b.map(se=>se.id),j=r.id&&!i.stepNameError(r.id,w)?r.id:i.suggestStepId(w,i.slugifyLabel(i.internalNodeLabel(r.uses.app,r.uses.action))),y=W({id:j,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),k={id:j,type:u?"control":"step",position:(fe==null?void 0:fe.position)??(De==null?void 0:De.position)??{x:80,y:80+b.length*24},data:{step:y,isInternal:u}},F=[...b,k];let M=E,U=null;const X=(se,re,he,We)=>{const ot=i.connectRefusal(se,re,F,E,he,te);ot&&ot.refused==="loop"&&(U={nodeId:We,reason:ot.reason})};if(fe){const[se,re]=fe.handleType==="target"?[j,fe.nodeId]:[fe.nodeId,j],he=i.applyConnect(se,re,F,E,fe.lane,te,fe.route);he||X(se,re,fe.lane,fe.nodeId),M=he??E}else{const se=b.find(re=>i.isTriggerStep(re.data.step.uses));if(i.isTriggerStep(r.uses)){if(!se){const re=i.findChainRoot(b,E);if(re){const he=i.applyConnect(j,re.id,F,E,"success",te);he||X(j,re.id,"success",re.id),M=he??E}}}else{const he=(se&&!E.some(We=>We.source===se.id)?se:void 0)??i.findChainTail(b,E);if(he){const We=i.applyConnect(he.id,j,F,E,"success",te);We||X(he.id,j,"success",he.id),M=We??E}}}return $(F),M!==E&&Z(M),Je(U),D(j),ie(F,M),j},[b,E,$,Z,ie,n,fe,De,te,W]),ms=d.useCallback((r,u)=>{var U;let w=u;const j=(U=b.find(X=>X.id===r))==null?void 0:U.data.step;if(u.uses.connection&&!u.uses.connectionRef&&(j!=null&&j.uses.connectionRef)&&j.uses.app===u.uses.app){const X=i.selectNodeConnection(i.withConnectionRef(u,j.uses.connectionRef),u.uses.connection,b.map(se=>se.data.step),A.current);R(X.connections),w=X.step}else w=W(u);const y=w.id!==r;if(y&&b.some(X=>X.id===w.id))return;const k=b.map(X=>X.id===r?{...X,id:w.id,data:{step:w,isInternal:i.isInternalApp(w.uses.app)}}:X);if(y){const X=i.renameStepInEdges(E,r,w.id),se=hn(O,r,w.id);$(k),Z(X),J(se),_===r&&D(w.id),Q===r&&pe(w.id),ie(k,X,se);return}$(k);const F=new Set(i.routesForStep(w).map(X=>X.id)),M=E.filter(X=>{var se;return X.source!==w.id||((se=X.data)==null?void 0:se.route)===void 0||F.has(String(X.data.route))});M.length!==E.length&&Z(M),ie(k,M)},[b,E,O,$,Z,_,Q,ie,W,R]),qe=d.useCallback(r=>{n||(J(r),ie(b,E,r))},[n,b,E,ie]),zn=d.useCallback(()=>{var y;if(n)return;const r=(y=je.current)==null?void 0:y.getBoundingClientRect(),u=r?me({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},w=O.notes??[],j={id:on("note",w.map(k=>k.id)),color:"#facc15",position:{x:Math.round(u.x-100),y:Math.round(u.y-60)},size:{width:200,height:120},content:""};qe(Xt({...O,notes:[...w,j]}))},[n,O,me,qe]),Hn=d.useCallback((r,u)=>{if(n)return;const w=u?Math.min(r.x,u.x):r.x,j=u?Math.min(r.y,u.y):r.y,y=u?Math.abs(u.x-r.x):360,k=u?Math.abs(u.y-r.y):240,F=b.filter(re=>{const he=qt(re),We=he.x+he.w/2,ot=he.y+he.h/2;return We>=w&&We<=w+y&&ot>=j&&ot<=j+k}).map(re=>re.id),M=O.sections??[],U=on("section",M.map(re=>re.id)),X={id:U,title:"Section",color:"#6366f1",position:{x:Math.round(w),y:Math.round(j)},size:{width:Math.round(y),height:Math.round(k)},nodes:[]},se={...O,sections:[...M,X]};qe(Xt(Kt(se,U,F)))},[n,b,O,qe]);d.useEffect(()=>{if(!Be)return;const r=u=>{u.key==="Escape"&&(Pe(!1),Se(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Be]);const Jn=d.useCallback((r,u)=>{var F;if(n)return;const w=(F=O.sections)==null?void 0:F.find(M=>M.id===r);if(!w)return;const j=new Set(w.nodes),y=b.map(M=>j.has(M.id)?{...M,position:{x:M.position.x+u.dx,y:M.position.y+u.dy}}:M),k={...O,sections:(O.sections??[]).map(M=>M.id===r?{...M,position:{x:M.position.x+u.dx,y:M.position.y+u.dy}}:M)};$(y),J(k),ie(y,E,k)},[n,O,b,E,$,ie]),Un=d.useCallback((r,u)=>{if(n)return;const w=r==="note"?{...O,notes:(O.notes??[]).filter(j=>j.id!==u)}:{...O,sections:(O.sections??[]).filter(j=>j.id!==u)};qe(w)},[n,O,qe]),qn=r=>{let u=O;for(const w of r){const j=qt(w),y=j.x+j.w/2,k=j.y+j.h/2,F=(u.sections??[]).find(U=>y>=U.position.x&&y<=U.position.x+U.size.width&&k>=U.position.y&&k<=U.position.y+U.size.height),M=mn(u,w.id);F?(M.length!==1||M[0]!==F.id)&&(u=Kt(u,F.id,[w.id])):M.length>0&&(u=ts(u,w.id))}return u},Ft=d.useCallback((r,u,w)=>{(async()=>{const j=await S.saveStepTest(s.id,r,u).catch(y=>(console.error("step run fixture save failed",y),null));await S.recordStepTestRun(s.id,r,{stepTestId:(j==null?void 0:j.id)??null,status:w.status,input:u.input,output:w.output,error:w.error,...w.meta?{meta:w.meta}:{}})})().catch(j=>{console.error("step run persist failed",j)})},[S,s.id]),ws=d.useCallback(r=>{const u=b.find(w=>w.id===r);!u||!v&&i.isControlApp(u.data.step.uses.app)||B({stepId:r,status:"collect"})},[b,v]),Gn=d.useCallback(async(r,u,w)=>{if(!v)return;const j=b.find(F=>F.id===r);if(!j)return;const y=i.isTriggerStep(j.data.step.uses),k={stopAt:Zt(b.map(F=>F.data.step),r),...w?{state:w}:{},...y?{input:u}:{}};B({stepId:r,status:"running"});try{await v(r,k),B(null)}catch(F){const M=F;B({stepId:r,status:"error",error:M.message??String(F),errorCode:M.code})}},[b,v]),wt=d.useCallback((r,u)=>{if(n)return;const w=b.map(j=>j.id===r?{...j,data:{...j.data,step:u(j.data.step)}}:j);$(w),ie(w,E)},[b,E,$,ie,n]),gs=d.useCallback(r=>wt(r,u=>bn(u,!Xe(u))),[wt]),xs=d.useCallback(r=>wt(r,u=>jn(u,!Ie(u))),[wt]),Kn=d.useCallback(async(r,u,w)=>{x==null||x();const j=b.find(U=>U.id===r);if(!j)return;const y=j.data.step,k=i.isTriggerStep(y.uses),F=k?{input:u}:{...y.with??{},...u},M=k?{input:u,with:u}:{input:u,with:F};B({stepId:r,status:"running"});try{const U=await S.invokeAction(y.uses.app,y.uses.action,F,{connectionId:i.connectionIdFor(y,A.current),project:p,...w?{state:w}:{},workflowId:s.id}),X=U.logs,se=U.meta;B({stepId:r,status:"done",value:U.value,logs:X,...se?{meta:se}:{}}),Ft(r,M,{status:"succeeded",output:U.value,...se?{meta:se}:{}})}catch(U){const X=U;B({stepId:r,status:"error",error:X.message??String(U),errorCode:X.code}),Ft(r,M,{status:"failed",error:X.message??String(U)})}},[b,S,Ft,p,x,s.id]),Dt=d.useMemo(()=>({onEdit:r=>{He("props"),pe(r)},onEditJson:r=>{He("json"),pe(r)},onRun:ws,onDuplicate:hs,onDelete:us,onTogglePause:gs,onToggleDisable:xs,runsFromNode:!!v,onAddFromPort:ds,readOnly:n}),[ws,hs,us,gs,xs,v,ds,n]);d.useEffect(()=>{const r=je.current;if(!r)return;const u=w=>{const j=w.target.closest(".react-flow__node");if(!j)return;const y=j.getAttribute("data-id");y&&(w.stopPropagation(),Dt.onEdit(y))};return r.addEventListener("dblclick",u,!0),()=>r.removeEventListener("dblclick",u,!0)},[Dt]);const nt=b.find(r=>r.id===Q),gt=(nt==null?void 0:nt.data.step)??null,Ot=m?((Os=b.find(r=>r.id===m.stepId))==null?void 0:Os.data.step)??null:null,_t=(m==null?void 0:m.status)==="collect"&&!!Ot,bs=d.useMemo(()=>{const r=new Map;for(const u of b)r.set(u.id,So(u.id,E).count);return r},[b,E]),js=Do(b),xt=d.useMemo(()=>Oo(js),[js]),Xn=d.useMemo(()=>Lo(E,xt.tones,xt.loopOf),[E,xt]),Yn=d.useMemo(()=>({step:Ai,control:Ti}),[]),[bt,ys]=d.useState({}),[jt,vs]=d.useState({}),[Ss,Cs]=d.useState({}),[yt,Ns]=d.useState({}),[ze,vt]=d.useState(null),[ks,Es]=d.useState([]),Zn=Q??ze??"";d.useEffect(()=>{const r=S.loadNodeSamples;if(typeof r!="function"||!s.id){Es([]);return}let u=!1;return r(s.id).then(w=>{u||Es(Array.isArray(w)?w:[])},()=>{}),()=>{u=!0}},[S,s.id,Zn]);const St=d.useMemo(()=>i.indexNodeSamples(ks),[ks]),Wt=d.useMemo(()=>i.splitNodeOutputs(bt,St,yt),[bt,St,yt]),_e=d.useMemo(()=>i.splitPreviewOutputs(bt,St,yt),[bt,St,yt]),xe=d.useMemo(()=>({actionDef:(r,u)=>{var w;return(w=de[r])==null?void 0:w.find(j=>j.key===u)},triggerDef:(r,u)=>{var w;return(w=ve[r])==null?void 0:w.find(j=>j.key===u)},testOutputs:Wt.fresh,persistedOutputs:Wt.persisted,loopSamples:Ss}),[de,ve,Wt,Ss]),Ge=d.useMemo(()=>m?i.upstreamStateSources(m.stepId,b,E,xe):void 0,[m,b,E,xe]),Qn=d.useMemo(()=>(Ge==null?void 0:Ge.steps)??[],[Ge]),ge=d.useMemo(()=>{const r=i.upstreamStateSources(Q,b,E,xe,ze);return{...r,steps:i.excludeSelfStep(r.steps,Q??ze)}},[Q,ze,b,E,xe]),$t=d.useMemo(()=>ai({anchorId:Q??ze,nodes:b,edges:E,initialState:s.initialState,variables:s.variables,shapes:xe,previewOutputs:{..._e.persisted,..._e.fresh}}),[Q,ze,b,E,s.initialState,s.variables,xe,_e]),As=JSON.stringify([...ge.steps.map(r=>r.id),...ge.extraSampleIds??[]]);d.useEffect(()=>{const r=JSON.parse(As);if(!Q&&!ze||r.length===0){ys({}),vs({}),Cs({}),Ns({});return}let u=!1;return Promise.all(r.map(async w=>{try{const j=await S.listStepTests(s.id,w),y=j.length?j[j.length-1]:null;return y?{id:w,output:y.lastRunOutput,runAt:y.lastRunAt,meta:y.lastRunMeta,loopSample:i.foreachTestSample(y)}:null}catch{return null}})).then(w=>{if(u)return;const j={},y={},k={},F={};for(const M of w)M!=null&&M.meta&&(y[M.id]=M.meta),M!=null&&M.loopSample&&(k[M.id]=M.loopSample),!(!M||M.output===void 0||M.output===null)&&(j[M.id]=M.output,F[M.id]=M.runAt);ys(j),Ns(F),vs(y),Cs(k)}),()=>{u=!0}},[S,s.id,Q,ze,As]);const Bt=d.useMemo(()=>i.declaredSamples(b,xe),[b,xe]),Ct=d.useMemo(()=>({persisted:_e.persisted,samples:Bt.samples,event:Bt.event}),[_e.persisted,Bt]),Ts=d.useMemo(()=>i.upstreamSampleValues(ge.steps,_e.fresh,jt,ge.loop,Ct),[ge.steps,ge.loop,_e.fresh,jt,Ct]),Is=d.useMemo(()=>i.upstreamSampleValueSources(ge.steps,_e.fresh,jt,ge.loop,Ct),[ge.steps,ge.loop,_e.fresh,jt,Ct]),Ps=i.useExpressionOptions(),Rs=d.useMemo(()=>i.nodeConfigSources(b),[b]),Ms=d.useMemo(()=>i.nodeConfigValues(b,L.subs),[b,L.subs]),Vt=d.useMemo(()=>i.nodeMetaValues(b,L.subs,I,H),[b,L.subs,I,H]),zt=d.useMemo(()=>({...l??{},steps:ge.steps,hasTrigger:ge.hasTrigger,eventOutputs:ge.eventOutputs,eventOutputsFrom:ge.eventOutputsFrom,loop:ge.loop,stateShape:{fields:$t.fields},nodeConfigs:Rs,nodeConfig:Ms,nodeMeta:Vt,valueSources:Is,sampleValues:{...Ps.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...i.nodeMetaSampleValues(Vt),...Ts,...$t.sampleValues}}),[l,Ps.sampleValues,ge,$t,Ts,Is,Rs,Ms,Vt]),Ls=r=>{var y;if(n)return;const u=G[r]();if(!u)return;const w=ko(s,u);$(w.nodes.map(k=>({...k,selected:k.id===_}))),Z(w.edges.map(k=>({...k,selected:k.id===K}))),J(u.canvas),R(u.connections),w.nodes.some(k=>k.id===_)||D(null),w.edges.some(k=>k.id===K)||Ce(null);const j=w.nodes.some(k=>k.id===Q);j||pe(null),Me(!1),vt(null),Oe(null),Ae(null),Ye(null),ke(null),Fe(null),Je(null),Ue(null),ue.current=void 0,at(k=>k+1),o(ct(i.flowToWorkflow({...s,nodes:u.nodes,connections:u.connections},w.nodes,w.edges),u.canvas)),!j&&!m&&((y=je.current)==null||y.focus({preventScroll:!0}))},Fs=d.useRef(Ls);Fs.current=Ls,d.useEffect(()=>{const r=je.current;if(!r)return;let u=r.contains(document.activeElement);const w=y=>{y.type==="focusin"&&y.target===document.body||(u=r.contains(y.target))},j=y=>{if(n||y.defaultPrevented||Ht(y.target)||!r.contains(y.target)&&!(u&&y.target===document.body))return;const k=y.key.toLowerCase();!(y.ctrlKey||y.metaKey)||y.altKey||k!=="z"&&!(k==="y"&&!y.shiftKey)||(y.preventDefault(),Fs.current(k==="y"||y.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",w),document.addEventListener("focusin",w),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",w),document.removeEventListener("focusin",w),document.removeEventListener("keydown",j)}},[n]);const Nt=d.useCallback((r,u)=>{var M;if(Ht(r.target))return;const w=(M=je.current)==null?void 0:M.getBoundingClientRect();if(!w)return;r.preventDefault();const j=qs(b,E),y=j.nodeIds,k=ro(y,u),F=u!==void 0&&!y.includes(u);F&&$(b.map(U=>U.selected!==(U.id===u)?{...U,selected:U.id===u}:U)),Fe({x:r.clientX-w.left,y:r.clientY-w.top,flow:me({x:r.clientX,y:r.clientY}),nodeIds:k,edgeIds:F?[]:j.edgeIds})},[b,E,$,me]),eo=d.useCallback(r=>{var u;Fe(null),r&&((u=je.current)==null||u.focus({preventScroll:!0}))},[]),to=r=>{const u=Le;!u||n||(r==="duplicate"?Lt(u.nodeIds):r==="delete"?Ae({nodeIds:u.nodeIds,edgeIds:u.edgeIds}):(Oe(null),ke({position:u.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),Me(!0)))},so=t.jsx(as.Provider,{value:Dt,children:t.jsx(ns.Provider,{value:te,children:t.jsx(os.Provider,{value:bs,children:t.jsx(is.Provider,{value:xt,children:t.jsx(gi,{apps:I,registration:L,children:t.jsx(i.WorkflowProjectProvider,{project:p,workflowId:s.id,children:t.jsx(i.ExpressionOptionsProvider,{value:zt,children:t.jsxs("section",{ref:je,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{ue.current=Ht(r.target)?{}:void 0},onBlurCapture:()=>{ue.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||Q||Ve||Ee)return;const u=r.target;if(u.isContentEditable||u.tagName==="INPUT"||u.tagName==="TEXTAREA"||u.tagName==="SELECT"||u.closest("dialog, .w6w-modal")!==null)return;const w=qs(b,E);!w.nodeIds.length&&!w.edgeIds.length||(r.preventDefault(),!w.nodeIds.length&&w.edgeIds.length===1?Bn(w.edgeIds[0]):Ae(w))},children:[t.jsxs(oe.ReactFlow,{nodes:T,edges:Xn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:le,onEdgesChange:P,onConnect:Dn,onConnectStart:(r,u)=>{Mt.current=u},onConnectEnd:On,onPaneClick:()=>Je(null),onPaneContextMenu:r=>Nt(r),onNodeContextMenu:(r,u)=>Nt(r,u.id),onEdgeContextMenu:r=>Nt(r),onSelectionContextMenu:r=>Nt(r),onMoveStart:()=>Fe(null),isValidConnection:tt,onNodeDragStop:(r,u,w)=>{const j=qn(w),y=j!==O;if(y&&J(j),!ee&&!y){G.record(kt(s,b,E,A.current,j));return}ie(b,E,j)},onMoveEnd:(r,u)=>{if(!r||n)return;const w=i.flowToWorkflow(s,b,E),j=i.withViewport(w,u);j!==w&&o(j,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:u})=>{var w,j,y,k;D(((w=r[0])==null?void 0:w.id)??null),Ce(((j=u[0])==null?void 0:j.id)??null),ls.current!==(((y=r[0])==null?void 0:y.id)??null)&&(ls.current=((k=r[0])==null?void 0:k.id)??null,Je(null))},nodeTypes:Yn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...V?{defaultViewport:V}:{fitView:!0},deleteKeyCode:null,colorMode:Qe,proOptions:{hideAttribution:!0},children:[t.jsx(oe.Background,{gap:16}),t.jsx(oe.Controls,{showInteractive:!1,children:!n&&t.jsx(oe.ControlButton,{onClick:Wn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(ye.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:()=>Me(!0),children:"+ Node"}),t.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:zn}),t.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${Be?" active":""}`,"aria-pressed":Be,"data-testid":"draw-section",onClick:()=>{Pe(!Be),Se(null)}})]}),!n&&Be&&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:u,clientY:w}=r;Se({sx:u,sy:w,ex:u,ey:w})},onPointerMove:r=>{const{clientX:u,clientY:w}=r;Se(j=>j&&{...j,ex:u,ey:w})},onPointerUp:()=>{const r=ae;if(Se(null),Pe(!1),!r)return;const u=me({x:r.sx,y:r.sy}),w=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Hn(u,w?me({x:r.ex,y:r.ey}):null)},children:ae&&(()=>{var j;const r=(j=je.current)==null?void 0:j.getBoundingClientRect(),u=(r==null?void 0:r.left)??0,w=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ae.sx,ae.ex)-u,top:Math.min(ae.sy,ae.ey)-w,width:Math.abs(ae.ex-ae.sx),height:Math.abs(ae.ey-ae.sy)}})})()}),!n&&st&&i.edgeLane(st)!=="each"&&((_s=b.find(r=>r.id===st.source))==null?void 0:_s.data.step.uses.app)!==i.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${i.edgeLane(st)===r?" active":""}`,"aria-pressed":i.edgeLane(st)===r,title:wi,onClick:()=>$n(r),children:r==="success"?"Success":"Error"},r)),(mt==null?void 0:mt.edgeId)===st.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:mt.message})]})}),Rt&&t.jsx(oe.NodeToolbar,{nodeId:Rt.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(Rt.reason)})}),t.jsx(i.CanvasLayer,{canvas:O,readOnly:n,savePosition:ee,onChange:qe,onSectionDrop:Jn,onRequestDelete:(r,u)=>!n&&Ye({kind:r,id:u})})]}),Re&&t.jsx(i.ConfirmModal,{title:Re.kind==="note"?"Delete note":"Delete section",message:Re.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Un(Re.kind,Re.id),Ye(null)},onClose:()=>Ye(null)}),Ve&&t.jsx(i.StepBuilderModal,{initialTab:De==null?void 0:De.tab,onClose:()=>{Me(!1),Oe(null),ke(null),vt(null)},onAdd:r=>{const u=Vn(r);return u&&vt(u),u},onDraftChange:(r,u)=>ms(r,{id:r,...u}),stepIds:b.map(r=>r.id),onOpenStep:r=>{Me(!1),Oe(null),ke(null),vt(null),He("props"),pe(r)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(fe,b,E),loop:i.stepBuilderLoop(fe,b,E,xe)}),gt&&Q&&t.jsx(Pi,{workflowId:s.id,step:gt,restoreVersion:rt,upstreamSteps:zt.steps??[],loop:zt.loop,readOnly:n,fanOutCount:bs.get(Q)??0,stateOutputFields:(Vs=i.resolveOutputShape((Ws=xe.actionDef)==null?void 0:Ws.call(xe,gt.uses.app,gt.uses.action),($s=xe.testOutputs)==null?void 0:$s[Q],(Bs=xe.persistedOutputs)==null?void 0:Bs[Q]))==null?void 0:Vs.fields.map(r=>r.key),initialView:Pt,stepProblems:nt==null?void 0:nt.data.stepProblems,otherStepIds:b.filter(r=>r.id!==Q).map(r=>r.id),onChange:r=>ms(Q,r),onClose:()=>pe(null),onTestRun:x}),m&&t.jsxs(i.Modal,{title:`${_t?"Run node":"Test run"}: ${m.stepId}`,onClose:()=>B(null),children:[_t&&Ot&&t.jsx(Si,{workflowId:s.id,step:Ot,upstreamSteps:Qn,loop:Ge==null?void 0:Ge.loop,continues:v?{stopAt:Zt(b.map(r=>r.data.step),m.stepId)}:void 0,onCancel:()=>B(null),onRun:(r,u)=>v?Gn(m.stepId,r,u):Kn(m.stepId,r,u)},m.stepId),!_t&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[m.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),m.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[m.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:m.errorCode})}),m.error||"The node failed with no error message."]}),m.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(i.ResultViewer,{value:m.value,maxHeight:360}),m.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(i.ResultViewer,{value:m.meta,maxHeight:360})]})]}),m.logs&&m.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("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:m.logs.join(`
2
+ `)})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>B(null),children:"Close"})})]})]}),Ee!==null&&t.jsx(i.ConfirmModal,{title:Ee.nodeIds.length===1?"Delete node":Ee.nodeIds.length>1?`Delete ${Ee.nodeIds.length} nodes`:`Delete ${Ee.edgeIds.length} connections`,message:vo(Ee,b,E),confirmLabel:"Delete",onConfirm:()=>{_n(Ee),Ae(null)},onClose:()=>Ae(null)}),Le&&t.jsx(io,{x:Le.x,y:Le.y,items:ao(Le.nodeIds,!!n),onAction:to,onClose:eo})]})})})})})})})});return t.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:b.map(r=>r.data.step),connections:H,setConnections:R,readOnly:n},children:so})}const ji=["code"];function It(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function yi(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return It(e)}function vi({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 o=e[0],n=o!==void 0?(i.inferOutputFields(o)??[]).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(i.ResultViewer,{value:o,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,c)=>t.jsxs("span",{children:[c>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 kn(e){const[s,o]=d.useState(null),[n,a]=d.useState("0"),c=s??i.loopItemText(e),l=e?i.parseLoopSeed(c,n):void 0;return{active:!!e,itemText:c,indexText:n,setItemText:o,setIndexText:a,parsed:l}}function En(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function cs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function An({seed:e,readOnly:s}){if(!e.active)return null;const o=cs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[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."}),o&&t.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function es({text:e,onChange:s,seeds:o,readOnly:n,expand:a,hint:c}){const l=It(e),p=l?Object.keys(l).length:0,h=p>0,[g,x]=d.useState(h);d.useEffect(()=>{(h||a)&&x(!0)},[h,a]);const f=v=>{s(JSON.stringify(v.lastRunOutput??v.input??{},null,2)),x(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),o.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:o.map(v=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${v.label}'s saved test as the incoming state`,disabled:n,onClick:()=>f(v.test),children:[t.jsx("code",{children:v.label}),v.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",v.test.lastRunStatus]}):null]},v.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:g,onToggle:v=>x(v.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",p>0?` · ${p} key${p===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:v=>s(v.target.value)}),t.jsx("span",{className:"w6w-hint",children:c??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 Si({workflowId:e,step:s,upstreamSteps:o,loop:n,onRun:a,onCancel:c,continues:l}){const p=i.useW6WApi(),h=i.isTriggerStep(s.uses),g=i.isInternalApp(s.uses.app),x=d.useMemo(()=>{var D;return h?i.asFieldDefs((D=s.with)==null?void 0:D.fields):[]},[h,s.with]),f=d.useMemo(()=>h?i.fieldsToParams(x):g?i.internalNodeParams(s.uses.app,s.uses.action):null,[h,g,x,s.uses.app,s.uses.action]),[v,S]=d.useState(null),I=f??v;d.useEffect(()=>{if(f)return;if(!s.uses.app||!s.uses.action){S([]);return}let D=!1;return S(null),p.getAppActions(s.uses.app).then(q=>{var O;D||S(((O=q.find(J=>J.key===s.uses.action))==null?void 0:O.params)??[])}).catch(()=>!D&&S([])),()=>{D=!0}},[p,f,s.uses.app,s.uses.action]);const[L,m]=d.useState(()=>{var D;return h?i.seedValues(i.asFieldDefs((D=s.with)==null?void 0:D.fields)):{}}),[B,N]=d.useState("{}"),z=i.useSeedSources(e,o,!h),H=kn(n),C=i.startStateFromSeeds(z,En(H)),A=i.useRememberedTestInput(e,s.id),[R,W]=d.useState(!1),[V,ee]=d.useState(!1);d.useEffect(()=>{if(!A.loaded)return;let D=!1;const q=(O,J)=>{O&&Object.keys(O).length>0&&(h?m(G=>({...G,...O})):N(JSON.stringify(O,null,2)),J&&ee(!0)),W(!0)};if(A.input!==void 0){q(A.input,!0);return}return p.listStepTests(e,s.id).then(O=>{if(D)return;const J=O.length?O[O.length-1]:null;q(h?J==null?void 0:J.with:J==null?void 0:J.input,!1)}).catch(()=>{D||W(!0)}),()=>{D=!0}},[p,e,s.id,h,A.loaded]);const[b,$]=d.useState(0),le=()=>{A.clear(),ee(!1),h?m(i.seedValues(x)):N("{}"),$(D=>D+1)},[de,ve]=d.useState(!0),te=It(B),E=h?de:te!==null,Z=h?L:{...s.with??{},...te??{}},P=h?null:cs(H),_=!!I&&R&&E&&!P&&i.requiredParamsFilled(I,Z);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((D,q)=>t.jsxs("span",{children:[q>0?", ":"",t.jsx("code",{children:D})]},D))]}):null,". Disabled nodes are skipped."]}),V&&I!==null&&R&&t.jsx(i.LastUsedNote,{onClear:le}),I===null||!R?t.jsx("p",{className:"w6w-muted w6w-small",children:I===null?"Loading parameters…":"Loading saved values…"}):h?t.jsxs(t.Fragment,{children:[t.jsx(i.PropertyEntryForm,{params:I,values:L,onChange:m,onValidityChange:ve},b),I.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(An,{seed:H}),t.jsx(es,{text:B,onChange:N,seeds:z})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!_&&I!==null&&R&&t.jsx("span",{className:"w6w-muted w6w-small",children:P?`${P} Fix it to run.`:E?h?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":h?"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:!_,onClick:()=>{A.save(h?L:te??{},I??[]),a(h?L:te??{},h?void 0:C)},children:"▶ Run"})]})]})}function Ci(e){return e.uses.app===i.CONTROL_APP&&e.uses.action==="foreach"}function Tn({id:e}){const{tones:s,loopOf:o}=d.useContext(is),n=xn(e,o);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:ss(s.get(a)??1)}},a))})}function In(e){return Fo(e,d.useContext(is).tones)}function $e({type:e,position:s,multiple:o,id:n,variant:a,top:c,routeLabel:l}){const p=oe.useNodeId(),h=d.useContext(as),g=!!p&&!!h&&!h.readOnly,x=()=>{g&&p&&h.onAddFromPort(p,e,n)},f=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":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:g?x:void 0,title:l?`${l} — drag or click to connect`:g?`Drag to empty canvas (or click) to add ${f} · 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 Pn({id:e,step:s,runnable:o}){const n=d.useContext(as);if(!n||n.readOnly)return null;const a=o||n.runsFromNode,c=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=Xe(s),p=Ie(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:c,"aria-label":c,onClick:()=>n.onRun(e),children:t.jsx(ye.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(ye.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":p,title:p?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":p?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:t.jsx(ye.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(ye.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(ye.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(ye.Icon,{name:"trash",size:15})})]})}function Rn({step:e,count:s}){if(s<2)return null;const o=e.fanOut==="parallel",n=No(s,o?"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:o?"⇉":"→"})," ",s]})}function Mn({step:e}){const s=Xe(e),o=Ie(e);return!s&&!o?null:t.jsxs("div",{children:[o&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":Ks,title:Ks,children:[t.jsx(ye.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":Gs,title:Gs,children:[t.jsx(ye.Icon,{name:"pause",size:11})," Paused"]})]})}function Ln(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(i.stepProblemTooltip).join(`
3
+ `)}}function Fn({problems:e}){if(!e||e.length===0)return null;const s=e.map(i.stepProblemTooltip).join(`
4
+ `);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(ye.Icon,{name:"warning",size:12})})}function Ni(e){const s=i.useW6WApi(),o=e.uses.action,[n,a]=d.useState(null),c=e.uses.trigger===!0,l=e.uses.app;return d.useEffect(()=>{if(!c||!s.getAppTriggers)return;let p=!1;return s.getAppTriggers(l).then(h=>{var g;return!p&&a(((g=h.find(x=>x.key===o))==null?void 0:g.title)??null)}).catch(()=>{}),()=>{p=!0}},[s,l,o,c]),n||o}function ki(e){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,a=e.id,c=[...pi(e.nodes),...(e.nodes??[]).filter(I=>{var L;return((L=I.uses)==null?void 0:L.app)===i.WEBHOOK_APP&&I.uses.trigger!==!0})],l=c.length>0,p=c.map(I=>`${I.id}:${I.uses.app}:${I.uses.action}:${i.connectionIdFor(I,e.connections)??""}`).join("|"),[h,g]=d.useState([]),x=d.useMemo(()=>ui(h),[h]),[f,v]=d.useState(0);d.useEffect(()=>{if(!o||!l){g([]);return}let I=!1;return o.call(s,a).then(L=>!I&&g(L)).catch(()=>{}),()=>{I=!0}},[s,o,a,l,p,f]);const S=d.useMemo(()=>n?async I=>{try{await n.call(s,I)}finally{v(L=>L+1)}}:void 0,[s,n]);return d.useMemo(()=>({byNode:x,subs:h,retry:S}),[x,h,S])}function Ei({nodeId:e}){const{byNode:s,retry:o}=d.useContext(Nn),[n,a]=d.useState(!1),c=s.get(e),l=di(c,o!==void 0);return!c||!l?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":c.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&&o&&t.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),o(c.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function Ai({id:e,data:s,selected:o}){const n=s.step,c=d.useContext(rs).get(n.uses.app),l=(c==null?void 0:c.displayName)||n.uses.app||"—",p=i.isTriggerStep(n.uses),h=Ni(n),g=n.uses.trigger?`${l} · ${h}`:l,x=i.nodePortsForStep(n,d.useContext(ns)),f=Sn(s.stepStatus??"no-run",s.runStatus),v=t.jsx(Rn,{step:n,count:d.useContext(os).get(e)??0}),S=In(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",Ie(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:S,"data-disabled":Ie(n)||void 0,"data-paused":Xe(n)||void 0,children:[t.jsx(Pn,{id:e,step:n,runnable:!0}),t.jsxs("div",{className:p?"w6w-node-trigger":void 0,"data-node-kind":p?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Ln(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${f.borderWidth}px ${f.borderStyle} ${o?"var(--w6w-accent)":f.borderColor}`,opacity:Ie(n)?.45:o?1:f.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...p?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fn,{problems:s.stepProblems}),x.in>0&&t.jsx($e,{type:"target",position:oe.Position.Left,multiple:x.in>1}),t.jsx(i.AppIcon,{src:c==null?void 0:c.iconSvg,srcDark:c==null?void 0:c.iconSvgDark,brandColor:c==null?void 0:c.brandColor,name:l,size:28}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:g}),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($e,{type:"source",position:oe.Position.Right,multiple:x.out>1}),!p&&t.jsx($e,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),v,t.jsx(Mn,{step:n}),p&&n.uses.trigger===!0&&t.jsx(Ei,{nodeId:e}),s.loopOf&&t.jsx(Tn,{id:e}),t.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,c!=null&&c.version?` - v${c.version}`:""]}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ti({id:e,data:s,selected:o}){const n=s.step,a=i.routesForStep(n),c=n.uses.app===i.ROUTER_APP,l=i.isIfStep(n),p=a.length?i.routerPortLayout(a):l?i.ifPortLayout():void 0,h=JSON.stringify(a.map(N=>N.id)),g=oe.useUpdateNodeInternals();d.useEffect(()=>{g(e)},[e,h,g]);const x=i.internalNodeLabel(n.uses.app,n.uses.action),f=i.internalNodeIcon(n.uses.app,n.uses.action),v=i.nodePortsForStep(n,d.useContext(ns)),S=i.isTriggerStep(n.uses),I=Ci(n),L=Sn(s.stepStatus??"no-run",s.runStatus),m=t.jsx(Rn,{step:n,count:d.useContext(os).get(e)??0}),B=In(e);return t.jsxs("div",{className:[I?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",Ie(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:B,"data-disabled":Ie(n)||void 0,"data-paused":Xe(n)||void 0,children:[t.jsx(Pn,{id:e,step:n,runnable:!i.isControlApp(n.uses.app)}),t.jsxs("div",{className:S?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":S?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Ln(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${L.borderWidth}px ${L.borderStyle} ${o?"var(--w6w-accent)":L.borderColor}`,opacity:Ie(n)?.45:o?1:L.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...S?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...p!=null&&p.minHeight?{minHeight:p.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fn,{problems:s.stepProblems}),v.in>0&&t.jsx($e,{type:"target",position:oe.Position.Left,multiple:v.in>1}),f&&t.jsx(i.InternalIcon,{icon:f}),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||"—"})})]}),I&&t.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[t.jsx("span",{children:"Each item"}),t.jsx("span",{children:"Done"})]}),!!(p!=null&&p.right.length)&&t.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${p.right.length}, 1fr)`},"aria-hidden":"true",children:p.right.map(N=>t.jsx("span",{title:N.label,children:N.label},N.id))}),v.out>0&&t.jsxs(t.Fragment,{children:[I&&t.jsx($e,{type:"source",position:oe.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),p?t.jsxs(t.Fragment,{children:[p.right.map(N=>t.jsx($e,{type:"source",position:oe.Position.Right,multiple:!1,id:N.handleId,top:N.top,routeLabel:N.label},N.id)),p.bottom&&t.jsxs(t.Fragment,{children:[t.jsx($e,{type:"source",position:oe.Position.Bottom,multiple:!1,id:p.bottom.handleId,routeLabel:p.bottom.label}),t.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:p.bottom.label})]})]}):t.jsx($e,{type:"source",position:oe.Position.Right,multiple:v.out>1,id:I?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!S&&!c&&!l&&n.uses.app!==i.RACE_APP&&t.jsx($e,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),m,t.jsx(Mn,{step:n}),s.loopOf&&t.jsx(Tn,{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 Ii(e,s){var l,p;if(!s)return e;const o={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[h,g]of Object.entries(s)){const x=/^nodes\.([^.]+)\.output$/.exec(h);!x||((l=o[x[1]])==null?void 0:l.output)!==void 0||(o[x[1]]={...o[x[1]]??{},output:g},n=!0)}const a=s["trigger.event"],c=a!==void 0&&((p=e==null?void 0:e.trigger)==null?void 0:p.event)===void 0;return!n&&!c?e:{...e??{},...n?{steps:o}:{},...c?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Pi(e){return t.jsx(Ri,{...e})}function Ri({workflowId:e,step:s,restoreVersion:o,upstreamSteps:n,loop:a,onChange:c,onClose:l,readOnly:p,initialView:h="props",fanOutCount:g=0,stateOutputFields:x,onTestRun:f,stepProblems:v,otherStepIds:S}){var et,ht;const I=i.useW6WApi(),L=d.useContext(rs),[m,B]=d.useState(s),N=i.useWorkflowConnections(),z=i.connectionIdFor(m,N==null?void 0:N.connections),H={...m,uses:{...m.uses,connection:z}},A=m.uses.connectionRef!==void 0&&!z||i.isConnectionBlocked(H,v),R=v==null?void 0:v.find(T=>T.code==="unknown_connection"&&T.connection===z),W=(v??[]).filter(T=>"fix"in T),[V,ee]=d.useState(A?"setup":"configure"),[b,$]=d.useState(h==="json"?"code":h==="settings"?"config":"props"),[le,de]=d.useState("props"),[ve,te]=d.useState(()=>i.stepToJson(s)),[E,Z]=d.useState("{}"),P=d.useRef(null),[_,D]=d.useState(!1),q=d.useRef(o);d.useEffect(()=>{q.current!==o&&(q.current=o,B(s),te(i.stepToJson(s)))},[o,s]);const[O,J]=d.useState(null),[G,ue]=d.useState(null),[rt,at]=d.useState(null),[Be,Pe]=d.useState(!1),ae=i.isInternalApp(m.uses.app),Se=m.uses.trigger===!0;d.useEffect(()=>{if(ae){J(i.internalNodeParams(m.uses.app,m.uses.action));const Y=i.INTERNAL_NODES.filter(ne=>ne.app===m.uses.app&&ne.groupActions&&!ne.hidden);ue(Y.length?Y.map(ne=>({key:ne.action,title:ne.label,params:ne.params})):null);return}if(!m.uses.app){ue(null),J([]);return}let T=!1;return J(null),(Se?i.getTriggerDefs(I,m.uses.app):I.getAppActions(m.uses.app)).then(Y=>{var ne;T||(ue(Y),J(m.uses.action?((ne=Y.find(we=>we.key===m.uses.action))==null?void 0:ne.params)??[]:[]))}).catch(()=>!T&&J([])),()=>{T=!0}},[I,m.uses.app,m.uses.action,ae,Se]);const Re=d.useRef(0);d.useEffect(()=>()=>{Re.current++},[]);const Ye=d.useCallback(()=>{ae||!m.uses.app||I.listConnectionsForApp(m.uses.app).then(T=>{at(T),Pe(!1)}).catch(()=>Pe(!0))},[I,m.uses.app,ae]);d.useEffect(()=>{if(ae||!m.uses.app)return;let T=!1;return at(null),Pe(!1),I.listConnectionsForApp(m.uses.app).then(Y=>{T||(at(Y),Pe(!1))}).catch(()=>!T&&Pe(!0)),()=>{T=!0}},[I,m.uses.app,ae]);const K=d.useCallback(T=>{B(T),c(T)},[c]),Ce=bo({enabled:m.uses.app===i.SCRIPT_APP&&!p,values:m.with??{},onChange:T=>K({...m,with:T})}),Ve=T=>{T==="code"&&te(i.stepToJson(m)),$(T)},Me=T=>{const Y=i.stepNameError(T,S??[]);return Y||K({...m,id:T}),Y},Ne=!!m.uses.app&&!!m.uses.action&&!i.isControlApp(m.uses.app),Q=i.isForeachStep(m),pe=i.isTriggerStep(m.uses),Pt=V==="test"&&Ne&&!pe,He=i.useSeedSources(e,n,Ne&&!pe||Q),Le=kn(Ne&&!pe?a:void 0),Fe=i.startStateFromSeeds(He,En(Le)),De=Ii(Fe,i.useExpressionOptions().sampleValues),ke=i.useRememberedTestInput(Ne&&!pe||Q?e:void 0,m.id),[Ee,Ae]=d.useState(!1);d.useEffect(()=>{if((!Ne||pe)&&!Q||!ke.loaded)return;if(!Q&&ke.input!==void 0){const Y=ke.input;if(Object.keys(Y).length===0)return;const ne=JSON.stringify(Y,null,2);Z(we=>we.trim()==="{}"?ne:we),Ae(!0);return}let T=!1;return I.listStepTests(e,m.id).then(Y=>{if(T)return;const ne=Y.length?Y[Y.length-1]:null;if(!(ne!=null&&ne.input)||Object.keys(ne.input).length===0)return;const we=JSON.stringify(ne.input,null,2);Z(tt=>tt.trim()==="{}"?we:tt)}).catch(()=>{}),()=>{T=!0}},[I,e,m.id,Ne,pe,Q,ke.loaded]);const Ze=Q?yi(E):It(E),je={...m.with??{},...Ze??{}},fe=Ze??{},Oe=!!O&&!cs(Le)&&i.requiredParamsFilled(O,je),me=Q?i.resolveLoopItemsInState(je.items,Fe):void 0,[Te,Qe]=d.useState("idle"),ct=T=>{Z(T),Qe("idle")},ie=async()=>{if(me){Qe("saving");try{await I.saveStepTest(e,m.id,i.foreachTestFixture(me,fe)),Qe("saved")}catch{Qe("failed")}}},ce=L.get(m.uses.app),lt=ae?i.internalNodeIcon(m.uses.app,m.uses.action):null,ft=ae?lt?t.jsx(i.InternalIcon,{icon:lt}):null:t.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 t.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:ft,title:t.jsx(i.StepNameEditor,{value:m.id,onCommit:Me,readOnly:p}),onClose: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(T=>m.uses.app!==i.RACE_APP||T!=="test").map(T=>t.jsx("button",{type:"button",className:`w6w-subtab${V===T?" active":""}`,disabled:A&&T!=="setup",onClick:()=>ee(T),children:T==="setup"?"Setup":T==="configure"?"Configure":"Test"},T))}),Pt?t.jsx(i.ConfigViewToggle,{view:le,views:["props","code"],onChange:T=>de(T)}):t.jsx(i.ConfigViewToggle,{view:b,customized:i.hasParamCustomization(m.with??{}),onChange:Ve,disabled:V!=="configure"})]}),A&&R&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",R.connection," no longer exists — choose another to continue."]}),W.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:W.map(T=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:i.stepProblemTooltip(T)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":T.code,disabled:p,onClick:()=>{const Y=vn(m,T);K(Y),te(i.stepToJson(Y))},children:"fix"in T?T.fix.label:""})]},T.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[V==="setup"&&t.jsx(Oi,{step:m,app:ce,actions:G,conns:rt,connsFailed:Be,isInternal:ae,actionLabel:Se?"Trigger":"Action",readOnly:p,onChangeAction:T=>{var ne;const Y=ae?i.internalNodeDefaults(m.uses.app,T):{};if(ae)for(const we of i.internalNodeParams(m.uses.app,T))we.key in(m.with??{})&&(Y[we.key]=(ne=m.with)==null?void 0:ne[we.key]);K({...m,uses:{...m.uses,action:T},with:Y})},onChangeTriggerEvents:(T,Y)=>K({...m,uses:{...m.uses,action:T},with:{...m.with,actions:Y}}),onChangeConnection:T=>{if(!N){const{connectionRef:ne,...we}=m.uses;K({...m,uses:{...we,connection:T}});return}const Y=i.selectNodeConnection(m,T,(N==null?void 0:N.nodes)??[m],(N==null?void 0:N.connections)??{});N==null||N.setConnections(Y.connections),K(Y.step)},onChangeConnectionRef:T=>K(i.withConnectionRef(m,T)),onConnectionCreated:Ye,onChangeApp:T=>{const Y=++Re.current;if(T===m.uses.app){K(m);return}const ne={...m,uses:{app:T,action:"",...Se?{trigger:!0}:{}},with:{}};(i.isInternalApp(T)?Promise.resolve([]):I.listConnectionsForApp(T)).catch(()=>[]).then(we=>{if(Y!==Re.current)return;const tt=i.defaultConnectionFor(ne,we,(N==null?void 0:N.nodes)??[],(N==null?void 0:N.connections)??{});K({...ne,uses:{...ne.uses,...tt}})})}}),V==="configure"&&t.jsxs(t.Fragment,{children:[m.uses.app===i.WEBHOOK_APP&&I.listSubscriptionsForWorkflow&&I.createSubscription&&t.jsx(Di,{workflowId:e,step:m,readOnly:p}),O===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):b==="props"?m.uses.app===i.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):m.uses.action==="wait"&&i.isControlApp(m.uses.app)?t.jsx(i.WaitEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):m.uses.action==="if"&&i.isControlApp(m.uses.app)?t.jsx(i.ConditionEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):m.uses.app==="@w6w/stop"?t.jsx(i.StopEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):m.uses.app===i.ROUTER_APP?t.jsx(i.RouterEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):t.jsxs(t.Fragment,{children:[m.uses.app===i.SCRIPT_APP&&t.jsx(jo,{values:m.with??{},conversion:Ce,readOnly:p}),t.jsx(i.ParamsForm,{params:O,values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T}),dynamic:ae||!m.uses.action?void 0:{appId:m.uses.app,actionKey:m.uses.action,connectionId:A?void 0:z,appName:ce==null?void 0:ce.displayName}})]}):b==="code"?t.jsx(i.JsonEditor,{value:ve,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${m.id} JSON`,copyable:!0}):b==="params-code"?t.jsx(i.ParamCustomization,{values:m.with??{},onChange:T=>K({...m,with:T}),readOnly:p}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(i.NodeConfigForm,{config:{retry:m.retry,onError:m.onError,notes:m.notes},onChange:T=>K({...m,...T}),readOnly:p,failureHandling:!pe,retryControls:!i.isControlApp(m.uses.app)&&m.uses.app!==i.CALL_APP}),Mi,t.jsx(Li,{step:m,count:g,readOnly:p,onChange:K}),Yo(m)&&t.jsx(Fi,{step:m,inLoop:a!==void 0,outputFields:x,readOnly:p,onChange:K})]})]}),V==="test"&&t.jsx("div",{className:"w6w-stack",children:Ne?Se?t.jsx(i.AppTriggerTestNote,{title:((et=G==null?void 0:G.find(T=>T.key===m.uses.action))==null?void 0:et.title)??m.uses.action,app:(ce==null?void 0:ce.displayName)??m.uses.app}):pe?t.jsx(i.TriggerFillForm,{app:m.uses.app,action:m.uses.action,fields:(ht=m.with)==null?void 0:ht.fields,persist:{workflowId:e,stepId:m.id,input:fe},listen:m.uses.app===i.WEBHOOK_APP&&I.listSubscriptionsForWorkflow&&I.startWebhookListen?{stepWith:m.with,readOnly:p}:void 0}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",t.jsx("code",{children:m.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),t.jsx(An,{seed:Le,readOnly:p}),Ee&&!p&&t.jsx(i.LastUsedNote,{onClear:()=>{ke.clear(),Ae(!1),Z("{}")}}),t.jsx(es,{text:E,onChange:Z,seeds:He,readOnly:p}),O===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(ho,{params:O,values:je,testStartState:De,view:le,literalKeys:m.uses.app===i.SCRIPT_APP?ji:void 0}),t.jsx(i.StepTestRun,{ref:P,app:m.uses.app,action:m.uses.action,connectionId:z,values:je,state:Fe,canRun:Oe,hideRunButton:!0,persist:{workflowId:e,stepId:m.id,input:fe},onBusyChange:D})]}):Q?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(es,{text:E,onChange:ct,seeds:He,readOnly:p,expand:!me,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(vi,{items:me,save:Te})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),t.jsx("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:m.uses.app===i.RACE_APP&&V==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):V!=="test"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:A,onClick:()=>ee(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"}),Ne&&!pe&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!Oe||_,onClick:()=>{var T;f==null||f(),(T=P.current)==null||T.run()},children:_?"Testing…":"Test"}),Q&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(me!=null&&me.length)||Te==="saving",onClick:()=>void ie(),children:Te==="saving"?"Testing…":"Test"})]})})]})})}const Mi=!1;function Li({step:e,count:s,readOnly:o,onChange:n}){const a=s>=2,c=e.fanOut==="parallel"?"parallel":"sequential";return t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Run next nodes"}),t.jsxs("select",{"aria-label":"Run next nodes",value:c,disabled:o||!a,onChange:l=>n(Co(e,l.target.value)),children:[t.jsx("option",{value:"sequential",children:"In sequence"}),t.jsx("option",{value:"parallel",children:"In parallel"})]}),!a&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function rn({to:e}){return t.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[t.jsx("span",{children:"From this step output"}),t.jsx("span",{}),t.jsx("span",{children:e})]})}function an(){return t.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function cn({label:e,fields:s,value:o,readOnly:n,onChange:a}){const c=d.useMemo(()=>(s??[]).map(l=>({value:l,label:l})),[s]);return t.jsx(i.Combobox,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:c,value:o,disabled:n,emptyText:c.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:a})}function Fi({step:e,inLoop:s,outputFields:o,readOnly:n,onChange:a}){const c=qo(e),l=be.validateStateConfig(c),p=f=>a(Ko(e,f)),h=c.mode==="pick"&&Array.isArray(c.map)?c.map:[],g=(f,v)=>p({mode:"pick",map:h.map((S,I)=>I===f?{...S,...v}:S)}),x=f=>{if(c.mode!=="append")return;const v=f.path??c.path,S="from"in f?f.from:c.from;p({mode:"append",path:v,...S?{from:S}:{}})};return t.jsxs("div",{className:"w6w-field w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Write to state"}),t.jsx("select",{"aria-label":"Write to state",value:c.mode,disabled:n,onChange:f=>p(Xo(e,f.target.value)),children:Jo.map(f=>t.jsx("option",{value:f,children:Uo[f]},f))})]}),c.mode==="key"&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"To state key"}),t.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:c.key,disabled:n,onChange:f=>p({mode:"key",key:f.target.value})}),t.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",t.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",t.jsx("code",{children:"order.id"})," nests."]})]}),c.mode==="pick"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(rn,{to:"To state key"}),h.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),h.map((f,v)=>t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(cn,{label:"From output field",fields:o,value:f.from,readOnly:n,onChange:S=>g(v,{from:S})}),t.jsx(an,{}),t.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:f.to,disabled:n,onChange:S=>g(v,{to:S.target.value})}),!n&&t.jsx(i.DeleteButton,{label:"Remove field",onClick:()=>p({mode:"pick",map:h.filter((S,I)=>I!==v)})})]},v)),!n&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>p({mode:"pick",map:[...h,{from:"",to:""}]}),children:"+ Add field"}),t.jsxs("span",{className:"w6w-hint",children:["Copies ",t.jsx("code",{children:"output.<path>"})," into ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),c.mode==="append"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(rn,{to:"Append to state list"}),t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(cn,{label:"Output field to append",fields:o,value:c.from??"",readOnly:n,onChange:f=>x({from:f})}),t.jsx(an,{}),t.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:c.path,disabled:n,onChange:f=>x({path:f.target.value})})]}),t.jsxs("span",{className:"w6w-hint",children:["Appends ",t.jsx("code",{children:"output.<path>"})," to the list at ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),l.length>0&&t.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:l.map(f=>t.jsx("div",{children:f.message},`${f.code}:${f.message}`))}),c.mode!=="off"&&t.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",t.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),s&&t.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function Di({workflowId:e,step:s,readOnly:o}){const n=i.useW6WApi(),[a,c]=d.useState(void 0),[l,p]=d.useState(null),[h,g]=d.useState(!1);d.useEffect(()=>{const f=n.listSubscriptionsForWorkflow;if(!f)return;let v=!1;return f(e).then(S=>{v||c(i.pickWebhookSubscription(S,s.id))}).catch(S=>!v&&p(S.message)),()=>{v=!0}},[n,e,s.id]);const x=()=>{const f=n.createSubscription;f&&(p(null),g(!0),f(i.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(v=>{g(!1),c(v)}).catch(v=>{g(!1),p(v instanceof Error?v.message:String(v))}))};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(ye.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…"}):!o&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:h,onClick:x,children:h?"Creating…":"Create webhook URL"})]})}function Oi({step:e,app:s,actions:o,conns:n,connsFailed:a,isInternal:c,actionLabel:l="Action",readOnly:p,onChangeAction:h,onChangeTriggerEvents:g,onChangeConnection:x,onChangeConnectionRef:f,onChangeApp:v,onConnectionCreated:S}){const I=e.uses.trigger?i.eventbriteTriggerChoices(e.uses.app,o,e.uses.action,e.with??{}):null,[L,m]=d.useState(null),B=d.useRef(null),N=i.useWorkflowConnections(),z=i.connectionIdFor(e,N==null?void 0:N.connections);return t.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!z&&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:B,children:[t.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":L==="app",disabled:p,onClick:()=>m(H=>H==="app"?null:"app"),children:[!c&&s&&t.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:c?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!c&&t.jsx(i.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:p,open:L==="conn",onOpenChange:H=>m(H?"conn":null),anchorRef:B,onChangeConnection:x,onChangeConnectionRef:f,onConnectionCreated:S})]}),L==="app"&&t.jsx(i.AnchoredFlyout,{anchorRef:B,onClose:()=>m(null),children:t.jsx(i.AppPicker,{onSelectApp:H=>{const C=H.id===e.uses.app;v(H.id),m(C?"conn":null)}})})]}),c&&!(o!=null&&o.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})})]}):I?t.jsx(i.EventbriteTriggerPicker,{choices:I,readOnly:p,onChange:H=>g(I.triggerKey,H)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:l}),t.jsx(i.Combobox,{value:e.uses.action,disabled:p||o===null,onChange:h,options:o===null?[{value:e.uses.action,label:e.uses.action}]:o.map(H=>({value:H.key,label:H.title??H.key}))})]})]})}function ln({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 _i({resources:e}){const s=i.useW6WApi(),o=e.highlightNode;d.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,a]=d.useState([]),[c,l]=d.useState(!0),[p,h]=d.useState(),[g,x]=d.useState(),[f,v]=d.useState(null),[S,I]=d.useState(!1),[L,m]=d.useState(!1),B=d.useRef(0),N=d.useCallback(async()=>{const P=++B.current;l(!0),h(void 0);try{const _=await s.listConnections();return P!==B.current?void 0:(a(_),_)}catch(_){P===B.current&&h(_.message)}finally{P===B.current&&l(!1)}},[s]);d.useEffect(()=>(N(),()=>{B.current++}),[N]);const[z,H]=d.useState(new Map),C=JSON.stringify([...new Set([...Object.values(e.connections).map(P=>P.app),...n.map(P=>P.appId)])].filter(P=>{var _;return!((_=e.apps)!=null&&_.has(P))&&!n.some(D=>D.appId===P&&D.app!==void 0)}).sort());d.useEffect(()=>{var O,J;let P=!1;const _=JSON.parse(C);if(c||!_.length)return;const D=(O=s.listAppsByIds)==null?void 0:O.bind(s),q=D?Promise.all(Array.from({length:Math.ceil(_.length/50)},(G,ue)=>D(_.slice(ue*50,(ue+1)*50)))).then(G=>G.flat()):(J=s.listApps)==null?void 0:J.call(s);return q==null||q.then(G=>{P||H(new Map(G.map(ue=>[ue.id,ue])))}).catch(()=>{}),()=>{P=!0}},[s,C,c]);const A=P=>{var O;const _=n.find(J=>J.appId===P&&J.app)??n.find(J=>J.appId===P&&J.app!==void 0),D=_?i.resolveConnectionAppMeta(_,z):z.get(P),q=(O=e.apps)==null?void 0:O.get(P);return q?{...D,...q}:D},R=P=>{var _;return((_=A(P))==null?void 0:_.displayName)||P},W=P=>{if(e.readOnly)return!1;try{return e.edit(P),x(void 0),!0}catch(_){return x(_.message),!1}},V=P=>i.nextWorkflowConnectionName(P.appId,e.connections),ee=()=>{v(null),x(void 0),I(!1)},b=f!=null&&f.ref?e.connections[f.ref]:void 0,$=n.find(P=>P.id===(f==null?void 0:f.connection)),le=(b==null?void 0:b.app)??($==null?void 0:$.appId),de=e.nodes.filter(P=>P.uses.app===le),ve=e.nodes.filter(P=>(f==null?void 0:f.ref)!==void 0&&P.uses.connectionRef===f.ref),te=n.filter(P=>!b||P.appId===b.app).map(P=>({value:P.id,label:b?P.displayName||P.id:`${R(P.appId)} · ${P.displayName||P.id}`}));f!=null&&f.connection&&!te.some(P=>P.value===f.connection)&&te.unshift({value:f.connection,label:f.connection.startsWith("zerocred:")?"Built-in":f.connection});const E=(P,_=28)=>{const D=A(P);return t.jsx(i.AppIcon,{src:D==null?void 0:D.iconSvg,srcDark:D==null?void 0:D.iconSvgDark,brandColor:D==null?void 0:D.brandColor,name:R(P),size:_})},Z=()=>{if(!f||!f.name.trim()||!f.connection||!le)return;const P=f.ref!==void 0?{type:"update",ref:f.ref,name:f.name,connection:f.connection,nodeIds:f.allNodes?de.map(_=>_.id):void 0}:{type:"add",name:f.name,app:le,connection:f.connection};W(P)&&ee()};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(i.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{x(void 0),v({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"})})})]}),p&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",p]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void N(),children:"Retry"})]}),Object.entries(e.connections).map(([P,_])=>{var J;const D=e.nodes.filter(G=>G.uses.connectionRef===P),q=n.find(G=>G.id===_.connection),O=(q==null?void 0:q.displayName)||((J=_.connection)!=null&&J.startsWith("zerocred:")?"Built-in":_.connection)||"No credentials selected";return t.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":P,children:[t.jsxs("div",{className:"w6w-connection-app-heading",children:[E(_.app),t.jsxs("div",{className:"w6w-connection-summary",children:[t.jsx("strong",{children:R(_.app)}),t.jsx("span",{className:"w6w-small",children:O}),t.jsxs("span",{className:"w6w-muted w6w-small",children:[P,q!=null&&q.state?` · ${q.state}`:""]})]}),t.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${P}`,disabled:e.readOnly,onClick:()=>{x(void 0),v({ref:P,name:P,connection:_.connection??"",allNodes:!1})}})]}),D.length>0?t.jsxs("details",{className:"w6w-connection-consumers",onToggle:G=>{G.currentTarget.open||o==null||o(null)},children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",D.length," ",D.length===1?"node":"nodes"]}),t.jsx("ul",{className:"w6w-connection-node-list",children:D.map(G=>t.jsx("li",{children:e.focusNode?t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${G.id} on canvas`,onClick:()=>{var ue;return(ue=e.focusNode)==null?void 0:ue.call(e,G.id)},onMouseEnter:()=>o==null?void 0:o(G.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(G.id),onBlur:()=>o==null?void 0:o(null),children:[t.jsx(ln,{trigger:i.isTriggerStep(G.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:G.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:G.id})]})]}):t.jsxs("span",{className:"w6w-connection-app-heading",children:[t.jsx(ln,{trigger:i.isTriggerStep(G.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:G.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:G.id})]})]})},G.id))})]}):t.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},P)}),!Object.keys(e.connections).length&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),f&&!L&&!S&&t.jsxs(i.Modal,{title:f.ref!==void 0?"Edit connection":"Add connection",titleIcon:le?E(le):void 0,subtitle:le?R(le):void 0,onClose:ee,children:[t.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[g&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:g}),p&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",p]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void N(),children:"Retry"})]}),f.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:f.name,disabled:e.readOnly,onChange:P=>v({...f,name:P.target.value})})]}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:b?"Credentials":"Existing connection"}),t.jsx(i.Combobox,{"aria-label":b?"Credentials":"Connection to add",options:te,value:f.connection,placeholder:c?"Loading connections…":"Choose a connection…",disabled:e.readOnly||c||!!p,onChange:P=>{const _=n.find(D=>D.id===P);v({...f,connection:P,name:!f.name&&_?V(_):f.name})}})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>m(!0),children:"Create new credentials"}),b&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"w6w-muted w6w-small",children:f.allNodes?`Saving applies these credentials to all ${de.length} ${R(b.app)} nodes.`:`Saving updates credentials for ${ve.length} linked ${ve.length===1?"node":"nodes"}.`}),de.length>0&&t.jsxs("label",{className:"w6w-connection-scope",children:[t.jsx("input",{type:"checkbox",checked:f.allNodes||de.every(P=>P.uses.connectionRef===f.ref),disabled:e.readOnly||de.every(P=>P.uses.connectionRef===f.ref),onChange:P=>v({...f,allNodes:P.target.checked})}),"Use for all ",de.length," ",R(b.app)," ",de.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||ve.length>0,onClick:()=>I(!0),children:"Remove from workflow"}),ve.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:ee,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||c||!!p||!f.name.trim()||!f.connection||!le||f.ref!==void 0&&!b,onClick:Z,children:f.ref!==void 0?"Save changes":"Add to workflow"})]})]}),f&&S&&t.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${f.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>I(!1),onConfirm:()=>{f.ref&&W({type:"remove",ref:f.ref})?ee():I(!1)}}),f&&L&&t.jsx(i.AddConnectionModal,{initialAppId:b==null?void 0:b.app,onClose:()=>m(!1),onCreated:({connectionId:P})=>{m(!1),N().then(_=>{const D=_==null?void 0:_.find(q=>q.id===P);D&&v(q=>q?{...q,connection:D.id,name:q.name||V(D)}: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=dn;exports.MAX_NOTE_BYTES=pn;exports.MAX_SECTIONS=un;exports.WorkflowConnectionsPanel=_i;exports.WorkflowFlowEditor=xi;exports.applyStepProblemFix=vn;exports.assignMembership=Kt;exports.clampCanvas=Xt;exports.findLoopProblems=$o;exports.findStateWriteProblems=zo;exports.isDisabledStep=Ie;exports.isPausedStep=Xe;exports.pausedStopAt=Zt;exports.pruneSectionMembers=ts;exports.renameSectionMember=hn;exports.roundGeometry=Gt;exports.sectionsContaining=mn;exports.withCanvasGeometry=fn;exports.withDisabled=jn;exports.withPaused=bn;
5
5
  //# sourceMappingURL=flow.cjs.map