@w6w/ui 0.2.11 → 0.2.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CHANGELOG.md +139 -2
  2. package/README.md +28 -10
  3. package/dist/AppPicker.d.ts +12 -1
  4. package/dist/CanvasContextMenu.d.ts +19 -0
  5. package/dist/{CodeBlock-BqXDA35P.js → CodeBlock-C-oIIYfC.js} +1436 -555
  6. package/dist/CodeBlock-C-oIIYfC.js.map +1 -0
  7. package/dist/CodeBlock-CymlfyeA.cjs +15 -0
  8. package/dist/CodeBlock-CymlfyeA.cjs.map +1 -0
  9. package/dist/CodeEditor.d.ts +4 -1
  10. package/dist/ConditionEditor.d.ts +11 -0
  11. package/dist/JsonEditor.d.ts +12 -0
  12. package/dist/ParamCustomization.d.ts +5 -0
  13. package/dist/ParamsForm.d.ts +11 -3
  14. package/dist/RouterEditor.d.ts +5 -0
  15. package/dist/StepBuilderModal.d.ts +83 -13
  16. package/dist/StepNameEditor.d.ts +11 -0
  17. package/dist/StopEditor.d.ts +5 -0
  18. package/dist/TriggerFillForm.d.ts +14 -1
  19. package/dist/WebhookListenPanel.d.ts +28 -0
  20. package/dist/WorkflowConnections.d.ts +29 -0
  21. package/dist/WorkflowConnectionsPanel.d.ts +5 -0
  22. package/dist/WorkflowFlowEditor.d.ts +67 -8
  23. package/dist/assets/script-completion.worker-DDJKkj5M.js +8290 -0
  24. package/dist/assets/script-completion.worker-DDJKkj5M.js.map +1 -0
  25. package/dist/canvas-context-menu.d.ts +27 -0
  26. package/dist/code.cjs +1 -1
  27. package/dist/code.mjs +3 -4
  28. package/dist/code.mjs.map +1 -1
  29. package/dist/components/AnchoredFlyout.d.ts +7 -0
  30. package/dist/components/ColumnsEditor.d.ts +27 -0
  31. package/dist/components/Combobox.d.ts +12 -1
  32. package/dist/components/ConfirmModal.d.ts +3 -1
  33. package/dist/components/CsvPanel.d.ts +21 -0
  34. package/dist/components/DataEntryEditor.d.ts +38 -0
  35. package/dist/components/DataEntryList.d.ts +33 -0
  36. package/dist/components/DataStoreList.d.ts +33 -0
  37. package/dist/components/DataTableGrid.d.ts +46 -0
  38. package/dist/components/EventbriteTriggerPicker.d.ts +7 -0
  39. package/dist/components/ExecutionDetail.d.ts +17 -1
  40. package/dist/components/ExecutionList.d.ts +19 -1
  41. package/dist/components/ExecutionLogPanel.d.ts +61 -3
  42. package/dist/components/ExpressionEditorModal.d.ts +33 -10
  43. package/dist/components/ExpressionOptions.d.ts +101 -15
  44. package/dist/components/HtmlPreview.d.ts +7 -0
  45. package/dist/components/JsonTree.d.ts +32 -0
  46. package/dist/components/ResolvedParams.d.ts +6 -1
  47. package/dist/components/ResultViewer.d.ts +46 -0
  48. package/dist/components/ScriptBindingsNotice.d.ts +31 -0
  49. package/dist/components/ScriptCodeField.d.ts +13 -0
  50. package/dist/components/StepStatusPill.d.ts +7 -0
  51. package/dist/components/expression-authoring.d.ts +13 -0
  52. package/dist/components/expression-dom.d.ts +17 -2
  53. package/dist/components/expression-template.d.ts +25 -3
  54. package/dist/components/icons.d.ts +1 -1
  55. package/dist/components/json-compose.d.ts +53 -0
  56. package/dist/components/result-format.d.ts +13 -0
  57. package/dist/condition-editor.d.ts +44 -0
  58. package/dist/connection-app-meta-BEXlKBgV.cjs +22 -0
  59. package/dist/connection-app-meta-BEXlKBgV.cjs.map +1 -0
  60. package/dist/connection-app-meta-ZCPakGjD.js +12422 -0
  61. package/dist/connection-app-meta-ZCPakGjD.js.map +1 -0
  62. package/dist/data-stores/data-store-view.d.ts +371 -0
  63. package/dist/eventbrite-trigger-selection.d.ts +13 -0
  64. package/dist/flow-connect.d.ts +22 -16
  65. package/dist/flow-delete.d.ts +16 -0
  66. package/dist/flow-history.d.ts +75 -0
  67. package/dist/flow-layout.d.ts +13 -0
  68. package/dist/flow-loop-colors.d.ts +39 -0
  69. package/dist/flow-loop.d.ts +98 -0
  70. package/dist/flow-node-flags.d.ts +14 -0
  71. package/dist/flow-problems.d.ts +69 -0
  72. package/dist/flow-state.d.ts +20 -0
  73. package/dist/flow-types.d.ts +137 -9
  74. package/dist/flow-utils.d.ts +27 -13
  75. package/dist/flow.cjs +4 -2
  76. package/dist/flow.cjs.map +1 -1
  77. package/dist/flow.d.ts +9 -3
  78. package/dist/flow.mjs +4028 -1585
  79. package/dist/flow.mjs.map +1 -1
  80. package/dist/index.cjs +2 -1
  81. package/dist/index.cjs.map +1 -1
  82. package/dist/index.d.ts +30 -4
  83. package/dist/index.mjs +2559 -1287
  84. package/dist/index.mjs.map +1 -1
  85. package/dist/node-samples.d.ts +80 -0
  86. package/dist/output-shape.d.ts +30 -14
  87. package/dist/param-customization.d.ts +7 -0
  88. package/dist/provider.d.ts +119 -7
  89. package/dist/resolve-params.d.ts +45 -11
  90. package/dist/run-visuals.d.ts +14 -21
  91. package/dist/script-bindings.d.ts +63 -0
  92. package/dist/script-completion-service.d.ts +9 -0
  93. package/dist/script-completion.worker.d.ts +1 -0
  94. package/dist/script-completions.d.ts +2 -0
  95. package/dist/state-shape.d.ts +38 -0
  96. package/dist/step-preview-state.d.ts +155 -6
  97. package/dist/step-problems.d.ts +42 -12
  98. package/dist/test-inputs.d.ts +25 -0
  99. package/dist/trigger-registration.d.ts +28 -0
  100. package/dist/types.d.ts +70 -8
  101. package/dist/use-app-action-defs.d.ts +9 -1
  102. package/dist/use-test-input.d.ts +18 -0
  103. package/dist/workflow-connections.d.ts +78 -0
  104. package/package.json +16 -7
  105. package/src/code.css +60 -6
  106. package/src/styles/_canvas.scss +35 -0
  107. package/src/styles/_code-editor.scss +35 -0
  108. package/src/styles/_code.scss +6 -5
  109. package/src/styles/_connections.scss +64 -0
  110. package/src/styles/_copyable.scss +24 -0
  111. package/src/styles/_data-stores.scss +138 -0
  112. package/src/styles/_data-vars.scss +17 -6
  113. package/src/styles/_execution-history.scss +73 -0
  114. package/src/styles/_execution-log.scss +145 -1
  115. package/src/styles/_expression-modal.scss +106 -16
  116. package/src/styles/_fields.scss +11 -0
  117. package/src/styles/_flow.scss +166 -0
  118. package/src/styles/_fx.scss +3 -1
  119. package/src/styles/_incoming-state.scss +33 -0
  120. package/src/styles/_modal.scss +12 -0
  121. package/src/styles/_multiselect.scss +35 -0
  122. package/src/styles/_sections.scss +36 -0
  123. package/src/styles/_step-builder.scss +145 -0
  124. package/src/styles/_tester.scss +56 -0
  125. package/src/styles/_tokens.scss +27 -1
  126. package/src/styles.css +1347 -41
  127. package/src/styles.scss +2 -0
  128. package/dist/CodeBlock-BqXDA35P.js.map +0 -1
  129. package/dist/CodeBlock-CulfbnZD.cjs +0 -15
  130. package/dist/CodeBlock-CulfbnZD.cjs.map +0 -1
  131. package/dist/ConfirmModal-Ln99S9NT.js +0 -7919
  132. package/dist/ConfirmModal-Ln99S9NT.js.map +0 -1
  133. package/dist/ConfirmModal-fjHW5rN-.cjs +0 -14
  134. package/dist/ConfirmModal-fjHW5rN-.cjs.map +0 -1
  135. package/dist/Copyable-DA6eiU7w.cjs +0 -2
  136. package/dist/Copyable-DA6eiU7w.cjs.map +0 -1
  137. package/dist/Copyable-F4NTaG77.js +0 -847
  138. package/dist/Copyable-F4NTaG77.js.map +0 -1
package/dist/flow.cjs CHANGED
@@ -1,3 +1,5 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),_=require("@xyflow/react"),c=require("react"),ss=require("react-dom"),i=require("./ConfirmModal-fjHW5rN-.cjs"),de=require("./Copyable-DA6eiU7w.cjs"),Rt=200,It=200,Ft=10240;function Ue(t){const s={};for(const[o,a]of Object.entries(t))s[o]=Math.round(a);return s}const ns=t=>!!t&&Number.isFinite(t.x)&&Number.isFinite(t.y),os=t=>!!t&&Number.isFinite(t.width)&&Number.isFinite(t.height);function yt(t,s,o){return t&&t.map(a=>{const l=s==null?void 0:s[a.id],u=ns(l==null?void 0:l.position)?l.position:a.position,f=os(l==null?void 0:l.size)?l.size:a.size;return{...a,position:Ue(u),size:Ue(f)}})}function Mt(t,s,o){if(!s)return t;const a={...t};return t.notes&&(a.notes=yt(t.notes,o)),t.sections&&(a.sections=yt(t.sections,o)),a}function qe(t,s){return t.sections?{...t,sections:t.sections.map(o=>({...o,nodes:o.nodes.filter(a=>a!==s)}))}:t}function Dt(t,s,o){return t.sections?{...t,sections:t.sections.map(a=>({...a,nodes:a.nodes.map(l=>l===s?o:l)}))}:t}function Ke(t,s,o){if(!t.sections)return t;const a=new Set(o);return{...t,sections:t.sections.map(l=>{const u=l.nodes.filter(f=>!a.has(f));return l.id===s?{...l,nodes:[...new Set([...u,...o])]}:{...l,nodes:u}})}}function Lt(t,s){return(t.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function rs(t,s){const o=new TextEncoder;if(o.encode(t).length<=s)return t;let a="",l=0;for(const u of t){const f=o.encode(u).length;if(l+f>s)break;a+=u,l+=f}return a}function Xe(t){const s={...t};return t.notes&&(s.notes=t.notes.slice(0,Rt).map(o=>({...o,content:rs(o.content,Ft)}))),t.sections&&(s.sections=t.sections.slice(0,It)),s}function is(t,s,o){const a={};for(const f of[...t.notes??[],...t.sections??[]])a[f.id]={position:f.position,size:f.size};const l=(f,b)=>f==null?void 0:f.map(C=>{const S=b==null?void 0:b.find(m=>m.id===C.id);return S?{...C,position:S.position,size:S.size}:C}),u=o?t:{...t,...t.notes?{notes:l(t.notes,s==null?void 0:s.notes)}:{},...t.sections?{sections:l(t.sections,s==null?void 0:s.sections)}:{}};return Mt(u,o,a)}const St=220;function as(t){return t.length<=St?{text:t,clipped:!1,length:t.length}:{text:t.slice(0,St).trimEnd(),clipped:!0,length:t.length}}function ls({params:t,values:s,testStartState:o,view:a="props"}){const{sampleValues:l}=i.useExpressionOptions(),u=c.useMemo(()=>i.buildResolveScope(l,o),[l,o]),f=i.flattenParams(t),b=m=>{var N;return s[m]!==void 0?s[m]:(N=f.find(d=>d.key===m))==null?void 0:N.default},C=f.filter(m=>m.type!=="section"&&i.isParamVisible(m,b));if(a==="code"){const m=cs(C,s,u);return e.jsx("div",{className:"w6w-resolved-params",children:e.jsx(i.JsonEditor,{value:JSON.stringify(m,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=C.filter(m=>!i.deepEqual(b(m.key),m.default));return C.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):S.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.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."})}):e.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:S.map(m=>m.type==="vars"?e.jsx(ds,{param:m,value:s[m.key],scope:u},m.key):e.jsx(us,{label:m.label??m.key,segments:i.resolveParamValue(s[m.key]!==void 0?s[m.key]:m.default,u)},m.key))})}function cs(t,s,o){const a={};for(const l of t)if(l.type==="vars"){const u=Array.isArray(s[l.key])?s[l.key]:Array.isArray(l.default)?l.default:[];a[l.key]=i.resolveVarsJson(u,o)}else a[l.key]=i.resolveParamJson(s[l.key]!==void 0?s[l.key]:l.default,o);return a}function us({label:t,segments:s}){return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t}),e.jsx("div",{className:"w6w-resolved-value",children:e.jsx(_t,{segments:s})})]})}function ds({param:t,value:s,scope:o}){const a=Array.isArray(s)?s:Array.isArray(t.default)?t.default:[];return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t.label??t.key}),a.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):e.jsx("div",{className:"w6w-stack",children:a.map((l,u)=>e.jsxs("div",{className:"w6w-resolved-value",children:[e.jsx("code",{children:l.key||"(no key)"})," → ",e.jsx(_t,{segments:i.resolveParamValue(l.value,o)})]},u))})]})}function _t({segments:t}){return e.jsx(e.Fragment,{children:t.map((s,o)=>e.jsx(ps,{segment:s},o))})}function ps({segment:t}){switch(t.status){case"resolved":return t.ref?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{kind:"var",refName:t.ref}),e.jsx(vt,{value:t.value})]}):e.jsx(vt,{value:t.value});case"unresolved":return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"not-evaluated":return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{kind:"expr"}),e.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return e.jsx(Ve,{kind:"secret",refName:t.ref})}}function vt({value:t}){const[s,o]=c.useState(!1),a=hs(t),l=as(a);return l.clipped?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:s?"w6w-resolved-text-full":void 0,children:s?a:`${l.text}…`}),e.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>o(u=>!u),children:s?"Show less":`Show all (${l.length.toLocaleString()} characters)`})]}):e.jsx("span",{children:a})}const fs={var:"◆",secret:"🔒",expr:"ƒ"};function Ve({kind:t,refName:s}){const o=t==="expr"?"expr":i.varLabel(s??"");return e.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${t}`,children:[e.jsx("span",{className:"w6w-expr-chip-sigil",children:fs[t]}),e.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function hs(t){if(t===null)return"null";if(t===void 0)return"(not set)";if(t==="")return'""';if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t)}catch{return String(t)}}function te(t){var s;return((s=t.data)==null?void 0:s.when)==="error"?"error":"success"}function Vt(t,s){var o;return((o=t.find(a=>a.id===s))==null?void 0:o.id)??null}function Wt(t,s,o,a,l){var S,m;if(!t||!s||t===s||a.some(N=>N.source===t&&N.target===s))return!1;const u=(S=o.find(N=>N.id===t))==null?void 0:S.data.step,f=(m=o.find(N=>N.id===s))==null?void 0:m.data.step;if(!u||!f)return!1;const b=i.nodePortsForStep(u,l),C=i.nodePortsForStep(f,l);return b.out>=1&&C.in>=1}function Ge(t,s,o,a,l,u){var I,A;if(!Wt(t,s,o,a,u)||!t||!s)return null;const f=(I=o.find(V=>V.id===t))==null?void 0:I.data.step,b=(A=o.find(V=>V.id===s))==null?void 0:A.data.step;if(!f||!b)return null;const C=i.nodePortsForStep(f,u),S=i.nodePortsForStep(b,u);let m=a;if(m.filter(V=>V.source===t&&te(V)===l).length>=C.out)return{next:a,conflict:null,refusal:{refused:"out_cap",cap:C.out}};const d=m.filter(V=>V.target===s);if(d.length>=S.in){const V=new Set(d.slice(0,d.length-S.in+1).map(T=>T.id));m=m.filter(T=>!V.has(T.id))}const v=i.flowEdgeId(t,s,l);return{next:_.addEdge({source:t,target:s,id:v,sourceHandle:i.sourceHandleForLane(l),data:{when:l},...i.edgeVisuals(l,void 0)},m),conflict:Vt(m,v),refusal:null}}function We(t,s,o,a,l="success",u){const f=Ge(t,s,o,a,l,u);return!f||f.conflict||f.refusal?null:f.next}function ws(t,s,o,a,l="success",u){var f;return((f=Ge(t,s,o,a,l,u))==null?void 0:f.conflict)??null}function ms(t,s,o,a,l="success",u){var f;return((f=Ge(t,s,o,a,l,u))==null?void 0:f.refusal)??null}function Ye(t,s,o,a,l){var I;const u=t.filter(A=>A.id===s);if(u.length!==1)return null;const f=u[0],b=(I=a.find(A=>A.id===f.source))==null?void 0:I.data.step;if(!b)return null;const C=i.nodePortsForStep(b,l).out,S=t.filter(A=>A.id!==s);if((te(f)===o?[]:S.filter(A=>A.source===f.source&&te(A)===o)).length>=C)return{next:t,conflict:null,refusal:{refused:"out_cap",cap:C}};const N=i.edgeVisuals(o,void 0),d={...f,id:i.flowEdgeId(f.source,f.target,o),data:{...f.data,when:o},className:N.className,label:N.label,sourceHandle:i.sourceHandleForLane(o)},v=Vt(S,d.id);return{next:t.map(A=>A.id===s?d:A),conflict:v,refusal:null}}function gs(t,s,o,a,l){const u=Ye(t,s,o,a,l);return!u||u.conflict||u.refusal?null:u.next}function xs(t,s,o,a,l){var u;return((u=Ye(t,s,o,a,l))==null?void 0:u.conflict)??null}function bs(t,s,o,a,l){var u;return((u=Ye(t,s,o,a,l))==null?void 0:u.refusal)??null}function js(t,s,o){return t.map(a=>{const l=a.source===s?o:a.source,u=a.target===s?o:a.target;return{...a,source:l,target:u,id:i.flowEdgeId(l,u,te(a))}})}function Cs(t,s){const o={success:0,error:0};for(const l of s)l.source===t&&o[te(l)]++;const a=Math.max(o.success,o.error);return{enabled:a>=2,count:a}}function ys(t,s){const{fanOut:o,...a}=t;return s==="parallel"?{...a,fanOut:"parallel"}:a}function Ss(t,s){return`Runs these ${t} nodes in ${s==="parallel"?"parallel":"sequence"}`}function Ot(t,s){var o;return(o=t.nodes??t.steps)==null?void 0:o[s]}const vs=new Set(["succeeded","failed","canceled"]);function Ns(t,s){var o;return t?((o=Ot(t,s))==null?void 0:o.status)??"pending":"no-run"}const Nt={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function $t(t,s){const o=s!==void 0&&vs.has(s);switch(t){case"no-run":return Nt;case"pending":return o?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return Nt}}function ks(t,s,o){if(!t)return;const a=Ot(t,s);if(!a)return;const l=o??"success";if(a.status==="succeeded")return l==="success"?"taken":"skipped";if(a.status==="failed")return l==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}function Es(t,s){return t.map(o=>{const a=s==null?void 0:s[o.id],l=o.data.stepProblem;if(a===void 0){if(l===void 0&&!("stepProblem"in o.data))return o;const{stepProblem:u,...f}=o.data;return{...o,data:f}}return l&&l.code===a.code&&l.connection===a.connection?o:{...o,data:{...o.data,stepProblem:{...a}}}})}function Je(t){return`Connection ${t.connection} no longer exists — open the step and choose another on the Setup tab`}function kt(t,s){return(s==null?void 0:s.code)==="unknown_connection"&&t.uses.connection===s.connection}function Ps(t,s,o){if(!t)return"No connection";if(o)return"Couldn't load connections";if(s===null)return t;const a=s.find(l=>l.id===t);return a?a.displayName??t:"Missing connection — choose another"}function As(t,s){const[o,a]=c.useState({}),l=c.useRef(new Set),u=JSON.stringify([...new Set(s.map(f=>f.data.step.uses.app))].filter(f=>f&&!i.isInternalApp(f)).sort());return c.useEffect(()=>{const f=JSON.parse(u).filter(b=>!l.current.has(b));if(f.length!==0){for(const b of f)l.current.add(b);Promise.all(f.map(async b=>{try{return[b,await t.getAppActions(b)]}catch{return l.current.delete(b),null}})).then(b=>{const C=b.filter(S=>S!==null);C.length!==0&&a(S=>({...S,...Object.fromEntries(C)}))})}},[t,u]),o}function Ts(t){return(s,o)=>{var a,l;return(l=(a=t[s])==null?void 0:a.find(u=>u.key===o))==null?void 0:l.ports}}const Rs="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 Et(t,s,o,a){const l=t.find(u=>u.id===s);return[o,a,l==null?void 0:l.source,l==null?void 0:l.target]}const Qe=c.createContext(void 0),Ze=c.createContext(new Map);function Pt(t){return`Can’t draw that edge: this node allows at most ${t} outgoing edge${t===1?"":"s"} per lane.`}const et=c.createContext(new Map),tt=c.createContext(null);function Is(t){return e.jsx(_.ReactFlowProvider,{children:e.jsx(Fs,{...t})})}function At(t,s){let o=s.length+1;for(;s.includes(`${t}-${o}`);)o++;return`${t}-${o}`}function ze(t){var s,o;return{x:t.position.x,y:t.position.y,w:((s=t.measured)==null?void 0:s.width)??t.width??200,h:((o=t.measured)==null?void 0:o.height)??t.height??64}}function Fs({value:t,onChange:s,readOnly:o,height:a=480,apps:l,exprOptions:u,project:f,runState:b,stepProblems:C,onTestRun:S,fitViewKey:m}){var xt,bt;const N=i.useW6WApi(),d=c.useMemo(()=>new Map((l??[]).map(n=>[n.id,n])),[l]),[v,I]=c.useState(null),A=c.useMemo(()=>i.workflowToFlow(t),[t.id]),V=c.useMemo(()=>i.storedViewport(t),[t.id]),T=((xt=t.settings)==null?void 0:xt.savePosition)!==!1,[g,F,me]=_.useNodesState(A.nodes),ie=As(N,g),O=c.useMemo(()=>Ts(ie),[ie]),[j,D,ge]=_.useEdgesState(A.edges);c.useEffect(()=>{F(n=>n.map(r=>{const p=Ns(b,r.id);return r.data.stepStatus===p&&r.data.runStatus===(b==null?void 0:b.status)?r:{...r,data:{...r.data,stepStatus:p,runStatus:b==null?void 0:b.status}}})),D(n=>n.map(r=>{const p=te(r),h=ks(b,r.source,p),w=i.edgeVisuals(p,h);return r.className===w.className&&r.label===w.label?r:{...r,className:w.className,label:w.label}}))},[b,F,D]),c.useEffect(()=>{F(n=>Es(n,C))},[C,F]);const[z,L]=c.useState(null),Y=c.useMemo(()=>t.canvas??{},[t.id]),[E,Q]=c.useState(Y),[se,xe]=c.useState(!1),[J,ae]=c.useState(null),[ne,oe]=c.useState(null),[W,pe]=c.useState(null),[be,je]=c.useState(!1),[B,le]=c.useState(null),[Ce,U]=c.useState("props"),[Ne,q]=c.useState(null),ke=c.useRef(!1),fe=c.useRef(null),[H,Z]=c.useState(null),{screenToFlowPosition:ce,fitView:he}=_.useReactFlow(),Re=i.useEffectiveTheme();c.useEffect(()=>{F(A.nodes),D(A.edges),L(null),le(null),Q(Y)},[A,Y,F,D]);const Ee=c.useCallback((n,r)=>{var w,y;const{canvas:p,...h}=n;return!((w=r.notes)!=null&&w.length)&&!((y=r.sections)!=null&&y.length)?h:{...h,canvas:is(r,t.canvas,T)}},[t.canvas,T]),M=c.useCallback((n,r,p)=>{s(Ee(i.flowToWorkflow(t,n,r),p??E))},[t,s,E,Ee]),Ie=c.useCallback(n=>Wt(n.source,n.target,g,j,O),[g,j,O]),Fe=c.useCallback(n=>{if(o)return;const r=We(n.source,n.target,g,j,i.laneForSourceHandle(n.sourceHandle),O);if(!r){const p=i.laneForSourceHandle(n.sourceHandle),h=ms(n.source,n.target,g,j,p,O);if(h){const y=j.find(k=>k.source===n.source&&te(k)===p);y&&(D(j.map(k=>({...k,selected:k.id===y.id}))),pe(y.id),re({edgeId:y.id,message:Pt(h.cap)}));return}const w=ws(n.source,n.target,g,j,i.laneForSourceHandle(n.sourceHandle));if(!w)return;D(j.map(y=>({...y,selected:y.id===w}))),pe(w),re({edgeId:w,message:i.idClashMessage("Can’t draw that edge",w,Et(j,w,n.source,n.target))});return}re(null),D(r),M(g,r)},[j,g,D,M,o,O]),$=c.useCallback((n,r)=>{var P,R,X;if(o||r.isValid)return;const p=r.fromNode;if(!p)return;const h=((P=r.fromHandle)==null?void 0:P.type)==="target"?"target":"source",w=(R=g.find(G=>G.id===p.id))==null?void 0:R.data.step;if(w){const G=i.nodePortsForStep(w,O);if((h==="source"?G.out:G.in)<1)return}const y="changedTouches"in n?n.changedTouches[0]:n,k=ce({x:y.clientX,y:y.clientY});Z({nodeId:p.id,handleType:h,position:k,lane:i.laneForSourceHandle((X=r.fromHandle)==null?void 0:X.id)}),je(!0)},[o,ce,g,O]),Pe=c.useCallback((n,r,p)=>{if(o)return;const h=g.find(R=>R.id===n);if(!h)return;const w=ze(h),y=i.laneForSourceHandle(p),k=120,P=r==="target"?{x:w.x-w.w-k,y:w.y}:y==="error"?{x:w.x,y:w.y+w.h+k}:{x:w.x+w.w+k,y:w.y};Z({nodeId:n,handleType:r,position:P,lane:y}),je(!0)},[o,g]),Ae=c.useCallback(n=>{o||q(n)},[o]),Me=c.useCallback(n=>{if(o)return;const r=g.filter(w=>w.id!==n),p=j.filter(w=>w.source!==n&&w.target!==n),h=qe(E,n);F(r),D(p),Q(h),z===n&&L(null),B===n&&le(null),M(r,p,h)},[g,j,E,F,D,M,o,z,B]),x=c.useCallback(()=>{if(o)return;const n=i.relayoutNodes(g,j);F(n),ke.current=!0,M(n,j)},[g,j,F,M,o]),K=c.useCallback(()=>{o||x()},[o,x]);c.useEffect(()=>{ke.current&&(ke.current=!1,he({duration:300}))},[g,he]);const ee=c.useRef(m);c.useEffect(()=>{Object.is(ee.current,m)||(ee.current=m,he({duration:300}))},[m,he]);const[ue,re]=c.useState(null),De=c.useMemo(()=>j.find(n=>n.id===W)??null,[j,W]),zt=c.useCallback(n=>{if(o||!W)return;const r=j.find(k=>k.id===W);if(!r||te(r)===n)return;const p=xs(j,W,n,g),h=bs(j,W,n,g,O),w=p||h?null:gs(j,W,n,g,O);if(!w){if(h){re({edgeId:W,message:Pt(h.cap)});return}re({edgeId:W,message:p?i.idClashMessage("Can’t switch this edge",p,Et(j,p,r.source,r.target)):"This edge can’t be switched right now."});return}re(null),D(w);const y=w.find(k=>k.source===r.source&&k.target===r.target&&te(k)===n);pe((y==null?void 0:y.id)??null),M(g,w)},[j,g,D,M,o,W,O]),Ut=c.useCallback(n=>{if(o)return;const r=j.filter(p=>p.id!==n);r.length!==j.length&&(D(r),W===n&&pe(null),M(g,r))},[g,j,D,M,o,W]),nt=c.useCallback(n=>{if(o)return;const r=g.find(k=>k.id===n);if(!r)return;const p=i.suggestStepId(g.map(k=>k.id),`${r.data.step.id}_copy`),h={...structuredClone(r.data.step),id:p},w={id:p,type:r.type,position:{x:r.position.x+40,y:r.position.y+60},data:{step:h,isInternal:r.data.isInternal}},y=[...g,w];F(y),L(p),M(y,j)},[g,j,F,M,o]),qt=c.useCallback(n=>{if(o)return;const r=i.isInternalApp(n.uses.app),p=i.suggestStepId(g.map(P=>P.id),i.slugifyLabel(i.internalNodeLabel(n.uses.app,n.uses.action))),h={id:p,uses:n.uses,...n.with&&Object.keys(n.with).length>0?{with:n.with}:{}},w={id:p,type:r?"control":"step",position:(H==null?void 0:H.position)??{x:80,y:80+g.length*24},data:{step:h,isInternal:r}},y=[...g,w];let k=j;if(H){const[P,R]=H.handleType==="target"?[p,H.nodeId]:[H.nodeId,p];k=We(P,R,y,j,H.lane,O)??j}else{const P=g.find(R=>i.isTriggerApp(R.data.step.uses.app));if(i.isTriggerApp(n.uses.app)){if(!P){const R=i.findChainRoot(g,j);R&&(k=We(p,R.id,y,j,"success",O)??j)}}else{const X=(P&&!j.some(G=>G.source===P.id)?P:void 0)??i.findChainTail(g,j);X&&(k=We(X.id,p,y,j,"success",O)??j)}}return F(y),k!==j&&D(k),L(p),M(y,k),p},[g,j,F,D,M,o,H,O]),ot=c.useCallback((n,r)=>{const p=r.id!==n;if(p&&g.some(w=>w.id===r.id))return;const h=g.map(w=>w.id===n?{...w,id:r.id,data:{step:r,isInternal:i.isInternalApp(r.uses.app)}}:w);if(p){const w=js(j,n,r.id),y=Dt(E,n,r.id);F(h),D(w),Q(y),z===n&&L(r.id),B===n&&le(r.id),M(h,w,y);return}F(h),M(h,j)},[g,j,E,F,D,z,B,M]),we=c.useCallback(n=>{o||(Q(n),M(g,j,n))},[o,g,j,M]),Kt=c.useCallback(()=>{var w;if(o)return;const n=(w=fe.current)==null?void 0:w.getBoundingClientRect(),r=n?ce({x:n.left+n.width/2,y:n.top+n.height/2}):{x:0,y:0},p=E.notes??[],h={id:At("note",p.map(y=>y.id)),color:"#facc15",position:{x:Math.round(r.x-100),y:Math.round(r.y-60)},size:{width:200,height:120},content:""};we(Xe({...E,notes:[...p,h]}))},[o,E,ce,we]),Xt=c.useCallback((n,r)=>{if(o)return;const p=r?Math.min(n.x,r.x):n.x,h=r?Math.min(n.y,r.y):n.y,w=r?Math.abs(r.x-n.x):360,y=r?Math.abs(r.y-n.y):240,k=g.filter(Te=>{const _e=ze(Te),jt=_e.x+_e.w/2,Ct=_e.y+_e.h/2;return jt>=p&&jt<=p+w&&Ct>=h&&Ct<=h+y}).map(Te=>Te.id),P=E.sections??[],R=At("section",P.map(Te=>Te.id)),X={id:R,title:"Section",color:"#6366f1",position:{x:Math.round(p),y:Math.round(h)},size:{width:Math.round(w),height:Math.round(y)},nodes:[]},G={...E,sections:[...P,X]};we(Xe(Ke(G,R,k)))},[o,g,E,we]);c.useEffect(()=>{if(!se)return;const n=r=>{r.key==="Escape"&&(xe(!1),ae(null))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[se]);const Gt=c.useCallback((n,r)=>{var k;if(o)return;const p=(k=E.sections)==null?void 0:k.find(P=>P.id===n);if(!p)return;const h=new Set(p.nodes),w=g.map(P=>h.has(P.id)?{...P,position:{x:P.position.x+r.dx,y:P.position.y+r.dy}}:P),y={...E,sections:(E.sections??[]).map(P=>P.id===n?{...P,position:{x:P.position.x+r.dx,y:P.position.y+r.dy}}:P)};F(w),Q(y),M(w,j,y)},[o,E,g,j,F,M]),Yt=c.useCallback((n,r)=>{if(o)return;const p=n==="note"?{...E,notes:(E.notes??[]).filter(h=>h.id!==r)}:{...E,sections:(E.sections??[]).filter(h=>h.id!==r)};we(p)},[o,E,we]),Qt=n=>{let r=E;for(const p of n){const h=ze(p),w=h.x+h.w/2,y=h.y+h.h/2,k=(r.sections??[]).find(R=>w>=R.position.x&&w<=R.position.x+R.size.width&&y>=R.position.y&&y<=R.position.y+R.size.height),P=Lt(r,p.id);k?(P.length!==1||P[0]!==k.id)&&(r=Ke(r,k.id,[p.id])):P.length>0&&(r=qe(r,p.id))}return r},Oe=c.useCallback((n,r,p)=>{(async()=>{const h=await N.saveStepTest(t.id,n,r).catch(w=>(console.error("step run fixture save failed",w),null));await N.recordStepTestRun(t.id,n,{stepTestId:(h==null?void 0:h.id)??null,status:p.status,input:r.input,output:p.output,error:p.error,...p.meta?{meta:p.meta}:{}})})().catch(h=>{console.error("step run persist failed",h)})},[N,t.id]),rt=c.useCallback(n=>{const r=g.find(p=>p.id===n);!r||i.isControlApp(r.data.step.uses.app)||I({stepId:n,status:"collect"})},[g]),Zt=c.useCallback(async(n,r,p)=>{S==null||S();const h=g.find(R=>R.id===n);if(!h)return;const w=h.data.step,y=i.isTriggerApp(w.uses.app),k=y?{input:r}:{...w.with??{},...r},P=y?{input:r,with:r}:{input:r,with:k};I({stepId:n,status:"running"});try{const R=await N.invokeAction(w.uses.app,w.uses.action,k,{...w.uses.connection?{connectionId:w.uses.connection}:{},project:f,...p?{state:p}:{}}),X=R.logs,G=R.meta;I({stepId:n,status:"done",value:R.value,logs:X,...G?{meta:G}:{}}),Oe(n,P,{status:"succeeded",output:R.value,...G?{meta:G}:{}})}catch(R){const X=R;I({stepId:n,status:"error",error:X.message??String(R),errorCode:X.code}),Oe(n,P,{status:"failed",error:X.message??String(R)})}},[g,N,Oe,f,S]),$e=c.useMemo(()=>({onEdit:n=>{U("props"),le(n)},onEditJson:n=>{U("json"),le(n)},onRun:rt,onDuplicate:nt,onDelete:Ae,onAddFromPort:Pe,readOnly:o}),[rt,nt,Ae,Pe,o]);c.useEffect(()=>{const n=fe.current;if(!n)return;const r=p=>{const h=p.target.closest(".react-flow__node");if(!h)return;const w=h.getAttribute("data-id");w&&(p.stopPropagation(),$e.onEdit(w))};return n.addEventListener("dblclick",r,!0),()=>n.removeEventListener("dblclick",r,!0)},[$e]);const ye=g.find(n=>n.id===B),it=(ye==null?void 0:ye.data.step)??null,Be=v?((bt=g.find(n=>n.id===v.stepId))==null?void 0:bt.data.step)??null:null,He=(v==null?void 0:v.status)==="collect"&&!!Be,es=c.useMemo(()=>v?i.upstreamStateSources(v.stepId,g,j).steps:[],[v,g,j]),at=c.useMemo(()=>{const n=new Map;for(const r of g)n.set(r.id,Cs(r.id,j).count);return n},[g,j]),ts=c.useMemo(()=>({step:Ds,control:Ls}),[]),[Le,lt]=c.useState({}),[ct,ut]=c.useState({}),dt=c.useMemo(()=>({actionDef:(n,r)=>{var p;return(p=ie[n])==null?void 0:p.find(h=>h.key===r)},testOutputs:Le}),[ie,Le]),[pt,ft]=c.useState(null),Se=c.useMemo(()=>{const n=i.upstreamStateSources(B,g,j,dt);return{...n,steps:i.excludeSelfStep(n.steps,B??pt)}},[B,pt,g,j,dt]),ht=JSON.stringify(Se.steps.map(n=>n.id));c.useEffect(()=>{const n=JSON.parse(ht);if(!B||n.length===0){lt({}),ut({});return}let r=!1;return Promise.all(n.map(async p=>{try{const h=await N.listStepTests(t.id,p),w=h.length?h[h.length-1]:null;return w?{id:p,output:w.lastRunOutput,meta:w.lastRunMeta}:null}catch{return null}})).then(p=>{if(r)return;const h={},w={};for(const y of p)y!=null&&y.meta&&(w[y.id]=y.meta),!(!y||y.output===void 0||y.output===null)&&(h[y.id]=y.output);lt(h),ut(w)}),()=>{r=!0}},[N,t.id,B,ht]);const wt=c.useMemo(()=>{const n={};for(const r of Se.steps){Object.assign(n,i.stepMetaSampleValues(r.id,ct[r.id]));const p=Le[r.id];if(p!==void 0){if(n[`steps.${r.id}.output`]=p,typeof p=="object"&&p!==null&&!Array.isArray(p))for(const[h,w]of Object.entries(p))n[`steps.${r.id}.output.${h}`]=w;for(const h of r.outputs??[]){if(!h.path||!h.key.includes("."))continue;const w=i.valueAtPath(p,h.key);w!==void 0&&(n[`steps.${r.id}.output.${h.key}`]=w)}}}return n},[Se.steps,Le,ct]),mt=i.useExpressionOptions(),gt=c.useMemo(()=>({...u??{},steps:Se.steps,hasTrigger:Se.hasTrigger,sampleValues:{...mt.sampleValues??{},...(u==null?void 0:u.sampleValues)??{},...wt}}),[u,mt.sampleValues,Se,wt]);return e.jsx(tt.Provider,{value:$e,children:e.jsx(Qe.Provider,{value:O,children:e.jsx(Ze.Provider,{value:at,children:e.jsx(et.Provider,{value:d,children:e.jsx(i.WorkflowProjectProvider,{project:f,children:e.jsx(i.ExpressionOptionsProvider,{value:gt,children:e.jsxs("div",{ref:fe,className:"w6w-flow",style:{width:"100%",height:a,position:"relative"},onKeyDown:n=>{if(n.key!=="Backspace"&&n.key!=="Delete"||B||be||!z&&!W)return;const r=n.target;r.isContentEditable||r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.tagName==="SELECT"||r.closest("dialog, .w6w-modal")!==null||(n.preventDefault(),z?Ae(z):W&&Ut(W))},children:[e.jsxs(_.ReactFlow,{nodes:g,edges:j,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:_.ConnectionLineType.SmoothStep,onNodesChange:me,onEdgesChange:ge,onConnect:Fe,onConnectEnd:$,isValidConnection:Ie,onNodeDragStop:(n,r,p)=>{const h=Qt(p),w=h!==E;w&&Q(h),!(!T&&!w)&&M(g,j,h)},onMoveEnd:(n,r)=>{if(!n||o)return;const p=i.flowToWorkflow(t,g,j),h=i.withViewport(p,r);h!==p&&s(h)},onSelectionChange:({nodes:n,edges:r})=>{var p,h;L(((p=n[0])==null?void 0:p.id)??null),pe(((h=r[0])==null?void 0:h.id)??null)},nodeTypes:ts,nodesDraggable:!o,nodesConnectable:!o,connectOnClick:!1,elementsSelectable:!0,...V?{defaultViewport:V}:{fitView:!0},deleteKeyCode:null,colorMode:Re,proOptions:{hideAttribution:!0},children:[e.jsx(_.Background,{gap:16}),e.jsx(_.Controls,{showInteractive:!1,children:!o&&e.jsx(_.ControlButton,{onClick:K,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:e.jsx(de.Icon,{name:"layout"})})}),e.jsx(_.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!o&&e.jsxs(_.Panel,{position:"top-left",className:"w6w-flow-tools",children:[e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>je(!0),children:"+ Node"}),e.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Kt}),e.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${se?" active":""}`,"aria-pressed":se,"data-testid":"draw-section",onClick:()=>{xe(!se),ae(null)}})]}),!o&&se&&e.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:n=>{if(n.button!==0)return;n.currentTarget.setPointerCapture(n.pointerId);const{clientX:r,clientY:p}=n;ae({sx:r,sy:p,ex:r,ey:p})},onPointerMove:n=>{const{clientX:r,clientY:p}=n;ae(h=>h&&{...h,ex:r,ey:p})},onPointerUp:()=>{const n=J;if(ae(null),xe(!1),!n)return;const r=ce({x:n.sx,y:n.sy}),p=Math.abs(n.ex-n.sx)>6||Math.abs(n.ey-n.sy)>6;Xt(r,p?ce({x:n.ex,y:n.ey}):null)},children:J&&(()=>{var h;const n=(h=fe.current)==null?void 0:h.getBoundingClientRect(),r=(n==null?void 0:n.left)??0,p=(n==null?void 0:n.top)??0;return e.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(J.sx,J.ex)-r,top:Math.min(J.sy,J.ey)-p,width:Math.abs(J.ex-J.sx),height:Math.abs(J.ey-J.sy)}})})()}),!o&&De&&e.jsx(_.Panel,{position:"top-right",children:e.jsxs("div",{className:"w6w-edge-lane",children:[e.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(n=>e.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${te(De)===n?" active":""}`,"aria-pressed":te(De)===n,title:Rs,onClick:()=>zt(n),children:n==="success"?"Success":"Error"},n)),(ue==null?void 0:ue.edgeId)===De.id&&e.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:ue.message})]})}),e.jsx(i.CanvasLayer,{canvas:E,readOnly:o,savePosition:T,onChange:we,onSectionDrop:Gt,onRequestDelete:(n,r)=>!o&&oe({kind:n,id:r})})]}),ne&&e.jsx(i.ConfirmModal,{title:ne.kind==="note"?"Delete note":"Delete section",message:ne.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Yt(ne.kind,ne.id),oe(null)},onClose:()=>oe(null)}),be&&e.jsx(i.StepBuilderModal,{onClose:()=>{je(!1),Z(null),ft(null)},onAdd:n=>{const r=qt(n);return r&&ft(r),r},onDraftChange:(n,r)=>ot(n,{id:n,...r}),workflowId:t.id,upstreamSteps:i.stepBuilderUpstreamSteps(H,g,j)}),it&&B&&e.jsx(_s,{workflowId:t.id,step:it,upstreamSteps:gt.steps??[],readOnly:o,fanOutCount:at.get(B)??0,initialView:Ce,stepProblem:ye==null?void 0:ye.data.stepProblem,onChange:n=>ot(B,n),onClose:()=>le(null),onTestRun:S}),v&&e.jsxs(i.Modal,{title:`${He?"Run node":"Test run"}: ${v.stepId}`,onClose:()=>I(null),children:[He&&Be&&e.jsx(Ms,{workflowId:t.id,step:Be,upstreamSteps:es,onCancel:()=>I(null),onRun:(n,r)=>Zt(v.stepId,n,r)},v.stepId),!He&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-modal-body",children:[v.status==="running"&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),v.status==="error"&&e.jsxs("div",{className:"w6w-result w6w-error",children:[v.errorCode&&e.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:e.jsx("code",{children:v.errorCode})}),v.error||"The node failed with no error message."]}),v.status==="done"&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:360,overflow:"auto",margin:0},children:JSON.stringify(v.value,null,2)}),v.meta&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:360,overflow:"auto",margin:0},children:JSON.stringify(v.meta,null,2)})]})]}),v.logs&&v.logs.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:v.logs.join(`
2
- `)})]})]}),e.jsx("div",{className:"w6w-modal-actions",children:e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>I(null),children:"Close"})})]})]}),Ne!==null&&e.jsx(i.ConfirmModal,{title:"Delete node",message:`Delete node "${Ne}"? Its connections are removed too.`,confirmLabel:"Delete",onConfirm:()=>{Me(Ne),q(null)},onClose:()=>q(null)})]})})})})})})})}function st(t){try{const s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function Bt({text:t,onChange:s,seeds:o,readOnly:a}){const l=st(t),u=l?Object.keys(l).length:0,f=u>0,[b,C]=c.useState(f);c.useEffect(()=>{f&&C(!0)},[f]);const S=m=>{s(JSON.stringify(m.lastRunOutput??m.input??{},null,2)),C(!0)};return e.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[e.jsx("span",{children:"Incoming state"}),o.length>0&&e.jsx("div",{className:"w6w-seed-picker",children:e.jsx("div",{className:"w6w-seed-chips",children:o.map(m=>e.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${m.label}'s saved test as the incoming state`,disabled:a,onClick:()=>S(m.test),children:[e.jsx("code",{children:m.label}),m.test.lastRunStatus?e.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",m.test.lastRunStatus]}):null]},m.stepId))})}),e.jsxs("details",{className:"w6w-state-override",open:b,onToggle:m=>C(m.currentTarget.open),children:[e.jsxs("summary",{children:["Override the incoming state",u>0?` · ${u} key${u===1?"":"s"} set`:""]}),e.jsx("textarea",{rows:3,value:t,readOnly:a,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:m=>s(m.target.value)}),e.jsxs("span",{className:"w6w-hint",children:["JSON merged into the call (e.g. a script's ",e.jsx("code",{children:"input"}),"). 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 Ms({workflowId:t,step:s,upstreamSteps:o,onRun:a,onCancel:l}){const u=i.useW6WApi(),f=i.isTriggerApp(s.uses.app),b=i.isInternalApp(s.uses.app),C=c.useMemo(()=>{var L;return f?i.asFieldDefs((L=s.with)==null?void 0:L.fields):[]},[f,s.with]),S=c.useMemo(()=>f?i.fieldsToParams(C):b?i.internalNodeParams(s.uses.app,s.uses.action):null,[f,b,C,s.uses.app,s.uses.action]),[m,N]=c.useState(null),d=S??m;c.useEffect(()=>{if(S)return;if(!s.uses.app||!s.uses.action){N([]);return}let L=!1;return N(null),u.getAppActions(s.uses.app).then(Y=>{var E;L||N(((E=Y.find(Q=>Q.key===s.uses.action))==null?void 0:E.params)??[])}).catch(()=>!L&&N([])),()=>{L=!0}},[u,S,s.uses.app,s.uses.action]);const[v,I]=c.useState(()=>{var L;return f?i.seedValues(i.asFieldDefs((L=s.with)==null?void 0:L.fields)):{}}),[A,V]=c.useState("{}"),T=i.useSeedSources(t,o,!f),g=i.startStateFromSeeds(T),[F,me]=c.useState(!1);c.useEffect(()=>{let L=!1;return u.listStepTests(t,s.id).then(Y=>{if(L)return;const E=Y.length?Y[Y.length-1]:null;f?E!=null&&E.with&&I(Q=>({...Q,...E.with})):E!=null&&E.input&&Object.keys(E.input).length>0&&V(JSON.stringify(E.input,null,2)),me(!0)}).catch(()=>{L||me(!0)}),()=>{L=!0}},[u,t,s.id,f]);const[ie,O]=c.useState(!0),j=st(A),D=f?ie:j!==null,ge=f?v:{...s.with??{},...j??{}},z=!!d&&F&&D&&i.requiredParamsFilled(d,ge);return e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsx("div",{className:"w6w-modal-body",children:e.jsx("div",{className:"w6w-stack",children:d===null||!F?e.jsx("p",{className:"w6w-muted w6w-small",children:d===null?"Loading parameters…":"Loading saved values…"}):f?e.jsxs(e.Fragment,{children:[e.jsx(i.PropertyEntryForm,{params:d,values:v,onChange:I,onValidityChange:O}),d.length===0&&e.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 (",e.jsx("code",{children:"input"}),")."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",e.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."]}),e.jsx(Bt,{text:A,onChange:V,seeds:T})]})})}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"}),!z&&d!==null&&F&&e.jsx("span",{className:"w6w-muted w6w-small",children:D?f?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":f?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:!z,onClick:()=>a(f?v:j??{},f?void 0:g),children:"▶ Run"})]})]})}function ve({type:t,position:s,multiple:o,id:a,variant:l}){const u=_.useNodeId(),f=c.useContext(tt),b=!!u&&!!f&&!f.readOnly,C=()=>{b&&u&&f.onAddFromPort(u,t,a)},S=l==="error"?"a step that handles this step's failure":t==="target"?"a step before this one":"the next step";return e.jsx(_.Handle,{type:t,position:s,id:a,className:l==="error"?"w6w-handle-error":o?"w6w-handle-multi":void 0,style:o?{height:22,borderRadius:3,width:8}:void 0,onClick:b?C:void 0,title:b?`Drag to empty canvas (or click) to add ${S} · drag to a port to connect`:l==="error"?"On error — drag to route this step's failure separately":o?t==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Ht({id:t,runnable:s}){const o=c.useContext(tt);return!o||o.readOnly?null:e.jsxs(_.NodeToolbar,{position:_.Position.Top,className:"w6w-node-toolbar",children:[s&&e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Test-run this node","aria-label":"Test-run this node",onClick:()=>o.onRun(t),children:e.jsx(de.Icon,{name:"run",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>o.onEdit(t),children:e.jsx(de.Icon,{name:"edit",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>o.onDuplicate(t),children:e.jsx(de.Icon,{name:"copy",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>o.onDelete(t),children:e.jsx(de.Icon,{name:"trash",size:15})})]})}function Jt({step:t,count:s}){if(s<2)return null;const o=t.fanOut==="parallel",a=Ss(s,o?"parallel":"sequential");return e.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":a,title:a,children:[e.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",s]})}function Ds({id:t,data:s,selected:o}){var m;const a=s.step,u=c.useContext(et).get(a.uses.app),f=(u==null?void 0:u.displayName)||a.uses.app||"—",b=i.nodePortsForStep(a,c.useContext(Qe)),C=$t(s.stepStatus??"no-run",s.runStatus),S=e.jsx(Jt,{step:a,count:c.useContext(Ze).get(t)??0});return e.jsxs("div",{children:[e.jsx(Ht,{id:t,runnable:!0}),e.jsxs("div",{"data-run-status":s.stepStatus??"no-run","data-step-problem":(m=s.stepProblem)==null?void 0:m.code,title:s.stepProblem?Je(s.stepProblem):void 0,style:{position:"relative",...s.stepProblem?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:o?1:C.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",borderRadius:4,padding:"8px 12px",minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[s.stepProblem&&e.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":Je(s.stepProblem),title:Je(s.stepProblem),style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:e.jsx(de.Icon,{name:"warning",size:12})}),b.in>0&&e.jsx(ve,{type:"target",position:_.Position.Left,multiple:b.in>1}),e.jsx(i.AppIcon,{src:u==null?void 0:u.iconSvg,srcDark:u==null?void 0:u.iconSvgDark,brandColor:u==null?void 0:u.brandColor,name:f,size:28}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:600},children:f}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:a.uses.action||"—"})})]}),b.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{type:"source",position:_.Position.Right,multiple:b.out>1}),e.jsx(ve,{type:"source",position:_.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,e.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[a.id,u!=null&&u.version?` - v${u.version}`:""]}),a.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:a.notes,children:a.notes})]})}function Ls({id:t,data:s,selected:o}){const a=s.step,l=i.internalNodeLabel(a.uses.app,a.uses.action),u=i.internalNodeIcon(a.uses.app,a.uses.action),f=i.nodePortsForStep(a,c.useContext(Qe)),b=i.isTriggerApp(a.uses.app),C=$t(s.stepStatus??"no-run",s.runStatus),S=e.jsx(Jt,{step:a,count:c.useContext(Ze).get(t)??0});return e.jsxs("div",{children:[e.jsx(Ht,{id:t,runnable:!i.isControlApp(a.uses.app)}),e.jsxs("div",{className:b?"w6w-node-trigger":void 0,"data-node-kind":b?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",style:{position:"relative",border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:o?1:C.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...b?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[f.in>0&&e.jsx(ve,{type:"target",position:_.Position.Left,multiple:f.in>1}),u&&e.jsx(i.InternalIcon,{icon:u}),e.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[e.jsx("div",{style:{fontWeight:600},children:l}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:a.uses.action||"—"})})]}),f.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{type:"source",position:_.Position.Right,multiple:f.out>1}),!b&&e.jsx(ve,{type:"source",position:_.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,e.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:a.id}),a.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:a.notes,children:a.notes})]})}function _s({workflowId:t,step:s,upstreamSteps:o,onChange:a,onClose:l,readOnly:u,initialView:f="props",fanOutCount:b=0,onTestRun:C,stepProblem:S}){var Me;const m=i.useW6WApi(),N=c.useContext(et),[d,v]=c.useState(s),I=kt(d,S),[A,V]=c.useState(kt(s,S)?"setup":"configure"),[T,g]=c.useState(f==="json"?"code":f==="settings"?"config":"props"),[F,me]=c.useState("props"),[ie,O]=c.useState(()=>i.stepToJson(s)),[j,D]=c.useState(()=>i.paramsToJson(s)),[ge,z]=c.useState("{}"),L=c.useRef(null),[Y,E]=c.useState(!1),[Q,se]=c.useState(!1),[xe,J]=c.useState(d.id),[ae,ne]=c.useState(null),[oe,W]=c.useState(null),[pe,be]=c.useState(null),[je,B]=c.useState(null),[le,Ce]=c.useState(!1),U=i.isInternalApp(d.uses.app);c.useEffect(()=>{if(U){W(i.internalNodeParams(d.uses.app,d.uses.action)),be(null);return}if(!d.uses.app){be(null),W([]);return}let x=!1;return W(null),m.getAppActions(d.uses.app).then(K=>{var ee;x||(be(K),W(d.uses.action?((ee=K.find(ue=>ue.key===d.uses.action))==null?void 0:ee.params)??[]:[]))}).catch(()=>!x&&W([])),()=>{x=!0}},[m,d.uses.app,d.uses.action,U]);const Ne=c.useCallback(()=>{U||!d.uses.app||m.listConnectionsForApp(d.uses.app).then(x=>{B(x),Ce(!1)}).catch(()=>Ce(!0))},[m,d.uses.app,U]);c.useEffect(()=>{if(U||!d.uses.app)return;let x=!1;return m.listConnectionsForApp(d.uses.app).then(K=>{x||(B(K),Ce(!1))}).catch(()=>!x&&Ce(!0)),()=>{x=!0}},[m,d.uses.app,U]);const q=c.useCallback(x=>{v(x),a(x)},[a]),ke=x=>{x==="code"?O(i.stepToJson(d)):x==="params-code"&&D(i.paramsToJson(d)),g(x)},fe=()=>{const x=xe.trim(),K=x&&x!==d.id?i.stepIdError(x):null;if(K){ne(K);return}x&&x!==d.id&&q({...d,id:x}),ne(null),se(!1)},H=!!d.uses.app&&!!d.uses.action&&!i.isControlApp(d.uses.app),Z=i.isTriggerApp(d.uses.app),ce=A==="test"&&H&&!Z,he=i.useSeedSources(t,o,H&&!Z),Re=i.startStateFromSeeds(he);c.useEffect(()=>{if(!H||Z)return;let x=!1;return m.listStepTests(t,d.id).then(K=>{if(x)return;const ee=K.length?K[K.length-1]:null;if(!(ee!=null&&ee.input)||Object.keys(ee.input).length===0)return;const ue=JSON.stringify(ee.input,null,2);z(re=>re.trim()==="{}"?ue:re)}).catch(()=>{}),()=>{x=!0}},[m,t,d.id,H,Z]);const Ee=st(ge),M={...d.with??{},...Ee??{}},Ie=Ee??{},Fe=!!oe&&i.requiredParamsFilled(oe,M),$=N.get(d.uses.app),Pe=U?i.internalNodeIcon(d.uses.app,d.uses.action):null,Ae=U?Pe?e.jsx(i.InternalIcon,{icon:Pe}):null:e.jsx(i.AppIcon,{src:$==null?void 0:$.iconSvg,srcDark:$==null?void 0:$.iconSvgDark,brandColor:$==null?void 0:$.brandColor,name:$==null?void 0:$.displayName});return e.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:Ae,title:e.jsxs("span",{className:"w6w-step-rename",children:[Q&&!u?e.jsx("input",{autoFocus:!0,value:xe,onChange:x=>{J(x.target.value),ne(null)},onBlur:fe,onKeyDown:x=>{x.key==="Enter"&&fe(),x.key==="Escape"&&(J(d.id),ne(null),se(!1))}}):e.jsxs(e.Fragment,{children:[e.jsx("code",{children:d.id}),!u&&e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Rename node","aria-label":"Rename node",onClick:()=>{J(d.id),se(!0)},children:e.jsx(de.Icon,{name:"edit",size:15})})]}),ae&&e.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:ae})]}),onClose:l,size:"wide",children:e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsxs("div",{className:"w6w-tabsbar",children:[e.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].map(x=>e.jsx("button",{type:"button",className:`w6w-subtab${A===x?" active":""}`,disabled:I&&x!=="setup",onClick:()=>V(x),children:x==="setup"?"Setup":x==="configure"?"Configure":"Test"},x))}),ce?e.jsx(i.ConfigViewToggle,{view:F,views:["props","code"],onChange:x=>me(x)}):e.jsx(i.ConfigViewToggle,{view:T,onChange:ke,disabled:A!=="configure"})]}),I&&S&&e.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",S.connection," no longer exists — choose another to continue."]}),e.jsxs("div",{className:"w6w-stepconfig-body",children:[A==="setup"&&e.jsx($s,{step:d,app:$,actions:pe,conns:je,connsFailed:le,isInternal:U,readOnly:u,onChangeAction:x=>q({...d,uses:{...d.uses,action:x},with:{}}),onChangeConnection:x=>q({...d,uses:{...d.uses,connection:x}}),onConnectionCreated:Ne,onChangeApp:x=>q(x===d.uses.app?d:{...d,uses:{app:x,action:"",connection:void 0},with:{}})}),A==="configure"&&e.jsxs(e.Fragment,{children:[d.uses.app===i.WEBHOOK_APP&&m.listSubscriptionsForWorkflow&&m.createSubscription&&e.jsx(Os,{workflowId:t,step:d,readOnly:u}),oe===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):T==="props"?d.uses.action==="wait"&&i.isControlApp(d.uses.app)?e.jsx(i.WaitEditor,{values:d.with??{},readOnly:u,onChange:x=>q({...d,with:x})}):e.jsx(i.ParamsForm,{params:oe,values:d.with??{},readOnly:u,onChange:x=>q({...d,with:x}),dynamic:U||!d.uses.action?void 0:{appId:d.uses.app,actionKey:d.uses.action,connectionId:I?void 0:d.uses.connection??void 0,appName:$==null?void 0:$.displayName}}):T==="code"?e.jsx(i.JsonEditor,{value:ie,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${d.id} JSON`,copyable:!0}):T==="params-code"?e.jsx(i.JsonEditor,{value:j,onChange:D,readOnly:u,minHeight:"260px",height:"100%","aria-label":`Node ${d.id} params JSON`,copyable:!0,onValidChange:x=>x&&typeof x=="object"&&!Array.isArray(x)&&q({...d,with:x})}):e.jsxs("div",{className:"w6w-stack",children:[e.jsx(i.NodeConfigForm,{config:{retry:d.retry,onError:d.onError,notes:d.notes},onChange:x=>q({...d,...x}),readOnly:u,failureHandling:!Z,retryControls:!i.isControlApp(d.uses.app)&&d.uses.app!==i.CALL_APP}),Vs,e.jsx(Ws,{step:d,count:b,readOnly:u,onChange:q})]})]}),A==="test"&&e.jsx("div",{className:"w6w-stack",children:H?Z?e.jsx(i.TriggerFillForm,{app:d.uses.app,action:d.uses.action,fields:(Me=d.with)==null?void 0:Me.fields,persist:{workflowId:t,stepId:d.id,input:Ie}}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",e.jsx("code",{children:d.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),e.jsx(Bt,{text:ge,onChange:z,seeds:he,readOnly:u}),oe===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):e.jsx(ls,{params:oe,values:M,testStartState:Re,view:F}),e.jsx(i.StepTestRun,{ref:L,app:d.uses.app,action:d.uses.action,connectionId:d.uses.connection??void 0,values:M,state:Re,canRun:Fe,hideRunButton:!0,persist:{workflowId:t,stepId:d.id,input:Ie},onBusyChange:E})]}):e.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),e.jsx("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:A!=="test"?e.jsx("button",{type:"button",className:"w6w-btn",disabled:I,onClick:()=>V(A==="setup"?"configure":"test"),children:"Next →"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),H&&!Z&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:u||!Fe||Y,onClick:()=>{var x;C==null||C(),(x=L.current)==null||x.run()},children:Y?"Testing…":"Test"})]})})]})})}const Vs=!1;function Ws({step:t,count:s,readOnly:o,onChange:a}){const l=s>=2,u=t.fanOut==="parallel"?"parallel":"sequential";return e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Run next nodes"}),e.jsxs("select",{"aria-label":"Run next nodes",value:u,disabled:o||!l,onChange:f=>a(ys(t,f.target.value)),children:[e.jsx("option",{value:"sequential",children:"In sequence"}),e.jsx("option",{value:"parallel",children:"In parallel"})]}),!l&&e.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function Os({workflowId:t,step:s,readOnly:o}){const a=i.useW6WApi(),[l,u]=c.useState(void 0),[f,b]=c.useState(null),[C,S]=c.useState(!1);c.useEffect(()=>{const N=a.listSubscriptionsForWorkflow;if(!N)return;let d=!1;return N(t).then(v=>{d||u(v.find(I=>I.appId===i.WEBHOOK_APP)??null)}).catch(v=>!d&&b(v.message)),()=>{d=!0}},[a,t]);const m=()=>{const N=a.createSubscription;N&&(b(null),S(!0),N(i.WEBHOOK_APP,s.uses.action,{workflowId:t,connectionId:null,params:s.with??{}}).then(d=>{S(!1),u(d)}).catch(d=>{S(!1),b(d instanceof Error?d.message:String(d))}))};return e.jsxs("div",{className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:[e.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]}),f&&e.jsx("div",{className:"w6w-result w6w-error",children:f}),l!=null&&l.webhookUrl?e.jsx(de.Copyable,{value:l.webhookUrl,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:l.webhookUrl,"aria-label":"Webhook URL"})}):l===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:C,onClick:m,children:C?"Creating…":"Create webhook URL"})]})}function Tt({anchorRef:t,onClose:s,children:o}){const a=c.useRef(null),[l,u]=c.useState(null),[f,b]=c.useState(null);return c.useEffect(()=>{const C=t.current;if(!C)return;const S=C.getBoundingClientRect();u({top:S.bottom+6,left:S.left,width:S.width}),b(C.closest("dialog")??document.body)},[t]),c.useEffect(()=>{function C(m){var d,v;const N=m.target;(d=a.current)!=null&&d.contains(N)||(v=t.current)!=null&&v.contains(N)||s()}function S(m){m.key==="Escape"&&s()}return document.addEventListener("mousedown",C),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",S)}},[s,t]),!l||!f?null:ss.createPortal(e.jsx("div",{ref:a,className:"w6w-flyout",style:{top:l.top,left:l.left,width:l.width},children:o}),f)}function $s({step:t,app:s,actions:o,conns:a,connsFailed:l,isInternal:u,readOnly:f,onChangeAction:b,onChangeConnection:C,onChangeApp:S,onConnectionCreated:m}){const[N,d]=c.useState(null),[v,I]=c.useState(!1),A=c.useRef(null),V=Ps(t.uses.connection,a,l);return e.jsxs("div",{className:"w6w-stack",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"App"}),e.jsxs("div",{className:"w6w-app-conn-row",ref:A,children:[e.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":N==="app",disabled:f,onClick:()=>d(T=>T==="app"?null:"app"),children:[!u&&s&&e.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),e.jsx("span",{className:"w6w-conn-label-name",children:u?t.uses.app:(s==null?void 0:s.displayName)??t.uses.app})]}),!u&&e.jsx("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"Connection","aria-expanded":N==="conn",disabled:f,onClick:()=>d(T=>T==="conn"?null:"conn"),children:e.jsx("span",{className:"w6w-conn-label-name",children:V})})]}),N==="app"&&e.jsx(Tt,{anchorRef:A,onClose:()=>d(null),children:e.jsx(i.AppPicker,{onSelectApp:T=>{const g=T.id===t.uses.app;S(T.id),d(g?"conn":null)}})}),N==="conn"&&e.jsx(Tt,{anchorRef:A,onClose:()=>d(null),children:e.jsxs("div",{className:"w6w-stack",children:[e.jsx("div",{className:"w6w-stepbuilder-list",children:(a??[]).map(T=>e.jsx("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>{C(T.id),d(null)},children:e.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[e.jsx("strong",{children:T.displayName||T.id}),T.state&&e.jsx("span",{className:"w6w-muted w6w-small",children:T.state})]})},T.id))}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>{I(!0),d(null)},children:"+ New connection"})]})})]}),!u&&v&&e.jsx(i.AddConnectionModal,{initialAppId:t.uses.app,onClose:()=>I(!1),onCreated:({connectionId:T})=>{I(!1),C(T),m(),d(null)}}),u?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx("div",{className:"w6w-muted w6w-small",children:e.jsx("code",{children:t.uses.action})})]}):e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx(i.Combobox,{value:t.uses.action,disabled:f||o===null,onChange:b,options:o===null?[{value:t.uses.action,label:t.uses.action}]:o.map(T=>({value:T.key,label:T.title??T.key}))})]})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.coerceDefault=i.coerceDefault;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=Rt;exports.MAX_NOTE_BYTES=Ft;exports.MAX_SECTIONS=It;exports.WorkflowFlowEditor=Is;exports.assignMembership=Ke;exports.clampCanvas=Xe;exports.pruneSectionMembers=qe;exports.renameSectionMember=Dt;exports.roundGeometry=Ue;exports.sectionsContaining=Lt;exports.withCanvasGeometry=Mt;
1
+ "use client";"use strict";var no=Object.defineProperty;var oo=(e,s,o)=>s in e?no(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o;var it=(e,s,o)=>oo(e,typeof s!="symbol"?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),be=require("@w6w/expr"),oe=require("@xyflow/react"),d=require("react"),i=require("./connection-app-meta-BEXlKBgV.cjs"),ye=require("./CodeBlock-CymlfyeA.cjs");function io({x:e,y:s,items:o,onAction:n,onClose:a}){const c=d.useRef(null),[l,p]=d.useState({left:e,top:s});d.useLayoutEffect(()=>{const g=c.current,x=g==null?void 0:g.offsetParent;if(!g||!x)return;const f=g.offsetWidth,v=g.offsetHeight;p({left:e+f>x.clientWidth?Math.max(0,e-f):e,top:s+v>x.clientHeight?Math.max(0,s-v):s})},[e,s]),d.useEffect(()=>{var g,x;(x=(g=c.current)==null?void 0:g.querySelector("[role=menuitem]"))==null||x.focus({preventScroll:!0})},[]),d.useEffect(()=>{const g=v=>{var S;(S=c.current)!=null&&S.contains(v.target)||a(!1)},x=v=>{var S;(S=c.current)!=null&&S.contains(v.target)||a(!1)},f=()=>a(!1);return document.addEventListener("pointerdown",g,!0),document.addEventListener("scroll",x,!0),document.addEventListener("wheel",x,{capture:!0,passive:!0}),window.addEventListener("blur",f),window.addEventListener("resize",f),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("scroll",x,!0),document.removeEventListener("wheel",x,!0),window.removeEventListener("blur",f),window.removeEventListener("resize",f)}},[a]);const h=g=>{g.disabled||(a(!1),n(g.action))};return t.jsx("div",{ref:c,className:"w6w-note-menu w6w-canvas-menu",role:"menu","aria-label":"Canvas actions","data-testid":"canvas-context-menu",style:{left:l.left,top:l.top},onContextMenu:g=>g.preventDefault(),onKeyDown:g=>{var S;g.stopPropagation();const x=[...((S=c.current)==null?void 0:S.querySelectorAll("[role=menuitem]"))??[]],f=x.indexOf(document.activeElement),v=I=>{var L;return(L=x[(I+x.length)%x.length])==null?void 0:L.focus()};if(g.key==="ArrowDown")v(f+1);else if(g.key==="ArrowUp")v(f<0?-1:f-1);else if(g.key==="Home")v(0);else if(g.key==="End")v(-1);else if(g.key==="Escape"||g.key==="Tab")a(!0);else if(g.key==="Enter"||g.key===" ")f>=0&&h(o[f]);else return;g.preventDefault()},children:o.map(g=>t.jsx("button",{type:"button",role:"menuitem",tabIndex:-1,"aria-disabled":g.disabled||void 0,className:`w6w-note-menu-item${g.danger?" danger":""}${g.separated?" separated":""}`,"data-action":g.action,onClick:()=>h(g),children:g.label},g.action))})}function ro(e,s){return s===void 0?[...e]:e.includes(s)?[...e]:[s]}function ao(e,s){const o=[],n=e.length;if(n>0){const a=n>1?` ${n} nodes`:"";o.push({action:"duplicate",label:`Duplicate${a}`,disabled:s}),o.push({action:"delete",label:`Delete${a}`,disabled:s,danger:!0})}return o.push({action:"add-node",label:"Add node",disabled:s,separated:n>0}),o.push({action:"add-trigger",label:"Add trigger",disabled:s}),o}const dn=200,un=200,pn=10240;function Gt(e){const s={};for(const[o,n]of Object.entries(e))s[o]=Math.round(n);return s}const co=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y),lo=e=>!!e&&Number.isFinite(e.width)&&Number.isFinite(e.height);function zs(e,s,o){return e&&e.map(n=>{const a=s==null?void 0:s[n.id],c=co(a==null?void 0:a.position)?a.position:n.position,l=lo(a==null?void 0:a.size)?a.size:n.size;return{...n,position:Gt(c),size:Gt(l)}})}function fn(e,s,o){if(!s)return e;const n={...e};return e.notes&&(n.notes=zs(e.notes,o)),e.sections&&(n.sections=zs(e.sections,o)),n}function ts(e,s){return e.sections?{...e,sections:e.sections.map(o=>({...o,nodes:o.nodes.filter(n=>n!==s)}))}:e}function hn(e,s,o){return e.sections?{...e,sections:e.sections.map(n=>({...n,nodes:n.nodes.map(a=>a===s?o:a)}))}:e}function Kt(e,s,o){if(!e.sections)return e;const n=new Set(o);return{...e,sections:e.sections.map(a=>{const c=a.nodes.filter(l=>!n.has(l));return a.id===s?{...a,nodes:[...new Set([...c,...o])]}:{...a,nodes:c}})}}function mn(e,s){return(e.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function uo(e,s){const o=new TextEncoder;if(o.encode(e).length<=s)return e;let n="",a=0;for(const c of e){const l=o.encode(c).length;if(a+l>s)break;n+=c,a+=l}return n}function Xt(e){const s={...e};return e.notes&&(s.notes=e.notes.slice(0,dn).map(o=>({...o,content:uo(o.content,pn)}))),e.sections&&(s.sections=e.sections.slice(0,un)),s}function po(e,s,o){const n={};for(const l of[...e.notes??[],...e.sections??[]])n[l.id]={position:l.position,size:l.size};const a=(l,p)=>l==null?void 0:l.map(h=>{const g=p==null?void 0:p.find(x=>x.id===h.id);return g?{...h,position:g.position,size:g.size}:h}),c=o?e:{...e,...e.notes?{notes:a(e.notes,s==null?void 0:s.notes)}:{},...e.sections?{sections:a(e.sections,s==null?void 0:s.sections)}:{}};return fn(c,o,n)}const Hs=220;function fo(e){return e.length<=Hs?{text:e,clipped:!1,length:e.length}:{text:e.slice(0,Hs).trimEnd(),clipped:!0,length:e.length}}function ho({params:e,values:s,testStartState:o,view:n="props",literalKeys:a}){const{sampleValues:c,nodeConfig:l,nodeMeta:p}=i.useExpressionOptions(),h=d.useMemo(()=>i.buildResolveScope(c,o,l,p),[c,o,l,p]),g=i.flattenParams(e),x=S=>{var I;return s[S]!==void 0?s[S]:(I=g.find(L=>L.key===S))==null?void 0:I.default},f=g.filter(S=>S.type!=="section"&&i.isParamVisible(S,x)).map(S=>be.effectiveParam(S,x));if(i.hasParamCustomization(s)){const S=i.previewCustomization(s.$merge,h,a),I=S!==null&&typeof S=="object"&&!Array.isArray(S),L=Js(f,s,h,a);for(const[B,N]of Object.entries(s))B!=="$merge"&&(L[B]=a!=null&&a.includes(B)?N:i.previewCustomization(N,h));const m=I?{...L,...S}:L;return t.jsxs("div",{className:"w6w-resolved-params",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:I?"JSON customization applied after form values.":`JSON customization is not available as an object in this preview (${String(S)}). Test the step to validate it.`}),n==="code"?t.jsx(i.JsonEditor,{value:JSON.stringify(m,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"}):t.jsx("div",{className:"w6w-resolved-table",children:Object.entries(m).map(([B,N])=>{var z;return t.jsx(Yt,{label:((z=g.find(H=>H.key===B))==null?void 0:z.label)??B,segments:[{status:"resolved",value:N}]},B)})})]})}if(n==="code"){const S=Js(f,s,h,a);return t.jsx("div",{className:"w6w-resolved-params",children:t.jsx(i.JsonEditor,{value:JSON.stringify(S,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const v=f.filter(S=>!i.deepEqual(x(S.key),S.default));return f.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):v.length===0?t.jsx("div",{className:"w6w-resolved-params",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):t.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:v.map(S=>S.type==="vars"?t.jsx(mo,{param:S,value:s[S.key],scope:h},S.key):t.jsx(Yt,{label:S.label??S.key,segments:a!=null&&a.includes(S.key)?[{status:"resolved",value:x(S.key)}]:i.resolveParamValue(x(S.key),h)},S.key))})}function Js(e,s,o,n){const a={};for(const c of e)if(n!=null&&n.includes(c.key))a[c.key]=s[c.key]!==void 0?s[c.key]:c.default;else if(c.type==="vars"){const l=s[c.key]??c.default??[],p=i.dataVarRows(l);a[c.key]=p?i.resolveVarsJson(p,o):i.resolveParamJson(l,o)}else a[c.key]=i.resolveParamJson(s[c.key]!==void 0?s[c.key]:c.default,o);return a}function Yt({label:e,segments:s}){return t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e}),t.jsx("div",{className:"w6w-resolved-value",children:t.jsx(wn,{segments:s})})]})}function mo({param:e,value:s,scope:o}){const n=s??e.default??[],a=i.dataVarRows(n);return a===null?t.jsx(Yt,{label:e.label??e.key,segments:i.resolveParamValue(n,o)}):t.jsxs("div",{className:"w6w-resolved-row",children:[t.jsx("span",{className:"w6w-resolved-label",children:e.label??e.key}),a.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):t.jsx("div",{className:"w6w-stack",children:a.map((c,l)=>t.jsxs("div",{className:"w6w-resolved-value",children:[t.jsx("code",{children:c.key||"(no key)"})," → ",t.jsx(wn,{segments:i.resolveParamValue(c.value,o)})]},l))})]})}function wn({segments:e}){return t.jsx(t.Fragment,{children:e.map((s,o)=>t.jsx(wo,{segment:s},o))})}function wo({segment:e}){switch(e.status){case"resolved":return e.ref?t.jsxs(t.Fragment,{children:[t.jsx(dt,{kind:"var",refName:e.ref}),t.jsx(Us,{value:e.value})]}):t.jsx(Us,{value:e.value});case"unresolved":return t.jsxs(t.Fragment,{children:[t.jsx(dt,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"at-run":return t.jsxs(t.Fragment,{children:[t.jsx(dt,{kind:"var",refName:e.ref}),t.jsx("span",{className:"w6w-param-unevaluated",children:"resolved at run"})]});case"not-evaluated":return t.jsxs(t.Fragment,{children:[t.jsx(dt,{kind:"expr"}),t.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return t.jsx(dt,{kind:"secret",refName:e.ref})}}function Us({value:e}){const[s,o]=d.useState(!1),n=xo(e),a=fo(n);return a.clipped?t.jsxs(t.Fragment,{children:[s?t.jsx(ye.Copyable,{value:n,label:"Copy resolved value",className:"w6w-resolved-copy",children:t.jsx("pre",{className:"w6w-resolved-text-full",children:n})}):t.jsxs("span",{children:[a.text,"…"]}),t.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>o(c=>!c),children:s?"Show less":`Show all (${a.length.toLocaleString()} characters)`})]}):t.jsx("span",{children:n})}const go={var:"◆",secret:"🔒",expr:"ƒ"};function dt({kind:e,refName:s}){const o=e==="expr"?"expr":i.varLabel(s??"");return t.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${e}`,children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:go[e]}),t.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function xo(e){if(e===null)return"null";if(e===void 0)return"(not set)";if(e==="")return'""';if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function gn(e){return e.language==="python"||e.language==="typescript"?e.language:"javascript"}function bo({enabled:e,values:s,onChange:o}){const[n,a]=d.useState(null),c=d.useRef(!1),l=typeof s.code=="string"?s.code:"";return d.useEffect(()=>{if(!e||c.current)return;c.current=!0;const p=i.convertCodeBindingsToReads(l,gn(s));p.converted!==0&&(a({original:l,converted:p.converted}),o({...s,code:p.code}))},[e,l,s,o]),n?{converted:n.converted,undo:()=>{o({...s,code:n.original}),a(null)}}:null}function jo({values:e,conversion:s,readOnly:o}){const n=typeof e.code=="string"?e.code:"",a=s,c=i.findCodeBindings(n,gn(e)).length;return!a&&c===0?null:t.jsxs("output",{className:"w6w-hint w6w-script-converted",children:[a&&t.jsxs(t.Fragment,{children:["Converted ",a.converted," reference",a.converted===1?"":"s"," to code reads",!o&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"w6w-script-converted-undo",onClick:a.undo,children:"Undo"})]}),c>0&&" · "]}),c>0&&t.jsxs(t.Fragment,{children:[c," ",t.jsx("code",{children:"{{ }}"})," left in the code stay",c===1?"s":""," literal text — read ",c===1?"it":"them"," from"," ",t.jsx("code",{children:"state"}),", or bind under Custom input"]})]})}function qs(e,s){return{nodeIds:e.filter(o=>o.selected).map(o=>o.id),edgeIds:s.filter(o=>o.selected).map(o=>o.id)}}function yo(e,s,o,n){const a=new Set(e.nodeIds),c=new Set(e.edgeIds),l=s.filter(f=>a.has(f.id)),p=[...l.filter(f=>i.isForeachStep(f.data.step)),...l.filter(f=>!i.isForeachStep(f.data.step))];let h=s,g=o,x=n;for(const f of p)g=i.bridgeDeletedBodyStep(f.id,h,g),h=h.filter(v=>v.id!==f.id),x=ts(x,f.id);return{nodes:h,edges:g.filter(f=>!c.has(f.id)),canvas:x}}function vo(e,s,o){var p;const n=new Set(e.nodeIds),a=new Set(e.edgeIds),c=o.filter(h=>a.has(h.id)&&!n.has(h.source)&&!n.has(h.target)),l=[];if(n.size===1)l.push(i.deleteStepMessage(e.nodeIds[0],s,o));else if(n.size>1){l.push(`Delete nodes ${[...n].map(g=>`"${g}"`).join(", ")}? Their connections are removed too.`);const h=new Set;for(const g of n)if(i.isForeachStep((p=s.find(x=>x.id===g))==null?void 0:p.data.step))for(const x of i.loopBody(g,s,o))n.has(x)||h.add(x);h.size&&l.push(`Loop body steps ${[...h].map(g=>`"${g}"`).join(", ")} stay as standalone steps.`)}return c.length&&l.push(`Delete ${c.length===1?"connection":"connections"} ${c.map(h=>`"${h.source} → ${h.target}"`).join(", ")}?`),l.join(" ")}function So(e,s){const o={success:0,error:0};for(const a of s){if(a.source!==e)continue;const c=i.edgeLane(a);c!=="each"&&o[c]++}const n=Math.max(o.success,o.error);return{enabled:n>=2,count:n}}function Co(e,s){const{fanOut:o,...n}=e;return s==="parallel"?{...n,fanOut:"parallel"}:n}function No(e,s){return`Runs these ${e} nodes in ${s==="parallel"?"parallel":"sequence"}`}function kt(e,s,o,n,a){const c=i.flowToWorkflow({...e,connections:n},s,o);return{nodes:c.nodes.map(({with:l,...p})=>l&&Object.keys(l).length?{...p,with:l}:p),edges:c.edges??[],connections:c.connections??{},canvas:a,positions:Object.fromEntries(s.map(l=>[l.id,l.position]))}}function ko(e,s){const o=i.workflowToFlow({...e,...s});return{...o,nodes:o.nodes.map(n=>({...n,position:s.positions[n.id]??n.position}))}}class Eo{constructor(s,o=100){it(this,"past",[]);it(this,"future",[]);it(this,"present");it(this,"group");it(this,"limit");this.limit=o,this.present=JSON.stringify(s)}reset(s){this.present=JSON.stringify(s),this.past=[],this.future=[],this.group=void 0}record(s,o){const n=JSON.stringify(s);n!==this.present&&((!o||o!==this.group)&&(this.past.push(this.present),this.past.length>this.limit&&this.past.shift()),this.present=n,this.group=o,this.future=[])}undo(){const s=this.past.pop();if(s!==void 0)return this.future.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}redo(){const s=this.future.pop();if(s!==void 0)return this.past.push(this.present),this.present=s,this.group=void 0,JSON.parse(s)}}function Ht(e){var o;const s=e;return!!(s!=null&&s.isContentEditable||(o=s==null?void 0:s.closest)!=null&&o.call(s,'input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"], .cm-editor'))}const Ao=64,ut=24,Ke=32;function Et(e){var s,o;return{width:((s=e.measured)==null?void 0:s.width)??e.width??200,height:((o=e.measured)==null?void 0:o.height)??e.height??64}}function To(e,s){return e.x<s.x+s.width&&e.x+e.width>s.x&&e.y<s.y+s.height&&e.y+e.height>s.y}function Io(e){const s=(a,c)=>{const l=new Map;for(const g of e){const x=g.position[a];l.set(x,Math.max(l.get(x)??0,Et(g)[c]))}const p=new Map;let h=Number.NEGATIVE_INFINITY;for(const[g,x]of[...l].sort(([f],[v])=>f-v)){const f=Math.max(g,h);p.set(g,f),h=f+x+Ao}return p},o=s("x","width"),n=s("y","height");return e.map(a=>({...a,position:{x:o.get(a.position.x)??a.position.x,y:n.get(a.position.y)??a.position.y}}))}function Po(e,s,o){var p;const n=Io(i.relayoutNodes(e,s));if(!((p=o.sections)!=null&&p.length))return{nodes:n,canvas:o};const a=new Map(n.map(h=>[h.id,h])),c=(o.notes??[]).map(h=>({...h.position,...h.size}));for(const h of o.sections)h.nodes.some(g=>a.has(g))||c.push({...h.position,...h.size,y:h.position.y-Ke,height:h.size.height+Ke});const l=o.sections.map(h=>{const g=new Set(h.nodes),x=n.filter(N=>g.has(N.id));if(!x.length)return h;const f=Math.min(...x.map(N=>N.position.x))-ut,v=Math.min(...x.map(N=>N.position.y))-ut,S=Math.max(...x.map(N=>N.position.x+Et(N).width)),I=Math.max(...x.map(N=>N.position.y+Et(N).height)),L={x:f,y:v,width:S+ut-f,height:I+ut-v},m=[...c,...[...a.values()].filter(N=>!g.has(N.id)).map(N=>({...N.position,...Et(N)}))].sort((N,z)=>N.y-z.y);for(const N of m){const z={...L,y:L.y-Ke,height:L.height+Ke};To(z,N)&&(L.y=N.y+N.height+ut+Ke)}const B=L.y-v;for(const N of x)a.set(N.id,{...N,position:{x:N.position.x,y:N.position.y+B}});return c.push({...L,y:L.y-Ke,height:L.height+Ke}),{...h,position:{x:L.x,y:L.y},size:{width:L.width,height:L.height}}});return{nodes:n.map(h=>a.get(h.id)??h),canvas:{...o,sections:l}}}const Jt=6;function Ro(e){let s=2166136261;for(let o=0;o<e.length;o++)s^=e.charCodeAt(o),s=Math.imul(s,16777619);return s>>>0}function Mo(e){const s=new Map;let o=new Set;for(const n of[...new Set(e)].sort()){o.size===Jt&&(o=new Set);let a=Ro(n)%Jt;for(;o.has(a);)a=(a+1)%Jt;o.add(a),s.set(n,a+1)}return s}function ss(e){return`var(--w6w-loop-${e})`}function xn(e,s){const o=[],n=new Set([e]);for(let a=s.get(e);a&&!n.has(a);a=s.get(a))n.add(a),o.unshift(a);return o}function Lo(e,s,o){return s.size===0?e:e.map(n=>{var l;if(((l=n.data)==null?void 0:l.when)!=="each")return n;const a=n.sourceHandle===i.EACH_SOURCE_HANDLE?n.source:o.get(n.source),c=a?s.get(a):void 0;return c===void 0?n:{...n,style:{...n.style,"--w6w-loop-color":ss(c)}}})}function Fo(e,s){const o=s.get(e);return o===void 0?void 0:{"--w6w-loop-color":ss(o)}}function Do(e){const s=[];for(const o of e){const n=i.isForeachStep(o.data.step);(n||o.data.loopOf)&&s.push([o.id,n?1:0,o.data.loopOf])}return JSON.stringify(s)}function Oo(e){const s=JSON.parse(e);return{tones:Mo(s.filter(o=>o[1]===1).map(o=>o[0])),loopOf:new Map(s.map(o=>[o[0],o[2]]))}}const Gs="Paused — test runs stop before this node",Ks="Disabled — skipped in every run";function Xe(e){var s;return((s=e.ui)==null?void 0:s.paused)===!0}function Ie(e){return e.disabled===!0}function bn(e,s){const{ui:o,...n}=e,{paused:a,...c}=o??{},l=s?{...c,paused:!0}:c;return Object.keys(l).length>0?{...n,ui:l}:n}function jn(e,s){const{disabled:o,...n}=e;return s?{...n,disabled:!0}:n}function Zt(e,s){return e.filter(o=>o.id!==s&&Xe(o)).map(o=>o.id)}const _o=["nodes","steps"];function Xs(e,s){for(const o of _o){const n=`${o}.${s}.output`;if(!e.startsWith(n))continue;const a=e.slice(n.length);if(a===""||a[0]==="."||a[0]==="[")return`foreach.item${a}`}return null}function At(e,s,o){if(typeof e=="string"){if(!e.includes("{{"))return e;const n=i.parseRootAnchoredTemplate(e);let a=!1;const c=n.map(l=>{if(l.kind!=="var"||l.ref===void 0)return l;const p=Xs(l.ref,s);return p===null?l:(a=!0,o.includes(l.ref)||o.push(l.ref),{...l,ref:p})});return a?be.serializeTemplate(c):e}if(i.isDollarPath(e)){const n=e.$;if(typeof n!="string")return e;const a=Xs(n,s);return a===null?e:(o.includes(n)||o.push(n),{$:a})}if(Array.isArray(e)){let n=!1;const a=e.map(c=>{const l=At(c,s,o);return l!==c&&(n=!0),l});return n?a:e}if(typeof e=="object"&&e!==null){let n=!1;const a={};for(const[c,l]of Object.entries(e)){const p=At(l,s,o);p!==l&&(n=!0),a[c]=p}return n?a:e}return e}function Wo(e){if(typeof e=="string"){if(!e.includes("{{"))return!1;const s=i.parseRootAnchoredTemplate(e);return s.length===1&&s[0].kind==="var"}return i.isDollarPath(e)&&typeof e.$=="string"}function yn(e){return Array.isArray(e)&&e.length===1&&Wo(e[0])}function $o(e){var s;try{const o=i.normalizeInput(e);if(!Array.isArray(o.nodes))return{};const n={},a=(l,p)=>{const h=Object.hasOwn(n,l)?n[l]:[];h.push(p),n[l]=h},c=new Map(o.nodes.map(l=>[l.id,l]));for(const[l,p]of Object.entries(i.definitionLoops(o))){const h=c.get(l);if(h&&yn((s=h.with)==null?void 0:s.items)&&a(l,{code:"foreach_wrapped_items",fix:{kind:"unwrap_items",label:"Unwrap Items"}}),"invalid"in p){a(l,{code:"loop_body_invalid",reason:{...p.invalid}});continue}for(const g of p.body){const x=c.get(g);if(!(x!=null&&x.with))continue;const f=[];At(x.with,l,f),f.length>0&&a(g,{code:"foreach_body_refs_output",foreachId:l,refs:f,fix:{kind:"use_current_item",foreachId:l,label:"Use Current item"}})}}return n}catch{return{}}}function Bo(e){const s=new Set,o=n=>{if(typeof n=="string")s.add(n);else if(Array.isArray(n))for(const a of n)o(a)};return o(e),s}function Vo(e){var s,o;try{const n=i.normalizeInput(e);if(!Array.isArray(n.nodes))return[];const a=n.nodes.filter(C=>typeof C=="object"&&C!==null&&typeof C.id=="string"),c=i.effectiveEdges({...n,nodes:a}).filter(C=>typeof(C==null?void 0:C.from)=="string"&&typeof(C==null?void 0:C.to)=="string"),l=[];for(const C of a)try{const A=be.staticWritePaths(be.effectiveStateConfig((s=C.uses)==null?void 0:s.app,(o=C.uses)==null?void 0:o.action,C.state));A.length>0&&l.push({id:C.id,paths:A})}catch{}if(l.length<2)return[];const p=new Map;for(const C of a)for(const A of i.controlOwnedIds(C))p.has(A)||p.set(A,C.id);const h=C=>{const A=[C];let R=C;for(;p.has(R)&&(R=p.get(R),!A.includes(R));)A.push(R);return A},g=C=>{const A=h(C);return A[A.length-1]},x=new Map;for(const C of c){const A=x.get(C.from)??[];A.push(C.to),x.set(C.from,A)}const f=new Map,v=C=>{const A=f.get(C);if(A)return A;const R=new Set,W=[...x.get(C)??[]];for(;W.length>0;){const V=W.pop();if(!R.has(V)){R.add(V);for(const ee of x.get(V)??[])W.push(ee)}}return f.set(C,R),R},S=(C,A)=>C===A||v(C).has(A),I=a.filter(C=>{var A;return((A=C.uses)==null?void 0:A.app)===i.CONTROL_APP&&C.uses.action==="parallel"}).map(C=>{var R;const A=(R=C.with)==null?void 0:R.branches;return Array.isArray(A)?A.map(Bo):[]}),L=(C,A)=>{for(const R of h(A)){const W=C.findIndex(V=>V.has(R));if(W>=0)return W}return-1},m=[];for(const C of a){if(C.fanOut!=="parallel")continue;const A=new Map;for(const R of c){if(R.from!==C.id||i.isEachLink(R))continue;const W=R.when??"success",V=A.get(W)??[];V.push(R.to),A.set(W,V)}for(const R of A.values())R.length>=2&&m.push(R)}const B=(C,A)=>{for(const V of I){const ee=L(V,C),b=L(V,A);if(ee>=0&&b>=0&&ee!==b)return!0}const R=g(C),W=g(A);return R===W||v(R).has(W)||v(W).has(R)?!1:m.some(V=>V.some((ee,b)=>V.some(($,le)=>b!==le&&S(ee,R)&&S($,W))))},N=new Set,z=[];for(let C=0;C<l.length;C++)for(let A=C+1;A<l.length;A++){const R=l[C],W=l[A];if(!(R.id===W.id||!B(R.id,W.id)))for(const V of R.paths)for(const ee of W.paths){if(!be.statePathsOverlap(V,ee))continue;const b={code:"state_parallel_write",nodes:[R.id,W.id].sort(),path:[...V.length<=ee.length?V:ee]},$=JSON.stringify([b.nodes,b.path]);N.has($)||(N.add($),z.push(b))}}const H=(C,A)=>C<A?-1:C>A?1:0;return z.sort((C,A)=>H(C.code,A.code)||H(C.nodes.join(","),A.nodes.join(","))||H(C.path.join("."),A.path.join(".")))}catch{return[]}}function zo(e){try{const s={};for(const o of Vo(e))for(const n of o.nodes){const a=Object.hasOwn(s,n)?s[n]:[];a.push({code:o.code,path:[...o.path],with:o.nodes.filter(c=>c!==n)}),s[n]=a}return s}catch{return{}}}function vn(e,s){var o;if(s.code==="foreach_wrapped_items"){const n=(o=e.with)==null?void 0:o.items;return!e.with||!yn(n)?e:{...e,with:{...e.with,items:n[0]}}}if(s.code==="foreach_body_refs_output"){if(!e.with)return e;const n=At(e.with,s.foreachId,[]);return n===e.with?e:{...e,with:n}}return e}function Ys(e,s,o){return e&&e.nodeId===s&&e.handleType===((o==null?void 0:o.type)??"source")?i.laneForSourceHandle(e.handleId):i.laneForSourceHandle(o==null?void 0:o.id)}function Ho(e,s,o,n,a){var h;const c=(h=n.find(g=>g.id===e))==null?void 0:h.data.step,l=i.loopMembership(n,a)[e]!==void 0,p=o==="success"&&l?"each":o;return p==="each"&&!l&&!i.isForeachStep(c)?null:i.loopRefusal(e,s,p,n,a)}const Jo=["off","root","key","pick","append"],Uo={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function qo(e){return be.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function Go(e,s){return JSON.stringify(e)===JSON.stringify(s)}function Ko(e,s){const{state:o,...n}=e,a=be.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return Go(s,a)?n:{...n,state:s}}function Xo(e,s){switch(s){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function Yo(e){return!i.isControlApp(e.uses.app)}function Tt(e,s){var o;return(o=e.nodes??e.steps)==null?void 0:o[s]}function Qt(e,s){const o=Tt(e,s);return(o==null?void 0:o.status)==="skipped"&&o.skipReason==="not_on_path"}const Zo=new Set(["succeeded","failed","canceled"]);function Qo(e,s,o=[]){var c,l;if(!e||[...o,s].some(p=>Qt(e,p)))return"no-run";const n=Tt(e,s);if(n)return n.status;const a=new Set;for(const p of Object.values(e.nodes??e.steps??{}))if(Array.isArray(p==null?void 0:p.iterations))for(const h of p.iterations){const g=(l=(c=h==null?void 0:h.nodes)==null?void 0:c[s])==null?void 0:l.status;g&&a.add(g)}for(const p of["failed","running","succeeded","skipped"])if(a.has(p))return p;return"pending"}const Zs={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function Sn(e,s){const o=s!==void 0&&Zo.has(s);switch(e){case"no-run":return Zs;case"pending":return o?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return Zs}}function ei(e,s,o,n,a){var l;if(!e||Qt(e,s)||a!==void 0&&Qt(e,a))return;const c=ti(e,s,o,n);return c==="taken"&&a!==void 0&&((l=Tt(e,a))==null?void 0:l.status)==="skipped"?"skipped":c}function ti(e,s,o,n){const a=Tt(e,s);if(!a)return;if(o==="each")return a.status==="skipped"?"skipped":void 0;const c=o??"success",l=a.output,p=n===i.FOREACH_DONE_ROUTE&&!(l&&typeof l=="object"&&"route"in l);if(n!==void 0&&!p&&a.status==="succeeded")return l&&typeof l=="object"&&"matched"in l?n==="false"!=(l.matched===!0)?"taken":"skipped":l&&typeof l=="object"&&"route"in l&&l.route===n?"taken":"skipped";if(a.status==="succeeded")return c==="success"?"taken":"skipped";if(a.status==="failed")return c==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}const Qs={fields:[],sampleValues:{}};function Cn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function si(e,s){var g;const o=e.map(x=>x.id),n=new Set(o),a=new Map(o.map(x=>[x,0])),c=new Map(o.map(x=>[x,[]]));for(const x of s)!n.has(x.source)||!n.has(x.target)||((g=c.get(x.source))==null||g.push(x.target),a.set(x.target,(a.get(x.target)??0)+1));const l=[],p=o.filter(x=>a.get(x)===0);for(;p.length>0;){const x=p.shift();l.push(x);for(const f of c.get(x)??[]){const v=(a.get(f)??0)-1;a.set(f,v),v===0&&p.push(f)}}const h=new Set(l);for(const x of o)h.has(x)||l.push(x);return l}const ni=new Set(["string","number","boolean","object","array"]);function pt(e){if(!Array.isArray(e))return;const s={type:"object",fields:{}};let o=!1;for(const n of e){if(!Cn(n)||typeof n.key!="string"||n.key==="")continue;const a=n.key.split(".");let c=s;for(const h of a.slice(0,-1)){const g=c.fields[h];(g==null?void 0:g.type)!=="object"&&(c.fields[h]={type:"object",fields:{}}),c=c.fields[h]}const l=typeof n.type=="string"&&ni.has(n.type)?n.type:"string";let p;if(l==="array"){const h=pt(n.items);p=h?{type:"array",items:h}:{type:"array"}}else l==="object"?p=pt(n.fields??n.properties)??{type:"object",fields:{}}:p={type:l};c.fields[a[a.length-1]]=p,o=!0}return o?s:void 0}function oi(e,s){var g,x,f,v,S,I,L;const o=e.data.step,n=((g=s.testOutputs)==null?void 0:g[o.id])??((x=s.persistedOutputs)==null?void 0:x[o.id]);if(n!=null)return n;const{app:a,action:c}=o.uses;if(a===i.TRIGGER_APP&&((f=i.internalNodeDef(a,c))==null?void 0:f.group)==="trigger"){const m=i.fieldsToParams(i.asFieldDefs((v=o.with)==null?void 0:v.fields)).map(B=>({key:B.key}));return i.shapeToSkeleton(pt(m))}const l=(S=i.internalNodeDef(a,c))==null?void 0:S.output;if(l&&l.length>0)return i.shapeToSkeleton(pt(l));const p=o.uses.trigger===!0?(I=s.triggerDef)==null?void 0:I.call(s,a,c):(L=s.actionDef)==null?void 0:L.call(s,a,c),h=pt(p==null?void 0:p.output);return h?i.shapeToSkeleton(h):p==null?void 0:p.sample}function ii(e,s){var p,h,g,x,f;const o=e.data.step,n=(p=s.previewOutputs)==null?void 0:p[o.id];if(n!=null)return n;const{app:a,action:c}=o.uses,l=o.uses.trigger===!0?(g=(h=s.shapes)==null?void 0:h.triggerDef)==null?void 0:g.call(h,a,c):(f=(x=s.shapes)==null?void 0:x.actionDef)==null?void 0:f.call(x,a,c);return l==null?void 0:l.sample}function ri(e){switch(e){case"number":case"integer":return 0;case"boolean":return!1;case"object":return{};case"array":return[];default:return""}}function en(e,s){const o=Cn(e.initialState)?{...e.initialState}:{};for(const n of e.variables??[])!n||typeof n.key!="string"||n.key===""||(n.default!==void 0?o[n.key]=n.default:s||(o[n.key]=ri(n.type)));return o}function Ut(e){return(i.inferOutputFields(e)??[]).map(s=>s.key)}function ai(e){const{anchorId:s,nodes:o,edges:n}=e;if(!s)return Qs;const a=e.shapes??{},c=i.ancestorIds(s,n);c.delete(s);const l=new Map(o.map(C=>[C.id,C])),p=[],h=[],g=new Map;for(const C of si(o,n)){if(!c.has(C))continue;const A=l.get(C);if(!A)continue;const{app:R,action:W}=A.data.step.uses,V=be.effectiveStateConfig(R,W,A.data.step.state);if(V.mode==="off")continue;const ee=oi(A,a);if(ee!==void 0){const{ops:$}=be.computeStateWrites(V,ee);p.push(...$);for(const le of Ut(be.foldState({},$))){const de=g.get(le)??new Set;de.add(C),g.set(le,de)}}const b=ii(A,e);b!==void 0&&h.push(...be.computeStateWrites(V,b).ops)}const x=en(e,!1),f=be.foldState(x,p),v=Ut(f);if(v.length===0)return Qs;const S=new Set(Ut(x)),I=new Map,L=new Map;for(const C of n)c.has(C.source)&&(!c.has(C.target)&&C.target!==s||(I.set(C.target,[...I.get(C.target)??[],C.source]),L.set(C.source,[...L.get(C.source)??[],C.target])));const m=[...c].filter(C=>!(I.get(C)??[]).length),B=C=>{const A=new Set,R=m.filter(W=>!C.has(W));for(;R.length>0;){const W=R.pop();if(W===s)return!1;if(!A.has(W)){A.add(W);for(const V of L.get(W)??[])C.has(V)||R.push(V)}}return!0},N=be.foldState(en(e,!0),h),z=[],H={};for(const C of v){const A=g.get(C)??new Set,R=S.has(C)||A.size>0&&B(A);z.push({key:C,path:!0,paths:R?"all":"some"});const W=i.valueAtPath(N,C);W!==void 0&&(H[`state.${C}`]=W)}return{fields:z,sampleValues:H}}const ci={registered:{label:"Registered",tone:"ok"},pending:{label:"Registering",tone:"pending"},failed:{label:"Registration failed",tone:"danger"},paused:{label:"Paused",tone:"muted"},destroying:{label:"Removing",tone:"muted"}},tn="Never fired";function li(e){if(!e)return tn;const s=new Date(e);return Number.isNaN(s.getTime())?tn:`Last fired ${s.toISOString().slice(0,16).replace("T"," ")} UTC`}function di(e,s){var a;if(!(e!=null&&e.status))return null;const o=ci[e.status];if(!o)return null;const n=e.status==="failed";return{label:o.label,tone:o.tone,error:n?((a=e.lastError)==null?void 0:a.message)??null:null,lastFire:li(e.lastFireAt),retryVisible:n&&s}}function ui(e){const s=new Map;for(const o of e)o.nodeId&&s.set(o.nodeId,o);return s}function pi(e){return(e??[]).filter(s=>{var o;return((o=s.uses)==null?void 0:o.trigger)===!0})}function fi(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),c=JSON.stringify([...new Set(s.map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return d.useEffect(()=>{const l=JSON.parse(c).filter(p=>!a.current.has(p));if(l.length!==0){for(const p of l)a.current.add(p);Promise.all(l.map(async p=>{try{return[p,await e.getAppActions(p)]}catch{return a.current.delete(p),null}})).then(p=>{const h=p.filter(g=>g!==null);h.length!==0&&n(g=>({...g,...Object.fromEntries(h)}))})}},[e,c]),o}function hi(e,s){const[o,n]=d.useState({}),a=d.useRef(new Set),c=JSON.stringify([...new Set(s.filter(l=>l.data.step.uses.trigger===!0).map(l=>l.data.step.uses.app))].filter(l=>l&&!i.isInternalApp(l)).sort());return d.useEffect(()=>{const l=e.getAppTriggers;if(typeof l!="function")return;const p=JSON.parse(c).filter(h=>!a.current.has(h));if(p.length!==0){for(const h of p)a.current.add(h);Promise.all(p.map(async h=>{try{return[h,await l.call(e,h)]}catch{return a.current.delete(h),null}})).then(h=>{const g=h.filter(x=>x!==null);g.length!==0&&n(x=>({...x,...Object.fromEntries(g)}))})}},[e,c]),o}function mi(e){return(s,o)=>{var n,a;return(a=(n=e[s])==null?void 0:n.find(c=>c.key===o))==null?void 0:a.ports}}const wi="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function sn(e,s,o,n){const a=e.find(c=>c.id===s);return[o,n,a==null?void 0:a.source,a==null?void 0:a.target]}const ns=d.createContext(void 0),os=d.createContext(new Map),is=d.createContext({tones:new Map,loopOf:new Map});function nn(e){return`Can’t draw that edge: this node allows at most ${e} outgoing edge${e===1?"":"s"} per lane.`}const rs=d.createContext(new Map),Nn=d.createContext({byNode:new Map,subs:[]});function gi({apps:e,registration:s,children:o}){return t.jsx(rs.Provider,{value:e,children:t.jsx(Nn.Provider,{value:s,children:o})})}const as=d.createContext(null);function xi(e){return t.jsx(oe.ReactFlowProvider,{children:t.jsx(bi,{...e})})}function on(e,s){let o=s.length+1;for(;s.includes(`${e}-${o}`);)o++;return`${e}-${o}`}function qt(e){var s,o;return{x:e.position.x,y:e.position.y,w:((s=e.measured)==null?void 0:s.width)??e.width??200,h:((o=e.measured)==null?void 0:o.height)??e.height??64}}function bi({onConnectionResourcesChange:e,value:s,onChange:o,readOnly:n,height:a=480,apps:c,exprOptions:l,project:p,runState:h,stepProblems:g,onTestRun:x,fitViewKey:f,onRunFromNode:v}){var Ds,Os,_s,Ws,$s,Bs,Vs;const S=i.useW6WApi(),I=d.useMemo(()=>new Map((c??[]).map(r=>[r.id,r])),[c]),L=ki(s),[m,B]=d.useState(null),N=d.useMemo(()=>i.centralizeConnections(s),[s.id]),z=d.useMemo(()=>i.workflowToFlow(N),[N]),[H,C]=d.useState(N.connections??{}),A=d.useRef(H),R=d.useCallback(r=>{A.current=r,C(r)},[]),W=d.useCallback(r=>{const u=i.centralizeConnections({nodes:[r],connections:A.current});return u.connections!==A.current&&R(u.connections),u.nodes[0]},[R]),V=d.useMemo(()=>i.storedViewport(s),[s.id]),ee=((Ds=s.settings)==null?void 0:Ds.savePosition)!==!1,[b,$,le]=oe.useNodesState(z.nodes),de=fi(S,b),ve=hi(S,b),te=d.useMemo(()=>mi(de),[de]),[E,Z,P]=oe.useEdgesState(z.edges),[_,D]=d.useState(null),q=d.useMemo(()=>s.canvas??{},[s.id]),[O,J]=d.useState(q),[G]=d.useState(()=>new Eo(kt(N,z.nodes,z.edges,H,q))),ue=d.useRef(),[rt,at]=d.useState(0),[Be,Pe]=d.useState(!1),[ae,Se]=d.useState(null),[Re,Ye]=d.useState(null),[K,Ce]=d.useState(null),[Ve,Me]=d.useState(!1),Ne=d.useRef({});d.useEffect(()=>{Ve||(Ne.current={})},[Ve]);const[Q,pe]=d.useState(null),[Pt,He]=d.useState("props"),[Le,Fe]=d.useState(null),[De,ke]=d.useState(null),[Ee,Ae]=d.useState(null),Ze=d.useRef(!1),je=d.useRef(null),[fe,Oe]=d.useState(null),{screenToFlowPosition:me,fitView:Te}=oe.useReactFlow(),Qe=i.useEffectiveTheme();d.useEffect(()=>{$(z.nodes),Z(z.edges),D(null),Ce(null),Ae(null),pe(null),Fe(null),J(q),R(N.connections??{}),G.reset(kt(N,z.nodes,z.edges,N.connections??{},q)),ue.current=void 0},[z,q,N,$,Z,R,G]),d.useEffect(()=>{$(r=>{const u=new Map(i.stampLoopOf(r,E).map(w=>[w.id,w.data.loopOf]));return r.map(w=>{const j=Qo(h,w.id,xn(w.id,u));return w.data.stepStatus===j&&w.data.runStatus===(h==null?void 0:h.status)?w:{...w,data:{...w.data,stepStatus:j,runStatus:h==null?void 0:h.status}}})}),Z(r=>r.map(u=>{var k;const w=i.edgeLane(u),j=ei(h,u.source,w,typeof((k=u.data)==null?void 0:k.route)=="string"?u.data.route:void 0,u.target),y=i.edgeVisuals(w,j);return u.className===y.className&&u.label===y.label?u:{...u,className:y.className,label:y.label}}))},[h,z,rt,$,Z]),d.useEffect(()=>{$(r=>i.applyStepProblems(r,g))},[g,z,rt,$]);const ct=d.useCallback((r,u)=>{var y,k;const{canvas:w,...j}=r;return!((y=u.notes)!=null&&y.length)&&!((k=u.sections)!=null&&k.length)?j:{...j,canvas:po(u,s.canvas,ee)}},[s.canvas,ee]),ie=d.useCallback((r,u,w)=>{G.record(kt(s,r,u,A.current,w??O),Ve?Ne.current:ue.current),o(ct(i.flowToWorkflow({...s,connections:A.current},r,u),w??O))},[s,o,O,ct,G,Ve]),ce=d.useRef(()=>{});ce.current=r=>{if(n)return;const u=i.editConnectionResources(b.map(j=>j.data.step),A.current,r),w=b.map((j,y)=>({...j,data:{...j.data,step:u.nodes[y]}}));R(u.connections),$(w),ie(w,E)};const lt=d.useCallback(r=>ce.current(r),[]),ft=d.useCallback(r=>{D(r),Ce(null),$(u=>u.map(w=>({...w,selected:w.id===r}))),Z(u=>u.map(w=>({...w,selected:!1}))),Te({nodes:[{id:r}],duration:300,maxZoom:1})},[$,Z,Te]),[et,ht]=d.useState(null),T=d.useMemo(()=>et?b.map(r=>r.id===et?{...r,className:`${r.className??""} w6w-connection-highlight`.trim()}:r):b,[b,et]),Y=b.map(r=>({id:r.data.step.id,uses:r.data.step.uses})),ne=JSON.stringify(Y),we=JSON.stringify([...I]);d.useEffect(()=>{e==null||e({workflowId:s.id,nodes:Y,apps:I,connections:H,readOnly:n,edit:lt,focusNode:ft,highlightNode:ht})},[e,s.id,ne,we,H,n,lt,ft]),d.useEffect(()=>()=>e==null?void 0:e(null),[e]);const tt=d.useCallback(r=>i.canConnect(r.source,r.target,b,E,te,i.routeFromHandle(r.sourceHandle)),[b,E,te]),[Rt,Je]=d.useState(null),ls=d.useRef(null),Mt=d.useRef(null);d.useEffect(()=>{$(r=>i.stampLoopOf(r,E))},[E,$]);const Dn=d.useCallback(r=>{if(n)return;const u=i.applyConnect(r.source,r.target,b,E,i.laneForSourceHandle(r.sourceHandle),te,i.routeFromHandle(r.sourceHandle));if(!u){const w=i.laneForSourceHandle(r.sourceHandle),j=i.connectRefusal(r.source,r.target,b,E,w,te,i.routeFromHandle(r.sourceHandle));if(j&&j.refused==="loop"){Je({nodeId:r.source,reason:j.reason});return}if(j){const k=E.find(F=>F.source===r.source&&i.edgeLane(F)===w);k&&(Z(E.map(F=>({...F,selected:F.id===k.id}))),Ce(k.id),Ue({edgeId:k.id,message:nn(j.cap)}));return}const y=i.connectConflict(r.source,r.target,b,E,i.laneForSourceHandle(r.sourceHandle));if(!y)return;Z(E.map(k=>({...k,selected:k.id===y}))),Ce(y),Ue({edgeId:y,message:i.idClashMessage("Can’t draw that edge",y,sn(E,y,r.source,r.target))});return}Ue(null),Je(null),Z(u),ie(b,u)},[E,b,Z,ie,n,te]),On=d.useCallback((r,u)=>{var U,X,se;if(n||u.isValid)return;const w=u.fromNode;if(!w)return;const j=((U=u.fromHandle)==null?void 0:U.type)==="target"?"target":"source",y=u.toNode;if(y&&j==="source"){const re=Ho(w.id,y.id,Ys(Mt.current,w.id,u.fromHandle),b,E);if(re){Je({nodeId:w.id,reason:re});return}}const k=(X=b.find(re=>re.id===w.id))==null?void 0:X.data.step;if(k){const re=i.nodePortsForStep(k,te);if((j==="source"?re.out:re.in)<1)return}const F="changedTouches"in r?r.changedTouches[0]:r,M=me({x:F.clientX,y:F.clientY});Oe({nodeId:w.id,handleType:j,position:M,lane:Ys(Mt.current,w.id,u.fromHandle),route:i.routeFromHandle((se=u.fromHandle)==null?void 0:se.id)}),Me(!0)},[n,me,b,E,te]),ds=d.useCallback((r,u,w)=>{if(n)return;const j=b.find(U=>U.id===r);if(!j)return;const y=qt(j),k=i.laneForSourceHandle(w),F=120,M=u==="target"?{x:y.x-y.w-F,y:y.y}:k==="error"?{x:y.x,y:y.y+y.h+F}:k==="each"?{x:y.x+y.w+F,y:y.y-y.h-F/2}:{x:y.x+y.w+F,y:y.y};Oe({nodeId:r,handleType:u,position:M,lane:k,route:i.routeFromHandle(w)}),Me(!0)},[n,b]),us=d.useCallback(r=>{n||Ae({nodeIds:[r],edgeIds:[]})},[n]),_n=d.useCallback(r=>{if(n)return;const u=yo(r,b,E,O);$(u.nodes),Z(u.edges),J(u.canvas),u.nodes.some(w=>w.id===_)||D(null),u.nodes.some(w=>w.id===Q)||pe(null),u.edges.some(w=>w.id===K)||Ce(null),ie(u.nodes,u.edges,u.canvas)},[b,E,O,$,Z,ie,n,_,Q,K]),ps=d.useCallback(()=>{if(n)return;const r=Po(b,E,O);$(r.nodes),J(r.canvas),Ze.current=!0,ie(r.nodes,E,r.canvas)},[b,E,O,$,ie,n]),Wn=d.useCallback(()=>{n||ps()},[n,ps]);d.useEffect(()=>{Ze.current&&(Ze.current=!1,Te({duration:300}))},[b,Te]);const fs=d.useRef(f);d.useEffect(()=>{Object.is(fs.current,f)||(fs.current=f,Te({duration:300}))},[f,Te]);const[mt,Ue]=d.useState(null),st=d.useMemo(()=>E.find(r=>r.id===K)??null,[E,K]),$n=d.useCallback(r=>{if(n||!K)return;const u=E.find(F=>F.id===K);if(!u||i.edgeLane(u)===r)return;const w=i.edgeWhenConflict(E,K,r,b),j=i.relaneRefusal(E,K,r,b,te),y=w||j?null:i.setEdgeWhen(E,K,r,b,te);if(!y){if(j){Ue({edgeId:K,message:nn(j.cap)});return}Ue({edgeId:K,message:w?i.idClashMessage("Can’t switch this edge",w,sn(E,w,u.source,u.target)):"This edge can’t be switched right now."});return}Ue(null),Z(y);const k=y.find(F=>F.source===u.source&&F.target===u.target&&i.edgeLane(F)===r);Ce((k==null?void 0:k.id)??null),ie(b,y)},[E,b,Z,ie,n,K,te]),Bn=d.useCallback(r=>{if(n)return;const u=E.filter(w=>w.id!==r);u.length!==E.length&&(Z(u),K===r&&Ce(null),ie(b,u))},[b,E,Z,ie,n,K]),Lt=d.useCallback(r=>{if(n)return;const u=r.map(k=>b.find(F=>F.id===k)).filter(k=>k!==void 0);if(u.length===0)return;const w=b.map(k=>k.id),j=u.map(k=>{const F=i.suggestStepId(w,`${k.data.step.id}_copy`);w.push(F);const M={...i.stripBody(structuredClone(k.data.step)),id:F};return{id:F,type:k.type,position:{x:k.position.x+40,y:k.position.y+60},data:{step:M,isInternal:k.data.isInternal},...u.length>1?{selected:!0}:{}}}),y=[...u.length>1?b.map(k=>k.selected?{...k,selected:!1}:k):b,...j];$(y),D(j[0].id),ie(y,E)},[b,E,$,ie,n]),hs=d.useCallback(r=>Lt([r]),[Lt]),Vn=d.useCallback(r=>{if(n)return;const u=i.isInternalApp(r.uses.app),w=b.map(se=>se.id),j=r.id&&!i.stepNameError(r.id,w)?r.id:i.suggestStepId(w,i.slugifyLabel(i.internalNodeLabel(r.uses.app,r.uses.action))),y=W({id:j,uses:r.uses,...r.with&&Object.keys(r.with).length>0?{with:r.with}:{}}),k={id:j,type:u?"control":"step",position:(fe==null?void 0:fe.position)??(De==null?void 0:De.position)??{x:80,y:80+b.length*24},data:{step:y,isInternal:u}},F=[...b,k];let M=E,U=null;const X=(se,re,he,We)=>{const ot=i.connectRefusal(se,re,F,E,he,te);ot&&ot.refused==="loop"&&(U={nodeId:We,reason:ot.reason})};if(fe){const[se,re]=fe.handleType==="target"?[j,fe.nodeId]:[fe.nodeId,j],he=i.applyConnect(se,re,F,E,fe.lane,te,fe.route);he||X(se,re,fe.lane,fe.nodeId),M=he??E}else{const se=b.find(re=>i.isTriggerStep(re.data.step.uses));if(i.isTriggerStep(r.uses)){if(!se){const re=i.findChainRoot(b,E);if(re){const he=i.applyConnect(j,re.id,F,E,"success",te);he||X(j,re.id,"success",re.id),M=he??E}}}else{const he=(se&&!E.some(We=>We.source===se.id)?se:void 0)??i.findChainTail(b,E);if(he){const We=i.applyConnect(he.id,j,F,E,"success",te);We||X(he.id,j,"success",he.id),M=We??E}}}return $(F),M!==E&&Z(M),Je(U),D(j),ie(F,M),j},[b,E,$,Z,ie,n,fe,De,te,W]),ms=d.useCallback((r,u)=>{var U;let w=u;const j=(U=b.find(X=>X.id===r))==null?void 0:U.data.step;if(u.uses.connection&&!u.uses.connectionRef&&(j!=null&&j.uses.connectionRef)&&j.uses.app===u.uses.app){const X=i.selectNodeConnection(i.withConnectionRef(u,j.uses.connectionRef),u.uses.connection,b.map(se=>se.data.step),A.current);R(X.connections),w=X.step}else w=W(u);const y=w.id!==r;if(y&&b.some(X=>X.id===w.id))return;const k=b.map(X=>X.id===r?{...X,id:w.id,data:{step:w,isInternal:i.isInternalApp(w.uses.app)}}:X);if(y){const X=i.renameStepInEdges(E,r,w.id),se=hn(O,r,w.id);$(k),Z(X),J(se),_===r&&D(w.id),Q===r&&pe(w.id),ie(k,X,se);return}$(k);const F=new Set(i.routesForStep(w).map(X=>X.id)),M=E.filter(X=>{var se;return X.source!==w.id||((se=X.data)==null?void 0:se.route)===void 0||F.has(String(X.data.route))});M.length!==E.length&&Z(M),ie(k,M)},[b,E,O,$,Z,_,Q,ie,W,R]),qe=d.useCallback(r=>{n||(J(r),ie(b,E,r))},[n,b,E,ie]),zn=d.useCallback(()=>{var y;if(n)return;const r=(y=je.current)==null?void 0:y.getBoundingClientRect(),u=r?me({x:r.left+r.width/2,y:r.top+r.height/2}):{x:0,y:0},w=O.notes??[],j={id:on("note",w.map(k=>k.id)),color:"#facc15",position:{x:Math.round(u.x-100),y:Math.round(u.y-60)},size:{width:200,height:120},content:""};qe(Xt({...O,notes:[...w,j]}))},[n,O,me,qe]),Hn=d.useCallback((r,u)=>{if(n)return;const w=u?Math.min(r.x,u.x):r.x,j=u?Math.min(r.y,u.y):r.y,y=u?Math.abs(u.x-r.x):360,k=u?Math.abs(u.y-r.y):240,F=b.filter(re=>{const he=qt(re),We=he.x+he.w/2,ot=he.y+he.h/2;return We>=w&&We<=w+y&&ot>=j&&ot<=j+k}).map(re=>re.id),M=O.sections??[],U=on("section",M.map(re=>re.id)),X={id:U,title:"Section",color:"#6366f1",position:{x:Math.round(w),y:Math.round(j)},size:{width:Math.round(y),height:Math.round(k)},nodes:[]},se={...O,sections:[...M,X]};qe(Xt(Kt(se,U,F)))},[n,b,O,qe]);d.useEffect(()=>{if(!Be)return;const r=u=>{u.key==="Escape"&&(Pe(!1),Se(null))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Be]);const Jn=d.useCallback((r,u)=>{var F;if(n)return;const w=(F=O.sections)==null?void 0:F.find(M=>M.id===r);if(!w)return;const j=new Set(w.nodes),y=b.map(M=>j.has(M.id)?{...M,position:{x:M.position.x+u.dx,y:M.position.y+u.dy}}:M),k={...O,sections:(O.sections??[]).map(M=>M.id===r?{...M,position:{x:M.position.x+u.dx,y:M.position.y+u.dy}}:M)};$(y),J(k),ie(y,E,k)},[n,O,b,E,$,ie]),Un=d.useCallback((r,u)=>{if(n)return;const w=r==="note"?{...O,notes:(O.notes??[]).filter(j=>j.id!==u)}:{...O,sections:(O.sections??[]).filter(j=>j.id!==u)};qe(w)},[n,O,qe]),qn=r=>{let u=O;for(const w of r){const j=qt(w),y=j.x+j.w/2,k=j.y+j.h/2,F=(u.sections??[]).find(U=>y>=U.position.x&&y<=U.position.x+U.size.width&&k>=U.position.y&&k<=U.position.y+U.size.height),M=mn(u,w.id);F?(M.length!==1||M[0]!==F.id)&&(u=Kt(u,F.id,[w.id])):M.length>0&&(u=ts(u,w.id))}return u},Ft=d.useCallback((r,u,w)=>{(async()=>{const j=await S.saveStepTest(s.id,r,u).catch(y=>(console.error("step run fixture save failed",y),null));await S.recordStepTestRun(s.id,r,{stepTestId:(j==null?void 0:j.id)??null,status:w.status,input:u.input,output:w.output,error:w.error,...w.meta?{meta:w.meta}:{}})})().catch(j=>{console.error("step run persist failed",j)})},[S,s.id]),ws=d.useCallback(r=>{const u=b.find(w=>w.id===r);!u||!v&&i.isControlApp(u.data.step.uses.app)||B({stepId:r,status:"collect"})},[b,v]),Gn=d.useCallback(async(r,u,w)=>{if(!v)return;const j=b.find(F=>F.id===r);if(!j)return;const y=i.isTriggerStep(j.data.step.uses),k={stopAt:Zt(b.map(F=>F.data.step),r),...w?{state:w}:{},...y?{input:u}:{}};B({stepId:r,status:"running"});try{await v(r,k),B(null)}catch(F){const M=F;B({stepId:r,status:"error",error:M.message??String(F),errorCode:M.code})}},[b,v]),wt=d.useCallback((r,u)=>{if(n)return;const w=b.map(j=>j.id===r?{...j,data:{...j.data,step:u(j.data.step)}}:j);$(w),ie(w,E)},[b,E,$,ie,n]),gs=d.useCallback(r=>wt(r,u=>bn(u,!Xe(u))),[wt]),xs=d.useCallback(r=>wt(r,u=>jn(u,!Ie(u))),[wt]),Kn=d.useCallback(async(r,u,w)=>{x==null||x();const j=b.find(U=>U.id===r);if(!j)return;const y=j.data.step,k=i.isTriggerStep(y.uses),F=k?{input:u}:{...y.with??{},...u},M=k?{input:u,with:u}:{input:u,with:F};B({stepId:r,status:"running"});try{const U=await S.invokeAction(y.uses.app,y.uses.action,F,{connectionId:i.connectionIdFor(y,A.current),project:p,...w?{state:w}:{},workflowId:s.id}),X=U.logs,se=U.meta;B({stepId:r,status:"done",value:U.value,logs:X,...se?{meta:se}:{}}),Ft(r,M,{status:"succeeded",output:U.value,...se?{meta:se}:{}})}catch(U){const X=U;B({stepId:r,status:"error",error:X.message??String(U),errorCode:X.code}),Ft(r,M,{status:"failed",error:X.message??String(U)})}},[b,S,Ft,p,x,s.id]),Dt=d.useMemo(()=>({onEdit:r=>{He("props"),pe(r)},onEditJson:r=>{He("json"),pe(r)},onRun:ws,onDuplicate:hs,onDelete:us,onTogglePause:gs,onToggleDisable:xs,runsFromNode:!!v,onAddFromPort:ds,readOnly:n}),[ws,hs,us,gs,xs,v,ds,n]);d.useEffect(()=>{const r=je.current;if(!r)return;const u=w=>{const j=w.target.closest(".react-flow__node");if(!j)return;const y=j.getAttribute("data-id");y&&(w.stopPropagation(),Dt.onEdit(y))};return r.addEventListener("dblclick",u,!0),()=>r.removeEventListener("dblclick",u,!0)},[Dt]);const nt=b.find(r=>r.id===Q),gt=(nt==null?void 0:nt.data.step)??null,Ot=m?((Os=b.find(r=>r.id===m.stepId))==null?void 0:Os.data.step)??null:null,_t=(m==null?void 0:m.status)==="collect"&&!!Ot,bs=d.useMemo(()=>{const r=new Map;for(const u of b)r.set(u.id,So(u.id,E).count);return r},[b,E]),js=Do(b),xt=d.useMemo(()=>Oo(js),[js]),Xn=d.useMemo(()=>Lo(E,xt.tones,xt.loopOf),[E,xt]),Yn=d.useMemo(()=>({step:Ai,control:Ti}),[]),[bt,ys]=d.useState({}),[jt,vs]=d.useState({}),[Ss,Cs]=d.useState({}),[yt,Ns]=d.useState({}),[ze,vt]=d.useState(null),[ks,Es]=d.useState([]),Zn=Q??ze??"";d.useEffect(()=>{const r=S.loadNodeSamples;if(typeof r!="function"||!s.id){Es([]);return}let u=!1;return r(s.id).then(w=>{u||Es(Array.isArray(w)?w:[])},()=>{}),()=>{u=!0}},[S,s.id,Zn]);const St=d.useMemo(()=>i.indexNodeSamples(ks),[ks]),Wt=d.useMemo(()=>i.splitNodeOutputs(bt,St,yt),[bt,St,yt]),_e=d.useMemo(()=>i.splitPreviewOutputs(bt,St,yt),[bt,St,yt]),xe=d.useMemo(()=>({actionDef:(r,u)=>{var w;return(w=de[r])==null?void 0:w.find(j=>j.key===u)},triggerDef:(r,u)=>{var w;return(w=ve[r])==null?void 0:w.find(j=>j.key===u)},testOutputs:Wt.fresh,persistedOutputs:Wt.persisted,loopSamples:Ss}),[de,ve,Wt,Ss]),Ge=d.useMemo(()=>m?i.upstreamStateSources(m.stepId,b,E,xe):void 0,[m,b,E,xe]),Qn=d.useMemo(()=>(Ge==null?void 0:Ge.steps)??[],[Ge]),ge=d.useMemo(()=>{const r=i.upstreamStateSources(Q,b,E,xe,ze);return{...r,steps:i.excludeSelfStep(r.steps,Q??ze)}},[Q,ze,b,E,xe]),$t=d.useMemo(()=>ai({anchorId:Q??ze,nodes:b,edges:E,initialState:s.initialState,variables:s.variables,shapes:xe,previewOutputs:{..._e.persisted,..._e.fresh}}),[Q,ze,b,E,s.initialState,s.variables,xe,_e]),As=JSON.stringify([...ge.steps.map(r=>r.id),...ge.extraSampleIds??[]]);d.useEffect(()=>{const r=JSON.parse(As);if(!Q&&!ze||r.length===0){ys({}),vs({}),Cs({}),Ns({});return}let u=!1;return Promise.all(r.map(async w=>{try{const j=await S.listStepTests(s.id,w),y=j.length?j[j.length-1]:null;return y?{id:w,output:y.lastRunOutput,runAt:y.lastRunAt,meta:y.lastRunMeta,loopSample:i.foreachTestSample(y)}:null}catch{return null}})).then(w=>{if(u)return;const j={},y={},k={},F={};for(const M of w)M!=null&&M.meta&&(y[M.id]=M.meta),M!=null&&M.loopSample&&(k[M.id]=M.loopSample),!(!M||M.output===void 0||M.output===null)&&(j[M.id]=M.output,F[M.id]=M.runAt);ys(j),Ns(F),vs(y),Cs(k)}),()=>{u=!0}},[S,s.id,Q,ze,As]);const Bt=d.useMemo(()=>i.declaredSamples(b,xe),[b,xe]),Ct=d.useMemo(()=>({persisted:_e.persisted,samples:Bt.samples,event:Bt.event}),[_e.persisted,Bt]),Ts=d.useMemo(()=>i.upstreamSampleValues(ge.steps,_e.fresh,jt,ge.loop,Ct),[ge.steps,ge.loop,_e.fresh,jt,Ct]),Is=d.useMemo(()=>i.upstreamSampleValueSources(ge.steps,_e.fresh,jt,ge.loop,Ct),[ge.steps,ge.loop,_e.fresh,jt,Ct]),Ps=i.useExpressionOptions(),Rs=d.useMemo(()=>i.nodeConfigSources(b),[b]),Ms=d.useMemo(()=>i.nodeConfigValues(b,L.subs),[b,L.subs]),Vt=d.useMemo(()=>i.nodeMetaValues(b,L.subs,I,H),[b,L.subs,I,H]),zt=d.useMemo(()=>({...l??{},steps:ge.steps,hasTrigger:ge.hasTrigger,eventOutputs:ge.eventOutputs,eventOutputsFrom:ge.eventOutputsFrom,loop:ge.loop,stateShape:{fields:$t.fields},nodeConfigs:Rs,nodeConfig:Ms,nodeMeta:Vt,valueSources:Is,sampleValues:{...Ps.sampleValues??{},...(l==null?void 0:l.sampleValues)??{},...i.nodeMetaSampleValues(Vt),...Ts,...$t.sampleValues}}),[l,Ps.sampleValues,ge,$t,Ts,Is,Rs,Ms,Vt]),Ls=r=>{var y;if(n)return;const u=G[r]();if(!u)return;const w=ko(s,u);$(w.nodes.map(k=>({...k,selected:k.id===_}))),Z(w.edges.map(k=>({...k,selected:k.id===K}))),J(u.canvas),R(u.connections),w.nodes.some(k=>k.id===_)||D(null),w.edges.some(k=>k.id===K)||Ce(null);const j=w.nodes.some(k=>k.id===Q);j||pe(null),Me(!1),vt(null),Oe(null),Ae(null),Ye(null),ke(null),Fe(null),Je(null),Ue(null),ue.current=void 0,at(k=>k+1),o(ct(i.flowToWorkflow({...s,nodes:u.nodes,connections:u.connections},w.nodes,w.edges),u.canvas)),!j&&!m&&((y=je.current)==null||y.focus({preventScroll:!0}))},Fs=d.useRef(Ls);Fs.current=Ls,d.useEffect(()=>{const r=je.current;if(!r)return;let u=r.contains(document.activeElement);const w=y=>{y.type==="focusin"&&y.target===document.body||(u=r.contains(y.target))},j=y=>{if(n||y.defaultPrevented||Ht(y.target)||!r.contains(y.target)&&!(u&&y.target===document.body))return;const k=y.key.toLowerCase();!(y.ctrlKey||y.metaKey)||y.altKey||k!=="z"&&!(k==="y"&&!y.shiftKey)||(y.preventDefault(),Fs.current(k==="y"||y.shiftKey?"redo":"undo"))};return document.addEventListener("pointerdown",w),document.addEventListener("focusin",w),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",w),document.removeEventListener("focusin",w),document.removeEventListener("keydown",j)}},[n]);const Nt=d.useCallback((r,u)=>{var M;if(Ht(r.target))return;const w=(M=je.current)==null?void 0:M.getBoundingClientRect();if(!w)return;r.preventDefault();const j=qs(b,E),y=j.nodeIds,k=ro(y,u),F=u!==void 0&&!y.includes(u);F&&$(b.map(U=>U.selected!==(U.id===u)?{...U,selected:U.id===u}:U)),Fe({x:r.clientX-w.left,y:r.clientY-w.top,flow:me({x:r.clientX,y:r.clientY}),nodeIds:k,edgeIds:F?[]:j.edgeIds})},[b,E,$,me]),eo=d.useCallback(r=>{var u;Fe(null),r&&((u=je.current)==null||u.focus({preventScroll:!0}))},[]),to=r=>{const u=Le;!u||n||(r==="duplicate"?Lt(u.nodeIds):r==="delete"?Ae({nodeIds:u.nodeIds,edgeIds:u.edgeIds}):(Oe(null),ke({position:u.flow,...r==="add-trigger"?{tab:"triggers"}:{}}),Me(!0)))},so=t.jsx(as.Provider,{value:Dt,children:t.jsx(ns.Provider,{value:te,children:t.jsx(os.Provider,{value:bs,children:t.jsx(is.Provider,{value:xt,children:t.jsx(gi,{apps:I,registration:L,children:t.jsx(i.WorkflowProjectProvider,{project:p,workflowId:s.id,children:t.jsx(i.ExpressionOptionsProvider,{value:zt,children:t.jsxs("section",{ref:je,className:"w6w-flow",tabIndex:-1,"aria-label":"Workflow editor",style:{width:"100%",height:a,position:"relative"},onFocusCapture:r=>{ue.current=Ht(r.target)?{}:void 0},onBlurCapture:()=>{ue.current=void 0},onKeyDown:r=>{if(r.defaultPrevented||r.key!=="Backspace"&&r.key!=="Delete"||n||Q||Ve||Ee)return;const u=r.target;if(u.isContentEditable||u.tagName==="INPUT"||u.tagName==="TEXTAREA"||u.tagName==="SELECT"||u.closest("dialog, .w6w-modal")!==null)return;const w=qs(b,E);!w.nodeIds.length&&!w.edgeIds.length||(r.preventDefault(),!w.nodeIds.length&&w.edgeIds.length===1?Bn(w.edgeIds[0]):Ae(w))},children:[t.jsxs(oe.ReactFlow,{nodes:T,edges:Xn,minZoom:.05,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:oe.ConnectionLineType.SmoothStep,onNodesChange:le,onEdgesChange:P,onConnect:Dn,onConnectStart:(r,u)=>{Mt.current=u},onConnectEnd:On,onPaneClick:()=>Je(null),onPaneContextMenu:r=>Nt(r),onNodeContextMenu:(r,u)=>Nt(r,u.id),onEdgeContextMenu:r=>Nt(r),onSelectionContextMenu:r=>Nt(r),onMoveStart:()=>Fe(null),isValidConnection:tt,onNodeDragStop:(r,u,w)=>{const j=qn(w),y=j!==O;if(y&&J(j),!ee&&!y){G.record(kt(s,b,E,A.current,j));return}ie(b,E,j)},onMoveEnd:(r,u)=>{if(!r||n)return;const w=i.flowToWorkflow(s,b,E),j=i.withViewport(w,u);j!==w&&o(j,{viewportOnly:!0})},onSelectionChange:({nodes:r,edges:u})=>{var w,j,y,k;D(((w=r[0])==null?void 0:w.id)??null),Ce(((j=u[0])==null?void 0:j.id)??null),ls.current!==(((y=r[0])==null?void 0:y.id)??null)&&(ls.current=((k=r[0])==null?void 0:k.id)??null,Je(null))},nodeTypes:Yn,nodesDraggable:!n,nodesConnectable:!n,connectOnClick:!1,elementsSelectable:!0,...V?{defaultViewport:V}:{fitView:!0},deleteKeyCode:null,colorMode:Qe,proOptions:{hideAttribution:!0},children:[t.jsx(oe.Background,{gap:16}),t.jsx(oe.Controls,{showInteractive:!1,children:!n&&t.jsx(oe.ControlButton,{onClick:Wn,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:t.jsx(ye.Icon,{name:"layout"})})}),t.jsx(oe.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!n&&t.jsxs(oe.Panel,{position:"top-left",className:"w6w-flow-tools",children:[t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>Me(!0),children:"+ Node"}),t.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:zn}),t.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${Be?" active":""}`,"aria-pressed":Be,"data-testid":"draw-section",onClick:()=>{Pe(!Be),Se(null)}})]}),!n&&Be&&t.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:r=>{if(r.button!==0)return;r.currentTarget.setPointerCapture(r.pointerId);const{clientX:u,clientY:w}=r;Se({sx:u,sy:w,ex:u,ey:w})},onPointerMove:r=>{const{clientX:u,clientY:w}=r;Se(j=>j&&{...j,ex:u,ey:w})},onPointerUp:()=>{const r=ae;if(Se(null),Pe(!1),!r)return;const u=me({x:r.sx,y:r.sy}),w=Math.abs(r.ex-r.sx)>6||Math.abs(r.ey-r.sy)>6;Hn(u,w?me({x:r.ex,y:r.ey}):null)},children:ae&&(()=>{var j;const r=(j=je.current)==null?void 0:j.getBoundingClientRect(),u=(r==null?void 0:r.left)??0,w=(r==null?void 0:r.top)??0;return t.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(ae.sx,ae.ex)-u,top:Math.min(ae.sy,ae.ey)-w,width:Math.abs(ae.ex-ae.sx),height:Math.abs(ae.ey-ae.sy)}})})()}),!n&&st&&i.edgeLane(st)!=="each"&&((_s=b.find(r=>r.id===st.source))==null?void 0:_s.data.step.uses.app)!==i.ROUTER_APP&&t.jsx(oe.Panel,{position:"top-right",children:t.jsxs("div",{className:"w6w-edge-lane",children:[t.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(r=>t.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${i.edgeLane(st)===r?" active":""}`,"aria-pressed":i.edgeLane(st)===r,title:wi,onClick:()=>$n(r),children:r==="success"?"Success":"Error"},r)),(mt==null?void 0:mt.edgeId)===st.id&&t.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:mt.message})]})}),Rt&&t.jsx(oe.NodeToolbar,{nodeId:Rt.nodeId,position:oe.Position.Bottom,isVisible:!0,children:t.jsx("div",{className:"w6w-loop-notice w6w-small",role:"alert",children:i.loopRefusalMessage(Rt.reason)})}),t.jsx(i.CanvasLayer,{canvas:O,readOnly:n,savePosition:ee,onChange:qe,onSectionDrop:Jn,onRequestDelete:(r,u)=>!n&&Ye({kind:r,id:u})})]}),Re&&t.jsx(i.ConfirmModal,{title:Re.kind==="note"?"Delete note":"Delete section",message:Re.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Un(Re.kind,Re.id),Ye(null)},onClose:()=>Ye(null)}),Ve&&t.jsx(i.StepBuilderModal,{initialTab:De==null?void 0:De.tab,onClose:()=>{Me(!1),Oe(null),ke(null),vt(null)},onAdd:r=>{const u=Vn(r);return u&&vt(u),u},onDraftChange:(r,u)=>ms(r,{id:r,...u}),stepIds:b.map(r=>r.id),onOpenStep:r=>{Me(!1),Oe(null),ke(null),vt(null),He("props"),pe(r)},workflowId:s.id,upstreamSteps:i.stepBuilderUpstreamSteps(fe,b,E),loop:i.stepBuilderLoop(fe,b,E,xe)}),gt&&Q&&t.jsx(Pi,{workflowId:s.id,step:gt,restoreVersion:rt,upstreamSteps:zt.steps??[],loop:zt.loop,readOnly:n,fanOutCount:bs.get(Q)??0,stateOutputFields:(Vs=i.resolveOutputShape((Ws=xe.actionDef)==null?void 0:Ws.call(xe,gt.uses.app,gt.uses.action),($s=xe.testOutputs)==null?void 0:$s[Q],(Bs=xe.persistedOutputs)==null?void 0:Bs[Q]))==null?void 0:Vs.fields.map(r=>r.key),initialView:Pt,stepProblems:nt==null?void 0:nt.data.stepProblems,otherStepIds:b.filter(r=>r.id!==Q).map(r=>r.id),onChange:r=>ms(Q,r),onClose:()=>pe(null),onTestRun:x}),m&&t.jsxs(i.Modal,{title:`${_t?"Run node":"Test run"}: ${m.stepId}`,onClose:()=>B(null),children:[_t&&Ot&&t.jsx(Si,{workflowId:s.id,step:Ot,upstreamSteps:Qn,loop:Ge==null?void 0:Ge.loop,continues:v?{stopAt:Zt(b.map(r=>r.data.step),m.stepId)}:void 0,onCancel:()=>B(null),onRun:(r,u)=>v?Gn(m.stepId,r,u):Kn(m.stepId,r,u)},m.stepId),!_t&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-modal-body",children:[m.status==="running"&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),m.status==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[m.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:m.errorCode})}),m.error||"The node failed with no error message."]}),m.status==="done"&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),t.jsx(i.ResultViewer,{value:m.value,maxHeight:360}),m.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),t.jsx(i.ResultViewer,{value:m.meta,maxHeight:360})]})]}),m.logs&&m.logs.length>0&&t.jsxs("div",{children:[t.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:m.logs.join(`
2
+ `)})]})]}),t.jsx("div",{className:"w6w-modal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>B(null),children:"Close"})})]})]}),Ee!==null&&t.jsx(i.ConfirmModal,{title:Ee.nodeIds.length===1?"Delete node":Ee.nodeIds.length>1?`Delete ${Ee.nodeIds.length} nodes`:`Delete ${Ee.edgeIds.length} connections`,message:vo(Ee,b,E),confirmLabel:"Delete",onConfirm:()=>{_n(Ee),Ae(null)},onClose:()=>Ae(null)}),Le&&t.jsx(io,{x:Le.x,y:Le.y,items:ao(Le.nodeIds,!!n),onAction:to,onClose:eo})]})})})})})})})});return t.jsx(i.WorkflowConnectionsContext.Provider,{value:{nodes:b.map(r=>r.data.step),connections:H,setConnections:R,readOnly:n},children:so})}const ji=["code"];function It(e){try{const s=JSON.parse(e);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function yi(e){try{const s=JSON.parse(e);if(Array.isArray(s))return{items:s}}catch{return null}return It(e)}function vi({items:e,save:s}){if(!e)return t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:[t.jsx("strong",{children:"Items"})," doesn't resolve to a list yet: no step before this one has a saved test that produces it. Test an earlier step, or paste a sample list under"," ",t.jsx("strong",{children:"Override the incoming state"})," below."]});const o=e[0],n=o!==void 0?(i.inferOutputFields(o)??[]).map(a=>a.key):[];return t.jsxs("div",{className:"w6w-testout",children:[t.jsxs("div",{className:"w6w-testout-label",children:[e.length," ",e.length===1?"item":"items"]}),e.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"The list is empty, so there is no item to sample."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-testout-label",children:"First item"}),t.jsx(i.ResultViewer,{value:o,maxHeight:220})]}),s==="saved"&&t.jsxs("output",{className:"w6w-small",style:{display:"block"},children:["Saved as this loop's sample.",n.length>0&&t.jsxs(t.Fragment,{children:[" ","Steps on ",t.jsx("strong",{children:"Each item"})," now offer ",t.jsx("strong",{children:"Current item"})," ›"," ",n.map((a,c)=>t.jsxs("span",{children:[c>0&&", ",t.jsx("code",{children:a})]},a)),"."]})]}),s==="failed"&&t.jsx("p",{className:"w6w-small",role:"alert",children:"Couldn't save the sample. Try Test again."})]})}function kn(e){const[s,o]=d.useState(null),[n,a]=d.useState("0"),c=s??i.loopItemText(e),l=e?i.parseLoopSeed(c,n):void 0;return{active:!!e,itemText:c,indexText:n,setItemText:o,setIndexText:a,parsed:l}}function En(e){var s;return(s=e.parsed)!=null&&s.ok?e.parsed.value:void 0}function cs(e){return e.parsed&&!e.parsed.ok?e.parsed.error:null}function An({seed:e,readOnly:s}){if(!e.active)return null;const o=cs(e);return t.jsxs("div",{className:"w6w-field w6w-loop-seed",children:[t.jsx("span",{children:"Current item"}),t.jsx("textarea",{rows:3,value:e.itemText,readOnly:s,spellCheck:!1,"aria-label":"Current item",onChange:n=>e.setItemText(n.target.value)}),t.jsx("span",{children:"Index"}),t.jsx("input",{type:"text",inputMode:"numeric",value:e.indexText,readOnly:s,"aria-label":"Index",onChange:n=>e.setIndexText(n.target.value)}),t.jsx("span",{className:"w6w-hint",children:"This step runs once per item of the For each. Test it as one iteration — starting from the sample item, or edit it."}),o&&t.jsx("span",{className:"w6w-hint",role:"alert",children:o})]})}function es({text:e,onChange:s,seeds:o,readOnly:n,expand:a,hint:c}){const l=It(e),p=l?Object.keys(l).length:0,h=p>0,[g,x]=d.useState(h);d.useEffect(()=>{(h||a)&&x(!0)},[h,a]);const f=v=>{s(JSON.stringify(v.lastRunOutput??v.input??{},null,2)),x(!0)};return t.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[t.jsx("span",{children:"Incoming state"}),o.length>0&&t.jsx("div",{className:"w6w-seed-picker",children:t.jsx("div",{className:"w6w-seed-chips",children:o.map(v=>t.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${v.label}'s saved test as the incoming state`,disabled:n,onClick:()=>f(v.test),children:[t.jsx("code",{children:v.label}),v.test.lastRunStatus?t.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",v.test.lastRunStatus]}):null]},v.stepId))})}),t.jsxs("details",{className:"w6w-state-override",open:g,onToggle:v=>x(v.currentTarget.open),children:[t.jsxs("summary",{children:["Override the incoming state",p>0?` · ${p} key${p===1?"":"s"} set`:""]}),t.jsx("textarea",{rows:3,value:e,readOnly:n,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:v=>s(v.target.value)}),t.jsx("span",{className:"w6w-hint",children:c??t.jsxs(t.Fragment,{children:["JSON whose keys replace this step's parameters by name, for this test only — so a script's data goes under ",t.jsx("code",{children:"input"}),": ",t.jsx("code",{children:'{"input": {…}}'}),". Upstream outputs already reach ",t.jsx("code",{children:"{{ nodes.<id>.output }}"})," bindings from their saved tests. Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})})]})]})}function Si({workflowId:e,step:s,upstreamSteps:o,loop:n,onRun:a,onCancel:c,continues:l}){const p=i.useW6WApi(),h=i.isTriggerStep(s.uses),g=i.isInternalApp(s.uses.app),x=d.useMemo(()=>{var D;return h?i.asFieldDefs((D=s.with)==null?void 0:D.fields):[]},[h,s.with]),f=d.useMemo(()=>h?i.fieldsToParams(x):g?i.internalNodeParams(s.uses.app,s.uses.action):null,[h,g,x,s.uses.app,s.uses.action]),[v,S]=d.useState(null),I=f??v;d.useEffect(()=>{if(f)return;if(!s.uses.app||!s.uses.action){S([]);return}let D=!1;return S(null),p.getAppActions(s.uses.app).then(q=>{var O;D||S(((O=q.find(J=>J.key===s.uses.action))==null?void 0:O.params)??[])}).catch(()=>!D&&S([])),()=>{D=!0}},[p,f,s.uses.app,s.uses.action]);const[L,m]=d.useState(()=>{var D;return h?i.seedValues(i.asFieldDefs((D=s.with)==null?void 0:D.fields)):{}}),[B,N]=d.useState("{}"),z=i.useSeedSources(e,o,!h),H=kn(n),C=i.startStateFromSeeds(z,En(H)),A=i.useRememberedTestInput(e,s.id),[R,W]=d.useState(!1),[V,ee]=d.useState(!1);d.useEffect(()=>{if(!A.loaded)return;let D=!1;const q=(O,J)=>{O&&Object.keys(O).length>0&&(h?m(G=>({...G,...O})):N(JSON.stringify(O,null,2)),J&&ee(!0)),W(!0)};if(A.input!==void 0){q(A.input,!0);return}return p.listStepTests(e,s.id).then(O=>{if(D)return;const J=O.length?O[O.length-1]:null;q(h?J==null?void 0:J.with:J==null?void 0:J.input,!1)}).catch(()=>{D||W(!0)}),()=>{D=!0}},[p,e,s.id,h,A.loaded]);const[b,$]=d.useState(0),le=()=>{A.clear(),ee(!1),h?m(i.seedValues(x)):N("{}"),$(D=>D+1)},[de,ve]=d.useState(!0),te=It(B),E=h?de:te!==null,Z=h?L:{...s.with??{},...te??{}},P=h?null:cs(H),_=!!I&&R&&E&&!P&&i.requiredParamsFilled(I,Z);return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[l&&t.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"run-from-node-hint",children:["Runs this node, then continues through every node after it",l.stopAt.length>0?t.jsxs(t.Fragment,{children:[" ","and stops before"," ",l.stopAt.length===1?"the paused node":"paused nodes"," ",l.stopAt.map((D,q)=>t.jsxs("span",{children:[q>0?", ":"",t.jsx("code",{children:D})]},D))]}):null,". Disabled nodes are skipped."]}),V&&I!==null&&R&&t.jsx(i.LastUsedNote,{onClear:le}),I===null||!R?t.jsx("p",{className:"w6w-muted w6w-small",children:I===null?"Loading parameters…":"Loading saved values…"}):h?t.jsxs(t.Fragment,{children:[t.jsx(i.PropertyEntryForm,{params:I,values:L,onChange:m,onValidityChange:ve},b),I.length===0&&t.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",t.jsx("code",{children:"input"}),")."]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",t.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),t.jsx(An,{seed:H}),t.jsx(es,{text:B,onChange:N,seeds:z})]})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:c,children:"Cancel"}),!_&&I!==null&&R&&t.jsx("span",{className:"w6w-muted w6w-small",children:P?`${P} Fix it to run.`:E?h?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":h?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:!_,onClick:()=>{A.save(h?L:te??{},I??[]),a(h?L:te??{},h?void 0:C)},children:"▶ Run"})]})]})}function Ci(e){return e.uses.app===i.CONTROL_APP&&e.uses.action==="foreach"}function Tn({id:e}){const{tones:s,loopOf:o}=d.useContext(is),n=xn(e,o);return n.length===0?null:t.jsx("span",{className:"w6w-loop-dots",children:n.map(a=>t.jsx("span",{className:"w6w-loop-dot",role:"img","aria-label":`In loop · ${a}`,title:`In loop · ${a}`,style:{background:ss(s.get(a)??1)}},a))})}function In(e){return Fo(e,d.useContext(is).tones)}function $e({type:e,position:s,multiple:o,id:n,variant:a,top:c,routeLabel:l}){const p=oe.useNodeId(),h=d.useContext(as),g=!!p&&!!h&&!h.readOnly,x=()=>{g&&p&&h.onAddFromPort(p,e,n)},f=a==="error"?"a step that handles this step's failure":a==="each"?"the first step of this loop's body":e==="target"?"a step before this one":"the next step";return t.jsx(oe.Handle,{type:e,position:s,id:n,className:a==="error"?"w6w-handle-error":a==="each"?"w6w-handle-each":o?"w6w-handle-multi":void 0,style:{...o?{height:22,borderRadius:3,width:8}:{},...c?{top:c}:{}},onClick:g?x:void 0,title:l?`${l} — drag or click to connect`:g?`Drag to empty canvas (or click) to add ${f} · drag to a port to connect`:a==="error"?"On error — drag to route this step's failure separately":a==="each"?"Each item — drag to the first step to repeat for every item":o?e==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Pn({id:e,step:s,runnable:o}){const n=d.useContext(as);if(!n||n.readOnly)return null;const a=o||n.runsFromNode,c=n.runsFromNode?"Run from this node — continues through the nodes after it":"Test-run this node",l=Xe(s),p=Ie(s);return t.jsxs(oe.NodeToolbar,{position:oe.Position.Top,className:"w6w-node-toolbar",children:[a&&t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:c,"aria-label":c,onClick:()=>n.onRun(e),children:t.jsx(ye.Icon,{name:"run",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-pause-toggle","aria-pressed":l,title:l?"Resume — test runs go through this node":"Pause — test runs stop before this node","aria-label":l?"Unpause node":"Pause node",onClick:()=>n.onTogglePause(e),children:t.jsx(ye.Icon,{name:"pause",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn","data-testid":"node-disable-toggle","aria-pressed":p,title:p?"Enable — this node runs again":"Disable — skip this node in every run","aria-label":p?"Enable node":"Disable node",onClick:()=>n.onToggleDisable(e),children:t.jsx(ye.Icon,{name:"ban",size:15})}),t.jsx("span",{className:"w6w-node-toolbar-divider","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>n.onEdit(e),children:t.jsx(ye.Icon,{name:"edit",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>n.onDuplicate(e),children:t.jsx(ye.Icon,{name:"copy",size:15})}),t.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>n.onDelete(e),children:t.jsx(ye.Icon,{name:"trash",size:15})})]})}function Rn({step:e,count:s}){if(s<2)return null;const o=e.fanOut==="parallel",n=No(s,o?"parallel":"sequential");return t.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":n,title:n,children:[t.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",s]})}function Mn({step:e}){const s=Xe(e),o=Ie(e);return!s&&!o?null:t.jsxs("div",{children:[o&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-disabled","data-testid":"step-disabled-badge",role:"img","aria-label":Ks,title:Ks,children:[t.jsx(ye.Icon,{name:"ban",size:11})," Disabled"]}),s&&t.jsxs("span",{className:"w6w-node-flag w6w-node-flag-paused","data-testid":"step-paused-badge",role:"img","aria-label":Gs,title:Gs,children:[t.jsx(ye.Icon,{name:"pause",size:11})," Paused"]})]})}function Ln(e){return!e||e.length===0?{}:{"data-step-problem":e.map(s=>s.code).join(" "),title:e.map(i.stepProblemTooltip).join(`
3
+ `)}}function Fn({problems:e}){if(!e||e.length===0)return null;const s=e.map(i.stepProblemTooltip).join(`
4
+ `);return t.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":s,title:s,style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:t.jsx(ye.Icon,{name:"warning",size:12})})}function Ni(e){const s=i.useW6WApi(),o=e.uses.action,[n,a]=d.useState(null),c=e.uses.trigger===!0,l=e.uses.app;return d.useEffect(()=>{if(!c||!s.getAppTriggers)return;let p=!1;return s.getAppTriggers(l).then(h=>{var g;return!p&&a(((g=h.find(x=>x.key===o))==null?void 0:g.title)??null)}).catch(()=>{}),()=>{p=!0}},[s,l,o,c]),n||o}function ki(e){const s=i.useW6WApi(),o=s.listSubscriptionsForWorkflow,n=s.retrySubscriptionRegistration,a=e.id,c=[...pi(e.nodes),...(e.nodes??[]).filter(I=>{var L;return((L=I.uses)==null?void 0:L.app)===i.WEBHOOK_APP&&I.uses.trigger!==!0})],l=c.length>0,p=c.map(I=>`${I.id}:${I.uses.app}:${I.uses.action}:${i.connectionIdFor(I,e.connections)??""}`).join("|"),[h,g]=d.useState([]),x=d.useMemo(()=>ui(h),[h]),[f,v]=d.useState(0);d.useEffect(()=>{if(!o||!l){g([]);return}let I=!1;return o.call(s,a).then(L=>!I&&g(L)).catch(()=>{}),()=>{I=!0}},[s,o,a,l,p,f]);const S=d.useMemo(()=>n?async I=>{try{await n.call(s,I)}finally{v(L=>L+1)}}:void 0,[s,n]);return d.useMemo(()=>({byNode:x,subs:h,retry:S}),[x,h,S])}function Ei({nodeId:e}){const{byNode:s,retry:o}=d.useContext(Nn),[n,a]=d.useState(!1),c=s.get(e),l=di(c,o!==void 0);return!c||!l?null:t.jsxs("div",{className:"w6w-small","data-trigger-registration":c.status,"data-tone":l.tone,style:{marginTop:3,paddingLeft:2},children:[t.jsx("span",{style:l.tone==="danger"?{color:"var(--w6w-danger)"}:void 0,children:l.label}),t.jsxs("span",{className:"w6w-muted",children:[" · ",l.lastFire]}),l.error&&t.jsx("div",{role:"alert",style:{color:"var(--w6w-danger)"},children:l.error}),l.retryVisible&&o&&t.jsx("button",{type:"button",className:"nodrag",disabled:n,onClick:()=>{a(!0),o(c.id).catch(()=>{}).finally(()=>a(!1))},children:"Retry"})]})}function Ai({id:e,data:s,selected:o}){const n=s.step,c=d.useContext(rs).get(n.uses.app),l=(c==null?void 0:c.displayName)||n.uses.app||"—",p=i.isTriggerStep(n.uses),h=Ni(n),g=n.uses.trigger?`${l} · ${h}`:l,x=i.nodePortsForStep(n,d.useContext(ns)),f=Sn(s.stepStatus??"no-run",s.runStatus),v=t.jsx(Rn,{step:n,count:d.useContext(os).get(e)??0}),S=In(e);return t.jsxs("div",{className:[s.loopOf?"w6w-node-in-loop":"",Ie(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:S,"data-disabled":Ie(n)||void 0,"data-paused":Xe(n)||void 0,children:[t.jsx(Pn,{id:e,step:n,runnable:!0}),t.jsxs("div",{className:p?"w6w-node-trigger":void 0,"data-node-kind":p?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Ln(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${f.borderWidth}px ${f.borderStyle} ${o?"var(--w6w-accent)":f.borderColor}`,opacity:Ie(n)?.45:o?1:f.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",...p?{}:{borderRadius:4,padding:"8px 12px"},minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fn,{problems:s.stepProblems}),x.in>0&&t.jsx($e,{type:"target",position:oe.Position.Left,multiple:x.in>1}),t.jsx(i.AppIcon,{src:c==null?void 0:c.iconSvg,srcDark:c==null?void 0:c.iconSvgDark,brandColor:c==null?void 0:c.brandColor,name:l,size:28}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontWeight:600},children:g}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),x.out>0&&t.jsxs(t.Fragment,{children:[t.jsx($e,{type:"source",position:oe.Position.Right,multiple:x.out>1}),!p&&t.jsx($e,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),v,t.jsx(Mn,{step:n}),p&&n.uses.trigger===!0&&t.jsx(Ei,{nodeId:e}),s.loopOf&&t.jsx(Tn,{id:e}),t.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[n.id,c!=null&&c.version?` - v${c.version}`:""]}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ti({id:e,data:s,selected:o}){const n=s.step,a=i.routesForStep(n),c=n.uses.app===i.ROUTER_APP,l=i.isIfStep(n),p=a.length?i.routerPortLayout(a):l?i.ifPortLayout():void 0,h=JSON.stringify(a.map(N=>N.id)),g=oe.useUpdateNodeInternals();d.useEffect(()=>{g(e)},[e,h,g]);const x=i.internalNodeLabel(n.uses.app,n.uses.action),f=i.internalNodeIcon(n.uses.app,n.uses.action),v=i.nodePortsForStep(n,d.useContext(ns)),S=i.isTriggerStep(n.uses),I=Ci(n),L=Sn(s.stepStatus??"no-run",s.runStatus),m=t.jsx(Rn,{step:n,count:d.useContext(os).get(e)??0}),B=In(e);return t.jsxs("div",{className:[I?"w6w-node-foreach":"",s.loopOf?"w6w-node-in-loop":"",Ie(n)?"w6w-node-disabled":""].filter(Boolean).join(" ")||void 0,"data-loop-of":s.loopOf,style:B,"data-disabled":Ie(n)||void 0,"data-paused":Xe(n)||void 0,children:[t.jsx(Pn,{id:e,step:n,runnable:!i.isControlApp(n.uses.app)}),t.jsxs("div",{className:S?"w6w-node-trigger":c?"w6w-node-router":void 0,"data-node-kind":S?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",...Ln(s.stepProblems),style:{position:"relative",...s.stepProblems?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${L.borderWidth}px ${L.borderStyle} ${o?"var(--w6w-accent)":L.borderColor}`,opacity:Ie(n)?.45:o?1:L.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...S?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,...p!=null&&p.minHeight?{minHeight:p.minHeight,boxSizing:"border-box"}:{},fontSize:13,display:"flex",alignItems:"center",gap:10},children:[t.jsx(Fn,{problems:s.stepProblems}),v.in>0&&t.jsx($e,{type:"target",position:oe.Position.Left,multiple:v.in>1}),f&&t.jsx(i.InternalIcon,{icon:f}),t.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[t.jsx("div",{style:{fontWeight:600},children:x}),t.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:t.jsx("code",{children:n.uses.action||"—"})})]}),I&&t.jsxs("div",{className:"w6w-foreach-ports w6w-small","aria-hidden":"true",children:[t.jsx("span",{children:"Each item"}),t.jsx("span",{children:"Done"})]}),!!(p!=null&&p.right.length)&&t.jsx("div",{className:"w6w-router-ports w6w-small",style:{gridTemplateRows:`repeat(${p.right.length}, 1fr)`},"aria-hidden":"true",children:p.right.map(N=>t.jsx("span",{title:N.label,children:N.label},N.id))}),v.out>0&&t.jsxs(t.Fragment,{children:[I&&t.jsx($e,{type:"source",position:oe.Position.Right,multiple:!1,id:i.EACH_SOURCE_HANDLE,variant:"each"}),p?t.jsxs(t.Fragment,{children:[p.right.map(N=>t.jsx($e,{type:"source",position:oe.Position.Right,multiple:!1,id:N.handleId,top:N.top,routeLabel:N.label},N.id)),p.bottom&&t.jsxs(t.Fragment,{children:[t.jsx($e,{type:"source",position:oe.Position.Bottom,multiple:!1,id:p.bottom.handleId,routeLabel:p.bottom.label}),t.jsx("span",{className:"w6w-router-fallback-label w6w-small","aria-hidden":"true",children:p.bottom.label})]})]}):t.jsx($e,{type:"source",position:oe.Position.Right,multiple:v.out>1,id:I?i.routeHandle(i.FOREACH_DONE_ROUTE):void 0}),!S&&!c&&!l&&n.uses.app!==i.RACE_APP&&t.jsx($e,{type:"source",position:oe.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),m,t.jsx(Mn,{step:n}),s.loopOf&&t.jsx(Tn,{id:e}),s.legacyLoop&&t.jsx("div",{className:"w6w-loop-legacy-note w6w-small",children:"This loop was converted from an older definition. Its steps after For each now run once per item; check the order, then save."}),t.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:n.id}),n.notes&&t.jsx("div",{className:"w6w-muted w6w-node-notes",title:n.notes,children:n.notes})]})}function Ii(e,s){var l,p;if(!s)return e;const o={...(e==null?void 0:e.steps)??{}};let n=!1;for(const[h,g]of Object.entries(s)){const x=/^nodes\.([^.]+)\.output$/.exec(h);!x||((l=o[x[1]])==null?void 0:l.output)!==void 0||(o[x[1]]={...o[x[1]]??{},output:g},n=!0)}const a=s["trigger.event"],c=a!==void 0&&((p=e==null?void 0:e.trigger)==null?void 0:p.event)===void 0;return!n&&!c?e:{...e??{},...n?{steps:o}:{},...c?{trigger:{...(e==null?void 0:e.trigger)??{},event:a}}:{}}}function Pi(e){return t.jsx(Ri,{...e})}function Ri({workflowId:e,step:s,restoreVersion:o,upstreamSteps:n,loop:a,onChange:c,onClose:l,readOnly:p,initialView:h="props",fanOutCount:g=0,stateOutputFields:x,onTestRun:f,stepProblems:v,otherStepIds:S}){var et,ht;const I=i.useW6WApi(),L=d.useContext(rs),[m,B]=d.useState(s),N=i.useWorkflowConnections(),z=i.connectionIdFor(m,N==null?void 0:N.connections),H={...m,uses:{...m.uses,connection:z}},A=m.uses.connectionRef!==void 0&&!z||i.isConnectionBlocked(H,v),R=v==null?void 0:v.find(T=>T.code==="unknown_connection"&&T.connection===z),W=(v??[]).filter(T=>"fix"in T),[V,ee]=d.useState(A?"setup":"configure"),[b,$]=d.useState(h==="json"?"code":h==="settings"?"config":"props"),[le,de]=d.useState("props"),[ve,te]=d.useState(()=>i.stepToJson(s)),[E,Z]=d.useState("{}"),P=d.useRef(null),[_,D]=d.useState(!1),q=d.useRef(o);d.useEffect(()=>{q.current!==o&&(q.current=o,B(s),te(i.stepToJson(s)))},[o,s]);const[O,J]=d.useState(null),[G,ue]=d.useState(null),[rt,at]=d.useState(null),[Be,Pe]=d.useState(!1),ae=i.isInternalApp(m.uses.app),Se=m.uses.trigger===!0;d.useEffect(()=>{if(ae){J(i.internalNodeParams(m.uses.app,m.uses.action));const Y=i.INTERNAL_NODES.filter(ne=>ne.app===m.uses.app&&ne.groupActions&&!ne.hidden);ue(Y.length?Y.map(ne=>({key:ne.action,title:ne.label,params:ne.params})):null);return}if(!m.uses.app){ue(null),J([]);return}let T=!1;return J(null),(Se?i.getTriggerDefs(I,m.uses.app):I.getAppActions(m.uses.app)).then(Y=>{var ne;T||(ue(Y),J(m.uses.action?((ne=Y.find(we=>we.key===m.uses.action))==null?void 0:ne.params)??[]:[]))}).catch(()=>!T&&J([])),()=>{T=!0}},[I,m.uses.app,m.uses.action,ae,Se]);const Re=d.useRef(0);d.useEffect(()=>()=>{Re.current++},[]);const Ye=d.useCallback(()=>{ae||!m.uses.app||I.listConnectionsForApp(m.uses.app).then(T=>{at(T),Pe(!1)}).catch(()=>Pe(!0))},[I,m.uses.app,ae]);d.useEffect(()=>{if(ae||!m.uses.app)return;let T=!1;return at(null),Pe(!1),I.listConnectionsForApp(m.uses.app).then(Y=>{T||(at(Y),Pe(!1))}).catch(()=>!T&&Pe(!0)),()=>{T=!0}},[I,m.uses.app,ae]);const K=d.useCallback(T=>{B(T),c(T)},[c]),Ce=bo({enabled:m.uses.app===i.SCRIPT_APP&&!p,values:m.with??{},onChange:T=>K({...m,with:T})}),Ve=T=>{T==="code"&&te(i.stepToJson(m)),$(T)},Me=T=>{const Y=i.stepNameError(T,S??[]);return Y||K({...m,id:T}),Y},Ne=!!m.uses.app&&!!m.uses.action&&!i.isControlApp(m.uses.app),Q=i.isForeachStep(m),pe=i.isTriggerStep(m.uses),Pt=V==="test"&&Ne&&!pe,He=i.useSeedSources(e,n,Ne&&!pe||Q),Le=kn(Ne&&!pe?a:void 0),Fe=i.startStateFromSeeds(He,En(Le)),De=Ii(Fe,i.useExpressionOptions().sampleValues),ke=i.useRememberedTestInput(Ne&&!pe||Q?e:void 0,m.id),[Ee,Ae]=d.useState(!1);d.useEffect(()=>{if((!Ne||pe)&&!Q||!ke.loaded)return;if(!Q&&ke.input!==void 0){const Y=ke.input;if(Object.keys(Y).length===0)return;const ne=JSON.stringify(Y,null,2);Z(we=>we.trim()==="{}"?ne:we),Ae(!0);return}let T=!1;return I.listStepTests(e,m.id).then(Y=>{if(T)return;const ne=Y.length?Y[Y.length-1]:null;if(!(ne!=null&&ne.input)||Object.keys(ne.input).length===0)return;const we=JSON.stringify(ne.input,null,2);Z(tt=>tt.trim()==="{}"?we:tt)}).catch(()=>{}),()=>{T=!0}},[I,e,m.id,Ne,pe,Q,ke.loaded]);const Ze=Q?yi(E):It(E),je={...m.with??{},...Ze??{}},fe=Ze??{},Oe=!!O&&!cs(Le)&&i.requiredParamsFilled(O,je),me=Q?i.resolveLoopItemsInState(je.items,Fe):void 0,[Te,Qe]=d.useState("idle"),ct=T=>{Z(T),Qe("idle")},ie=async()=>{if(me){Qe("saving");try{await I.saveStepTest(e,m.id,i.foreachTestFixture(me,fe)),Qe("saved")}catch{Qe("failed")}}},ce=L.get(m.uses.app),lt=ae?i.internalNodeIcon(m.uses.app,m.uses.action):null,ft=ae?lt?t.jsx(i.InternalIcon,{icon:lt}):null:t.jsx(i.AppIcon,{src:ce==null?void 0:ce.iconSvg,srcDark:ce==null?void 0:ce.iconSvgDark,brandColor:ce==null?void 0:ce.brandColor,name:ce==null?void 0:ce.displayName});return t.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:ft,title:t.jsx(i.StepNameEditor,{value:m.id,onCommit:Me,readOnly:p}),onClose:l,size:"wide",children:t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].filter(T=>m.uses.app!==i.RACE_APP||T!=="test").map(T=>t.jsx("button",{type:"button",className:`w6w-subtab${V===T?" active":""}`,disabled:A&&T!=="setup",onClick:()=>ee(T),children:T==="setup"?"Setup":T==="configure"?"Configure":"Test"},T))}),Pt?t.jsx(i.ConfigViewToggle,{view:le,views:["props","code"],onChange:T=>de(T)}):t.jsx(i.ConfigViewToggle,{view:b,customized:i.hasParamCustomization(m.with??{}),onChange:Ve,disabled:V!=="configure"})]}),A&&R&&t.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",R.connection," no longer exists — choose another to continue."]}),W.length>0&&t.jsx("div",{className:"w6w-stepproblem-fixes",style:{display:"grid",gap:6},children:W.map(T=>t.jsxs("div",{className:"w6w-small",style:{display:"flex",gap:8,alignItems:"center"},children:[t.jsx("span",{children:i.stepProblemTooltip(T)}),t.jsx("button",{type:"button",className:"w6w-btn","data-fix-code":T.code,disabled:p,onClick:()=>{const Y=vn(m,T);K(Y),te(i.stepToJson(Y))},children:"fix"in T?T.fix.label:""})]},T.code))}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[V==="setup"&&t.jsx(Oi,{step:m,app:ce,actions:G,conns:rt,connsFailed:Be,isInternal:ae,actionLabel:Se?"Trigger":"Action",readOnly:p,onChangeAction:T=>{var ne;const Y=ae?i.internalNodeDefaults(m.uses.app,T):{};if(ae)for(const we of i.internalNodeParams(m.uses.app,T))we.key in(m.with??{})&&(Y[we.key]=(ne=m.with)==null?void 0:ne[we.key]);K({...m,uses:{...m.uses,action:T},with:Y})},onChangeTriggerEvents:(T,Y)=>K({...m,uses:{...m.uses,action:T},with:{...m.with,actions:Y}}),onChangeConnection:T=>{if(!N){const{connectionRef:ne,...we}=m.uses;K({...m,uses:{...we,connection:T}});return}const Y=i.selectNodeConnection(m,T,(N==null?void 0:N.nodes)??[m],(N==null?void 0:N.connections)??{});N==null||N.setConnections(Y.connections),K(Y.step)},onChangeConnectionRef:T=>K(i.withConnectionRef(m,T)),onConnectionCreated:Ye,onChangeApp:T=>{const Y=++Re.current;if(T===m.uses.app){K(m);return}const ne={...m,uses:{app:T,action:"",...Se?{trigger:!0}:{}},with:{}};(i.isInternalApp(T)?Promise.resolve([]):I.listConnectionsForApp(T)).catch(()=>[]).then(we=>{if(Y!==Re.current)return;const tt=i.defaultConnectionFor(ne,we,(N==null?void 0:N.nodes)??[],(N==null?void 0:N.connections)??{});K({...ne,uses:{...ne.uses,...tt}})})}}),V==="configure"&&t.jsxs(t.Fragment,{children:[m.uses.app===i.WEBHOOK_APP&&I.listSubscriptionsForWorkflow&&I.createSubscription&&t.jsx(Di,{workflowId:e,step:m,readOnly:p}),O===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):b==="props"?m.uses.app===i.RACE_APP?t.jsx("p",{className:"w6w-muted w6w-small",children:i.RACE_DESCRIPTION}):m.uses.action==="wait"&&i.isControlApp(m.uses.app)?t.jsx(i.WaitEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):m.uses.action==="if"&&i.isControlApp(m.uses.app)?t.jsx(i.ConditionEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):m.uses.app==="@w6w/stop"?t.jsx(i.StopEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):m.uses.app===i.ROUTER_APP?t.jsx(i.RouterEditor,{values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T})}):t.jsxs(t.Fragment,{children:[m.uses.app===i.SCRIPT_APP&&t.jsx(jo,{values:m.with??{},conversion:Ce,readOnly:p}),t.jsx(i.ParamsForm,{params:O,values:m.with??{},readOnly:p,onChange:T=>K({...m,with:T}),dynamic:ae||!m.uses.action?void 0:{appId:m.uses.app,actionKey:m.uses.action,connectionId:A?void 0:z,appName:ce==null?void 0:ce.displayName}})]}):b==="code"?t.jsx(i.JsonEditor,{value:ve,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${m.id} JSON`,copyable:!0}):b==="params-code"?t.jsx(i.ParamCustomization,{values:m.with??{},onChange:T=>K({...m,with:T}),readOnly:p}):t.jsxs("div",{className:"w6w-stack",children:[t.jsx(i.NodeConfigForm,{config:{retry:m.retry,onError:m.onError,notes:m.notes},onChange:T=>K({...m,...T}),readOnly:p,failureHandling:!pe,retryControls:!i.isControlApp(m.uses.app)&&m.uses.app!==i.CALL_APP}),Mi,t.jsx(Li,{step:m,count:g,readOnly:p,onChange:K}),Yo(m)&&t.jsx(Fi,{step:m,inLoop:a!==void 0,outputFields:x,readOnly:p,onChange:K})]})]}),V==="test"&&t.jsx("div",{className:"w6w-stack",children:Ne?Se?t.jsx(i.AppTriggerTestNote,{title:((et=G==null?void 0:G.find(T=>T.key===m.uses.action))==null?void 0:et.title)??m.uses.action,app:(ce==null?void 0:ce.displayName)??m.uses.app}):pe?t.jsx(i.TriggerFillForm,{app:m.uses.app,action:m.uses.action,fields:(ht=m.with)==null?void 0:ht.fields,persist:{workflowId:e,stepId:m.id,input:fe},listen:m.uses.app===i.WEBHOOK_APP&&I.listSubscriptionsForWorkflow&&I.startWebhookListen?{stepWith:m.with,readOnly:p}:void 0}):t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",t.jsx("code",{children:m.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),t.jsx(An,{seed:Le,readOnly:p}),Ee&&!p&&t.jsx(i.LastUsedNote,{onClear:()=>{ke.clear(),Ae(!1),Z("{}")}}),t.jsx(es,{text:E,onChange:Z,seeds:He,readOnly:p}),O===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):t.jsx(ho,{params:O,values:je,testStartState:De,view:le,literalKeys:m.uses.app===i.SCRIPT_APP?ji:void 0}),t.jsx(i.StepTestRun,{ref:P,app:m.uses.app,action:m.uses.action,connectionId:z,values:je,state:Fe,canRun:Oe,hideRunButton:!0,persist:{workflowId:e,stepId:m.id,input:fe},onBusyChange:D})]}):Q?t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:["Resolves ",t.jsx("strong",{children:"Items"})," against the incoming state — nothing inside the loop runs. ",t.jsx("strong",{children:"Test"})," saves the first item as this loop's sample, so the steps on its ",t.jsx("strong",{children:"Each item"})," output can pick its keys. To run the loop's work, test a step on ",t.jsx("strong",{children:"Each item"}),": it runs once, on one item."]}),t.jsx(es,{text:E,onChange:ct,seeds:He,readOnly:p,expand:!me,hint:t.jsxs(t.Fragment,{children:["Paste a sample list — ",t.jsx("code",{children:'[{"id": 1, "name": "…"}]'})," — or"," ",t.jsx("code",{children:'{"items": […]}'}),". It replaces what ",t.jsx("strong",{children:"Items"})," ","resolves to, for this test only."]})}),t.jsx(vi,{items:me,save:Te})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),t.jsx("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:m.uses.app===i.RACE_APP&&V==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",onClick:l,children:"Done"}):V!=="test"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:A,onClick:()=>ee(V==="setup"?"configure":"test"),children:"Next →"}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),Ne&&!pe&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!Oe||_,onClick:()=>{var T;f==null||f(),(T=P.current)==null||T.run()},children:_?"Testing…":"Test"}),Q&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:p||!(me!=null&&me.length)||Te==="saving",onClick:()=>void ie(),children:Te==="saving"?"Testing…":"Test"})]})})]})})}const Mi=!1;function Li({step:e,count:s,readOnly:o,onChange:n}){const a=s>=2,c=e.fanOut==="parallel"?"parallel":"sequential";return t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Run next nodes"}),t.jsxs("select",{"aria-label":"Run next nodes",value:c,disabled:o||!a,onChange:l=>n(Co(e,l.target.value)),children:[t.jsx("option",{value:"sequential",children:"In sequence"}),t.jsx("option",{value:"parallel",children:"In parallel"})]}),!a&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function rn({to:e}){return t.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[t.jsx("span",{children:"From this step output"}),t.jsx("span",{}),t.jsx("span",{children:e})]})}function an(){return t.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function cn({label:e,fields:s,value:o,readOnly:n,onChange:a}){const c=d.useMemo(()=>(s??[]).map(l=>({value:l,label:l})),[s]);return t.jsx(i.Combobox,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:c,value:o,disabled:n,emptyText:c.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:a})}function Fi({step:e,inLoop:s,outputFields:o,readOnly:n,onChange:a}){const c=qo(e),l=be.validateStateConfig(c),p=f=>a(Ko(e,f)),h=c.mode==="pick"&&Array.isArray(c.map)?c.map:[],g=(f,v)=>p({mode:"pick",map:h.map((S,I)=>I===f?{...S,...v}:S)}),x=f=>{if(c.mode!=="append")return;const v=f.path??c.path,S="from"in f?f.from:c.from;p({mode:"append",path:v,...S?{from:S}:{}})};return t.jsxs("div",{className:"w6w-field w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Write to state"}),t.jsx("select",{"aria-label":"Write to state",value:c.mode,disabled:n,onChange:f=>p(Xo(e,f.target.value)),children:Jo.map(f=>t.jsx("option",{value:f,children:Uo[f]},f))})]}),c.mode==="key"&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"To state key"}),t.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:c.key,disabled:n,onChange:f=>p({mode:"key",key:f.target.value})}),t.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",t.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",t.jsx("code",{children:"order.id"})," nests."]})]}),c.mode==="pick"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(rn,{to:"To state key"}),h.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),h.map((f,v)=>t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(cn,{label:"From output field",fields:o,value:f.from,readOnly:n,onChange:S=>g(v,{from:S})}),t.jsx(an,{}),t.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:f.to,disabled:n,onChange:S=>g(v,{to:S.target.value})}),!n&&t.jsx(i.DeleteButton,{label:"Remove field",onClick:()=>p({mode:"pick",map:h.filter((S,I)=>I!==v)})})]},v)),!n&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>p({mode:"pick",map:[...h,{from:"",to:""}]}),children:"+ Add field"}),t.jsxs("span",{className:"w6w-hint",children:["Copies ",t.jsx("code",{children:"output.<path>"})," into ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),c.mode==="append"&&t.jsxs("div",{className:"w6w-stack",children:[t.jsx(rn,{to:"Append to state list"}),t.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[t.jsx(cn,{label:"Output field to append",fields:o,value:c.from??"",readOnly:n,onChange:f=>x({from:f})}),t.jsx(an,{}),t.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:c.path,disabled:n,onChange:f=>x({path:f.target.value})})]}),t.jsxs("span",{className:"w6w-hint",children:["Appends ",t.jsx("code",{children:"output.<path>"})," to the list at ",t.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),l.length>0&&t.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:l.map(f=>t.jsx("div",{children:f.message},`${f.code}:${f.message}`))}),c.mode!=="off"&&t.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",t.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),s&&t.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function Di({workflowId:e,step:s,readOnly:o}){const n=i.useW6WApi(),[a,c]=d.useState(void 0),[l,p]=d.useState(null),[h,g]=d.useState(!1);d.useEffect(()=>{const f=n.listSubscriptionsForWorkflow;if(!f)return;let v=!1;return f(e).then(S=>{v||c(i.pickWebhookSubscription(S,s.id))}).catch(S=>!v&&p(S.message)),()=>{v=!0}},[n,e,s.id]);const x=()=>{const f=n.createSubscription;f&&(p(null),g(!0),f(i.WEBHOOK_APP,s.uses.action,{workflowId:e,connectionId:null,params:s.with??{}}).then(v=>{g(!1),c(v)}).catch(v=>{g(!1),p(v instanceof Error?v.message:String(v))}))};return t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:[t.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]}),l&&t.jsx("div",{className:"w6w-result w6w-error",children:l}),a!=null&&a.webhookUrl?t.jsx(ye.Copyable,{value:a.webhookUrl,readOnly:!0,children:t.jsx("input",{type:"text",readOnly:!0,value:a.webhookUrl,"aria-label":"Webhook URL"})}):a===void 0?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&t.jsx("button",{type:"button",className:"w6w-btn",disabled:h,onClick:x,children:h?"Creating…":"Create webhook URL"})]})}function Oi({step:e,app:s,actions:o,conns:n,connsFailed:a,isInternal:c,actionLabel:l="Action",readOnly:p,onChangeAction:h,onChangeTriggerEvents:g,onChangeConnection:x,onChangeConnectionRef:f,onChangeApp:v,onConnectionCreated:S}){const I=e.uses.trigger?i.eventbriteTriggerChoices(e.uses.app,o,e.uses.action,e.with??{}):null,[L,m]=d.useState(null),B=d.useRef(null),N=i.useWorkflowConnections(),z=i.connectionIdFor(e,N==null?void 0:N.connections);return t.jsxs("div",{className:"w6w-stack",children:[e.uses.connectionRef&&!z&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:"The shared connection is missing or unbound. Choose an account."}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-app-conn-row",ref:B,children:[t.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":L==="app",disabled:p,onClick:()=>m(H=>H==="app"?null:"app"),children:[!c&&s&&t.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:c?e.uses.app:(s==null?void 0:s.displayName)??e.uses.app})]}),!c&&t.jsx(i.WorkflowConnectionPicker,{step:e,conns:n,failed:a,readOnly:p,open:L==="conn",onOpenChange:H=>m(H?"conn":null),anchorRef:B,onChangeConnection:x,onChangeConnectionRef:f,onConnectionCreated:S})]}),L==="app"&&t.jsx(i.AnchoredFlyout,{anchorRef:B,onClose:()=>m(null),children:t.jsx(i.AppPicker,{onSelectApp:H=>{const C=H.id===e.uses.app;v(H.id),m(C?"conn":null)}})})]}),c&&!(o!=null&&o.length)?t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Action"}),t.jsx("div",{className:"w6w-muted w6w-small",children:t.jsx("code",{children:e.uses.action})})]}):I?t.jsx(i.EventbriteTriggerPicker,{choices:I,readOnly:p,onChange:H=>g(I.triggerKey,H)}):t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:l}),t.jsx(i.Combobox,{value:e.uses.action,disabled:p||o===null,onChange:h,options:o===null?[{value:e.uses.action,label:e.uses.action}]:o.map(H=>({value:H.key,label:H.title??H.key}))})]})]})}function ln({trigger:e}){return t.jsx("span",{className:"w6w-connection-node-kind",role:"img","aria-label":e?"Trigger":"Node",children:t.jsx("svg",{"aria-hidden":"true",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e?t.jsx("path",{d:"M13 2 4 14h7l-1 8 10-12h-7l1-8Z"}):t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"3"}),t.jsx("path",{d:"M2 12h3m14 0h3"})]})})})}function _i({resources:e}){const s=i.useW6WApi(),o=e.highlightNode;d.useEffect(()=>()=>o==null?void 0:o(null),[o]);const[n,a]=d.useState([]),[c,l]=d.useState(!0),[p,h]=d.useState(),[g,x]=d.useState(),[f,v]=d.useState(null),[S,I]=d.useState(!1),[L,m]=d.useState(!1),B=d.useRef(0),N=d.useCallback(async()=>{const P=++B.current;l(!0),h(void 0);try{const _=await s.listConnections();return P!==B.current?void 0:(a(_),_)}catch(_){P===B.current&&h(_.message)}finally{P===B.current&&l(!1)}},[s]);d.useEffect(()=>(N(),()=>{B.current++}),[N]);const[z,H]=d.useState(new Map),C=JSON.stringify([...new Set([...Object.values(e.connections).map(P=>P.app),...n.map(P=>P.appId)])].filter(P=>{var _;return!((_=e.apps)!=null&&_.has(P))&&!n.some(D=>D.appId===P&&D.app!==void 0)}).sort());d.useEffect(()=>{var O,J;let P=!1;const _=JSON.parse(C);if(c||!_.length)return;const D=(O=s.listAppsByIds)==null?void 0:O.bind(s),q=D?Promise.all(Array.from({length:Math.ceil(_.length/50)},(G,ue)=>D(_.slice(ue*50,(ue+1)*50)))).then(G=>G.flat()):(J=s.listApps)==null?void 0:J.call(s);return q==null||q.then(G=>{P||H(new Map(G.map(ue=>[ue.id,ue])))}).catch(()=>{}),()=>{P=!0}},[s,C,c]);const A=P=>{var O;const _=n.find(J=>J.appId===P&&J.app)??n.find(J=>J.appId===P&&J.app!==void 0),D=_?i.resolveConnectionAppMeta(_,z):z.get(P),q=(O=e.apps)==null?void 0:O.get(P);return q?{...D,...q}:D},R=P=>{var _;return((_=A(P))==null?void 0:_.displayName)||P},W=P=>{if(e.readOnly)return!1;try{return e.edit(P),x(void 0),!0}catch(_){return x(_.message),!1}},V=P=>i.nextWorkflowConnectionName(P.appId,e.connections),ee=()=>{v(null),x(void 0),I(!1)},b=f!=null&&f.ref?e.connections[f.ref]:void 0,$=n.find(P=>P.id===(f==null?void 0:f.connection)),le=(b==null?void 0:b.app)??($==null?void 0:$.appId),de=e.nodes.filter(P=>P.uses.app===le),ve=e.nodes.filter(P=>(f==null?void 0:f.ref)!==void 0&&P.uses.connectionRef===f.ref),te=n.filter(P=>!b||P.appId===b.app).map(P=>({value:P.id,label:b?P.displayName||P.id:`${R(P.appId)} · ${P.displayName||P.id}`}));f!=null&&f.connection&&!te.some(P=>P.value===f.connection)&&te.unshift({value:f.connection,label:f.connection.startsWith("zerocred:")?"Built-in":f.connection});const E=(P,_=28)=>{const D=A(P);return t.jsx(i.AppIcon,{src:D==null?void 0:D.iconSvg,srcDark:D==null?void 0:D.iconSvgDark,brandColor:D==null?void 0:D.brandColor,name:R(P),size:_})},Z=()=>{if(!f||!f.name.trim()||!f.connection||!le)return;const P=f.ref!==void 0?{type:"update",ref:f.ref,name:f.name,connection:f.connection,nodeIds:f.allNodes?de.map(_=>_.id):void 0}:{type:"add",name:f.name,app:le,connection:f.connection};W(P)&&ee()};return t.jsxs("div",{className:"w6w-stack","data-testid":"workflow-connections-panel",children:[t.jsxs("div",{className:"w6w-workflow-connections-heading",children:[t.jsx("h3",{children:"Connections"}),t.jsx(i.IconButton,{label:"Add connection",disabled:e.readOnly,onClick:()=>{x(void 0),v({name:"",connection:"",allNodes:!1})},children:t.jsx("svg",{"aria-hidden":"true",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t.jsx("path",{d:"M12 5v14M5 12h14"})})})]}),p&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load connections: ",p]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void N(),children:"Retry"})]}),Object.entries(e.connections).map(([P,_])=>{var J;const D=e.nodes.filter(G=>G.uses.connectionRef===P),q=n.find(G=>G.id===_.connection),O=(q==null?void 0:q.displayName)||((J=_.connection)!=null&&J.startsWith("zerocred:")?"Built-in":_.connection)||"No credentials selected";return t.jsxs("section",{className:"w6w-workflow-connection","data-connection-resource":P,children:[t.jsxs("div",{className:"w6w-connection-app-heading",children:[E(_.app),t.jsxs("div",{className:"w6w-connection-summary",children:[t.jsx("strong",{children:R(_.app)}),t.jsx("span",{className:"w6w-small",children:O}),t.jsxs("span",{className:"w6w-muted w6w-small",children:[P,q!=null&&q.state?` · ${q.state}`:""]})]}),t.jsx(i.IconButton,{icon:"edit",label:`Edit connection ${P}`,disabled:e.readOnly,onClick:()=>{x(void 0),v({ref:P,name:P,connection:_.connection??"",allNodes:!1})}})]}),D.length>0?t.jsxs("details",{className:"w6w-connection-consumers",onToggle:G=>{G.currentTarget.open||o==null||o(null)},children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Used by ",D.length," ",D.length===1?"node":"nodes"]}),t.jsx("ul",{className:"w6w-connection-node-list",children:D.map(G=>t.jsx("li",{children:e.focusNode?t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Show ${G.id} on canvas`,onClick:()=>{var ue;return(ue=e.focusNode)==null?void 0:ue.call(e,G.id)},onMouseEnter:()=>o==null?void 0:o(G.id),onMouseLeave:()=>o==null?void 0:o(null),onFocus:()=>o==null?void 0:o(G.id),onBlur:()=>o==null?void 0:o(null),children:[t.jsx(ln,{trigger:i.isTriggerStep(G.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:G.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:G.id})]})]}):t.jsxs("span",{className:"w6w-connection-app-heading",children:[t.jsx(ln,{trigger:i.isTriggerStep(G.uses)}),t.jsxs("span",{className:"w6w-connection-node-label",children:[t.jsx("strong",{children:G.uses.action}),t.jsx("span",{className:"w6w-muted w6w-small",children:G.id})]})]})},G.id))})]}):t.jsx("span",{className:"w6w-muted w6w-small",children:"Not used by any nodes yet."})]},P)}),!Object.keys(e.connections).length&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No workflow connections yet."}),f&&!L&&!S&&t.jsxs(i.Modal,{title:f.ref!==void 0?"Edit connection":"Add connection",titleIcon:le?E(le):void 0,subtitle:le?R(le):void 0,onClose:ee,children:[t.jsxs("div",{className:"w6w-modal-body w6w-stack",children:[g&&t.jsx("p",{role:"alert",className:"w6w-field-error",children:g}),p&&t.jsxs("div",{role:"alert",className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-field-error",children:["Couldn’t load credentials: ",p]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>void N(),children:"Retry"})]}),f.ref!==void 0&&!b&&t.jsx("p",{role:"alert",children:"This workflow connection no longer exists."}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Workflow connection name"}),t.jsx("input",{className:"w6w-input","aria-label":"Workflow connection name",value:f.name,disabled:e.readOnly,onChange:P=>v({...f,name:P.target.value})})]}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:b?"Credentials":"Existing connection"}),t.jsx(i.Combobox,{"aria-label":b?"Credentials":"Connection to add",options:te,value:f.connection,placeholder:c?"Loading connections…":"Choose a connection…",disabled:e.readOnly||c||!!p,onChange:P=>{const _=n.find(D=>D.id===P);v({...f,connection:P,name:!f.name&&_?V(_):f.name})}})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly,onClick:()=>m(!0),children:"Create new credentials"}),b&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"w6w-muted w6w-small",children:f.allNodes?`Saving applies these credentials to all ${de.length} ${R(b.app)} nodes.`:`Saving updates credentials for ${ve.length} linked ${ve.length===1?"node":"nodes"}.`}),de.length>0&&t.jsxs("label",{className:"w6w-connection-scope",children:[t.jsx("input",{type:"checkbox",checked:f.allNodes||de.every(P=>P.uses.connectionRef===f.ref),disabled:e.readOnly||de.every(P=>P.uses.connectionRef===f.ref),onChange:P=>v({...f,allNodes:P.target.checked})}),"Use for all ",de.length," ",R(b.app)," ",de.length===1?"node":"nodes"," in this workflow"]}),t.jsxs("div",{className:"w6w-connection-remove",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:e.readOnly||ve.length>0,onClick:()=>I(!0),children:"Remove from workflow"}),ve.length>0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Assign another connection to the linked nodes before removing this one."})]})]})]}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:ee,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:e.readOnly||c||!!p||!f.name.trim()||!f.connection||!le||f.ref!==void 0&&!b,onClick:Z,children:f.ref!==void 0?"Save changes":"Add to workflow"})]})]}),f&&S&&t.jsx(i.ConfirmModal,{title:"Remove workflow connection",message:`Remove “${f.ref}” from this workflow? The saved credentials will remain available.`,confirmLabel:"Remove",onClose:()=>I(!1),onConfirm:()=>{f.ref&&W({type:"remove",ref:f.ref})?ee():I(!1)}}),f&&L&&t.jsx(i.AddConnectionModal,{initialAppId:b==null?void 0:b.app,onClose:()=>m(!1),onCreated:({connectionId:P})=>{m(!1),N().then(_=>{const D=_==null?void 0:_.find(q=>q.id===P);D&&v(q=>q?{...q,connection:D.id,name:q.name||V(D)}:null)})}})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.RACE_APP=i.RACE_APP;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.centralizeConnections=i.centralizeConnections;exports.coerceDefault=i.coerceDefault;exports.connectionIdFor=i.connectionIdFor;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.isTriggerStep=i.isTriggerStep;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=dn;exports.MAX_NOTE_BYTES=pn;exports.MAX_SECTIONS=un;exports.WorkflowConnectionsPanel=_i;exports.WorkflowFlowEditor=xi;exports.applyStepProblemFix=vn;exports.assignMembership=Kt;exports.clampCanvas=Xt;exports.findLoopProblems=$o;exports.findStateWriteProblems=zo;exports.isDisabledStep=Ie;exports.isPausedStep=Xe;exports.pausedStopAt=Zt;exports.pruneSectionMembers=ts;exports.renameSectionMember=hn;exports.roundGeometry=Gt;exports.sectionsContaining=mn;exports.withCanvasGeometry=fn;exports.withDisabled=jn;exports.withPaused=bn;
3
5
  //# sourceMappingURL=flow.cjs.map