@w6w/ui 0.2.62 → 0.2.63
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/{CodeBlock-CPKXSNEs.js → CodeBlock-Bp0SGY1m.js} +82 -57
- package/dist/{CodeBlock-CPKXSNEs.js.map → CodeBlock-Bp0SGY1m.js.map} +1 -1
- package/dist/{CodeBlock-BSX1pi6W.cjs → CodeBlock-a2aIm-0b.cjs} +5 -5
- package/dist/{CodeBlock-BSX1pi6W.cjs.map → CodeBlock-a2aIm-0b.cjs.map} +1 -1
- package/dist/EditConnectionModal.d.ts +1 -1
- package/dist/code.cjs +1 -1
- package/dist/code.mjs +1 -1
- package/dist/components/CallableBindingSetup.d.ts +15 -0
- package/dist/components/ConnectionList.d.ts +1 -1
- package/dist/components/DataStoreList.d.ts +1 -1
- package/dist/components/DataTable.d.ts +6 -0
- package/dist/components/IconButton.d.ts +4 -0
- package/dist/components/RunCallable.d.ts +52 -0
- package/dist/components/expression-authoring.d.ts +3 -2
- package/dist/components/expression-dom.d.ts +30 -0
- package/dist/components/icons.d.ts +1 -1
- package/dist/{connection-app-meta-CIfXp2O-.js → connection-app-meta-HBKXI0nk.js} +2720 -2659
- package/dist/connection-app-meta-HBKXI0nk.js.map +1 -0
- package/dist/connection-app-meta-pnATcKeZ.cjs +26 -0
- package/dist/connection-app-meta-pnATcKeZ.cjs.map +1 -0
- package/dist/flow.cjs +1 -1
- package/dist/flow.mjs +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +1696 -1284
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +29 -0
- package/dist/run-callable.d.ts +50 -0
- package/dist/types.d.ts +4 -0
- package/package.json +2 -2
- package/src/styles/_connections.scss +1 -0
- package/src/styles/_data-stores.scss +26 -3
- package/src/styles/_data-table.scss +38 -1
- package/src/styles.css +74 -4
- package/dist/connection-app-meta-CIfXp2O-.js.map +0 -1
- package/dist/connection-app-meta-Cn39S3ED.cjs +0 -24
- package/dist/connection-app-meta-Cn39S3ED.cjs.map +0 -1
package/dist/flow.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";"use strict";var io=Object.defineProperty;var ro=(e,s,i)=>s in e?io(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var it=(e,s,i)=>ro(e,typeof s!="symbol"?s+"":s,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),oe=require("@xyflow/react"),c=require("react"),o=require("./connection-app-meta-Cn39S3ED.cjs"),Ee=require("./CodeBlock-BSX1pi6W.cjs"),Ie=require("@w6w/expr");function ao({x:e,y:s,items:i,onAction:n,onClose:a}){const u=c.useRef(null),[l,f]=c.useState({left:e,top:s});c.useLayoutEffect(()=>{const w=u.current,x=w==null?void 0:w.offsetParent;if(!w||!x)return;const g=w.offsetWidth,S=w.offsetHeight;f({left:e+g>x.clientWidth?Math.max(0,e-g):e,top:s+S>x.clientHeight?Math.max(0,s-S):s})},[e,s]),c.useEffect(()=>{var w,x;(x=(w=u.current)==null?void 0:w.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),c.useEffect(()=>{const w=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},x=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},g=()=>a(!1);return document.addEventListener("pointerdown",w,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",g),window.addEventListener("resize",g),()=>{document.removeEventListener("pointerdown",w,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",g),window.removeEventListener("resize",g)}},[a]);const p=w=>{w.disabled||(a(!1),n(w.action))};return t.jsx("div",{ref:u,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:w=>w.preventDefault(),onKeyDown:w=>{var v;w.stopPropagation();const x=[...((v=u.current)==null?void 0:v.querySelectorAll("[role=menuitem]"))??[]],g=x.indexOf(document.activeElement),S=R=>{var E;return(E=x[(R+x.length)%x.length])==null?void 0:E.focus()};if(w.key==="ArrowDown")S(g+1);else if(w.key==="ArrowUp")S(g<0?-1:g-1);else if(w.key==="Home")S(0);else if(w.key==="End")S(-1);else if(w.key==="Escape"||w.key==="Tab")a(!0);else if(w.key==="Enter"||w.key===" ")g>=0&&p(i[g]);else return;w.preventDefault()},children:i.map(w=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":w.disabled||void 0,className:`w6w-note-menu-item${w.danger?" danger":""}${w.separated?" separated":""}`,"data-action":w.action,onClick:()=>p(w),children:w.label},w.action))})}function co(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function lo({app:e,trigger:s,onUse:i}){const n=o.useW6WApi(),[a,u]=c.useState(null);return c.useEffect(()=>{var f;let l=!1;return u(null),(f=n.getAppTriggers)==null||f.call(n,e).then(p=>{var w;l||u(co((w=p.find(x=>x.key===s))==null?void 0:w.sample))}).catch(()=>{}),()=>{l=!0}},[n,e,s]),a?t.jsx("div",{children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>i(a),children:"Use sample event"})}):null}function uo(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function po(e,s,i={}){const n=[],a=e.length;if(a>0){const u=a>1?` ${a} nodes`:"";n.push({action:"duplicate",label:`Duplicate${u}`,disabled:s}),a===1&&i.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${u}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:a>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const mn=200,gn=200,wn=10240;function Zt(e){const s={};for(const[i,n]of Object.entries(e))s[i]=Math.round(n);return s}const fo=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),ho=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Ys(e,s,i){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],u=fo(a==null?void 0:a.position)?a.position:n.position,l=ho(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Zt(u),size:Zt(l)}})}function xn(e,s,i){if(!s)return e;const n={...e};return e.notes&&(n.notes=Ys(e.notes,i)),e.sections&&(n.sections=Ys(e.sections,i)),n}function rs(e,s){return e.sections?{...e,sections:e.sections.map(i=>({...i,nodes:i.nodes.filter(n=>n!==s)}))}:e}function Qt(e,s,i){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?i:a)}))}:e}function es(e,s,i){if(!e.sections)return e;const n=new Set(i);return{...e,sections:e.sections.map(a=>{const u=a.nodes.filter(l=>!n.has(l));return a.id===s?{...a,nodes:[...new Set([...u,...i])]}:{...a,nodes:u}})}}function bn(e,s){return(e.sections??[]).filter(i=>i.nodes.includes(s)).map(i=>i.id)}function mo(e,s){const i=new TextEncoder;if(i.encode(e).length<=s)return e;let n="",a=0;for(const u of e){const l=i.encode(u).length;if(a+l>s)break;n+=u,a+=l}return n}function ts(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,mn).map(i=>({...i,content:mo(i.content,wn)}))),e.sections&&(s.sections=e.sections.slice(0,gn)),s}function go(e,s,i){const n={};for(const l of[...e.notes??[],...e.sections??[]])n[l.id]={position:l.position,size:l.size};const a=(l,f)=>l==null?void 0:l.map(p=>{const w=f==null?void 0:f.find(x=>x.id===p.id);return w?{...p,position:w.position,size:w.size}:p}),u=i?e:{...e,...e.notes?{notes:a(e.notes,s==null?void 0:s.notes)}:{},...e.sections?{sections:a(e.sections,s==null?void 0:s.sections)}:{}};return xn(u,i,n)}const Zs=220;function wo(e){return e.length<=Zs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Zs).trimEnd(),clipped:!0,length:e.length}}function xo({params:e,values:s,testStartState:i,view:n="props",literalKeys:a}){const{sampleValues:u,nodeConfig:l,nodeMeta:f}=o.useExpressionOptions(),p=c.useMemo(()=>o.buildResolveScope(u,i,l,f),[u,i,l,f]),w=o.flattenParams(e),x=v=>{var R;return s[v]!==void 0?s[v]:(R=w.find(E=>E.key===v))==null?void 0:R.default},g=w.filter(v=>v.type!=="section"&&o.isParamVisible(v,x)).map(v=>Ie.effectiveParam(v,x));if(o.hasParamCustomization(s)){const v=o.previewCustomization(s.$merge,p,a),R=v!==null&&typeof v=="object"&&!Array.isArray(v),E=Qs(g,s,p,a);for(const[h,A]of Object.entries(s))h!=="$merge"&&(E[h]=a!=null&&a.includes(h)?A:o.previewCustomization(A,p));const D=R?{...E,...v}:E;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:R?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(v)}). Test the step to validate it.`}),n==="code"?t.jsx(o.JsonEditor,{value:JSON.stringify(D,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):t.jsx("div",{className:"w6w-resolved-table",children:Object.entries(D).map(([h,A])=>{var O;return t.jsx(ss,{label:((O=w.find(U=>U.key===h))==null?void 0:O.label)??h,segments:[{status:"resolved",value:A}]},h)})})]})}if(n==="code"){const v=Qs(g,s,p,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(o.JsonEditor,{value:JSON.stringify(v,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=g.filter(v=>!o.deepEqual(x(v.key),v.default));return g.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):S.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):t.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:S.map(v=>v.type==="vars"?t.jsx(bo,{param:v,value:s[v.key],scope:p},v.key):t.jsx(ss,{label:v.label??v.key,segments:a!=null&&a.includes(v.key)?[{status:"resolved",value:x(v.key)}]:o.resolveParamValue(x(v.key),p)},v.key))})}function Qs(e,s,i,n){const a={};for(const u of e)if(n!=null&&n.includes(u.key))a[u.key]=s[u.key]!==void 0?s[u.key]:u.default;else if(u.type==="vars"){const l=s[u.key]??u.default??[],f=o.dataVarRows(l);a[u.key]=f?o.resolveVarsJson(f,i):o.resolveParamJson(l,i)}else a[u.key]=o.resolveParamJson(s[u.key]!==void 0?s[u.key]:u.default,i);return a}function ss({label:e,segments:s}){return t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e}),t.jsx("div",{className:"w6w-resolved-value",children:t.jsx(yn,{segments:s})})]})}function bo({param:e,value:s,scope:i}){const n=s??e.default??[],a=o.dataVarRows(n);return a===null?t.jsx(ss,{label:e.label??e.key,segments:o.resolveParamValue(n,i)}):t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e.label??e.key}),a.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):t.jsx("div",{className:"w6w-stack",children:a.map((u,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:u.key||"(no key)"})," → ",t.jsx(yn,{segments:o.resolveParamValue(u.value,i)})]},l))})]})}function yn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,i)=>t.jsx(yo,{segment:s},i))})}function yo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx(en,{value:e.value})]}):t.jsx(en,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(ft,{kind:"secret",refName:e.ref})}}function en({value:e}){const[s,i]=c.useState(!1),n=vo(e),a=wo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(Ee.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:t.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):t.jsxs("span",{children:[a.text,"…"]}),t.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>i(u=>!u),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const jo={var:"◆",secret:"🔒",expr:"ƒ"};function ft({kind:e,refName:s}){const i=e==="expr"?"expr":o.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:jo[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:i})]})}function vo(e){if(e===null)return"null";if(e===void 0)return"(not set)";if(e==="")return'""';if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function jn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function So({enabled:e,values:s,onChange:i}){const[n,a]=c.useState(null),u=c.useRef(!1),l=typeof s.code=="string"?s.code:"";return c.useEffect(()=>{if(!e||u.current)return;u.current=!0;const f=o.convertCodeBindingsToReads(l,jn(s));f.converted!==0&&(a({original:l,converted:f.converted}),i({...s,code:f.code}))},[e,l,s,i]),n?{converted:n.converted,undo:()=>{i({...s,code:n.original}),a(null)}}:null}function Co({values:e,conversion:s,readOnly:i}){const n=typeof e.code=="string"?e.code:"",a=s,u=o.findCodeBindings(n,jn(e)).length;return!a&&u===0?null:t.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[a&&t.jsxs(t.Fragment,{children:["Converted ",a.converted," reference",a.converted===1?"":"s"," to code reads",!i&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),u>0&&" · "]}),u>0&&t.jsxs(t.Fragment,{children:[u," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",u===1?"s":""," literal text — read ",u===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function tn(e,s){return{nodeIds:e.filter(i=>i.selected).map(i=>i.id),edgeIds:s.filter(i=>i.selected).map(i=>i.id)}}function No(e,s,i,n){const a=new Set(e.nodeIds),u=new Set(e.edgeIds),l=s.filter(g=>a.has(g.id)),f=[...l.filter(g=>o.isForeachStep(g.data.step)),...l.filter(g=>!o.isForeachStep(g.data.step))];let p=s,w=i,x=n;for(const g of f)w=o.bridgeDeletedBodyStep(g.id,p,w),p=p.filter(S=>S.id!==g.id),x=rs(x,g.id);return{nodes:p,edges:w.filter(g=>!u.has(g.id)),canvas:x}}function ko(e,s,i){var f;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),u=i.filter(p=>a.has(p.id)&&!n.has(p.source)&&!n.has(p.target)),l=[];if(n.size===1)l.push(o.deleteStepMessage(e.nodeIds[0],s,i));else if(n.size>1){l.push(`Delete nodes ${[...n].map(w=>`"${w}"`).join(", ")}? Their connections are removed too.`);const p=new Set;for(const w of n)if(o.isForeachStep((f=s.find(x=>x.id===w))==null?void 0:f.data.step))for(const x of o.loopBody(w,s,i))n.has(x)||p.add(x);p.size&&l.push(`Loop body steps ${[...p].map(w=>`"${w}"`).join(", ")} stay as standalone steps.`)}return u.length&&l.push(`Delete ${u.length===1?"connection":"connections"} ${u.map(p=>`"${p.source} → ${p.target}"`).join(", ")}?`),l.join(" ")}function Lt(e,s,i,n,a){const u=o.flowToWorkflow({...e,connections:n},s,i);return{nodes:u.nodes.map(({with:l,...f})=>l&&Object.keys(l).length?{...f,with:l}:f),edges:u.edges??[],connections:u.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Eo(e,s){const i=o.workflowToFlow({...e,...s});return{...i,nodes:i.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class To{constructor(s,i=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(this,"limit");this.limit=i,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,i){const n=JSON.stringify(s);n!==this.present&&((!i||i!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=i,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const i=this.past.lastIndexOf(s);return i>=0&&(this.past.length=i),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Gt(e){var i;const s=e;return!!(s!=null&&s.isContentEditable||(i=s==null?void 0:s.closest)!=null&&i.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Io=64,ht=24,Ze=32;function Ft(e){var s,i;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((i=e.measured)==null?void 0:i.height)??e.height??64}}function Ao(e,s){return e.x<s.x+s.width&&e.x+e.width>s.x&&e.y<s.y+s.height&&e.y+e.height>s.y}function Po(e){const s=(a,u)=>{const l=new Map;for(const w of e){const x=w.position[a];l.set(x,Math.max(l.get(x)??0,Ft(w)[u]))}const f=new Map;let p=Number.NEGATIVE_INFINITY;for(const[w,x]of[...l].sort(([g],[S])=>g-S)){const g=Math.max(w,p);f.set(w,g),p=g+x+Io}return f},i=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:i.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Ro(e,s,i){var f;const n=Po(o.relayoutNodes(e,s));if(!((f=i.sections)!=null&&f.length))return{nodes:n,canvas:i};const a=new Map(n.map(p=>[p.id,p])),u=(i.notes??[]).map(p=>({...p.position,...p.size}));for(const p of i.sections)p.nodes.some(w=>a.has(w))||u.push({...p.position,...p.size,y:p.position.y-Ze,height:p.size.height+Ze});const l=i.sections.map(p=>{const w=new Set(p.nodes),x=n.filter(A=>w.has(A.id));if(!x.length)return p;const g=Math.min(...x.map(A=>A.position.x))-ht,S=Math.min(...x.map(A=>A.position.y))-ht,v=Math.max(...x.map(A=>A.position.x+Ft(A).width)),R=Math.max(...x.map(A=>A.position.y+Ft(A).height)),E={x:g,y:S,width:v+ht-g,height:R+ht-S},D=[...u,...[...a.values()].filter(A=>!w.has(A.id)).map(A=>({...A.position,...Ft(A)}))].sort((A,O)=>A.y-O.y);for(const A of D){const O={...E,y:E.y-Ze,height:E.height+Ze};Ao(O,A)&&(E.y=A.y+A.height+ht+Ze)}const h=E.y-S;for(const A of x)a.set(A.id,{...A,position:{x:A.position.x,y:A.position.y+h}});return u.push({...E,y:E.y-Ze,height:E.height+Ze}),{...p,position:{x:E.x,y:E.y},size:{width:E.width,height:E.height}}});return{nodes:n.map(p=>a.get(p.id)??p),canvas:{...i,sections:l}}}const Kt=6;function Mo(e){let s=2166136261;for(let i=0;i<e.length;i++)s^=e.charCodeAt(i),s=Math.imul(s,16777619);return s>>>0}function Lo(e){const s=new Map;let i=new Set;for(const n of[...new Set(e)].sort()){i.size===Kt&&(i=new Set);let a=Mo(n)%Kt;for(;i.has(a);)a=(a+1)%Kt;i.add(a),s.set(n,a+1)}return s}function as(e){return`var(--w6w-loop-${e})`}function vn(e,s){const i=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),i.unshift(a);return i}function Fo(e,s,i){return s.size===0?e:e.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const a=n.sourceHandle===o.EACH_SOURCE_HANDLE?n.source:i.get(n.source),u=a?s.get(a):void 0;return u===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":as(u)}}})}function Do(e,s){const i=s.get(e);return i===void 0?void 0:{"--w6w-loop-color":as(i)}}function Oo(e){const s=[];for(const i of e){const n=o.isForeachStep(i.data.step);(n||i.data.loopOf)&&s.push([i.id,n?1:0,i.data.loopOf])}return JSON.stringify(s)}function _o(e){const s=JSON.parse(e);return{tones:Lo(s.filter(i=>i[1]===1).map(i=>i[0])),loopOf:new Map(s.map(i=>[i[0],i[2]]))}}const sn="Paused — test runs stop before this node",nn="Disabled — skipped in every run";function Qe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function We(e){return e.disabled===!0}function Sn(e,s){const{ui:i,...n}=e,{paused:a,...u}=i??{},l=s?{...u,paused:!0}:u;return Object.keys(l).length>0?{...n,ui:l}:n}function Cn(e,s){const{disabled:i,...n}=e;return s?{...n,disabled:!0}:n}function ns(e,s){return e.filter(i=>i.id!==s&&Qe(i)).map(i=>i.id)}const Wo=["nodes","steps"];function on(e,s){for(const i of Wo){const n=`${i}.${s}.output`;if(!e.startsWith(n))continue;const a=e.slice(n.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function Dt(e,s,i){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=o.parseRootAnchoredTemplate(e);let a=!1;const u=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const f=on(l.ref,s);return f===null?l:(a=!0,i.includes(l.ref)||i.push(l.ref),{...l,ref:f})});return a?Ie.serializeTemplate(u):e}if(o.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=on(n,s);return a===null?e:(i.includes(n)||i.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(u=>{const l=Dt(u,s,i);return l!==u&&(n=!0),l});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[u,l]of Object.entries(e)){const f=Dt(l,s,i);f!==l&&(n=!0),a[u]=f}return n?a:e}return e}function $o(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=o.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return o.isDollarPath(e)&&typeof e.$=="string"}function Nn(e){return Array.isArray(e)&&e.length===1&&$o(e[0])}function Bo(e){var s;try{const i=o.normalizeInput(e);if(!Array.isArray(i.nodes))return{};const n={},a=(l,f)=>{const p=Object.hasOwn(n,l)?n[l]:[];p.push(f),n[l]=p},u=new Map(i.nodes.map(l=>[l.id,l]));for(const[l,f]of Object.entries(o.definitionLoops(i))){const p=u.get(l);if(p&&Nn((s=p.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){a(l,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const w of f.body){const x=u.get(w);if(!(x!=null&&x.with))continue;const g=[];Dt(x.with,l,g),g.length>0&&a(w,{code:"foreach_body_refs_output",foreachId:l,refs:g,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function Vo(e){const s=new Set,i=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)i(a)};return i(e),s}function zo(e){var s,i;try{const n=o.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(P=>typeof P=="object"&&P!==null&&typeof P.id=="string"),u=o.effectiveEdges({...n,nodes:a}).filter(P=>typeof(P==null?void 0:P.from)=="string"&&typeof(P==null?void 0:P.to)=="string"),l=[];for(const P of a)try{const M=Ie.staticWritePaths(Ie.effectiveStateConfig((s=P.uses)==null?void 0:s.app,(i=P.uses)==null?void 0:i.action,P.state));M.length>0&&l.push({id:P.id,paths:M})}catch{}if(l.length<2)return[];const f=new Map;for(const P of a)for(const M of o.controlOwnedIds(P))f.has(M)||f.set(M,P.id);const p=P=>{const M=[P];let C=P;for(;f.has(C)&&(C=f.get(C),!M.includes(C));)M.push(C);return M},w=P=>{const M=p(P);return M[M.length-1]},x=new Map;for(const P of u){const M=x.get(P.from)??[];M.push(P.to),x.set(P.from,M)}const g=new Map,S=P=>{const M=g.get(P);if(M)return M;const C=new Set,$=[...x.get(P)??[]];for(;$.length>0;){const K=$.pop();if(!C.has(K)){C.add(K);for(const V of x.get(K)??[])$.push(V)}}return g.set(P,C),C},v=(P,M)=>P===M||S(P).has(M),R=a.filter(P=>{var M;return((M=P.uses)==null?void 0:M.app)===o.CONTROL_APP&&P.uses.action==="parallel"}).map(P=>{var C;const M=(C=P.with)==null?void 0:C.branches;return Array.isArray(M)?M.map(Vo):[]}),E=(P,M)=>{for(const C of p(M)){const $=P.findIndex(K=>K.has(C));if($>=0)return $}return-1},D=[];for(const P of a){if(P.fanOut!=="parallel")continue;const M=new Map;for(const C of u){if(C.from!==P.id||o.isEachLink(C))continue;const $=C.when??"success",K=M.get($)??[];K.push(C.to),M.set($,K)}for(const C of M.values())C.length>=2&&D.push(C)}const h=(P,M)=>{for(const K of R){const V=E(K,P),b=E(K,M);if(V>=0&&b>=0&&V!==b)return!0}const C=w(P),$=w(M);return C===$||S(C).has($)||S($).has(C)?!1:D.some(K=>K.some((V,b)=>K.some((_,de)=>b!==de&&v(V,C)&&v(_,$))))},A=new Set,O=[];for(let P=0;P<l.length;P++)for(let M=P+1;M<l.length;M++){const C=l[P],$=l[M];if(!(C.id===$.id||!h(C.id,$.id)))for(const K of C.paths)for(const V of $.paths){if(!Ie.statePathsOverlap(K,V))continue;const b={code:"state_parallel_write",nodes:[C.id,$.id].sort(),path:[...K.length<=V.length?K:V]},_=JSON.stringify([b.nodes,b.path]);A.has(_)||(A.add(_),O.push(b))}}const U=(P,M)=>P<M?-1:P>M?1:0;return O.sort((P,M)=>U(P.code,M.code)||U(P.nodes.join(","),M.nodes.join(","))||U(P.path.join("."),M.path.join(".")))}catch{return[]}}function Ho(e){try{const s={};for(const i of zo(e))for(const n of i.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:i.code,path:[...i.path],with:i.nodes.filter(u=>u!==n)}),s[n]=a}return s}catch{return{}}}function kn(e,s){var i;if(s.code==="foreach_wrapped_items"){const n=(i=e.with)==null?void 0:i.items;return!e.with||!Nn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=Dt(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function rn(e,s,i){return e&&e.nodeId===s&&e.handleType===((i==null?void 0:i.type)??"source")?o.laneForSourceHandle(e.handleId):o.laneForSourceHandle(i==null?void 0:i.id)}function Jo(e,s,i,n,a){var w;const u=(w=n.find(x=>x.id===e))==null?void 0:w.data.step,l=o.loopMembership(n,a)[e]!==void 0,f=i==="success"&&l?"each":i;if(f==="each"&&!l&&!o.isForeachStep(u))return null;const p=i==="success"&&o.isForeachStep(u)?o.FOREACH_DONE_ROUTE:void 0;return o.loopRefusal(e,s,f,n,a,p)}function Ot(e,s){var i;return(i=e.nodes??e.steps)==null?void 0:i[s]}function os(e,s){const i=Ot(e,s);return(i==null?void 0:i.status)==="skipped"&&i.skipReason==="not_on_path"}const Uo=new Set(["succeeded","failed","canceled"]);function qo(e,s,i=[]){var u,l;if(!e||[...i,s].some(f=>os(e,f)))return"no-run";const n=Ot(e,s);if(n)return n.status;const a=new Set;for(const f of Object.values(e.nodes??e.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const p of f.iterations){const w=(l=(u=p==null?void 0:p.nodes)==null?void 0:u[s])==null?void 0:l.status;w&&a.add(w)}for(const f of["failed","running","succeeded","skipped"])if(a.has(f))return f;return"pending"}const an={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function En(e,s){const i=s!==void 0&&Uo.has(s);switch(e){case"no-run":return an;case"pending":return i?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return an}}function Go(e,s,i,n,a){var l;if(!e||os(e,s)||a!==void 0&&os(e,a))return;const u=Ko(e,s,i,n);return u==="taken"&&a!==void 0&&((l=Ot(e,a))==null?void 0:l.status)==="skipped"?"skipped":u}function Ko(e,s,i,n){const a=Ot(e,s);if(!a)return;if(i==="each")return a.status==="skipped"?"skipped":void 0;const u=i??"success",l=a.output,f=n===o.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!f&&a.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(a.status==="succeeded")return u==="success"?"taken":"skipped";if(a.status==="failed")return u==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const cn={fields:[],sampleValues:{}};function cs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Xo(e,s){var w;const i=e.map(x=>x.id),n=new Set(i),a=new Map(i.map(x=>[x,0])),u=new Map(i.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((w=u.get(x.source))==null||w.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const l=[],f=i.filter(x=>a.get(x)===0);for(;f.length>0;){const x=f.shift();l.push(x);for(const g of u.get(x)??[]){const S=(a.get(g)??0)-1;a.set(g,S),S===0&&f.push(g)}}const p=new Set(l);for(const x of i)p.has(x)||l.push(x);return l}const Yo=new Set(["string","number","boolean","object","array"]);function mt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let i=!1;for(const n of e){if(!cs(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let u=s;for(const p of a.slice(0,-1)){const w=u.fields[p];(w==null?void 0:w.type)!=="object"&&(u.fields[p]={type:"object",fields:{}}),u=u.fields[p]}const l=typeof n.type=="string"&&Yo.has(n.type)?n.type:"string";let f;if(l==="array"){const p=mt(n.items);f=p?{type:"array",items:p}:{type:"array"}}else l==="object"?f=mt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:l};u.fields[a[a.length-1]]=f,i=!0}return i?s:void 0}function Zo(e,s){var w,x,g,S,v,R,E;const i=e.data.step,n=((w=s.testOutputs)==null?void 0:w[i.id])??((x=s.persistedOutputs)==null?void 0:x[i.id]);if(n!=null)return n;const{app:a,action:u}=i.uses;if(a===o.TRIGGER_APP&&((g=o.internalNodeDef(a,u))==null?void 0:g.group)==="trigger"){const D=o.fieldsToParams(o.asFieldDefs((S=i.with)==null?void 0:S.fields)).map(h=>({key:h.key}));return o.shapeToSkeleton(mt(D))}const l=(v=o.internalNodeDef(a,u))==null?void 0:v.output;if(l&&l.length>0)return o.shapeToSkeleton(mt(l));const f=i.uses.trigger===!0?(R=s.triggerDef)==null?void 0:R.call(s,a,u):(E=s.actionDef)==null?void 0:E.call(s,a,u),p=mt(f==null?void 0:f.output);return p?o.shapeToSkeleton(p):f==null?void 0:f.sample}function Qo(e,s){var f,p,w,x,g;const i=e.data.step,n=(f=s.previewOutputs)==null?void 0:f[i.id];if(n!=null)return n;const{app:a,action:u}=i.uses,l=i.uses.trigger===!0?(w=(p=s.shapes)==null?void 0:p.triggerDef)==null?void 0:w.call(p,a,u):(g=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:g.call(x,a,u);return l==null?void 0:l.sample}function ei(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function ln(e,s){const i=cs(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?i[n.key]=n.default:s||(i[n.key]=ei(n.type)));return i}function Xt(e){return(o.inferOutputFields(e)??[]).map(s=>s.key)}function ti(e){const{anchorId:s,nodes:i,edges:n}=e;if(!s)return cn;const a=e.shapes??{},u=e.floating?new Set(i.map(C=>C.id)):o.ancestorIds(s,n);u.delete(s);const l=new Map(i.map(C=>[C.id,C])),f=[],p=[],w=new Map;for(const C of Xo(i,n)){if(!u.has(C))continue;const $=l.get(C);if(!$)continue;const{app:K,action:V}=$.data.step.uses,b=Ie.effectiveStateConfig(K,V,$.data.step.state);if(b.mode==="off")continue;const _=Zo($,a);if(_!==void 0){const{ops:ue}=Ie.computeStateWrites(b,_);f.push(...ue);for(const je of Xt(Ie.foldState({},ue))){const ie=w.get(je)??new Set;ie.add(C),w.set(je,ie)}}const de=Qo($,e);de!==void 0&&p.push(...Ie.computeStateWrites(b,de).ops)}const x=ln(e,!1),g=Ie.foldState(x,f),S=Xt(g);if(S.length===0)return cn;const v=new Set(Xt(x)),R=new Map,E=new Map;for(const C of n)u.has(C.source)&&(!u.has(C.target)&&C.target!==s||(R.set(C.target,[...R.get(C.target)??[],C.source]),E.set(C.source,[...E.get(C.source)??[],C.target])));const D=[...u].filter(C=>!(R.get(C)??[]).length),h=C=>{const $=new Set,K=D.filter(V=>!C.has(V));for(;K.length>0;){const V=K.pop();if(V===s)return!1;if(!$.has(V)){$.add(V);for(const b of E.get(V)??[])C.has(b)||K.push(b)}}return!0},A=Ie.foldState(ln(e,!0),p),O=p.length>0?Ie.foldState({},p):void 0,U=cs(O)&&Object.keys(O).length>0?O:void 0,P=[],M={};for(const C of S){const $=w.get(C)??new Set,K=v.has(C)||$.size>0&&h($);P.push({key:C,path:!0,paths:K?"all":"some"});const V=o.valueAtPath(A,C);V!==void 0&&(M[`state.${C}`]=V)}return{fields:P,sampleValues:M,...U?{written:U}:{}}}const si={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},dn="Never fired";function ni(e){if(!e)return dn;const s=new Date(e);return Number.isNaN(s.getTime())?dn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function oi(e,s){var a;if(!(e!=null&&e.status))return null;const i=si[e.status];if(!i)return null;const n=e.status==="failed";return{label:i.label,tone:i.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:ni(e.lastFireAt),retryVisible:n&&s}}function ii(e){const s=new Map;for(const i of e)i.nodeId&&s.set(i.nodeId,i);return s}function ri(e){return(e??[]).filter(s=>{var i;return((i=s.uses)==null?void 0:i.trigger)===!0})}function ai(e,s){const[i,n]=c.useState({}),a=c.useRef(new Set),u=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!o.isInternalApp(l)).sort());return c.useEffect(()=>{const l=JSON.parse(u).filter(f=>!a.current.has(f));if(l.length!==0){for(const f of l)a.current.add(f);Promise.all(l.map(async f=>{try{return[f,await e.getAppActions(f)]}catch{return a.current.delete(f),null}})).then(f=>{const p=f.filter(w=>w!==null);p.length!==0&&n(w=>({...w,...Object.fromEntries(p)}))})}},[e,u]),i}function ci(e,s){const[i,n]=c.useState({}),a=c.useRef(new Set),u=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!o.isInternalApp(l)).sort());return c.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const f=JSON.parse(u).filter(p=>!a.current.has(p));if(f.length!==0){for(const p of f)a.current.add(p);Promise.all(f.map(async p=>{try{return[p,await l.call(e,p)]}catch{return a.current.delete(p),null}})).then(p=>{const w=p.filter(x=>x!==null);w.length!==0&&n(x=>({...x,...Object.fromEntries(w)}))})}},[e,u]),i}function li(e){return(s,i)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(u=>u.key===i))==null?void 0:a.ports}}const di="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function un(e,s,i,n){const a=e.find(u=>u.id===s);return[i,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ls=c.createContext(void 0),ds=c.createContext(new Map),us=c.createContext({tones:new Map,loopOf:new Map});function pn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const ps=c.createContext(new Map),Tn=c.createContext({byNode:new Map,subs:[]});function ui({apps:e,registration:s,children:i}){return t.jsx(ps.Provider,{value:e,children:t.jsx(Tn.Provider,{value:s,children:i})})}const fs=c.createContext(null);function pi(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(fi,{...e})})}function fn(e,s){let i=s.length+1;for(;s.includes(`${e}-${i}`);)i++;return`${e}-${i}`}function Yt(e){var s,i;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((i=e.measured)==null?void 0:i.height)??e.height??64}}function fi({onConnectionResourcesChange:e,value:s,onChange:i,readOnly:n,height:a=480,apps:u,exprOptions:l,project:f,runState:p,stepProblems:w,onTestRun:x,fitViewKey:g,onRunFromNode:S}){var Hs,Js,Us,qs,Gs,Ks,Xs;const v=o.useW6WApi(),R=c.useMemo(()=>new Map((u??[]).map(r=>[r.id,r])),[u]),E=yi(s),[D,h]=c.useState(null),A=c.useMemo(()=>o.centralizeConnections(s),[s.id]),O=c.useMemo(()=>o.workflowToFlow(A),[A]),[U,P]=c.useState(A.connections??{}),M=c.useRef(U),C=c.useCallback(r=>{M.current=r,P(r)},[]),$=c.useCallback(r=>{const d=o.centralizeConnections({nodes:[r],connections:M.current});return d.connections!==M.current&&C(d.connections),d.nodes[0]},[C]),K=c.useMemo(()=>o.storedViewport(s),[s.id]),V=((Hs=s.settings)==null?void 0:Hs.savePosition)!==!1,[b,_,de]=oe.useNodesState(O.nodes),ue=ai(v,b),je=ci(v,b),ie=c.useMemo(()=>li(ue),[ue]),[k,X,T]=oe.useEdgesState(O.edges),[W,B]=c.useState(null),ee=c.useMemo(()=>s.canvas??{},[s.id]),[H,z]=c.useState(ee),[J]=c.useState(()=>new To(Lt(A,O.nodes,O.edges,U,ee))),Z=c.useRef(),[pe,Je]=c.useState(0),[De,rt]=c.useState(!1),[ve,Ue]=c.useState(null),[Ae,ge]=c.useState(null),[ae,Ne]=c.useState(null),[$e,te]=c.useState(!1),gt=c.useRef({});c.useEffect(()=>{$e||(gt.current={})},[$e]);const[re,Pe]=c.useState(null),[Oe,ke]=c.useState("props"),[we,qe]=c.useState(null),[ye,Be]=c.useState(null),[Re,Me]=c.useState(null),at=c.useRef(!1),Se=c.useRef(null),[xe,_e]=c.useState(null),{screenToFlowPosition:Le,fitView:Fe}=oe.useReactFlow(),ct=o.useEffectiveTheme();c.useEffect(()=>{_(O.nodes),X(O.edges),B(null),Ne(null),Me(null),Pe(null),qe(null),z(ee),C(A.connections??{}),J.reset(Lt(A,O.nodes,O.edges,A.connections??{},ee)),Z.current=void 0},[O,ee,A,_,X,C,J]),c.useEffect(()=>{_(r=>{const d=new Map(o.stampLoopOf(r,k).map(m=>[m.id,m.data.loopOf]));return r.map(m=>{const y=qo(p,m.id,vn(m.id,d));return m.data.stepStatus===y&&m.data.runStatus===(p==null?void 0:p.status)?m:{...m,data:{...m.data,stepStatus:y,runStatus:p==null?void 0:p.status}}})}),X(r=>r.map(d=>{var I;const m=o.edgeLane(d),y=Go(p,d.source,m,typeof((I=d.data)==null?void 0:I.route)=="string"?d.data.route:void 0,d.target),j=o.edgeVisuals(m,y);return d.className===j.className&&d.label===j.label?d:{...d,className:j.className,label:j.label}}))},[p,O,pe,_,X]),c.useEffect(()=>{_(r=>o.applyStepProblems(r,w))},[w,O,pe,_]);const et=c.useCallback((r,d)=>{var j,I;const{canvas:m,...y}=r;return!((j=d.notes)!=null&&j.length)&&!((I=d.sections)!=null&&I.length)?y:{...y,canvas:go(d,s.canvas,V)}},[s.canvas,V]),Y=c.useCallback((r,d,m)=>{J.record(Lt(s,r,d,M.current,m??H),$e?gt.current:Z.current),i(et(o.flowToWorkflow({...s,connections:M.current},r,d),m??H))},[s,i,H,et,J,$e]),tt=c.useRef(()=>{});tt.current=r=>{if(n)return;const d=o.editConnectionResources(b.map(y=>y.data.step),M.current,r),m=b.map((y,j)=>({...y,data:{...y.data,step:d.nodes[j]}}));C(d.connections),_(m),Y(m,k)};const Ge=c.useCallback(r=>tt.current(r),[]),wt=c.useCallback(r=>{B(r),Ne(null),_(d=>d.map(m=>({...m,selected:m.id===r}))),X(d=>d.map(m=>({...m,selected:!1}))),Fe({nodes:[{id:r}],duration:300,maxZoom:1})},[_,X,Fe]),[lt,ce]=c.useState(null),xt=c.useMemo(()=>lt?b.map(r=>r.id===lt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,lt]),bt=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),yt=JSON.stringify(bt),jt=JSON.stringify([...R]);c.useEffect(()=>{e==null||e({workflowId:s.id,nodes:bt,apps:R,connections:U,readOnly:n,edit:Ge,focusNode:wt,highlightNode:ce})},[e,s.id,yt,jt,U,n,Ge,wt]),c.useEffect(()=>()=>e==null?void 0:e(null),[e]);const vt=c.useCallback(r=>o.canConnect(r.source,r.target,b,k,ie,o.routeFromHandle(r.sourceHandle)),[b,k,ie]),[N,G]=c.useState(null),se=c.useRef(null),he=c.useRef(null);c.useEffect(()=>{_(r=>o.stampLoopOf(r,k))},[k,_]);const st=c.useCallback(r=>{if(n)return;const d=o.applyConnect(r.source,r.target,b,k,o.laneForSourceHandle(r.sourceHandle),ie,o.routeFromHandle(r.sourceHandle));if(!d){const m=o.laneForSourceHandle(r.sourceHandle),y=o.connectRefusal(r.source,r.target,b,k,m,ie,o.routeFromHandle(r.sourceHandle));if(y&&y.refused==="loop"){G({nodeId:r.source,reason:y.reason});return}if(y){const I=k.find(F=>F.source===r.source&&o.edgeLane(F)===m);I&&(X(k.map(F=>({...F,selected:F.id===I.id}))),Ne(I.id),Ke({edgeId:I.id,message:pn(y.cap)}));return}const j=o.connectConflict(r.source,r.target,b,k,o.laneForSourceHandle(r.sourceHandle));if(!j)return;X(k.map(I=>({...I,selected:I.id===j}))),Ne(j),Ke({edgeId:j,message:o.idClashMessage("Can’t draw that edge",j,un(k,j,r.source,r.target))});return}Ke(null),G(null),X(d),Y(b,d)},[k,b,X,Y,n,ie]),Wn=c.useCallback((r,d)=>{var q,Q,le;if(n||d.isValid)return;const m=d.fromNode;if(!m)return;const y=((q=d.fromHandle)==null?void 0:q.type)==="target"?"target":"source",j=d.toNode;if(j&&y==="source"){const ne=Jo(m.id,j.id,rn(he.current,m.id,d.fromHandle),b,k);if(ne){G({nodeId:m.id,reason:ne});return}}const I=(Q=b.find(ne=>ne.id===m.id))==null?void 0:Q.data.step;if(I){const ne=o.nodePortsForStep(I,ie);if((y==="source"?ne.out:ne.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,L=Le({x:F.clientX,y:F.clientY});_e({nodeId:m.id,handleType:y,position:L,lane:rn(he.current,m.id,d.fromHandle),route:o.routeFromHandle((le=d.fromHandle)==null?void 0:le.id)}),te(!0)},[n,Le,b,k,ie]),ms=c.useCallback((r,d,m)=>{if(n)return;const y=b.find(q=>q.id===r);if(!y)return;const j=Yt(y),I=o.laneForSourceHandle(m),F=120,L=d==="target"?{x:j.x-j.w-F,y:j.y}:I==="error"?{x:j.x,y:j.y+j.h+F}:I==="each"?{x:j.x+j.w+F,y:j.y-j.h-F/2}:{x:j.x+j.w+F,y:j.y};_e({nodeId:r,handleType:d,position:L,lane:I,route:o.routeFromHandle(m)}),te(!0)},[n,b]),gs=c.useCallback(r=>{n||Me({nodeIds:[r],edgeIds:[]})},[n]),$n=c.useCallback(r=>{if(n)return;const d=No(r,b,k,H);_(d.nodes),X(d.edges),z(d.canvas),d.nodes.some(m=>m.id===W)||B(null),d.nodes.some(m=>m.id===re)||Pe(null),d.edges.some(m=>m.id===ae)||Ne(null),Y(d.nodes,d.edges,d.canvas)},[b,k,H,_,X,Y,n,W,re,ae]),ws=c.useCallback(()=>{if(n)return;const r=Ro(b,k,H);_(r.nodes),z(r.canvas),at.current=!0,Y(r.nodes,k,r.canvas)},[b,k,H,_,Y,n]),Bn=c.useCallback(()=>{n||ws()},[n,ws]);c.useEffect(()=>{at.current&&(at.current=!1,Fe({duration:300}))},[b,Fe]);const xs=c.useRef(g);c.useEffect(()=>{Object.is(xs.current,g)||(xs.current=g,Fe({duration:300}))},[g,Fe]);const[St,Ke]=c.useState(null),nt=c.useMemo(()=>k.find(r=>r.id===ae)??null,[k,ae]),Vn=c.useCallback(r=>{if(n||!ae)return;const d=k.find(F=>F.id===ae);if(!d||o.edgeLane(d)===r)return;const m=o.edgeWhenConflict(k,ae,r,b),y=o.relaneRefusal(k,ae,r,b,ie),j=m||y?null:o.setEdgeWhen(k,ae,r,b,ie);if(!j){if(y){Ke({edgeId:ae,message:pn(y.cap)});return}Ke({edgeId:ae,message:m?o.idClashMessage("Can’t switch this edge",m,un(k,m,d.source,d.target)):"This edge can’t be switched right now."});return}Ke(null),X(j);const I=j.find(F=>F.source===d.source&&F.target===d.target&&o.edgeLane(F)===r);Ne((I==null?void 0:I.id)??null),Y(b,j)},[k,b,X,Y,n,ae,ie]),zn=c.useCallback(r=>{if(n)return;const d=k.filter(m=>m.id!==r);d.length!==k.length&&(X(d),ae===r&&Ne(null),Y(b,d))},[b,k,X,Y,n,ae]),Wt=c.useCallback(r=>{if(n)return;const d=r.map(I=>b.find(F=>F.id===I)).filter(I=>I!==void 0);if(d.length===0)return;const m=b.map(I=>I.id),y=d.map(I=>{const F=o.suggestStepId(m,`${I.data.step.id}_copy`);m.push(F);const L={...o.stripBody(structuredClone(I.data.step)),id:F};return{id:F,type:I.type,position:{x:I.position.x+40,y:I.position.y+60},data:{step:L,isInternal:I.data.isInternal},...d.length>1?{selected:!0}:{}}}),j=[...d.length>1?b.map(I=>I.selected?{...I,selected:!1}:I):b,...y];_(j),B(y[0].id),Y(j,k)},[b,k,_,Y,n]),bs=c.useCallback(r=>Wt([r]),[Wt]),Hn=c.useCallback(r=>{if(n)return;const d=o.isInternalApp(r.uses.app),m=b.map(ne=>ne.id),y=r.id&&!o.stepNameError(r.id,m)?r.id:o.suggestStepId(m,o.slugifyLabel(o.internalNodeLabel(r.uses.app,r.uses.action))),j=$({id:y,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),I={id:y,type:d?"control":"step",position:(xe==null?void 0:xe.position)??(ye==null?void 0:ye.position)??{x:80,y:80+b.length*24},data:{step:j,isInternal:d}},F=ye!=null&&ye.replaces?b.find(ne=>ne.id===ye.replaces):void 0;if(F&&o.isTriggerStep(r.uses)){const ne={...I,position:F.position},fe=[...b.filter(pt=>pt.id!==F.id),ne],me=o.renameStepInEdges(k,F.id,y),Te=Qt(H,F.id,y);return _(fe),X(me),z(Te),G(null),B(y),Y(fe,me,Te),y}const L=[...b,I];let q=k,Q=null;const le=(ne,fe,me,Te)=>{const pt=o.connectRefusal(ne,fe,L,k,me,ie);pt&&pt.refused==="loop"&&(Q={nodeId:Te,reason:pt.reason})};if(xe){const[ne,fe]=xe.handleType==="target"?[y,xe.nodeId]:[xe.nodeId,y],me=o.applyConnect(ne,fe,L,k,xe.lane,ie,xe.route);me||le(ne,fe,xe.lane,xe.nodeId),q=me??k}else{const ne=b.find(fe=>o.isTriggerStep(fe.data.step.uses));if(o.isTriggerStep(r.uses)){if(!ne){const fe=o.findChainRoot(b,k);if(fe){const me=o.applyConnect(y,fe.id,L,k,"success",ie);me||le(y,fe.id,"success",fe.id),q=me??k}}}else{const me=(ne&&!k.some(Te=>Te.source===ne.id)?ne:void 0)??o.findChainTail(b,k);if(me){const Te=o.applyConnect(me.id,y,L,k,"success",ie);Te||le(me.id,y,"success",me.id),q=Te??k}}}return _(L),q!==k&&X(q),G(Q),B(y),Y(L,q),y},[b,k,_,X,Y,n,xe,ye,ie,$,H]),ys=c.useCallback((r,d)=>{var q;let m=d;const y=(q=b.find(Q=>Q.id===r))==null?void 0:q.data.step;if(d.uses.connection&&!d.uses.connectionRef&&(y!=null&&y.uses.connectionRef)&&y.uses.app===d.uses.app){const Q=o.selectNodeConnection(o.withConnectionRef(d,y.uses.connectionRef),d.uses.connection,b.map(le=>le.data.step),M.current);C(Q.connections),m=Q.step}else m=$(d);const j=m.id!==r;if(j&&b.some(Q=>Q.id===m.id))return;const I=b.map(Q=>Q.id===r?{...Q,id:m.id,data:{step:m,isInternal:o.isInternalApp(m.uses.app)}}:Q);if(j){const Q=o.renameStepInEdges(k,r,m.id),le=Qt(H,r,m.id);_(I),X(Q),z(le),W===r&&B(m.id),re===r&&Pe(m.id),Y(I,Q,le);return}_(I);const F=new Set(o.routesForStep(m).map(Q=>Q.id)),L=k.filter(Q=>{var le;return Q.source!==m.id||((le=Q.data)==null?void 0:le.route)===void 0||F.has(String(Q.data.route))});L.length!==k.length&&X(L),Y(I,L)},[b,k,H,_,X,W,re,Y,$,C]),Xe=c.useCallback(r=>{n||(z(r),Y(b,k,r))},[n,b,k,Y]),Jn=c.useCallback(()=>{var j;if(n)return;const r=(j=Se.current)==null?void 0:j.getBoundingClientRect(),d=r?Le({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},m=H.notes??[],y={id:fn("note",m.map(I=>I.id)),color:"#facc15",position:{x:Math.round(d.x-100),y:Math.round(d.y-60)},size:{width:200,height:120},content:""};Xe(ts({...H,notes:[...m,y]}))},[n,H,Le,Xe]),Un=c.useCallback((r,d)=>{if(n)return;const m=d?Math.min(r.x,d.x):r.x,y=d?Math.min(r.y,d.y):r.y,j=d?Math.abs(d.x-r.x):360,I=d?Math.abs(d.y-r.y):240,F=b.filter(ne=>{const fe=Yt(ne),me=fe.x+fe.w/2,Te=fe.y+fe.h/2;return me>=m&&me<=m+j&&Te>=y&&Te<=y+I}).map(ne=>ne.id),L=H.sections??[],q=fn("section",L.map(ne=>ne.id)),Q={id:q,title:"Section",color:"#6366f1",position:{x:Math.round(m),y:Math.round(y)},size:{width:Math.round(j),height:Math.round(I)},nodes:[]},le={...H,sections:[...L,Q]};Xe(ts(es(le,q,F)))},[n,b,H,Xe]);c.useEffect(()=>{if(!De)return;const r=d=>{d.key==="Escape"&&(rt(!1),Ue(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[De]);const qn=c.useCallback((r,d)=>{var F;if(n)return;const m=(F=H.sections)==null?void 0:F.find(L=>L.id===r);if(!m)return;const y=new Set(m.nodes),j=b.map(L=>y.has(L.id)?{...L,position:{x:L.position.x+d.dx,y:L.position.y+d.dy}}:L),I={...H,sections:(H.sections??[]).map(L=>L.id===r?{...L,position:{x:L.position.x+d.dx,y:L.position.y+d.dy}}:L)};_(j),z(I),Y(j,k,I)},[n,H,b,k,_,Y]),Gn=c.useCallback((r,d)=>{if(n)return;const m=r==="note"?{...H,notes:(H.notes??[]).filter(y=>y.id!==d)}:{...H,sections:(H.sections??[]).filter(y=>y.id!==d)};Xe(m)},[n,H,Xe]),Kn=r=>{let d=H;for(const m of r){const y=Yt(m),j=y.x+y.w/2,I=y.y+y.h/2,F=(d.sections??[]).find(q=>j>=q.position.x&&j<=q.position.x+q.size.width&&I>=q.position.y&&I<=q.position.y+q.size.height),L=bn(d,m.id);F?(L.length!==1||L[0]!==F.id)&&(d=es(d,F.id,[m.id])):L.length>0&&(d=rs(d,m.id))}return d},$t=c.useCallback((r,d,m)=>{(async()=>{const y=await v.saveStepTest(s.id,r,d).catch(j=>(console.error("step run fixture save failed",j),null));await v.recordStepTestRun(s.id,r,{stepTestId:(y==null?void 0:y.id)??null,status:m.status,input:d.input,output:m.output,error:m.error,...m.meta?{meta:m.meta}:{}})})().catch(y=>{console.error("step run persist failed",y)})},[v,s.id]),js=c.useCallback(r=>{const d=b.find(m=>m.id===r);!d||!S&&o.isControlApp(d.data.step.uses.app)||h({stepId:r,status:"collect"})},[b,S]),Xn=c.useCallback(async(r,d,m)=>{if(!S)return;const y=b.find(F=>F.id===r);if(!y)return;const j=o.isTriggerStep(y.data.step.uses),I={stopAt:ns(b.map(F=>F.data.step),r),...m?{state:m}:{},...j?{input:d}:{}};h({stepId:r,status:"running"});try{await S(r,I),h(null)}catch(F){const L=F;h({stepId:r,status:"error",error:L.message??String(F),errorCode:L.code})}},[b,S]),Ct=c.useCallback((r,d)=>{if(n)return;const m=b.map(y=>y.id===r?{...y,data:{...y.data,step:d(y.data.step)}}:y);_(m),Y(m,k)},[b,k,_,Y,n]),vs=c.useCallback(r=>Ct(r,d=>Sn(d,!Qe(d))),[Ct]),Ss=c.useCallback(r=>Ct(r,d=>Cn(d,!We(d))),[Ct]),Yn=c.useCallback(async(r,d,m)=>{x==null||x();const y=b.find(q=>q.id===r);if(!y)return;const j=y.data.step,I=o.isTriggerStep(j.uses),F=I?{input:d}:{...j.with??{},...d},L=I?{input:d,with:d}:{input:d,with:F};h({stepId:r,status:"running"});try{const q=await v.invokeAction(j.uses.app,j.uses.action,F,{connectionId:o.connectionIdFor(j,M.current),project:f,...m?{state:m}:{},workflowId:s.id}),Q=q.logs,le=q.meta;h({stepId:r,status:"done",value:q.value,logs:Q,...le?{meta:le}:{}}),$t(r,L,{status:"succeeded",output:q.value,...le?{meta:le}:{}})}catch(q){const Q=q;h({stepId:r,status:"error",error:Q.message??String(q),errorCode:Q.code}),$t(r,L,{status:"failed",error:Q.message??String(q)})}},[b,v,$t,f,x,s.id]),Bt=c.useMemo(()=>({onEdit:r=>{ke("props"),Pe(r)},onEditJson:r=>{ke("json"),Pe(r)},onRun:js,onDuplicate:bs,onDelete:gs,onTogglePause:vs,onToggleDisable:Ss,runsFromNode:!!S,onAddFromPort:ms,readOnly:n}),[js,bs,gs,vs,Ss,S,ms,n]);c.useEffect(()=>{const r=Se.current;if(!r)return;const d=m=>{const y=m.target.closest(".react-flow__node");if(!y)return;const j=y.getAttribute("data-id");j&&(m.stopPropagation(),Bt.onEdit(j))};return r.addEventListener("dblclick",d,!0),()=>r.removeEventListener("dblclick",d,!0)},[Bt]);const ot=b.find(r=>r.id===re),Nt=(ot==null?void 0:ot.data.step)??null,Vt=D?((Js=b.find(r=>r.id===D.stepId))==null?void 0:Js.data.step)??null:null,zt=(D==null?void 0:D.status)==="collect"&&!!Vt,Cs=c.useMemo(()=>{const r=new Map;for(const d of b)r.set(d.id,o.fanOutState(d.id,k).count);return r},[b,k]),Ns=Oo(b),kt=c.useMemo(()=>_o(Ns),[Ns]),Zn=c.useMemo(()=>Fo(k,kt.tones,kt.loopOf),[k,kt]),Qn=c.useMemo(()=>({step:vi,control:Si}),[]),[Et,ks]=c.useState({}),[Tt,Es]=c.useState({}),[Ts,Is]=c.useState({}),[It,As]=c.useState({}),[Ve,At]=c.useState(null),[Ps,Rs]=c.useState([]),eo=re??Ve??"";c.useEffect(()=>{const r=v.loadNodeSamples;if(typeof r!="function"||!s.id){Rs([]);return}let d=!1;return r(s.id).then(m=>{d||Rs(Array.isArray(m)?m:[])},()=>{}),()=>{d=!0}},[v,s.id,eo]);const Pt=c.useMemo(()=>o.indexNodeSamples(Ps),[Ps]),Ht=c.useMemo(()=>o.splitNodeOutputs(Et,Pt,It),[Et,Pt,It]),ze=c.useMemo(()=>o.splitPreviewOutputs(Et,Pt,It),[Et,Pt,It]),Ce=c.useMemo(()=>({actionDef:(r,d)=>{var m;return(m=ue[r])==null?void 0:m.find(y=>y.key===d)},triggerDef:(r,d)=>{var m;return(m=je[r])==null?void 0:m.find(y=>y.key===d)},testOutputs:Ht.fresh,persistedOutputs:Ht.persisted,loopSamples:Ts}),[ue,je,Ht,Ts]),Ye=c.useMemo(()=>D?o.upstreamStateSources(D.stepId,b,k,Ce):void 0,[D,b,k,Ce]),to=c.useMemo(()=>(Ye==null?void 0:Ye.steps)??[],[Ye]),be=c.useMemo(()=>{const r=o.upstreamStateSources(re,b,k,Ce,Ve);return{...r,steps:o.excludeSelfStep(r.steps,re??Ve)}},[re,Ve,b,k,Ce]),dt=c.useMemo(()=>ti({anchorId:re??Ve,nodes:b,edges:k,floating:o.isFloatingDraft(re,Ve,b,k),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...ze.persisted,...ze.fresh}}),[re,Ve,b,k,s.initialState,s.variables,Ce,ze]),Ms=JSON.stringify([...be.steps.map(r=>r.id),...be.extraSampleIds??[]]);c.useEffect(()=>{const r=JSON.parse(Ms);if(!re&&!Ve||r.length===0){ks({}),Es({}),Is({}),As({});return}let d=!1;return Promise.all(r.map(async m=>{try{const y=await v.listStepTests(s.id,m),j=y.length?y[y.length-1]:null;return j?{id:m,output:j.lastRunOutput,runAt:j.lastRunAt,meta:j.lastRunMeta,loopSample:o.foreachTestSample(j)}:null}catch{return null}})).then(m=>{if(d)return;const y={},j={},I={},F={};for(const L of m)L!=null&&L.meta&&(j[L.id]=L.meta),L!=null&&L.loopSample&&(I[L.id]=L.loopSample),!(!L||L.output===void 0||L.output===null)&&(y[L.id]=L.output,F[L.id]=L.runAt);ks(y),As(F),Es(j),Is(I)}),()=>{d=!0}},[v,s.id,re,Ve,Ms]);const Jt=c.useMemo(()=>o.declaredSamples(b,Ce),[b,Ce]),Rt=c.useMemo(()=>({persisted:ze.persisted,samples:Jt.samples,event:Jt.event}),[ze.persisted,Jt]),Ls=c.useMemo(()=>o.upstreamSampleValues(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Fs=c.useMemo(()=>o.upstreamSampleValueSources(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Ds=o.useExpressionOptions(),Os=c.useMemo(()=>o.nodeConfigSources(b),[b]),_s=c.useMemo(()=>o.nodeConfigValues(b,E.subs),[b,E.subs]),Ut=c.useMemo(()=>o.nodeMetaValues(b,E.subs,R,U),[b,E.subs,R,U]),qt=c.useMemo(()=>({...l??{},steps:be.steps,hasTrigger:be.hasTrigger,eventOutputs:be.eventOutputs,eventOutputsFrom:be.eventOutputsFrom,loop:be.loop,stateShape:{fields:dt.fields,...dt.written?{written:dt.written}:{}},nodeConfigs:Os,nodeConfig:_s,nodeMeta:Ut,valueSources:Fs,sampleValues:{...Ds.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...o.nodeMetaSampleValues(Ut),...Ls,...dt.sampleValues}}),[l,Ds.sampleValues,be,dt,Ls,Fs,Os,_s,Ut]),ut=c.useRef(null);$e||re?ut.current===null&&(ut.current=J.mark()):ut.current=null;const Ws=()=>{te(!1),_e(null),Be(null),At(null)},$s=()=>{const r=ut.current;if(ut.current=null,n||r===null)return;const d=J.rollbackTo(r);d&&Vs(d)},Bs=r=>{if(n)return;const d=J[r]();d&&Vs(d)},Vs=r=>{var y;const d=Eo(s,r);_(d.nodes.map(j=>({...j,selected:j.id===W}))),X(d.edges.map(j=>({...j,selected:j.id===ae}))),z(r.canvas),C(r.connections),d.nodes.some(j=>j.id===W)||B(null),d.edges.some(j=>j.id===ae)||Ne(null);const m=d.nodes.some(j=>j.id===re);m||Pe(null),te(!1),At(null),_e(null),Me(null),ge(null),Be(null),qe(null),G(null),Ke(null),Z.current=void 0,Je(j=>j+1),i(et(o.flowToWorkflow({...s,nodes:r.nodes,connections:r.connections},d.nodes,d.edges),r.canvas)),!m&&!D&&((y=Se.current)==null||y.focus({preventScroll:!0}))},zs=c.useRef(Bs);zs.current=Bs,c.useEffect(()=>{const r=Se.current;if(!r)return;let d=r.contains(document.activeElement);const m=j=>{j.type==="focusin"&&j.target===document.body||(d=r.contains(j.target))},y=j=>{if(n||j.defaultPrevented||Gt(j.target)||!r.contains(j.target)&&!(d&&j.target===document.body))return;const I=j.key.toLowerCase();!(j.ctrlKey||j.metaKey)||j.altKey||I!=="z"&&!(I==="y"&&!j.shiftKey)||(j.preventDefault(),zs.current(I==="y"||j.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",m),document.addEventListener("focusin",m),document.addEventListener("keydown",y),()=>{document.removeEventListener("pointerdown",m),document.removeEventListener("focusin",m),document.removeEventListener("keydown",y)}},[n]);const Mt=c.useCallback((r,d)=>{var L;if(Gt(r.target))return;const m=(L=Se.current)==null?void 0:L.getBoundingClientRect();if(!m)return;r.preventDefault();const y=tn(b,k),j=y.nodeIds,I=uo(j,d),F=d!==void 0&&!j.includes(d);F&&_(b.map(q=>q.selected!==(q.id===d)?{...q,selected:q.id===d}:q)),qe({x:r.clientX-m.left,y:r.clientY-m.top,flow:Le({x:r.clientX,y:r.clientY}),nodeIds:I,edgeIds:F?[]:y.edgeIds})},[b,k,_,Le]),so=c.useCallback(r=>{var d;qe(null),r&&((d=Se.current)==null||d.focus({preventScroll:!0}))},[]),no=r=>{const d=we;if(!(!d||n))if(r==="duplicate")Wt(d.nodeIds);else if(r==="delete")Me({nodeIds:d.nodeIds,edgeIds:d.edgeIds});else if(r==="replace-trigger"){const m=b.find(y=>y.id===d.nodeIds[0]);if(!m)return;_e(null),Be({position:m.position,tab:"triggers",replaces:m.id}),te(!0)}else _e(null),Be({position:d.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),te(!0)},oo=t.jsx(fs.Provider,{value:Bt,children:t.jsx(ls.Provider,{value:ie,children:t.jsx(ds.Provider,{value:Cs,children:t.jsx(us.Provider,{value:kt,children:t.jsx(ui,{apps:R,registration:E,children:t.jsx(o.WorkflowProjectProvider,{project:f,workflowId:s.id,children:t.jsx(o.ExpressionOptionsProvider,{value:qt,children:t.jsxs("section",{ref:Se,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{Z.current=Gt(r.target)?{}:void 0},onBlurCapture:()=>{Z.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||re||$e||Re)return;const d=r.target;if(d.isContentEditable||d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.tagName==="SELECT"||d.closest("dialog, .w6w-modal")!==null)return;const m=tn(b,k);!m.nodeIds.length&&!m.edgeIds.length||(r.preventDefault(),!m.nodeIds.length&&m.edgeIds.length===1?zn(m.edgeIds[0]):Me(m))},children:[t.jsxs(oe.ReactFlow,{nodes:xt,edges:Zn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:de,onEdgesChange:T,onConnect:st,onConnectStart:(r,d)=>{he.current=d},onConnectEnd:Wn,onPaneClick:()=>G(null),onPaneContextMenu:r=>Mt(r),onNodeContextMenu:(r,d)=>Mt(r,d.id),onEdgeContextMenu:r=>Mt(r),onSelectionContextMenu:r=>Mt(r),onMoveStart:()=>qe(null),isValidConnection:vt,onNodeDragStop:(r,d,m)=>{const y=Kn(m),j=y!==H;if(j&&z(y),!V&&!j){J.record(Lt(s,b,k,M.current,y));return}Y(b,k,y)},onMoveEnd:(r,d)=>{if(!r||n)return;const m=o.flowToWorkflow(s,b,k),y=o.withViewport(m,d);y!==m&&i(y,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:d})=>{var m,y,j,I;B(((m=r[0])==null?void 0:m.id)??null),Ne(((y=d[0])==null?void 0:y.id)??null),se.current!==(((j=r[0])==null?void 0:j.id)??null)&&(se.current=((I=r[0])==null?void 0:I.id)??null,G(null))},nodeTypes:Qn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:ct,proOptions:{hideAttribution:!0},children:[t.jsx(oe.Background,{gap:16}),t.jsx(oe.Controls,{showInteractive:!1,children:!n&&t.jsx(oe.ControlButton,{onClick:Bn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(Ee.Icon,{name:"layout"})})}),t.jsx(oe.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(oe.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>te(!0),children:"+ Node"}),t.jsx(o.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Jn}),t.jsx(o.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${De?" active":""}`,"aria-pressed":De,"data-testid":"draw-section",onClick:()=>{rt(!De),Ue(null)}})]}),!n&&De&&t.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:r=>{if(r.button!==0)return;r.currentTarget.setPointerCapture(r.pointerId);const{clientX:d,clientY:m}=r;Ue({sx:d,sy:m,ex:d,ey:m})},onPointerMove:r=>{const{clientX:d,clientY:m}=r;Ue(y=>y&&{...y,ex:d,ey:m})},onPointerUp:()=>{const r=ve;if(Ue(null),rt(!1),!r)return;const d=Le({x:r.sx,y:r.sy}),m=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Un(d,m?Le({x:r.ex,y:r.ey}):null)},children:ve&&(()=>{var y;const r=(y=Se.current)==null?void 0:y.getBoundingClientRect(),d=(r==null?void 0:r.left)??0,m=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ve.sx,ve.ex)-d,top:Math.min(ve.sy,ve.ey)-m,width:Math.abs(ve.ex-ve.sx),height:Math.abs(ve.ey-ve.sy)}})})()}),!n&&nt&&o.edgeLane(nt)!=="each"&&((Us=b.find(r=>r.id===nt.source))==null?void 0:Us.data.step.uses.app)!==o.ROUTER_APP&&t.jsx(oe.Panel,{position:"top-right",children:t.jsxs("div",{className:"w6w-edge-lane",children:[t.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(r=>t.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${o.edgeLane(nt)===r?" active":""}`,"aria-pressed":o.edgeLane(nt)===r,title:di,onClick:()=>Vn(r),children:r==="success"?"Success":"Error"},r)),(St==null?void 0:St.edgeId)===nt.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:St.message})]})}),N&&t.jsx(oe.NodeToolbar,{nodeId:N.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:o.loopRefusalMessage(N.reason)})}),t.jsx(o.CanvasLayer,{canvas:H,readOnly:n,savePosition:V,onChange:Xe,onSectionDrop:qn,onRequestDelete:(r,d)=>!n&&ge({kind:r,id:d})})]}),Ae&&t.jsx(o.ConfirmModal,{title:Ae.kind==="note"?"Delete note":"Delete section",message:Ae.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Gn(Ae.kind,Ae.id),ge(null)},onClose:()=>ge(null)}),$e&&t.jsx(o.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{$s(),Ws()},onDone:Ws,onAdd:r=>{const d=Hn(r);return d&&At(d),d},onDraftChange:(r,d)=>ys(r,{id:r,...d}),stepIds:b.map(r=>r.id),onOpenStep:r=>{te(!1),_e(null),Be(null),At(null),ke("props"),Pe(r)},workflowId:s.id,upstreamSteps:o.stepBuilderUpstreamSteps(xe,b,k),loop:o.stepBuilderLoop(xe,b,k,Ce)}),Nt&&re&&t.jsx(Ni,{workflowId:s.id,step:Nt,restoreVersion:pe,upstreamSteps:qt.steps??[],loop:qt.loop,readOnly:n,fanOutCount:Cs.get(re)??0,stateOutputFields:(Xs=o.resolveOutputShape((qs=Ce.actionDef)==null?void 0:qs.call(Ce,Nt.uses.app,Nt.uses.action),(Gs=Ce.testOutputs)==null?void 0:Gs[re],(Ks=Ce.persistedOutputs)==null?void 0:Ks[re]))==null?void 0:Xs.fields.map(r=>r.key),initialView:Oe,stepProblems:ot==null?void 0:ot.data.stepProblems,otherStepIds:b.filter(r=>r.id!==re).map(r=>r.id),onChange:r=>ys(re,r),onClose:()=>Pe(null),onCancel:()=>{$s(),Pe(null)},onTestRun:x}),D&&t.jsxs(o.Modal,{title:`${zt?"Run node":"Test run"}: ${D.stepId}`,onClose:()=>h(null),children:[zt&&Vt&&t.jsx(wi,{workflowId:s.id,step:Vt,upstreamSteps:to,loop:Ye==null?void 0:Ye.loop,continues:S?{stopAt:ns(b.map(r=>r.data.step),D.stepId)}:void 0,onCancel:()=>h(null),onRun:(r,d)=>S?Xn(D.stepId,r,d):Yn(D.stepId,r,d)},D.stepId),!zt&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[D.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),D.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[D.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:D.errorCode})}),D.error||"The node failed with no error message."]}),D.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(o.ResultViewer,{value:D.value,maxHeight:360}),D.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(o.ResultViewer,{value:D.meta,maxHeight:360})]})]}),D.logs&&D.logs.length>0&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),t.jsx(Ee.Copyable,{value:D.logs.join(`
|
|
1
|
+
"use client";"use strict";var io=Object.defineProperty;var ro=(e,s,i)=>s in e?io(e,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[s]=i;var it=(e,s,i)=>ro(e,typeof s!="symbol"?s+"":s,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),oe=require("@xyflow/react"),c=require("react"),o=require("./connection-app-meta-pnATcKeZ.cjs"),Ee=require("./CodeBlock-a2aIm-0b.cjs"),Ie=require("@w6w/expr");function ao({x:e,y:s,items:i,onAction:n,onClose:a}){const u=c.useRef(null),[l,f]=c.useState({left:e,top:s});c.useLayoutEffect(()=>{const w=u.current,x=w==null?void 0:w.offsetParent;if(!w||!x)return;const g=w.offsetWidth,S=w.offsetHeight;f({left:e+g>x.clientWidth?Math.max(0,e-g):e,top:s+S>x.clientHeight?Math.max(0,s-S):s})},[e,s]),c.useEffect(()=>{var w,x;(x=(w=u.current)==null?void 0:w.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),c.useEffect(()=>{const w=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},x=S=>{var v;(v=u.current)!=null&&v.contains(S.target)||a(!1)},g=()=>a(!1);return document.addEventListener("pointerdown",w,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",g),window.addEventListener("resize",g),()=>{document.removeEventListener("pointerdown",w,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",g),window.removeEventListener("resize",g)}},[a]);const p=w=>{w.disabled||(a(!1),n(w.action))};return t.jsx("div",{ref:u,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:w=>w.preventDefault(),onKeyDown:w=>{var v;w.stopPropagation();const x=[...((v=u.current)==null?void 0:v.querySelectorAll("[role=menuitem]"))??[]],g=x.indexOf(document.activeElement),S=R=>{var E;return(E=x[(R+x.length)%x.length])==null?void 0:E.focus()};if(w.key==="ArrowDown")S(g+1);else if(w.key==="ArrowUp")S(g<0?-1:g-1);else if(w.key==="Home")S(0);else if(w.key==="End")S(-1);else if(w.key==="Escape"||w.key==="Tab")a(!0);else if(w.key==="Enter"||w.key===" ")g>=0&&p(i[g]);else return;w.preventDefault()},children:i.map(w=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":w.disabled||void 0,className:`w6w-note-menu-item${w.danger?" danger":""}${w.separated?" separated":""}`,"data-action":w.action,onClick:()=>p(w),children:w.label},w.action))})}function co(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function lo({app:e,trigger:s,onUse:i}){const n=o.useW6WApi(),[a,u]=c.useState(null);return c.useEffect(()=>{var f;let l=!1;return u(null),(f=n.getAppTriggers)==null||f.call(n,e).then(p=>{var w;l||u(co((w=p.find(x=>x.key===s))==null?void 0:w.sample))}).catch(()=>{}),()=>{l=!0}},[n,e,s]),a?t.jsx("div",{children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>i(a),children:"Use sample event"})}):null}function uo(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function po(e,s,i={}){const n=[],a=e.length;if(a>0){const u=a>1?` ${a} nodes`:"";n.push({action:"duplicate",label:`Duplicate${u}`,disabled:s}),a===1&&i.replaceableTrigger&&n.push({action:"replace-trigger",label:"Replace trigger",disabled:s}),n.push({action:"delete",label:`Delete${u}`,disabled:s,danger:!0})}return n.push({action:"add-node",label:"Add node",disabled:s,separated:a>0}),n.push({action:"add-trigger",label:"Add trigger",disabled:s}),n}const mn=200,gn=200,wn=10240;function Zt(e){const s={};for(const[i,n]of Object.entries(e))s[i]=Math.round(n);return s}const fo=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),ho=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function Ys(e,s,i){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],u=fo(a==null?void 0:a.position)?a.position:n.position,l=ho(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Zt(u),size:Zt(l)}})}function xn(e,s,i){if(!s)return e;const n={...e};return e.notes&&(n.notes=Ys(e.notes,i)),e.sections&&(n.sections=Ys(e.sections,i)),n}function rs(e,s){return e.sections?{...e,sections:e.sections.map(i=>({...i,nodes:i.nodes.filter(n=>n!==s)}))}:e}function Qt(e,s,i){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?i:a)}))}:e}function es(e,s,i){if(!e.sections)return e;const n=new Set(i);return{...e,sections:e.sections.map(a=>{const u=a.nodes.filter(l=>!n.has(l));return a.id===s?{...a,nodes:[...new Set([...u,...i])]}:{...a,nodes:u}})}}function bn(e,s){return(e.sections??[]).filter(i=>i.nodes.includes(s)).map(i=>i.id)}function mo(e,s){const i=new TextEncoder;if(i.encode(e).length<=s)return e;let n="",a=0;for(const u of e){const l=i.encode(u).length;if(a+l>s)break;n+=u,a+=l}return n}function ts(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,mn).map(i=>({...i,content:mo(i.content,wn)}))),e.sections&&(s.sections=e.sections.slice(0,gn)),s}function go(e,s,i){const n={};for(const l of[...e.notes??[],...e.sections??[]])n[l.id]={position:l.position,size:l.size};const a=(l,f)=>l==null?void 0:l.map(p=>{const w=f==null?void 0:f.find(x=>x.id===p.id);return w?{...p,position:w.position,size:w.size}:p}),u=i?e:{...e,...e.notes?{notes:a(e.notes,s==null?void 0:s.notes)}:{},...e.sections?{sections:a(e.sections,s==null?void 0:s.sections)}:{}};return xn(u,i,n)}const Zs=220;function wo(e){return e.length<=Zs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Zs).trimEnd(),clipped:!0,length:e.length}}function xo({params:e,values:s,testStartState:i,view:n="props",literalKeys:a}){const{sampleValues:u,nodeConfig:l,nodeMeta:f}=o.useExpressionOptions(),p=c.useMemo(()=>o.buildResolveScope(u,i,l,f),[u,i,l,f]),w=o.flattenParams(e),x=v=>{var R;return s[v]!==void 0?s[v]:(R=w.find(E=>E.key===v))==null?void 0:R.default},g=w.filter(v=>v.type!=="section"&&o.isParamVisible(v,x)).map(v=>Ie.effectiveParam(v,x));if(o.hasParamCustomization(s)){const v=o.previewCustomization(s.$merge,p,a),R=v!==null&&typeof v=="object"&&!Array.isArray(v),E=Qs(g,s,p,a);for(const[h,A]of Object.entries(s))h!=="$merge"&&(E[h]=a!=null&&a.includes(h)?A:o.previewCustomization(A,p));const D=R?{...E,...v}:E;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:R?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(v)}). Test the step to validate it.`}),n==="code"?t.jsx(o.JsonEditor,{value:JSON.stringify(D,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):t.jsx("div",{className:"w6w-resolved-table",children:Object.entries(D).map(([h,A])=>{var O;return t.jsx(ss,{label:((O=w.find(U=>U.key===h))==null?void 0:O.label)??h,segments:[{status:"resolved",value:A}]},h)})})]})}if(n==="code"){const v=Qs(g,s,p,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(o.JsonEditor,{value:JSON.stringify(v,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=g.filter(v=>!o.deepEqual(x(v.key),v.default));return g.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):S.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):t.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:S.map(v=>v.type==="vars"?t.jsx(bo,{param:v,value:s[v.key],scope:p},v.key):t.jsx(ss,{label:v.label??v.key,segments:a!=null&&a.includes(v.key)?[{status:"resolved",value:x(v.key)}]:o.resolveParamValue(x(v.key),p)},v.key))})}function Qs(e,s,i,n){const a={};for(const u of e)if(n!=null&&n.includes(u.key))a[u.key]=s[u.key]!==void 0?s[u.key]:u.default;else if(u.type==="vars"){const l=s[u.key]??u.default??[],f=o.dataVarRows(l);a[u.key]=f?o.resolveVarsJson(f,i):o.resolveParamJson(l,i)}else a[u.key]=o.resolveParamJson(s[u.key]!==void 0?s[u.key]:u.default,i);return a}function ss({label:e,segments:s}){return t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e}),t.jsx("div",{className:"w6w-resolved-value",children:t.jsx(yn,{segments:s})})]})}function bo({param:e,value:s,scope:i}){const n=s??e.default??[],a=o.dataVarRows(n);return a===null?t.jsx(ss,{label:e.label??e.key,segments:o.resolveParamValue(n,i)}):t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e.label??e.key}),a.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):t.jsx("div",{className:"w6w-stack",children:a.map((u,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:u.key||"(no key)"})," → ",t.jsx(yn,{segments:o.resolveParamValue(u.value,i)})]},l))})]})}function yn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,i)=>t.jsx(yo,{segment:s},i))})}function yo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx(en,{value:e.value})]}):t.jsx(en,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return t.jsxs(t.Fragment,{children:[t.jsx(ft,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(ft,{kind:"secret",refName:e.ref})}}function en({value:e}){const[s,i]=c.useState(!1),n=vo(e),a=wo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(Ee.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:t.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):t.jsxs("span",{children:[a.text,"…"]}),t.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>i(u=>!u),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const jo={var:"◆",secret:"🔒",expr:"ƒ"};function ft({kind:e,refName:s}){const i=e==="expr"?"expr":o.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:jo[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:i})]})}function vo(e){if(e===null)return"null";if(e===void 0)return"(not set)";if(e==="")return'""';if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function jn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function So({enabled:e,values:s,onChange:i}){const[n,a]=c.useState(null),u=c.useRef(!1),l=typeof s.code=="string"?s.code:"";return c.useEffect(()=>{if(!e||u.current)return;u.current=!0;const f=o.convertCodeBindingsToReads(l,jn(s));f.converted!==0&&(a({original:l,converted:f.converted}),i({...s,code:f.code}))},[e,l,s,i]),n?{converted:n.converted,undo:()=>{i({...s,code:n.original}),a(null)}}:null}function Co({values:e,conversion:s,readOnly:i}){const n=typeof e.code=="string"?e.code:"",a=s,u=o.findCodeBindings(n,jn(e)).length;return!a&&u===0?null:t.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[a&&t.jsxs(t.Fragment,{children:["Converted ",a.converted," reference",a.converted===1?"":"s"," to code reads",!i&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),u>0&&" · "]}),u>0&&t.jsxs(t.Fragment,{children:[u," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",u===1?"s":""," literal text — read ",u===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function tn(e,s){return{nodeIds:e.filter(i=>i.selected).map(i=>i.id),edgeIds:s.filter(i=>i.selected).map(i=>i.id)}}function No(e,s,i,n){const a=new Set(e.nodeIds),u=new Set(e.edgeIds),l=s.filter(g=>a.has(g.id)),f=[...l.filter(g=>o.isForeachStep(g.data.step)),...l.filter(g=>!o.isForeachStep(g.data.step))];let p=s,w=i,x=n;for(const g of f)w=o.bridgeDeletedBodyStep(g.id,p,w),p=p.filter(S=>S.id!==g.id),x=rs(x,g.id);return{nodes:p,edges:w.filter(g=>!u.has(g.id)),canvas:x}}function ko(e,s,i){var f;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),u=i.filter(p=>a.has(p.id)&&!n.has(p.source)&&!n.has(p.target)),l=[];if(n.size===1)l.push(o.deleteStepMessage(e.nodeIds[0],s,i));else if(n.size>1){l.push(`Delete nodes ${[...n].map(w=>`"${w}"`).join(", ")}? Their connections are removed too.`);const p=new Set;for(const w of n)if(o.isForeachStep((f=s.find(x=>x.id===w))==null?void 0:f.data.step))for(const x of o.loopBody(w,s,i))n.has(x)||p.add(x);p.size&&l.push(`Loop body steps ${[...p].map(w=>`"${w}"`).join(", ")} stay as standalone steps.`)}return u.length&&l.push(`Delete ${u.length===1?"connection":"connections"} ${u.map(p=>`"${p.source} → ${p.target}"`).join(", ")}?`),l.join(" ")}function Lt(e,s,i,n,a){const u=o.flowToWorkflow({...e,connections:n},s,i);return{nodes:u.nodes.map(({with:l,...f})=>l&&Object.keys(l).length?{...f,with:l}:f),edges:u.edges??[],connections:u.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function Eo(e,s){const i=o.workflowToFlow({...e,...s});return{...i,nodes:i.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class To{constructor(s,i=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(this,"limit");this.limit=i,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,i){const n=JSON.stringify(s);n!==this.present&&((!i||i!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=i,this.future=[])}mark(){return this.present}rollbackTo(s){if(this.present===s)return;const i=this.past.lastIndexOf(s);return i>=0&&(this.past.length=i),this.present=s,this.future=[],this.group=void 0,JSON.parse(s)}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Gt(e){var i;const s=e;return!!(s!=null&&s.isContentEditable||(i=s==null?void 0:s.closest)!=null&&i.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Io=64,ht=24,Ze=32;function Ft(e){var s,i;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((i=e.measured)==null?void 0:i.height)??e.height??64}}function Ao(e,s){return e.x<s.x+s.width&&e.x+e.width>s.x&&e.y<s.y+s.height&&e.y+e.height>s.y}function Po(e){const s=(a,u)=>{const l=new Map;for(const w of e){const x=w.position[a];l.set(x,Math.max(l.get(x)??0,Ft(w)[u]))}const f=new Map;let p=Number.NEGATIVE_INFINITY;for(const[w,x]of[...l].sort(([g],[S])=>g-S)){const g=Math.max(w,p);f.set(w,g),p=g+x+Io}return f},i=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:i.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Ro(e,s,i){var f;const n=Po(o.relayoutNodes(e,s));if(!((f=i.sections)!=null&&f.length))return{nodes:n,canvas:i};const a=new Map(n.map(p=>[p.id,p])),u=(i.notes??[]).map(p=>({...p.position,...p.size}));for(const p of i.sections)p.nodes.some(w=>a.has(w))||u.push({...p.position,...p.size,y:p.position.y-Ze,height:p.size.height+Ze});const l=i.sections.map(p=>{const w=new Set(p.nodes),x=n.filter(A=>w.has(A.id));if(!x.length)return p;const g=Math.min(...x.map(A=>A.position.x))-ht,S=Math.min(...x.map(A=>A.position.y))-ht,v=Math.max(...x.map(A=>A.position.x+Ft(A).width)),R=Math.max(...x.map(A=>A.position.y+Ft(A).height)),E={x:g,y:S,width:v+ht-g,height:R+ht-S},D=[...u,...[...a.values()].filter(A=>!w.has(A.id)).map(A=>({...A.position,...Ft(A)}))].sort((A,O)=>A.y-O.y);for(const A of D){const O={...E,y:E.y-Ze,height:E.height+Ze};Ao(O,A)&&(E.y=A.y+A.height+ht+Ze)}const h=E.y-S;for(const A of x)a.set(A.id,{...A,position:{x:A.position.x,y:A.position.y+h}});return u.push({...E,y:E.y-Ze,height:E.height+Ze}),{...p,position:{x:E.x,y:E.y},size:{width:E.width,height:E.height}}});return{nodes:n.map(p=>a.get(p.id)??p),canvas:{...i,sections:l}}}const Kt=6;function Mo(e){let s=2166136261;for(let i=0;i<e.length;i++)s^=e.charCodeAt(i),s=Math.imul(s,16777619);return s>>>0}function Lo(e){const s=new Map;let i=new Set;for(const n of[...new Set(e)].sort()){i.size===Kt&&(i=new Set);let a=Mo(n)%Kt;for(;i.has(a);)a=(a+1)%Kt;i.add(a),s.set(n,a+1)}return s}function as(e){return`var(--w6w-loop-${e})`}function vn(e,s){const i=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),i.unshift(a);return i}function Fo(e,s,i){return s.size===0?e:e.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const a=n.sourceHandle===o.EACH_SOURCE_HANDLE?n.source:i.get(n.source),u=a?s.get(a):void 0;return u===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":as(u)}}})}function Do(e,s){const i=s.get(e);return i===void 0?void 0:{"--w6w-loop-color":as(i)}}function Oo(e){const s=[];for(const i of e){const n=o.isForeachStep(i.data.step);(n||i.data.loopOf)&&s.push([i.id,n?1:0,i.data.loopOf])}return JSON.stringify(s)}function _o(e){const s=JSON.parse(e);return{tones:Lo(s.filter(i=>i[1]===1).map(i=>i[0])),loopOf:new Map(s.map(i=>[i[0],i[2]]))}}const sn="Paused — test runs stop before this node",nn="Disabled — skipped in every run";function Qe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function We(e){return e.disabled===!0}function Sn(e,s){const{ui:i,...n}=e,{paused:a,...u}=i??{},l=s?{...u,paused:!0}:u;return Object.keys(l).length>0?{...n,ui:l}:n}function Cn(e,s){const{disabled:i,...n}=e;return s?{...n,disabled:!0}:n}function ns(e,s){return e.filter(i=>i.id!==s&&Qe(i)).map(i=>i.id)}const Wo=["nodes","steps"];function on(e,s){for(const i of Wo){const n=`${i}.${s}.output`;if(!e.startsWith(n))continue;const a=e.slice(n.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function Dt(e,s,i){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=o.parseRootAnchoredTemplate(e);let a=!1;const u=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const f=on(l.ref,s);return f===null?l:(a=!0,i.includes(l.ref)||i.push(l.ref),{...l,ref:f})});return a?Ie.serializeTemplate(u):e}if(o.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=on(n,s);return a===null?e:(i.includes(n)||i.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(u=>{const l=Dt(u,s,i);return l!==u&&(n=!0),l});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[u,l]of Object.entries(e)){const f=Dt(l,s,i);f!==l&&(n=!0),a[u]=f}return n?a:e}return e}function $o(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=o.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return o.isDollarPath(e)&&typeof e.$=="string"}function Nn(e){return Array.isArray(e)&&e.length===1&&$o(e[0])}function Bo(e){var s;try{const i=o.normalizeInput(e);if(!Array.isArray(i.nodes))return{};const n={},a=(l,f)=>{const p=Object.hasOwn(n,l)?n[l]:[];p.push(f),n[l]=p},u=new Map(i.nodes.map(l=>[l.id,l]));for(const[l,f]of Object.entries(o.definitionLoops(i))){const p=u.get(l);if(p&&Nn((s=p.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in f){a(l,{code:"loop_body_invalid",reason:{...f.invalid}});continue}for(const w of f.body){const x=u.get(w);if(!(x!=null&&x.with))continue;const g=[];Dt(x.with,l,g),g.length>0&&a(w,{code:"foreach_body_refs_output",foreachId:l,refs:g,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function Vo(e){const s=new Set,i=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)i(a)};return i(e),s}function zo(e){var s,i;try{const n=o.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(P=>typeof P=="object"&&P!==null&&typeof P.id=="string"),u=o.effectiveEdges({...n,nodes:a}).filter(P=>typeof(P==null?void 0:P.from)=="string"&&typeof(P==null?void 0:P.to)=="string"),l=[];for(const P of a)try{const M=Ie.staticWritePaths(Ie.effectiveStateConfig((s=P.uses)==null?void 0:s.app,(i=P.uses)==null?void 0:i.action,P.state));M.length>0&&l.push({id:P.id,paths:M})}catch{}if(l.length<2)return[];const f=new Map;for(const P of a)for(const M of o.controlOwnedIds(P))f.has(M)||f.set(M,P.id);const p=P=>{const M=[P];let C=P;for(;f.has(C)&&(C=f.get(C),!M.includes(C));)M.push(C);return M},w=P=>{const M=p(P);return M[M.length-1]},x=new Map;for(const P of u){const M=x.get(P.from)??[];M.push(P.to),x.set(P.from,M)}const g=new Map,S=P=>{const M=g.get(P);if(M)return M;const C=new Set,$=[...x.get(P)??[]];for(;$.length>0;){const K=$.pop();if(!C.has(K)){C.add(K);for(const V of x.get(K)??[])$.push(V)}}return g.set(P,C),C},v=(P,M)=>P===M||S(P).has(M),R=a.filter(P=>{var M;return((M=P.uses)==null?void 0:M.app)===o.CONTROL_APP&&P.uses.action==="parallel"}).map(P=>{var C;const M=(C=P.with)==null?void 0:C.branches;return Array.isArray(M)?M.map(Vo):[]}),E=(P,M)=>{for(const C of p(M)){const $=P.findIndex(K=>K.has(C));if($>=0)return $}return-1},D=[];for(const P of a){if(P.fanOut!=="parallel")continue;const M=new Map;for(const C of u){if(C.from!==P.id||o.isEachLink(C))continue;const $=C.when??"success",K=M.get($)??[];K.push(C.to),M.set($,K)}for(const C of M.values())C.length>=2&&D.push(C)}const h=(P,M)=>{for(const K of R){const V=E(K,P),b=E(K,M);if(V>=0&&b>=0&&V!==b)return!0}const C=w(P),$=w(M);return C===$||S(C).has($)||S($).has(C)?!1:D.some(K=>K.some((V,b)=>K.some((_,de)=>b!==de&&v(V,C)&&v(_,$))))},A=new Set,O=[];for(let P=0;P<l.length;P++)for(let M=P+1;M<l.length;M++){const C=l[P],$=l[M];if(!(C.id===$.id||!h(C.id,$.id)))for(const K of C.paths)for(const V of $.paths){if(!Ie.statePathsOverlap(K,V))continue;const b={code:"state_parallel_write",nodes:[C.id,$.id].sort(),path:[...K.length<=V.length?K:V]},_=JSON.stringify([b.nodes,b.path]);A.has(_)||(A.add(_),O.push(b))}}const U=(P,M)=>P<M?-1:P>M?1:0;return O.sort((P,M)=>U(P.code,M.code)||U(P.nodes.join(","),M.nodes.join(","))||U(P.path.join("."),M.path.join(".")))}catch{return[]}}function Ho(e){try{const s={};for(const i of zo(e))for(const n of i.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:i.code,path:[...i.path],with:i.nodes.filter(u=>u!==n)}),s[n]=a}return s}catch{return{}}}function kn(e,s){var i;if(s.code==="foreach_wrapped_items"){const n=(i=e.with)==null?void 0:i.items;return!e.with||!Nn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=Dt(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function rn(e,s,i){return e&&e.nodeId===s&&e.handleType===((i==null?void 0:i.type)??"source")?o.laneForSourceHandle(e.handleId):o.laneForSourceHandle(i==null?void 0:i.id)}function Jo(e,s,i,n,a){var w;const u=(w=n.find(x=>x.id===e))==null?void 0:w.data.step,l=o.loopMembership(n,a)[e]!==void 0,f=i==="success"&&l?"each":i;if(f==="each"&&!l&&!o.isForeachStep(u))return null;const p=i==="success"&&o.isForeachStep(u)?o.FOREACH_DONE_ROUTE:void 0;return o.loopRefusal(e,s,f,n,a,p)}function Ot(e,s){var i;return(i=e.nodes??e.steps)==null?void 0:i[s]}function os(e,s){const i=Ot(e,s);return(i==null?void 0:i.status)==="skipped"&&i.skipReason==="not_on_path"}const Uo=new Set(["succeeded","failed","canceled"]);function qo(e,s,i=[]){var u,l;if(!e||[...i,s].some(f=>os(e,f)))return"no-run";const n=Ot(e,s);if(n)return n.status;const a=new Set;for(const f of Object.values(e.nodes??e.steps??{}))if(Array.isArray(f==null?void 0:f.iterations))for(const p of f.iterations){const w=(l=(u=p==null?void 0:p.nodes)==null?void 0:u[s])==null?void 0:l.status;w&&a.add(w)}for(const f of["failed","running","succeeded","skipped"])if(a.has(f))return f;return"pending"}const an={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function En(e,s){const i=s!==void 0&&Uo.has(s);switch(e){case"no-run":return an;case"pending":return i?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return an}}function Go(e,s,i,n,a){var l;if(!e||os(e,s)||a!==void 0&&os(e,a))return;const u=Ko(e,s,i,n);return u==="taken"&&a!==void 0&&((l=Ot(e,a))==null?void 0:l.status)==="skipped"?"skipped":u}function Ko(e,s,i,n){const a=Ot(e,s);if(!a)return;if(i==="each")return a.status==="skipped"?"skipped":void 0;const u=i??"success",l=a.output,f=n===o.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!f&&a.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(a.status==="succeeded")return u==="success"?"taken":"skipped";if(a.status==="failed")return u==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const cn={fields:[],sampleValues:{}};function cs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Xo(e,s){var w;const i=e.map(x=>x.id),n=new Set(i),a=new Map(i.map(x=>[x,0])),u=new Map(i.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((w=u.get(x.source))==null||w.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const l=[],f=i.filter(x=>a.get(x)===0);for(;f.length>0;){const x=f.shift();l.push(x);for(const g of u.get(x)??[]){const S=(a.get(g)??0)-1;a.set(g,S),S===0&&f.push(g)}}const p=new Set(l);for(const x of i)p.has(x)||l.push(x);return l}const Yo=new Set(["string","number","boolean","object","array"]);function mt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let i=!1;for(const n of e){if(!cs(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let u=s;for(const p of a.slice(0,-1)){const w=u.fields[p];(w==null?void 0:w.type)!=="object"&&(u.fields[p]={type:"object",fields:{}}),u=u.fields[p]}const l=typeof n.type=="string"&&Yo.has(n.type)?n.type:"string";let f;if(l==="array"){const p=mt(n.items);f=p?{type:"array",items:p}:{type:"array"}}else l==="object"?f=mt(n.fields??n.properties)??{type:"object",fields:{}}:f={type:l};u.fields[a[a.length-1]]=f,i=!0}return i?s:void 0}function Zo(e,s){var w,x,g,S,v,R,E;const i=e.data.step,n=((w=s.testOutputs)==null?void 0:w[i.id])??((x=s.persistedOutputs)==null?void 0:x[i.id]);if(n!=null)return n;const{app:a,action:u}=i.uses;if(a===o.TRIGGER_APP&&((g=o.internalNodeDef(a,u))==null?void 0:g.group)==="trigger"){const D=o.fieldsToParams(o.asFieldDefs((S=i.with)==null?void 0:S.fields)).map(h=>({key:h.key}));return o.shapeToSkeleton(mt(D))}const l=(v=o.internalNodeDef(a,u))==null?void 0:v.output;if(l&&l.length>0)return o.shapeToSkeleton(mt(l));const f=i.uses.trigger===!0?(R=s.triggerDef)==null?void 0:R.call(s,a,u):(E=s.actionDef)==null?void 0:E.call(s,a,u),p=mt(f==null?void 0:f.output);return p?o.shapeToSkeleton(p):f==null?void 0:f.sample}function Qo(e,s){var f,p,w,x,g;const i=e.data.step,n=(f=s.previewOutputs)==null?void 0:f[i.id];if(n!=null)return n;const{app:a,action:u}=i.uses,l=i.uses.trigger===!0?(w=(p=s.shapes)==null?void 0:p.triggerDef)==null?void 0:w.call(p,a,u):(g=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:g.call(x,a,u);return l==null?void 0:l.sample}function ei(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function ln(e,s){const i=cs(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?i[n.key]=n.default:s||(i[n.key]=ei(n.type)));return i}function Xt(e){return(o.inferOutputFields(e)??[]).map(s=>s.key)}function ti(e){const{anchorId:s,nodes:i,edges:n}=e;if(!s)return cn;const a=e.shapes??{},u=e.floating?new Set(i.map(C=>C.id)):o.ancestorIds(s,n);u.delete(s);const l=new Map(i.map(C=>[C.id,C])),f=[],p=[],w=new Map;for(const C of Xo(i,n)){if(!u.has(C))continue;const $=l.get(C);if(!$)continue;const{app:K,action:V}=$.data.step.uses,b=Ie.effectiveStateConfig(K,V,$.data.step.state);if(b.mode==="off")continue;const _=Zo($,a);if(_!==void 0){const{ops:ue}=Ie.computeStateWrites(b,_);f.push(...ue);for(const je of Xt(Ie.foldState({},ue))){const ie=w.get(je)??new Set;ie.add(C),w.set(je,ie)}}const de=Qo($,e);de!==void 0&&p.push(...Ie.computeStateWrites(b,de).ops)}const x=ln(e,!1),g=Ie.foldState(x,f),S=Xt(g);if(S.length===0)return cn;const v=new Set(Xt(x)),R=new Map,E=new Map;for(const C of n)u.has(C.source)&&(!u.has(C.target)&&C.target!==s||(R.set(C.target,[...R.get(C.target)??[],C.source]),E.set(C.source,[...E.get(C.source)??[],C.target])));const D=[...u].filter(C=>!(R.get(C)??[]).length),h=C=>{const $=new Set,K=D.filter(V=>!C.has(V));for(;K.length>0;){const V=K.pop();if(V===s)return!1;if(!$.has(V)){$.add(V);for(const b of E.get(V)??[])C.has(b)||K.push(b)}}return!0},A=Ie.foldState(ln(e,!0),p),O=p.length>0?Ie.foldState({},p):void 0,U=cs(O)&&Object.keys(O).length>0?O:void 0,P=[],M={};for(const C of S){const $=w.get(C)??new Set,K=v.has(C)||$.size>0&&h($);P.push({key:C,path:!0,paths:K?"all":"some"});const V=o.valueAtPath(A,C);V!==void 0&&(M[`state.${C}`]=V)}return{fields:P,sampleValues:M,...U?{written:U}:{}}}const si={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},dn="Never fired";function ni(e){if(!e)return dn;const s=new Date(e);return Number.isNaN(s.getTime())?dn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function oi(e,s){var a;if(!(e!=null&&e.status))return null;const i=si[e.status];if(!i)return null;const n=e.status==="failed";return{label:i.label,tone:i.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:ni(e.lastFireAt),retryVisible:n&&s}}function ii(e){const s=new Map;for(const i of e)i.nodeId&&s.set(i.nodeId,i);return s}function ri(e){return(e??[]).filter(s=>{var i;return((i=s.uses)==null?void 0:i.trigger)===!0})}function ai(e,s){const[i,n]=c.useState({}),a=c.useRef(new Set),u=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!o.isInternalApp(l)).sort());return c.useEffect(()=>{const l=JSON.parse(u).filter(f=>!a.current.has(f));if(l.length!==0){for(const f of l)a.current.add(f);Promise.all(l.map(async f=>{try{return[f,await e.getAppActions(f)]}catch{return a.current.delete(f),null}})).then(f=>{const p=f.filter(w=>w!==null);p.length!==0&&n(w=>({...w,...Object.fromEntries(p)}))})}},[e,u]),i}function ci(e,s){const[i,n]=c.useState({}),a=c.useRef(new Set),u=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!o.isInternalApp(l)).sort());return c.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const f=JSON.parse(u).filter(p=>!a.current.has(p));if(f.length!==0){for(const p of f)a.current.add(p);Promise.all(f.map(async p=>{try{return[p,await l.call(e,p)]}catch{return a.current.delete(p),null}})).then(p=>{const w=p.filter(x=>x!==null);w.length!==0&&n(x=>({...x,...Object.fromEntries(w)}))})}},[e,u]),i}function li(e){return(s,i)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(u=>u.key===i))==null?void 0:a.ports}}const di="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function un(e,s,i,n){const a=e.find(u=>u.id===s);return[i,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ls=c.createContext(void 0),ds=c.createContext(new Map),us=c.createContext({tones:new Map,loopOf:new Map});function pn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const ps=c.createContext(new Map),Tn=c.createContext({byNode:new Map,subs:[]});function ui({apps:e,registration:s,children:i}){return t.jsx(ps.Provider,{value:e,children:t.jsx(Tn.Provider,{value:s,children:i})})}const fs=c.createContext(null);function pi(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(fi,{...e})})}function fn(e,s){let i=s.length+1;for(;s.includes(`${e}-${i}`);)i++;return`${e}-${i}`}function Yt(e){var s,i;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((i=e.measured)==null?void 0:i.height)??e.height??64}}function fi({onConnectionResourcesChange:e,value:s,onChange:i,readOnly:n,height:a=480,apps:u,exprOptions:l,project:f,runState:p,stepProblems:w,onTestRun:x,fitViewKey:g,onRunFromNode:S}){var Hs,Js,Us,qs,Gs,Ks,Xs;const v=o.useW6WApi(),R=c.useMemo(()=>new Map((u??[]).map(r=>[r.id,r])),[u]),E=yi(s),[D,h]=c.useState(null),A=c.useMemo(()=>o.centralizeConnections(s),[s.id]),O=c.useMemo(()=>o.workflowToFlow(A),[A]),[U,P]=c.useState(A.connections??{}),M=c.useRef(U),C=c.useCallback(r=>{M.current=r,P(r)},[]),$=c.useCallback(r=>{const d=o.centralizeConnections({nodes:[r],connections:M.current});return d.connections!==M.current&&C(d.connections),d.nodes[0]},[C]),K=c.useMemo(()=>o.storedViewport(s),[s.id]),V=((Hs=s.settings)==null?void 0:Hs.savePosition)!==!1,[b,_,de]=oe.useNodesState(O.nodes),ue=ai(v,b),je=ci(v,b),ie=c.useMemo(()=>li(ue),[ue]),[k,X,T]=oe.useEdgesState(O.edges),[W,B]=c.useState(null),ee=c.useMemo(()=>s.canvas??{},[s.id]),[H,z]=c.useState(ee),[J]=c.useState(()=>new To(Lt(A,O.nodes,O.edges,U,ee))),Z=c.useRef(),[pe,Je]=c.useState(0),[De,rt]=c.useState(!1),[ve,Ue]=c.useState(null),[Ae,ge]=c.useState(null),[ae,Ne]=c.useState(null),[$e,te]=c.useState(!1),gt=c.useRef({});c.useEffect(()=>{$e||(gt.current={})},[$e]);const[re,Pe]=c.useState(null),[Oe,ke]=c.useState("props"),[we,qe]=c.useState(null),[ye,Be]=c.useState(null),[Re,Me]=c.useState(null),at=c.useRef(!1),Se=c.useRef(null),[xe,_e]=c.useState(null),{screenToFlowPosition:Le,fitView:Fe}=oe.useReactFlow(),ct=o.useEffectiveTheme();c.useEffect(()=>{_(O.nodes),X(O.edges),B(null),Ne(null),Me(null),Pe(null),qe(null),z(ee),C(A.connections??{}),J.reset(Lt(A,O.nodes,O.edges,A.connections??{},ee)),Z.current=void 0},[O,ee,A,_,X,C,J]),c.useEffect(()=>{_(r=>{const d=new Map(o.stampLoopOf(r,k).map(m=>[m.id,m.data.loopOf]));return r.map(m=>{const y=qo(p,m.id,vn(m.id,d));return m.data.stepStatus===y&&m.data.runStatus===(p==null?void 0:p.status)?m:{...m,data:{...m.data,stepStatus:y,runStatus:p==null?void 0:p.status}}})}),X(r=>r.map(d=>{var I;const m=o.edgeLane(d),y=Go(p,d.source,m,typeof((I=d.data)==null?void 0:I.route)=="string"?d.data.route:void 0,d.target),j=o.edgeVisuals(m,y);return d.className===j.className&&d.label===j.label?d:{...d,className:j.className,label:j.label}}))},[p,O,pe,_,X]),c.useEffect(()=>{_(r=>o.applyStepProblems(r,w))},[w,O,pe,_]);const et=c.useCallback((r,d)=>{var j,I;const{canvas:m,...y}=r;return!((j=d.notes)!=null&&j.length)&&!((I=d.sections)!=null&&I.length)?y:{...y,canvas:go(d,s.canvas,V)}},[s.canvas,V]),Y=c.useCallback((r,d,m)=>{J.record(Lt(s,r,d,M.current,m??H),$e?gt.current:Z.current),i(et(o.flowToWorkflow({...s,connections:M.current},r,d),m??H))},[s,i,H,et,J,$e]),tt=c.useRef(()=>{});tt.current=r=>{if(n)return;const d=o.editConnectionResources(b.map(y=>y.data.step),M.current,r),m=b.map((y,j)=>({...y,data:{...y.data,step:d.nodes[j]}}));C(d.connections),_(m),Y(m,k)};const Ge=c.useCallback(r=>tt.current(r),[]),wt=c.useCallback(r=>{B(r),Ne(null),_(d=>d.map(m=>({...m,selected:m.id===r}))),X(d=>d.map(m=>({...m,selected:!1}))),Fe({nodes:[{id:r}],duration:300,maxZoom:1})},[_,X,Fe]),[lt,ce]=c.useState(null),xt=c.useMemo(()=>lt?b.map(r=>r.id===lt?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,lt]),bt=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),yt=JSON.stringify(bt),jt=JSON.stringify([...R]);c.useEffect(()=>{e==null||e({workflowId:s.id,nodes:bt,apps:R,connections:U,readOnly:n,edit:Ge,focusNode:wt,highlightNode:ce})},[e,s.id,yt,jt,U,n,Ge,wt]),c.useEffect(()=>()=>e==null?void 0:e(null),[e]);const vt=c.useCallback(r=>o.canConnect(r.source,r.target,b,k,ie,o.routeFromHandle(r.sourceHandle)),[b,k,ie]),[N,G]=c.useState(null),se=c.useRef(null),he=c.useRef(null);c.useEffect(()=>{_(r=>o.stampLoopOf(r,k))},[k,_]);const st=c.useCallback(r=>{if(n)return;const d=o.applyConnect(r.source,r.target,b,k,o.laneForSourceHandle(r.sourceHandle),ie,o.routeFromHandle(r.sourceHandle));if(!d){const m=o.laneForSourceHandle(r.sourceHandle),y=o.connectRefusal(r.source,r.target,b,k,m,ie,o.routeFromHandle(r.sourceHandle));if(y&&y.refused==="loop"){G({nodeId:r.source,reason:y.reason});return}if(y){const I=k.find(F=>F.source===r.source&&o.edgeLane(F)===m);I&&(X(k.map(F=>({...F,selected:F.id===I.id}))),Ne(I.id),Ke({edgeId:I.id,message:pn(y.cap)}));return}const j=o.connectConflict(r.source,r.target,b,k,o.laneForSourceHandle(r.sourceHandle));if(!j)return;X(k.map(I=>({...I,selected:I.id===j}))),Ne(j),Ke({edgeId:j,message:o.idClashMessage("Can’t draw that edge",j,un(k,j,r.source,r.target))});return}Ke(null),G(null),X(d),Y(b,d)},[k,b,X,Y,n,ie]),Wn=c.useCallback((r,d)=>{var q,Q,le;if(n||d.isValid)return;const m=d.fromNode;if(!m)return;const y=((q=d.fromHandle)==null?void 0:q.type)==="target"?"target":"source",j=d.toNode;if(j&&y==="source"){const ne=Jo(m.id,j.id,rn(he.current,m.id,d.fromHandle),b,k);if(ne){G({nodeId:m.id,reason:ne});return}}const I=(Q=b.find(ne=>ne.id===m.id))==null?void 0:Q.data.step;if(I){const ne=o.nodePortsForStep(I,ie);if((y==="source"?ne.out:ne.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,L=Le({x:F.clientX,y:F.clientY});_e({nodeId:m.id,handleType:y,position:L,lane:rn(he.current,m.id,d.fromHandle),route:o.routeFromHandle((le=d.fromHandle)==null?void 0:le.id)}),te(!0)},[n,Le,b,k,ie]),ms=c.useCallback((r,d,m)=>{if(n)return;const y=b.find(q=>q.id===r);if(!y)return;const j=Yt(y),I=o.laneForSourceHandle(m),F=120,L=d==="target"?{x:j.x-j.w-F,y:j.y}:I==="error"?{x:j.x,y:j.y+j.h+F}:I==="each"?{x:j.x+j.w+F,y:j.y-j.h-F/2}:{x:j.x+j.w+F,y:j.y};_e({nodeId:r,handleType:d,position:L,lane:I,route:o.routeFromHandle(m)}),te(!0)},[n,b]),gs=c.useCallback(r=>{n||Me({nodeIds:[r],edgeIds:[]})},[n]),$n=c.useCallback(r=>{if(n)return;const d=No(r,b,k,H);_(d.nodes),X(d.edges),z(d.canvas),d.nodes.some(m=>m.id===W)||B(null),d.nodes.some(m=>m.id===re)||Pe(null),d.edges.some(m=>m.id===ae)||Ne(null),Y(d.nodes,d.edges,d.canvas)},[b,k,H,_,X,Y,n,W,re,ae]),ws=c.useCallback(()=>{if(n)return;const r=Ro(b,k,H);_(r.nodes),z(r.canvas),at.current=!0,Y(r.nodes,k,r.canvas)},[b,k,H,_,Y,n]),Bn=c.useCallback(()=>{n||ws()},[n,ws]);c.useEffect(()=>{at.current&&(at.current=!1,Fe({duration:300}))},[b,Fe]);const xs=c.useRef(g);c.useEffect(()=>{Object.is(xs.current,g)||(xs.current=g,Fe({duration:300}))},[g,Fe]);const[St,Ke]=c.useState(null),nt=c.useMemo(()=>k.find(r=>r.id===ae)??null,[k,ae]),Vn=c.useCallback(r=>{if(n||!ae)return;const d=k.find(F=>F.id===ae);if(!d||o.edgeLane(d)===r)return;const m=o.edgeWhenConflict(k,ae,r,b),y=o.relaneRefusal(k,ae,r,b,ie),j=m||y?null:o.setEdgeWhen(k,ae,r,b,ie);if(!j){if(y){Ke({edgeId:ae,message:pn(y.cap)});return}Ke({edgeId:ae,message:m?o.idClashMessage("Can’t switch this edge",m,un(k,m,d.source,d.target)):"This edge can’t be switched right now."});return}Ke(null),X(j);const I=j.find(F=>F.source===d.source&&F.target===d.target&&o.edgeLane(F)===r);Ne((I==null?void 0:I.id)??null),Y(b,j)},[k,b,X,Y,n,ae,ie]),zn=c.useCallback(r=>{if(n)return;const d=k.filter(m=>m.id!==r);d.length!==k.length&&(X(d),ae===r&&Ne(null),Y(b,d))},[b,k,X,Y,n,ae]),Wt=c.useCallback(r=>{if(n)return;const d=r.map(I=>b.find(F=>F.id===I)).filter(I=>I!==void 0);if(d.length===0)return;const m=b.map(I=>I.id),y=d.map(I=>{const F=o.suggestStepId(m,`${I.data.step.id}_copy`);m.push(F);const L={...o.stripBody(structuredClone(I.data.step)),id:F};return{id:F,type:I.type,position:{x:I.position.x+40,y:I.position.y+60},data:{step:L,isInternal:I.data.isInternal},...d.length>1?{selected:!0}:{}}}),j=[...d.length>1?b.map(I=>I.selected?{...I,selected:!1}:I):b,...y];_(j),B(y[0].id),Y(j,k)},[b,k,_,Y,n]),bs=c.useCallback(r=>Wt([r]),[Wt]),Hn=c.useCallback(r=>{if(n)return;const d=o.isInternalApp(r.uses.app),m=b.map(ne=>ne.id),y=r.id&&!o.stepNameError(r.id,m)?r.id:o.suggestStepId(m,o.slugifyLabel(o.internalNodeLabel(r.uses.app,r.uses.action))),j=$({id:y,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),I={id:y,type:d?"control":"step",position:(xe==null?void 0:xe.position)??(ye==null?void 0:ye.position)??{x:80,y:80+b.length*24},data:{step:j,isInternal:d}},F=ye!=null&&ye.replaces?b.find(ne=>ne.id===ye.replaces):void 0;if(F&&o.isTriggerStep(r.uses)){const ne={...I,position:F.position},fe=[...b.filter(pt=>pt.id!==F.id),ne],me=o.renameStepInEdges(k,F.id,y),Te=Qt(H,F.id,y);return _(fe),X(me),z(Te),G(null),B(y),Y(fe,me,Te),y}const L=[...b,I];let q=k,Q=null;const le=(ne,fe,me,Te)=>{const pt=o.connectRefusal(ne,fe,L,k,me,ie);pt&&pt.refused==="loop"&&(Q={nodeId:Te,reason:pt.reason})};if(xe){const[ne,fe]=xe.handleType==="target"?[y,xe.nodeId]:[xe.nodeId,y],me=o.applyConnect(ne,fe,L,k,xe.lane,ie,xe.route);me||le(ne,fe,xe.lane,xe.nodeId),q=me??k}else{const ne=b.find(fe=>o.isTriggerStep(fe.data.step.uses));if(o.isTriggerStep(r.uses)){if(!ne){const fe=o.findChainRoot(b,k);if(fe){const me=o.applyConnect(y,fe.id,L,k,"success",ie);me||le(y,fe.id,"success",fe.id),q=me??k}}}else{const me=(ne&&!k.some(Te=>Te.source===ne.id)?ne:void 0)??o.findChainTail(b,k);if(me){const Te=o.applyConnect(me.id,y,L,k,"success",ie);Te||le(me.id,y,"success",me.id),q=Te??k}}}return _(L),q!==k&&X(q),G(Q),B(y),Y(L,q),y},[b,k,_,X,Y,n,xe,ye,ie,$,H]),ys=c.useCallback((r,d)=>{var q;let m=d;const y=(q=b.find(Q=>Q.id===r))==null?void 0:q.data.step;if(d.uses.connection&&!d.uses.connectionRef&&(y!=null&&y.uses.connectionRef)&&y.uses.app===d.uses.app){const Q=o.selectNodeConnection(o.withConnectionRef(d,y.uses.connectionRef),d.uses.connection,b.map(le=>le.data.step),M.current);C(Q.connections),m=Q.step}else m=$(d);const j=m.id!==r;if(j&&b.some(Q=>Q.id===m.id))return;const I=b.map(Q=>Q.id===r?{...Q,id:m.id,data:{step:m,isInternal:o.isInternalApp(m.uses.app)}}:Q);if(j){const Q=o.renameStepInEdges(k,r,m.id),le=Qt(H,r,m.id);_(I),X(Q),z(le),W===r&&B(m.id),re===r&&Pe(m.id),Y(I,Q,le);return}_(I);const F=new Set(o.routesForStep(m).map(Q=>Q.id)),L=k.filter(Q=>{var le;return Q.source!==m.id||((le=Q.data)==null?void 0:le.route)===void 0||F.has(String(Q.data.route))});L.length!==k.length&&X(L),Y(I,L)},[b,k,H,_,X,W,re,Y,$,C]),Xe=c.useCallback(r=>{n||(z(r),Y(b,k,r))},[n,b,k,Y]),Jn=c.useCallback(()=>{var j;if(n)return;const r=(j=Se.current)==null?void 0:j.getBoundingClientRect(),d=r?Le({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},m=H.notes??[],y={id:fn("note",m.map(I=>I.id)),color:"#facc15",position:{x:Math.round(d.x-100),y:Math.round(d.y-60)},size:{width:200,height:120},content:""};Xe(ts({...H,notes:[...m,y]}))},[n,H,Le,Xe]),Un=c.useCallback((r,d)=>{if(n)return;const m=d?Math.min(r.x,d.x):r.x,y=d?Math.min(r.y,d.y):r.y,j=d?Math.abs(d.x-r.x):360,I=d?Math.abs(d.y-r.y):240,F=b.filter(ne=>{const fe=Yt(ne),me=fe.x+fe.w/2,Te=fe.y+fe.h/2;return me>=m&&me<=m+j&&Te>=y&&Te<=y+I}).map(ne=>ne.id),L=H.sections??[],q=fn("section",L.map(ne=>ne.id)),Q={id:q,title:"Section",color:"#6366f1",position:{x:Math.round(m),y:Math.round(y)},size:{width:Math.round(j),height:Math.round(I)},nodes:[]},le={...H,sections:[...L,Q]};Xe(ts(es(le,q,F)))},[n,b,H,Xe]);c.useEffect(()=>{if(!De)return;const r=d=>{d.key==="Escape"&&(rt(!1),Ue(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[De]);const qn=c.useCallback((r,d)=>{var F;if(n)return;const m=(F=H.sections)==null?void 0:F.find(L=>L.id===r);if(!m)return;const y=new Set(m.nodes),j=b.map(L=>y.has(L.id)?{...L,position:{x:L.position.x+d.dx,y:L.position.y+d.dy}}:L),I={...H,sections:(H.sections??[]).map(L=>L.id===r?{...L,position:{x:L.position.x+d.dx,y:L.position.y+d.dy}}:L)};_(j),z(I),Y(j,k,I)},[n,H,b,k,_,Y]),Gn=c.useCallback((r,d)=>{if(n)return;const m=r==="note"?{...H,notes:(H.notes??[]).filter(y=>y.id!==d)}:{...H,sections:(H.sections??[]).filter(y=>y.id!==d)};Xe(m)},[n,H,Xe]),Kn=r=>{let d=H;for(const m of r){const y=Yt(m),j=y.x+y.w/2,I=y.y+y.h/2,F=(d.sections??[]).find(q=>j>=q.position.x&&j<=q.position.x+q.size.width&&I>=q.position.y&&I<=q.position.y+q.size.height),L=bn(d,m.id);F?(L.length!==1||L[0]!==F.id)&&(d=es(d,F.id,[m.id])):L.length>0&&(d=rs(d,m.id))}return d},$t=c.useCallback((r,d,m)=>{(async()=>{const y=await v.saveStepTest(s.id,r,d).catch(j=>(console.error("step run fixture save failed",j),null));await v.recordStepTestRun(s.id,r,{stepTestId:(y==null?void 0:y.id)??null,status:m.status,input:d.input,output:m.output,error:m.error,...m.meta?{meta:m.meta}:{}})})().catch(y=>{console.error("step run persist failed",y)})},[v,s.id]),js=c.useCallback(r=>{const d=b.find(m=>m.id===r);!d||!S&&o.isControlApp(d.data.step.uses.app)||h({stepId:r,status:"collect"})},[b,S]),Xn=c.useCallback(async(r,d,m)=>{if(!S)return;const y=b.find(F=>F.id===r);if(!y)return;const j=o.isTriggerStep(y.data.step.uses),I={stopAt:ns(b.map(F=>F.data.step),r),...m?{state:m}:{},...j?{input:d}:{}};h({stepId:r,status:"running"});try{await S(r,I),h(null)}catch(F){const L=F;h({stepId:r,status:"error",error:L.message??String(F),errorCode:L.code})}},[b,S]),Ct=c.useCallback((r,d)=>{if(n)return;const m=b.map(y=>y.id===r?{...y,data:{...y.data,step:d(y.data.step)}}:y);_(m),Y(m,k)},[b,k,_,Y,n]),vs=c.useCallback(r=>Ct(r,d=>Sn(d,!Qe(d))),[Ct]),Ss=c.useCallback(r=>Ct(r,d=>Cn(d,!We(d))),[Ct]),Yn=c.useCallback(async(r,d,m)=>{x==null||x();const y=b.find(q=>q.id===r);if(!y)return;const j=y.data.step,I=o.isTriggerStep(j.uses),F=I?{input:d}:{...j.with??{},...d},L=I?{input:d,with:d}:{input:d,with:F};h({stepId:r,status:"running"});try{const q=await v.invokeAction(j.uses.app,j.uses.action,F,{connectionId:o.connectionIdFor(j,M.current),project:f,...m?{state:m}:{},workflowId:s.id}),Q=q.logs,le=q.meta;h({stepId:r,status:"done",value:q.value,logs:Q,...le?{meta:le}:{}}),$t(r,L,{status:"succeeded",output:q.value,...le?{meta:le}:{}})}catch(q){const Q=q;h({stepId:r,status:"error",error:Q.message??String(q),errorCode:Q.code}),$t(r,L,{status:"failed",error:Q.message??String(q)})}},[b,v,$t,f,x,s.id]),Bt=c.useMemo(()=>({onEdit:r=>{ke("props"),Pe(r)},onEditJson:r=>{ke("json"),Pe(r)},onRun:js,onDuplicate:bs,onDelete:gs,onTogglePause:vs,onToggleDisable:Ss,runsFromNode:!!S,onAddFromPort:ms,readOnly:n}),[js,bs,gs,vs,Ss,S,ms,n]);c.useEffect(()=>{const r=Se.current;if(!r)return;const d=m=>{const y=m.target.closest(".react-flow__node");if(!y)return;const j=y.getAttribute("data-id");j&&(m.stopPropagation(),Bt.onEdit(j))};return r.addEventListener("dblclick",d,!0),()=>r.removeEventListener("dblclick",d,!0)},[Bt]);const ot=b.find(r=>r.id===re),Nt=(ot==null?void 0:ot.data.step)??null,Vt=D?((Js=b.find(r=>r.id===D.stepId))==null?void 0:Js.data.step)??null:null,zt=(D==null?void 0:D.status)==="collect"&&!!Vt,Cs=c.useMemo(()=>{const r=new Map;for(const d of b)r.set(d.id,o.fanOutState(d.id,k).count);return r},[b,k]),Ns=Oo(b),kt=c.useMemo(()=>_o(Ns),[Ns]),Zn=c.useMemo(()=>Fo(k,kt.tones,kt.loopOf),[k,kt]),Qn=c.useMemo(()=>({step:vi,control:Si}),[]),[Et,ks]=c.useState({}),[Tt,Es]=c.useState({}),[Ts,Is]=c.useState({}),[It,As]=c.useState({}),[Ve,At]=c.useState(null),[Ps,Rs]=c.useState([]),eo=re??Ve??"";c.useEffect(()=>{const r=v.loadNodeSamples;if(typeof r!="function"||!s.id){Rs([]);return}let d=!1;return r(s.id).then(m=>{d||Rs(Array.isArray(m)?m:[])},()=>{}),()=>{d=!0}},[v,s.id,eo]);const Pt=c.useMemo(()=>o.indexNodeSamples(Ps),[Ps]),Ht=c.useMemo(()=>o.splitNodeOutputs(Et,Pt,It),[Et,Pt,It]),ze=c.useMemo(()=>o.splitPreviewOutputs(Et,Pt,It),[Et,Pt,It]),Ce=c.useMemo(()=>({actionDef:(r,d)=>{var m;return(m=ue[r])==null?void 0:m.find(y=>y.key===d)},triggerDef:(r,d)=>{var m;return(m=je[r])==null?void 0:m.find(y=>y.key===d)},testOutputs:Ht.fresh,persistedOutputs:Ht.persisted,loopSamples:Ts}),[ue,je,Ht,Ts]),Ye=c.useMemo(()=>D?o.upstreamStateSources(D.stepId,b,k,Ce):void 0,[D,b,k,Ce]),to=c.useMemo(()=>(Ye==null?void 0:Ye.steps)??[],[Ye]),be=c.useMemo(()=>{const r=o.upstreamStateSources(re,b,k,Ce,Ve);return{...r,steps:o.excludeSelfStep(r.steps,re??Ve)}},[re,Ve,b,k,Ce]),dt=c.useMemo(()=>ti({anchorId:re??Ve,nodes:b,edges:k,floating:o.isFloatingDraft(re,Ve,b,k),initialState:s.initialState,variables:s.variables,shapes:Ce,previewOutputs:{...ze.persisted,...ze.fresh}}),[re,Ve,b,k,s.initialState,s.variables,Ce,ze]),Ms=JSON.stringify([...be.steps.map(r=>r.id),...be.extraSampleIds??[]]);c.useEffect(()=>{const r=JSON.parse(Ms);if(!re&&!Ve||r.length===0){ks({}),Es({}),Is({}),As({});return}let d=!1;return Promise.all(r.map(async m=>{try{const y=await v.listStepTests(s.id,m),j=y.length?y[y.length-1]:null;return j?{id:m,output:j.lastRunOutput,runAt:j.lastRunAt,meta:j.lastRunMeta,loopSample:o.foreachTestSample(j)}:null}catch{return null}})).then(m=>{if(d)return;const y={},j={},I={},F={};for(const L of m)L!=null&&L.meta&&(j[L.id]=L.meta),L!=null&&L.loopSample&&(I[L.id]=L.loopSample),!(!L||L.output===void 0||L.output===null)&&(y[L.id]=L.output,F[L.id]=L.runAt);ks(y),As(F),Es(j),Is(I)}),()=>{d=!0}},[v,s.id,re,Ve,Ms]);const Jt=c.useMemo(()=>o.declaredSamples(b,Ce),[b,Ce]),Rt=c.useMemo(()=>({persisted:ze.persisted,samples:Jt.samples,event:Jt.event}),[ze.persisted,Jt]),Ls=c.useMemo(()=>o.upstreamSampleValues(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Fs=c.useMemo(()=>o.upstreamSampleValueSources(be.steps,ze.fresh,Tt,be.loop,Rt),[be.steps,be.loop,ze.fresh,Tt,Rt]),Ds=o.useExpressionOptions(),Os=c.useMemo(()=>o.nodeConfigSources(b),[b]),_s=c.useMemo(()=>o.nodeConfigValues(b,E.subs),[b,E.subs]),Ut=c.useMemo(()=>o.nodeMetaValues(b,E.subs,R,U),[b,E.subs,R,U]),qt=c.useMemo(()=>({...l??{},steps:be.steps,hasTrigger:be.hasTrigger,eventOutputs:be.eventOutputs,eventOutputsFrom:be.eventOutputsFrom,loop:be.loop,stateShape:{fields:dt.fields,...dt.written?{written:dt.written}:{}},nodeConfigs:Os,nodeConfig:_s,nodeMeta:Ut,valueSources:Fs,sampleValues:{...Ds.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...o.nodeMetaSampleValues(Ut),...Ls,...dt.sampleValues}}),[l,Ds.sampleValues,be,dt,Ls,Fs,Os,_s,Ut]),ut=c.useRef(null);$e||re?ut.current===null&&(ut.current=J.mark()):ut.current=null;const Ws=()=>{te(!1),_e(null),Be(null),At(null)},$s=()=>{const r=ut.current;if(ut.current=null,n||r===null)return;const d=J.rollbackTo(r);d&&Vs(d)},Bs=r=>{if(n)return;const d=J[r]();d&&Vs(d)},Vs=r=>{var y;const d=Eo(s,r);_(d.nodes.map(j=>({...j,selected:j.id===W}))),X(d.edges.map(j=>({...j,selected:j.id===ae}))),z(r.canvas),C(r.connections),d.nodes.some(j=>j.id===W)||B(null),d.edges.some(j=>j.id===ae)||Ne(null);const m=d.nodes.some(j=>j.id===re);m||Pe(null),te(!1),At(null),_e(null),Me(null),ge(null),Be(null),qe(null),G(null),Ke(null),Z.current=void 0,Je(j=>j+1),i(et(o.flowToWorkflow({...s,nodes:r.nodes,connections:r.connections},d.nodes,d.edges),r.canvas)),!m&&!D&&((y=Se.current)==null||y.focus({preventScroll:!0}))},zs=c.useRef(Bs);zs.current=Bs,c.useEffect(()=>{const r=Se.current;if(!r)return;let d=r.contains(document.activeElement);const m=j=>{j.type==="focusin"&&j.target===document.body||(d=r.contains(j.target))},y=j=>{if(n||j.defaultPrevented||Gt(j.target)||!r.contains(j.target)&&!(d&&j.target===document.body))return;const I=j.key.toLowerCase();!(j.ctrlKey||j.metaKey)||j.altKey||I!=="z"&&!(I==="y"&&!j.shiftKey)||(j.preventDefault(),zs.current(I==="y"||j.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",m),document.addEventListener("focusin",m),document.addEventListener("keydown",y),()=>{document.removeEventListener("pointerdown",m),document.removeEventListener("focusin",m),document.removeEventListener("keydown",y)}},[n]);const Mt=c.useCallback((r,d)=>{var L;if(Gt(r.target))return;const m=(L=Se.current)==null?void 0:L.getBoundingClientRect();if(!m)return;r.preventDefault();const y=tn(b,k),j=y.nodeIds,I=uo(j,d),F=d!==void 0&&!j.includes(d);F&&_(b.map(q=>q.selected!==(q.id===d)?{...q,selected:q.id===d}:q)),qe({x:r.clientX-m.left,y:r.clientY-m.top,flow:Le({x:r.clientX,y:r.clientY}),nodeIds:I,edgeIds:F?[]:y.edgeIds})},[b,k,_,Le]),so=c.useCallback(r=>{var d;qe(null),r&&((d=Se.current)==null||d.focus({preventScroll:!0}))},[]),no=r=>{const d=we;if(!(!d||n))if(r==="duplicate")Wt(d.nodeIds);else if(r==="delete")Me({nodeIds:d.nodeIds,edgeIds:d.edgeIds});else if(r==="replace-trigger"){const m=b.find(y=>y.id===d.nodeIds[0]);if(!m)return;_e(null),Be({position:m.position,tab:"triggers",replaces:m.id}),te(!0)}else _e(null),Be({position:d.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),te(!0)},oo=t.jsx(fs.Provider,{value:Bt,children:t.jsx(ls.Provider,{value:ie,children:t.jsx(ds.Provider,{value:Cs,children:t.jsx(us.Provider,{value:kt,children:t.jsx(ui,{apps:R,registration:E,children:t.jsx(o.WorkflowProjectProvider,{project:f,workflowId:s.id,children:t.jsx(o.ExpressionOptionsProvider,{value:qt,children:t.jsxs("section",{ref:Se,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{Z.current=Gt(r.target)?{}:void 0},onBlurCapture:()=>{Z.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||re||$e||Re)return;const d=r.target;if(d.isContentEditable||d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.tagName==="SELECT"||d.closest("dialog, .w6w-modal")!==null)return;const m=tn(b,k);!m.nodeIds.length&&!m.edgeIds.length||(r.preventDefault(),!m.nodeIds.length&&m.edgeIds.length===1?zn(m.edgeIds[0]):Me(m))},children:[t.jsxs(oe.ReactFlow,{nodes:xt,edges:Zn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:de,onEdgesChange:T,onConnect:st,onConnectStart:(r,d)=>{he.current=d},onConnectEnd:Wn,onPaneClick:()=>G(null),onPaneContextMenu:r=>Mt(r),onNodeContextMenu:(r,d)=>Mt(r,d.id),onEdgeContextMenu:r=>Mt(r),onSelectionContextMenu:r=>Mt(r),onMoveStart:()=>qe(null),isValidConnection:vt,onNodeDragStop:(r,d,m)=>{const y=Kn(m),j=y!==H;if(j&&z(y),!V&&!j){J.record(Lt(s,b,k,M.current,y));return}Y(b,k,y)},onMoveEnd:(r,d)=>{if(!r||n)return;const m=o.flowToWorkflow(s,b,k),y=o.withViewport(m,d);y!==m&&i(y,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:d})=>{var m,y,j,I;B(((m=r[0])==null?void 0:m.id)??null),Ne(((y=d[0])==null?void 0:y.id)??null),se.current!==(((j=r[0])==null?void 0:j.id)??null)&&(se.current=((I=r[0])==null?void 0:I.id)??null,G(null))},nodeTypes:Qn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...K?{defaultViewport:K}:{fitView:!0,fitViewOptions:{maxZoom:1}},deleteKeyCode:null,colorMode:ct,proOptions:{hideAttribution:!0},children:[t.jsx(oe.Background,{gap:16}),t.jsx(oe.Controls,{showInteractive:!1,children:!n&&t.jsx(oe.ControlButton,{onClick:Bn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(Ee.Icon,{name:"layout"})})}),t.jsx(oe.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(oe.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>te(!0),children:"+ Node"}),t.jsx(o.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Jn}),t.jsx(o.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${De?" active":""}`,"aria-pressed":De,"data-testid":"draw-section",onClick:()=>{rt(!De),Ue(null)}})]}),!n&&De&&t.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:r=>{if(r.button!==0)return;r.currentTarget.setPointerCapture(r.pointerId);const{clientX:d,clientY:m}=r;Ue({sx:d,sy:m,ex:d,ey:m})},onPointerMove:r=>{const{clientX:d,clientY:m}=r;Ue(y=>y&&{...y,ex:d,ey:m})},onPointerUp:()=>{const r=ve;if(Ue(null),rt(!1),!r)return;const d=Le({x:r.sx,y:r.sy}),m=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Un(d,m?Le({x:r.ex,y:r.ey}):null)},children:ve&&(()=>{var y;const r=(y=Se.current)==null?void 0:y.getBoundingClientRect(),d=(r==null?void 0:r.left)??0,m=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ve.sx,ve.ex)-d,top:Math.min(ve.sy,ve.ey)-m,width:Math.abs(ve.ex-ve.sx),height:Math.abs(ve.ey-ve.sy)}})})()}),!n&&nt&&o.edgeLane(nt)!=="each"&&((Us=b.find(r=>r.id===nt.source))==null?void 0:Us.data.step.uses.app)!==o.ROUTER_APP&&t.jsx(oe.Panel,{position:"top-right",children:t.jsxs("div",{className:"w6w-edge-lane",children:[t.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(r=>t.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${o.edgeLane(nt)===r?" active":""}`,"aria-pressed":o.edgeLane(nt)===r,title:di,onClick:()=>Vn(r),children:r==="success"?"Success":"Error"},r)),(St==null?void 0:St.edgeId)===nt.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:St.message})]})}),N&&t.jsx(oe.NodeToolbar,{nodeId:N.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:o.loopRefusalMessage(N.reason)})}),t.jsx(o.CanvasLayer,{canvas:H,readOnly:n,savePosition:V,onChange:Xe,onSectionDrop:qn,onRequestDelete:(r,d)=>!n&&ge({kind:r,id:d})})]}),Ae&&t.jsx(o.ConfirmModal,{title:Ae.kind==="note"?"Delete note":"Delete section",message:Ae.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Gn(Ae.kind,Ae.id),ge(null)},onClose:()=>ge(null)}),$e&&t.jsx(o.StepBuilderModal,{initialTab:ye==null?void 0:ye.tab,onClose:()=>{$s(),Ws()},onDone:Ws,onAdd:r=>{const d=Hn(r);return d&&At(d),d},onDraftChange:(r,d)=>ys(r,{id:r,...d}),stepIds:b.map(r=>r.id),onOpenStep:r=>{te(!1),_e(null),Be(null),At(null),ke("props"),Pe(r)},workflowId:s.id,upstreamSteps:o.stepBuilderUpstreamSteps(xe,b,k),loop:o.stepBuilderLoop(xe,b,k,Ce)}),Nt&&re&&t.jsx(Ni,{workflowId:s.id,step:Nt,restoreVersion:pe,upstreamSteps:qt.steps??[],loop:qt.loop,readOnly:n,fanOutCount:Cs.get(re)??0,stateOutputFields:(Xs=o.resolveOutputShape((qs=Ce.actionDef)==null?void 0:qs.call(Ce,Nt.uses.app,Nt.uses.action),(Gs=Ce.testOutputs)==null?void 0:Gs[re],(Ks=Ce.persistedOutputs)==null?void 0:Ks[re]))==null?void 0:Xs.fields.map(r=>r.key),initialView:Oe,stepProblems:ot==null?void 0:ot.data.stepProblems,otherStepIds:b.filter(r=>r.id!==re).map(r=>r.id),onChange:r=>ys(re,r),onClose:()=>Pe(null),onCancel:()=>{$s(),Pe(null)},onTestRun:x}),D&&t.jsxs(o.Modal,{title:`${zt?"Run node":"Test run"}: ${D.stepId}`,onClose:()=>h(null),children:[zt&&Vt&&t.jsx(wi,{workflowId:s.id,step:Vt,upstreamSteps:to,loop:Ye==null?void 0:Ye.loop,continues:S?{stopAt:ns(b.map(r=>r.data.step),D.stepId)}:void 0,onCancel:()=>h(null),onRun:(r,d)=>S?Xn(D.stepId,r,d):Yn(D.stepId,r,d)},D.stepId),!zt&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[D.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),D.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[D.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:D.errorCode})}),D.error||"The node failed with no error message."]}),D.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(o.ResultViewer,{value:D.value,maxHeight:360}),D.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(o.ResultViewer,{value:D.meta,maxHeight:360})]})]}),D.logs&&D.logs.length>0&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),t.jsx(Ee.Copyable,{value:D.logs.join(`
|
|
2
2
|
`),label:"Copy console output",children:t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:D.logs.join(`
|
|
3
3
|
`)})})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>h(null),children:"Close"})})]})]}),Re!==null&&t.jsx(o.ConfirmModal,{title:Re.nodeIds.length===1?"Delete node":Re.nodeIds.length>1?`Delete ${Re.nodeIds.length} nodes`:`Delete ${Re.edgeIds.length} connections`,message:ko(Re,b,k),confirmLabel:"Delete",autoFocusConfirm:!0,onConfirm:()=>{$n(Re),Me(null)},onClose:()=>Me(null)}),we&&t.jsx(ao,{x:we.x,y:we.y,items:po(we.nodeIds,!!n,{replaceableTrigger:we.nodeIds.length===1&&b.some(r=>r.id===we.nodeIds[0]&&o.isTriggerStep(r.data.step.uses))}),onAction:no,onClose:so})]})})})})})})})});return t.jsx(o.WorkflowConnectionsContext.Provider,{value:{nodes:b.map(r=>r.data.step),connections:U,setConnections:C,readOnly:n},children:oo})}const hi=["code"];function _t(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function mi(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return _t(e)}function gi({items:e,save:s}){if(!e)return t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[t.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",t.jsx("strong",{children:"Override the incoming state"})," below."]});const i=e[0],n=i!==void 0?(o.inferOutputFields(i)??[]).map(a=>a.key):[];return t.jsxs("div",{className:"w6w-testout",children:[t.jsxs("div",{className:"w6w-testout-label",children:[e.length," ",e.length===1?"item":"items"]}),e.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-testout-label",children:"First item"}),t.jsx(o.ResultViewer,{value:i,maxHeight:220})]}),s==="saved"&&t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&t.jsxs(t.Fragment,{children:[" ","Steps on ",t.jsx("strong",{children:"Each item"})," now offer ",t.jsx("strong",{children:"Current item"})," ›"," ",n.map((a,u)=>t.jsxs("span",{children:[u>0&&", ",t.jsx("code",{children:a})]},a)),"."]})]}),s==="failed"&&t.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function In(e){const[s,i]=c.useState(null),[n,a]=c.useState("0"),[u,l]=c.useState({}),[f,p]=c.useState({}),w=s??o.loopItemText(e),x=((e==null?void 0:e.outer)??[]).map(v=>({foreachId:v.foreachId,name:v.name??v.foreachId,itemText:u[v.foreachId]??o.loopItemText(v),indexText:f[v.foreachId]??"0",setItemText:R=>l(E=>({...E,[v.foreachId]:R})),setIndexText:R=>p(E=>({...E,[v.foreachId]:R}))})),g=e?o.parseLoopSeed(w,n):void 0;let S=g!=null&&g.ok?{ok:!0,value:g.value}:g;if(e&&(g!=null&&g.ok)){const v={};for(const R of x){const E=o.parseLoopSeed(R.itemText,R.indexText);if(!E.ok){S={ok:!1,error:`${R.name}: ${E.error}`};break}v[R.foreachId]=E.value}S!=null&&S.ok&&(v[e.foreachId]=g.value,S={ok:!0,value:{...g.value,loops:v}})}return{active:!!e,itemText:w,indexText:n,setItemText:i,setIndexText:a,outers:x,parsed:S}}function An(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function hs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function Pn({seed:e,readOnly:s}){if(!e.active)return null;const i=hs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[e.outers.map(n=>t.jsxs("div",{"data-testid":`loop-seed-outer-${n.foreachId}`,children:[t.jsxs("span",{children:[n.name," item"]}),t.jsx("textarea",{rows:3,value:n.itemText,readOnly:s,spellCheck:!1,"aria-label":`${n.name} item`,onChange:a=>n.setItemText(a.target.value)}),t.jsxs("span",{children:[n.name," index"]}),t.jsx("input",{type:"text",inputMode:"numeric",value:n.indexText,readOnly:s,"aria-label":`${n.name} index`,onChange:a=>n.setIndexText(a.target.value)})]},n.foreachId)),t.jsx("span",{children:"Current item"}),t.jsx("textarea",{rows:3,value:e.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>e.setItemText(n.target.value)}),t.jsx("span",{children:"Index"}),t.jsx("input",{type:"text",inputMode:"numeric",value:e.indexText,readOnly:s,"aria-label":"Index",onChange:n=>e.setIndexText(n.target.value)}),t.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),i&&t.jsx("span",{className:"w6w-hint",role:"alert",children:i})]})}function is({text:e,onChange:s,seeds:i,readOnly:n,expand:a,hint:u}){const l=_t(e),f=l?Object.keys(l).length:0,p=f>0,[w,x]=c.useState(p);c.useEffect(()=>{(p||a)&&x(!0)},[p,a]);const g=S=>{s(JSON.stringify(S.lastRunOutput??S.input??{},null,2)),x(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),i.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:i.map(S=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${S.label}'s saved test as the incoming state`,disabled:n,onClick:()=>g(S.test),children:[t.jsx("code",{children:S.label}),S.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",S.test.lastRunStatus]}):null]},S.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:w,onToggle:S=>x(S.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",f>0?` · ${f} key${f===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:S=>s(S.target.value)}),t.jsx("span",{className:"w6w-hint",children:u??t.jsxs(t.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",t.jsx("code",{children:"input"}),": ",t.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",t.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function wi({workflowId:e,step:s,upstreamSteps:i,loop:n,onRun:a,onCancel:u,continues:l}){var H;const f=o.useW6WApi(),p=o.isTriggerStep(s.uses),w=o.isInternalApp(s.uses.app),x=c.useMemo(()=>{var z;return p?o.asFieldDefs((z=s.with)==null?void 0:z.fields):[]},[p,s.with]),g=c.useMemo(()=>p?o.fieldsToParams(x):w?o.internalNodeParams(s.uses.app,s.uses.action):null,[p,w,x,s.uses.app,s.uses.action]),[S,v]=c.useState(null),R=g??S;c.useEffect(()=>{if(g)return;if(!s.uses.app||!s.uses.action){v([]);return}let z=!1;return v(null),f.getAppActions(s.uses.app).then(J=>{var Z;z||v(((Z=J.find(pe=>pe.key===s.uses.action))==null?void 0:Z.params)??[])}).catch(()=>!z&&v([])),()=>{z=!0}},[f,g,s.uses.app,s.uses.action]);const[E,D]=c.useState(()=>{var z;return p?o.seedValues(o.asFieldDefs((z=s.with)==null?void 0:z.fields)):{}}),[h,A]=c.useState("{}"),O=o.useSeedSources(e,i,!p),U=In(n),P=(H=o.useExpressionOptions().stateShape)==null?void 0:H.written,M=o.startStateFromSeeds(O,An(U),P),C=o.useRememberedTestInput(e,s.id),[$,K]=c.useState(!1),[V,b]=c.useState(!1);c.useEffect(()=>{if(!C.loaded)return;let z=!1;const J=(Z,pe)=>{Z&&Object.keys(Z).length>0&&(p?D(Je=>({...Je,...Z})):A(JSON.stringify(Z,null,2)),pe&&b(!0)),K(!0)};if(C.input!==void 0){J(C.input,!0);return}return f.listStepTests(e,s.id).then(Z=>{if(z)return;const pe=Z.length?Z[Z.length-1]:null;J(p?pe==null?void 0:pe.with:pe==null?void 0:pe.input,!1)}).catch(()=>{z||K(!0)}),()=>{z=!0}},[f,e,s.id,p,C.loaded]);const[_,de]=c.useState(0),ue=()=>{C.clear(),b(!1),p?D(o.seedValues(x)):A("{}"),de(z=>z+1)},je=z=>{D(z),k(!0),b(!1),de(J=>J+1)},[ie,k]=c.useState(!0),X=_t(h),T=p?ie:X!==null,W=p?E:{...s.with??{},...X??{}},B=p?null:hs(U),ee=!!R&&$&&T&&!B&&o.requiredParamsFilled(R,W);return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[l&&t.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",l.stopAt.length>0?t.jsxs(t.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((z,J)=>t.jsxs("span",{children:[J>0?", ":"",t.jsx("code",{children:z})]},z))]}):null,". Disabled nodes are skipped."]}),V&&R!==null&&$&&t.jsx(o.LastUsedNote,{onClear:ue}),R===null||!$?t.jsx("p",{className:"w6w-muted w6w-small",children:R===null?"Loading parameters…":"Loading saved values…"}):p?t.jsxs(t.Fragment,{children:[t.jsx(o.PropertyEntryForm,{params:R,values:E,onChange:D,onValidityChange:k},_),s.uses.trigger===!0&&t.jsx(lo,{app:s.uses.app,trigger:s.uses.action,onUse:je}),R.length===0&&t.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",t.jsx("code",{children:"input"}),")."]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",t.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),t.jsx(Pn,{seed:U}),t.jsx(is,{text:h,onChange:A,seeds:O})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:u,children:"Cancel"}),!ee&&R!==null&&$&&t.jsx("span",{className:"w6w-muted w6w-small",children:B?`${B} Fix it to run.`:T?p?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":p?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:!ee,onClick:()=>{C.save(p?E:X??{},R??[]),a(p?E:X??{},p?void 0:M)},children:"▶ Run"})]})]})}function xi(e){return e.uses.app===o.CONTROL_APP&&e.uses.action==="foreach"}function Rn({id:e}){const{tones:s,loopOf:i}=c.useContext(us),n=vn(e,i);return n.length===0?null:t.jsx("span",{className:"w6w-loop-dots",children:n.map(a=>t.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${a}`,title:`In loop · ${a}`,style:{background:as(s.get(a)??1)}},a))})}function Mn(e){return Do(e,c.useContext(us).tones)}function He({type:e,position:s,multiple:i,id:n,variant:a,top:u,routeLabel:l}){const f=oe.useNodeId(),p=c.useContext(fs),w=!!f&&!!p&&!p.readOnly,x=()=>{w&&f&&p.onAddFromPort(f,e,n)},g=a==="error"?"a step that handles this step's failure":a==="each"?"the first step of this loop's body":e==="target"?"a step before this one":"the next step";return t.jsx(oe.Handle,{type:e,position:s,id:n,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":i?"w6w-handle-multi":void 0,style:{...i?{height:22,borderRadius:3,width:8}:{},...u?{top:u}:{}},onClick:w?x:void 0,title:l?`${l} — drag or click to connect`:w?`Drag to empty canvas (or click) to add ${g} · drag to a port to connect`:a==="error"?"On error — drag to route this step's failure separately":a==="each"?"Each item — drag to the first step to repeat for every item":i?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Ln({id:e,step:s,runnable:i}){const n=c.useContext(fs);if(!n||n.readOnly)return null;const a=i||n.runsFromNode,u=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=Qe(s),f=We(s);return t.jsxs(oe.NodeToolbar,{position:oe.Position.Top,className:"w6w-node-toolbar",children:[a&&t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:u,"aria-label":u,onClick:()=>n.onRun(e),children:t.jsx(Ee.Icon,{name:"run",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":l,title:l?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":l?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(e),children:t.jsx(Ee.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":f,title:f?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":f?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:t.jsx(Ee.Icon,{name:"ban",size:15})}),t.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(e),children:t.jsx(Ee.Icon,{name:"edit",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(e),children:t.jsx(Ee.Icon,{name:"copy",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(e),children:t.jsx(Ee.Icon,{name:"trash",size:15})})]})}function Fn({step:e,count:s}){if(s<2)return null;const i=e.fanOut==="parallel",n=o.fanOutLabel(s,i?"parallel":"sequential");return t.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[t.jsx("span",{"aria-hidden":"true",children:i?"⇉":"→"})," ",s]})}function Dn({step:e}){const s=Qe(e),i=We(e);return!s&&!i?null:t.jsxs("div",{children:[i&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":nn,title:nn,children:[t.jsx(Ee.Icon,{name:"ban",size:11})," Disabled"]}),s&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":sn,title:sn,children:[t.jsx(Ee.Icon,{name:"pause",size:11})," Paused"]})]})}function On(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(o.stepProblemTooltip).join(`
|
|
4
4
|
`)}}function _n({problems:e}){if(!e||e.length===0)return null;const s=e.map(o.stepProblemTooltip).join(`
|
package/dist/flow.mjs
CHANGED
|
@@ -5,9 +5,9 @@ var ht = (e, t, s) => Ei(e, typeof t != "symbol" ? t + "" : t, s);
|
|
|
5
5
|
import { jsx as o, jsxs as y, Fragment as ie } from "react/jsx-runtime";
|
|
6
6
|
import { ReactFlowProvider as Ai, useNodesState as Ri, useEdgesState as Pi, useReactFlow as Di, ReactFlow as Li, ConnectionLineType as Mi, Background as Oi, Controls as Fi, ControlButton as $i, MiniMap as _i, Panel as Ps, NodeToolbar as mo, Position as je, useUpdateNodeInternals as ji, useNodeId as Bi, Handle as Vi } from "@xyflow/react";
|
|
7
7
|
import { useRef as me, useState as R, useLayoutEffect as Wi, useEffect as Q, useMemo as Z, useCallback as Y, useContext as Be, createContext as mt } from "react";
|
|
8
|
-
import { u as Ze, a as rn, b as zi, f as Ji, i as Hi, h as bo, p as Ds, J as In, d as Ui, r as Tn, c as yo, e as qi, g as Ls, v as Gi, j as Ki, k as Yi, l as at, m as Xi, n as Zi, o as Qi, q as Qt, w as vo, s as er, E as No, t as So, x as tr, y as Co, z as ko, A as nr, B as sr, C as xo, D as or, F as ir, G as On, H as rr, I as wt, K as ar, L as cr, T as lr, M as Ms, N as Io, O as En, P as vn, Q as To, R as ct, S as Os, U as dr, V as ur, W as Fs, X as it, Y as pr, Z as fr, _ as hr, $ as wr, a0 as It, a1 as Kt, a2 as $s, a3 as gr, a4 as _s, a5 as Fn, a6 as mr, a7 as br, a8 as yr, a9 as js, aa as vr, ab as Eo, ac as Nr, ad as Ao, ae as De, af as Bs, ag as Sr, ah as Cr, ai as Ro, aj as Po, ak as Do, al as gt, am as an, an as kr, ao as xr, ap as Ir, aq as Tr, ar as Vs, as as Er, at as Ar, au as Rr, av as Pr, aw as Dr, ax as Lr, ay as Mr, az as Or, aA as Fr, aB as $r, aC as _r, aD as jr, aE as nn, aF as $n, aG as Br, aH as Vr, aI as Wr, aJ as An, aK as zr, aL as Jr, aM as Hr, aN as Ur, aO as _n, aP as Rn, aQ as qr, aR as sn, aS as Gr, aT as Kr, aU as Yr, aV as Lo, aW as Mo, aX as Xr, aY as en, aZ as Oo, a_ as cn, a$ as Pn, b0 as Ws, b1 as Fo, b2 as $o, b3 as _o, b4 as jo, b5 as Bo, b6 as Zr, b7 as jn, b8 as Vo, b9 as Qr, ba as Yt, bb as ea, bc as ta, bd as Nn, be as Tt, bf as na, bg as zs, bh as Js, bi as sa, bj as oa, bk as ia, bl as ra, bm as aa, bn as ca, bo as la, bp as da, bq as ua, br as pa, bs as fa, bt as ha, bu as wa, bv as ga, bw as ma, bx as ba, by as ya, bz as Hs, bA as Us, bB as va, bC as Na, bD as Sa, bE as Ca, bF as ka, bG as xa, bH as Wo, bI as Ia, bJ as Ta, bK as Ea, bL as Aa, bM as Ra } from "./connection-app-meta-
|
|
9
|
-
import { bN as Nl, bO as Sl, bP as Cl, bQ as kl, bR as xl, bS as Il } from "./connection-app-meta-
|
|
10
|
-
import { a as Bn, I as Je } from "./CodeBlock-
|
|
8
|
+
import { u as Ze, a as rn, b as zi, f as Ji, i as Hi, h as bo, p as Ds, J as In, d as Ui, r as Tn, c as yo, e as qi, g as Ls, v as Gi, j as Ki, k as Yi, l as at, m as Xi, n as Zi, o as Qi, q as Qt, w as vo, s as er, E as No, t as So, x as tr, y as Co, z as ko, A as nr, B as sr, C as xo, D as or, F as ir, G as On, H as rr, I as wt, K as ar, L as cr, T as lr, M as Ms, N as Io, O as En, P as vn, Q as To, R as ct, S as Os, U as dr, V as ur, W as Fs, X as it, Y as pr, Z as fr, _ as hr, $ as wr, a0 as It, a1 as Kt, a2 as $s, a3 as gr, a4 as _s, a5 as Fn, a6 as mr, a7 as br, a8 as yr, a9 as js, aa as vr, ab as Eo, ac as Nr, ad as Ao, ae as De, af as Bs, ag as Sr, ah as Cr, ai as Ro, aj as Po, ak as Do, al as gt, am as an, an as kr, ao as xr, ap as Ir, aq as Tr, ar as Vs, as as Er, at as Ar, au as Rr, av as Pr, aw as Dr, ax as Lr, ay as Mr, az as Or, aA as Fr, aB as $r, aC as _r, aD as jr, aE as nn, aF as $n, aG as Br, aH as Vr, aI as Wr, aJ as An, aK as zr, aL as Jr, aM as Hr, aN as Ur, aO as _n, aP as Rn, aQ as qr, aR as sn, aS as Gr, aT as Kr, aU as Yr, aV as Lo, aW as Mo, aX as Xr, aY as en, aZ as Oo, a_ as cn, a$ as Pn, b0 as Ws, b1 as Fo, b2 as $o, b3 as _o, b4 as jo, b5 as Bo, b6 as Zr, b7 as jn, b8 as Vo, b9 as Qr, ba as Yt, bb as ea, bc as ta, bd as Nn, be as Tt, bf as na, bg as zs, bh as Js, bi as sa, bj as oa, bk as ia, bl as ra, bm as aa, bn as ca, bo as la, bp as da, bq as ua, br as pa, bs as fa, bt as ha, bu as wa, bv as ga, bw as ma, bx as ba, by as ya, bz as Hs, bA as Us, bB as va, bC as Na, bD as Sa, bE as Ca, bF as ka, bG as xa, bH as Wo, bI as Ia, bJ as Ta, bK as Ea, bL as Aa, bM as Ra } from "./connection-app-meta-HBKXI0nk.js";
|
|
9
|
+
import { bN as Nl, bO as Sl, bP as Cl, bQ as kl, bR as xl, bS as Il } from "./connection-app-meta-HBKXI0nk.js";
|
|
10
|
+
import { a as Bn, I as Je } from "./CodeBlock-Bp0SGY1m.js";
|
|
11
11
|
import { effectiveParam as Pa, serializeTemplate as Da, staticWritePaths as La, effectiveStateConfig as zo, statePathsOverlap as Ma, computeStateWrites as qs, foldState as Xt } from "@w6w/expr";
|
|
12
12
|
function Oa({
|
|
13
13
|
x: e,
|