@w6w/ui 0.2.0 → 0.2.54

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