@w6w/ui 0.2.0 → 0.2.11

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 (78) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/AppPicker.d.ts +47 -2
  3. package/dist/CanvasLayer.d.ts +38 -0
  4. package/dist/{CodeBlock-Dot3Pd7P.js → CodeBlock-BqXDA35P.js} +2 -2
  5. package/dist/{CodeBlock-Dot3Pd7P.js.map → CodeBlock-BqXDA35P.js.map} +1 -1
  6. package/dist/{CodeBlock-CZu4TFSi.cjs → CodeBlock-CulfbnZD.cjs} +2 -2
  7. package/dist/{CodeBlock-CZu4TFSi.cjs.map → CodeBlock-CulfbnZD.cjs.map} +1 -1
  8. package/dist/ConfirmModal-Ln99S9NT.js +7919 -0
  9. package/dist/ConfirmModal-Ln99S9NT.js.map +1 -0
  10. package/dist/ConfirmModal-fjHW5rN-.cjs +14 -0
  11. package/dist/ConfirmModal-fjHW5rN-.cjs.map +1 -0
  12. package/dist/Copyable-DA6eiU7w.cjs +2 -0
  13. package/dist/Copyable-DA6eiU7w.cjs.map +1 -0
  14. package/dist/{Copyable-1niV9gUa.js → Copyable-F4NTaG77.js} +91 -15
  15. package/dist/Copyable-F4NTaG77.js.map +1 -0
  16. package/dist/EditConnectionModal.d.ts +6 -1
  17. package/dist/JsonEditor.d.ts +8 -0
  18. package/dist/Markdown.d.ts +25 -0
  19. package/dist/ParamsForm.d.ts +7 -1
  20. package/dist/StepBuilderModal.d.ts +23 -5
  21. package/dist/WorkflowFlowEditor.d.ts +14 -3
  22. package/dist/app-pages.d.ts +2 -0
  23. package/dist/canvas-types.d.ts +36 -0
  24. package/dist/canvas-utils.d.ts +44 -0
  25. package/dist/code.cjs +1 -1
  26. package/dist/code.mjs +2 -2
  27. package/dist/components/AuthFieldsForm.d.ts +11 -0
  28. package/dist/components/BudgetMeter.d.ts +15 -0
  29. package/dist/components/CallableList.d.ts +3 -2
  30. package/dist/components/Combobox.d.ts +8 -1
  31. package/dist/components/ConnectionList.d.ts +2 -3
  32. package/dist/components/CredentialPicker.d.ts +35 -0
  33. package/dist/components/DataTable.d.ts +27 -0
  34. package/dist/components/EmptyState.d.ts +9 -0
  35. package/dist/components/icons.d.ts +1 -1
  36. package/dist/dynamic-fields.d.ts +60 -0
  37. package/dist/editor-theme.d.ts +24 -0
  38. package/dist/flow-fanout.d.ts +2 -2
  39. package/dist/flow-types.d.ts +18 -1
  40. package/dist/flow-utils.d.ts +10 -3
  41. package/dist/flow.cjs +2 -2
  42. package/dist/flow.cjs.map +1 -1
  43. package/dist/flow.d.ts +9 -0
  44. package/dist/flow.mjs +1519 -1138
  45. package/dist/flow.mjs.map +1 -1
  46. package/dist/index.cjs +1 -1
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.ts +14 -2
  49. package/dist/index.mjs +1362 -1123
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/note-markdown.d.ts +22 -0
  52. package/dist/provider.d.ts +56 -7
  53. package/dist/resolve-params.d.ts +5 -0
  54. package/dist/run-visuals.d.ts +4 -1
  55. package/dist/step-problems.d.ts +34 -0
  56. package/dist/types.d.ts +109 -3
  57. package/dist/use-dynamic-fields.d.ts +23 -0
  58. package/package.json +4 -2
  59. package/src/styles/_budget-meter.scss +46 -0
  60. package/src/styles/_callable-list.scss +15 -6
  61. package/src/styles/_canvas.scss +318 -0
  62. package/src/styles/_connections.scss +2 -14
  63. package/src/styles/_data-table.scss +55 -0
  64. package/src/styles/_empty-state.scss +21 -0
  65. package/src/styles/_flow.scss +11 -0
  66. package/src/styles/_fx.scss +23 -0
  67. package/src/styles/_layout.scss +10 -0
  68. package/src/styles/_markdown.scss +20 -0
  69. package/src/styles/_tester.scss +1 -14
  70. package/src/styles.css +572 -39
  71. package/src/styles.scss +5 -0
  72. package/dist/ConfirmModal-ChoiGy2K.cjs +0 -11
  73. package/dist/ConfirmModal-ChoiGy2K.cjs.map +0 -1
  74. package/dist/ConfirmModal-Wx3i8F1n.js +0 -6359
  75. package/dist/ConfirmModal-Wx3i8F1n.js.map +0 -1
  76. package/dist/Copyable-1niV9gUa.js.map +0 -1
  77. package/dist/Copyable-CYZU1o4X.cjs +0 -2
  78. package/dist/Copyable-CYZU1o4X.cjs.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { Edge, Node } from '@xyflow/react';
2
- import { FlowEdge, FlowStep, FlowWorkflow } from './flow-types.ts';
2
+ import { FlowEdge, FlowStep, FlowWorkflow, FlowWorkflowInput } from './flow-types.ts';
3
3
  import { RunStatus, StepVisualState } from './run-visuals.ts';
4
+ import { StepProblem } from './step-problems.ts';
4
5
  export interface StepNodeData extends Record<string, unknown> {
5
6
  step: FlowStep;
6
7
  /** True for internal pseudo-app nodes (`@w6w/*`) — rendered as pill cards. */
@@ -21,6 +22,12 @@ export interface StepNodeData extends Record<string, unknown> {
21
22
  * provenance/persistence rules as `stepStatus`.
22
23
  */
23
24
  runStatus?: RunStatus;
25
+ /**
26
+ * A host-supplied problem with this step (e.g. a dangling connection).
27
+ * Patched in by `WorkflowFlowEditor.tsx`'s `stepProblems` effect — never set
28
+ * here and never read by {@link flowToWorkflow} (not persisted).
29
+ */
30
+ stepProblem?: StepProblem;
24
31
  }
25
32
  export type StepNode = Node<StepNodeData>;
26
33
  /**
@@ -116,7 +123,7 @@ export declare function idClashMessage(lead: string, id: string, involved: reado
116
123
  * does not shift depending on which of its neighbours happen to carry a
117
124
  * coordinate.
118
125
  */
119
- export declare function workflowToFlow(wf: FlowWorkflow): {
126
+ export declare function workflowToFlow(input: FlowWorkflowInput): {
120
127
  nodes: StepNode[];
121
128
  edges: Edge[];
122
129
  };
@@ -163,7 +170,7 @@ export declare function relayoutNodes(nodes: StepNode[], edges: Edge[]): StepNod
163
170
  * intended — **a workflow that has never been saved by this editor starts
164
171
  * carrying `position` on every step the first time it is saved.**
165
172
  */
166
- export declare function flowToWorkflow(original: FlowWorkflow, nodes: StepNode[], edges: Edge[]): FlowWorkflow;
173
+ export declare function flowToWorkflow(originalInput: FlowWorkflowInput, nodes: StepNode[], edges: Edge[]): FlowWorkflow;
167
174
  /** The workflow's stored camera, as `settings.viewport` declares it. */
168
175
  type StoredViewport = NonNullable<NonNullable<FlowWorkflow["settings"]>["viewport"]>;
169
176
  /**
package/dist/flow.cjs CHANGED
@@ -1,3 +1,3 @@
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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),_=require("@xyflow/react"),c=require("react"),ss=require("react-dom"),i=require("./ConfirmModal-fjHW5rN-.cjs"),de=require("./Copyable-DA6eiU7w.cjs"),Rt=200,It=200,Ft=10240;function Ue(t){const s={};for(const[o,a]of Object.entries(t))s[o]=Math.round(a);return s}const ns=t=>!!t&&Number.isFinite(t.x)&&Number.isFinite(t.y),os=t=>!!t&&Number.isFinite(t.width)&&Number.isFinite(t.height);function yt(t,s,o){return t&&t.map(a=>{const l=s==null?void 0:s[a.id],u=ns(l==null?void 0:l.position)?l.position:a.position,f=os(l==null?void 0:l.size)?l.size:a.size;return{...a,position:Ue(u),size:Ue(f)}})}function Mt(t,s,o){if(!s)return t;const a={...t};return t.notes&&(a.notes=yt(t.notes,o)),t.sections&&(a.sections=yt(t.sections,o)),a}function qe(t,s){return t.sections?{...t,sections:t.sections.map(o=>({...o,nodes:o.nodes.filter(a=>a!==s)}))}:t}function Dt(t,s,o){return t.sections?{...t,sections:t.sections.map(a=>({...a,nodes:a.nodes.map(l=>l===s?o:l)}))}:t}function Ke(t,s,o){if(!t.sections)return t;const a=new Set(o);return{...t,sections:t.sections.map(l=>{const u=l.nodes.filter(f=>!a.has(f));return l.id===s?{...l,nodes:[...new Set([...u,...o])]}:{...l,nodes:u}})}}function Lt(t,s){return(t.sections??[]).filter(o=>o.nodes.includes(s)).map(o=>o.id)}function rs(t,s){const o=new TextEncoder;if(o.encode(t).length<=s)return t;let a="",l=0;for(const u of t){const f=o.encode(u).length;if(l+f>s)break;a+=u,l+=f}return a}function Xe(t){const s={...t};return t.notes&&(s.notes=t.notes.slice(0,Rt).map(o=>({...o,content:rs(o.content,Ft)}))),t.sections&&(s.sections=t.sections.slice(0,It)),s}function is(t,s,o){const a={};for(const f of[...t.notes??[],...t.sections??[]])a[f.id]={position:f.position,size:f.size};const l=(f,b)=>f==null?void 0:f.map(C=>{const S=b==null?void 0:b.find(m=>m.id===C.id);return S?{...C,position:S.position,size:S.size}:C}),u=o?t:{...t,...t.notes?{notes:l(t.notes,s==null?void 0:s.notes)}:{},...t.sections?{sections:l(t.sections,s==null?void 0:s.sections)}:{}};return Mt(u,o,a)}const St=220;function as(t){return t.length<=St?{text:t,clipped:!1,length:t.length}:{text:t.slice(0,St).trimEnd(),clipped:!0,length:t.length}}function ls({params:t,values:s,testStartState:o,view:a="props"}){const{sampleValues:l}=i.useExpressionOptions(),u=c.useMemo(()=>i.buildResolveScope(l,o),[l,o]),f=i.flattenParams(t),b=m=>{var N;return s[m]!==void 0?s[m]:(N=f.find(d=>d.key===m))==null?void 0:N.default},C=f.filter(m=>m.type!=="section"&&i.isParamVisible(m,b));if(a==="code"){const m=cs(C,s,u);return e.jsx("div",{className:"w6w-resolved-params",children:e.jsx(i.JsonEditor,{value:JSON.stringify(m,null,2),onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":"Resolved test values (JSON)"})})}const S=C.filter(m=>!i.deepEqual(b(m.key),m.default));return C.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."})}):S.length===0?e.jsx("div",{className:"w6w-resolved-params",children:e.jsx("p",{className:"w6w-muted w6w-small",children:"Every configured value matches its default — nothing to show here. Switch to JSON to see the full set."})}):e.jsx("div",{className:"w6w-resolved-params w6w-resolved-table",children:S.map(m=>m.type==="vars"?e.jsx(ds,{param:m,value:s[m.key],scope:u},m.key):e.jsx(us,{label:m.label??m.key,segments:i.resolveParamValue(s[m.key]!==void 0?s[m.key]:m.default,u)},m.key))})}function cs(t,s,o){const a={};for(const l of t)if(l.type==="vars"){const u=Array.isArray(s[l.key])?s[l.key]:Array.isArray(l.default)?l.default:[];a[l.key]=i.resolveVarsJson(u,o)}else a[l.key]=i.resolveParamJson(s[l.key]!==void 0?s[l.key]:l.default,o);return a}function us({label:t,segments:s}){return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t}),e.jsx("div",{className:"w6w-resolved-value",children:e.jsx(_t,{segments:s})})]})}function ds({param:t,value:s,scope:o}){const a=Array.isArray(s)?s:Array.isArray(t.default)?t.default:[];return e.jsxs("div",{className:"w6w-resolved-row",children:[e.jsx("span",{className:"w6w-resolved-label",children:t.label??t.key}),a.length===0?e.jsx("p",{className:"w6w-muted w6w-small",children:"None configured."}):e.jsx("div",{className:"w6w-stack",children:a.map((l,u)=>e.jsxs("div",{className:"w6w-resolved-value",children:[e.jsx("code",{children:l.key||"(no key)"})," → ",e.jsx(_t,{segments:i.resolveParamValue(l.value,o)})]},u))})]})}function _t({segments:t}){return e.jsx(e.Fragment,{children:t.map((s,o)=>e.jsx(ps,{segment:s},o))})}function ps({segment:t}){switch(t.status){case"resolved":return t.ref?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{kind:"var",refName:t.ref}),e.jsx(vt,{value:t.value})]}):e.jsx(vt,{value:t.value});case"unresolved":return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{kind:"var",refName:t.ref}),e.jsx("span",{className:"w6w-param-unresolved",children:"unresolved"})]});case"not-evaluated":return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{kind:"expr"}),e.jsx("span",{className:"w6w-param-unevaluated",children:"not evaluated"})]});case"masked":return e.jsx(Ve,{kind:"secret",refName:t.ref})}}function vt({value:t}){const[s,o]=c.useState(!1),a=hs(t),l=as(a);return l.clipped?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:s?"w6w-resolved-text-full":void 0,children:s?a:`${l.text}…`}),e.jsx("button",{type:"button",className:"w6w-resolved-more","aria-expanded":s,onClick:()=>o(u=>!u),children:s?"Show less":`Show all (${l.length.toLocaleString()} characters)`})]}):e.jsx("span",{children:a})}const fs={var:"◆",secret:"🔒",expr:"ƒ"};function Ve({kind:t,refName:s}){const o=t==="expr"?"expr":i.varLabel(s??"");return e.jsxs("span",{className:`w6w-expr-chip w6w-expr-chip-${t}`,children:[e.jsx("span",{className:"w6w-expr-chip-sigil",children:fs[t]}),e.jsx("span",{className:"w6w-expr-chip-label",children:o})]})}function hs(t){if(t===null)return"null";if(t===void 0)return"(not set)";if(t==="")return'""';if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t)}catch{return String(t)}}function te(t){var s;return((s=t.data)==null?void 0:s.when)==="error"?"error":"success"}function Vt(t,s){var o;return((o=t.find(a=>a.id===s))==null?void 0:o.id)??null}function Wt(t,s,o,a,l){var S,m;if(!t||!s||t===s||a.some(N=>N.source===t&&N.target===s))return!1;const u=(S=o.find(N=>N.id===t))==null?void 0:S.data.step,f=(m=o.find(N=>N.id===s))==null?void 0:m.data.step;if(!u||!f)return!1;const b=i.nodePortsForStep(u,l),C=i.nodePortsForStep(f,l);return b.out>=1&&C.in>=1}function Ge(t,s,o,a,l,u){var I,A;if(!Wt(t,s,o,a,u)||!t||!s)return null;const f=(I=o.find(V=>V.id===t))==null?void 0:I.data.step,b=(A=o.find(V=>V.id===s))==null?void 0:A.data.step;if(!f||!b)return null;const C=i.nodePortsForStep(f,u),S=i.nodePortsForStep(b,u);let m=a;if(m.filter(V=>V.source===t&&te(V)===l).length>=C.out)return{next:a,conflict:null,refusal:{refused:"out_cap",cap:C.out}};const d=m.filter(V=>V.target===s);if(d.length>=S.in){const V=new Set(d.slice(0,d.length-S.in+1).map(T=>T.id));m=m.filter(T=>!V.has(T.id))}const v=i.flowEdgeId(t,s,l);return{next:_.addEdge({source:t,target:s,id:v,sourceHandle:i.sourceHandleForLane(l),data:{when:l},...i.edgeVisuals(l,void 0)},m),conflict:Vt(m,v),refusal:null}}function We(t,s,o,a,l="success",u){const f=Ge(t,s,o,a,l,u);return!f||f.conflict||f.refusal?null:f.next}function ws(t,s,o,a,l="success",u){var f;return((f=Ge(t,s,o,a,l,u))==null?void 0:f.conflict)??null}function ms(t,s,o,a,l="success",u){var f;return((f=Ge(t,s,o,a,l,u))==null?void 0:f.refusal)??null}function Ye(t,s,o,a,l){var I;const u=t.filter(A=>A.id===s);if(u.length!==1)return null;const f=u[0],b=(I=a.find(A=>A.id===f.source))==null?void 0:I.data.step;if(!b)return null;const C=i.nodePortsForStep(b,l).out,S=t.filter(A=>A.id!==s);if((te(f)===o?[]:S.filter(A=>A.source===f.source&&te(A)===o)).length>=C)return{next:t,conflict:null,refusal:{refused:"out_cap",cap:C}};const N=i.edgeVisuals(o,void 0),d={...f,id:i.flowEdgeId(f.source,f.target,o),data:{...f.data,when:o},className:N.className,label:N.label,sourceHandle:i.sourceHandleForLane(o)},v=Vt(S,d.id);return{next:t.map(A=>A.id===s?d:A),conflict:v,refusal:null}}function gs(t,s,o,a,l){const u=Ye(t,s,o,a,l);return!u||u.conflict||u.refusal?null:u.next}function xs(t,s,o,a,l){var u;return((u=Ye(t,s,o,a,l))==null?void 0:u.conflict)??null}function bs(t,s,o,a,l){var u;return((u=Ye(t,s,o,a,l))==null?void 0:u.refusal)??null}function js(t,s,o){return t.map(a=>{const l=a.source===s?o:a.source,u=a.target===s?o:a.target;return{...a,source:l,target:u,id:i.flowEdgeId(l,u,te(a))}})}function Cs(t,s){const o={success:0,error:0};for(const l of s)l.source===t&&o[te(l)]++;const a=Math.max(o.success,o.error);return{enabled:a>=2,count:a}}function ys(t,s){const{fanOut:o,...a}=t;return s==="parallel"?{...a,fanOut:"parallel"}:a}function Ss(t,s){return`Runs these ${t} nodes in ${s==="parallel"?"parallel":"sequence"}`}function Ot(t,s){var o;return(o=t.nodes??t.steps)==null?void 0:o[s]}const vs=new Set(["succeeded","failed","canceled"]);function Ns(t,s){var o;return t?((o=Ot(t,s))==null?void 0:o.status)??"pending":"no-run"}const Nt={borderColor:"var(--w6w-border)",borderStyle:"solid",borderWidth:1,opacity:1};function $t(t,s){const o=s!==void 0&&vs.has(s);switch(t){case"no-run":return Nt;case"pending":return o?{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.5}:{borderColor:"var(--w6w-border)",borderStyle:"dashed",borderWidth:1,opacity:1};case"running":return{borderColor:"var(--w6w-accent)",borderStyle:"solid",borderWidth:2,opacity:1};case"succeeded":return{borderColor:"var(--w6w-success)",borderStyle:"solid",borderWidth:2,opacity:1};case"failed":return{borderColor:"var(--w6w-danger)",borderStyle:"solid",borderWidth:2,opacity:1};case"skipped":return{borderColor:"var(--w6w-muted)",borderStyle:"dashed",borderWidth:1,opacity:.7};default:return Nt}}function ks(t,s,o){if(!t)return;const a=Ot(t,s);if(!a)return;const l=o??"success";if(a.status==="succeeded")return l==="success"?"taken":"skipped";if(a.status==="failed")return l==="error"?"taken":"skipped";if(a.status==="skipped")return"skipped"}function Es(t,s){return t.map(o=>{const a=s==null?void 0:s[o.id],l=o.data.stepProblem;if(a===void 0){if(l===void 0&&!("stepProblem"in o.data))return o;const{stepProblem:u,...f}=o.data;return{...o,data:f}}return l&&l.code===a.code&&l.connection===a.connection?o:{...o,data:{...o.data,stepProblem:{...a}}}})}function Je(t){return`Connection ${t.connection} no longer exists — open the step and choose another on the Setup tab`}function kt(t,s){return(s==null?void 0:s.code)==="unknown_connection"&&t.uses.connection===s.connection}function Ps(t,s,o){if(!t)return"No connection";if(o)return"Couldn't load connections";if(s===null)return t;const a=s.find(l=>l.id===t);return a?a.displayName??t:"Missing connection — choose another"}function As(t,s){const[o,a]=c.useState({}),l=c.useRef(new Set),u=JSON.stringify([...new Set(s.map(f=>f.data.step.uses.app))].filter(f=>f&&!i.isInternalApp(f)).sort());return c.useEffect(()=>{const f=JSON.parse(u).filter(b=>!l.current.has(b));if(f.length!==0){for(const b of f)l.current.add(b);Promise.all(f.map(async b=>{try{return[b,await t.getAppActions(b)]}catch{return l.current.delete(b),null}})).then(b=>{const C=b.filter(S=>S!==null);C.length!==0&&a(S=>({...S,...Object.fromEntries(C)}))})}},[t,u]),o}function Ts(t){return(s,o)=>{var a,l;return(l=(a=t[s])==null?void 0:a.find(u=>u.key===o))==null?void 0:l.ports}}const Rs="Which outcome of the source node this edge carries. An error edge is drawn by dragging from the node's error exit port; use this control to re-lane an edge already drawn. An error edge overrides the node’s “On error” policy.";function Et(t,s,o,a){const l=t.find(u=>u.id===s);return[o,a,l==null?void 0:l.source,l==null?void 0:l.target]}const Qe=c.createContext(void 0),Ze=c.createContext(new Map);function Pt(t){return`Can’t draw that edge: this node allows at most ${t} outgoing edge${t===1?"":"s"} per lane.`}const et=c.createContext(new Map),tt=c.createContext(null);function Is(t){return e.jsx(_.ReactFlowProvider,{children:e.jsx(Fs,{...t})})}function At(t,s){let o=s.length+1;for(;s.includes(`${t}-${o}`);)o++;return`${t}-${o}`}function ze(t){var s,o;return{x:t.position.x,y:t.position.y,w:((s=t.measured)==null?void 0:s.width)??t.width??200,h:((o=t.measured)==null?void 0:o.height)??t.height??64}}function Fs({value:t,onChange:s,readOnly:o,height:a=480,apps:l,exprOptions:u,project:f,runState:b,stepProblems:C,onTestRun:S,fitViewKey:m}){var xt,bt;const N=i.useW6WApi(),d=c.useMemo(()=>new Map((l??[]).map(n=>[n.id,n])),[l]),[v,I]=c.useState(null),A=c.useMemo(()=>i.workflowToFlow(t),[t.id]),V=c.useMemo(()=>i.storedViewport(t),[t.id]),T=((xt=t.settings)==null?void 0:xt.savePosition)!==!1,[g,F,me]=_.useNodesState(A.nodes),ie=As(N,g),O=c.useMemo(()=>Ts(ie),[ie]),[j,D,ge]=_.useEdgesState(A.edges);c.useEffect(()=>{F(n=>n.map(r=>{const p=Ns(b,r.id);return r.data.stepStatus===p&&r.data.runStatus===(b==null?void 0:b.status)?r:{...r,data:{...r.data,stepStatus:p,runStatus:b==null?void 0:b.status}}})),D(n=>n.map(r=>{const p=te(r),h=ks(b,r.source,p),w=i.edgeVisuals(p,h);return r.className===w.className&&r.label===w.label?r:{...r,className:w.className,label:w.label}}))},[b,F,D]),c.useEffect(()=>{F(n=>Es(n,C))},[C,F]);const[z,L]=c.useState(null),Y=c.useMemo(()=>t.canvas??{},[t.id]),[E,Q]=c.useState(Y),[se,xe]=c.useState(!1),[J,ae]=c.useState(null),[ne,oe]=c.useState(null),[W,pe]=c.useState(null),[be,je]=c.useState(!1),[B,le]=c.useState(null),[Ce,U]=c.useState("props"),[Ne,q]=c.useState(null),ke=c.useRef(!1),fe=c.useRef(null),[H,Z]=c.useState(null),{screenToFlowPosition:ce,fitView:he}=_.useReactFlow(),Re=i.useEffectiveTheme();c.useEffect(()=>{F(A.nodes),D(A.edges),L(null),le(null),Q(Y)},[A,Y,F,D]);const Ee=c.useCallback((n,r)=>{var w,y;const{canvas:p,...h}=n;return!((w=r.notes)!=null&&w.length)&&!((y=r.sections)!=null&&y.length)?h:{...h,canvas:is(r,t.canvas,T)}},[t.canvas,T]),M=c.useCallback((n,r,p)=>{s(Ee(i.flowToWorkflow(t,n,r),p??E))},[t,s,E,Ee]),Ie=c.useCallback(n=>Wt(n.source,n.target,g,j,O),[g,j,O]),Fe=c.useCallback(n=>{if(o)return;const r=We(n.source,n.target,g,j,i.laneForSourceHandle(n.sourceHandle),O);if(!r){const p=i.laneForSourceHandle(n.sourceHandle),h=ms(n.source,n.target,g,j,p,O);if(h){const y=j.find(k=>k.source===n.source&&te(k)===p);y&&(D(j.map(k=>({...k,selected:k.id===y.id}))),pe(y.id),re({edgeId:y.id,message:Pt(h.cap)}));return}const w=ws(n.source,n.target,g,j,i.laneForSourceHandle(n.sourceHandle));if(!w)return;D(j.map(y=>({...y,selected:y.id===w}))),pe(w),re({edgeId:w,message:i.idClashMessage("Can’t draw that edge",w,Et(j,w,n.source,n.target))});return}re(null),D(r),M(g,r)},[j,g,D,M,o,O]),$=c.useCallback((n,r)=>{var P,R,X;if(o||r.isValid)return;const p=r.fromNode;if(!p)return;const h=((P=r.fromHandle)==null?void 0:P.type)==="target"?"target":"source",w=(R=g.find(G=>G.id===p.id))==null?void 0:R.data.step;if(w){const G=i.nodePortsForStep(w,O);if((h==="source"?G.out:G.in)<1)return}const y="changedTouches"in n?n.changedTouches[0]:n,k=ce({x:y.clientX,y:y.clientY});Z({nodeId:p.id,handleType:h,position:k,lane:i.laneForSourceHandle((X=r.fromHandle)==null?void 0:X.id)}),je(!0)},[o,ce,g,O]),Pe=c.useCallback((n,r,p)=>{if(o)return;const h=g.find(R=>R.id===n);if(!h)return;const w=ze(h),y=i.laneForSourceHandle(p),k=120,P=r==="target"?{x:w.x-w.w-k,y:w.y}:y==="error"?{x:w.x,y:w.y+w.h+k}:{x:w.x+w.w+k,y:w.y};Z({nodeId:n,handleType:r,position:P,lane:y}),je(!0)},[o,g]),Ae=c.useCallback(n=>{o||q(n)},[o]),Me=c.useCallback(n=>{if(o)return;const r=g.filter(w=>w.id!==n),p=j.filter(w=>w.source!==n&&w.target!==n),h=qe(E,n);F(r),D(p),Q(h),z===n&&L(null),B===n&&le(null),M(r,p,h)},[g,j,E,F,D,M,o,z,B]),x=c.useCallback(()=>{if(o)return;const n=i.relayoutNodes(g,j);F(n),ke.current=!0,M(n,j)},[g,j,F,M,o]),K=c.useCallback(()=>{o||x()},[o,x]);c.useEffect(()=>{ke.current&&(ke.current=!1,he({duration:300}))},[g,he]);const ee=c.useRef(m);c.useEffect(()=>{Object.is(ee.current,m)||(ee.current=m,he({duration:300}))},[m,he]);const[ue,re]=c.useState(null),De=c.useMemo(()=>j.find(n=>n.id===W)??null,[j,W]),zt=c.useCallback(n=>{if(o||!W)return;const r=j.find(k=>k.id===W);if(!r||te(r)===n)return;const p=xs(j,W,n,g),h=bs(j,W,n,g,O),w=p||h?null:gs(j,W,n,g,O);if(!w){if(h){re({edgeId:W,message:Pt(h.cap)});return}re({edgeId:W,message:p?i.idClashMessage("Can’t switch this edge",p,Et(j,p,r.source,r.target)):"This edge can’t be switched right now."});return}re(null),D(w);const y=w.find(k=>k.source===r.source&&k.target===r.target&&te(k)===n);pe((y==null?void 0:y.id)??null),M(g,w)},[j,g,D,M,o,W,O]),Ut=c.useCallback(n=>{if(o)return;const r=j.filter(p=>p.id!==n);r.length!==j.length&&(D(r),W===n&&pe(null),M(g,r))},[g,j,D,M,o,W]),nt=c.useCallback(n=>{if(o)return;const r=g.find(k=>k.id===n);if(!r)return;const p=i.suggestStepId(g.map(k=>k.id),`${r.data.step.id}_copy`),h={...structuredClone(r.data.step),id:p},w={id:p,type:r.type,position:{x:r.position.x+40,y:r.position.y+60},data:{step:h,isInternal:r.data.isInternal}},y=[...g,w];F(y),L(p),M(y,j)},[g,j,F,M,o]),qt=c.useCallback(n=>{if(o)return;const r=i.isInternalApp(n.uses.app),p=i.suggestStepId(g.map(P=>P.id),i.slugifyLabel(i.internalNodeLabel(n.uses.app,n.uses.action))),h={id:p,uses:n.uses,...n.with&&Object.keys(n.with).length>0?{with:n.with}:{}},w={id:p,type:r?"control":"step",position:(H==null?void 0:H.position)??{x:80,y:80+g.length*24},data:{step:h,isInternal:r}},y=[...g,w];let k=j;if(H){const[P,R]=H.handleType==="target"?[p,H.nodeId]:[H.nodeId,p];k=We(P,R,y,j,H.lane,O)??j}else{const P=g.find(R=>i.isTriggerApp(R.data.step.uses.app));if(i.isTriggerApp(n.uses.app)){if(!P){const R=i.findChainRoot(g,j);R&&(k=We(p,R.id,y,j,"success",O)??j)}}else{const X=(P&&!j.some(G=>G.source===P.id)?P:void 0)??i.findChainTail(g,j);X&&(k=We(X.id,p,y,j,"success",O)??j)}}return F(y),k!==j&&D(k),L(p),M(y,k),p},[g,j,F,D,M,o,H,O]),ot=c.useCallback((n,r)=>{const p=r.id!==n;if(p&&g.some(w=>w.id===r.id))return;const h=g.map(w=>w.id===n?{...w,id:r.id,data:{step:r,isInternal:i.isInternalApp(r.uses.app)}}:w);if(p){const w=js(j,n,r.id),y=Dt(E,n,r.id);F(h),D(w),Q(y),z===n&&L(r.id),B===n&&le(r.id),M(h,w,y);return}F(h),M(h,j)},[g,j,E,F,D,z,B,M]),we=c.useCallback(n=>{o||(Q(n),M(g,j,n))},[o,g,j,M]),Kt=c.useCallback(()=>{var w;if(o)return;const n=(w=fe.current)==null?void 0:w.getBoundingClientRect(),r=n?ce({x:n.left+n.width/2,y:n.top+n.height/2}):{x:0,y:0},p=E.notes??[],h={id:At("note",p.map(y=>y.id)),color:"#facc15",position:{x:Math.round(r.x-100),y:Math.round(r.y-60)},size:{width:200,height:120},content:""};we(Xe({...E,notes:[...p,h]}))},[o,E,ce,we]),Xt=c.useCallback((n,r)=>{if(o)return;const p=r?Math.min(n.x,r.x):n.x,h=r?Math.min(n.y,r.y):n.y,w=r?Math.abs(r.x-n.x):360,y=r?Math.abs(r.y-n.y):240,k=g.filter(Te=>{const _e=ze(Te),jt=_e.x+_e.w/2,Ct=_e.y+_e.h/2;return jt>=p&&jt<=p+w&&Ct>=h&&Ct<=h+y}).map(Te=>Te.id),P=E.sections??[],R=At("section",P.map(Te=>Te.id)),X={id:R,title:"Section",color:"#6366f1",position:{x:Math.round(p),y:Math.round(h)},size:{width:Math.round(w),height:Math.round(y)},nodes:[]},G={...E,sections:[...P,X]};we(Xe(Ke(G,R,k)))},[o,g,E,we]);c.useEffect(()=>{if(!se)return;const n=r=>{r.key==="Escape"&&(xe(!1),ae(null))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[se]);const Gt=c.useCallback((n,r)=>{var k;if(o)return;const p=(k=E.sections)==null?void 0:k.find(P=>P.id===n);if(!p)return;const h=new Set(p.nodes),w=g.map(P=>h.has(P.id)?{...P,position:{x:P.position.x+r.dx,y:P.position.y+r.dy}}:P),y={...E,sections:(E.sections??[]).map(P=>P.id===n?{...P,position:{x:P.position.x+r.dx,y:P.position.y+r.dy}}:P)};F(w),Q(y),M(w,j,y)},[o,E,g,j,F,M]),Yt=c.useCallback((n,r)=>{if(o)return;const p=n==="note"?{...E,notes:(E.notes??[]).filter(h=>h.id!==r)}:{...E,sections:(E.sections??[]).filter(h=>h.id!==r)};we(p)},[o,E,we]),Qt=n=>{let r=E;for(const p of n){const h=ze(p),w=h.x+h.w/2,y=h.y+h.h/2,k=(r.sections??[]).find(R=>w>=R.position.x&&w<=R.position.x+R.size.width&&y>=R.position.y&&y<=R.position.y+R.size.height),P=Lt(r,p.id);k?(P.length!==1||P[0]!==k.id)&&(r=Ke(r,k.id,[p.id])):P.length>0&&(r=qe(r,p.id))}return r},Oe=c.useCallback((n,r,p)=>{(async()=>{const h=await N.saveStepTest(t.id,n,r).catch(w=>(console.error("step run fixture save failed",w),null));await N.recordStepTestRun(t.id,n,{stepTestId:(h==null?void 0:h.id)??null,status:p.status,input:r.input,output:p.output,error:p.error,...p.meta?{meta:p.meta}:{}})})().catch(h=>{console.error("step run persist failed",h)})},[N,t.id]),rt=c.useCallback(n=>{const r=g.find(p=>p.id===n);!r||i.isControlApp(r.data.step.uses.app)||I({stepId:n,status:"collect"})},[g]),Zt=c.useCallback(async(n,r,p)=>{S==null||S();const h=g.find(R=>R.id===n);if(!h)return;const w=h.data.step,y=i.isTriggerApp(w.uses.app),k=y?{input:r}:{...w.with??{},...r},P=y?{input:r,with:r}:{input:r,with:k};I({stepId:n,status:"running"});try{const R=await N.invokeAction(w.uses.app,w.uses.action,k,{...w.uses.connection?{connectionId:w.uses.connection}:{},project:f,...p?{state:p}:{}}),X=R.logs,G=R.meta;I({stepId:n,status:"done",value:R.value,logs:X,...G?{meta:G}:{}}),Oe(n,P,{status:"succeeded",output:R.value,...G?{meta:G}:{}})}catch(R){const X=R;I({stepId:n,status:"error",error:X.message??String(R),errorCode:X.code}),Oe(n,P,{status:"failed",error:X.message??String(R)})}},[g,N,Oe,f,S]),$e=c.useMemo(()=>({onEdit:n=>{U("props"),le(n)},onEditJson:n=>{U("json"),le(n)},onRun:rt,onDuplicate:nt,onDelete:Ae,onAddFromPort:Pe,readOnly:o}),[rt,nt,Ae,Pe,o]);c.useEffect(()=>{const n=fe.current;if(!n)return;const r=p=>{const h=p.target.closest(".react-flow__node");if(!h)return;const w=h.getAttribute("data-id");w&&(p.stopPropagation(),$e.onEdit(w))};return n.addEventListener("dblclick",r,!0),()=>n.removeEventListener("dblclick",r,!0)},[$e]);const ye=g.find(n=>n.id===B),it=(ye==null?void 0:ye.data.step)??null,Be=v?((bt=g.find(n=>n.id===v.stepId))==null?void 0:bt.data.step)??null:null,He=(v==null?void 0:v.status)==="collect"&&!!Be,es=c.useMemo(()=>v?i.upstreamStateSources(v.stepId,g,j).steps:[],[v,g,j]),at=c.useMemo(()=>{const n=new Map;for(const r of g)n.set(r.id,Cs(r.id,j).count);return n},[g,j]),ts=c.useMemo(()=>({step:Ds,control:Ls}),[]),[Le,lt]=c.useState({}),[ct,ut]=c.useState({}),dt=c.useMemo(()=>({actionDef:(n,r)=>{var p;return(p=ie[n])==null?void 0:p.find(h=>h.key===r)},testOutputs:Le}),[ie,Le]),[pt,ft]=c.useState(null),Se=c.useMemo(()=>{const n=i.upstreamStateSources(B,g,j,dt);return{...n,steps:i.excludeSelfStep(n.steps,B??pt)}},[B,pt,g,j,dt]),ht=JSON.stringify(Se.steps.map(n=>n.id));c.useEffect(()=>{const n=JSON.parse(ht);if(!B||n.length===0){lt({}),ut({});return}let r=!1;return Promise.all(n.map(async p=>{try{const h=await N.listStepTests(t.id,p),w=h.length?h[h.length-1]:null;return w?{id:p,output:w.lastRunOutput,meta:w.lastRunMeta}:null}catch{return null}})).then(p=>{if(r)return;const h={},w={};for(const y of p)y!=null&&y.meta&&(w[y.id]=y.meta),!(!y||y.output===void 0||y.output===null)&&(h[y.id]=y.output);lt(h),ut(w)}),()=>{r=!0}},[N,t.id,B,ht]);const wt=c.useMemo(()=>{const n={};for(const r of Se.steps){Object.assign(n,i.stepMetaSampleValues(r.id,ct[r.id]));const p=Le[r.id];if(p!==void 0){if(n[`steps.${r.id}.output`]=p,typeof p=="object"&&p!==null&&!Array.isArray(p))for(const[h,w]of Object.entries(p))n[`steps.${r.id}.output.${h}`]=w;for(const h of r.outputs??[]){if(!h.path||!h.key.includes("."))continue;const w=i.valueAtPath(p,h.key);w!==void 0&&(n[`steps.${r.id}.output.${h.key}`]=w)}}}return n},[Se.steps,Le,ct]),mt=i.useExpressionOptions(),gt=c.useMemo(()=>({...u??{},steps:Se.steps,hasTrigger:Se.hasTrigger,sampleValues:{...mt.sampleValues??{},...(u==null?void 0:u.sampleValues)??{},...wt}}),[u,mt.sampleValues,Se,wt]);return e.jsx(tt.Provider,{value:$e,children:e.jsx(Qe.Provider,{value:O,children:e.jsx(Ze.Provider,{value:at,children:e.jsx(et.Provider,{value:d,children:e.jsx(i.WorkflowProjectProvider,{project:f,children:e.jsx(i.ExpressionOptionsProvider,{value:gt,children:e.jsxs("div",{ref:fe,className:"w6w-flow",style:{width:"100%",height:a,position:"relative"},onKeyDown:n=>{if(n.key!=="Backspace"&&n.key!=="Delete"||B||be||!z&&!W)return;const r=n.target;r.isContentEditable||r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.tagName==="SELECT"||r.closest("dialog, .w6w-modal")!==null||(n.preventDefault(),z?Ae(z):W&&Ut(W))},children:[e.jsxs(_.ReactFlow,{nodes:g,edges:j,defaultEdgeOptions:{type:"smoothstep"},connectionLineType:_.ConnectionLineType.SmoothStep,onNodesChange:me,onEdgesChange:ge,onConnect:Fe,onConnectEnd:$,isValidConnection:Ie,onNodeDragStop:(n,r,p)=>{const h=Qt(p),w=h!==E;w&&Q(h),!(!T&&!w)&&M(g,j,h)},onMoveEnd:(n,r)=>{if(!n||o)return;const p=i.flowToWorkflow(t,g,j),h=i.withViewport(p,r);h!==p&&s(h)},onSelectionChange:({nodes:n,edges:r})=>{var p,h;L(((p=n[0])==null?void 0:p.id)??null),pe(((h=r[0])==null?void 0:h.id)??null)},nodeTypes:ts,nodesDraggable:!o,nodesConnectable:!o,connectOnClick:!1,elementsSelectable:!0,...V?{defaultViewport:V}:{fitView:!0},deleteKeyCode:null,colorMode:Re,proOptions:{hideAttribution:!0},children:[e.jsx(_.Background,{gap:16}),e.jsx(_.Controls,{showInteractive:!1,children:!o&&e.jsx(_.ControlButton,{onClick:K,title:"Auto-layout — re-flow the graph into columns","aria-label":"Auto-layout the graph",children:e.jsx(de.Icon,{name:"layout"})})}),e.jsx(_.MiniMap,{pannable:!0,zoomable:!0,style:{background:"var(--w6w-panel-2)"}}),!o&&e.jsxs(_.Panel,{position:"top-left",className:"w6w-flow-tools",children:[e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>je(!0),children:"+ Node"}),e.jsx(i.IconButton,{label:"Add note",icon:"sticky-note",className:"w6w-flow-tool","data-testid":"add-note",onClick:Kt}),e.jsx(i.IconButton,{label:"Draw section",title:"Draw section — drag a frame on the canvas (Esc cancels)",icon:"frame",className:`w6w-flow-tool${se?" active":""}`,"aria-pressed":se,"data-testid":"draw-section",onClick:()=>{xe(!se),ae(null)}})]}),!o&&se&&e.jsx("div",{className:"w6w-section-draw nopan nodrag nowheel","data-testid":"section-draw-surface",onPointerDown:n=>{if(n.button!==0)return;n.currentTarget.setPointerCapture(n.pointerId);const{clientX:r,clientY:p}=n;ae({sx:r,sy:p,ex:r,ey:p})},onPointerMove:n=>{const{clientX:r,clientY:p}=n;ae(h=>h&&{...h,ex:r,ey:p})},onPointerUp:()=>{const n=J;if(ae(null),xe(!1),!n)return;const r=ce({x:n.sx,y:n.sy}),p=Math.abs(n.ex-n.sx)>6||Math.abs(n.ey-n.sy)>6;Xt(r,p?ce({x:n.ex,y:n.ey}):null)},children:J&&(()=>{var h;const n=(h=fe.current)==null?void 0:h.getBoundingClientRect(),r=(n==null?void 0:n.left)??0,p=(n==null?void 0:n.top)??0;return e.jsx("div",{className:"w6w-section-draw-rect",style:{left:Math.min(J.sx,J.ex)-r,top:Math.min(J.sy,J.ey)-p,width:Math.abs(J.ex-J.sx),height:Math.abs(J.ey-J.sy)}})})()}),!o&&De&&e.jsx(_.Panel,{position:"top-right",children:e.jsxs("div",{className:"w6w-edge-lane",children:[e.jsx("span",{className:"w6w-muted w6w-small",children:"Run on"}),["success","error"].map(n=>e.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${te(De)===n?" active":""}`,"aria-pressed":te(De)===n,title:Rs,onClick:()=>zt(n),children:n==="success"?"Success":"Error"},n)),(ue==null?void 0:ue.edgeId)===De.id&&e.jsx("span",{className:"w6w-edge-lane-err w6w-small",role:"alert",children:ue.message})]})}),e.jsx(i.CanvasLayer,{canvas:E,readOnly:o,savePosition:T,onChange:we,onSectionDrop:Gt,onRequestDelete:(n,r)=>!o&&oe({kind:n,id:r})})]}),ne&&e.jsx(i.ConfirmModal,{title:ne.kind==="note"?"Delete note":"Delete section",message:ne.kind==="note"?"Delete this note?":"Delete this section? Its nodes are kept.",confirmLabel:"Delete",onConfirm:()=>{Yt(ne.kind,ne.id),oe(null)},onClose:()=>oe(null)}),be&&e.jsx(i.StepBuilderModal,{onClose:()=>{je(!1),Z(null),ft(null)},onAdd:n=>{const r=qt(n);return r&&ft(r),r},onDraftChange:(n,r)=>ot(n,{id:n,...r}),workflowId:t.id,upstreamSteps:i.stepBuilderUpstreamSteps(H,g,j)}),it&&B&&e.jsx(_s,{workflowId:t.id,step:it,upstreamSteps:gt.steps??[],readOnly:o,fanOutCount:at.get(B)??0,initialView:Ce,stepProblem:ye==null?void 0:ye.data.stepProblem,onChange:n=>ot(B,n),onClose:()=>le(null),onTestRun:S}),v&&e.jsxs(i.Modal,{title:`${He?"Run node":"Test run"}: ${v.stepId}`,onClose:()=>I(null),children:[He&&Be&&e.jsx(Ms,{workflowId:t.id,step:Be,upstreamSteps:es,onCancel:()=>I(null),onRun:(n,r)=>Zt(v.stepId,n,r)},v.stepId),!He&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w6w-modal-body",children:[v.status==="running"&&e.jsx("p",{className:"w6w-muted w6w-small",children:"Running…"}),v.status==="error"&&e.jsxs("div",{className:"w6w-result w6w-error",children:[v.errorCode&&e.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:e.jsx("code",{children:v.errorCode})}),v.error||"The node failed with no error message."]}),v.status==="done"&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{marginBottom:6},children:"Result"}),e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:360,overflow:"auto",margin:0},children:JSON.stringify(v.value,null,2)}),v.meta&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Metadata"}),e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:360,overflow:"auto",margin:0},children:JSON.stringify(v.meta,null,2)})]})]}),v.logs&&v.logs.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"w6w-muted w6w-small",style:{margin:"10px 0 6px"},children:"Console output"}),e.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:200,overflow:"auto",margin:0},children:v.logs.join(`
2
+ `)})]})]}),e.jsx("div",{className:"w6w-modal-actions",children:e.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>I(null),children:"Close"})})]})]}),Ne!==null&&e.jsx(i.ConfirmModal,{title:"Delete node",message:`Delete node "${Ne}"? Its connections are removed too.`,confirmLabel:"Delete",onConfirm:()=>{Me(Ne),q(null)},onClose:()=>q(null)})]})})})})})})})}function st(t){try{const s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:null}catch{return null}}function Bt({text:t,onChange:s,seeds:o,readOnly:a}){const l=st(t),u=l?Object.keys(l).length:0,f=u>0,[b,C]=c.useState(f);c.useEffect(()=>{f&&C(!0)},[f]);const S=m=>{s(JSON.stringify(m.lastRunOutput??m.input??{},null,2)),C(!0)};return e.jsxs("div",{className:"w6w-field w6w-incoming-state",children:[e.jsx("span",{children:"Incoming state"}),o.length>0&&e.jsx("div",{className:"w6w-seed-picker",children:e.jsx("div",{className:"w6w-seed-chips",children:o.map(m=>e.jsxs("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Use ${m.label}'s saved test as the incoming state`,disabled:a,onClick:()=>S(m.test),children:[e.jsx("code",{children:m.label}),m.test.lastRunStatus?e.jsxs("span",{className:"w6w-muted w6w-small",children:[" · ",m.test.lastRunStatus]}):null]},m.stepId))})}),e.jsxs("details",{className:"w6w-state-override",open:b,onToggle:m=>C(m.currentTarget.open),children:[e.jsxs("summary",{children:["Override the incoming state",u>0?` · ${u} key${u===1?"":"s"} set`:""]}),e.jsx("textarea",{rows:3,value:t,readOnly:a,spellCheck:!1,"aria-label":"Incoming state override (JSON)",onChange:m=>s(m.target.value)}),e.jsxs("span",{className:"w6w-hint",children:["JSON merged into the call (e.g. a script's ",e.jsx("code",{children:"input"}),"). Reach for this to test against a state the flow cannot currently produce — a field no upstream step returns yet, or a case you can't reproduce by running the flow."]})]})]})}function Ms({workflowId:t,step:s,upstreamSteps:o,onRun:a,onCancel:l}){const u=i.useW6WApi(),f=i.isTriggerApp(s.uses.app),b=i.isInternalApp(s.uses.app),C=c.useMemo(()=>{var L;return f?i.asFieldDefs((L=s.with)==null?void 0:L.fields):[]},[f,s.with]),S=c.useMemo(()=>f?i.fieldsToParams(C):b?i.internalNodeParams(s.uses.app,s.uses.action):null,[f,b,C,s.uses.app,s.uses.action]),[m,N]=c.useState(null),d=S??m;c.useEffect(()=>{if(S)return;if(!s.uses.app||!s.uses.action){N([]);return}let L=!1;return N(null),u.getAppActions(s.uses.app).then(Y=>{var E;L||N(((E=Y.find(Q=>Q.key===s.uses.action))==null?void 0:E.params)??[])}).catch(()=>!L&&N([])),()=>{L=!0}},[u,S,s.uses.app,s.uses.action]);const[v,I]=c.useState(()=>{var L;return f?i.seedValues(i.asFieldDefs((L=s.with)==null?void 0:L.fields)):{}}),[A,V]=c.useState("{}"),T=i.useSeedSources(t,o,!f),g=i.startStateFromSeeds(T),[F,me]=c.useState(!1);c.useEffect(()=>{let L=!1;return u.listStepTests(t,s.id).then(Y=>{if(L)return;const E=Y.length?Y[Y.length-1]:null;f?E!=null&&E.with&&I(Q=>({...Q,...E.with})):E!=null&&E.input&&Object.keys(E.input).length>0&&V(JSON.stringify(E.input,null,2)),me(!0)}).catch(()=>{L||me(!0)}),()=>{L=!0}},[u,t,s.id,f]);const[ie,O]=c.useState(!0),j=st(A),D=f?ie:j!==null,ge=f?v:{...s.with??{},...j??{}},z=!!d&&F&&D&&i.requiredParamsFilled(d,ge);return e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsx("div",{className:"w6w-modal-body",children:e.jsx("div",{className:"w6w-stack",children:d===null||!F?e.jsx("p",{className:"w6w-muted w6w-small",children:d===null?"Loading parameters…":"Loading saved values…"}):f?e.jsxs(e.Fragment,{children:[e.jsx(i.PropertyEntryForm,{params:d,values:v,onChange:I,onValidityChange:O}),d.length===0&&e.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to run with. It becomes the trigger's output state (",e.jsx("code",{children:"input"}),")."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Runs ",e.jsx("code",{children:s.uses.action})," with the configuration saved on this node — only the incoming state changes per run. Edit the node to change how it is configured."]}),e.jsx(Bt,{text:A,onChange:V,seeds:T})]})})}),e.jsxs("div",{className:"w6w-modal-actions",children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"}),!z&&d!==null&&F&&e.jsx("span",{className:"w6w-muted w6w-small",children:D?f?"Fill the required fields to test.":"This step is missing required configuration — set it on the Configure tab.":f?"The payload must be a JSON object to run.":"The incoming state must be a JSON object to run."}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:!z,onClick:()=>a(f?v:j??{},f?void 0:g),children:"▶ Run"})]})]})}function ve({type:t,position:s,multiple:o,id:a,variant:l}){const u=_.useNodeId(),f=c.useContext(tt),b=!!u&&!!f&&!f.readOnly,C=()=>{b&&u&&f.onAddFromPort(u,t,a)},S=l==="error"?"a step that handles this step's failure":t==="target"?"a step before this one":"the next step";return e.jsx(_.Handle,{type:t,position:s,id:a,className:l==="error"?"w6w-handle-error":o?"w6w-handle-multi":void 0,style:o?{height:22,borderRadius:3,width:8}:void 0,onClick:b?C:void 0,title:b?`Drag to empty canvas (or click) to add ${S} · drag to a port to connect`:l==="error"?"On error — drag to route this step's failure separately":o?t==="target"?"Accepts multiple incoming connections":"Multiple outgoing connections":void 0})}function Ht({id:t,runnable:s}){const o=c.useContext(tt);return!o||o.readOnly?null:e.jsxs(_.NodeToolbar,{position:_.Position.Top,className:"w6w-node-toolbar",children:[s&&e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Test-run this node","aria-label":"Test-run this node",onClick:()=>o.onRun(t),children:e.jsx(de.Icon,{name:"run",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Edit","aria-label":"Edit node",onClick:()=>o.onEdit(t),children:e.jsx(de.Icon,{name:"edit",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn",title:"Duplicate","aria-label":"Duplicate node",onClick:()=>o.onDuplicate(t),children:e.jsx(de.Icon,{name:"copy",size:15})}),e.jsx("button",{type:"button",className:"w6w-node-toolbar-btn danger",title:"Delete","aria-label":"Delete node",onClick:()=>o.onDelete(t),children:e.jsx(de.Icon,{name:"trash",size:15})})]})}function Jt({step:t,count:s}){if(s<2)return null;const o=t.fanOut==="parallel",a=Ss(s,o?"parallel":"sequential");return e.jsxs("div",{className:"w6w-fanout-badge",role:"img","aria-label":a,title:a,children:[e.jsx("span",{"aria-hidden":"true",children:o?"⇉":"→"})," ",s]})}function Ds({id:t,data:s,selected:o}){var m;const a=s.step,u=c.useContext(et).get(a.uses.app),f=(u==null?void 0:u.displayName)||a.uses.app||"—",b=i.nodePortsForStep(a,c.useContext(Qe)),C=$t(s.stepStatus??"no-run",s.runStatus),S=e.jsx(Jt,{step:a,count:c.useContext(Ze).get(t)??0});return e.jsxs("div",{children:[e.jsx(Ht,{id:t,runnable:!0}),e.jsxs("div",{"data-run-status":s.stepStatus??"no-run","data-step-problem":(m=s.stepProblem)==null?void 0:m.code,title:s.stepProblem?Je(s.stepProblem):void 0,style:{position:"relative",...s.stepProblem?{boxShadow:"0 0 0 2px var(--w6w-danger)"}:{},border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:o?1:C.opacity,background:"var(--w6w-panel)",color:"var(--w6w-text)",borderRadius:4,padding:"8px 12px",minWidth:180,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[s.stepProblem&&e.jsx("span",{"data-step-problem-badge":"",role:"img","aria-label":Je(s.stepProblem),title:Je(s.stepProblem),style:{position:"absolute",top:-9,right:-9,width:18,height:18,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--w6w-danger)",color:"#fff"},children:e.jsx(de.Icon,{name:"warning",size:12})}),b.in>0&&e.jsx(ve,{type:"target",position:_.Position.Left,multiple:b.in>1}),e.jsx(i.AppIcon,{src:u==null?void 0:u.iconSvg,srcDark:u==null?void 0:u.iconSvgDark,brandColor:u==null?void 0:u.brandColor,name:f,size:28}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:600},children:f}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:a.uses.action||"—"})})]}),b.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{type:"source",position:_.Position.Right,multiple:b.out>1}),e.jsx(ve,{type:"source",position:_.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,e.jsxs("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:[a.id,u!=null&&u.version?` - v${u.version}`:""]}),a.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:a.notes,children:a.notes})]})}function Ls({id:t,data:s,selected:o}){const a=s.step,l=i.internalNodeLabel(a.uses.app,a.uses.action),u=i.internalNodeIcon(a.uses.app,a.uses.action),f=i.nodePortsForStep(a,c.useContext(Qe)),b=i.isTriggerApp(a.uses.app),C=$t(s.stepStatus??"no-run",s.runStatus),S=e.jsx(Jt,{step:a,count:c.useContext(Ze).get(t)??0});return e.jsxs("div",{children:[e.jsx(Ht,{id:t,runnable:!i.isControlApp(a.uses.app)}),e.jsxs("div",{className:b?"w6w-node-trigger":void 0,"data-node-kind":b?"trigger":void 0,"data-run-status":s.stepStatus??"no-run",style:{position:"relative",border:`${C.borderWidth}px ${C.borderStyle} ${o?"var(--w6w-accent)":C.borderColor}`,opacity:o?1:C.opacity,background:"var(--w6w-panel-2)",color:"var(--w6w-text)",...b?{}:{borderRadius:4,padding:"6px 14px 6px 8px"},minWidth:140,fontSize:13,display:"flex",alignItems:"center",gap:10},children:[f.in>0&&e.jsx(ve,{type:"target",position:_.Position.Left,multiple:f.in>1}),u&&e.jsx(i.InternalIcon,{icon:u}),e.jsxs("div",{style:{minWidth:0,textAlign:"left"},children:[e.jsx("div",{style:{fontWeight:600},children:l}),e.jsx("div",{className:"w6w-muted w6w-small",style:{marginTop:2},children:e.jsx("code",{children:a.uses.action||"—"})})]}),f.out>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{type:"source",position:_.Position.Right,multiple:f.out>1}),!b&&e.jsx(ve,{type:"source",position:_.Position.Bottom,multiple:!1,id:i.ERROR_SOURCE_HANDLE,variant:"error"})]})]}),S,e.jsx("div",{className:"w6w-muted",style:{marginTop:3,fontSize:10,opacity:.75,paddingLeft:2},children:a.id}),a.notes&&e.jsx("div",{className:"w6w-muted w6w-node-notes",title:a.notes,children:a.notes})]})}function _s({workflowId:t,step:s,upstreamSteps:o,onChange:a,onClose:l,readOnly:u,initialView:f="props",fanOutCount:b=0,onTestRun:C,stepProblem:S}){var Me;const m=i.useW6WApi(),N=c.useContext(et),[d,v]=c.useState(s),I=kt(d,S),[A,V]=c.useState(kt(s,S)?"setup":"configure"),[T,g]=c.useState(f==="json"?"code":f==="settings"?"config":"props"),[F,me]=c.useState("props"),[ie,O]=c.useState(()=>i.stepToJson(s)),[j,D]=c.useState(()=>i.paramsToJson(s)),[ge,z]=c.useState("{}"),L=c.useRef(null),[Y,E]=c.useState(!1),[Q,se]=c.useState(!1),[xe,J]=c.useState(d.id),[ae,ne]=c.useState(null),[oe,W]=c.useState(null),[pe,be]=c.useState(null),[je,B]=c.useState(null),[le,Ce]=c.useState(!1),U=i.isInternalApp(d.uses.app);c.useEffect(()=>{if(U){W(i.internalNodeParams(d.uses.app,d.uses.action)),be(null);return}if(!d.uses.app){be(null),W([]);return}let x=!1;return W(null),m.getAppActions(d.uses.app).then(K=>{var ee;x||(be(K),W(d.uses.action?((ee=K.find(ue=>ue.key===d.uses.action))==null?void 0:ee.params)??[]:[]))}).catch(()=>!x&&W([])),()=>{x=!0}},[m,d.uses.app,d.uses.action,U]);const Ne=c.useCallback(()=>{U||!d.uses.app||m.listConnectionsForApp(d.uses.app).then(x=>{B(x),Ce(!1)}).catch(()=>Ce(!0))},[m,d.uses.app,U]);c.useEffect(()=>{if(U||!d.uses.app)return;let x=!1;return m.listConnectionsForApp(d.uses.app).then(K=>{x||(B(K),Ce(!1))}).catch(()=>!x&&Ce(!0)),()=>{x=!0}},[m,d.uses.app,U]);const q=c.useCallback(x=>{v(x),a(x)},[a]),ke=x=>{x==="code"?O(i.stepToJson(d)):x==="params-code"&&D(i.paramsToJson(d)),g(x)},fe=()=>{const x=xe.trim(),K=x&&x!==d.id?i.stepIdError(x):null;if(K){ne(K);return}x&&x!==d.id&&q({...d,id:x}),ne(null),se(!1)},H=!!d.uses.app&&!!d.uses.action&&!i.isControlApp(d.uses.app),Z=i.isTriggerApp(d.uses.app),ce=A==="test"&&H&&!Z,he=i.useSeedSources(t,o,H&&!Z),Re=i.startStateFromSeeds(he);c.useEffect(()=>{if(!H||Z)return;let x=!1;return m.listStepTests(t,d.id).then(K=>{if(x)return;const ee=K.length?K[K.length-1]:null;if(!(ee!=null&&ee.input)||Object.keys(ee.input).length===0)return;const ue=JSON.stringify(ee.input,null,2);z(re=>re.trim()==="{}"?ue:re)}).catch(()=>{}),()=>{x=!0}},[m,t,d.id,H,Z]);const Ee=st(ge),M={...d.with??{},...Ee??{}},Ie=Ee??{},Fe=!!oe&&i.requiredParamsFilled(oe,M),$=N.get(d.uses.app),Pe=U?i.internalNodeIcon(d.uses.app,d.uses.action):null,Ae=U?Pe?e.jsx(i.InternalIcon,{icon:Pe}):null:e.jsx(i.AppIcon,{src:$==null?void 0:$.iconSvg,srcDark:$==null?void 0:$.iconSvgDark,brandColor:$==null?void 0:$.brandColor,name:$==null?void 0:$.displayName});return e.jsx(i.Modal,{ariaLabel:"Edit step",titleIcon:Ae,title:e.jsxs("span",{className:"w6w-step-rename",children:[Q&&!u?e.jsx("input",{autoFocus:!0,value:xe,onChange:x=>{J(x.target.value),ne(null)},onBlur:fe,onKeyDown:x=>{x.key==="Enter"&&fe(),x.key==="Escape"&&(J(d.id),ne(null),se(!1))}}):e.jsxs(e.Fragment,{children:[e.jsx("code",{children:d.id}),!u&&e.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Rename node","aria-label":"Rename node",onClick:()=>{J(d.id),se(!0)},children:e.jsx(de.Icon,{name:"edit",size:15})})]}),ae&&e.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:ae})]}),onClose:l,size:"wide",children:e.jsxs("div",{className:"w6w-stepconfig",children:[e.jsxs("div",{className:"w6w-tabsbar",children:[e.jsx("div",{className:"w6w-subtabs",children:["setup","configure","test"].map(x=>e.jsx("button",{type:"button",className:`w6w-subtab${A===x?" active":""}`,disabled:I&&x!=="setup",onClick:()=>V(x),children:x==="setup"?"Setup":x==="configure"?"Configure":"Test"},x))}),ce?e.jsx(i.ConfigViewToggle,{view:F,views:["props","code"],onChange:x=>me(x)}):e.jsx(i.ConfigViewToggle,{view:T,onChange:ke,disabled:A!=="configure"})]}),I&&S&&e.jsxs("div",{role:"alert",className:"w6w-field-error",children:["Connection ",S.connection," no longer exists — choose another to continue."]}),e.jsxs("div",{className:"w6w-stepconfig-body",children:[A==="setup"&&e.jsx($s,{step:d,app:$,actions:pe,conns:je,connsFailed:le,isInternal:U,readOnly:u,onChangeAction:x=>q({...d,uses:{...d.uses,action:x},with:{}}),onChangeConnection:x=>q({...d,uses:{...d.uses,connection:x}}),onConnectionCreated:Ne,onChangeApp:x=>q(x===d.uses.app?d:{...d,uses:{app:x,action:"",connection:void 0},with:{}})}),A==="configure"&&e.jsxs(e.Fragment,{children:[d.uses.app===i.WEBHOOK_APP&&m.listSubscriptionsForWorkflow&&m.createSubscription&&e.jsx(Os,{workflowId:t,step:d,readOnly:u}),oe===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):T==="props"?d.uses.action==="wait"&&i.isControlApp(d.uses.app)?e.jsx(i.WaitEditor,{values:d.with??{},readOnly:u,onChange:x=>q({...d,with:x})}):e.jsx(i.ParamsForm,{params:oe,values:d.with??{},readOnly:u,onChange:x=>q({...d,with:x}),dynamic:U||!d.uses.action?void 0:{appId:d.uses.app,actionKey:d.uses.action,connectionId:I?void 0:d.uses.connection??void 0,appName:$==null?void 0:$.displayName}}):T==="code"?e.jsx(i.JsonEditor,{value:ie,onChange:()=>{},readOnly:!0,minHeight:"260px",height:"100%","aria-label":`Node ${d.id} JSON`,copyable:!0}):T==="params-code"?e.jsx(i.JsonEditor,{value:j,onChange:D,readOnly:u,minHeight:"260px",height:"100%","aria-label":`Node ${d.id} params JSON`,copyable:!0,onValidChange:x=>x&&typeof x=="object"&&!Array.isArray(x)&&q({...d,with:x})}):e.jsxs("div",{className:"w6w-stack",children:[e.jsx(i.NodeConfigForm,{config:{retry:d.retry,onError:d.onError,notes:d.notes},onChange:x=>q({...d,...x}),readOnly:u,failureHandling:!Z,retryControls:!i.isControlApp(d.uses.app)&&d.uses.app!==i.CALL_APP}),Vs,e.jsx(Ws,{step:d,count:b,readOnly:u,onChange:q})]})]}),A==="test"&&e.jsx("div",{className:"w6w-stack",children:H?Z?e.jsx(i.TriggerFillForm,{app:d.uses.app,action:d.uses.action,fields:(Me=d.with)==null?void 0:Me.fields,persist:{workflowId:t,stepId:d.id,input:Ie}}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:["Tests ",e.jsx("code",{children:d.uses.action})," with the configuration saved on this step — only the incoming state changes per run."]}),e.jsx(Bt,{text:ge,onChange:z,seeds:he,readOnly:u}),oe===null?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading parameters…"}):e.jsx(ls,{params:oe,values:M,testStartState:Re,view:F}),e.jsx(i.StepTestRun,{ref:L,app:d.uses.app,action:d.uses.action,connectionId:d.uses.connection??void 0,values:M,state:Re,canRun:Fe,hideRunButton:!0,persist:{workflowId:t,stepId:d.id,input:Ie},onBusyChange:E})]}):e.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes can't be tested on their own."})})]}),e.jsx("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:A!=="test"?e.jsx("button",{type:"button",className:"w6w-btn",disabled:I,onClick:()=>V(A==="setup"?"configure":"test"),children:"Next →"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Done"}),H&&!Z&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:u||!Fe||Y,onClick:()=>{var x;C==null||C(),(x=L.current)==null||x.run()},children:Y?"Testing…":"Test"})]})})]})})}const Vs=!1;function Ws({step:t,count:s,readOnly:o,onChange:a}){const l=s>=2,u=t.fanOut==="parallel"?"parallel":"sequential";return e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Run next nodes"}),e.jsxs("select",{"aria-label":"Run next nodes",value:u,disabled:o||!l,onChange:f=>a(ys(t,f.target.value)),children:[e.jsx("option",{value:"sequential",children:"In sequence"}),e.jsx("option",{value:"parallel",children:"In parallel"})]}),!l&&e.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function Os({workflowId:t,step:s,readOnly:o}){const a=i.useW6WApi(),[l,u]=c.useState(void 0),[f,b]=c.useState(null),[C,S]=c.useState(!1);c.useEffect(()=>{const N=a.listSubscriptionsForWorkflow;if(!N)return;let d=!1;return N(t).then(v=>{d||u(v.find(I=>I.appId===i.WEBHOOK_APP)??null)}).catch(v=>!d&&b(v.message)),()=>{d=!0}},[a,t]);const m=()=>{const N=a.createSubscription;N&&(b(null),S(!0),N(i.WEBHOOK_APP,s.uses.action,{workflowId:t,connectionId:null,params:s.with??{}}).then(d=>{S(!1),u(d)}).catch(d=>{S(!1),b(d instanceof Error?d.message:String(d))}))};return e.jsxs("div",{className:"w6w-stack",children:[e.jsxs("p",{className:"w6w-muted w6w-small",children:[e.jsx("strong",{children:"Webhook URL"})," — the address a third party posts to."]}),f&&e.jsx("div",{className:"w6w-result w6w-error",children:f}),l!=null&&l.webhookUrl?e.jsx(de.Copyable,{value:l.webhookUrl,readOnly:!0,children:e.jsx("input",{type:"text",readOnly:!0,value:l.webhookUrl,"aria-label":"Webhook URL"})}):l===void 0?e.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):!o&&e.jsx("button",{type:"button",className:"w6w-btn",disabled:C,onClick:m,children:C?"Creating…":"Create webhook URL"})]})}function Tt({anchorRef:t,onClose:s,children:o}){const a=c.useRef(null),[l,u]=c.useState(null),[f,b]=c.useState(null);return c.useEffect(()=>{const C=t.current;if(!C)return;const S=C.getBoundingClientRect();u({top:S.bottom+6,left:S.left,width:S.width}),b(C.closest("dialog")??document.body)},[t]),c.useEffect(()=>{function C(m){var d,v;const N=m.target;(d=a.current)!=null&&d.contains(N)||(v=t.current)!=null&&v.contains(N)||s()}function S(m){m.key==="Escape"&&s()}return document.addEventListener("mousedown",C),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",S)}},[s,t]),!l||!f?null:ss.createPortal(e.jsx("div",{ref:a,className:"w6w-flyout",style:{top:l.top,left:l.left,width:l.width},children:o}),f)}function $s({step:t,app:s,actions:o,conns:a,connsFailed:l,isInternal:u,readOnly:f,onChangeAction:b,onChangeConnection:C,onChangeApp:S,onConnectionCreated:m}){const[N,d]=c.useState(null),[v,I]=c.useState(!1),A=c.useRef(null),V=Ps(t.uses.connection,a,l);return e.jsxs("div",{className:"w6w-stack",children:[e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"App"}),e.jsxs("div",{className:"w6w-app-conn-row",ref:A,children:[e.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App","aria-expanded":N==="app",disabled:f,onClick:()=>d(T=>T==="app"?null:"app"),children:[!u&&s&&e.jsx(i.AppIcon,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,size:20}),e.jsx("span",{className:"w6w-conn-label-name",children:u?t.uses.app:(s==null?void 0:s.displayName)??t.uses.app})]}),!u&&e.jsx("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"Connection","aria-expanded":N==="conn",disabled:f,onClick:()=>d(T=>T==="conn"?null:"conn"),children:e.jsx("span",{className:"w6w-conn-label-name",children:V})})]}),N==="app"&&e.jsx(Tt,{anchorRef:A,onClose:()=>d(null),children:e.jsx(i.AppPicker,{onSelectApp:T=>{const g=T.id===t.uses.app;S(T.id),d(g?"conn":null)}})}),N==="conn"&&e.jsx(Tt,{anchorRef:A,onClose:()=>d(null),children:e.jsxs("div",{className:"w6w-stack",children:[e.jsx("div",{className:"w6w-stepbuilder-list",children:(a??[]).map(T=>e.jsx("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>{C(T.id),d(null)},children:e.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[e.jsx("strong",{children:T.displayName||T.id}),T.state&&e.jsx("span",{className:"w6w-muted w6w-small",children:T.state})]})},T.id))}),e.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>{I(!0),d(null)},children:"+ New connection"})]})})]}),!u&&v&&e.jsx(i.AddConnectionModal,{initialAppId:t.uses.app,onClose:()=>I(!1),onCreated:({connectionId:T})=>{I(!1),C(T),m(),d(null)}}),u?e.jsxs("div",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx("div",{className:"w6w-muted w6w-small",children:e.jsx("code",{children:t.uses.action})})]}):e.jsxs("label",{className:"w6w-field",children:[e.jsx("span",{children:"Action"}),e.jsx(i.Combobox,{value:t.uses.action,disabled:f||o===null,onChange:b,options:o===null?[{value:t.uses.action,label:t.uses.action}]:o.map(T=>({value:T.key,label:T.title??T.key}))})]})]})}exports.CALL_APP=i.CALL_APP;exports.CONTROL_APP=i.CONTROL_APP;exports.CanvasLayer=i.CanvasLayer;exports.DATA_APP=i.DATA_APP;exports.ExpressionOptionsProvider=i.ExpressionOptionsProvider;exports.INTERNAL_NODES=i.INTERNAL_NODES;exports.Markdown=i.Markdown;exports.SCHEDULER_APP=i.SCHEDULER_APP;exports.SCRIPT_APP=i.SCRIPT_APP;exports.TRIGGER_APP=i.TRIGGER_APP;exports.WEBHOOK_APP=i.WEBHOOK_APP;exports.asFieldDefs=i.asFieldDefs;exports.coerceDefault=i.coerceDefault;exports.fieldWidget=i.fieldWidget;exports.fieldsToParams=i.fieldsToParams;exports.flowToWorkflow=i.flowToWorkflow;exports.internalNodeDefaults=i.internalNodeDefaults;exports.internalNodeIcon=i.internalNodeIcon;exports.internalNodeLabel=i.internalNodeLabel;exports.internalNodeParams=i.internalNodeParams;exports.isControlApp=i.isControlApp;exports.isInternalApp=i.isInternalApp;exports.isTriggerApp=i.isTriggerApp;exports.seedValues=i.seedValues;exports.workflowToFlow=i.workflowToFlow;exports.MAX_NOTES=Rt;exports.MAX_NOTE_BYTES=Ft;exports.MAX_SECTIONS=It;exports.WorkflowFlowEditor=Is;exports.assignMembership=Ke;exports.clampCanvas=Xe;exports.pruneSectionMembers=qe;exports.renameSectionMember=Dt;exports.roundGeometry=Ue;exports.sectionsContaining=Lt;exports.withCanvasGeometry=Mt;
3
3
  //# sourceMappingURL=flow.cjs.map