@w6w/ui 0.1.0 → 0.2.0

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 (47) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +25 -8
  3. package/dist/AppPicker.d.ts +1 -0
  4. package/dist/ConfirmModal-ChoiGy2K.cjs +11 -0
  5. package/dist/ConfirmModal-ChoiGy2K.cjs.map +1 -0
  6. package/dist/{ConfirmModal-sY1tzkBO.js → ConfirmModal-Wx3i8F1n.js} +4470 -4446
  7. package/dist/ConfirmModal-Wx3i8F1n.js.map +1 -0
  8. package/dist/ConnectionHeader.d.ts +19 -0
  9. package/dist/EditConnectionModal.d.ts +21 -0
  10. package/dist/app-pages.d.ts +3 -0
  11. package/dist/code.cjs +1 -1
  12. package/dist/code.mjs +1 -0
  13. package/dist/code.mjs.map +1 -1
  14. package/dist/components/AuthFieldsForm.d.ts +8 -1
  15. package/dist/components/CallableList.d.ts +57 -0
  16. package/dist/components/ConnectionList.d.ts +44 -0
  17. package/dist/components/ListItem.d.ts +16 -6
  18. package/dist/components/ReliabilityChart.d.ts +10 -0
  19. package/dist/components/ReliabilityList.d.ts +47 -0
  20. package/dist/connection-app-meta.d.ts +32 -0
  21. package/dist/flow.cjs +1 -1
  22. package/dist/flow.cjs.map +1 -1
  23. package/dist/flow.d.ts +3 -1
  24. package/dist/flow.mjs +50 -49
  25. package/dist/flow.mjs.map +1 -1
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +16 -0
  29. package/dist/index.mjs +1701 -891
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/provider.d.ts +21 -1
  32. package/dist/reliability-board-layout.d.ts +121 -0
  33. package/dist/types.d.ts +8 -0
  34. package/package.json +3 -2
  35. package/src/code.css +23 -4
  36. package/src/styles/_callable-list.scss +60 -0
  37. package/src/styles/_connections.scss +100 -0
  38. package/src/styles/_flow.scss +4 -4
  39. package/src/styles/_lists.scss +4 -0
  40. package/src/styles/_reliability.scss +339 -0
  41. package/src/styles/_tokens.scss +23 -4
  42. package/src/styles.css +4386 -3108
  43. package/src/styles.scss +3 -0
  44. package/dist/ConfirmModal-DJPYXE9t.cjs +0 -11
  45. package/dist/ConfirmModal-DJPYXE9t.cjs.map +0 -1
  46. package/dist/ConfirmModal-sY1tzkBO.js.map +0 -1
  47. package/dist/ui.css +0 -1
package/src/styles.scss CHANGED
@@ -59,3 +59,6 @@
59
59
  @use "styles/execution-log";
60
60
  @use "styles/execution-history";
61
61
  @use "styles/server-resources";
62
+ @use "styles/reliability";
63
+ @use "styles/callable-list";
64
+ @use "styles/connections";
@@ -1,11 +0,0 @@
1
- "use strict";const t=require("react/jsx-runtime"),d=require("react"),Mt=require("@codemirror/lang-json"),Ot=require("@codemirror/lint"),Gt=require("@codemirror/view"),Kt=require("@uiw/react-codemirror"),ue=require("./Copyable-CYZU1o4X.cjs"),Us=require("@codemirror/lang-javascript"),Bs=require("@codemirror/lang-python"),oe=require("@w6w/expr"),Yt=d.createContext(void 0);function Ft(e,s){var r;if(e)return e;if(s)return s;if(typeof document>"u")return"light";const n=document.documentElement.getAttribute("data-theme");return n==="dark"||n==="light"?n:(r=window.matchMedia)!=null&&r.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"}function Ue(e){const s=d.useContext(Yt),[n,r]=d.useState(()=>Ft(e,s));return d.useEffect(()=>{if(e){r(e);return}if(s){r(s);return}if(typeof window>"u")return;const o=()=>r(Ft(void 0,s)),a=window.matchMedia("(prefers-color-scheme: dark)");a.addEventListener("change",o);const l=new MutationObserver(o);return l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),o(),()=>{a.removeEventListener("change",o),l.disconnect()}},[e,s]),n}function Js(e){switch(e){case"javascript":return Us.javascript();case"python":return Bs.python()}}function Xt(e){const s=Ue(e.theme),n=d.useMemo(()=>[...e.language?[Js(e.language)]:[],Gt.EditorView.theme({"&":{fontSize:"13px",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",backgroundColor:"var(--w6w-panel-2)",color:"var(--w6w-text)",border:"1px solid var(--w6w-border)",borderRadius:"8px"},"&.cm-focused":{outline:"2px solid var(--w6w-accent)"},".cm-gutters":{backgroundColor:"var(--w6w-panel)",color:"var(--w6w-muted)",border:"none",borderRight:"1px solid var(--w6w-border)"},".cm-scroller":{overflow:"auto"}})],[e.language]);return t.jsx("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:t.jsx(Kt,{value:e.value,onChange:e.onChange,extensions:n,placeholder:e.placeholder,readOnly:e.readOnly,theme:s,height:e.height,minHeight:e.minHeight??"160px",maxHeight:e.maxHeight,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!e.readOnly,bracketMatching:!0,closeBrackets:!0}})})}function ce(e){const s=Ue(e.theme),{copied:n,copy:r}=ue.useCopyToClipboard(e.value),o=d.useMemo(()=>[Mt.json(),Ot.linter(Mt.jsonParseLinter()),Ot.lintGutter(),Gt.EditorView.theme({"&":{fontSize:"13px",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",backgroundColor:"var(--w6w-panel-2)",color:"var(--w6w-text)",border:"1px solid var(--w6w-border)",borderRadius:"8px"},"&.cm-focused":{outline:"2px solid var(--w6w-accent)"},".cm-gutters":{backgroundColor:"var(--w6w-panel)",color:"var(--w6w-muted)",border:"none",borderRight:"1px solid var(--w6w-border)"},".cm-scroller":{overflow:"auto"}})],[]);function a(l){var i,c,u,m;if(e.onChange(l),!(!e.onValidChange&&!e.onValidityChange)){if(l.trim().length===0){(i=e.onValidityChange)==null||i.call(e,{valid:!1,error:"Empty"});return}try{const w=JSON.parse(l);(c=e.onValidChange)==null||c.call(e,w),(u=e.onValidityChange)==null||u.call(e,{valid:!0})}catch(w){(m=e.onValidityChange)==null||m.call(e,{valid:!1,error:w.message})}}}return t.jsxs("div",{className:"w6w-json-editor","aria-label":e["aria-label"]??"JSON editor",children:[t.jsx(Kt,{value:e.value,onChange:a,extensions:o,placeholder:e.placeholder,readOnly:e.readOnly,editable:!e.readOnly,theme:s,height:e.height,minHeight:e.minHeight??"240px",maxHeight:e.maxHeight,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:!e.readOnly,autocompletion:!0,bracketMatching:!0,closeBrackets:!0}}),e.copyable&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:`w6w-icon-btn w6w-copyable-btn${n?" is-copied":""}`,"aria-label":"Copy",onClick:()=>void r(),children:n?t.jsx(ue.CheckGlyph,{}):t.jsx(ue.CopyGlyph,{})}),t.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:n?"Copied":""})]})]})}const ft=d.forwardRef(function(s,n){const{label:r,children:o,icon:a,iconSize:l,title:i,onClick:c,disabled:u,className:m,danger:w,...h}=s,f=o??(a?t.jsx(ue.Icon,{name:a,size:l??16}):null);return t.jsx("button",{ref:n,type:"button",className:["w6w-icon-button",w?"w6w-icon-button-danger":"",m??""].filter(Boolean).join(" "),title:i??r,"aria-label":r,"aria-pressed":h["aria-pressed"],"aria-expanded":h["aria-expanded"],"aria-controls":h["aria-controls"],disabled:u,onClick:c,"data-testid":h["data-testid"],children:f})});ft.displayName="IconButton";const zs={default:"",wide:" w6w-modal-wide",xl:" w6w-modal-xl",full:" w6w-modal-full",fullscreen:" w6w-modal-fullscreen"};function ne({title:e,ariaLabel:s,onClose:n,children:r,size:o="default",titleIcon:a,subtitle:l,headerRight:i}){const c=d.useRef(null);return d.useEffect(()=>{const u=c.current;if(!u)return;u.open||u.showModal();const m=h=>{h.preventDefault(),n()},w=h=>{if(h.target!==u)return;const f=u.getBoundingClientRect();(h.clientX<f.left||h.clientX>f.right||h.clientY<f.top||h.clientY>f.bottom)&&n()};return u.addEventListener("cancel",m),u.addEventListener("click",w),()=>{u.removeEventListener("cancel",m),u.removeEventListener("click",w)}},[n]),t.jsx("div",{className:"w6w-modal-backdrop",children:t.jsxs("dialog",{ref:c,className:`w6w-modal${zs[o]}`,"aria-label":s??(typeof e=="string"?e:void 0),children:[t.jsxs("div",{className:"w6w-modal-header",children:[t.jsxs("h3",{className:"w6w-modal-title",children:[a,t.jsx("span",{children:e}),l&&t.jsx("span",{className:"w6w-modal-subtitle",children:l})]}),i]}),r]})})}function Be(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="expr"&&Array.isArray(e.parts)}function mt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function Gs(e){return e.kind==="text"?{kind:"text",value:e.value??""}:e.kind==="expr"?{kind:"expr",expr:e.expr}:{kind:e.kind,ref:e.ref??""}}function Te(e){const s=e.filter(n=>n.kind!=="text"||(n.value??"")!=="");return s.length===0?"":s.length===1&&s[0].kind==="text"?s[0].value??"":{type:"expr",parts:s.map(Gs)}}const Qt={vars:!0,steps:!0,trigger:!0,foreach:!0,inputs:!0,output:!0,secrets:!0,documents:!0};Object.freeze(Object.keys(Qt));const $t=e=>Object.prototype.hasOwnProperty.call(Qt,e);function Lt(e){const s=e.indexOf(".");return s===-1?e:e.slice(0,s)}function _e(e){const s=oe.parseTemplate(e);return s.every(r=>{if(r.kind==="var"){const o=r.ref??"";return!oe.hasRefusedChainToken(o)&&$t(Lt(o))}if(r.kind==="expr"){const o=oe.coalesceOperandRefs(r.expr);return o===null?!0:o.every(a=>$t(Lt(a)))}return!0})?s:[{kind:"text",value:e}]}function at(e){if(mt(e))return{parts:[],sealed:e};if(Be(e))return{parts:e.parts.map(n=>({...n})),sealed:null};const s=typeof e=="string"?e:"";return{parts:s?_e(s):[],sealed:null}}function Ks(e,s){let n="";for(const r of e)switch(r.kind){case"text":n+=r.value??"";break;case"var":case"render":{const o=r.ref??"";n+=o in s?s[o]:"";break}case"secret":n+="•••";break;case"expr":n+=oe.serializeTemplate([r]);break}return n}const Ys=/^steps\.([^.]+)\.output(?:\.(.+))?$/,Xs=/^steps\.([^.]+)\.meta\.(app|version|action|connectionId)$/,he=e=>{if(e.startsWith("vars."))return e.slice(5);const s=Ys.exec(e);if(s)return s[2]?`${s[1]}.${s[2]}`:s[1];const n=Xs.exec(e);return n?`${n[1]} meta · ${n[2]}`:e};function Qs(e){if(e===null||typeof e!="object"||Array.isArray(e))return;const s=Object.keys(e);if(s.length!==1||s[0]!=="var")return;const n=e.var;return typeof n=="string"?n:void 0}function Zs(e){const s=e.op==="or"?"||":"??",n=e.operands.map(r=>{const o=Qs(r);return o!==void 0?he(o):JSON.stringify(r)}).join(` ${s} `);return n.length>40?`${n.slice(0,40)}…`:n}const en=/[.{}]/;function ot(e){return e===""||e!==e.trim()?!1:!en.test(e)}function tn(e){return e.split(".").every(ot)}function Re(e,s,{renderToggle:n}={}){const r=e.createElement("span");r.contentEditable="false",r.className=`w6w-expr-chip w6w-expr-chip-${s.kind}`,r.setAttribute("data-kind",s.kind);const o=e.createElement("span");o.className="w6w-expr-chip-sigil";const a=e.createElement("span");if(a.className="w6w-expr-chip-label",s.kind==="var")r.setAttribute("data-ref",s.ref??""),o.textContent="◆",a.textContent=he(s.ref??""),r.title=`Variable: ${s.ref??""}`;else if(s.kind==="render")r.setAttribute("data-ref",s.ref??""),o.textContent="▤",a.textContent=he(s.ref??""),r.title=`Render as template: ${s.ref??""}`;else if(s.kind==="secret")r.setAttribute("data-ref",s.ref??""),o.textContent="🔒",a.textContent=s.ref??"",r.title=`Secret: ${s.ref??""}`;else{const i=typeof s.expr=="string"?s.expr:JSON.stringify(s.expr??"");r.setAttribute("data-expr",i),o.textContent="ƒ";const c=oe.parseCoalesceChain(s.expr);c?(a.textContent=Zs(c),r.title=`Expression: ${oe.serializeTemplate([s])}`):(a.textContent=i.length>24?`${i.slice(0,24)}…`:i||"expr",r.title=`Expression: ${i}`)}if(r.append(o,a),(s.kind==="var"||s.kind==="render")&&n){const i=e.createElement("span");i.className="w6w-expr-chip-toggle",i.setAttribute("data-render-toggle","1"),i.setAttribute("role","button");const c=s.kind==="render"?"Stop rendering as a template":"Render this as a template";i.setAttribute("aria-label",c),i.title=c,i.textContent="⇄",r.append(i)}const l=e.createElement("span");return l.className="w6w-expr-chip-x",l.setAttribute("data-x","1"),l.setAttribute("role","button"),l.setAttribute("aria-label","Remove"),l.textContent="×",r.append(l),r}const Zt=new Set(["div","p"]);function es(e){const s=e.getAttribute("data-kind");if(s==="var"||s==="secret"||s==="render")return{kind:s,ref:e.getAttribute("data-ref")??""};if(s==="expr"){const n=e.getAttribute("data-expr")??"";let r=n;try{r=JSON.parse(n)}catch{r=n}return{kind:"expr",expr:r}}return null}function Ae(e){const s=[],n=a=>{if(!a)return;const l=s[s.length-1];l&&l.kind==="text"?l.value=(l.value??"")+a:s.push({kind:"text",value:a})},r=(a,l)=>{if(a.nodeType===Node.TEXT_NODE){n(a.textContent??"");return}if(a.nodeType!==Node.ELEMENT_NODE)return;const i=a,c=es(i);if(c){s.push(c);return}const u=(i.tagName??"").toLowerCase();if(u==="br"){l||n(`
2
- `);return}const m=Zt.has(u);m&&s.length>0&&n(`
3
- `),o(i,m)},o=(a,l)=>{const i=Array.from(a.childNodes);i.forEach((c,u)=>r(c,l&&u===i.length-1))};return o(e,!0),s}const ts=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function ss(e){ts(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function sn(e){const s=e.ownerDocument.getSelection(),n=s!=null&&s.rangeCount?s.getRangeAt(0):null;if(!n||!e.contains(n.endContainer))return e;let r=n.endContainer;for(;r&&r!==e;){if(r.nodeType===Node.ELEMENT_NODE){const o=r;if(Zt.has((o.tagName??"").toLowerCase()))return o}r=r.parentNode}return e}function ns(e){ss(sn(e))}const nn=e=>e.getAttribute("aria-multiline")!=="false";function rs(e,s,n){var a;const r=e.ownerDocument;e.textContent="";for(const l of s)l.kind==="text"?l.value&&e.appendChild(r.createTextNode(l.value)):e.appendChild(Re(r,l,n));const o=s[s.length-1];(o==null?void 0:o.kind)==="text"&&((a=o.value)!=null&&a.endsWith(`
4
- `))&&nn(e)&&ss(e)}function bt(e){const s=e.ownerDocument.getSelection();if(!s)return;const n=e.ownerDocument.createRange();n.selectNodeContents(e),n.collapse(!1),s.removeAllRanges(),s.addRange(n)}function Ee(e,s){const n=e.ownerDocument,r=n.getSelection(),o=r!=null&&r.rangeCount?r.getRangeAt(0):null;if(o&&e.contains(o.commonAncestorContainer)){o.deleteContents(),o.insertNode(s);const a=n.createRange();a.setStartAfter(s),a.collapse(!0),r==null||r.removeAllRanges(),r==null||r.addRange(a)}else ts(e.lastChild)?e.insertBefore(s,e.lastChild):e.appendChild(s),bt(e);e.focus()}function as(e,s={}){const n=e.ownerDocument,r=n.getSelection();if(!r||r.rangeCount===0||!r.isCollapsed)return!1;const o=r.getRangeAt(0),a=o.startContainer;if(a.nodeType!==Node.TEXT_NODE||!e.contains(a))return!1;const l=o.startOffset,i=a.textContent??"";if(l<2||i.slice(l-2,l)!=="}}")return!1;const c=i.lastIndexOf("{{",l-2);if(c===-1)return!1;const u=i.slice(c,l),m=_e(u);if(m.length!==1||m[0].kind==="text")return!1;const w=n.createRange();w.setStart(a,c),w.setEnd(a,l),w.deleteContents();const h=Re(n,m[0],s);w.insertNode(h);const f=n.createRange();return f.setStartAfter(h),f.collapse(!0),r.removeAllRanges(),r.addRange(f),!0}function os(e){const s=es(e);if(!s)return null;const n=e.ownerDocument.createTextNode(oe.serializeTemplate([s]));return e.replaceWith(n),n}function xt({value:e,masked:s,multiline:n,options:r,fieldLabel:o,onSave:a,onClose:l,mode:i,onBind:c}){const u=i==="json-binding",[m,w]=d.useState(()=>at(e).parts),[h,f]=d.useState(0),p=d.useRef(null),b=d.useRef(!1),[S,y]=d.useState({}),[x,v]=d.useState(null),[N,E]=d.useState(()=>new Set),k=g=>{E(O=>{const F=new Set(O);return F.has(g)?F.delete(g):F.add(g),F})};d.useLayoutEffect(()=>{const g=p.current;g&&(rs(g,m,{renderToggle:!0}),b.current&&(b.current=!1,bt(g),g.focus()))},[h]);const P=()=>{const g=p.current;g&&w(Ae(g))},A=g=>{const O=p.current;O&&(Ee(O,Re(O.ownerDocument,g,{renderToggle:!0})),w(Ae(O)))},I=m.some(g=>g.kind==="render"),L=(g,{restoreFocus:O})=>{w(_e(g)),f(F=>F+1)},D=()=>{const g=p.current;a==null||a(Te(g?Ae(g):m)),l()},j=g=>{u?c==null||c({$:g.ref??""}):a==null||a(Te([g])),l()},C=()=>{v(null),b.current=!0,f(g=>g+1)},_=r.vars??[],U=r.secrets??[],M=r.inputs??[],W=r.documents??[],H=r.steps??[],X=H.length>0||!!r.hasTrigger,ee=oe.serializeTemplate(m),G=d.useMemo(()=>{const g={};for(const[O,F]of Object.entries(r.sampleValues??{}))g[O]=typeof F=="string"?F:JSON.stringify(F);return{...g,...S}},[r.sampleValues,S]),J=d.useMemo(()=>{const g=new Set,O=[];for(const F of m)(F.kind==="var"||F.kind==="render")&&F.ref&&!g.has(F.ref)&&(g.add(F.ref),O.push(F.ref));return O},[m]),ae=d.useMemo(()=>{try{return Ks(m,G)}catch{return ee}},[m,G,ee]),K=(g,O,F,V,q=!1,B)=>t.jsxs("div",{className:"w6w-exprmodal-item",style:{display:"flex",alignItems:"center",gap:4,minWidth:0},children:[t.jsxs("button",{type:"button",className:`w6w-exprmodal-source ${F}`,style:{flex:1,minWidth:0},title:q?`Insert ${g}`:`Use ${g}`,"aria-label":B,onClick:()=>q?A(O):j(O),children:[V!==null&&t.jsx("span",{className:"w6w-expr-chip-sigil",children:V}),t.jsx("span",{className:"w6w-exprmodal-source-label",children:g})]}),!u&&t.jsx(ft,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>A(O)})]},`${O.kind}:${O.ref??g}`);return t.jsxs(ne,{title:u?"Bind to a step output":"Edit expression",subtitle:o?t.jsx("code",{children:o}):void 0,onClose:l,size:"full",headerRight:u?t.jsx("div",{className:"w6w-exprmodal-actions",children:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"})}):t.jsxs("div",{className:"w6w-exprmodal-actions",children:[!s&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:I,title:I?"Unavailable — a render part has no plain-text form. Flip it back to a variable first.":"Close the expression and keep the text as a literal value",onClick:()=>{a==null||a(oe.serializeTemplate(m)),l()},children:"Use a plain value"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:l,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",onClick:D,children:"Save"})]}),children:[t.jsxs("div",{className:"w6w-exprmodal",style:u?{gridTemplateColumns:"1fr"}:void 0,children:[t.jsxs("aside",{className:"w6w-exprmodal-sources",children:[u&&!X&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),X&&t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Workflow state"}),r.hasTrigger&&K("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var","⚡"),H.map(g=>{const O=$=>{const Q=N.has(`meta:${$}`);return t.jsxs("button",{type:"button",className:"w6w-exprmodal-toggle-btn","data-testid":"expr-meta-toggle","aria-expanded":Q,title:Q?"Hide metadata":"Show metadata",onClick:()=>k(`meta:${$}`),children:["Metadata ",Q?"⌄":"›"]})},F=(g.outputs??[]).filter($=>$.path?tn($.key):ot($.key)),V=`step:${g.id}`,q=N.has(V),B=K(g.label??g.id,{kind:"var",ref:`steps.${g.id}.output`},"w6w-expr-chip-var",F.length>0?null:"▸",F.length>0);return u?t.jsxs(d.Fragment,{children:[t.jsx("span",{className:"w6w-exprmodal-shape-note",children:g.label??g.id}),K("Entire output",{kind:"var",ref:`steps.${g.id}.output`},"w6w-expr-chip-var","▸",!1,`Entire output of ${g.label??g.id}`),g.needsTest&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:t.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),F.length>0&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w6w-exprmodal-source-row",children:[t.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":q,"aria-label":q?"Hide fields":"Show fields",title:q?"Hide fields":"Show fields",onClick:()=>k(V),children:q?"▾":"▸"}),t.jsx(tt,{count:F.length,open:q,onToggle:()=>k(V)})]}),q&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:F.map($=>{const Q=`steps.${g.id}.output.${$.key}`;return K(he(Q),{kind:"var",ref:Q},"w6w-expr-chip-var","·")})})]})]},g.id):t.jsxs(d.Fragment,{children:[F.length>0?t.jsxs("div",{className:"w6w-exprmodal-source-row",children:[t.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":q,"aria-label":q?"Hide fields":"Show fields",title:q?"Hide fields":"Show fields",onClick:()=>k(V),children:q?"▾":"▸"}),B,t.jsxs("div",{className:"w6w-exprmodal-toggle-stack",children:[t.jsx(tt,{count:F.length,open:q,onToggle:()=>k(V)}),g.hasMeta===!0&&O(g.id)]})]}):B,g.needsTest&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:t.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),F.length>0&&q&&t.jsxs("div",{className:"w6w-exprmodal-subsources",children:[g.outputsFrom==="test"&&t.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:"Fields from the last test run"}),F.map($=>{const Q=`steps.${g.id}.output.${$.key}`;return K(he(Q),{kind:"var",ref:Q},"w6w-expr-chip-var","·")})]}),g.hasMeta===!0&&t.jsxs(t.Fragment,{children:[F.length===0&&t.jsx("div",{className:"w6w-exprmodal-source-row w6w-exprmodal-meta-row",children:O(g.id)}),N.has(`meta:${g.id}`)&&t.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-meta-fields",children:rn.map(([$,Q])=>K(Q,{kind:"var",ref:`steps.${g.id}.meta.${$}`},"w6w-expr-chip-var","·"))})]})]},g.id)})]}),!u&&t.jsxs(t.Fragment,{children:[r.inputs!==void 0&&t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Inputs"}),M.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),M.map(g=>K(g,{kind:"var",ref:`inputs.${g}`},"w6w-expr-chip-var","⇥"))]}),t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsxs("div",{className:"w6w-field-labelrow",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Variables"}),r.createVar&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-var",onClick:()=>v("var"),children:"+ Add"})]}),_.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),_.map(g=>K(g,{kind:"var",ref:`vars.${g}`},"w6w-expr-chip-var","◆"))]}),t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Documents"}),W.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),W.map(g=>{const O=(g.fields??[]).filter(B=>ot(B.key)),F=`doc:${g.key}`,V=N.has(F),q=K(g.key,{kind:"var",ref:`documents.${g.key}`},"w6w-expr-chip-var","▦",O.length>0);return t.jsxs(d.Fragment,{children:[O.length>0?t.jsxs("div",{className:"w6w-exprmodal-source-row",children:[q,t.jsx(tt,{count:O.length,open:V,onToggle:()=>k(F)})]}):q,O.length>0&&V&&t.jsx("div",{className:"w6w-exprmodal-subsources",children:O.map(B=>{const $=`documents.${g.key}.${B.key}`;return t.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[K(B.key,{kind:"var",ref:$},"w6w-expr-chip-var","·"),t.jsx("button",{type:"button",className:"w6w-exprmodal-render-btn","data-testid":"expr-insert-render",title:`Insert ${$} and render its {{ }} placeholders`,"aria-label":`Insert ${$} and render its {{ }} placeholders`,onClick:()=>A({kind:"render",ref:$}),children:"▤"})]},$)})})]},g.key)})]}),t.jsxs("div",{className:"w6w-exprmodal-group",children:[t.jsxs("div",{className:"w6w-field-labelrow",children:[t.jsx("span",{className:"w6w-exprmodal-group-label",children:"Secrets"}),r.createSecret&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-secret",onClick:()=>v("secret"),children:"+ Add"})]}),U.length===0&&t.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),U.map(g=>K(g,{kind:"secret",ref:g},"w6w-expr-chip-secret","🔒"))]})]})]}),!u&&t.jsxs("div",{className:"w6w-exprmodal-main",children:[t.jsxs("div",{className:"w6w-exprmodal-editor",children:[t.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Expression",t.jsx("span",{className:"w6w-muted w6w-small",children:" — click a source on the left, or type"})]}),t.jsx("div",{ref:p,className:`w6w-exprmodal-chips${s?" is-masked":""}${m.length===0?" is-empty":""}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":n?"true":"false","aria-label":"Expression","data-placeholder":"Type text and insert {x} variables, 🔒 secrets, or ▸ step outputs…",spellCheck:!1,onInput:()=>{const g=p.current;g&&as(g,{renderToggle:!0}),P()},onDoubleClick:g=>{const O=g.target;if(O.closest("[data-x]")||O.closest("[data-render-toggle]"))return;const F=O.closest(".w6w-expr-chip");if(!F)return;g.preventDefault();const V=os(F);if(V){const q=V.ownerDocument,B=q.createRange();B.setStartAfter(V),B.collapse(!0);const $=q.getSelection();$==null||$.removeAllRanges(),$==null||$.addRange(B)}P()},onBlur:()=>{const g=p.current;g&&L(oe.serializeTemplate(Ae(g)),{restoreFocus:!1})},onPaste:g=>{var V;g.preventDefault();const O=p.current;if(!O)return;const F=((V=g.clipboardData)==null?void 0:V.getData("text/plain"))??"";for(const q of _e(F))q.kind==="text"?Ee(O,O.ownerDocument.createTextNode(q.value??"")):Ee(O,Re(O.ownerDocument,q,{renderToggle:!0}));P()},onClick:g=>{var q;const O=g.target,F=O.closest("[data-x]");if(F){g.preventDefault(),(q=F.closest(".w6w-expr-chip"))==null||q.remove(),P();return}const V=O.closest("[data-render-toggle]");if(V){g.preventDefault();const B=V.closest(".w6w-expr-chip");if(B){const $=B.getAttribute("data-ref")??"",Q=B.getAttribute("data-kind")==="render"?"var":"render";B.replaceWith(Re(B.ownerDocument,{kind:Q,ref:$},{renderToggle:!0}))}P()}},onKeyDown:g=>{if(g.key!=="Enter"||(g.preventDefault(),!n))return;const O=p.current;O&&(Ee(O,O.ownerDocument.createTextNode(`
5
- `)),ns(O),P())}})]}),J.length>0&&t.jsxs("div",{className:"w6w-exprmodal-preview",children:[t.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Sample values",t.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— try the expression against example data"]})]}),J.map(g=>t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:g}),t.jsx("input",{type:"text",value:S[g]??"",placeholder:"sample value",onChange:O=>y(F=>({...F,[g]:O.target.value}))})]},g))]}),t.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[t.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",t.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— live preview against the sample values"]})]}),t.jsx(ue.Copyable,{value:ae,readOnly:!0,children:t.jsx("pre",{className:"w6w-exprmodal-result",children:ae||" "})})]})]})]}),x==="var"&&r.createVar&&t.jsx(Dt,{kind:"var",onCreate:r.createVar,onClose:C}),x==="secret"&&r.createSecret&&t.jsx(Dt,{kind:"secret",onCreate:r.createSecret,onClose:C})]})}function tt({count:e,open:s,onToggle:n}){return t.jsxs("button",{type:"button",className:"w6w-exprmodal-toggle-btn","data-testid":"expr-toggle-fields","aria-expanded":s,title:s?"Hide fields":"Show fields",onClick:n,children:[e," ",e===1?"field":"fields"," ",s?"⌄":"›"]})}const rn=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"]];function Dt({kind:e,onCreate:s,onClose:n}){const[r,o]=d.useState(""),[a,l]=d.useState(""),[i,c]=d.useState(""),[u,m]=d.useState(null),[w,h]=d.useState(!1),f=e==="var"?"variable":"secret";async function p(){m(null),h(!0);try{await s({name:r,value:a,description:i||void 0}),n()}catch(b){m(b.message)}finally{h(!1)}}return t.jsxs(ne,{title:`Add ${f}`,onClose:n,children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Name"}),t.jsx("input",{type:"text",value:r,onChange:b=>o(b.target.value),placeholder:e==="var"?"e.g. api_base_url":"e.g. openai_api_key",autoComplete:"off","data-testid":"expr-add-value-name",autoFocus:!0}),t.jsx("span",{className:"w6w-muted w6w-small",children:"Lowercase letters, digits, and underscores. Must start with a letter or underscore."})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Value"}),t.jsx("input",{type:e==="secret"?"password":"text",value:a,onChange:b=>l(b.target.value),autoComplete:"off","data-testid":"expr-add-value-value"}),e==="secret"&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Stored encrypted at rest. Once saved, it is not readable through the UI."})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Description"}),t.jsx("input",{type:"text",value:i,onChange:b=>c(b.target.value),placeholder:"Optional",autoComplete:"off"})]}),u&&t.jsx("div",{className:"w6w-result w6w-error",children:u})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"expr-add-value-cancel",onClick:n,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-add-value-save",disabled:!r||!a||w,onClick:p,children:w?"Saving…":"Save"})]})]})}function an(e,s){return s?e.filter(n=>n.id!==s):e}const lt=d.createContext({});function on({value:e,children:s}){const n=d.useContext(lt),r=d.useMemo(()=>({...n,...e}),[n,e]);return t.jsx(lt.Provider,{value:r,children:s})}function Je(){return d.useContext(lt)}function gt({value:e,onChange:s,placeholder:n,masked:r,multiline:o,readOnly:a,options:l,"aria-label":i}){const[c,u]=d.useState(()=>at(e)),{parts:m,sealed:w}=c,[h,f]=d.useState(0),[p,b]=d.useState(!1),[S,y]=d.useState(!1),x=d.useRef(!1),v=d.useRef(null),N=d.useRef(null),E=Je(),k={...E,...l??{}},P=E.sealSecret;d.useLayoutEffect(()=>{const j=v.current;!j||w||(rs(j,m),(x.current||j.ownerDocument.activeElement===j)&&(j.focus(),bt(j),x.current=!1))},[h,w]);const A=()=>{const j=v.current;if(!j)return;const C=Ae(j);u(_=>({..._,parts:C})),s(Te(C))},I=async j=>{if(!P)return!1;b(!0);try{const C=await P(j);return x.current=!1,u({parts:[],sealed:C}),f(_=>_+1),s(C),!0}catch{return!1}finally{b(!1)}},L=j=>{var U;if(S||!r||a||p)return;const C=j.relatedTarget;if(C&&((U=N.current)!=null&&U.contains(C)))return;const _=Te(m);typeof _=="string"&&_!==""&&I(_)},D=j=>{if(r&&typeof j=="string"&&j.trim()!==""){I(j);return}x.current=!1,u(at(j)),f(C=>C+1),s(j)};return w?t.jsxs("div",{className:`w6w-expr-sealed${a?" is-readonly":""}`,"aria-label":i,children:[t.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-secret",title:"Encrypted secret",children:[t.jsx("span",{className:"w6w-expr-chip-sigil",children:"🔒"}),t.jsx("span",{className:"w6w-expr-chip-label",children:"••••••"})]}),!a&&t.jsx("button",{type:"button",className:"w6w-expr-replace",onClick:()=>{x.current=!0,u({parts:[],sealed:null}),f(j=>j+1),s("")},children:"Replace"})]}):t.jsxs("div",{className:"w6w-expr",ref:N,onBlur:L,children:[t.jsxs("div",{className:"w6w-expr-field",children:[t.jsx("div",{ref:v,className:`w6w-expr-editor${r?" is-masked":""}${m.length===0?" is-empty":""}${a?" is-readonly":""}`,contentEditable:!a,suppressContentEditableWarning:!0,role:"textbox",tabIndex:a?-1:0,"aria-multiline":o?"true":"false","aria-label":i,"data-placeholder":n??"",spellCheck:!1,onInput:()=>{const j=v.current;j&&as(j),A()},onClick:j=>{var _;const C=j.target.closest("[data-x]");C&&(j.preventDefault(),(_=C.closest(".w6w-expr-chip"))==null||_.remove(),A())},onDoubleClick:j=>{const C=j.target;if(C.closest("[data-x]"))return;const _=C.closest(".w6w-expr-chip");if(!_)return;j.preventDefault();const U=os(_);if(U){const M=U.ownerDocument,W=M.createRange();W.setStartAfter(U),W.collapse(!0);const H=M.getSelection();H==null||H.removeAllRanges(),H==null||H.addRange(W)}A()},onKeyDown:j=>{if(j.key!=="Enter"||(j.preventDefault(),!o))return;const C=v.current;C&&(Ee(C,C.ownerDocument.createTextNode(`
6
- `)),ns(C),A())}}),!a&&t.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse variables, secrets & step outputs","aria-label":"Edit expression",onClick:()=>y(!0),children:"ƒx"})]}),S&&t.jsx(xt,{value:Te(m),masked:r,multiline:o,options:k,fieldLabel:i,onSave:D,onClose:()=>y(!1)})]})}const it="vars.",ct="documents.";function ls(e,s){const n={},r={};for(const[o,a]of Object.entries(e??{}))o.startsWith(it)?n[o.slice(it.length)]=a:o.startsWith(ct)&&(r[o.slice(ct.length)]=a);return{vars:n,documents:r,steps:(s==null?void 0:s.steps)??{},trigger:(s==null?void 0:s.trigger)??{},flat:e??{}}}function ln(e,s){const n=s.split(".");let r=e;for(const o of n){if(r===null||typeof r!="object")return{present:!1,value:void 0};if(!(o in r))return{present:!1,value:void 0};r=r[o]}return{present:!0,value:r}}function is(e,s){if(s.flat&&(e.startsWith(it)||e.startsWith(ct))&&Object.hasOwn(s.flat,e))return{status:"resolved",ref:e,value:s.flat[e]};const n=ln(s,e);return n.present?{status:"resolved",ref:e,value:n.value}:{status:"unresolved",ref:e}}function cn(e,s){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return is(e.ref??"",s);case"secret":return{status:"masked",ref:e.ref};case"expr":return{status:"not-evaluated"};case"render":return{status:"not-evaluated"};default:return{status:"resolved",value:void 0}}}function cs(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function un(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function us(e,s){return mt(e)?[{status:"masked"}]:Be(e)?e.parts.map(n=>cn(n,s)):cs(e)?[is(String(e.$),s)]:un(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function ut(e,s){if(e===s)return!0;if(typeof e!=typeof s||e===null||s===null||typeof e!="object")return!1;const n=Array.isArray(e),r=Array.isArray(s);if(n!==r)return!1;if(n){const c=e,u=s;return c.length===u.length&&c.every((m,w)=>ut(m,u[w]))}const o=e,a=s,l=Object.keys(o),i=Object.keys(a);return l.length===i.length&&l.every(c=>c in a&&ut(o[c],a[c]))}function ds(e){switch(e.status){case"resolved":return e.value===void 0?"<not set>":e.value;case"unresolved":return`<unresolved: ${e.ref}>`;case"not-evaluated":return"<not evaluated>";case"masked":return e.ref?`<masked: ${e.ref}>`:"<masked>"}}function dn(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(ds(e))}function pn(e){return e.length===1?ds(e[0]):e.map(dn).join("")}function yt(e,s){return pn(us(e,s))}function wn(e,s){const n={};for(const r of e)n[r.key||"(no key)"]=yt(r.value,s);return n}function Pe(e,s){const n=e.showIf;if(!n)return!0;const r=s(n.field);return n.equals!==void 0?r===n.equals:n.in?n.in.some(o=>o===r):n.notIn?!n.notIn.some(o=>o===r):n.truthy!==void 0?n.truthy?!!r:!r:!0}function fe(e){const s=[];for(const n of e)s.push(n),n.type==="section"&&n.children&&s.push(...fe(n.children));return s}function Ie(e,s){const n=[];for(let r=0;r<e.length;){const o=e[r].row;if(o){const a=[];for(;r<e.length&&e[r].row===o;)a.push(e[r++]);n.push(t.jsx("div",{className:"w6w-field-row",children:a.map(s)},`row:${o}`))}else n.push(s(e[r])),r++}return n}function ps(e,s,n,r){const o=a=>a.type==="section"?t.jsx(hn,{param:a,effective:n,renderOne:o},a.key):a.repeat&&a.type!=="array"?t.jsx(xn,{param:a,value:e[a.key],onChange:s,readOnly:r},a.key):a.type==="group"&&a.children&&a.children.length>0?t.jsx(bn,{param:a,value:e[a.key],onChange:s,effective:n,readOnly:r},a.key):t.jsx(gn,{param:a,value:e[a.key],onChange:s,effective:n,readOnly:r},a.key);return o}function de({params:e,values:s,onChange:n,readOnly:r}){const o=fe(e),a=w=>{var h;return s[w]!==void 0?s[w]:(h=o.find(f=>f.key===w))==null?void 0:h.default},l=e.filter(w=>Pe(w,a)),i=l.filter(w=>w.required||!w.advanced),c=l.filter(w=>!w.required&&w.advanced),u=(w,h)=>{if(w==="language"){const f={...s,[w]:h};for(const p of o){if(p.type!=="code")continue;const b=s[p.key];(b===void 0||b===p.default||b===dt)&&(f[p.key]=h==="python"?dt:p.default)}n(f);return}n({...s,[w]:h})};if(e.length===0)return t.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."});const m=ps(s,u,a,r);return t.jsxs("div",{className:"w6w-stack",children:[Ie(i,m),c.length>0&&t.jsxs("details",{className:"w6w-params-optional",children:[t.jsxs("summary",{className:"w6w-muted w6w-small",children:["Additional parameters (",c.length,")"]}),t.jsx("div",{className:"w6w-stack",style:{marginTop:8},children:Ie(c,m)})]})]})}function hn({param:e,effective:s,renderOne:n}){const r=(e.children??[]).filter(o=>Pe(o,s));return e.section==="collapsible"?t.jsxs("details",{className:"w6w-section",open:e.collapsed===!1,children:[t.jsxs("summary",{className:"w6w-section-summary",children:[t.jsx("span",{className:"w6w-section-title",children:e.title??e.label??e.key}),e.subtitle&&t.jsx("span",{className:"w6w-section-subtitle",children:e.subtitle})]}),t.jsx("div",{className:"w6w-stack w6w-section-body",children:Ie(r,n)})]}):e.layout==="row"?t.jsx("div",{className:"w6w-field-row",children:r.map(n)}):t.jsx("div",{className:"w6w-stack",children:Ie(r,n)})}const fn=new Set(["string","text","number","boolean","select"]);function mn(e){return e.length>0&&e.every(s=>fn.has(s.type)&&!s.children)}function bn({param:e,value:s,onChange:n,effective:r,readOnly:o}){const a=e.children??[],l=s??{},i=(h,f)=>n(e.key,{...l,[h]:f}),c=fe(a),u=h=>{const f=c.find(p=>p.key===h);return f?l[h]!==void 0?l[h]:f.default:r(h)},m=a.filter(h=>Pe(h,u)),w=ps(l,i,u,o);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("span",{className:"w6w-section-title",children:e.label??e.key}),t.jsx("div",{className:"w6w-stack w6w-section-body",children:Ie(m,w)})]})}function xn({param:e,value:s,onChange:n,readOnly:r}){if(e.type==="group"){const a=e.children??[];if(!mn(a))return t.jsx(ws,{param:e,value:s,onChange:n,readOnly:r});const l={...e,item:{type:"object",fields:a}};return t.jsx(pt,{param:l,value:s,onChange:n,readOnly:r})}const o={...e,item:{type:e.type,options:e.options}};return t.jsx(pt,{param:o,value:s,onChange:n,readOnly:r})}const dt=`# Runs as a function body. Return the step's output.
7
- return input`;function gn({param:e,value:s,onChange:n,effective:r,readOnly:o}){var w,h;const a=e.label??e.key,l=e.required&&e.type!=="boolean"?" *":"",i=d.useId();if(e.type==="boolean"){const f=!!(s??e.default??!1);return t.jsx(we,{param:e,value:s,onChange:n,readOnly:o,label:a,req:l,variant:"inline",controlId:i,children:t.jsx("input",{id:i,type:"checkbox",checked:f,disabled:o,onChange:p=>n(e.key,p.target.checked)})})}if(e.type==="json"||e.type==="group")return t.jsx(ws,{param:e,value:s,onChange:n,readOnly:o});if(e.type==="code"){const f=r==null?void 0:r("language"),p=f==="python"?"python":f==="javascript"?"javascript":void 0,b=p==="python"?dt:e.default,S=s??b??"";return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[a,l]}),t.jsx(Xt,{value:String(S),readOnly:o,minHeight:"180px",language:p,"aria-label":`${e.key} code`,onChange:y=>n(e.key,y)}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="vars")return t.jsx(Nn,{param:e,value:s,onChange:n,readOnly:o});if(e.type==="text"||(w=e.config)!=null&&w.multiline){const f=s??e.default??"";return t.jsx(we,{param:e,value:s,onChange:n,readOnly:o,label:a,req:l,children:t.jsx("textarea",{rows:3,value:String(f),readOnly:o,"aria-label":a,onChange:p=>n(e.key,p.target.value)})})}if(e.type==="multiselect")return t.jsx(yn,{param:e,value:s,onChange:n,readOnly:o});if(e.type==="array")return t.jsx(pt,{param:e,value:s,onChange:n,readOnly:o});if(Array.isArray(e.options)&&e.options.length>0){const f=s??e.default??((h=e.options[0])==null?void 0:h.value)??"",p=e.type==="number";return t.jsx(we,{param:e,value:s,onChange:n,readOnly:o,label:a,req:l,children:t.jsx("select",{value:String(f),disabled:o,"aria-label":a,onChange:b=>n(e.key,p?Number(b.target.value):b.target.value),children:e.options.map(b=>t.jsx("option",{value:String(b.value),children:b.label},String(b.value)))})})}if(e.type==="secret"){const f=s??e.default;return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[a,l]}),t.jsx(gt,{value:f,masked:!0,readOnly:o,"aria-label":a,onChange:p=>n(e.key,p)}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}const c=e.type==="number"?"number":"text",u=s??e.default??"",m=typeof u=="object"&&u!==null?JSON.stringify(u):String(u??"");return t.jsx(we,{param:e,value:s,onChange:n,readOnly:o,label:a,req:l,children:t.jsx("input",{type:c,value:m,readOnly:o,"aria-label":a,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",onChange:f=>n(e.key,e.type==="number"?Number(f.target.value):f.target.value)})})}function we({param:e,value:s,onChange:n,readOnly:r,label:o,req:a,bare:l,variant:i="boxed",controlId:c,children:u}){var y;const m=Be(s),w=e.type==="text"||!!((y=e.config)!=null&&y.multiline),[h,f]=d.useState(!1),p=Je(),b=i==="inline"&&!m,S=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:b?"w6w-fx-inline":`w6w-fx-wrap${m?" is-fx":""}`,children:m?t.jsx(gt,{value:s,multiline:w,readOnly:r,"aria-label":o,onChange:x=>n(e.key,x)}):t.jsxs(t.Fragment,{children:[u,!r&&t.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${o}`,onClick:()=>f(!0),children:"ƒx"}),b&&t.jsxs("label",{className:"w6w-fx-inline-label",htmlFor:c,children:[o,a]})]})}),h&&t.jsx(xt,{value:s,multiline:w,options:p,fieldLabel:o,onSave:x=>n(e.key,x),onClose:()=>f(!1)})]});return l?S:t.jsxs("div",{className:"w6w-field",children:[!b&&t.jsxs("span",{children:[o,a]}),S,e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}function ws({param:e,value:s,onChange:n,readOnly:r}){const o=cs(s)&&typeof s.$=="string",a=o?String(s.$):"",l=s??e.default,[i,c]=d.useState(()=>o||l===void 0?"":JSON.stringify(l,null,2)),[u,m]=d.useState(!1),[w,h]=d.useState(!1),[f,p]=d.useState(!1),b=Je();d.useEffect(()=>{if(o)return;let E;try{E=i.trim()===""?void 0:JSON.parse(i)}catch{E=void 0}JSON.stringify(E)!==JSON.stringify(l)&&(c(l===void 0?"":JSON.stringify(l,null,2)),m(!1))},[l,e.key,o]);const S=E=>{c(E)},y=E=>{m(!1),n(e.key,E)},x=e.label??e.key,v=()=>{let E;try{E=i.trim()===""?void 0:JSON.parse(i)}catch{E=void 0}n(e.key,E)},N=(()=>{if(!o)return"";const E={};for(const[k,P]of Object.entries(b.sampleValues??{})){const A=/^steps\.([^.]+)\.output$/.exec(k);A&&(E[A[1]]={output:P})}return JSON.stringify(yt(s,ls(void 0,{steps:E})),null,2)})();return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{className:"w6w-field-labelrow",children:[t.jsxs("span",{children:[x,e.required?" *":""]}),!r&&!o&&t.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${x}`,onClick:()=>p(!0),children:"ƒx"}),!o&&t.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${x} in full view`,onClick:()=>h(!0),children:t.jsx(ue.Icon,{name:"maximize",size:14})})]}),o?t.jsxs("div",{className:"w6w-json-binding",children:[t.jsxs("div",{className:"w6w-fx-wrap is-fx",children:[t.jsx("code",{children:a}),!r&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>p(!0),children:"Edit"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:v,children:"Clear"})]})]}),t.jsx("pre",{className:"w6w-json-binding-preview","data-testid":"json-binding-preview",style:{margin:0,maxHeight:260,overflow:"auto",fontSize:"0.85em"},children:N})]}):t.jsx(ce,{value:i,onChange:S,readOnly:r,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:y,onValidityChange:({valid:E})=>m(!E)}),f&&t.jsx(xt,{mode:"json-binding",value:void 0,options:b,fieldLabel:x,onBind:E=>n(e.key,E),onClose:()=>p(!1)}),!o&&u&&t.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint}),w&&!o&&t.jsxs(ne,{title:x,subtitle:t.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>h(!1),children:[t.jsx("div",{className:"w6w-json-fullview",children:t.jsx(ce,{value:i,onChange:S,readOnly:r,height:"100%",minHeight:"360px","aria-label":`${e.key} JSON (full view)`,onValidChange:y,onValidityChange:({valid:E})=>m(!E)})}),u&&t.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function yn({param:e,value:s,onChange:n,readOnly:r}){const o=Array.isArray(e.options)?e.options:[],a=Array.isArray(s)?s:Array.isArray(e.default)?e.default:[],l=new Set(a.map(String)),i=o.filter(p=>!l.has(String(p.value))),c=p=>{var b;return((b=o.find(S=>String(S.value)===String(p)))==null?void 0:b.label)??String(p)},u=p=>{if(!p||l.has(p))return;const b=o.find(S=>String(S.value)===p);n(e.key,[...a,b?b.value:p])},m=p=>n(e.key,a.filter(b=>String(b)!==String(p))),w=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",h=e.label??e.key,f=e.required?" *":"";return t.jsx(we,{param:e,value:s,onChange:n,readOnly:r,label:h,req:f,children:t.jsxs("div",{className:`w6w-multiselect${r?" is-readonly":""}`,children:[a.map(p=>t.jsxs("span",{className:"w6w-chip",children:[c(p),!r&&t.jsx("button",{type:"button",className:"w6w-chip-x","aria-label":`Remove ${c(p)}`,title:"Remove",onClick:()=>m(p),children:"×"})]},String(p))),!r&&t.jsxs("select",{className:"w6w-multiselect-add",value:"",disabled:i.length===0,"aria-label":`Add to ${e.label??e.key}`,onChange:p=>u(p.target.value),children:[t.jsx("option",{value:"",children:i.length>0?a.length?"Add more…":w:"All selected"}),i.map(p=>t.jsx("option",{value:String(p.value),children:p.label},String(p.value)))]})]})})}function jn({field:e,value:s,onChange:n,readOnly:r}){var l;const o=e.placeholder??e.label??e.key;if(Array.isArray(e.options)&&e.options.length>0)return t.jsx("select",{className:"w6w-array-input",value:String(s??e.default??((l=e.options[0])==null?void 0:l.value)??""),disabled:r,"aria-label":e.label??e.key,onChange:i=>n(i.target.value),children:e.options.map(i=>t.jsx("option",{value:String(i.value),children:i.label},String(i.value)))});if(e.type==="boolean")return t.jsxs("label",{className:"w6w-array-check",title:e.label??e.key,children:[t.jsx("input",{type:"checkbox",checked:!!(s??e.default??!1),disabled:r,"aria-label":e.label??e.key,onChange:i=>n(i.target.checked)}),t.jsx("span",{children:e.label??e.key})]});const a=e.type==="number";return t.jsx("input",{className:"w6w-array-input",type:a?"number":"text",value:String(s??e.default??""),placeholder:o,"aria-label":e.label??e.key,readOnly:r,onChange:i=>n(a?Number(i.target.value):i.target.value)})}function pt({param:e,value:s,onChange:n,readOnly:r}){const o=e.item??{type:"string"},a=o.type==="object",l=Array.isArray(s)?s:Array.isArray(e.default)?e.default:[],i=m=>n(e.key,m),c=()=>a?Object.fromEntries((o.fields??[]).map(m=>[m.key,m.default??""])):o.type==="number"?0:"",u=(m,w)=>i(l.map((h,f)=>f===m?w:h));return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),t.jsxs("div",{className:"w6w-array",children:[l.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"None yet — add one below."}),l.map((m,w)=>t.jsxs("div",{className:"w6w-array-row",children:[a?t.jsx("div",{className:"w6w-array-cells",children:(o.fields??[]).map(h=>t.jsx(jn,{field:h,value:m==null?void 0:m[h.key],readOnly:r,onChange:f=>u(w,{...m??{},[h.key]:f})},h.key))}):t.jsx("input",{className:"w6w-array-input",type:o.type==="number"?"number":"text",value:String(m??""),placeholder:o.placeholder,readOnly:r,onChange:h=>u(w,o.type==="number"?Number(h.target.value):h.target.value)}),!r&&t.jsx("button",{type:"button",className:"w6w-array-x","aria-label":"Remove item",title:"Remove",onClick:()=>i(l.filter((h,f)=>f!==w)),children:"×"})]},w)),!r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-array-add",onClick:()=>i([...l,c()]),children:"+ Add"})]}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}const vn=["string","number","boolean","json"];function _t(e,s){if(e==="number"){if(s.trim()==="")return"";const n=Number(s);return Number.isNaN(n)?s:n}if(e==="boolean")return s==="true";if(e==="json")try{return JSON.parse(s)}catch{return s}return s}function qt(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Nn({param:e,value:s,onChange:n,readOnly:r}){const o=Array.isArray(s)?s:Array.isArray(e.default)?e.default:[],a=i=>n(e.key,i),l=(i,c)=>a(o.map((u,m)=>m===i?{...u,...c}:u));return t.jsxs("div",{className:"w6w-field",children:[t.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),t.jsxs("div",{className:"w6w-stack",children:[o.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"No variables yet — add one below."}),o.map((i,c)=>t.jsxs("div",{className:"w6w-datavar-row",children:[t.jsx("input",{type:"text",placeholder:"key",value:i.key,readOnly:r,onChange:u=>l(c,{key:u.target.value})}),t.jsx("select",{value:i.type,disabled:r,onChange:u=>{const m=u.target.value;l(c,{type:m,value:_t(m,qt(i.value))})},children:vn.map(u=>t.jsx("option",{value:u,children:u},u))}),t.jsx(we,{bare:!0,param:e,value:i.value,onChange:(u,m)=>l(c,{value:m}),readOnly:r,label:i.key||"value",req:"",children:i.type==="boolean"?t.jsxs("select",{value:i.value===!0?"true":"false",disabled:r,onChange:u=>l(c,{value:u.target.value==="true"}),children:[t.jsx("option",{value:"true",children:"true"}),t.jsx("option",{value:"false",children:"false"})]}):t.jsx("input",{type:i.type==="number"?"number":"text",placeholder:"value",value:qt(i.value),readOnly:r,onChange:u=>l(c,{value:_t(i.type,u.target.value)})})}),!r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Remove variable ${i.key||c+1}`,title:"Remove",onClick:()=>a(o.filter((u,m)=>m!==c)),children:"×"})]},c)),!r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>a([...o,{key:"",type:"string",value:""}]),children:"+ Add variable"})]}),e.hint&&t.jsx("span",{className:"w6w-hint",children:e.hint})]})}const kn=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],Cn=/^(?=\d)(?:\d+w)?(?:\d+d)?(?:\d+h)?(?:\d+m)?(?:\d+(?:\.\d+)?s)?$|^P(?:\d+W)?(?:\d+D)?(?:T(?=\d)(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?$/i;function hs({values:e,onChange:s,readOnly:n}){const r=e.duration??"1s",o=typeof r=="string"?r.match(/^(\d+(?:\.\d+)?)([smhdw])$/i):null,[a,l]=d.useState("s"),[i,c]=d.useState("text"),[u,m]=d.useState(e.until?"until":"duration"),w=typeof r=="string"&&(!Cn.test(r.trim())||/^P$/i.test(r.trim()));return t.jsxs("div",{className:"w6w-params-form",children:[t.jsxs("label",{children:["Wait for",t.jsxs("select",{"aria-label":"Wait for",disabled:n,value:u,onChange:h=>{const f=h.target.value;m(f),s({...e,duration:f==="duration"?"1s":"",until:""})},children:[t.jsx("option",{value:"duration",children:"A duration"}),t.jsx("option",{value:"until",children:"Until a timestamp"})]})]}),u==="until"?t.jsx(de,{params:[{key:"until",label:"Until",type:"string",hint:"ISO-8601 timestamp, e.g. 2026-10-08T09:00:00Z."}],values:e,onChange:s,readOnly:n}):t.jsxs(t.Fragment,{children:[t.jsxs("label",{children:["Duration input",t.jsxs("select",{"aria-label":"Duration input",disabled:n,value:i,onChange:h=>{o&&l((o==null?void 0:o[2].toLowerCase())??a),c(h.target.value)},children:[t.jsx("option",{value:"text",children:"Shorthand"}),t.jsx("option",{value:"value",disabled:!o,children:"Value and unit"})]})]}),i==="value"?t.jsxs("div",{className:"w6w-field-row",children:[t.jsxs("label",{children:["Value",t.jsx("input",{"aria-label":"Duration value",type:"number",min:"0",step:((o==null?void 0:o[2].toLowerCase())??a)==="s"?"any":"1",disabled:n,value:(o==null?void 0:o[1])??"",onChange:h=>s({...e,duration:`${h.target.value}${(o==null?void 0:o[2].toLowerCase())??a}`})})]}),t.jsxs("label",{children:["Unit",t.jsx("select",{"aria-label":"Duration unit",disabled:n,value:(o==null?void 0:o[2].toLowerCase())??a,onChange:h=>{l(h.target.value),s({...e,duration:`${(o==null?void 0:o[1])??""}${h.target.value}`})},children:kn.map(([h,f])=>t.jsx("option",{value:h,children:f},h))})]})]}):t.jsx(de,{params:[{key:"duration",label:"Duration",type:"string",default:"1s",hint:"Use 30s, 1h30m30s, or 3d30s. Units: w, d, h, m, s, in that order. Uppercase and ISO-8601 also work. Value and unit is available for single-unit durations."}],values:e,onChange:s,readOnly:n}),w&&t.jsx("p",{role:"alert",children:"Enter a duration such as 30s or 1h30m30s, using units w, d, h, m, s in order."})]})]})}const Sn={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function An(e){if(typeof e!="string"||e.trim()==="")return"";const s=Sn[e];return s||e.split(/[-_\s]+/).filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}function En(e){const s=new Map;for(const n of e)for(const r of n.categories??[])s.set(r,(s.get(r)??0)+1);return[...s.entries()].map(([n,r])=>({slug:n,label:An(n),count:r})).sort((n,r)=>r.count-n.count||n.label.localeCompare(r.label,void 0,{sensitivity:"base"}))}function Tn(e,s){if(s.length===0)return!0;const n=e.categories??[];return s.some(r=>n.includes(r))}function fs(e,s){const n=e==="error"?{className:"w6w-edge-error",label:"on error"}:{};if(!s)return n;const r=s==="taken"?"w6w-edge-taken":"w6w-edge-skipped";return{className:n.className?`${n.className} ${r}`:r,...n.label?{label:n.label}:{}}}const jt="out-error";function ms(e){return e==="error"?jt:void 0}function Rn(e){return e===jt?"error":"success"}const In="@w6w/",ie="@w6w/control",bs="@w6w/script",ze="@w6w/data",Ge="@w6w/trigger",Pn="@w6w/http",vt="@w6w/webhook",Nt="@w6w/scheduler",Mn="@w6w/respond",Ke="@w6w/call",On="@w6w/document",Fn="@w6w/template";function me(e){return e.startsWith(In)}function Le(e){return e===ie}function qe(e){return e===Ge||e===vt||e===Nt}const Ht={in:1,out:Number.POSITIVE_INFINITY};function Vt(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function $n(...e){let s,n;for(const r of e)s??(s=Vt(r==null?void 0:r.in)),n??(n=Vt(r==null?void 0:r.out));return{in:s??Ht.in,out:n??Ht.out}}function Ln(e,s){var o;const{app:n,action:r}=e.uses;return $n(e.ports,s==null?void 0:s(n,r),(o=be(n,r))==null?void 0:o.ports)}const Dn='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',_n='<line x1="6" y1="3" x2="6" y2="15" /><circle cx="18" cy="6" r="3" /><circle cx="6" cy="18" r="3" /><path d="M18 9a9 9 0 0 1-9 9" />',qn='<polyline points="17 1 21 5 17 9" /><path d="M3 11V9a4 4 0 0 1 4-4h14" /><polyline points="7 23 3 19 7 15" /><path d="M21 13v2a4 4 0 0 1-4 4H3" />',Hn='<line x1="6" y1="4" x2="6" y2="20" /><line x1="12" y1="4" x2="12" y2="20" /><line x1="18" y1="4" x2="18" y2="20" />',Vn='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',Wn='<rect x="3" y="4" width="18" height="18" rx="2" /><line x1="16" y1="2" x2="16" y2="6" /><line x1="8" y1="2" x2="8" y2="6" /><line x1="3" y1="10" x2="21" y2="10" /><polyline points="12 13 12 16 14 17" />',Un='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',Bn='<ellipse cx="12" cy="5" rx="9" ry="3" /><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3" /><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5" />',Jn='<circle cx="12" cy="12" r="10" /><line x1="2" y1="12" x2="22" y2="12" /><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z" />',zn='<circle cx="18" cy="5" r="3" /><circle cx="6" cy="12" r="3" /><circle cx="18" cy="19" r="3" /><line x1="8.59" y1="13.51" x2="15.42" y2="17.49" /><line x1="15.41" y1="6.51" x2="8.59" y2="10.49" />',Gn='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',Wt='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',Kn='<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /><polyline points="15 3 21 3 21 9" /><line x1="10" y1="14" x2="21" y2="3" />',Yn='<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" /><polyline points="14 2 14 8 20 8" /><line x1="16" y1="13" x2="8" y2="13" /><line x1="16" y1="17" x2="8" y2="17" /><polyline points="10 9 9 9 8 9" />',Xn='<path d="M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1" /><path d="M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-1" />',ye=[{app:Ge,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:Dn,ports:{in:0,out:1},params:[{key:"fields",label:"Fields",type:"array",default:[],hint:'The fields this trigger emits into the run. Reference them downstream as {"$": "steps.<trigger>.output.<key>"}.',item:{type:"object",fields:[{key:"key",label:"Key",type:"string",placeholder:"e.g. email"},{key:"type",label:"Type",type:"select",default:"string",options:[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"json",label:"JSON"}]},{key:"default",label:"Default",type:"string",placeholder:"optional"},{key:"required",label:"Required",type:"boolean",default:!1}]}}]},{app:vt,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:zn,ports:{in:0,out:1},params:[{key:"methods",label:"HTTP Methods",type:"multiselect",required:!0,default:["POST"],hint:"Which HTTP methods this webhook accepts.",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"PATCH",label:"PATCH"},{value:"DELETE",label:"DELETE"},{value:"HEAD",label:"HEAD"}]},{key:"auth",label:"Authentication",type:"select",default:"none",hint:"How incoming requests are authenticated.",options:[{value:"none",label:"None"},{value:"basic",label:"Basic auth"},{value:"header",label:"Header auth"},{value:"jwt",label:"JWT (HMAC)"}]},{key:"basicUser",label:"Username",type:"string",row:"basic-auth",showIf:{field:"auth",equals:"basic"}},{key:"basicPassword",label:"Password",type:"secret",row:"basic-auth",showIf:{field:"auth",equals:"basic"}},{key:"headerName",label:"Header name",type:"string",row:"header-auth",placeholder:"e.g. X-Api-Key",showIf:{field:"auth",equals:"header"}},{key:"headerValue",label:"Header value",type:"secret",row:"header-auth",showIf:{field:"auth",equals:"header"}},{key:"jwtSecret",label:"JWT secret",type:"secret",showIf:{field:"auth",equals:"jwt"}},{key:"responseMode",label:"Respond",type:"select",default:"onReceived",hint:"When and how to respond to the caller.",options:[{value:"onReceived",label:"Immediately (ASAP)"},{value:"lastNode",label:"When the run finishes"},{value:"responseNode",label:"Using a Response node"},{value:"streaming",label:"Streaming"}]},{key:"responseCode",label:"Response status code",type:"number",default:200,showIf:{field:"responseMode",notIn:["responseNode"]}},{key:"responseData",label:"Response body (immediate)",type:"text",hint:'Body for "Immediately" responses. Empty = { "message": "Workflow was started" }.',showIf:{field:"responseMode",equals:"onReceived"}},{key:"rawBody",label:"Raw body",type:"boolean",default:!1,advanced:!0},{key:"ignoreBots",label:"Ignore bots",type:"boolean",default:!1,advanced:!0},{key:"ipAllowList",label:"IP allow list",type:"array",advanced:!0,item:{type:"string",placeholder:"e.g. 203.0.113.4"},hint:"Client IPs allowed to call this webhook. Empty = allow all."},{key:"binaryPropertyName",label:"Binary field name",type:"string",advanced:!0},{key:"cors",label:"CORS allowed origin",type:"string",advanced:!0},{key:"responseHeaders",label:"Response headers",type:"array",default:[],advanced:!0,item:{type:"object",fields:[{key:"name",label:"Name",type:"string"},{key:"value",label:"Value",type:"string"}]}}]},{app:Nt,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:Wn,ports:{in:0,out:1},params:[{key:"mode",label:"Mode",type:"select",required:!0,default:"cron",hint:"How the schedule fires.",options:[{value:"once",label:"Once"},{value:"cron",label:"Cron"},{value:"interval",label:"Interval"}]},{key:"cron",label:"Cron expression",type:"string",placeholder:"e.g. 0 9 * * 1-5",showIf:{field:"mode",equals:"cron"}},{key:"runAt",label:"Run at",type:"string",placeholder:"e.g. 2026-01-01T09:00:00Z",showIf:{field:"mode",equals:"once"}},{key:"intervalSeconds",label:"Interval (seconds)",type:"number",showIf:{field:"mode",equals:"interval"}},{key:"timezone",label:"Timezone",type:"string",default:"UTC",advanced:!0}]},{app:ie,action:"if",label:"If",displayName:"If",group:"control",icon:_n,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:'A boolean, or an expression binding like { "$": "steps.x.output.ok" }.'}]},{app:ie,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:qn,params:[{key:"items",type:"json",label:"Items",required:!0,default:[],hint:"An array to iterate, or an expression binding to one."}]},{app:ie,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:Hn,params:[]},{app:ie,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:Vn,params:[{key:"duration",type:"string",label:"Duration",default:"1s",hint:"Use 30s, 1h30m30s, or 3d30s. Units: w, d, h, m, s; uppercase also works."}]},{app:bs,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:Un,params:[{key:"language",label:"Language",type:"select",default:"javascript",options:[{value:"javascript",label:"JavaScript"},{value:"python",label:"Python"}],hint:"Execution language for this step's code. Python runs CPython-on-WASM with no network."},{key:"code",type:"code",label:"Script",required:!0,default:`// Runs as a function body. Return the step's output.
8
- return input;`,hint:"Function body; return the step's output."}]},{app:Fn,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:Xn,output:[{key:"result"}],params:[{key:"template",label:"Template",type:"text",required:!0,hint:"Handlebars template. Placeholder names are workflow-agnostic — bind them below. {{name}} is HTML-escaped; use {{{name}}} for raw output."},{key:"values",label:"Values",type:"vars",required:!0,default:[],hint:'A typed key/value array: [{ "key": "data", "type": "json", "value": ... }]. Each key becomes a top-level placeholder root.'}]},{app:ze,action:"set",label:"Data",displayName:"Data set",group:"compute",icon:Bn,params:[{key:"vars",type:"vars",label:"Variables",required:!0,default:[],hint:"Typed key/value variables for downstream steps to reference."}]},{app:Pn,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:Jn,output:[{key:"status"},{key:"statusText"},{key:"ok"},{key:"headers"},{key:"body"}],params:[{key:"method",type:"string",label:"Method",required:!0,default:"GET",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"PATCH",label:"PATCH"},{value:"DELETE",label:"DELETE"}],hint:"HTTP method for the request."},{key:"url",type:"string",label:"URL",required:!0,default:"",hint:"Full request URL, e.g. https://api.example.com/v1/things."},{key:"headers",type:"json",label:"Headers",default:{},hint:"Object of header name → value."},{key:"query",type:"json",label:"Query params",default:{},hint:"Object of query-string name → value, appended to the URL."},{key:"body",type:"text",label:"Body",default:"",hint:"Request body (raw text or a JSON string). Ignored for GET/HEAD."}]},{app:Mn,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:Gn,params:[{key:"respondWith",label:"Respond with",type:"select",default:"json",hint:"Shape of the response returned to the webhook caller.",options:[{value:"json",label:"JSON"},{value:"text",label:"Text"},{value:"noData",label:"No body"}]},{key:"responseCode",label:"Response status code",type:"number",default:200},{key:"responseBody",label:"Response body",type:"json",default:{},hint:"Body to return (object for JSON, string for Text)."},{key:"responseHeaders",label:"Response headers",type:"array",default:[],item:{type:"object",fields:[{key:"name",label:"Name",type:"string"},{key:"value",label:"Value",type:"string"}]}}]},{app:ie,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:Wt,hidden:!0,ports:{in:10,out:1},params:[{key:"mode",label:"Mode",type:"select",default:"array",hint:"How to combine the inbound branch outputs: an array of results, or an object keyed by source step.",options:[{value:"array",label:"Array"},{value:"object",label:"Object"}]}]},{app:ie,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:Wt,ports:{in:"many",out:1},params:[{key:"mode",label:"Mode",type:"select",default:"array",hint:"Combine the entries into an array, or into an object keyed by each entry's key.",options:[{value:"array",label:"Array"},{value:"object",label:"Object"}]},{key:"entries",label:"Entries",type:"array",default:[],hint:"Each entry's value may be an expression (ƒx) over the inbound branches' outputs.",item:{type:"object",fields:[{key:"key",label:"Key",type:"string"},{key:"value",label:"Value",type:"string"}]}}]},{app:Ke,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:Kn,ports:{in:1,out:1},params:[{key:"targetKind",label:"Target kind",type:"select",required:!0,default:"workflow",hint:"Whether this node calls another Workflow or a Function.",options:[{value:"workflow",label:"Workflow"},{value:"function",label:"Function"}]},{key:"targetId",label:"Target id",type:"string",required:!0,default:"",placeholder:"e.g. wf_… or fn_…",hint:"Id of the Workflow (wf_…) or Function (fn_…) to call, within this project."},{key:"inputs",label:"Inputs",type:"json",default:{},hint:"Payload passed to the target — an object keyed by the callee's declared inputs. Values may be expressions."},{key:"wait",label:"Wait for completion",type:"boolean",default:!0,hint:"On: block until the sub-run finishes and expose its output. Off: return a run handle and continue."}]},{app:On,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:Yn,ports:{in:1,out:1},params:[{key:"key",label:"Key",type:"string",required:!0,default:"",hint:"Document key to read — may be an expression, e.g. a step output."}]}];function be(e,s){return ye.find(n=>n.app===e&&n.action===s)}function Qn(e,s){var n;return((n=be(e,s))==null?void 0:n.label)??s}function Zn(e,s){var n;return((n=be(e,s))==null?void 0:n.icon)??""}function xs(e,s){var n;return((n=be(e,s))==null?void 0:n.params)??[]}function gs(e,s){const n={};for(const r of xs(e,s))r.default!==void 0&&(n[r.key]=r.default);return n}function er(e,s){return e.q===s.q&&(e.category??"")===(s.category??"")}function ys(e,s=0){return{query:e,generation:s,status:"loading",apps:[],hasMore:!1}}function tr(e,s){const n=new Set(e.map(o=>o.id)),r=[];for(const o of s)n.has(o.id)||(n.add(o.id),r.push(o));return r.length===0?e:[...e,...r]}function sr(e,s){switch(s.type){case"query-changed":return s.generation===e.generation&&er(s.query,e.query)?e:ys(s.query,s.generation);case"load-more":return e.status!=="ready"||!e.hasMore?e:{...e,status:"loading-more"};case"retry":return e.status!=="error"?e:{...e,status:e.apps.length===0?"loading":"loading-more"};case"page-loaded":{if(s.generation!==e.generation)return e;const n=tr(e.apps,s.apps),r=s.nextCursor!==void 0&&s.nextCursor===s.requestedCursor,o=!!s.nextCursor&&!r;return{...e,status:"ready",apps:n,cursor:o?s.nextCursor:void 0,hasMore:o,error:void 0}}case"page-failed":return s.generation!==e.generation?e:{...e,status:"error",error:s.error};default:return e}}function nr(e){return e.filter(s=>!me(s.id))}function st(e,s,n){if(n<=0)return[];const r=[];for(const o of e)if(!s.has(o)&&(r.push(o),r.length>=n))break;return r}function rr(e,s){const n=[];for(const r of e){const o=s.get(r);o&&n.push(o)}return n}function pe({src:e,srcDark:s,brandColor:n,name:r,size:o=32,theme:a}){const i=Ue(a)==="dark"?s??e:e,[c,u]=d.useState(void 0);if(i&&i!==c)return t.jsx("img",{src:i,width:o,height:o,alt:"",onError:()=>u(i),style:{width:o,height:o,borderRadius:6,flexShrink:0,objectFit:"contain",padding:Math.max(1,Math.round(o*.06)),boxSizing:"border-box",background:"var(--w6w-icon-swatch, var(--w6w-panel-2))"}});const m=(r??"?").split(/\s+/).slice(0,2).map(w=>{var h;return((h=w[0])==null?void 0:h.toUpperCase())??""}).join("");return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o,height:o,borderRadius:6,background:n??"var(--w6w-accent)",color:"#fff",fontWeight:700,fontSize:Math.round(o*.42),flexShrink:0},children:m})}const js=d.createContext(null);function ar({api:e,theme:s,children:n}){const r=t.jsx(js.Provider,{value:e,children:t.jsx(Yt.Provider,{value:s,children:n})});return s?t.jsx("div",{"data-theme":s,style:{display:"contents"},children:r}):r}function te(){const e=d.useContext(js);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}const vs=d.createContext(void 0);function or({project:e,children:s}){return t.jsx(vs.Provider,{value:e,children:s})}function Ns(){return d.useContext(vs)}const nt=8,lr=60,ir=300;function xe({onSelectApp:e,theme:s,filter:n,searchPlaceholder:r,emptyMessage:o,search:a=!0,emptyAction:l,apps:i,categoryFilter:c=!1,category:u,pageLimit:m=lr,loadPage:w}){const h=te(),f=i!==void 0,p=!f&&(w!==void 0||typeof h.listAppsPage=="function"),b=d.useRef(w);b.current=w;const[S,y]=d.useState(null),[x,v]=d.useState(null);d.useEffect(()=>{if(f||p)return;const T=h.listApps;if(typeof T!="function"){y([]);return}let Y=!1;return T().then(Z=>!Y&&y(Z)).catch(Z=>!Y&&v(Z.message)),()=>{Y=!0}},[h,f,p]);const[N,E]=d.useReducer(sr,ys({q:"",category:u},0)),[k,P]=d.useState(""),[A,I]=d.useState(""),L=d.useRef(0),D=d.useRef(null),j=d.useCallback((T,Y,Z)=>{var R;const Ne=b.current,re=h.listAppsPage;if(!Ne&&!re)return;(R=D.current)==null||R.abort();const ke=new AbortController;D.current=ke;let Ce;try{Ce=Ne?Ne({q:T.q||void 0,cursor:Z,limit:m,signal:ke.signal}):re({q:T.q||void 0,category:T.category,cursor:Z,limit:m,compact:!0,signal:ke.signal})}catch(z){Ce=Promise.reject(z)}Ce.then(z=>{if(L.current===Y){if(!z||!Array.isArray(z.apps)){E({type:"page-failed",generation:Y,error:"The server returned a malformed apps page."});return}E({type:"page-loaded",generation:Y,apps:z.apps,nextCursor:z.nextCursor,requestedCursor:Z})}}).catch(z=>{L.current===Y&&(z instanceof Error&&z.name==="AbortError"||E({type:"page-failed",generation:Y,error:z.message}))})},[h,m]);d.useEffect(()=>{if(!p)return;const T=setTimeout(()=>I(k.trim()),ir);return()=>clearTimeout(T)},[k,p]),d.useEffect(()=>{if(!p)return;const T=++L.current,Y={q:A,category:u};return E({type:"query-changed",query:Y,generation:T}),j(Y,T,void 0),()=>{var Z;(Z=D.current)==null||Z.abort()}},[p,A,u,j]),d.useEffect(()=>{if(p)return()=>{var T;return(T=D.current)==null?void 0:T.abort()}},[p]);const C=()=>{if(!p||N.status!=="ready"||!N.hasMore)return;const T=L.current;E({type:"load-more"}),j(N.query,T,N.cursor)},_=()=>{!p||N.status!=="error"||(E({type:"retry"}),j(N.query,L.current,N.cursor))},[U,M]=d.useState([]),[W,H]=d.useState(!1),X=T=>t.jsx("div",{className:"w6w-apppicker-host",children:T});let ee,G=null,J=!1,ae=!1,K=null,g=!1;if(f?ee=i??null:p?(ee=N.apps,g=N.status==="loading",J=N.status==="loading-more",ae=N.hasMore,N.status==="error"&&(N.apps.length===0?G=N.error??"Failed to load apps.":K=N.error??"Failed to load apps.")):(ee=S,G=x),!p&&G)return X(t.jsx("div",{className:"w6w-result w6w-error",children:G}));if(!p&&ee===null)return X(t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));ee??(ee=[]);const O=nr(ee),F=n?O.filter(n):O;if(!p&&F.length===0)return X(t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:o??"No apps registered yet. Register one from the Apps page first."}),l]}));const V=c?En(F):[],q=V.slice(0,nt),B=V.slice(nt).filter(T=>U.includes(T.slug)),$=[...q,...B],Q=V.length-$.length,je=W?V:$,Ze=T=>M(Y=>Y.includes(T)?Y.filter(Z=>Z!==T):[...Y,T]),ve=()=>M([]),Me=c&&U.length>0?F.filter(T=>Tn(T,U)):F,Oe=p?Me:[...Me].sort((T,Y)=>T.displayName.localeCompare(Y.displayName,void 0,{sensitivity:"base"})),Fe=p?"":k.trim().toLowerCase(),se=k.trim().length>0,le=Fe?Oe.filter(T=>T.displayName.toLowerCase().includes(Fe)||T.id.toLowerCase().includes(Fe)):Oe,et=c&&U.length>0&&le.length===0;return X(t.jsxs("div",{className:"w6w-stepbuilder-apps",children:[a&&t.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:r??"Search apps…",value:k,onChange:T=>P(T.target.value),"aria-label":"Search apps"}),c&&V.length>0&&t.jsxs("div",{className:"w6w-apppicker-cats",children:[je.map(T=>t.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":U.includes(T.slug),"aria-label":`Filter by ${T.label}`,onClick:()=>Ze(T.slug),children:[T.label," ",t.jsxs("span",{className:"w6w-muted",children:["(",T.count,")"]})]},T.slug)),!W&&Q>0&&t.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>H(!0),children:["+",Q," more"]}),W&&V.length>nt&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>H(!1),children:"Show less"}),U.length>0&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:ve,children:"Clear"})]}),p&&g?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):p&&G?t.jsxs("div",{className:"w6w-result w6w-error",children:[G," ",t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:_,children:"Retry"})]}):le.length===0&&!ae?et?t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:se?`No apps match “${k}” in the selected categories.`:"No apps match the selected categories."}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{M([]),P("")},children:"Clear filters"})]}):p?t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:se?`No apps match “${k}”.`:o??"No apps registered yet. Register one from the Apps page first."}),!se&&l]}):t.jsxs("p",{className:"w6w-muted w6w-small",children:["No apps match “",k,"”."]}):t.jsxs(t.Fragment,{children:[le.length===0&&ae?t.jsx("p",{className:"w6w-muted w6w-small",children:"No matching apps on this page yet — try “Load more”."}):t.jsx("div",{className:"w6w-stepbuilder-list w6w-apppicker-grid w6w-stepbuilder-scroll",children:le.map(T=>t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(T),children:[t.jsx(pe,{src:T.iconSvg,srcDark:T.iconSvgDark,brandColor:T.brandColor,name:T.displayName,theme:s,size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:T.displayName}),t.jsx("code",{className:"w6w-apppicker-card-id",children:T.id}),T.version&&t.jsxs("span",{className:"w6w-apppicker-card-version",children:["v",T.version]})]})]},T.id))}),p&&K&&t.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[K," ",t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:_,children:"Retry"})]}),p&&ae&&!K&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:C,disabled:J,children:J?"Loading more…":"Load more"})]})]}))}function ks({fields:e,values:s,onChange:n,enterSubmitProps:r}){const o=(a,l)=>n({...s,[a]:l});return t.jsxs("div",{className:"w6w-stack",children:[e.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"This auth method declares no fields — nothing to fill in. The credential will be an empty object."}),e.map(a=>{const l=s[a.key]??a.default??"";if(a.type==="boolean")return t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[t.jsx("input",{type:"checkbox",checked:!!l,onChange:u=>o(a.key,u.target.checked),...r}),a.label,a.required?" *":""]}),a.hint&&t.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key);const i=a.type==="secret",c=a.type==="number"?"number":"text";return t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[a.label,a.required?" *":""]}),t.jsx("input",{type:c,className:i?"w6w-secret-input":void 0,value:String(l??""),onChange:u=>o(a.key,a.type==="number"?Number(u.target.value):u.target.value),name:`w6w-cred-${a.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...r}),a.hint&&t.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key)})]})}const cr="width=560,height=720,menubar=no,toolbar=no,location=no";function Cs(e){return new Promise((s,n)=>{const r=window.open(e,"w6w-oauth",cr);if(!r){n(new Error("Popup blocked — allow popups for this site and try again."));return}let o=!1;const a=()=>{o=!0,window.removeEventListener("message",l),window.clearInterval(i)},l=c=>{const u=c.data;if((u==null?void 0:u.w6w)==="oauth-result"){a();try{r.close()}catch{}u.ok&&typeof u.connectionId=="string"?s({connectionId:u.connectionId}):n(new Error(u.error??"OAuth flow failed."))}};window.addEventListener("message",l);const i=window.setInterval(()=>{o||r.closed&&(a(),n(new Error("OAuth popup was closed before the flow completed.")))},500)})}const ur=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function dr(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function Ss(e,s){return{onKeyDown:n=>{if((s==null?void 0:s.enabled)===!1||n.key!=="Enter"||n.shiftKey||n.altKey||n.ctrlKey||n.metaKey||n.nativeEvent.isComposing)return;const r=n.target;r.tagName!=="TEXTAREA"&&(dr(r)||r.tagName==="INPUT"&&ur.has(r.type)||(n.preventDefault(),e()))}}}function kt(e){const s=te(),[n,r]=d.useState(null),[o,a]=d.useState(!!e.initialAppId);return d.useEffect(()=>{const l=e.initialAppId;if(!l)return;let i=!1;const c=w=>{i||(r(w),a(!1))},u=s.listAppsByIds;if(u)return u([l]).then(w=>c(w.find(h=>h.id===l)??null)).catch(()=>c(null)),()=>{i=!0};const m=s.listApps;return typeof m=="function"?m().then(w=>c(w.find(h=>h.id===l)??null)).catch(()=>c(null)):c(null),()=>{i=!0}},[s,e.initialAppId]),n?t.jsx(ne,{title:n.displayName,subtitle:t.jsxs(t.Fragment,{children:[t.jsx("code",{children:n.id}),n.version&&` · v${n.version}`]}),onClose:e.onClose,size:"xl",titleIcon:t.jsx(pe,{src:n.iconSvg,srcDark:n.iconSvgDark,brandColor:n.brandColor,name:n.displayName,theme:e.theme,size:22}),headerRight:e.initialAppId?void 0:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>r(null),children:"← Apps"}),children:t.jsx(pr,{app:n,onCreated:e.onCreated,onClose:e.onClose})}):o?t.jsx(ne,{title:"Add connection",onClose:e.onClose,size:"xl",children:t.jsx("div",{className:"w6w-stepbuilder-content",children:t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"})})}):t.jsx(ne,{title:"Add connection",onClose:e.onClose,size:"xl",children:t.jsx("div",{className:"w6w-stepbuilder-content",children:t.jsx(xe,{onSelectApp:r,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function pr({app:e,onCreated:s,onClose:n}){const r=te(),[o,a]=d.useState(null),[l,i]=d.useState(""),[c,u]=d.useState(""),[m,w]=d.useState({}),[h,f]=d.useState(null),[p,b]=d.useState(!1);d.useEffect(()=>{let I=!1;return a(null),r.getAppAuth(e.id).then(L=>!I&&a(L.filter(D=>D.available!==!1))).catch(L=>!I&&f(L.message)),()=>{I=!0}},[r,e.id]);const S=o??[],y=S.find(I=>I.key===l)??S.find(I=>I.default===!0)??S[0],x=(y==null?void 0:y.fields)??[],v=(y==null?void 0:y.type)==="oauth2",N=(y==null?void 0:y.key)==="zero-credential",E=!v&&!N&&x.some(I=>I.required&&(m[I.key]===void 0||m[I.key]==="")),k=!y||!v&&!N&&E||p;async function P(){if(y){f(null),b(!0);try{if(N)s({connectionId:`zerocred:${e.id}`});else if(v){const{authorizationUrl:I}=await r.startAppOAuthFlow(e.id,y.key,{displayName:c||void 0}),{connectionId:L}=await Cs(I);s({connectionId:L})}else{const I=await r.createConnection(e.id,{authKey:y.key,credential:m,displayName:c||void 0});s({connectionId:I.id})}}catch(I){f(I.message)}finally{b(!1)}}}const A=Ss(P,{enabled:!k});return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-modal-body",children:t.jsxs("div",{className:"w6w-stack",children:[o===null&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading auth methods…"}),o!==null&&S.length===0&&t.jsx("p",{className:"w6w-muted w6w-small",children:"This app has no available auth methods. If it uses OAuth, its client credentials may not be configured on the server yet."}),S.length>1&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Auth method"}),t.jsx("select",{value:(y==null?void 0:y.key)??"",onChange:I=>{i(I.target.value),w({}),f(null)},children:S.map(I=>t.jsxs("option",{value:I.key,children:[I.displayName??I.key," (",I.type,")"]},I.key))})]}),y&&t.jsxs(t.Fragment,{children:[!N&&t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Display name"}),t.jsx("input",{type:"text",value:c,onChange:I=>u(I.target.value),placeholder:"e.g. Production API key",maxLength:80,name:"w6w-connection-label",autoComplete:"off","data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...A})]}),y.description&&t.jsx("p",{className:"w6w-muted w6w-small",children:y.description}),N?null:v?t.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",t.jsx("strong",{children:y.displayName??y.key})," to authorize this connection."]}):t.jsx(ks,{fields:x,values:m,onChange:w,enterSubmitProps:A})]}),h&&t.jsx("div",{className:"w6w-result w6w-error",children:h})]})}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:n,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:k,onClick:P,children:p?N?"Saving…":v?"Waiting for authorization…":"Saving…":N?"Use this":v?`Sign in with ${(y==null?void 0:y.displayName)??(y==null?void 0:y.key)??"provider"}`:"Save connection"})]})]})}const wr={step:"Re-run this step if it fails, up to N attempts.",function:"Re-run this function call if it fails, up to N attempts.",endpoint:"Re-run this endpoint call if it fails, up to N attempts.",workflow:"Re-run the whole workflow run if it fails, up to N attempts."};function As({value:e,onChange:s,readOnly:n,target:r="step"}){const o=!!e,a=(e==null?void 0:e.maxAttempts)??3,l=(e==null?void 0:e.delayMs)??1e3,i=(e==null?void 0:e.backoff)??"fixed",c=u=>s({maxAttempts:a,delayMs:l,backoff:i,...e,...u});return t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[t.jsx("input",{type:"checkbox",checked:o,disabled:n,onChange:u=>s(u.target.checked?{maxAttempts:a,delayMs:l,backoff:i}:void 0)})," ","Retry on failure"]}),t.jsx("span",{className:"w6w-hint",children:wr[r]})]}),o&&t.jsxs("div",{className:"w6w-field-row",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Attempts"}),t.jsx("input",{type:"number",min:1,value:a,readOnly:n,onChange:u=>c({maxAttempts:Math.max(1,Number(u.target.value)||1)})})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Delay (ms)"}),t.jsx("input",{type:"number",min:0,value:l,readOnly:n,onChange:u=>c({delayMs:Math.max(0,Number(u.target.value)||0)})})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Backoff"}),t.jsxs("select",{value:i,disabled:n,onChange:u=>c({backoff:u.target.value}),children:[t.jsx("option",{value:"fixed",children:"Fixed"}),t.jsx("option",{value:"exponential",children:"Exponential"})]})]})]})]})}function Ct({config:e,onChange:s,readOnly:n,hasGraph:r=!0,failureHandling:o=!0,retryControls:a=!0,reroute:l}){const i=e.onError??"fail";return t.jsxs("div",{className:"w6w-stack",children:[o&&t.jsxs(t.Fragment,{children:[a&&t.jsx(As,{value:e.retry,onChange:c=>s({...e,retry:c}),readOnly:n}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"On error"}),t.jsxs("select",{value:i,disabled:n,onChange:c=>{const u=c.target.value;s({...e,onError:u==="fail"?void 0:u})},children:[t.jsx("option",{value:"fail",children:"Stop the run (default)"}),t.jsx("option",{value:"continue",children:"Continue to the next step"}),r&&t.jsx("option",{value:"continue-record",children:"Continue to the next step & record the error"})]}),r?t.jsxs("span",{className:"w6w-muted w6w-small",children:["Retries run first: this policy is reached only once this step's retry attempts (if any) are exhausted — a run that succeeds on a later attempt continues down the normal path instead. Once reached, ",t.jsx("strong",{children:"Continue"})," and"," ",t.jsx("strong",{children:"Continue & record the error"})," both carry on down this step's ordinary outgoing edges despite the failure. If this step has an outgoing"," ",t.jsx("strong",{children:"error"})," edge on the canvas, that edge decides what happens instead and this policy is not consulted — drawn by dragging from the step's error exit port."]}):t.jsxs("span",{className:"w6w-muted w6w-small",children:["Retries run first: this policy (and reroute, below) is only reached once this step's retry attempts (if any) are exhausted — a run that succeeds on a later attempt continues normally. This step has no canvas of its own, so it can't carry an error edge. Set a ",t.jsx("strong",{children:"reroute"})," target below to send a failure somewhere else instead of stopping."]})]})]}),l&&t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Reroute on failure"}),t.jsxs("div",{className:"w6w-field-row",children:[l.picker,l.value&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:n,onClick:()=>l.onChange(void 0),children:"Clear"})]}),t.jsx("span",{className:"w6w-hint",children:"Invoked once, after retry is exhausted, if this step still fails; its output becomes this step's output."})]}),t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Notes"}),t.jsx("textarea",{rows:3,value:e.notes??"",readOnly:n,placeholder:"A short description — shown under this step on the canvas. Not executed.",onChange:c=>s({...e,notes:c.target.value||void 0})})]})]})}function St(e){return Array.isArray(e)?e:[]}function Es(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function Ts(e,s){if(!(s==null||s==="")){if(typeof s=="object")return s;if(e==="number"){const n=Number(s);return Number.isFinite(n)?n:void 0}if(e==="boolean")return s===!0||s==="true";if(e==="json")try{return JSON.parse(String(s))}catch{return}return String(s)}}function At(e){return e.filter(s=>typeof s.key=="string"&&s.key.trim()!=="").map(s=>({key:s.key,label:s.key,type:Es(s.type),required:!!s.required}))}function Rs(e){const s={};for(const n of e){if(typeof n.key!="string"||n.key.trim()==="")continue;const r=Ts(n.type,n.default);r!==void 0&&(s[n.key]=r)}return s}function Is({app:e,action:s,fields:n,persist:r}){const o=te(),a=Ns(),l=d.useMemo(()=>St(n),[n]),i=d.useMemo(()=>At(l),[l]),c=i.length>0,[u,m]=d.useState(()=>Rs(l)),[w,h]=d.useState(null),f=r==null?void 0:r.workflowId,p=r==null?void 0:r.stepId,[b,S]=d.useState(!f||!p);d.useEffect(()=>{if(!f||!p){S(!0);return}let k=!1;return o.listStepTests(f,p).then(P=>{if(k)return;const A=P.length?P[P.length-1]:null;A!=null&&A.with&&m(I=>({...I,...A.with})),S(!0)}).catch(()=>{k||S(!0)}),()=>{k=!0}},[o,f,p]);const[y,x]=d.useState(!0),v=y&&ge(i,u),N=async()=>{h({status:"running"});let k;try{const P=await o.invokeAction(e,s,{input:u},{project:a});k={status:"done",value:P.value,logs:P.logs}}catch(P){const A=P;k={status:"error",error:A.message??String(P),errorCode:A.code,logs:A.logs}}if(h(k),r)try{const P=await o.saveStepTest(r.workflowId,r.stepId,{input:r.input,with:u});await o.recordStepTestRun(r.workflowId,r.stepId,{stepTestId:P.id,status:k.status==="done"?"succeeded":"failed",input:r.input,output:k.status==="done"?k.value:void 0,error:k.status==="error"?k.error:void 0})}catch(P){console.error("step test persist failed",P)}},E=w&&w.status!=="running"?w.logs:void 0;return t.jsxs("div",{className:"w6w-stack",children:[b?t.jsxs(t.Fragment,{children:[t.jsx(Hs,{params:i,values:u,onChange:m,onValidityChange:x}),!c&&t.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to test with. It becomes the trigger's output state (",t.jsx("code",{children:"input"}),")."]})]}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading saved values…"}),t.jsxs("div",{className:"w6w-steptest",children:[t.jsxs("div",{className:"w6w-steptest-bar",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!b||!v||(w==null?void 0:w.status)==="running",onClick:N,children:(w==null?void 0:w.status)==="running"?"Running…":"▶ Test run"}),b&&!v&&t.jsx("span",{className:"w6w-muted w6w-small",children:y?"Fill the required fields to test.":"The payload must be a JSON object to test."})]}),(w==null?void 0:w.status)==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[w.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:w.errorCode})}),w.error]}),(w==null?void 0:w.status)==="done"&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Output state (filled values)"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(w.value,null,2)})]}),E&&E.length>0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Console output"}),t.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:E.join(`
9
- `)})]})]})]})}function Ps(e,s,n){return e*s>.6*n}function Ms(e,s){const n=s.trim().toLowerCase();return n?e.filter(r=>r.label.toLowerCase().includes(n)||r.value.toLowerCase().includes(n)):e}const hr={position:"absolute",zIndex:50,left:0,right:0,top:"100%",maxHeight:240,overflowY:"auto",margin:0,padding:4,listStyle:"none",background:"var(--w6w-surface, #fff)",border:"1px solid var(--w6w-border, #ccc)",borderRadius:6,boxShadow:"0 4px 12px rgba(0,0,0,0.15)"};function Os({options:e,value:s,onChange:n,placeholder:r,disabled:o,"aria-label":a,mode:l="auto",forceSelection:i=!0,optionHeight:c=32,className:u}){var j;const m=l==="combobox"||l==="auto"&&Ps(e.length,c,typeof window>"u"?0:window.innerHeight),w=d.useId(),h=((j=e.find(C=>C.value===s))==null?void 0:j.label)??(i?"":s),[f,p]=d.useState(h),[b,S]=d.useState(!1),[y,x]=d.useState(!1),[v,N]=d.useState(0),E=d.useRef(null);d.useEffect(()=>{p(h)},[h]);const k=d.useMemo(()=>y?Ms(e,f):e,[e,f,y]);if(!m)return t.jsxs("select",{className:u,value:s,disabled:o,"aria-label":a,onChange:C=>n(C.target.value),children:[r!==void 0&&s===""&&t.jsx("option",{value:"",disabled:!0,children:r}),e.map(C=>t.jsx("option",{value:C.value,children:C.label},C.value))]});const P=C=>`${w}-opt-${C}`,A=()=>{S(!1),x(!1)},I=C=>{p(C.label),n(C.value),A()},L=C=>{C.key==="ArrowDown"?(C.preventDefault(),b?N(_=>Math.min(_+1,k.length-1)):S(!0)):C.key==="ArrowUp"?(C.preventDefault(),b?N(_=>Math.max(_-1,0)):S(!0)):C.key==="Enter"?b&&k[v]?(C.preventDefault(),I(k[v])):i||(n(f),A()):C.key==="Escape"&&(b&&C.stopPropagation(),p(h),A())},D=()=>{i?p(h):f!==s&&n(f),A()};return t.jsxs("div",{ref:E,style:{position:"relative"},children:[t.jsx("input",{type:"text",role:"combobox",className:u,value:f,disabled:o,placeholder:r,"aria-label":a,"aria-expanded":b,"aria-controls":`${w}-list`,"aria-autocomplete":"list","aria-activedescendant":b&&k[v]?P(v):void 0,autoComplete:"off",onFocus:()=>S(!0),onChange:C=>{p(C.target.value),x(!0),N(0),S(!0)},onKeyDown:L,onBlur:D}),b&&t.jsxs("div",{id:`${w}-list`,role:"listbox",tabIndex:-1,"aria-label":a,style:hr,children:[k.map((C,_)=>t.jsx("div",{id:P(_),role:"option",tabIndex:-1,"aria-selected":C.value===s,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:_===v?"var(--w6w-hover, rgba(127,127,127,0.18))":void 0},onMouseDown:U=>{U.preventDefault(),I(C)},onMouseEnter:()=>N(_),children:C.label},C.value)),k.length===0&&t.jsx("div",{role:"presentation",style:{padding:"6px 8px",opacity:.6},children:"No matches"})]})]})}function Ye({icon:e,size:s=28}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:s,height:s,borderRadius:6,flexShrink:0,background:"var(--w6w-icon-swatch, var(--w6w-panel-2))",color:"var(--w6w-accent)"},children:t.jsx("svg",{width:Math.round(s*.6),height:Math.round(s*.6),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",dangerouslySetInnerHTML:{__html:e}})})}function He(e,s,n){return n==="error"?`${e}->${s}:error`:`${e}->${s}`}function fr(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function mr(e,s,n){const r=(w,h)=>!w||!h?void 0:He(w,h)===s?"success":He(w,h,"error")===s?"error":void 0,o=r(n[0],n[1]),a=r(n[2],n[3]),l=o!==void 0&&o===a,i=o!==void 0&&a!==void 0&&o!==a,c=o==="success"?n[1]:n[3],u=l?n.find(w=>!!w&&w.includes("->")):i&&(c!=null&&c.endsWith(":error"))?c:void 0,m=u===void 0?"Rename one of the steps it connects, then try again.":l?`A step id containing “->” collides with the edge-id separator, so two different edges mint one id — rename the step “${u}”, then try again.`:`A step id ending in “:error” collides with the error-lane marker, so two different edges mint one id — rename the step “${u}”, then try again.`;return`${e}: the id “${s}” is already taken by another edge. ${m}`}const br=240,xr=100,gr=40,yr=40;function Fs(e,s){return{x:gr+e*br,y:yr+s*xr}}function $s(e,s){var i;const n=new Map,r=new Map;for(const c of e)n.set(c.id,0),r.set(c.id,[]);for(const c of s)(i=r.get(c.to))==null||i.push(c.from);const o=e.length+1;let a=0,l=!0;for(;l&&a<o;){a++,l=!1;for(const c of e){const u=r.get(c.id)??[];if(u.length===0)continue;const m=u.reduce((w,h)=>Math.max(w,(n.get(h)??0)+1),0);(n.get(c.id)??0)<m&&(n.set(c.id,m),l=!0)}}if(l){const c=Math.max(0,e.length-1);for(const[u,m]of n)m>c&&n.set(u,c)}return n}function jr(e){const s=e.position;if(!(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y)))return{x:s.x,y:s.y}}function vr(e){const s=e.edges??Sr(e.steps),n=$s(e.steps,s),r=new Map,o=e.steps.map(l=>{const i=me(l.uses.app),c=n.get(l.id)??0,u=r.get(c)??0;return r.set(c,u+1),{id:l.id,type:i?"control":"step",position:jr(l)??Fs(c,u),data:{step:l,isInternal:i}}}),a=s.map(l=>{const i=l.when??"success";return{id:He(l.from,l.to,i),source:l.from,target:l.to,sourceHandle:ms(i),animated:!1,data:{when:i},...fs(i,void 0)}});return{nodes:o,edges:a}}function Nr(e,s){const n=e.map(a=>({...a.data.step,id:a.id})),r=$s(n,s.map(a=>({from:a.source,to:a.target}))),o=new Map;return e.map(a=>{const l=r.get(a.id)??0,i=o.get(l)??0;return o.set(l,i+1),{...a,position:Fs(l,i)}})}function kr(e,s,n){var m,w;const r=((m=e.settings)==null?void 0:m.savePosition)!==!1,o=new Map(s.map(h=>[h.id,h])),a=h=>{var p;if(!r)return h;const f=(p=o.get(h.id))==null?void 0:p.position;return!f||!Number.isFinite(f.x)||!Number.isFinite(f.y)?h:{...h,position:{x:Math.round(f.x),y:Math.round(f.y)}}},l=new Map;for(const h of e.steps)l.set(h.id,h);for(const h of s)(w=h.data)!=null&&w.step&&l.set(h.id,h.data.step);const i=[],c=new Set;for(const h of e.steps){const f=l.get(h.id);f&&s.some(p=>p.id===h.id)&&(i.push(a(f)),c.add(h.id))}for(const h of s){if(c.has(h.id))continue;const f=l.get(h.id);f&&i.push(a(f))}const u=n.map(h=>{var p;const f=(p=h.data)==null?void 0:p.when;return f==="error"?{from:h.source,to:h.target,when:f}:{from:h.source,to:h.target}});return{...e,steps:i,edges:u}}function Ls(e){var n;const s=(n=e.settings)==null?void 0:n.viewport;if(!(!s||!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.zoom)))return{x:s.x,y:s.y,zoom:s.zoom}}function Cr(e,s){var l;if(!(((l=e.settings)==null?void 0:l.savePosition)!==!1)||!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.zoom))return e;const r={x:Math.round(s.x),y:Math.round(s.y),zoom:Math.round(s.zoom*1e3)/1e3},o=Ls(e);if(o&&o.x===r.x&&o.y===r.y&&o.zoom===r.zoom)return e;const a=typeof e.settings=="object"&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:void 0;return{...e,settings:{...a,viewport:r}}}function Sr(e){const s=[];for(let n=0;n<e.length-1;n++)s.push({from:e[n].id,to:e[n+1].id});return s}function Ar(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function Er(e,s){const n=new Set(s.map(r=>r.target));return e.find(r=>!n.has(r.id))}function Tr(e,s){const n=new Set(s.map(r=>r.source));for(let r=e.length-1;r>=0;r--)if(!n.has(e[r].id))return e[r]}function Rr(e,s="step"){const n=new Set(e);for(let r=1;r<1e3;r++){const o=`${s}_${r}`;if(!n.has(o))return o}return`${s}_${crypto.randomUUID().slice(0,8)}`}function Et(e){return JSON.stringify(e,null,2)}function Tt(e){return JSON.stringify(e.with??{},null,2)}const Ir=3,Pr=100;function Ve(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Mr(e){if(!Array.isArray(e))return;const s=[];for(const n of e){if(!Ve(n)||typeof n.key!="string"||n.key==="")continue;const r=typeof n.label=="string"&&n.label!==""?n.label:void 0;s.push(r?{key:n.key,label:r,path:!0}:{key:n.key,path:!0})}return s.length>0?s:void 0}function wt(e){if(!Ve(e))return;const s=[],n=(r,o,a)=>{for(const[l,i]of Object.entries(r)){if(s.length>=Pr)return;const c=o?`${o}.${l}`:l;s.push({key:c,path:!0}),Ve(i)&&a<Ir&&n(i,c,a+1)}};return n(e,"",1),s.length>0?s:void 0}function Or(e,s){let n=e;for(const r of s.split(".")){if(!Ve(n)||!(r in n))return;n=n[r]}return n}function Fr(e,s){const n=Mr(e==null?void 0:e.output);if(n)return{fields:n,from:"declared"};const r=wt(e==null?void 0:e.sample);if(r)return{fields:r,from:"sample"};const o=wt(s);if(o)return{fields:o,from:"test"}}function Ds(e,s){const n=new Map;for(const a of s){const l=n.get(a.target)??[];l.push(a.source),n.set(a.target,l)}const r=new Set,o=[e];for(;o.length;){const a=o.pop();for(const l of n.get(a)??[])r.has(l)||(r.add(l),o.push(l))}return r}function _s(e,s,n={}){var a,l,i,c,u;const r=[];let o=!1;for(const m of s){if(!e.has(m.id))continue;const w=m.data.step,h=((a=be(w.uses.app,w.uses.action))==null?void 0:a.group)==="trigger";h&&(o=!0);const p=h&&w.uses.app===Ge?At(St((l=w.with)==null?void 0:l.fields)).map(N=>({key:N.key,label:N.label})):((i=be(w.uses.app,w.uses.action))==null?void 0:i.output)??[],b={id:w.id,label:w.id};if(p.length>0){r.push({...b,outputs:p});continue}if(h){r.push(b);continue}const S=(c=n.testOutputs)==null?void 0:c[w.id];if(me(w.uses.app)){const N=wt(S);r.push(N?{...b,outputs:N,outputsFrom:"test"}:b);continue}const y=(u=n.actionDef)==null?void 0:u.call(n,w.uses.app,w.uses.action),x=Fr(y,S),v=w.uses.app.trim()!==""?{hasMeta:!0}:{};x?r.push({...b,outputs:x.fields,outputsFrom:x.from,...v}):r.push(y?{...b,needsTest:!0,...v}:{...b,...v})}return{steps:r,hasTrigger:o}}function $r(e,s,n,r){const o=e?Ds(e,n):new Set(s.map(a=>a.id));return _s(o,s,r)}function Lr(e,s,n,r){if(!e||e.handleType==="target")return[];const o=Ds(e.nodeId,n);return o.add(e.nodeId),_s(o,s,r).steps}async function Dr(e,s){return(await Promise.all(s.map(async r=>{try{const o=await e(r.id),a=o.length?o[o.length-1]:null;return a?{stepId:r.id,label:r.label??r.id,test:a}:null}catch{return null}}))).filter(r=>r!==null)}function Rt(e){const s={};for(const n of e){const r=n.test.lastRunOutput,o=r!=null;if(!o&&n.test.lastRunStatus!=="succeeded")continue;const a=n.test.lastRunMeta;s[n.stepId]={output:o?r:null,...a?{meta:a}:{}}}return Object.keys(s).length>0?{steps:s}:void 0}function _r(e,s){if(!s)return{};const n=`steps.${e}.meta`;return{[`${n}.app`]:s.app,[`${n}.version`]:s.version,[`${n}.action`]:s.action,[`${n}.connectionId`]:s.connectionId}}function It(e,s,n){const r=te(),[o,a]=d.useState([]),l=JSON.stringify(s.map(i=>[i.id,i.label]));return d.useEffect(()=>{const i=JSON.parse(l);if(!n||i.length===0){a([]);return}let c=!1;return Dr(u=>r.listStepTests(e,u),i.map(([u,m])=>({id:u,label:m}))).then(u=>{c||a(u)}),()=>{c=!0}},[r,e,l,n]),o}const qr=["function","workflow"],Hr={workflow:'<line x1="6" y1="3" x2="6" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',function:'<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>'},rt={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},Vr=["props","code","params-code","config"];function Xe({view:e,onChange:s,disabled:n,views:r=Vr}){const o=a=>t.jsx("button",{type:"button",title:rt[a].label,"aria-label":rt[a].label,"aria-pressed":e===a,disabled:n,className:`w6w-icon-btn${e===a&&!n?" active":""}`,onClick:()=>s(a),children:t.jsx(ue.Icon,{name:rt[a].icon,size:15})},a);return t.jsx("div",{className:"w6w-view-toggle",children:r.map(o)})}function Wr({onClose:e,onAdd:s,onDraftChange:n,theme:r,appsOnly:o,callables:a=qr,initialTab:l,title:i,workflowId:c,stepId:u,upstreamSteps:m=[],initialApp:w,initialAction:h,initialConnection:f,initialWith:p,appsFilter:b,connectionOnly:S,onConnected:y}){const[x,v]=d.useState(l??"connected"),[N,E]=d.useState(w??null),[k,P]=d.useState(null),[A,I]=d.useState(null),L=sa(a,b),D=L.state!=="empty";return d.useEffect(()=>{!D&&x==="connected"&&v("apps")},[D,x]),A?t.jsx(ne,{title:A.label,subtitle:t.jsx("code",{children:A.id}),onClose:e,size:"xl",headerRight:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>I(null),children:"← Back"}),children:t.jsx("div",{className:"w6w-stepbuilder-config",children:t.jsx(ea,{family:A.family,targetId:A.id,targetLabel:A.label,onAdd:s,onClose:e,onDraftChange:n})})}):k?t.jsx(ne,{title:k.label,titleIcon:t.jsx(Ye,{icon:k.icon,size:22}),subtitle:t.jsxs("code",{children:[k.app," · ",k.action]}),onClose:e,size:"xl",headerRight:t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>P(null),children:"← Back"}),children:t.jsx("div",{className:"w6w-stepbuilder-config",children:t.jsx(Xr,{node:k,onAdd:s,onClose:e,onDraftChange:n,workflowId:c,upstreamSteps:m})})}):N?t.jsx(ne,{title:N.displayName,subtitle:t.jsxs(t.Fragment,{children:[t.jsx("code",{children:N.id}),N.version&&` · v${N.version}`]}),onClose:e,size:"xl",titleIcon:t.jsx(pe,{src:N.iconSvg,srcDark:N.iconSvgDark,brandColor:N.brandColor,name:N.displayName,theme:r,size:22}),children:t.jsx("div",{className:"w6w-stepbuilder-config",children:S?t.jsx(aa,{appId:N.id,app:N,onClose:e,onChangeApp:()=>E(null),theme:r,initialConnection:f,onConnected:(j,C)=>y==null?void 0:y(j,C)}):t.jsx(ra,{appId:N.id,app:N,onAdd:s,onClose:e,onDraftChange:n,onChangeApp:()=>E(null),theme:r,workflowId:c,stepId:u,upstreamSteps:m,initialAction:h,initialConnection:f,initialWith:p})})}):t.jsx(ne,{title:i??"Add a step",onClose:e,size:"xl",children:t.jsxs("div",{className:"w6w-stepbuilder",children:[t.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[D&&t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="connected"?" active":""}`,onClick:()=>v("connected"),children:"Ready to use"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="apps"?" active":""}`,onClick:()=>v("apps"),children:"Apps"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="ai"?" active":""}`,onClick:()=>v("ai"),children:"AI"}),a.includes("workflow")&&t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="workflows"?" active":""}`,onClick:()=>v("workflows"),children:"Workflows"}),a.includes("function")&&t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="functions"?" active":""}`,onClick:()=>v("functions"),children:"Functions"}),!o&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="triggers"?" active":""}`,onClick:()=>v("triggers"),children:"Triggers"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="controls"?" active":""}`,onClick:()=>v("controls"),children:"Controls"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="utilities"?" active":""}`,onClick:()=>v("utilities"),children:"Utilities"}),t.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${x==="data"?" active":""}`,onClick:()=>v("data"),children:"Data"})]})]}),t.jsx("div",{className:"w6w-stepbuilder-content",children:x==="connected"?t.jsx(na,{data:L,onSelectApp:E,onSelectCallable:I,theme:r}):x==="functions"?t.jsx(Ut,{family:"function",onSelect:j=>I({family:"function",...j})}):x==="workflows"?t.jsx(Ut,{family:"workflow",onSelect:j=>I({family:"workflow",...j})}):x==="apps"?t.jsx(xe,{onSelectApp:E,theme:r,filter:b}):x==="ai"?t.jsx(xe,{onSelectApp:E,theme:r,category:"ai",filter:j=>{var C;return((b==null?void 0:b(j))??!0)&&(((C=j.categories)==null?void 0:C.includes("ai"))??!1)},searchPlaceholder:"Search AI apps…",emptyMessage:"No AI apps registered yet."}):x==="triggers"?t.jsx(Ur,{onSelect:P,workflowId:c,onClose:e}):x==="controls"?t.jsx(Gr,{onSelect:P}):x==="data"?t.jsx(Yr,{onSelect:P}):t.jsx(Kr,{onSelect:P})})]})})}function Qe({nodes:e,onSelect:s}){return t.jsx("div",{className:"w6w-stepbuilder-list",children:e.map(n=>t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>s(n),children:[t.jsx(Ye,{icon:n.icon,size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:n.label}),t.jsxs("code",{className:"w6w-muted w6w-small",children:[n.app," · ",n.action]})]})]},`${n.app}:${n.action}`))})}function Ur({onSelect:e,workflowId:s,onClose:n}){const r=ye.filter(a=>a.group==="trigger"),o=te();return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Triggers start a workflow — run it manually or on an inbound webhook."}),t.jsx(Qe,{nodes:r,onSelect:e}),s&&o.listTriggerApps&&t.jsx(Jr,{workflowId:s,onClose:n})]})}function Br(e){return(e.triggerCount??0)>0}function Jr({workflowId:e,onClose:s}){const n=te(),r=typeof n.listAppsPage=="function",[o,a]=d.useState(null),[l,i]=d.useState(null),[c,u]=d.useState(null);return d.useEffect(()=>{if(r)return;const m=n.listTriggerApps;if(!m)return;let w=!1;return m().then(h=>!w&&a(h)).catch(h=>!w&&i(h.message)),()=>{w=!0}},[n,r]),!r&&!n.listTriggerApps?null:t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("p",{className:"w6w-muted w6w-small",children:[t.jsx("strong",{children:"App triggers"})," — bind one of these apps' declared triggers to this workflow."]}),c?t.jsx(zr,{app:c,workflowId:e,onBack:()=>u(null),onClose:s}):r?t.jsx(xe,{onSelectApp:u,filter:Br,search:!0,searchPlaceholder:"Search apps with triggers…",emptyMessage:"No apps declare triggers yet."}):l?t.jsx("div",{className:"w6w-result w6w-error",children:l}):t.jsx(xe,{apps:o,onSelectApp:u,search:!1,emptyMessage:"No apps declare triggers yet."})]})}function zr({app:e,workflowId:s,onBack:n,onClose:r}){const o=te(),[a,l]=d.useState(null),[i,c]=d.useState(null),[u,m]=d.useState(!1),[w,h]=d.useState(null),[f,p]=d.useState("5");d.useEffect(()=>{const x=o.getAppTriggers;if(!x)return;let v=!1;return x(e.id).then(N=>!v&&l(N)).catch(N=>!v&&c(N.message)),()=>{v=!0}},[o,e.id]);const b=x=>Math.max(1,Math.ceil((x.minIntervalMs??0)/6e4)),S=x=>{if(x.type!=="poll")return y(x.key);c(null),h(x),p(String(Math.max(5,Math.ceil((x.minIntervalMs??0)/6e4))))},y=(x,v)=>{const N=o.createSubscription;N&&(c(null),m(!0),N(e.id,x,{workflowId:s,connectionId:null,params:{},...v===void 0?{}:{intervalMs:v}}).then(()=>r()).catch(E=>{m(!1),c(E instanceof Error?E.message:String(E))}))};return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:n,children:"← Back"}),t.jsx("strong",{children:e.displayName}),i&&t.jsx("div",{className:"w6w-result w6w-error",children:i}),a===null?t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading triggers…"}):a.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"This app declares no triggers."}):t.jsx("div",{className:"w6w-stepbuilder-list",children:a.map(x=>t.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:u,onClick:()=>S(x),children:t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:x.title}),t.jsx("code",{className:"w6w-muted w6w-small",children:x.key}),x.description&&t.jsx("span",{className:"w6w-muted w6w-small",children:x.description})]})},x.key))}),w&&t.jsxs("div",{className:"w6w-stack",children:[t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Check every … minutes"}),t.jsx("input",{type:"number",min:b(w),step:1,value:f,disabled:u,onChange:x=>p(x.target.value),onBlur:()=>p(String(Jt(f,b(w))))})]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-primary w6w-btn-sm",disabled:u,onClick:()=>y(w.key,Jt(f,b(w))*6e4),children:"Add trigger"})]})]})}function Gr({onSelect:e}){const s=ye.filter(n=>n.group==="control"&&!n.hidden);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes branch, loop, parallelize, or pause the run."}),t.jsx(Qe,{nodes:s,onSelect:e})]})}function Kr({onSelect:e}){const s=ye.filter(n=>n.group!=="control"&&n.group!=="trigger"&&n.app!==ze&&!n.hidden);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Utilities run a script, call an HTTP(S) endpoint, or respond to a webhook."}),t.jsx(Qe,{nodes:s,onSelect:e})]})}function Yr({onSelect:e}){const s=ye.filter(n=>n.app===ze);return t.jsxs("div",{className:"w6w-stack",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:"Declare typed key/value variables for downstream steps to reference."}),t.jsx(Qe,{nodes:s,onSelect:e})]})}function Xr({node:e,onAdd:s,onClose:n,onDraftChange:r,workflowId:o,upstreamSteps:a=[]}){const[l,i]=d.useState(()=>gs(e.app,e.action)),c=!Le(e.app),u=It(o??"",a,c&&!!o),m=Rt(u),[w,h]=d.useState("configure"),[f,p]=d.useState("props"),[b,S]=d.useState("{}"),[y,x]=d.useState("{}"),[v,N]=d.useState({}),E=ge(e.params,l),[k,P]=d.useState(null),A=()=>({uses:{app:e.app,action:e.action},with:l,...v});d.useEffect(()=>{if(!r)return;const D=s(A());D&&P(D)},[]),d.useEffect(()=>{!r||k===null||r(k,A())},[k,l,v]);const I=D=>{D==="code"?S(Et(A())):D==="params-code"&&x(Tt(A())),p(D)},L=()=>s(A());return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsxs("div",{className:"w6w-subtabs",children:[t.jsx("button",{type:"button",className:`w6w-subtab${w==="configure"?" active":""}`,onClick:()=>h("configure"),children:"Configure"}),c&&t.jsx("button",{type:"button",disabled:!E,title:E?void 0:"Fill the required fields first",className:`w6w-subtab${w==="test"?" active":""}`,onClick:()=>E&&h("test"),children:"Test"})]}),t.jsx(Xe,{view:f,onChange:I,disabled:w!=="configure"})]}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[w==="configure"&&(f==="props"?e.action==="wait"&&Le(e.app)?t.jsx(hs,{values:l,onChange:i}):t.jsx(de,{params:e.params,values:l,onChange:i}):f==="code"?t.jsx(ce,{value:b,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Step JSON",copyable:!0}):f==="params-code"?t.jsx(ce,{value:y,onChange:x,minHeight:"240px",height:"100%","aria-label":"Parameters JSON",copyable:!0,onValidChange:D=>D&&typeof D=="object"&&!Array.isArray(D)&&i(D)}):t.jsx(Ct,{config:v,onChange:N,failureHandling:!qe(e.app),retryControls:!Le(e.app)&&e.app!==Ke})),w==="test"&&c&&(qe(e.app)?t.jsx(Is,{app:e.app,action:e.action,fields:l.fields}):t.jsx(Pt,{app:e.app,action:e.action,values:l,canRun:E,state:m}))]}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:n,children:"Cancel"}),w==="configure"&&c?t.jsx("button",{type:"button",className:"w6w-btn",disabled:!E,onClick:()=>h("test"),children:"Next →"}):t.jsx("button",{type:"button",className:"w6w-btn",onClick:k!==null?n:L,children:k!==null?"Done":"Add step"})]})]})}function Ut({family:e,onSelect:s}){const n=te(),[r,o]=d.useState(null),[a,l]=d.useState(null),[i,c]=d.useState(""),u=e==="function"?"Functions":"Workflows";d.useEffect(()=>{let b=!1;return(e==="function"?n.listFunctions():n.listWorkflows()).then(y=>!b&&o(y)).catch(y=>!b&&l(y.message)),()=>{b=!0}},[n,e]);const m=b=>t.jsx("div",{className:"w6w-apppicker-host",children:b});if(a)return m(t.jsx("div",{className:"w6w-result w6w-error",children:a}));if(r===null)return m(t.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",u.toLowerCase(),"…"]}));if(r.length===0)return m(t.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",u.toLowerCase()," registered yet."]}));const w=We,h=i.trim().toLowerCase(),f=[...r].sort(De(w)),p=h?f.filter(b=>w(b).toLowerCase().includes(h)||b.id.toLowerCase().includes(h)):f;return m(t.jsxs("div",{className:"w6w-stepbuilder-apps",children:[t.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:`Search ${u.toLowerCase()}…`,value:i,onChange:b=>c(b.target.value),"aria-label":`Search ${u.toLowerCase()}`}),p.length===0?t.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",u.toLowerCase()," match “",i,"”."]}):t.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:p.map(b=>t.jsx(ht,{family:e,item:b,onSelect:s},b.id))})]}))}const Qr=["string","number","boolean","json"];function Zr(e){var o;const s=e.steps.find(a=>qe(a.uses.app)),n=(o=s==null?void 0:s.with)==null?void 0:o.fields;if(!Array.isArray(n))return[];const r=[];for(const a of n){if(typeof a!="object"||a===null)continue;const l=a,i=typeof l.key=="string"?l.key:"";if(!i)continue;const c=typeof l.type=="string"?l.type:"string";r.push({key:i,label:i,type:Qr.includes(c)?c:"string",default:l.default,required:!!l.required})}return r}function ea({family:e,targetId:s,targetLabel:n,onAdd:r,onClose:o,onDraftChange:a}){const l=te(),[i,c]=d.useState(null),[u,m]=d.useState(null),[w,h]=d.useState({}),[f,p]=d.useState(!0),[b,S]=d.useState("configure"),[y,x]=d.useState(null);d.useEffect(()=>{let k=!1;return c(null),m(null),(e==="function"?l.getFunction(s).then(A=>A.inputs):l.getWorkflow(s).then(Zr)).then(A=>!k&&c(A)).catch(A=>!k&&m(A.message)),()=>{k=!0}},[l,e,s]);const v=i!==null&&ge(i,w),N=()=>({uses:{app:Ke,action:"call"},with:{targetKind:e,targetId:s,inputs:w,wait:f}});d.useEffect(()=>{if(!a)return;const k=r(N());k&&x(k)},[]),d.useEffect(()=>{!a||y===null||a(y,N())},[y,w,f]);const E=()=>r(N());return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-tabsbar",children:t.jsxs("div",{className:"w6w-subtabs",children:[t.jsx("button",{type:"button",className:`w6w-subtab${b==="configure"?" active":""}`,onClick:()=>S("configure"),children:"Configure"}),t.jsx("button",{type:"button",disabled:!v,title:v?void 0:"Fill the required fields first",className:`w6w-subtab${b==="test"?" active":""}`,onClick:()=>v&&S("test"),children:"Test"})]})}),t.jsx("div",{className:"w6w-stepconfig-body",children:b==="configure"?t.jsxs("div",{className:"w6w-stack",children:[u?t.jsx("div",{className:"w6w-result w6w-error",children:u}):i===null?t.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",n,"’s inputs…"]}):i.length===0?t.jsxs("p",{className:"w6w-muted w6w-small",children:[n," declares no inputs — it can be called as-is."]}):t.jsx(de,{params:i,values:w,onChange:h}),t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:[t.jsx("input",{type:"checkbox",checked:f,onChange:k=>p(k.target.checked)})," ","Wait for completion"]}),t.jsx("span",{className:"w6w-hint",children:"On: block until the sub-run finishes and expose its output. Off: return a run handle and continue."})]})]}):t.jsx(ta,{family:e,targetId:s,inputs:w,canRun:v})}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:o,children:"Cancel"}),b==="configure"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:!v,onClick:()=>S("test"),children:"Next →"}):t.jsx("button",{type:"button",className:"w6w-btn",onClick:y!==null?o:E,children:y!==null?"Done":"Add step"})]})]})}function ta({family:e,targetId:s,inputs:n,canRun:r}){const o=te(),[a,l]=d.useState(null),i=async()=>{if(!(!r||(a==null?void 0:a.status)==="running")){l({status:"running"});try{if(e==="function"){const c=await o.invokeFunction(s,n);l({status:"done",output:c,terminal:!0})}else{const c=await o.runWorkflow(s,{input:n});l({status:"done",output:c.output,runId:c.runId,terminal:c.terminal,error:c.error})}}catch(c){l({status:"error",error:c.message??String(c)})}}};return t.jsxs("div",{className:"w6w-steptest",children:[t.jsxs("div",{className:"w6w-steptest-bar",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!r||(a==null?void 0:a.status)==="running",onClick:i,children:(a==null?void 0:a.status)==="running"?"Running…":"▶ Test run"}),!r&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(a==null?void 0:a.status)==="error"&&t.jsx("div",{className:"w6w-result w6w-error",children:a.error}),(a==null?void 0:a.status)==="done"&&!a.terminal&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Still running"}),t.jsxs("div",{className:"w6w-result",children:["Run ",t.jsx("code",{children:a.runId})," has not finished yet — check its status from the workflow's run history."]})]}),(a==null?void 0:a.status)==="done"&&a.terminal&&a.error!==void 0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Run failed"}),t.jsx("pre",{className:"w6w-result w6w-error",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(a.error,null,2)})]}),(a==null?void 0:a.status)==="done"&&a.terminal&&a.error===void 0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Result"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(a.output,null,2)})]})]})}function ge(e,s){const n=fe(e),r=a=>{var l;return s[a]!==void 0?s[a]:(l=n.find(i=>i.key===a))==null?void 0:l.default},o=(a,l,i)=>a.every(c=>{if(c.type==="section")return o(c.children??[],l,i);if(c.type==="group"){const m=c.children??[],w=fe(m),h=p=>b=>{const S=w.find(y=>y.key===b);return S?p[b]!==void 0?p[b]:S.default:i(b)};if(c.repeat){const p=Array.isArray(l[c.key])?l[c.key]:[];return p.length===0?!c.required:p.every(b=>{const S=b??{};return o(m,S,h(S))})}const f=l[c.key]??{};return o(m,f,h(f))}if(!c.required||!Pe(c,i))return!0;const u=l[c.key]??c.default;return u==null?!1:typeof u=="string"?u.trim()!=="":!0});return o(e,s,r)}function qs(e){const s=e==null?void 0:e.testRequired;return typeof s=="boolean"?s:!0}const Pt=d.forwardRef(function({app:s,action:n,connectionId:r,values:o,canRun:a,hideRunButton:l,persist:i,state:c,onBusyChange:u,onResult:m},w){const h=te(),f=Ns(),[p,b]=d.useState(null),S=async()=>{if(!a||(p==null?void 0:p.status)==="running")return;b({status:"running"}),u==null||u(!0);let x;try{const v=await h.invokeAction(s,n,o,{...r?{connectionId:r}:{},project:f,...c?{state:c}:{}});x={status:"done",value:v.value,logs:v.logs,...v.meta?{meta:v.meta}:{}}}catch(v){const N=v;x={status:"error",error:N.message??String(v),errorCode:N.code,logs:N.logs}}if(b(x),m==null||m(x.status==="done"),i)try{const v=await h.saveStepTest(i.workflowId,i.stepId,{input:i.input,with:o});await h.recordStepTestRun(i.workflowId,i.stepId,{stepTestId:v.id,status:x.status==="done"?"succeeded":"failed",input:i.input,output:x.status==="done"?x.value:void 0,error:x.status==="error"?x.error:void 0,...x.status==="done"&&x.meta?{meta:x.meta}:{}})}catch(v){console.error("step test persist failed",v)}u==null||u(!1)};d.useImperativeHandle(w,()=>({run:S}));const y=p&&p.status!=="running"?p.logs:void 0;return t.jsxs("div",{className:"w6w-steptest",children:[!l&&t.jsxs("div",{className:"w6w-steptest-bar",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!a||(p==null?void 0:p.status)==="running",onClick:S,children:(p==null?void 0:p.status)==="running"?"Running…":"▶ Test run"}),!a&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(p==null?void 0:p.status)==="error"&&t.jsxs("div",{className:"w6w-result w6w-error",children:[p.errorCode&&t.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:t.jsx("code",{children:p.errorCode})}),p.error]}),(p==null?void 0:p.status)==="done"&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Result (return value)"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(p.value,null,2)}),p.meta&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),t.jsx("pre",{className:"w6w-result",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(p.meta,null,2)})]})]}),y&&y.length>0&&t.jsxs("div",{className:"w6w-testout",children:[t.jsx("div",{className:"w6w-testout-label",children:"Console output"}),t.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:y.join(`
10
- `)})]})]})}),Bt=12,$e=new Set;function Jt(e,s){const n=Number(e.trim());return e.trim()===""||!Number.isFinite(n)||n<s?s:Math.max(s,Math.round(n))}function sa(e,s){const n=te(),[r,o]=d.useState(null),[a,l]=d.useState(null),[i,c]=d.useState(null),[u,m]=d.useState(null),[w,h]=d.useState(null),[f,p]=d.useState(()=>new Map),[b,S]=d.useState(()=>new Set),[y,x]=d.useState($e),v=d.useRef($e),N=d.useCallback(M=>{v.current=M,x(M)},[]),E=d.useRef($e),k=e.includes("function"),P=e.includes("workflow"),A=typeof n.listAppsByIds=="function";d.useEffect(()=>{let M=!1;const W=H=>!M&&h(H.message);return n.listConnections().then(H=>{if(M)return;const X=[],ee=new Set,G=new Map;for(const J of H)me(J.appId)||(A&&J.app&&!G.has(J.appId)&&G.set(J.appId,{...J.app,id:J.appId}),!ee.has(J.appId)&&(ee.add(J.appId),X.push(J.appId)));G.size>0&&(E.current=new Set(G.keys()),p(J=>new Map([...J,...G])),S(J=>new Set([...J,...G.keys()]))),o(X)}).catch(W),k?n.listFunctions().then(H=>!M&&c(H)).catch(W):c([]),P?n.listWorkflows().then(H=>!M&&m(H)).catch(W):m([]),()=>{M=!0}},[n,A,k,P]),d.useEffect(()=>{if(A)return;const M=n.listApps;if(typeof M!="function"){l([]);return}let W=!1;return M().then(H=>!W&&l(H)).catch(H=>!W&&h(H.message)),()=>{W=!0}},[n,A]);const I=d.useRef(!0);d.useEffect(()=>()=>{I.current=!1},[]);const L=d.useCallback(M=>{const W=n.listAppsByIds;!W||M.length===0||v.current.size>0||(N(new Set(M)),W(M).then(H=>{I.current&&(N($e),p(X=>{const ee=new Map(X);for(const G of H)ee.set(G.id,G);return ee}),S(X=>new Set([...X,...M])))}).catch(H=>I.current&&h(H.message)))},[n,N]),D=d.useRef(!1);d.useEffect(()=>{if(!A||r===null||D.current)return;const M=st(r,E.current,Bt);M.length!==0&&(D.current=!0,L(M))},[A,r,L]);const j=()=>{if(!A||r===null||v.current.size>0)return;const M=new Set([...b,...v.current]);L(st(r,M,Bt))};if(w)return{state:"error",error:w,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:j};if(i===null||u===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:j};if(A){if(r===null)return{state:"loading",apps:[],fns:i,wfs:u,moreApps:!1,loadMoreApps:j};if(r.length>0&&b.size===0)return{state:"loading",apps:[],fns:i,wfs:u,moreApps:!1,loadMoreApps:j};const M=rr(r,f).filter(X=>(s==null?void 0:s(X))??!0),W=y.size===0&&st(r,new Set([...b,...y]),1).length>0;return{state:M.length===0&&i.length===0&&u.length===0&&!W?"empty":"ready",apps:M,fns:i,wfs:u,moreApps:W,loadMoreApps:j}}if(a===null)return{state:"loading",apps:[],fns:i,wfs:u,moreApps:!1,loadMoreApps:j};const C=new Set(r??[]),_=a.filter(M=>!me(M.id)&&((s==null?void 0:s(M))??!0)&&(C.has(M.id)||M.zeroCredential===!0));return{state:_.length===0&&i.length===0&&u.length===0?"empty":"ready",apps:_,fns:i,wfs:u,moreApps:!1,loadMoreApps:j}}function De(e){return(s,n)=>e(s).localeCompare(e(n),void 0,{sensitivity:"base"})}function We(e){const s=e.displayName;return s!=null&&s.trim()?s:"name"in e?e.name:e.id}function ht({family:e,item:s,onSelect:n}){const r=We(s);return t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-stepbuilder-item--callable","data-kind":e,onClick:()=>n({id:s.id,label:r}),children:[t.jsx(Ye,{icon:Hr[e],size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:r}),t.jsx("code",{className:"w6w-muted w6w-small",children:s.id})]})]})}function na({data:e,onSelectApp:s,onSelectCallable:n,theme:r}){const o=f=>t.jsx("div",{className:"w6w-apppicker-host",children:f});if(e.state==="error")return o(t.jsx("div",{className:"w6w-result w6w-error",children:e.error}));if(e.state==="loading")return o(t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}));const a=[...e.apps].sort(De(f=>f.displayName)),l=[...e.fns].sort(De(We)),i=[...e.wfs].sort(De(We)),c=(f,p)=>p.length===0?null:t.jsxs("section",{className:"w6w-readytouse-col",children:[t.jsx("h4",{className:"w6w-readytouse-heading",children:f}),t.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:p})]},f),u=a.map(f=>t.jsxs("button",{type:"button",className:"w6w-stepbuilder-item","data-kind":"app",onClick:()=>s(f),children:[t.jsx(pe,{src:f.iconSvg,srcDark:f.iconSvgDark,brandColor:f.brandColor,name:f.displayName,theme:r,size:24}),t.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[t.jsx("strong",{children:f.displayName}),t.jsx("code",{className:"w6w-muted w6w-small",children:f.id})]})]},f.id));e.moreApps&&u.push(t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:e.loadMoreApps,children:"Load more"},"__load_more_apps"));const m=c("Connected apps",u),w=[c("Functions",l.map(f=>t.jsx(ht,{family:"function",item:f,onSelect:p=>n({family:"function",...p})},f.id))),c("Workflows",i.map(f=>t.jsx(ht,{family:"workflow",item:f,onSelect:p=>n({family:"workflow",...p})},f.id)))].filter(Boolean),h=(m?1:0)+(w.length>0?1:0);return o(t.jsxs("div",{className:"w6w-readytouse","data-cols":h,children:[m,w.length>0&&t.jsx("div",{className:"w6w-readytouse-stack",children:w})]}))}function ra({appId:e,app:s,onAdd:n,onClose:r,onDraftChange:o,onChangeApp:a,theme:l,workflowId:i,stepId:c,upstreamSteps:u=[],initialAction:m,initialConnection:w,initialWith:h}){const f=te(),[p,b]=d.useState(null),[S,y]=d.useState(null),[x,v]=d.useState(null),[N,E]=d.useState(null),[k,P]=d.useState(w??""),[A,I]=d.useState(m??""),[L,D]=d.useState(h??{}),[j,C]=d.useState(!1),[_,U]=d.useState(!1),[M,W]=d.useState(m&&h?"configure":"setup"),[H,X]=d.useState("props"),[ee,G]=d.useState("{}"),[J,ae]=d.useState("{}"),[K,g]=d.useState({});d.useEffect(()=>{let R=!1;return E(null),Promise.all([f.getAppAuth(e),f.listConnectionsForApp(e),f.getAppActions(e)]).then(([z,Se,Vs])=>{if(R)return;b(z),y(Se),v(Vs),!(z??[]).some(Ws=>Ws.autoSatisfied===!0)&&Se.length>0&&P(Se[0].id)}).catch(z=>!R&&E(z.message)),()=>{R=!0}},[f,e]);const O=async()=>{const R=await f.listConnectionsForApp(e);y(R),R.length>0&&P(z=>z||R[0].id)},F=(p??[]).filter(R=>R.available!==!1),V=F.some(R=>R.autoSatisfied===!0&&(R.type==="tenantAuth"||R.type==="jit")),q=F.length>0&&!V,B=(S??[]).length>0,$=(x??[]).find(R=>R.key===A),Q=[...x??[]].sort((R,z)=>(R.title??R.key).localeCompare(z.title??z.key,void 0,{sensitivity:"base"})),je=qs(s),[Ze,ve]=d.useState(!1);d.useEffect(()=>{if(!je||!i||!c)return;let R=!1;return f.listStepTests(i,c).then(z=>{!R&&z.some(Se=>Se.lastRunStatus==="succeeded")&&ve(!0)}).catch(()=>{}),()=>{R=!0}},[f,je,i,c]);const Me=It(i??"",u,!!i),Oe=Rt(Me),se=!!A&&(!q||B&&!!k),le=se&&!!$&&ge($.params??[],L),et=se,T=(S??[]).find(R=>R.id===k),Y=_||!k;function Z(){return{uses:{app:e,action:($==null?void 0:$.key)??A,...(q||V)&&k?{connection:k}:{}},with:L,...K}}function Ne(){$&&n(Z())}const[re,ke]=d.useState(null);d.useEffect(()=>{if(!o||re!==null||!se)return;const R=n(Z());R&&ke(R)},[o,re,se]),d.useEffect(()=>{!o||re===null||o(re,Z())},[re,L,K,k]);const Ce=R=>{R==="code"?G(Et(Z())):R==="params-code"&&ae(Tt(Z())),X(R)};return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsxs("div",{className:"w6w-tabsbar",children:[t.jsxs("div",{className:"w6w-subtabs",children:[t.jsx("button",{type:"button",className:`w6w-subtab${M==="setup"?" active":""}`,onClick:()=>W("setup"),children:"Setup"}),t.jsx("button",{type:"button",disabled:!se,title:se?void 0:"Complete Setup first",className:`w6w-subtab${M==="configure"?" active":""}`,onClick:()=>se&&W("configure"),children:"Configure"}),t.jsx("button",{type:"button",disabled:!le,title:le?void 0:"Fill the required fields first",className:`w6w-subtab${M==="test"?" active":""}`,onClick:()=>le&&W("test"),children:"Test"})]}),t.jsx(Xe,{view:H,onChange:Ce,disabled:M!=="configure"})]}),t.jsxs("div",{className:"w6w-stepconfig-body",children:[M==="setup"&&t.jsxs("div",{className:"w6w-stack",children:[N&&t.jsx("div",{className:"w6w-result w6w-error",children:N}),p===null&&!N&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-conn-label",children:[s&&t.jsx(pe,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,theme:l,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:(s==null?void 0:s.displayName)??e}),a&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:a,children:"Change"})]})]}),p!==null&&V&&t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>C(!0),children:"Create connection"})]}),t.jsx("span",{className:"w6w-hint",children:'A scheduled or queued run of this workflow still needs a connection configured on this step — use "Create connection" if this step will run on a schedule.'})]}),p!==null&&q&&(B?Y?t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("select",{value:k,onChange:R=>{P(R.target.value),U(!1)},style:{flex:1},children:(S??[]).map(R=>t.jsxs("option",{value:R.id,children:[R.displayName||R.id," ",R.state?`(${R.state})`:""]},R.id))}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>C(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsxs("span",{className:"w6w-conn-label-name",children:[(T==null?void 0:T.displayName)||(T==null?void 0:T.id)||k,T!=null&&T.state?` (${T.state})`:""]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>U(!0),children:"Change"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>C(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[t.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>C(!0),children:"Create connection"})]})),x!==null&&(x.length===0?t.jsx("p",{className:"w6w-muted w6w-small",children:"This app exposes no actions."}):t.jsxs("label",{className:"w6w-field",children:[t.jsxs("span",{children:["Action",A?"":" *"]}),t.jsx(Os,{value:A,placeholder:"— pick an action —",onChange:R=>{I(R),D({}),ve(!1)},options:Q.map(R=>({value:R.key,label:`${R.title??R.key} (${R.key})`}))}),($==null?void 0:$.description)&&t.jsx("span",{className:"w6w-hint",children:$.description})]}))]}),M==="configure"&&($?H==="props"?t.jsx(de,{params:$.params??[],values:L,onChange:D}):H==="code"?t.jsx(ce,{value:ee,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Step JSON",copyable:!0}):H==="params-code"?t.jsx(ce,{value:J,onChange:ae,minHeight:"240px",height:"100%","aria-label":"Parameters JSON",copyable:!0,onValidChange:R=>R&&typeof R=="object"&&!Array.isArray(R)&&D(R)}):t.jsx(Ct,{config:K,onChange:g}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."})),M==="test"&&($?t.jsx(Pt,{app:e,action:$.key,connectionId:(q||V)&&k?k:void 0,values:L,canRun:se&&ge($.params??[],L),state:Oe,onResult:ve}):t.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),M==="test"&&t.jsx("div",{className:"w6w-stepconfig-testnote",children:je&&!Ze&&t.jsx("span",{className:"w6w-muted w6w-small",children:"Not yet tested — a passing test is required before this step can be published."})}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:r,children:"Cancel"}),M==="test"?t.jsx("button",{type:"button",className:"w6w-btn",disabled:re===null&&!et,onClick:re!==null?r:Ne,children:re!==null?"Done":"Add step"}):t.jsx("button",{type:"button",className:"w6w-btn",disabled:M==="setup"?!se:!le,onClick:()=>W(M==="setup"?"configure":"test"),children:"Next →"})]}),j&&t.jsx(kt,{theme:l,initialAppId:e,onClose:()=>C(!1),onCreated:async({connectionId:R})=>{C(!1),P(R),U(!1),await O()}})]})}function aa({appId:e,app:s,onClose:n,onChangeApp:r,theme:o,initialConnection:a,onConnected:l}){const i=te(),[c,u]=d.useState(null),[m,w]=d.useState(null),[h,f]=d.useState(null),[p,b]=d.useState(a??""),[S,y]=d.useState(!1),[x,v]=d.useState(!1);d.useEffect(()=>{let j=!1;return f(null),Promise.all([i.getAppAuth(e),i.listConnectionsForApp(e)]).then(([C,_])=>{if(j)return;u(C),w(_),!(C??[]).some(M=>M.autoSatisfied===!0)&&_.length>0&&b(_[0].id)}).catch(C=>!j&&f(C.message)),()=>{j=!0}},[i,e]);const N=async()=>{const j=await i.listConnectionsForApp(e);w(j),j.length>0&&b(C=>C||j[0].id)},E=(c??[]).filter(j=>j.available!==!1),k=E.some(j=>j.autoSatisfied===!0&&(j.type==="tenantAuth"||j.type==="jit")),P=E.length>0&&!k,A=(m??[]).length>0,I=!P||A&&!!p,L=(m??[]).find(j=>j.id===p),D=x||!p;return t.jsxs("div",{className:"w6w-stepconfig",children:[t.jsx("div",{className:"w6w-stepconfig-body",children:t.jsxs("div",{className:"w6w-stack",children:[h&&t.jsx("div",{className:"w6w-result w6w-error",children:h}),c===null&&!h&&t.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"App"}),t.jsxs("div",{className:"w6w-conn-label",children:[s&&t.jsx(pe,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,theme:o,size:20}),t.jsx("span",{className:"w6w-conn-label-name",children:(s==null?void 0:s.displayName)??e}),r&&t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:r,children:"Change"})]})]}),c!==null&&k&&t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"Create connection"})]}),t.jsx("span",{className:"w6w-hint",children:'A scheduled or queued run of this workflow still needs a connection configured on this step — use "Create connection" if this step will run on a schedule.'})]}),c!==null&&P&&(A?D?t.jsxs("label",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("select",{value:p,onChange:j=>{b(j.target.value),v(!1)},style:{flex:1},children:(m??[]).map(j=>t.jsxs("option",{value:j.id,children:[j.displayName||j.id," ",j.state?`(${j.state})`:""]},j.id))}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:"Connection"}),t.jsxs("div",{className:"w6w-conn-label",children:[t.jsxs("span",{className:"w6w-conn-label-name",children:[(L==null?void 0:L.displayName)||(L==null?void 0:L.id)||p,L!=null&&L.state?` (${L.state})`:""]}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>v(!0),children:"Change"}),t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"+ New"})]})]}):t.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[t.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),t.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>y(!0),children:"Create connection"})]}))]})}),t.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:n,children:"Cancel"}),t.jsx("button",{type:"button",className:"w6w-btn",disabled:!I||!s,onClick:()=>s&&l(p,s),children:"Next →"})]}),S&&t.jsx(kt,{theme:o,initialAppId:e,onClose:()=>y(!1),onCreated:async({connectionId:j})=>{y(!1),b(j),v(!1),await N()}})]})}const oa=["props","code"];function la(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Hs({params:e,values:s,onChange:n,onValidityChange:r,readOnly:o,initialView:a="props"}){const l=e.length>0,[i,c]=d.useState(a),u=!l||i==="code",[m,w]=d.useState(()=>zt(s)),[h,f]=d.useState(!0),p=d.useRef(!0),b=x=>{x!==p.current&&(p.current=x,f(x),r==null||r(x))},S=x=>{x==="code"&&w(zt(s)),b(!0),c(x)},y=l?"Values (JSON)":"Payload";return t.jsxs("div",{className:"w6w-stack",children:[l&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx(Xe,{view:i,views:[...oa],onChange:x=>S(x)})}),u?t.jsxs("div",{className:"w6w-field",children:[t.jsx("span",{children:y}),t.jsx(ce,{value:m,onChange:w,readOnly:o,minHeight:"140px","aria-label":`${y} JSON`,onValidChange:x=>{const v=la(x);b(v),v&&n(x)},onValidityChange:x=>{x.valid||b(!1)}}),!h&&t.jsx("span",{className:"w6w-hint",children:"This draft isn’t a JSON object yet — the collected values are unchanged until it is."})]}):t.jsx(de,{params:e,values:s,onChange:n,readOnly:o})]})}function zt(e){return JSON.stringify(e??{},null,2)}function ia({title:e,message:s,onConfirm:n,onClose:r,confirmLabel:o="Confirm",cancelLabel:a="Cancel",destructive:l=!0,children:i}){return t.jsxs(ne,{title:e,onClose:r,children:[t.jsxs("div",{className:"w6w-modal-body",children:[t.jsx("p",{className:"w6w-muted w6w-small",children:s}),i]}),t.jsxs("div",{className:"w6w-modal-actions",children:[t.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:r,children:a}),t.jsx("button",{type:"button",className:l?"w6w-btn w6w-btn-danger":"w6w-btn",onClick:n,children:o})]})]})}exports.AddConnectionModal=kt;exports.AppIcon=pe;exports.AppPicker=xe;exports.AuthFieldsForm=ks;exports.CALL_APP=Ke;exports.CONTROL_APP=ie;exports.CodeEditor=Xt;exports.Combobox=Os;exports.ConfigViewToggle=Xe;exports.ConfirmModal=ia;exports.DATA_APP=ze;exports.ERROR_SOURCE_HANDLE=jt;exports.ExpressionInput=gt;exports.ExpressionOptionsProvider=on;exports.INTERNAL_NODES=ye;exports.IconButton=ft;exports.InternalIcon=Ye;exports.JsonEditor=ce;exports.Modal=ne;exports.NodeConfigForm=Ct;exports.ParamsForm=de;exports.PropertyEntryForm=Hs;exports.RetryPolicyFields=As;exports.SCHEDULER_APP=Nt;exports.SCRIPT_APP=bs;exports.StepBuilderModal=Wr;exports.StepTestRun=Pt;exports.TRIGGER_APP=Ge;exports.TriggerFillForm=Is;exports.W6WUIProvider=ar;exports.WEBHOOK_APP=vt;exports.WaitEditor=hs;exports.WorkflowProjectProvider=or;exports.asFieldDefs=St;exports.buildResolveScope=ls;exports.coerceDefault=Ts;exports.deepEqual=ut;exports.edgeVisuals=fs;exports.excludeSelfStep=an;exports.fieldWidget=Es;exports.fieldsToParams=At;exports.filterOptions=Ms;exports.findChainRoot=Er;exports.findChainTail=Tr;exports.flattenParams=fe;exports.flowEdgeId=He;exports.flowToWorkflow=kr;exports.idClashMessage=mr;exports.internalNodeDefaults=gs;exports.internalNodeIcon=Zn;exports.internalNodeLabel=Qn;exports.internalNodeParams=xs;exports.isControlApp=Le;exports.isExprValue=Be;exports.isInternalApp=me;exports.isParamVisible=Pe;exports.isSecretValue=mt;exports.isTestRequired=qs;exports.isTriggerApp=qe;exports.laneForSourceHandle=Rn;exports.nodePortsForStep=Ln;exports.paramsToJson=Tt;exports.relayoutNodes=Nr;exports.requiredParamsFilled=ge;exports.resolveParamJson=yt;exports.resolveParamValue=us;exports.resolveVarsJson=wn;exports.seedValues=Rs;exports.shouldUseCombobox=Ps;exports.slugifyLabel=Ar;exports.sourceHandleForLane=ms;exports.startOAuthPopup=Cs;exports.startStateFromSeeds=Rt;exports.stepBuilderUpstreamSteps=Lr;exports.stepIdError=fr;exports.stepMetaSampleValues=_r;exports.stepToJson=Et;exports.storedViewport=Ls;exports.suggestStepId=Rr;exports.upstreamStateSources=$r;exports.useEffectiveTheme=Ue;exports.useEnterSubmit=Ss;exports.useExpressionOptions=Je;exports.useSeedSources=It;exports.useW6WApi=te;exports.valueAtPath=Or;exports.varLabel=he;exports.withViewport=Cr;exports.workflowToFlow=vr;
11
- //# sourceMappingURL=ConfirmModal-DJPYXE9t.cjs.map