@w6w/ui 0.2.67 → 0.2.68

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 (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/{CodeBlock-C1IC5_6O.cjs → CodeBlock-85y9qvE3.cjs} +4 -4
  3. package/dist/{CodeBlock-C1IC5_6O.cjs.map → CodeBlock-85y9qvE3.cjs.map} +1 -1
  4. package/dist/{CodeBlock-CsdRXzb0.js → CodeBlock-a5QVaIGk.js} +158 -131
  5. package/dist/{CodeBlock-CsdRXzb0.js.map → CodeBlock-a5QVaIGk.js.map} +1 -1
  6. package/dist/NodeConfigForm.d.ts +8 -2
  7. package/dist/StepBuilderModal.d.ts +2 -0
  8. package/dist/code.cjs +1 -1
  9. package/dist/code.mjs +1 -1
  10. package/dist/components/ExecutionLogDock.d.ts +44 -0
  11. package/dist/components/ExecutionLogPanel.d.ts +66 -0
  12. package/dist/components/ExecutionLogView.d.ts +30 -0
  13. package/dist/components/icons.d.ts +1 -1
  14. package/dist/connection-app-meta-DID4zDg-.cjs +29 -0
  15. package/dist/connection-app-meta-DID4zDg-.cjs.map +1 -0
  16. package/dist/{connection-app-meta-DEC0n4PA.js → connection-app-meta-mmyKM3H9.js} +4606 -3725
  17. package/dist/connection-app-meta-mmyKM3H9.js.map +1 -0
  18. package/dist/flow-types.d.ts +25 -1
  19. package/dist/flow.cjs +7 -5
  20. package/dist/flow.cjs.map +1 -1
  21. package/dist/flow.mjs +1119 -980
  22. package/dist/flow.mjs.map +1 -1
  23. package/dist/form-schema.d.ts +34 -0
  24. package/dist/index.cjs +3 -2
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.mjs +1683 -1313
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/provider.d.ts +2 -0
  30. package/package.json +2 -2
  31. package/src/styles/_execution-log-view.scss +322 -0
  32. package/src/styles/_form-builder.scss +13 -0
  33. package/src/styles.css +335 -0
  34. package/src/styles.scss +1 -0
  35. package/dist/connection-app-meta-DEC0n4PA.js.map +0 -1
  36. package/dist/connection-app-meta-Dk6F3KEH.cjs +0 -29
  37. package/dist/connection-app-meta-Dk6F3KEH.cjs.map +0 -1
@@ -0,0 +1,29 @@
1
+ "use strict";const n=require("react/jsx-runtime"),b=require("react"),ie=require("@w6w/expr"),In=require("@codemirror/lang-javascript"),zr=require("@codemirror/lang-python"),qs=require("@codemirror/view"),Jr=require("@uiw/react-codemirror"),le=require("./CodeBlock-85y9qvE3.cjs"),Kr=require("@codemirror/lang-json"),Wo=require("@codemirror/lint"),Rn=require("react-dom"),bs=require("@xyflow/react"),pl=require("react-markdown");var rs=typeof document<"u"?document.currentScript:null;const fl={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function hl(e){if(typeof e!="string"||e.trim()==="")return"";const t=fl[e];return t||e.split(/[-_\s]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function ml(e){const t=new Map;for(const s of e)for(const o of s.categories??[])t.set(o,(t.get(o)??0)+1);return[...t.entries()].map(([s,o])=>({slug:s,label:hl(s),count:o})).sort((s,o)=>o.count-s.count||s.label.localeCompare(o.label,void 0,{sensitivity:"base"}))}function wl(e,t){if(t.length===0)return!0;const s=e.categories??[];return t.some(o=>s.includes(o))}const bl=["text","textarea","email","number","phone","url","password","date","time","datetime","select","radio","checkboxes","checkbox","rating","file","hidden","heading","paragraph","pageBreak"],yl=new Set(["heading","paragraph","pageBreak"]),Wn=new Set(["select","radio","checkboxes"]),gl=new Set(["text","textarea","email","phone","url","password"]);function Gr(e){return!yl.has(e)}const Yr=["equals","notEquals","contains","notContains","isEmpty","isNotEmpty","greaterThan","lessThan"],as=200,Xr=1e3,xl=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/,vl=new Set(["__proto__","constructor","prototype"]),jl="#4f46e5",kl=[{name:"--bg",light:"#f5f6fa",dark:"#0f1115",use:"page background"},{name:"--card",light:"#ffffff",dark:"#181b21",use:"the box around the form"},{name:"--text",light:"#16181d",dark:"#eceef2",use:"text"},{name:"--muted",light:"#5d6472",dark:"#9aa1ad",use:"descriptions and help text"},{name:"--border",light:"#d9dce3",dark:"#2c313a",use:"borders and empty stars"},{name:"--input",light:"#ffffff",dark:"#11141a",use:"input background"},{name:"--err",light:"#c0262d",dark:"#ff6b6b",use:"errors and the required *"},{name:"--errbg",light:"#fdecec",dark:"#3a1a1c",use:"error banner background"},{name:"--ok",light:"#15803d",dark:"#4ade80",use:"the completion tick"}],Nl=[{rule:".wrap { max-width: 680px; }",use:"the form's column"},{rule:".card { border-radius: 14px; padding: 32px; }",use:"the box around the form"},{rule:"h1 { font-size: 1.6rem; }",use:"the title"},{rule:".desc { }",use:"the description"},{rule:".field { }",use:"one question"},{rule:".q { }",use:"a question's label"},{rule:".help { }",use:"a question's help text"},{rule:".choice { }",use:"one radio or checkbox option"},{rule:".drop { }",use:"the file upload area"},{rule:".primary { }",use:"the Submit / Next button"},{rule:".secondary { }",use:"the Back button"},{rule:".foot { }",use:"the footer"}];function Sl(){const e=(s,o)=>s+" ".repeat(Math.max(1,o-s.length)),t=s=>kl.map(o=>` ${e(`/* ${o.name}: ${s?o.dark:o.light}; */`,28)}/* ${o.use} */`);return["/* Custom CSS for the form page. Uncomment a line to use it. */","","/* Colours */",":root {",` ${e(`/* --accent: ${jl}; */`,28)}/* buttons, focus rings, progress (or set Accent colour) */`,...t(!1),"}","","/* Dark colours: used when Theme is auto and the visitor's system is dark. */","/* (With Theme dark or light, set the colours in :root above.) */","@media (prefers-color-scheme: dark) {"," :root {",...t(!0).map(s=>` ${s}`)," }","}","","/* Page parts */",...Nl.map(s=>`${e(`/* ${s.rule} */`,52)}/* ${s.use} */`),""].join(`
2
+ `)}function Zr(){return{version:1,title:"Contact us",description:"We'll get back to you within one business day.",fields:[{id:"f_name",type:"text",name:"name",label:"Name",required:!0,width:"half"},{id:"f_email",type:"email",name:"email",label:"Email",required:!0,width:"half",placeholder:"you@example.com"},{id:"f_message",type:"textarea",name:"message",label:"Message",required:!0}],submitLabel:"Submit",completion:{type:"message",title:"Thank you!",message:"Your response has been recorded."},settings:{allowPrefill:!0,showProgress:!0,theme:"auto"}}}function Cl(e,t,s){const o={id:t,type:e};if(e==="pageBreak")return{...o,label:""};if(e==="heading")return{...o,label:"Section title"};if(e==="paragraph")return{...o,help:"Some helpful text."};const r=Qr[e],a={...o,label:r,name:Us(ea(r),s)};return Wn.has(e)&&(a.options=[{label:"Option 1"},{label:"Option 2"}]),e==="rating"&&(a.max=5),e==="checkbox"&&(a.label="I agree"),a}const Qr={text:"Short text",textarea:"Long text",email:"Email",number:"Number",phone:"Phone",url:"Website",password:"Password",date:"Date",time:"Time",datetime:"Date & time",select:"Dropdown",radio:"Single choice",checkboxes:"Multiple choice",checkbox:"Checkbox",rating:"Rating",file:"File upload",hidden:"Hidden value",heading:"Heading",paragraph:"Paragraph",pageBreak:"Page break"};function ea(e){const t=e.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,48);return t?/^[0-9]/.test(t)?`f_${t}`:t:"field"}function Us(e,t){if(!t.has(e))return e;let s=2;for(;t.has(`${e}_${s}`);)s++;return`${e}_${s}`}const Xe=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),he=e=>typeof e=="string"?e:void 0,Ho=e=>typeof e=="number"&&Number.isFinite(e)?e:void 0;function Al(e){var l;let t=e;if(typeof t=="string")try{t=JSON.parse(t)}catch{return null}if(!Xe(t)||!Array.isArray(t.fields))return null;const s=[],o=[],r=new Set,a=new Set;for(const[c,u]of t.fields.slice(0,as).entries()){if(!Xe(u)){s.push({message:`Field ${c+1} is not an object.`});continue}const d=he(u.type);if(!d||!bl.includes(d)){s.push({message:`Field ${c+1} has an unknown type "${String(u.type)}".`});continue}let f=he(u.id)||`f_${c+1}`;a.has(f)&&(f=Us(f,a)),a.add(f);const p=El(u,f,d);if(Gr(d)&&(!p.name||!xl.test(p.name)||vl.has(p.name)?s.push({fieldId:f,message:`"${p.label||d}" needs a name made of letters, digits and _ (starting with a letter).`}):r.has(p.name)&&s.push({fieldId:f,message:`Two fields are named "${p.name}".`}),p.name&&r.add(p.name),Wn.has(d)&&!((l=p.options)!=null&&l.length)&&!p.optionsFrom&&s.push({fieldId:f,message:`"${p.label||p.name}" has no options.`}),p.pattern!==void 0))try{new RegExp(p.pattern)}catch{s.push({fieldId:f,message:`"${p.label||p.name}" has an invalid pattern.`})}const m=p.showIf;if(m&&!o.some(h=>h.name===m.field)){const h=p.label||p.name||d;s.push({fieldId:f,message:`"${h}" depends on "${m.field}", which is not an earlier field.`})}o.push(p)}t.fields.length>as&&s.push({message:`A form holds at most ${as} fields.`});const i={version:1,title:he(t.title)??"",fields:o};if(i.title.trim()||s.push({message:"The form needs a title."}),he(t.description)&&(i.description=he(t.description)),he(t.submitLabel)&&(i.submitLabel=he(t.submitLabel)),Xe(t.completion)){const c=t.completion,u={type:c.type==="redirect"?"redirect":"message"};he(c.title)!==void 0&&(u.title=he(c.title)),he(c.message)!==void 0&&(u.message=he(c.message)),he(c.redirectUrl)!==void 0&&(u.redirectUrl=he(c.redirectUrl)),c.allowAnother===!0&&(u.allowAnother=!0),u.type==="redirect"&&!Ol(u.redirectUrl)&&s.push({message:"The redirect URL must start with http:// or https://."}),i.completion=u}if(Xe(t.settings)){const c=t.settings,u={};typeof c.allowPrefill=="boolean"&&(u.allowPrefill=c.allowPrefill),typeof c.showProgress=="boolean"&&(u.showProgress=c.showProgress),(c.theme==="light"||c.theme==="dark"||c.theme==="auto")&&(u.theme=c.theme),typeof c.accentColor=="string"&&/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(c.accentColor)&&(u.accentColor=c.accentColor),he(c.customCss)&&(u.customCss=he(c.customCss)),c.hideBranding===!0&&(u.hideBranding=!0),c.closed===!0&&(u.closed=!0),he(c.closedMessage)&&(u.closedMessage=he(c.closedMessage)),i.settings=u}return{form:i,problems:s}}function El(e,t,s){const o={id:t,type:s};for(const a of["name","label","help","placeholder","pattern","patternMessage"]){const i=he(e[a]);i!==void 0&&i!==""&&(o[a]=i)}for(const a of["minDate","maxDate","accept"]){const i=he(e[a]);i&&(o[a]=i)}e.required===!0&&(o.required=!0),e.multiple===!0&&(o.multiple=!0),e.allowOther===!0&&(o.allowOther=!0);for(const a of["minLength","maxLength","min","max","step","minSelected","maxSelected","rows","maxFileSizeMb","maxFiles"]){const i=Ho(e[a]);i!==void 0&&(o[a]=i)}const r=e.defaultValue;if((typeof r=="string"||typeof r=="boolean"||Ho(r)!==void 0||Array.isArray(r)&&r.every(a=>typeof a=="string"))&&(o.defaultValue=r),Array.isArray(e.options)&&(o.options=e.options.flatMap(a=>{if(typeof a=="string")return a?[{label:a}]:[];if(!Xe(a))return[];const i=he(a.label)??he(a.value);if(!i)return[];const l={label:i};return he(a.value)&&(l.value=he(a.value)),[l]})),Wn.has(s)){const a=Bo(e.optionsFrom);a&&(o.optionsFrom=a,Array.isArray(a.items)&&(o.options=zo(a.items,a)))}if(s==="text"){if(Array.isArray(e.suggestions)){const i=e.suggestions.filter(l=>typeof l=="string"&&l!=="");i.length&&(o.suggestions=i.slice(0,Xr))}const a=Bo(e.suggestionsFrom);a&&(o.suggestionsFrom=a,Array.isArray(a.items)&&(o.suggestions=[...new Set(zo(a.items,a).map(i=>i.label))]))}if(e.width==="half"&&(o.width="half"),Xe(e.showIf)&&he(e.showIf.field)){const a=Yr.includes(String(e.showIf.op))?e.showIf.op:"equals";o.showIf={field:String(e.showIf.field),op:a},e.showIf.value!==void 0&&e.showIf.value!==null&&(o.showIf.value=String(e.showIf.value))}return o}function Bo(e){var r,a;if(!Xe(e)||e.items===void 0||e.items===null||e.items==="")return;const t={items:e.items},s=(r=he(e.label))==null?void 0:r.trim(),o=(a=he(e.value))==null?void 0:a.trim();return s&&(t.label=s),o&&(t.value=o),t}function Tl(e,t){let s=e;for(const o of t.split(".")){if(!Xe(s)||!Object.hasOwn(s,o))return;s=s[o]}return s}function Vo(e){if(typeof e=="string")return e===""?void 0:e;if(typeof e=="number"&&Number.isFinite(e)||typeof e=="boolean")return String(e)}function zo(e,t={}){const s=[],o=new Set,r=(a,i)=>{for(const l of i){const c=Vo(Tl(a,l));if(c!==void 0)return c}};for(const a of e){if(s.length>=Xr)break;let i,l;if(Xe(a)){const c=r(a,t.value?[t.value]:["value","id"]);i=r(a,t.label?[t.label]:["label","name","title"])??c,l=c??i}else i=l=Vo(a);i===void 0||l===void 0||o.has(l)||(o.add(l),s.push(l===i?{label:i}:{label:i,value:l}))}return s}function Ol(e){return typeof e=="string"&&/^https?:\/\/\S+$/i.test(e.trim())}function fn(e,t){const s=e==="error"?{className:"w6w-edge-error",label:"on error"}:e==="each"?{className:"w6w-edge-each"}:{};if(!t)return s;const o=t==="taken"?"w6w-edge-taken":"w6w-edge-skipped";return{className:s.className?`${s.className} ${o}`:o,...s.label?{label:s.label}:{}}}const Ws="out-error",Hn="out-each",Ct="done",ta="each";function Hs(e){return e==="error"?Ws:e==="each"?Hn:void 0}function Il(e){return e===Ws?"error":e===Hn?"each":"success"}const Rl="@w6w/",qe="@w6w/control",na="@w6w/script",on="@w6w/data",Vt="@w6w/trigger",$l="@w6w/http",ze="@w6w/webhook",Bs="@w6w/scheduler",ut="@w6w/form",_l="@w6w/respond",hn="@w6w/call",Vs="@w6w/document",yn="@w6w/model",Pl="@w6w/template",gn="@w6w/regex",Ve="@w6w/store",Pt="@w6w/csv",Fl="@w6w/files",Ll="@w6w/datetime",Ml="@w6w/crypto",Dl="@w6w/list",zs="@w6w/stop",Qe="@w6w/router",zt="@w6w/race",sa="Continue once with the first arriving path’s output. Later arrivals are ignored for this run. Other paths keep running.";function Js(e){var t;return e.uses.app!==Qe||!Array.isArray((t=e.with)==null?void 0:t.routes)?[]:e.with.routes.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string")}const Jt=e=>`route:${e}`,ql=e=>e!=null&&e.startsWith("route:")?e.slice(6):void 0,Ul=3,Wl=16;function Hl(e){const t=e.find(r=>r.default),s=r=>({id:r.id,handleId:Jt(r.id),label:r.default?"Fallback":r.label||r.id}),o=e.filter(r=>r!==t);return{right:o.map((r,a)=>({...s(r),top:`${(a+.5)/o.length*100}%`})),...t?{bottom:s(t)}:{},...o.length>Ul?{minHeight:o.length*Wl}:{}}}const $n="false";function Ks(e){return e.uses.app===qe&&e.uses.action==="if"}function Bl(){return{right:[{id:"true",label:"True",top:"50%"}],bottom:{id:$n,handleId:Jt($n),label:"False"}}}function it(e){return e.startsWith(Rl)}function Dt(e){return e===qe||e===zt}function _n(e){return e===Vt||e===ze||e===Bs||e===ut}function Vl(e){return _n(e.app)||e.trigger===!0}const Jo={in:1,out:Number.POSITIVE_INFINITY};function Ko(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function zl(...e){let t,s;for(const o of e)t??(t=Ko(o==null?void 0:o.in)),s??(s=Ko(o==null?void 0:o.out));return{in:t??Jo.in,out:s??Jo.out}}function rn(e,t){var a;if(e.uses.app===Qe)return{in:1,out:Js(e).length};const{app:s,action:o}=e.uses,r=e.uses.trigger?{in:0,out:1}:void 0;return zl(e.ports,t==null?void 0:t(s,o),((a=At(s,o))==null?void 0:a.ports)??r)}const Jl='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',Go='<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" />',Kl='<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" />',Gl='<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" />',Yl='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',Xl='<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" />',Zl='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',Yo='<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" />',Ql='<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" />',ec='<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" />',tc='<rect x="4" y="3" width="16" height="18" rx="2" /><line x1="8" y1="8" x2="16" y2="8" /><rect x="8" y="11" width="8" height="3" rx="1" /><line x1="8" y1="17.5" x2="12" y2="17.5" />',nc='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',Xo='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',sc='<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" />',oc='<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" />',is='<rect x="4" y="4" width="16" height="16" rx="2" /><rect x="9" y="9" width="6" height="6" /><line x1="9" y1="1" x2="9" y2="4" /><line x1="15" y1="1" x2="15" y2="4" /><line x1="9" y1="20" x2="9" y2="23" /><line x1="15" y1="20" x2="15" y2="23" /><line x1="20" y1="9" x2="23" y2="9" /><line x1="20" y1="14" x2="23" y2="14" /><line x1="1" y1="9" x2="4" y2="9" /><line x1="1" y1="14" x2="4" y2="14" />',rc='<rect x="4" y="8" width="16" height="12" rx="2" /><line x1="12" y1="4" x2="12" y2="8" /><circle cx="12" cy="3" r="1" /><circle cx="9" cy="14" r="1.2" /><circle cx="15" cy="14" r="1.2" /><line x1="2" y1="13" x2="2" y2="16" /><line x1="22" y1="13" x2="22" y2="16" />',ac='<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" />',ot='<ellipse cx="12" cy="5" rx="9" ry="3" /><path d="M3 5v14c0 1.66 4.03 3 9 3s9-1.34 9-3V5" /><path d="M3 12c0 1.66 4.03 3 9 3s9-1.34 9-3" />',Ft='<rect x="3" y="4" width="18" height="16" rx="2" /><line x1="3" y1="10" x2="21" y2="10" /><line x1="3" y1="15" x2="21" y2="15" /><line x1="9" y1="4" x2="9" y2="20" />',ic='<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" /><polyline points="14 3 14 8 19 8" /><line x1="12" y1="11" x2="12" y2="17" /><polyline points="9.5 14.5 12 17 14.5 14.5" />',lc=[{app:gn,action:"match",label:"Extract",displayName:"Regex",groupActions:!0,group:"compute",icon:'<circle cx="6" cy="17" r="1"/><path d="M16 4v12M11 7l10 6M11 13l10-6"/>',params:[{key:"text",label:"Text",type:"string",config:{multiline:!0},default:"",hint:"Text to process. Empty text is allowed."},{key:"pattern",label:"Pattern",type:"string",default:"",hint:"Enter a regular expression without enclosing / delimiters. The extracted value is the first capture group, or the full match if there are no capture groups."},{key:"flags",label:"Flags",type:"string",default:"",hint:"Optional flags: d, g, i, m, s, u, v, y. Use g for all matches or replacements; u and v cannot be combined."}],output:[{key:"value",label:"Extracted value"},{key:"matched",label:"Matched"},{key:"matches",label:"Matches"}]},{app:gn,action:"test",label:"Test",displayName:"Regex",groupActions:!0,group:"compute",icon:'<circle cx="6" cy="17" r="1"/><path d="M16 4v12M11 7l10 6M11 13l10-6"/>',params:[{key:"text",label:"Text",type:"string",config:{multiline:!0},default:"",hint:"Text to process. Empty text is allowed."},{key:"pattern",label:"Pattern",type:"string",default:"",hint:"JavaScript regular expression without / delimiters. An empty pattern matches an empty string."},{key:"flags",label:"Flags",type:"string",default:"",hint:"Optional flags: d, g, i, m, s, u, v, y. Use g for all matches or replacements; u and v cannot be combined."}],output:[{key:"matched",label:"Matched"}]},{app:gn,action:"replace",label:"Replace",displayName:"Regex",groupActions:!0,group:"compute",icon:'<circle cx="6" cy="17" r="1"/><path d="M16 4v12M11 7l10 6M11 13l10-6"/>',params:[{key:"text",label:"Text",type:"string",config:{multiline:!0},default:"",hint:"Text to process. Empty text is allowed."},{key:"pattern",label:"Pattern",type:"string",default:"",hint:"JavaScript regular expression without / delimiters. An empty pattern matches an empty string."},{key:"flags",label:"Flags",type:"string",default:"",hint:"Optional flags: d, g, i, m, s, u, v, y. Use g for all matches or replacements; u and v cannot be combined."},{key:"replacement",label:"Replacement",type:"string",config:{multiline:!0},default:"",hint:"Replacement text; supports $1, $<name>, $&, $$, $` and $'. Leave empty to remove matches."}],output:[{key:"result",label:"Result"}]},{app:gn,action:"split",label:"Split",displayName:"Regex",groupActions:!0,group:"compute",icon:'<circle cx="6" cy="17" r="1"/><path d="M16 4v12M11 7l10 6M11 13l10-6"/>',params:[{key:"text",label:"Text",type:"string",config:{multiline:!0},default:"",hint:"Text to process. Empty text is allowed."},{key:"pattern",label:"Pattern",type:"string",default:"",hint:"JavaScript regular expression without / delimiters. An empty pattern matches an empty string."},{key:"flags",label:"Flags",type:"string",default:"",hint:"Optional flags: d, g, i, m, s, u, v, y. Use g for all matches or replacements; u and v cannot be combined."}],output:[{key:"parts",label:"Parts"}]}],cc=[{app:Pt,action:"from-json",label:"From JSON",displayName:"CSV",groupActions:!0,group:"compute",icon:Ft,params:[{key:"items",label:"Items",type:"json",required:!0,hint:"A list of objects, one per row."},{key:"csv",label:"Table",type:"json",hint:"Optional table to append to. Its columns stay first.",required:!1},{key:"columns",label:"Columns",type:"json",hint:"Optional column names, in order. Keys not listed are dropped."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:Pt,action:"create",label:"Create table",displayName:"CSV",groupActions:!0,group:"compute",icon:Ft,params:[{key:"columns",label:"Columns",type:"json",hint:"Column names, in order. Leave empty to use the keys of the rows."},{key:"rows",label:"Rows",type:"json",hint:"Optional list of row objects."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:Pt,action:"add-rows",label:"Add rows",displayName:"CSV",groupActions:!0,group:"compute",icon:Ft,params:[{key:"csv",label:"Table",type:"json",hint:"A table: { columns: string[], rows: object[] }. Usually the output of another CSV step.",required:!0},{key:"rows",label:"Rows",type:"json",required:!0,hint:"A list of row objects to append."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:Pt,action:"remove-rows",label:"Remove rows",displayName:"CSV",groupActions:!0,group:"compute",icon:Ft,params:[{key:"csv",label:"Table",type:"json",hint:"A table: { columns: string[], rows: object[] }. Usually the output of another CSV step.",required:!0},{key:"indexes",label:"Row positions",type:"json",hint:"Zero-based positions to remove. Use this or Match, not both."},{key:"where",label:"Match",type:"json",hint:'An object such as { "status": "done" }. A row is removed when every listed column equals its value exactly ("1" is not 1).'}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:Pt,action:"to-text",label:"To CSV text",displayName:"CSV",groupActions:!0,group:"compute",icon:Ft,params:[{key:"csv",label:"Table",type:"json",hint:"A table: { columns: string[], rows: object[] }. Usually the output of another CSV step.",required:!0},{key:"delimiter",label:"Delimiter",type:"string",default:",",hint:"One of , ; | or a tab."},{key:"header",label:"Header row",type:"boolean",default:!0,hint:"Write the column names as the first line."},{key:"bom",label:"Byte order mark",type:"boolean",default:!1,hint:"Start the text with U+FEFF, which some spreadsheet apps need for UTF-8."},{key:"escapeFormulas",label:"Escape formulas",type:"boolean",default:!1,hint:"Prefix text starting with = + - @ tab or CR with an apostrophe so spreadsheets do not run it. This breaks an exact round trip."},{key:"file",label:"Also create a file",type:"boolean",default:!1,hint:"Create a downloadable text/csv file as well as the text."},{key:"filename",label:"File name",type:"string",default:"data.csv",hint:"Used when a file is created. 1 to 255 characters, no slashes."}],output:[{key:"text",label:"Text"},{key:"file",label:"File"}]},{app:Pt,action:"parse",label:"Parse CSV",displayName:"CSV",groupActions:!0,group:"compute",icon:Ft,params:[{key:"text",label:"Text",type:"text",hint:"CSV text. Use this or File."},{key:"file",label:"File",type:"file",hint:"A CSV file from an earlier step. Use this or Text."},{key:"delimiter",label:"Delimiter",type:"string",default:",",hint:"One of , ; | or a tab."},{key:"header",label:"Header row",type:"boolean",default:!0,hint:"Off names the columns column_1, column_2 and so on."},{key:"inferTypes",label:"Detect types",type:"boolean",default:!0,hint:"Off keeps every cell as text."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]}],uc='<rect x="3" y="4" width="18" height="17" rx="2" /><line x1="3" y1="9" x2="21" y2="9" /><line x1="8" y1="2.5" x2="8" y2="6" /><line x1="16" y1="2.5" x2="16" y2="6" /><polyline points="12 12 12 15.5 14.5 17" />',dc='<rect x="5" y="11" width="14" height="10" rx="2" /><path d="M8 11V7a4 4 0 0 1 8 0v4" /><line x1="12" y1="15" x2="12" y2="17" />',pc='<line x1="9" y1="6" x2="20" y2="6" /><line x1="9" y1="12" x2="20" y2="12" /><line x1="9" y1="18" x2="20" y2="18" /><circle cx="4.5" cy="6" r="1" /><circle cx="4.5" cy="12" r="1" /><circle cx="4.5" cy="18" r="1" />',oa="An ISO 8601 date or date-time (with or without an offset), an RFC 2822 / HTTP date, or an epoch number: below 100,000,000,000 it is seconds, otherwise milliseconds. A date without an offset is read in the time zone.",Zo="yyyy yy (year), MMMM MMM MM M (month), dd d (day), EEEE EEE (weekday), HH H (hour 0-23), hh h (hour 1-12), mm m (minute), ss s (second), SSS (milliseconds), a (AM/PM), XXX (offset, Z for UTC), xxx (+02:00), xx (+0200), VV (zone name), Q (quarter), ww w (ISO week). Put literal letters in single quotes, e.g. yyyy-MM-dd'T'HH:mm.",xt=e=>({key:"timezone",label:"Time zone",type:"string",default:"",hint:`${e} An IANA name such as Europe/Berlin or America/New_York. Leave empty for UTC.`}),vt=(e="date",t="Date")=>({key:e,label:t,type:"string",default:"",hint:oa}),ra=[{value:"years",label:"Years"},{value:"quarters",label:"Quarters"},{value:"months",label:"Months"},{value:"weeks",label:"Weeks"},{value:"days",label:"Days"},{value:"hours",label:"Hours"},{value:"minutes",label:"Minutes"},{value:"seconds",label:"Seconds"},{value:"milliseconds",label:"Milliseconds"}],jt=[{key:"iso",label:"ISO 8601"},{key:"epochMs",label:"Epoch milliseconds"},{key:"timezone",label:"Time zone"},{key:"offset",label:"UTC offset"}],at=(e,t,s,o)=>({app:Ll,action:e,label:t,displayName:"Date & Time",groupActions:!0,group:"compute",icon:uc,params:s,output:o}),Qo=e=>at(e,e==="add"?"Add":"Subtract",[vt(),{key:"amount",label:"Amount",type:"number",default:1,hint:`How much to ${e}. Whole number for years to days; hours and smaller may have decimals.`},{key:"unit",label:"Unit",type:"select",default:"days",options:ra,hint:"Days and larger follow the calendar in the time zone (the clock time is kept across daylight saving); hours and smaller are exact elapsed time."},xt("Where calendar math happens.")],jt),fc=[at("now","Now",[xt("The zone to show the time in."),{key:"format",label:"Format",type:"string",default:"",hint:"Optional. A preset (iso, date, time, datetime, rfc2822, http, epoch, epoch_ms) or a pattern. When set, the output also has a formatted value."}],[...jt,{key:"formatted",label:"Formatted"}]),at("format","Format",[vt(),{key:"format",label:"Format",type:"string",default:"iso",hint:`A preset: iso, date (yyyy-MM-dd), time (HH:mm:ss), datetime, rfc2822, http (GMT), epoch (seconds), epoch_ms. Or a pattern using: ${Zo}`},xt("The zone the date is shown in."),{key:"locale",label:"Locale",type:"string",default:"",hint:"Language for month and weekday names, e.g. de-DE. Leave empty for en-US."}],[...jt,{key:"formatted",label:"Formatted"}]),at("parse","Parse",[{key:"text",label:"Text",type:"string",default:"",hint:"The text to read. With no format it is detected: ISO 8601, epoch seconds or milliseconds, or an RFC 2822 / HTTP date."},{key:"format",label:"Format",type:"string",default:"",hint:`Optional pattern the text follows, using: ${Zo} Missing parts default to 1970-01-01 00:00:00. Q, w and ww are not available for parsing.`},xt("The zone for text that carries no offset."),{key:"locale",label:"Locale",type:"string",default:"",hint:"Language of month and weekday names in the text. Leave empty for en-US."}],jt),Qo("add"),Qo("subtract"),at("difference","Difference",[vt("start","Start"),vt("end","End"),{key:"unit",label:"Unit",type:"select",default:"days",options:ra,hint:"Years, quarters and months are calendar-aware; weeks and smaller are elapsed time. Only complete units count."},xt("Where calendar math happens.")],[{key:"value",label:"Difference"},{key:"unit",label:"Unit"},{key:"start",label:"Start (ISO 8601)"},{key:"end",label:"End (ISO 8601)"},{key:"timezone",label:"Time zone"}]),at("extract","Extract part",[vt(),{key:"part",label:"Part",type:"select",default:"year",options:[{value:"year",label:"Year"},{value:"quarter",label:"Quarter"},{value:"month",label:"Month"},{value:"week",label:"Week (ISO)"},{value:"day",label:"Day of month"},{value:"dayOfWeek",label:"Day of week (1 = Monday)"},{value:"dayOfYear",label:"Day of year"},{value:"hour",label:"Hour"},{value:"minute",label:"Minute"},{value:"second",label:"Second"},{value:"millisecond",label:"Millisecond"}],hint:"Which part to read, in the time zone."},xt("The zone the part is read in.")],[{key:"value",label:"Value"},{key:"part",label:"Part"},...jt]),at("round","Round",[vt(),{key:"unit",label:"Unit",type:"select",default:"day",options:[{value:"year",label:"Year"},{value:"quarter",label:"Quarter"},{value:"month",label:"Month"},{value:"week",label:"Week (starts Monday)"},{value:"day",label:"Day"},{value:"hour",label:"Hour"},{value:"minute",label:"Minute"},{value:"second",label:"Second"}],hint:"The boundary to round to, in the time zone."},{key:"direction",label:"Direction",type:"select",default:"down",options:[{value:"down",label:"Down (start of the unit)"},{value:"up",label:"Up (next boundary)"},{value:"nearest",label:"Nearest"}],hint:"Up leaves a date that is already on a boundary unchanged; nearest rounds halfway up."},xt("Where the boundaries are.")],[...jt,{key:"unit",label:"Unit"},{key:"direction",label:"Direction"}]),at("convert","Convert time zone",[{...vt(),hint:oa.replace("in the time zone","as UTC")},{key:"timezone",label:"Time zone",type:"string",default:"",hint:"The zone to show it in: an IANA name such as Asia/Tokyo, or UTC."}],jt)],ls=e=>({key:"text",label:"Text",type:"string",config:{multiline:!0},default:"",hint:e}),cs={key:"algorithm",label:"Algorithm",type:"select",default:"sha256",options:[{value:"sha256",label:"SHA-256"},{value:"sha1",label:"SHA-1"},{value:"sha384",label:"SHA-384"},{value:"sha512",label:"SHA-512"}],hint:"Hash function. SHA-256 is the usual choice; SHA-1 is only for vendors that still require it."},us=e=>({key:"encoding",label:"Encoding",type:"select",default:"hex",options:[{value:"hex",label:"Hex"},{value:"base64",label:"Base64"},{value:"base64url",label:"Base64 URL-safe"}],hint:e}),er=[{key:"key",label:"Key",type:"string",default:"",hint:"The shared secret. Use a vault secret, e.g. {{ secrets.webhook_signing_key }}. It is never returned in the output."},{key:"keyEncoding",label:"Key encoding",type:"select",default:"utf8",options:[{value:"utf8",label:"Plain text"},{value:"hex",label:"Hex"},{value:"base64",label:"Base64"}],hint:"How the key is written. Most vendors give a plain-text key; some give hex or Base64."}],Yt=(e,t,s,o)=>({app:Ml,action:e,label:t,displayName:"Crypto",groupActions:!0,group:"compute",icon:dc,params:s,output:o}),hc=[Yt("hash","Hash",[ls("Text to hash, up to 10 MB. Empty text is allowed."),cs,us("How the digest is written.")],[{key:"digest",label:"Digest"},{key:"algorithm",label:"Algorithm"},{key:"encoding",label:"Encoding"}]),Yt("hmac","HMAC",[ls("The message to sign, up to 10 MB."),...er,cs,us("How the signature is written.")],[{key:"digest",label:"Signature"},{key:"algorithm",label:"Algorithm"},{key:"encoding",label:"Encoding"}]),Yt("verify-hmac","Verify HMAC",[ls("The signed message, usually the raw request body."),...er,cs,us("How the expected signature is written."),{key:"signature",label:"Signature",type:"string",default:"",hint:"The signature to check, in the encoding above (e.g. from the request's signature header). The comparison is constant-time."}],[{key:"valid",label:"Valid"},{key:"algorithm",label:"Algorithm"},{key:"encoding",label:"Encoding"}]),Yt("uuid","UUID",[{key:"count",label:"Count",type:"number",default:1,hint:"How many UUIDs, from 1 to 1000."}],[{key:"uuid",label:"UUID"},{key:"uuids",label:"UUIDs"}]),Yt("random","Random",[{key:"length",label:"Length",type:"number",default:32,hint:"Number of random bytes (1 to 4096). For Alphanumeric it is the number of characters instead."},{key:"encoding",label:"Encoding",type:"select",default:"hex",options:[{value:"hex",label:"Hex"},{value:"base64",label:"Base64"},{value:"base64url",label:"Base64 URL-safe"},{value:"alphanumeric",label:"Letters and digits"}],hint:"How the random value is written."}],[{key:"value",label:"Value"},{key:"encoding",label:"Encoding"},{key:"length",label:"Length"}])],gt={key:"items",label:"Items",type:"json",required:!0,hint:"The list to work on. Bind the array itself, e.g. {{ steps.fetch.output.body.data }}, not the whole response."},Xt={key:"items",label:"Items"},mc="A dot path into each item, such as user.email or tags.0. Leave empty to use the item itself.",rt=(e,t,s,o)=>({app:Dl,action:e,label:t,displayName:"List",groupActions:!0,group:"compute",icon:pc,params:s,output:o}),wc=[rt("filter","Filter",[gt,{key:"conditions",label:"Conditions",type:"json",required:!0,hint:'A list such as [{ "field": "status", "operator": "equals", "value": "paid" }]. Operators: equals, not_equals, gt, gte, lt, lte, contains, not_contains, starts_with, ends_with, matches (regular expression, up to 500 characters), in, not_in (value is a list), exists, not_exists, is_empty, is_not_empty, is_true, is_false. Numbers and ISO dates compare by value; other text compares as plain text.'},{key:"combine",label:"Combine conditions",type:"select",default:"and",options:[{value:"and",label:"All must match"},{value:"or",label:"Any can match"}]},{key:"caseSensitive",label:"Case sensitive",type:"boolean",default:!0,hint:"Turn off to ignore upper and lower case in text comparisons."}],[Xt,{key:"kept",label:"Kept"},{key:"removed",label:"Removed"}]),rt("sort","Sort",[gt,{key:"by",label:"Sort by",type:"json",required:!0,hint:'A list such as [{ "field": "createdAt", "direction": "desc" }]. Direction is asc (default) or desc. Later entries break ties.'}],[Xt]),rt("limit","Limit",[gt,{key:"count",label:"Count",type:"number",required:!0,hint:"How many to keep."},{key:"from",label:"Keep from",type:"select",default:"start",options:[{value:"start",label:"Start of the list"},{value:"end",label:"End of the list"}]},{key:"offset",label:"Skip",type:"number",default:0,hint:"How many items to skip from that end first."}],[Xt]),rt("pluck","Extract field",[gt,{key:"field",label:"Field",type:"string",hint:mc},{key:"unique",label:"Only distinct values",type:"boolean",default:!1},{key:"skipEmpty",label:"Skip empty values",type:"boolean",default:!1,hint:"Leave out missing, null and empty-text values."}],[{key:"values",label:"Values"}]),rt("unique","Remove duplicates",[gt,{key:"fields",label:"Compare fields",type:"json",hint:'A list of field paths such as ["email"]. Leave empty to compare the whole item exactly.'},{key:"keep",label:"Keep",type:"select",default:"first",options:[{value:"first",label:"First occurrence"},{value:"last",label:"Last occurrence"}]}],[Xt,{key:"removed",label:"Removed items"}]),rt("chunk","Split into batches",[gt,{key:"size",label:"Batch size",type:"number",required:!0,default:10}],[{key:"chunks",label:"Batches"},{key:"count",label:"Number of batches"}]),rt("join","Merge lists",[{key:"left",label:"First list",type:"json",required:!0,hint:"Bind the array itself, not the whole response."},{key:"right",label:"Second list",type:"json",required:!0,hint:"Bind the array itself, not the whole response."},{key:"mode",label:"Combine by",type:"select",default:"field",options:[{value:"field",label:"Matching field"},{value:"position",label:"Position"},{value:"all",label:"Every pair"}]},{key:"leftField",label:"Field in first list",type:"string",hint:"Needed when combining by matching field. Text and numbers match by value."},{key:"rightField",label:"Field in second list",type:"string",hint:"Leave empty to use the same field as the first list."},{key:"type",label:"Keep",type:"select",default:"inner",options:[{value:"inner",label:"Only matches"},{value:"left",label:"All of the first list"},{value:"right",label:"All of the second list"},{value:"full",label:"Everything from both"}]},{key:"multipleMatches",label:"When several match",type:"select",default:"all",options:[{value:"all",label:"Keep every match"},{value:"first",label:"Keep the first match"}]},{key:"clash",label:"When fields share a name",type:"select",default:"right",options:[{value:"right",label:"Second list wins"},{value:"left",label:"First list wins"},{value:"prefix",label:"Keep both (prefix second with right_)"}]}],[Xt]),rt("summarize","Summarize",[gt,{key:"groupBy",label:"Group by",type:"json",hint:'A list of field paths such as ["country"]. Leave empty for one overall result.'},{key:"aggregations",label:"Calculations",type:"json",required:!0,hint:'A list such as [{ "field": "amount", "op": "sum", "as": "total" }]. Ops: count, count_unique, sum, avg, min, max, first, last, append, concat (add "separator", default ", "). Without "as" the result is named like sum_amount.'}],[{key:"groups",label:"Groups"}])],dt=[...lc,...cc,...fc,...hc,...wc,{app:zt,action:"race",label:"Race",displayName:"Race",group:"control",icon:'<path d="M3 5h4l5 7h9M3 19h4l5-7" /><polyline points="17 8 21 12 17 16" />',ports:{in:"many",out:1},params:[]},{app:Qe,action:"route",label:"Router",displayName:"Router",group:"control",icon:Go,params:[{key:"routes",label:"Routes",type:"json",required:!0,default:[{id:"route_1",label:"Route 1",condition:!1},{id:"default",label:"Default",default:!0}]}],output:[{key:"route",label:"Selected route"}]},{app:zs,action:"stop",label:"Stop workflow",displayName:"Stop workflow",group:"control",icon:'<rect x="5" y="5" width="14" height="14" rx="2" />',params:[{key:"condition",label:"Condition",type:"json",default:!0,hint:"Stop when this condition is true. Omit it to always stop."},{key:"outcome",label:"Outcome",type:"select",default:"success",hint:"Success: end the run as succeeded. Error: fail this step with the message below, so error paths and the workflow error handler run.",options:[{value:"success",label:"Success"},{value:"error",label:"Error"}]},{key:"message",label:"Error message",type:"string",default:"Stopped by workflow",hint:"Shown as the step's error when the condition holds.",showIf:{field:"outcome",equals:"error"}}],output:[{key:"stopped",label:"Stopped"}]},{app:Vt,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:Jl,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 {{ nodes.<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",config:{valueTypeFrom:"type"}},{key:"required",label:"Required",type:"boolean",default:!1}]}}]},{app:ze,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:ec,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 = { "runId": "run_…", "status": "started" }. Write {{ runId }} to include the run id.',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:ut,action:"submission",label:"Form",displayName:"On form submission",group:"trigger",icon:tc,ports:{in:1,out:1},params:[{key:"form",label:"Form",type:"json",ui:"form-builder",whole:!0,default:Zr(),hint:"The form's title, fields, pages and completion screen."},{key:"responseMode",label:"After submit",type:"select",default:"onSubmit",hint:"When the submitter sees the completion screen.",options:[{value:"onSubmit",label:"Show completion screen immediately"},{value:"lastNode",label:"Wait for the workflow to finish"},{value:"responseNode",label:"Using a Respond to Webhook step"}]},{key:"auth",label:"Authentication",type:"select",default:"none",hint:"Who may open and submit the form.",options:[{value:"none",label:"Anyone with the link"},{value:"basic",label:"Basic auth (username and password)"}]},{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:"ignoreBots",label:"Ignore bots",type:"boolean",default:!0,advanced:!0,hint:"Silently drop submissions from crawlers and link previewers."}]},{app:Bs,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:Xl,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:qe,action:"if",label:"If",displayName:"If",group:"control",icon:Go,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:"A boolean, or an expression like {{ nodes.x.output.ok }}."}]},{app:qe,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:Kl,params:[{key:"items",type:"json",label:"Items",required:!0,whole:!0,hint:"An array to iterate, or an expression binding to one."},{key:"body",type:"json",label:"Body",hidden:!0,hint:"Step ids run per item. The canvas owns it; the engine requires it at run time."},{key:"parallelism",type:"number",label:"Parallelism",hidden:!0,hint:"Concurrent iterations. The engine clamps it to 1."}]},{app:qe,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:Gl,params:[]},{app:qe,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:Yl,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:na,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:Zl,params:[{key:"language",label:"Language",type:"select",default:"javascript",options:[{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"python",label:"Python"}],hint:"Execution language for this step's code. TypeScript types are erased before it runs, not checked. Python runs CPython-on-WASM with no network."},{key:"code",type:"code",label:"Script",required:!0,scriptReads:!0,default:`// Runs as a function body. Return the step's output.
3
+ return input;`,hint:"Return the step's output. Read data from state, vars and consts; {{ }} isn't substituted in code. digest(value) returns a stable SHA-256 hex (await it in JavaScript or TypeScript)."},{key:"custom_input",type:"section",section:"collapsible",title:"Custom input (advanced)",openWhenSet:!0,children:[{key:"input",type:"json",label:"Input",whole:!0,hint:"Replaces what the script reads as `input` (by default, the run state). Each bound value keeps its type; a secret goes here, since state never holds one."}]}]},{app:Pl,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:ac,output:[{key:"result"}],params:[{key:"template",label:"Template",type:"json",required:!0,whole:!0,hint:'Enter a JSON string ("Hello {{name}}") or object, or bind one with ƒx. String values render recursively; other values stay unchanged. {{name}} is HTML-escaped; use {{{name}}} for raw output.'},{key:"values",label:"Values",type:"vars",required:!0,whole:!0,default:{},hint:"Enter a JSON object, or use ƒx to bind data from workflow state or variables. Each key becomes a top-level placeholder root."}]},{app:on,action:"set",label:"Data",displayName:"Data set",group:"compute",icon:Yo,params:[{key:"vars",type:"vars",label:"Variables",required:!0,default:[],hint:"Set values for downstream steps using individual fields or a JSON object."}]},{app:on,action:"update",label:"Update object",displayName:"Update object",group:"compute",icon:Yo,params:[{key:"object",type:"json",label:"Starting object",required:!0,whole:!0,hint:"Use ƒx to choose an object from state or a previous step. The original stays unchanged."},{key:"vars",type:"vars",label:"Fields to set",required:!0,default:[],hint:"Set one or more fields. Use dot paths for nested fields, such as address.city."}]},{app:$l,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:Ql,output:[{key:"status",label:"Status code"},{key:"statusText",label:"Status text"},{key:"ok",label:"Succeeded (2xx)"},{key:"headers",label:"Response headers"},{key:"body",label:"Response body"},{key:"pages",label:"Pages fetched (pagination only)"},{key:"items",label:"All items (pagination only)"}],params:[{key:"method",type:"string",label:"Method",required:!0,default:"GET",options:[{value:"GET",label:"GET"},{value:"HEAD",label:"HEAD"},{value:"OPTIONS",label:"OPTIONS"},{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, merged into the URL."},{key:"body",type:"text",label:"Body",default:"",hint:"Request body: raw text, a JSON string, or a file from an earlier step. Ignored for GET/HEAD."},{key:"responseType",label:"Response type",type:"select",default:"text",hint:"Text (default): decode the response as text, parsing it as JSON when the response says it is. File: store the raw response bytes and return a file reference instead of decoding them — use this for a non-text response (e.g. a PDF or image); decoding it as text would corrupt the bytes.",options:[{value:"text",label:"Text"},{value:"file",label:"File"}]},{key:"pagination",label:"Pagination",type:"select",default:"off",hint:"Fetch several pages and collect their items. Off (default): one request. Every page reuses this request's method, headers and body, and never leaves this URL's host.",options:[{value:"off",label:"Off"},{value:"next_url",label:"Next URL in the body"},{value:"link_header",label:"Link header (rel=next)"},{value:"page",label:"Page number"},{value:"offset",label:"Offset"},{value:"cursor",label:"Cursor"}]},{key:"itemsPath",label:"Items path",type:"string",placeholder:"e.g. data.items",hint:"Path to the list of items in each page's body. Leave empty when the body itself is the list.",showIf:{field:"pagination",notIn:["off"]}},{key:"maxPages",label:"Max pages",type:"number",default:10,hint:"Stop after this many requests (at most 100).",showIf:{field:"pagination",notIn:["off"]}},{key:"nextUrlPath",label:"Next URL path",type:"string",placeholder:"e.g. links.next",hint:"Path to the next page's URL in the body. Pagination stops when it is empty.",showIf:{field:"pagination",equals:"next_url"}},{key:"pageParam",label:"Page parameter",type:"string",default:"page",hint:"Query parameter that carries the page number.",showIf:{field:"pagination",equals:"page"}},{key:"pageStart",label:"First page",type:"number",default:1,hint:"Page number of the first request. Each next page adds 1.",showIf:{field:"pagination",equals:"page"}},{key:"offsetParam",label:"Offset parameter",type:"string",default:"offset",hint:"Query parameter that carries the offset. It starts at 0 and grows by the number of items received.",showIf:{field:"pagination",equals:"offset"}},{key:"limitParam",label:"Limit parameter",type:"string",placeholder:"e.g. limit",hint:"Optional query parameter that carries the page size.",showIf:{field:"pagination",equals:"offset"}},{key:"limitValue",label:"Limit value",type:"number",hint:"Page size sent in the limit parameter.",showIf:{field:"pagination",equals:"offset"}},{key:"cursorParam",label:"Cursor parameter",type:"string",placeholder:"e.g. cursor",hint:"Query parameter that carries the cursor on the next request.",showIf:{field:"pagination",equals:"cursor"}},{key:"cursorPath",label:"Cursor path",type:"string",placeholder:"e.g. meta.next_cursor",hint:"Path to the next cursor in the body. Pagination stops when it is empty.",showIf:{field:"pagination",equals:"cursor"}}]},{app:_l,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:nc,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:qe,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:Xo,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:qe,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:Xo,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:hn,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:sc,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:"entry",label:"Trigger node",type:"string",hint:"The manual trigger node to start at in the called workflow."},{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:Vs,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:oc,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."}]},{app:yn,action:"complete",label:"Complete with model",displayName:"Model",group:"compute",icon:is,ports:{in:1,out:1},params:[{key:"route",label:"Route",type:"model-route",hint:"Name of a model route (Models → Routes). Use this, or the model + connection pair below — never both."},{key:"model",label:"Model",type:"string",advanced:!0,hint:"Catalog id of a model (`mdl_…`, Models → Catalog), called through `connection`. Ignored when `route` is set."},{key:"connection",label:"Connection",type:"string",advanced:!0,hint:"Id of a model-provider connection on this account. Required by `model`; ignored when `route` is set."},{key:"input",label:"Input",type:"json",required:!0,default:{},hint:`The request body handed to the provider — e.g. { "messages": [{ "role": "user", "content": "hi" }] }, or the provider's native payload.`},{key:"dialect",label:"Dialect",type:"select",advanced:!0,hint:"Rewrite the result into this wire dialect; bridge keeps the baseline unprojected. Leave unset to keep the provider's own.",placeholder:"Provider native",options:[{value:"bridge",label:"Bridge (unprojected)"},{value:"openai",label:"OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"ollama",label:"Ollama"}]},{key:"response",label:"Response",type:"select",advanced:!0,hint:"Output: the dialect-shaped result. Raw: the provider's own response. Leave unset to carry both.",placeholder:"Both",options:[{value:"output",label:"Output"},{value:"raw",label:"Raw"}]}]},{app:yn,action:"agent",label:"Run agent",displayName:"Agent",group:"compute",icon:rc,ports:{in:1,out:1},params:[{key:"agent",label:"Agent",type:"agent",required:!0,hint:"An agent from the Agents dashboard. Its tools run when it calls them."},{key:"message",label:"Message",type:"text",required:!0,hint:"What to tell the agent — text, or an expression such as an earlier step's output (an object is sent as JSON)."}]},{app:yn,action:"list-models",label:"List models",displayName:"Model",group:"compute",icon:is,ports:{in:1,out:1},params:[{key:"connection",label:"Connection",type:"string",required:!0,hint:"Connection id of the provider to list models for."}]},{app:yn,action:"allowance",label:"Model allowance",displayName:"Model",group:"compute",icon:is,ports:{in:1,out:1},params:[{key:"connection",label:"Connection",type:"string",required:!0,hint:"Connection id of the provider to read the allowance of."}]},{app:Ve,action:"get",label:"Get entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."},{key:"required",label:"Required",type:"boolean",default:!1,hint:"Fail the step when the key is missing instead of returning found: false."}],output:[{key:"found"},{key:"key"},{key:"value"},{key:"version"},{key:"expiresAt"}]},{app:Ve,action:"set",label:"Set entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."},{key:"value",label:"Value",type:"json",required:!0,hint:"The JSON value to store."},{key:"ifVersion",label:"If version",type:"number",hint:"Write only when the stored version equals this number."},{key:"ttlSeconds",label:"TTL (seconds)",type:"number",hint:"Expire the entry after this many seconds. Omit to keep it."}],output:[{key:"key"},{key:"value"},{key:"version"},{key:"expiresAt"}]},{app:Ve,action:"update",label:"Update entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key. The entry must already exist and hold an object."},{key:"fields",label:"Fields",type:"json",required:!0,hint:"Object of field → new value. Listed fields are replaced; the others are kept."},{key:"ifVersion",label:"If version",type:"number",hint:"Write only when the stored version equals this number. Omit to fail only if someone else changes the entry while this step runs."}]},{app:Ve,action:"delete",label:"Delete entry",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."}],output:[{key:"key"},{key:"deleted"}]},{app:Ve,action:"increment",label:"Increment counter",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"key",label:"Key",type:"data-store-key",required:!0,hint:"Entry key — search the store's entries, type a key, or bind an expression."},{key:"by",label:"By",type:"number",default:1,hint:"Amount to add; may be negative."}],output:[{key:"key"},{key:"value"},{key:"version"}]},{app:Ve,action:"list",label:"List entries",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"prefix",label:"Prefix",type:"string",hint:"Only entries whose key starts with this."},{key:"cursor",label:"Cursor",type:"string",hint:"The nextCursor of a previous page."},{key:"limit",label:"Limit",type:"number",default:50,hint:"Page size, at most 200."}],output:[{key:"items"},{key:"nextCursor"}]},{app:Ve,action:"query",label:"Query rows",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"where",label:"Where",type:"json",hint:"Column equality filter."},{key:"order",label:"Order",type:"string",hint:"Column to order by; prefix with - for descending."},{key:"limit",label:"Limit",type:"number",hint:"Maximum rows to return."}],output:[{key:"items"}]},{app:Ve,action:"insert",label:"Insert row",displayName:"Store",group:"compute",icon:ot,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"row",label:"Row",type:"json",required:!0,hint:"The row, keyed by column name."},{key:"ttlSeconds",label:"TTL (seconds)",type:"number",hint:"Expire the entry after this many seconds. Omit to keep it."}],output:[{key:"key"},{key:"value"},{key:"version"}]},{app:Fl,action:"save",label:"Save file",displayName:"Files",group:"compute",icon:ic,ports:{in:1,out:1},params:[{key:"path",label:"Path",type:"string",required:!0,hint:"Where to save the file in this account and project, such as reports/summary.csv. Saving to the same path again adds a version."},{key:"text",label:"Text",type:"text",hint:"Text to save. Use exactly one of Text, CSV or File."},{key:"csv",label:"CSV table",type:"json",hint:"A table from a CSV step, saved as CSV text. Use exactly one of Text, CSV or File."},{key:"file",label:"File",type:"file",hint:"A file from an earlier step. Use exactly one of Text, CSV or File."},{key:"contentType",label:"Content type",type:"string",hint:"Optional media type, such as text/plain. Defaults to one that fits the content."}],output:[{key:"fileId"},{key:"versionId"},{key:"path"},{key:"size"},{key:"sha256"},{key:"contentType"}]}];function At(e,t){return dt.find(s=>s.app===e&&s.action===t)}function bc(e,t){var s;return((s=At(e,t))==null?void 0:s.label)??t}function yc(e,t){var s;return((s=At(e,t))==null?void 0:s.icon)??""}function aa(e,t){var s;return((s=At(e,t))==null?void 0:s.params)??[]}function Pn(e,t){const s={};for(const o of aa(e,t))o.default!==void 0&&(s[o.key]=o.default);return s}function gc(e,t){return e.q===t.q&&(e.category??"")===(t.category??"")&&(e.ids??[]).join(",")===(t.ids??[]).join(",")}function ia(e,t=0){return{query:e,generation:t,status:"loading",apps:[],hasMore:!1}}function xc(e,t){const s=new Set(e.map(r=>r.id)),o=[];for(const r of t)s.has(r.id)||(s.add(r.id),o.push(r));return o.length===0?e:[...e,...o]}function vc(e,t){switch(t.type){case"query-changed":return t.generation===e.generation&&gc(t.query,e.query)?e:ia(t.query,t.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(t.generation!==e.generation)return e;const s=xc(e.apps,t.apps),o=t.nextCursor!==void 0&&t.nextCursor===t.requestedCursor,r=!!t.nextCursor&&!o;return{...e,status:"ready",apps:s,cursor:r?t.nextCursor:void 0,hasMore:r,total:typeof t.total=="number"?t.total:e.total,error:void 0}}case"page-failed":return t.generation!==e.generation?e:{...e,status:"error",error:t.error};default:return e}}function jc(e){return e.filter(t=>!it(t.id))}function ds(e,t,s){if(s<=0)return[];const o=[];for(const r of e)if(!t.has(r)&&(o.push(r),o.length>=s))break;return o}function kc(e,t){const s=[];for(const o of e){const r=t.get(o);r&&s.push(r)}return s}const la=b.createContext(void 0);function tr(e,t){var o;if(e)return e;if(t)return t;if(typeof document>"u")return"light";const s=document.documentElement.getAttribute("data-theme");return s==="dark"||s==="light"?s:(o=window.matchMedia)!=null&&o.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"}function Bn(e){const t=b.useContext(la),[s,o]=b.useState(()=>tr(e,t));return b.useEffect(()=>{if(e){o(e);return}if(t){o(t);return}if(typeof window>"u")return;const r=()=>o(tr(void 0,t)),a=window.matchMedia("(prefers-color-scheme: dark)");a.addEventListener("change",r);const i=new MutationObserver(r);return i.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),r(),()=>{a.removeEventListener("change",r),i.disconnect()}},[e,t]),s}function It({src:e,srcDark:t,brandColor:s,name:o,size:r=32,theme:a}){const l=Bn(a)==="dark"?t??e:e,[c,u]=b.useState(void 0);if(l&&l!==c)return n.jsx("img",{src:l,width:r,height:r,alt:"",onError:()=>u(l),style:{width:r,height:r,borderRadius:6,flexShrink:0,objectFit:"contain",padding:Math.max(1,Math.round(r*.06)),boxSizing:"border-box",background:"var(--w6w-icon-swatch, var(--w6w-panel-2))"}});const d=(o??"?").split(/\s+/).slice(0,2).map(f=>{var p;return((p=f[0])==null?void 0:p.toUpperCase())??""}).join("");return n.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r,height:r,borderRadius:6,background:s??"var(--w6w-accent)",color:"#fff",fontWeight:700,fontSize:Math.round(r*.42),flexShrink:0},children:d})}const Nc={w6w:"by W6W",verified:"Verified publisher"};function ca({publisher:e,className:t,testId:s}){if(!e)return null;const o=e.byW6W?"w6w":e.verified?"verified":"name";return n.jsxs("span",{className:["w6w-publisher-app-badge",`w6w-publisher-app-badge-${o}`,t].filter(Boolean).join(" "),"data-publisher-kind":o,"data-publisher-slug":e.slug,title:e.displayName,"data-testid":s,children:[o==="name"?null:n.jsx("span",{className:"w6w-publisher-app-badge-label",children:Nc[o]}),o==="w6w"?null:n.jsx("span",{className:"w6w-publisher-app-badge-name",children:e.displayName})]})}const Gs=b.createContext(null);function Sc({api:e,theme:t,children:s}){const o=n.jsx(Gs.Provider,{value:e,children:n.jsx(la.Provider,{value:t,children:s})});return t?n.jsx("div",{"data-theme":t,style:{display:"contents"},children:o}):o}function Ce(){const e=b.useContext(Gs);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}function Zt(){return b.useContext(Gs)??void 0}const ua=b.createContext(void 0),da=b.createContext(void 0);function Cc({project:e,workflowId:t,children:s}){return n.jsx(ua.Provider,{value:e,children:n.jsx(da.Provider,{value:t,children:s})})}function Ys(){return b.useContext(ua)}function Ac(){return b.useContext(da)}const ps=8,Ec=60,Tc=300;function nr(e){const t=e.modelProvider;return!t||typeof t!="object"?null:t}function Oc(e){if(!e)return null;if(e.supported)return{text:"Bridge supported",title:"Bridge supported"};const t=typeof e.reason=="string"?e.reason.trim():"";return{text:t===""?"unsupported":`unsupported — ${t}`,title:t===""?"Bridge not supported":t}}function lt({onSelectApp:e,theme:t,filter:s,searchPlaceholder:o,emptyMessage:r,search:a=!0,searchValue:i,onSearchChange:l,emptyAction:c,apps:u,categoryFilter:d=!1,providerFilter:f=!1,bridgeSupport:p,category:m,hasTriggers:h,publisher:w,publisherFilter:g=!1,onPublisherChange:y,ids:x,pageLimit:S=Ec,loadPage:A}){const O=Ce(),j=u!==void 0,N=x&&x.length>0?x.join(","):"",k=!j&&(A!==void 0||typeof O.listAppsPage=="function"),_=b.useRef(A);_.current=A;const[U,T]=b.useState(null),[F,E]=b.useState(null);b.useEffect(()=>{if(j||k)return;const q=O.listApps;if(typeof q!="function"){T([]);return}let ce=!1;return q().then(v=>!ce&&T(v)).catch(v=>!ce&&E(v.message)),()=>{ce=!0}},[O,j,k]);const[P,I]=b.useReducer(vc,ia({q:"",category:m,ids:x},0)),[G,W]=b.useState(""),$=i??G,R=q=>{i===void 0&&W(q),l==null||l(q)},[z,K]=b.useState($.trim()),ne=b.useRef(0),B=b.useRef(null),[Y,J]=b.useState(void 0),M=w!==void 0?w:Y,te=q=>{w===void 0&&J(q),y==null||y(q)},ee=b.useCallback((q,ce,v)=>{var fe;const L=_.current,H=O.listAppsPage;if(!L&&!H)return;(fe=B.current)==null||fe.abort();const oe=new AbortController;B.current=oe;let we;try{we=L?L({q:q.q||void 0,cursor:v,limit:S,...q.ids?{ids:q.ids}:{},signal:oe.signal}):H({q:q.q||void 0,category:q.category,...h?{hasTriggers:!0}:{},...M?{publisher:M}:{},...q.ids?{ids:q.ids}:{},cursor:v,limit:S,compact:!0,signal:oe.signal})}catch(Z){we=Promise.reject(Z)}we.then(Z=>{if(ne.current===ce){if(!Z||!Array.isArray(Z.apps)){I({type:"page-failed",generation:ce,error:"The server returned a malformed apps page."});return}I({type:"page-loaded",generation:ce,apps:Z.apps,nextCursor:Z.nextCursor,requestedCursor:v,total:typeof Z.total=="number"?Z.total:void 0})}}).catch(Z=>{if(ne.current!==ce||Z instanceof Error&&Z.name==="AbortError")return;const Ae=Z==null?void 0:Z.code;if(v!==void 0&&(Ae==="snapshot_expired"||Ae==="unknown_snapshot")){const yt=++ne.current;I({type:"query-changed",query:q,generation:yt}),ee(q,yt,void 0);return}I({type:"page-failed",generation:ce,error:Z.message})})},[O,S,h,M]);b.useEffect(()=>{if(!k)return;const q=setTimeout(()=>K($.trim()),Tc);return()=>clearTimeout(q)},[$,k]),b.useEffect(()=>{if(!k)return;const q=++ne.current,ce={q:z,category:m,...N?{ids:N.split(",")}:{}};return I({type:"query-changed",query:ce,generation:q}),ee(ce,q,void 0),()=>{var v;(v=B.current)==null||v.abort()}},[k,z,m,N,ee]),b.useEffect(()=>{if(k)return()=>{var q;return(q=B.current)==null?void 0:q.abort()}},[k]);const C=()=>{if(!k||P.status!=="ready"||!P.hasMore)return;const q=ne.current;I({type:"load-more"}),ee(P.query,q,P.cursor)},V=()=>{!k||P.status!=="error"||(I({type:"retry"}),ee(P.query,ne.current,P.cursor))},[Q,ae]=b.useState([]),[X,ke]=b.useState(!1),[be,ye]=b.useState(!1),ge=q=>n.jsx("div",{className:"w6w-apppicker-host",children:q});let xe,ue=null,D=!1,re=!1,me=null,Oe=!1;if(j?xe=u??null:k?(xe=P.apps,Oe=P.status==="loading",D=P.status==="loading-more",re=P.hasMore,P.status==="error"&&(P.apps.length===0?ue=P.error??"Failed to load apps.":me=P.error??"Failed to load apps.")):(xe=U,ue=F),!k&&ue)return ge(n.jsx("div",{className:"w6w-result w6w-error",children:ue}));if(!k&&xe===null)return ge(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));xe??(xe=[]);const Ie=jc(xe),_e=s?Ie.filter(s):Ie;if(!k&&_e.length===0)return ge(n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:r??"No apps registered yet. Register one from the Apps page first."}),c]}));const de=d?ml(_e):[],We=de.slice(0,ps),Gt=de.slice(ps).filter(q=>Q.includes(q.slug)),He=[...We,...Gt],Rt=de.length-He.length,Ke=X?de:He,mt=q=>ae(ce=>ce.includes(q)?ce.filter(v=>v!==q):[...ce,q]),$t=()=>ae([]),wt=_e.filter(q=>nr(q)!==null).length,Re=f&&wt>0,ve=Re&&be,Pe=ve?_e.filter(q=>nr(q)!==null):_e,_t=(()=>{const q=new Map;for(const ce of _e){const v=ce.publisher;v&&typeof v.slug=="string"&&v.slug!==""&&!q.has(v.slug)&&q.set(v.slug,v.displayName||v.slug)}return M&&!q.has(M)&&q.set(M,M),[...q].map(([ce,v])=>({slug:ce,label:v}))})(),Fe=g&&_t.length>0,Me=Fe&&M!==void 0,Ge=d&&Q.length>0?Pe.filter(q=>wl(q,Q)):Pe,pe=k?Ge:[...Ge].sort((q,ce)=>q.displayName.localeCompare(ce.displayName,void 0,{sensitivity:"base"})),st=k?"":$.trim().toLowerCase(),Be=$.trim().length>0,De=st?pe.filter(q=>q.displayName.toLowerCase().includes(st)||q.id.toLowerCase().includes(st)):pe,bt=s!==void 0&&_e.length!==Ie.length||ve&&Pe.length!==_e.length||d&&Q.length>0&&Ge.length!==Pe.length,se=(d&&Q.length>0||ve||Me)&&De.length===0,Ne=ve&&Q.length===0,$e=()=>{ae([]),ye(!1),M!==void 0&&te(void 0),R("")};return ge(n.jsxs("div",{className:"w6w-stepbuilder-apps",children:[a&&n.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:o??"Search apps…",value:$,onChange:q=>R(q.target.value),"aria-label":"Search apps"}),(Re||d&&de.length>0||Fe)&&n.jsxs("div",{className:"w6w-apppicker-cats",children:[Fe&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Publisher"}),_t.map(q=>n.jsx("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":M===q.slug,"aria-label":`Filter by ${q.label}`,onClick:()=>te(M===q.slug?void 0:q.slug),children:q.label},q.slug))]}),Re&&n.jsxs("button",{type:"button",className:"w6w-apppicker-chip w6w-apppicker-provider-toggle","aria-pressed":be,"aria-label":"Filter to model providers",onClick:()=>ye(q=>!q),children:["Model providers ",n.jsxs("span",{className:"w6w-muted",children:["(",wt,")"]})]}),d&&de.length>0&&n.jsxs(n.Fragment,{children:[Ke.map(q=>n.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":Q.includes(q.slug),"aria-label":`Filter by ${q.label}`,onClick:()=>mt(q.slug),children:[q.label," ",n.jsxs("span",{className:"w6w-muted",children:["(",q.count,")"]})]},q.slug)),!X&&Rt>0&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>ke(!0),children:["+",Rt," more"]}),X&&de.length>ps&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>ke(!1),children:"Show less"}),Q.length>0&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:$t,children:"Clear"})]})]}),k&&Oe?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):k&&ue?n.jsxs("div",{className:"w6w-result w6w-error",children:[ue," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:V,children:"Retry"})]}):De.length===0&&!re?se?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:Me?Be?`No apps from this publisher match “${$}”.`:"No apps from this publisher.":Ne?Be?`No model providers match “${$}”.`:"No apps declare a model provider.":Be?`No apps match “${$}” in the selected categories.`:"No apps match the selected categories."}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:$e,children:"Clear filters"})]}):k?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:Be?`No apps match “${$}”.`:r??"No apps registered yet. Register one from the Apps page first."}),!Be&&c]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No apps match “",$,"”."]}):n.jsxs(n.Fragment,{children:[De.length===0&&re?n.jsx("p",{className:"w6w-muted w6w-small",children:"No matching apps on this page yet — try “Load more”."}):n.jsx("div",{className:"w6w-stepbuilder-list w6w-apppicker-grid w6w-stepbuilder-scroll",children:De.map(q=>{const ce=p==null?void 0:p.get(q.id),v=Oc(ce);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(q),children:[n.jsx(It,{src:q.iconSvg,srcDark:q.iconSvgDark,brandColor:q.brandColor,name:q.displayName,theme:t,size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:q.displayName}),n.jsx("code",{className:"w6w-apppicker-card-id",children:q.id}),q.version&&n.jsxs("span",{className:"w6w-apppicker-card-version",children:["v",q.version]}),q.publisher&&n.jsx(ca,{publisher:q.publisher,testId:`apppicker-publisher-${q.id}`}),v&&n.jsx("span",{className:ce!=null&&ce.supported?"w6w-chip w6w-apppicker-card-bridge":"w6w-chip w6w-apppicker-card-bridge w6w-apppicker-card-bridge-unsupported",title:v.title,children:v.text})]})]},q.id)})}),k&&typeof P.total=="number"&&n.jsx("div",{className:"w6w-small w6w-apppicker-count",children:bt?`${De.length} ${De.length===1?"app":"apps"}`:`${P.apps.length} of ${P.total}`}),k&&me&&n.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[me," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:V,children:"Retry"})]}),k&&re&&!me&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:C,disabled:D,children:D?"Loading more…":"Load more"})]})]}))}const Xs={"&":{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:"none",borderColor:"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",borderRadius:"7px"},".cm-content":{paddingTop:"var(--w6w-sp-2)",paddingBottom:"var(--w6w-sp-2)"},".cm-line":{paddingLeft:"var(--w6w-sp-2)"}};function sr(e){return{children:Object.create(null),detail:e}}function ys(e,t){return Object.hasOwn(e.children,t)?e.children[t]:void 0}function pa(e={}){var r;const t=sr(),s=(a,i)=>{var c;let l=t;for(const u of a)l=(c=l.children)[u]??(c[u]=sr());i&&(l.detail=i)},o=(a,i=[])=>{for(const l of i)s([...a,...l.path?l.key.split("."):[l.key]],l.declaredOnly?"Declared field — test the step to verify":l.label)};for(const a of["nodes","state","consts","trigger","foreach"])s([a]);for(const a of e.vars??[])s(["state",a],"Workflow variable");o(["state"],(r=e.stateShape)==null?void 0:r.fields);for(const a of e.constants??[])s(["consts",a],"Account constant");for(const a of e.steps??[])if(s(["nodes",a.id],a.label??"Earlier step"),s(["nodes",a.id,"output"],a.needsTest?"Test this step to discover fields":"Step output"),o(["nodes",a.id,"output"],a.outputs),a.hasMeta)for(const i of["app","version","action","connectionId"])s(["nodes",a.id,"meta",i]);for(const a of e.nodeConfigs??[])for(const i of a.keys)s(["nodes",a.id,"meta","config",i]);for(const[a,i]of Object.entries(e.nodeMeta??{}))for(const l of Object.keys(i))s(["nodes",a,"meta",l]);if(s(["trigger","type"]),e.loop){s(["foreach","item"]),s(["foreach","index"]),o(["foreach","item"],e.loop.itemOutputs);for(const a of[...e.loop.outer??[],e.loop])s(["foreach","loops",a.foreachId,"item"]),s(["foreach","loops",a.foreachId,"index"]),o(["foreach","loops",a.foreachId,"item"],a.itemOutputs)}return t}const Ic=`(?:"(?:[^"\\\\]|\\\\.)*"|'(?:[^'\\\\]|\\\\.)*')`,Et=`(?:${Ic}|\\d+)`,Rc=`(?:\\s*\\.\\s*[A-Za-z_$][\\w$]*|\\s*\\[\\s*${Et}\\s*\\])`,$c="(?:\\$|ctx|run|state|vars|consts)",_c=`(?:\\$|ctx)\\.get\\(\\s*${Et}(?:\\s*,\\s*${Et})*\\s*\\)`,Pc=`(?:${_c}|${$c})${Rc}*`,or=new RegExp(`(?<![\\w$.])(${Pc})\\s*$`),Fc=new RegExp(`\\.\\s*([A-Za-z_$][\\w$]*)|\\[\\s*(${Et})\\s*\\]`,"g");function gs(e){return e[0]==='"'?JSON.parse(e):e[0]!=="'"?e:e.slice(1,-1).replace(/\\(u[0-9a-fA-F]{4}|[\\'"nrtbf])/g,(t,s)=>s.startsWith("u")?String.fromCharCode(Number.parseInt(s.slice(1),16)):{n:`
4
+ `,r:"\r",t:" ",b:"\b",f:"\f"}[s]??s)}function fa(e,t){let s=e;for(const o of t)s=s&&ys(s,o);return s}function rr(e,t,s){var l;const o=/^(\$|ctx)\.get\((.*)\)/s.exec(e);let r,a,i=!1;if(o){if(o[1]==="ctx"!==s)return;const c=o[2].match(new RegExp(Et,"g"))??[];r=fa(t,c.map(gs)),a=e.slice(o[0].length)}else{const c=(l=/^(\$|ctx|run|state|vars|consts)/.exec(e))==null?void 0:l[0];if(!c||c==="$"&&s||c==="ctx"&&!s)return;i=c==="$"||c==="ctx",i||c==="run"?r=t:r=ys(t,c==="vars"?"state":c),a=e.slice(c.length),c==="run"&&(r={children:Object.fromEntries(["nodes","trigger","foreach"].map(u=>[u,t.children[u]]))})}for(const c of a.matchAll(Fc)){if(s&&c[1]&&!i)return;r=r&&ys(r,c[1]??gs(c[2])),i=!1}return r}function Lc(e,t,s){if(e.tokenBefore(["Comment","LineComment","BlockComment"]))return null;const o=s==="python",r=e.state.sliceDoc(0,e.pos),a=e.tokenBefore(["String","TemplateString"]);let i,l=e.pos,c,u=!1,d,f=!1;const p=new RegExp(`(?<![\\w$.])(?:${o?"ctx":"\\$"})\\.get\\(\\s*((?:${Et}\\s*,\\s*)*)(["']?)([^"'\\\\,\\n]*)$`).exec(r),m=/\[\s*(["']?)([^"'\\\]\n]*)$/.exec(r),h=/\.([\w$]*)$/.exec(r);try{if(p)i=fa(t,(p[1].match(new RegExp(Et,"g"))??[]).map(gs)),c=p[2],l=e.pos-p[3].length-c.length;else if(m){const y=or.exec(r.slice(0,m.index));if(!y)return null;i=rr(y[1],t,o),c=m[1],u=!0,l=e.pos-m[2].length-c.length}else if(h){const y=or.exec(r.slice(0,h.index));if(!y||o&&y[1]!=="ctx")return null;i=rr(y[1],t,o),f=y[1]===(o?"ctx":"$"),d=h.index,l=h.index+1}else if(o&&!a){const y=e.matchBefore(/\w*/);return!y||!e.explicit&&y.from===y.to?null:{from:y.from,options:["ctx","input","run","state","vars","consts","digest","print"].map(x=>({label:x,type:"variable"}))}}}catch{return null}if(!i||a&&(c===void 0||!c||a.from!==l))return null;let w=e.pos;if(c!==void 0){const y=e.state.sliceDoc(e.pos),x=c?new RegExp(`^[^${c}\\\\
5
+ ]*${c}`).exec(y):null;x&&(w+=x[0].length),u&&e.state.sliceDoc(w,w+1)==="]"&&w++}const g=Object.entries(i.children).map(([y,x])=>{const S=JSON.stringify(y);return{label:y,type:"property",detail:x.detail,apply:c!==void 0?`${S}${u?"]":""}`:/^[A-Za-z_$][\w$]*$/.test(y)?y:(A,O,j,N)=>{const k=d??j;A.dispatch({changes:{from:k,to:N,insert:`[${S}]`},selection:{anchor:k+S.length+2}})}}});if(f&&g.push({label:"get",type:"function",detail:`Read a path; missing values return ${o?"None":"undefined"}`}),c!==void 0){const y=e.state.sliceDoc(l+c.length,e.pos).trimStart().toLowerCase();return{from:l,to:w,filter:!1,options:g.filter(x=>x.label.toLowerCase().startsWith(y))}}return g.length?{from:l,to:w,options:g}:null}function Mc(e="javascript",t=pa()){let s,o=0,r=!1;const a=new Map,i=()=>{s==null||s.terminate(),s=void 0;for(const c of a.values())c([]);a.clear()},l=async c=>{if(r)return null;const u=Lc(c,t,e);if(u||e==="python")return u;const d=c.matchBefore(/[\w$]*/);if(r||!d||!c.explicit&&d.from===d.to&&c.state.sliceDoc(c.pos-1,c.pos)!==".")return null;s||(s=new Worker(new URL(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/script-completion.worker-Bjh2aftZ.js").href:new URL("assets/script-completion.worker-Bjh2aftZ.js",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"?require("url").pathToFileURL(__filename).href:rs&&rs.tagName.toUpperCase()==="SCRIPT"&&rs.src||new URL("connection-app-meta-DID4zDg-.cjs",document.baseURI).href),{type:"module"}),s.onmessage=p=>{var m;(m=a.get(p.data.id))==null||m(p.data.options),a.delete(p.data.id)},s.onerror=i);const f=await new Promise(p=>{const m=++o;a.set(m,p),c.addEventListener("abort",()=>{a.delete(m),p([])},{onDocChange:!0}),s==null||s.postMessage({id:m,code:c.state.doc.toString(),position:c.pos,scope:t})});return c.aborted||!f.length?null:{from:d.from,options:f}};return[(e==="python"?zr.pythonLanguage:e==="typescript"?In.typescriptLanguage:In.javascriptLanguage).data.of({autocomplete:l}),qs.ViewPlugin.define(()=>(r=!1,{destroy(){r=!0,i()}}))]}function Dc(e){switch(e){case"javascript":return In.javascript();case"typescript":return In.javascript({typescript:!0});case"python":return zr.python()}}function Zs(e){const t=Bn(e.theme),{copied:s,copy:o}=le.useCopyToClipboard(e.value),r=b.useMemo(()=>[...e.language?[Dc(e.language)]:[],...e.language?[Mc(e.language,e.scriptScope)]:[],qs.EditorView.theme(Xs)],[e.language,e.scriptScope]);return n.jsxs("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:[n.jsx(Jr,{value:e.value,onChange:e.onChange,extensions:r,placeholder:e.placeholder,readOnly:e.readOnly,theme:t,height:e.height,minHeight:e.minHeight??"160px",maxHeight:e.maxHeight,onCreateEditor:e.onCreateEditor,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!e.readOnly,bracketMatching:!0,closeBrackets:!0}}),e.copyable!==!1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-icon-btn w6w-copyable-btn${s?" is-copied":""}`,"aria-label":"Copy",onClick:()=>void o(),children:s?n.jsx(le.CheckGlyph,{}):n.jsx(le.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function qc(){const e=Kr.jsonParseLinter();return t=>t.state.doc.toString().trim()===""?[]:e(t)}function Ze(e){const t=Bn(e.theme),{copied:s,copy:o}=le.useCopyToClipboard(e.value),r=b.useMemo(()=>[Kr.json(),...e.showDiagnostics===!1?[]:[Wo.linter(qc()),Wo.lintGutter()],qs.EditorView.theme(Xs)],[e.showDiagnostics]);function a(i){var l,c,u,d;if(e.onChange(i),!(!e.onValidChange&&!e.onValidityChange)){if(i.trim().length===0){(l=e.onValidityChange)==null||l.call(e,{valid:!1,error:"Empty"});return}try{const f=JSON.parse(i);(c=e.onValidChange)==null||c.call(e,f),(u=e.onValidityChange)==null||u.call(e,{valid:!0})}catch(f){(d=e.onValidityChange)==null||d.call(e,{valid:!1,error:f.message})}}}return n.jsxs("div",{className:"w6w-json-editor","aria-label":e["aria-label"]??"JSON editor",children:[n.jsx(Jr,{value:e.value,onChange:a,extensions:r,placeholder:e.placeholder,readOnly:e.readOnly,editable:!e.readOnly,theme:t,height:e.height,minHeight:e.minHeight??"240px",maxHeight:e.maxHeight,onCreateEditor:e.onCreateEditor,onBlur:e.onBlur,onFocus:e.onFocus,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:!e.readOnly,autocompletion:!0,bracketMatching:!0,closeBrackets:!0}}),e.overlay,e.copyable!==!1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-icon-btn w6w-copyable-btn${s?" is-copied":""}`,"aria-label":"Copy",onClick:()=>void o(),children:s?n.jsx(le.CheckGlyph,{}):n.jsx(le.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}const Uc={padding:"8px 8px 2px",fontSize:"0.75em",fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",opacity:.6,cursor:"default"};function Wc(e){const t=[];for(const s of e){const o=t[t.length-1];o&&o.group===s.group?o.options.push(s):t.push({group:s.group,options:[s]})}return t}function ha(e,t,s){return e*t>.6*s}function ma(e,t){const s=t.trim().toLowerCase();return s?e.filter(o=>{var r;return o.label.toLowerCase().includes(s)||o.value.toLowerCase().includes(s)||(((r=o.keywords)==null?void 0:r.toLowerCase().includes(s))??!1)}):e}const ar={display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"none",width:"1.25em",height:"1.25em",overflow:"hidden"},Hc=240,ir={display:"block",fontSize:"0.85em",opacity:.65,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Bc={position:"absolute",zIndex:50,left:0,right:0,top:"100%",overflowY:"auto",overscrollBehavior:"contain",margin:0,padding:4,listStyle:"none",background:"var(--w6w-panel)",color:"var(--w6w-text)",border:"1px solid var(--w6w-border)",borderRadius:6,boxShadow:"0 4px 12px rgba(0,0,0,0.15)"};function et({options:e,value:t,onChange:s,placeholder:o,disabled:r,"aria-label":a,mode:i="auto",forceSelection:l=!0,optionHeight:c=32,listMaxHeight:u=Hc,className:d,onInputChange:f,emptyText:p="No matches",footer:m}){const h=i==="combobox"||i==="auto"&&ha(e.length,c,typeof window>"u"?0:window.innerHeight),w=b.useId(),g=e.find($=>$.value===t),y=(g==null?void 0:g.label)??(l?"":t),[x,S]=b.useState(y),[A,O]=b.useState(!1),[j,N]=b.useState(!1),[k,_]=b.useState(0),U=b.useRef(null);b.useEffect(()=>{S(y)},[y]);const T=b.useMemo(()=>j?ma(e,x):e,[e,x,j]),F=b.useMemo(()=>({...Bc,maxHeight:u}),[u]);if(!h)return n.jsxs("select",{className:d,value:t,disabled:r,"aria-label":a,onChange:$=>s($.target.value),children:[o!==void 0&&t===""&&n.jsx("option",{value:"",disabled:!0,children:o}),Wc(e).map($=>$.group===void 0?$.options.map(R=>n.jsx("option",{value:R.value,children:R.label},R.value)):n.jsx("optgroup",{label:$.group,children:$.options.map(R=>n.jsx("option",{value:R.value,children:R.label},R.value))},`${$.group}-${$.options[0].value}`))]});const E=$=>`${w}-opt-${$}`,P=()=>{O(!1),N(!1)},I=$=>{S($.label),s($.value),P()},G=$=>{$.key==="ArrowDown"?($.preventDefault(),A?_(R=>Math.min(R+1,T.length-1)):O(!0)):$.key==="ArrowUp"?($.preventDefault(),A?_(R=>Math.max(R-1,0)):O(!0)):$.key==="Enter"?A&&T[k]?($.preventDefault(),I(T[k])):l||(x!==y&&s(x),P()):$.key==="Escape"&&(A&&$.stopPropagation(),S(y),P())},W=()=>{l?S(y):x!==y&&s(x),P()};return n.jsxs("div",{ref:U,className:"w6w-combobox",style:{position:"relative"},children:[(g==null?void 0:g.icon)!==void 0&&!j&&n.jsx("span",{"aria-hidden":"true",className:"w6w-combobox-icon",style:{...ar,position:"absolute",left:"0.6em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:g.icon}),n.jsx("input",{type:"text",role:"combobox",className:d,style:(g==null?void 0:g.icon)!==void 0&&!j?{paddingLeft:"2.2em"}:void 0,value:x,disabled:r,placeholder:o,"aria-label":a,"aria-expanded":A,"aria-controls":`${w}-list`,"aria-autocomplete":"list","aria-activedescendant":A&&T[k]?E(k):void 0,autoComplete:"off",onFocus:()=>O(!0),onChange:$=>{S($.target.value),f==null||f($.target.value),N(!0),_(0),O(!0)},onKeyDown:G,onBlur:W}),A&&n.jsxs("div",{id:`${w}-list`,role:"listbox",tabIndex:-1,"aria-label":a,style:F,children:[T.map(($,R)=>{var z;return n.jsxs(b.Fragment,{children:[$.group!==void 0&&$.group!==((z=T[R-1])==null?void 0:z.group)&&n.jsx("div",{role:"presentation",className:"w6w-combobox-group",style:Uc,children:$.group}),n.jsx("div",{id:E(R),role:"option",tabIndex:-1,"aria-selected":$.value===t,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:R===k?"var(--w6w-panel-2)":void 0},onMouseDown:K=>{K.preventDefault(),I($)},onMouseEnter:()=>_(R),children:$.icon!==void 0?n.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"0.5em"},children:[n.jsx("span",{"aria-hidden":"true",className:"w6w-combobox-icon",style:ar,children:$.icon}),n.jsxs("span",{style:{minWidth:0,flex:1},children:[$.label,$.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:ir,children:$.detail})]})]}):n.jsxs(n.Fragment,{children:[$.label,$.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:ir,children:$.detail})]})})]},$.value)}),T.length===0&&n.jsx("div",{role:"presentation",style:{padding:"6px 8px",opacity:.6},children:p}),m!==void 0&&n.jsx("div",{role:"presentation",className:"w6w-combobox-footer",style:{padding:"6px 8px",opacity:.6,fontSize:"0.85em"},children:m})]})]})}function Vn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.source==="resolveFields"}function tt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="expr"&&Array.isArray(e.parts)}function pt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function lr(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 kn(e){const t=e.filter(o=>o.kind!=="text"||(o.value??"")!=="");if(t.length===0)return"";if(t.some(o=>o.kind==="render"))return{type:"expr",parts:t.map(lr)};let s="";for(const o of t){if(o.kind==="text"){s+=o.value??"";continue}Vc(s)%2===1&&(s+="\\"),s+=ie.serializeTemplate([lr(o)])}return s}function Vc(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t+=1;return t}const wa={var:!0,vars:!0,state:!0,steps:!0,nodes:!0,trigger:!0,foreach:!0,inputs:!0,output:!0,secrets:!0,documents:!0,connections:!0,const:!0};Object.freeze(Object.keys(wa));const cr=e=>Object.prototype.hasOwnProperty.call(wa,e),ur=["state","var","vars"];function ba(e){for(const t of ur)if(e===t||e.startsWith(`${t}.`)){const s=e.slice(t.length);return[...new Set([e,...ur.map(o=>o+s)])]}return[e]}function dr(e){const t=e.indexOf(".");return t===-1?e:e.slice(0,t)}function ft(e){const t=ie.parseTemplate(e,"editor",zc);return t.every(zn)?t:[{kind:"text",value:e}]}function zn(e){if(e.kind==="var"){const t=e.ref??"";return!ie.hasRefusedChainToken(t)&&cr(dr(t))}if(e.kind==="expr"){const t=ie.coalesceOperandRefs(e.expr);return t===null?!0:t.every(s=>cr(dr(s)))}return!0}const zc={isOurs:zn,backslash:"keep"},ya={isOurs:zn,backslash:"strip"};function ct(e){return tt(e)?!0:typeof e=="string"&&e.includes("{{")&&ft(e).some(t=>t.kind!=="text")}function Jn(e){if(!e.includes("{{"))return null;const t=ie.parseTemplate(e,"editor",ya);return t.every(zn)&&(t.some(s=>s.kind!=="text")||t.map(s=>s.value??"").join("")!==e)?t:null}function Jc(e){return e.includes("{{")?ie.parseTemplate(e,"editor",ya).map(t=>t.kind==="text"?t.value??"":ie.serializeTemplate([t])).join(""):e}function xs(e){if(pt(e))return{parts:[],sealed:e};if(tt(e))return{parts:e.parts.map(s=>({...s})),sealed:null};const t=typeof e=="string"?e:"";return{parts:t?ft(t):[],sealed:null}}function Kc(e,t){let s="";for(const o of e)switch(o.kind){case"text":s+=Jc(o.value??"");break;case"var":case"render":{const r=ba(o.ref??"").find(a=>a in t);s+=r===void 0?"":t[r];break}case"secret":s+="•••";break;case"expr":s+=ie.serializeTemplate([o]);break}return s}const Ut="var.",pr="vars.",vs="documents.",js="const.",fs="connections.",ks="state.";function ga(e){return e==="state"||e==="vars"?"var":e.startsWith(pr)?Ut+e.slice(pr.length):e.startsWith(ks)?Ut+e.slice(ks.length):e}function Gc(e){return e.startsWith(ks)?3:e.startsWith(Ut)?2:1}function xa(e){return e.rank>0?e.value:Object.fromEntries(Array.from(e.children,([t,s])=>[t,xa(s)]))}function Qs(e,t,s,o){const r={children:new Map,rank:0},a={},i={},l={};for(const[w,g]of Object.entries(e??{})){const y=ga(w);if(y.startsWith(Ut)){const x=y.slice(Ut.length),S=Gc(w);let A=r;for(const O of x.split(".")){let j=A.children.get(O);j||(j={children:new Map,rank:0},A.children.set(O,j)),A=j}S>=A.rank&&(A.value=g,A.rank=S)}else y.startsWith(vs)?a[y.slice(vs.length)]=g:y.startsWith(js)?i[y.slice(js.length)]=g:y.startsWith(fs)&&!y.slice(fs.length).includes(".")&&(l[y.slice(fs.length)]=g)}const c=xa(r),u=(t==null?void 0:t.steps)??{},d=e??{},f=Object.hasOwn(d,"foreach.item"),p=typeof d["foreach.index"]=="number",m=t==null?void 0:t.foreach,h=m?{...m}:f||p?{...f?{item:d["foreach.item"]}:{},...p?{index:d["foreach.index"]}:{}}:void 0;return{...h?{foreach:h}:{},vars:c,state:c,documents:a,connections:l,constants:i,steps:u,nodes:u,trigger:(t==null?void 0:t.trigger)??{},flat:e??{},...s?{config:s}:{},...o?{meta:o}:{}}}function Yc(e,t){const s=t.split(".");let o=e;for(const r of s){if(o===null||typeof o!="object")return{present:!1,value:void 0};if(!(r in o))return{present:!1,value:void 0};o=o[r]}return{present:!0,value:o}}const Xc=/^(?:nodes|steps)\.[^.]+\.(?:meta\.)?config(?:\.|$)/,Zc=/^(?:nodes|steps)\.([^.]+)\.meta(?:\.|$)/;function Qc(e,t,s){var r;if(!t&&!s)return e;const o={...e};for(const a of new Set([...Object.keys(s??{}),...Object.keys(t??{})])){const i=t==null?void 0:t[a];o[a]={...e[a],meta:{...s==null?void 0:s[a],...(r=e[a])==null?void 0:r.meta,...i?{config:i}:{}},...i?{config:i}:{}}}return o}function va(e,t){var p;const s=ga(e);if(t.flat&&(s.startsWith(Ut)||s.startsWith(vs)||s.startsWith(js))){const m=ba(e).find(h=>Object.hasOwn(t.flat,h));if(m!==void 0)return{status:"resolved",ref:e,value:t.flat[m]}}const{vars:o,constants:r,config:a,meta:i,...l}=t,c=Qc(t.nodes??t.steps,a,i),u={...l,var:o,...r?{const:r}:{},nodes:c,steps:c},d=Yc(u,s);if(d.present)return{status:"resolved",ref:e,value:d.value};if(Xc.test(s))return{status:"at-run",ref:e};const f=(p=Zc.exec(s))==null?void 0:p[1];return f!==void 0&&(i!=null&&i[f])?{status:"at-run",ref:e}:{status:"unresolved",ref:e}}function fr(e,t){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return va(e.ref??"",t);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 eo(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function to(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function no(e,t){if(pt(e))return[{status:"masked"}];if(tt(e))return e.parts.map(s=>fr(s,t));if(typeof e=="string"){const s=Jn(e);if(s)return s.map(o=>fr(o,t))}return eo(e)?[va(String(e.$),t)]:to(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function Ns(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object")return!1;const s=Array.isArray(e),o=Array.isArray(t);if(s!==o)return!1;if(s){const c=e,u=t;return c.length===u.length&&c.every((d,f)=>Ns(d,u[f]))}const r=e,a=t,i=Object.keys(r),l=Object.keys(a);return i.length===l.length&&i.every(c=>c in a&&Ns(r[c],a[c]))}function ja(e){switch(e.status){case"resolved":return e.value===void 0?"<not set>":e.value;case"unresolved":return`<unresolved: ${e.ref}>`;case"at-run":return`<resolved at run: ${e.ref}>`;case"not-evaluated":return"<not evaluated>";case"masked":return e.ref?`<masked: ${e.ref}>`:"<masked>"}}function eu(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(ja(e))}function tu(e){return e.length===1?ja(e[0]):e.map(eu).join("")}function an(e,t){return tu(no(e,t))}function nu(e,t){const s={};for(const o of e)s[o.key||"(no key)"]=an(o.value,t);return s}const Kn=b.forwardRef(function(t,s){const{label:o,children:r,icon:a,iconSize:i,title:l,onClick:c,disabled:u,className:d,danger:f,...p}=t,m=r??(a?n.jsx(le.Icon,{name:a,size:i??16}):null),h=Object.fromEntries(Object.entries(p).filter(([w])=>w.startsWith("data-")));return n.jsx("button",{ref:s,type:"button",className:["w6w-icon-button",f?"w6w-icon-button-danger":"",d??""].filter(Boolean).join(" "),title:l??o,"aria-label":o,"aria-pressed":p["aria-pressed"],"aria-expanded":p["aria-expanded"],"aria-controls":p["aria-controls"],"aria-haspopup":p["aria-haspopup"],disabled:u,onClick:c,...h,children:m})});Kn.displayName="IconButton";const su={default:"",wide:" w6w-modal-wide",xl:" w6w-modal-xl",full:" w6w-modal-full",fullscreen:" w6w-modal-fullscreen"};function Ee({title:e,ariaLabel:t,onClose:s,children:o,size:r="default",titleIcon:a,subtitle:i,headerRight:l}){const c=b.useRef(null),u=b.useRef(null);return b.useEffect(()=>()=>{var d;(d=u.current)!=null&&d.isConnected&&u.current.focus({preventScroll:!0})},[]),b.useEffect(()=>{const d=c.current;if(!d)return;d.open||(u.current=document.activeElement,d.showModal());const f=m=>{m.preventDefault(),s()},p=m=>{if(m.target!==d)return;const h=d.getBoundingClientRect();(m.clientX<h.left||m.clientX>h.right||m.clientY<h.top||m.clientY>h.bottom)&&s()};return d.addEventListener("cancel",f),d.addEventListener("click",p),()=>{d.removeEventListener("cancel",f),d.removeEventListener("click",p)}},[s]),n.jsx("div",{className:"w6w-modal-backdrop",children:n.jsxs("dialog",{ref:c,className:`w6w-modal${su[r]}`,"aria-label":t??(typeof e=="string"?e:void 0),children:[n.jsxs("div",{className:"w6w-modal-header",children:[n.jsxs("h3",{className:"w6w-modal-title",children:[a,n.jsx("span",{children:e}),i&&n.jsx("span",{className:"w6w-modal-subtitle",children:i})]}),l]}),o]})})}const so=new Set(["nodes","steps","state","var","vars","const","inputs","output","trigger","foreach","documents","connections"]),ou=/[=<>]|!=|&&|\|\||\?\?/,Nn=e=>ou.test(e)||/^\s*\(*\s*!/.test(e),Ss=e=>ie.expressionReferences(e).some(Nn);function ru(e,t){var a,i,l;const[s,...o]=e.split(".");if(s==="secrets")throw new Error("Secrets can be inserted into text, but cannot be used in comparisons.");if(so.has(s))return e;const r=[...(a=t.steps)!=null&&a.some(c=>c.id===s)?[`nodes.${s}.output`]:[],...(i=t.vars)!=null&&i.includes(s)?[`var.${s}`]:[],...(l=t.constants)!=null&&l.includes(s)?[`const.${s}`]:[]];if(r.length>1)throw new Error(`“${s}” is ambiguous. Select the field from the sources.`);if(r.length===0)throw new Error(`Unknown field “${s}”. Select a source, or put text values in quotes.`);return[r[0],...o].join(".")}function Qt(e,t){var u,d,f,p,m;const s={parts:e,error:null},o=e.flatMap(h=>h.kind==="text"?ft(h.value??""):[h]);if(o.some(h=>h.kind==="render"))return s;if(o.some(ka))return{parts:o,error:au};if(o.some(iu))return s;if(o.length===1&&o[0].kind==="expr"&&!Ss(o[0].expr))return{parts:o,error:null};let r=o.map(h=>{if(h.kind==="text")return h.value??"";if(h.kind==="secret")return`{{ secrets.${h.ref??""} }}`;if(h.kind==="expr"){if(Ss(h.expr)){const g=ie.serializeTemplate([h]);if(!g.startsWith("{{ ="))return`(${g.slice(2,-2).trim()})`}const w=ie.formatReadableExpression(h.expr);return w===null?ie.serializeTemplate([h]):`(${w})`}return Nn(h.ref??"")?h.ref??"":`{{ ${h.ref??""} }}`}).join("").trim();if(!Nn(r))return s;const a=/^\{\{([^{}]+)\}\}$/.exec(r);a&&Nn(a[1])&&(r=a[1].trim());const i=r.replace(/^[\s(!]+/,""),l=(u=/^(?:\{\{\s*)?([A-Za-z_$][\w$-]*)/.exec(i))==null?void 0:u[1],c=i.startsWith("{{")||l!==void 0&&(so.has(l)||l==="secrets"||((d=t.steps)==null?void 0:d.some(h=>h.id===l))||((f=t.vars)==null?void 0:f.includes(l))||((p=t.constants)==null?void 0:p.includes(l)));if(!c&&!/^(?:["']|-?\d|true\b|false\b|null\b)/.test(i))return s;if(c&&!/^\s*\(*\s*!/.test(r)){const h=(m=/^(?:\{\{[^{}]+\}\}|[A-Za-z_$][\w$-]*(?:\.[\w$-]+)*)/.exec(i))==null?void 0:m[0];if(h){const w=i.slice(h.length).replace(/^[\s)]+/,"");if(!/^(?:[=<>(]|!=|&&|\|\||\?\?)/.test(w)||/^<\/?[A-Za-z][^>]*>/.test(w))return s}}try{return{parts:[{kind:"expr",expr:ie.parseReadableExpression(r,w=>ru(w,t))}],error:null}}catch(h){return{parts:o,error:h instanceof Error?h.message:"Check the expression."}}}const au="The JSONLogic after “=” is not valid JSON. Check its quotes, brackets and commas.";function ka(e){return e.kind==="expr"&&typeof e.expr=="string"}function iu(e){return e.kind==="expr"&&e.expr!==null&&typeof e.expr=="object"&&!Ss(e.expr)&&ie.formatReadableExpression(e.expr)===null}function lu(e){return[...new Set(e.flatMap(t=>t.kind==="expr"?ie.expressionReferences(t.expr):(t.kind==="var"||t.kind==="render")&&t.ref?[t.ref]:[]))]}function cu(e){return e.replace(/^(?:vars|state)(?=\.|$)/,"var").replace(/^steps(?=\.|$)/,"nodes")}function uu(e){const t=Object.create(null);for(const[s,o]of Object.entries(e).sort(([r],[a])=>r.split(".").length-a.split(".").length)){const r=cu(s).split(".");if(!so.has(r[0])||r.some(i=>["__proto__","constructor","prototype"].includes(i)))continue;let a=t;for(const i of r.slice(0,-1)){const l=a[i],c=l&&typeof l=="object"?{...l}:{};a[i]=c,a=c}a[r[r.length-1]]=o}return t.steps=t.nodes,t.vars=t.var,t.state=t.var,t}function du(e,t={},s={}){const o={...t};for(const[i,l]of Object.entries(s))try{o[i]=JSON.parse(l)}catch{o[i]=l}const r=uu(o),a=Object.fromEntries(Object.entries(o).map(([i,l])=>[i,typeof l=="string"?l:JSON.stringify(l)]));return e.map(i=>{if(i.kind!=="expr"||ka(i))return Kc([i],a);if(ie.expressionReferences(i.expr).some(u=>!u||u.split(".")[0]==="secrets"))return"••••";const c=ie.evaluate(i.expr,r);return typeof c=="string"?c:JSON.stringify(c)??""}).join("")}const pu=/^(?:nodes|steps)\.([^.]+)\.output(?:\.(.+))?$/,fu=/^(?:nodes|steps)\.([^.]+)\.meta\.(app|version|action|connectionId)$/,Nt=e=>{if(e.startsWith("var."))return e.slice(4);if(e.startsWith("vars."))return e.slice(5);if(e.startsWith("const."))return e.slice(6);const t=pu.exec(e);if(t)return t[2]?`${t[1]}.${t[2]}`:t[1];const s=fu.exec(e);return s?`${s[1]} meta · ${s[2]}`:e};function hu(e){if(e===null||typeof e!="object"||Array.isArray(e))return;const t=Object.keys(e);if(t.length!==1||t[0]!=="var")return;const s=e.var;return typeof s=="string"?s:void 0}function mu(e){const t=e.op==="or"?"||":"??",s=e.operands.map(o=>{const r=hu(o);return r!==void 0?Nt(r):JSON.stringify(o)}).join(` ${t} `);return s.length>40?`${s.slice(0,40)}…`:s}const wu=/[.{}]/;function Mt(e){return e===""||e!==e.trim()?!1:!wu.test(e)}function xn(e){return e.split(".").every(Mt)}function bu(e){const t=new Set(e.filter(s=>s.path).map(s=>s.key));return e.map(s=>{if(!s.path)return{field:s,depth:0,name:s.key,parent:null};const o=s.key.split(".");let r=0,a=0;for(let l=1;l<o.length;l++)t.has(o.slice(0,l).join("."))&&(r++,a=l);const i=a>0?o.slice(0,a).join("."):null;return{field:s,depth:r,name:o.slice(a).join("."),parent:i}})}function hr(e,t){const s=bu(e),o=new Map(s.map(i=>[i.field.key,i.parent])),r=new Map;for(const i of s)i.parent!==null&&r.set(i.parent,(r.get(i.parent)??0)+1);const a=i=>{const l=o.get(i)??null;return l===null||t(l)&&a(l)};return s.filter(i=>a(i.field.key)).map(({field:i,depth:l,name:c})=>({field:i,depth:l,name:c,children:r.get(i.key)??0}))}function ln(e,t,{renderToggle:s}={}){const o=e.createElement("span");o.contentEditable="false",o.className=`w6w-expr-chip w6w-expr-chip-${t.kind}`,o.setAttribute("data-kind",t.kind);const r=e.createElement("span");r.className="w6w-expr-chip-sigil";const a=e.createElement("span");if(a.className="w6w-expr-chip-label",t.kind==="var")o.setAttribute("data-ref",t.ref??""),r.textContent="◆",a.textContent=Nt(t.ref??""),o.title=`Variable: ${t.ref??""}`;else if(t.kind==="render")o.setAttribute("data-ref",t.ref??""),r.textContent="▤",a.textContent=Nt(t.ref??""),o.title=`Render as template: ${t.ref??""}`;else if(t.kind==="secret")o.setAttribute("data-ref",t.ref??""),r.textContent="🔒",a.textContent=t.ref??"",o.title=`Secret: ${t.ref??""}`;else{const l=typeof t.expr=="string"?t.expr:JSON.stringify(t.expr??"");o.setAttribute("data-expr",l),r.textContent="ƒ";const c=ie.parseCoalesceChain(t.expr);if(c)a.textContent=mu(c),o.title=`Expression: ${ie.serializeTemplate([t])}`;else{const u=ie.formatReadableExpression(t.expr,Nt);a.textContent=u??(l.length>24?`${l.slice(0,24)}…`:l||"expr"),o.title=`Expression: ${u??l}`}}if(o.append(r,a),(t.kind==="var"||t.kind==="render")&&s){const l=e.createElement("span");l.className="w6w-expr-chip-toggle",l.setAttribute("data-render-toggle","1"),l.setAttribute("role","button");const c=t.kind==="render"?"Stop rendering as a template":"Render this as a template";l.setAttribute("aria-label",c),l.title=c,l.textContent="⇄",o.append(l)}const i=e.createElement("span");return i.className="w6w-expr-chip-x",i.setAttribute("data-x","1"),i.setAttribute("role","button"),i.setAttribute("aria-label","Remove"),i.textContent="×",o.append(i),o}const Na=new Set(["div","p"]);function Sa(e){const t=e.getAttribute("data-kind");if(t==="var"||t==="secret"||t==="render")return{kind:t,ref:e.getAttribute("data-ref")??""};if(t==="expr"){const s=e.getAttribute("data-expr")??"";let o=s;try{o=JSON.parse(s)}catch{o=s}return{kind:"expr",expr:o}}return null}function en(e){const t=[],s=a=>{if(!a)return;const i=t[t.length-1];i&&i.kind==="text"?i.value=(i.value??"")+a:t.push({kind:"text",value:a})},o=(a,i)=>{if(a.nodeType===Node.TEXT_NODE){s(a.textContent??"");return}if(a.nodeType!==Node.ELEMENT_NODE)return;const l=a,c=Sa(l);if(c){t.push(c);return}const u=(l.tagName??"").toLowerCase();if(u==="br"){i||s(`
6
+ `);return}const d=Na.has(u);d&&t.length>0&&s(`
7
+ `),r(l,d)},r=(a,i)=>{const l=Array.from(a.childNodes);l.forEach((c,u)=>o(c,i&&u===l.length-1))};return r(e,!0),t}const Ca=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function Aa(e){Ca(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function yu(e){const t=e.ownerDocument.getSelection(),s=t!=null&&t.rangeCount?t.getRangeAt(0):null;if(!s||!e.contains(s.endContainer))return e;let o=s.endContainer;for(;o&&o!==e;){if(o.nodeType===Node.ELEMENT_NODE){const r=o;if(Na.has((r.tagName??"").toLowerCase()))return r}o=o.parentNode}return e}function oo(e){Aa(yu(e))}const Ea=e=>e.getAttribute("aria-multiline")!=="false";function Ta(e,t,s){var a;const o=e.ownerDocument;e.textContent="";for(const i of t)i.kind==="text"?i.value&&e.appendChild(o.createTextNode(i.value)):e.appendChild(ln(o,i,s));const r=t[t.length-1];(r==null?void 0:r.kind)==="text"&&((a=r.value)!=null&&a.endsWith(`
8
+ `))&&Ea(e)&&Aa(e)}function ro(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),s.collapse(!1),t.removeAllRanges(),t.addRange(s)}function Fn(e,t){const s=e.ownerDocument,o=s.getSelection(),r=o!=null&&o.rangeCount?o.getRangeAt(0):null;if(r&&e.contains(r.commonAncestorContainer)){r.deleteContents(),r.insertNode(t);const a=s.createRange();a.setStartAfter(t),a.collapse(!0),o==null||o.removeAllRanges(),o==null||o.addRange(a)}else Ca(e.lastChild)?e.insertBefore(t,e.lastChild):e.appendChild(t),ro(e);e.focus()}function Oa(e,t,s={}){const o=Ea(e),r=o?t.replace(/\r\n?/g,`
9
+ `):t.replace(/\r\n?|\n/g,"");if(!r)return;const a=e.ownerDocument;for(const i of ft(r))Fn(e,i.kind==="text"?a.createTextNode(i.value??""):ln(a,i,s));o&&r.endsWith(`
10
+ `)&&oo(e)}function Ia(e,t={}){const s=e.ownerDocument,o=s.getSelection();if(!o||o.rangeCount===0||!o.isCollapsed)return!1;const r=o.getRangeAt(0),a=r.startContainer;if(a.nodeType!==Node.TEXT_NODE||!e.contains(a))return!1;const i=r.startOffset,l=a.textContent??"";if(i<2||l.slice(i-2,i)!=="}}")return!1;const c=l.lastIndexOf("{{",i-2);if(c===-1)return!1;const u=l.slice(c,i),d=ft(u);if(d.length!==1||d[0].kind==="text")return!1;let f=0;for(;c-1-f>=0&&l[c-1-f]==="\\";)f+=1;if(f%2===1)return!1;const p=s.createRange();p.setStart(a,c),p.setEnd(a,i),p.deleteContents();const m=ln(s,d[0],t);p.insertNode(m);const h=s.createRange();return h.setStartAfter(m),h.collapse(!0),o.removeAllRanges(),o.addRange(h),!0}function Ra(e){const t=Sa(e);if(!t)return null;const s=t.kind==="expr"&&!ie.parseCoalesceChain(t.expr)?ie.formatReadableExpression(t.expr):null,o=e.ownerDocument.createTextNode(s??ie.serializeTemplate([t]));return e.replaceWith(o),o}function gu(e,t){let s=!1;for(let o=0;o<t&&o<e.length;o++){const r=e[o];if(s&&r==="\\"){o++;continue}r==='"'&&(s=!s)}return s}function xu(e){const t=e.split(".").filter(o=>o!==""),s=t[t.length-1]??"value";return(s==="output"||s==="meta")&&t.length>=3?s==="meta"?`${t[t.length-2]}_meta`:t[t.length-2]:s}function vu(e,t){const s=[];let o=!1;for(let a=0;a<t&&a<e.length;a++){const i=e[a];if(o){i==="\\"?a++:i==='"'&&(o=!1);continue}i==='"'?o=!0:i==="{"||i==="["?s.push(i):(i==="}"||i==="]")&&s.pop()}const r=s[s.length-1];return r==="{"||r==="["?r:null}function ju(e,t){if(!e||!Object.hasOwn(e,t))return t;let s=2;for(;Object.hasOwn(e,`${t}_${s}`);)s++;return`${t}_${s}`}function mr(e,t,s,o){var g;const r=o?JSON.stringify(o.value)??"null":"",a=o?JSON.stringify(typeof o.value=="string"?o.value:r).slice(1,-1):`{{ ${s} }}`,i=o?r:JSON.stringify(a),l=(y,x)=>({text:e.slice(0,y)+x+e.slice(y),caret:y+x.length});if(gu(e,t))return l(t,a);let c,u=!0;try{c=JSON.parse(e)}catch{u=!1}const d=u&&c!==null&&typeof c=="object"&&!Array.isArray(c)?c:null,f=()=>`${JSON.stringify(ju(d,xu(s)))}: ${i}`,p=e.slice(0,t).trimEnd(),m=p[p.length-1],h=e.slice(t).trimStart()[0],w=vu(e,t);if(m===":"||m==="["||m===","&&w==="[")return l(t,i+(m!==":"&&h!==void 0&&h!=="]"?", ":""));if(m==="{"||m===","&&w==="{"){const y=h!==void 0&&h!=="}"?", ":"";return l(t,(m===","?" ":"")+f()+y)}if(u&&(d||Array.isArray(c))){const y=e.lastIndexOf(d?"}":"]"),x=e.slice(0,y).trimEnd(),S=x.endsWith(d?"{":"["),A=d?f():i,O=e.slice(x.length,y);if(O.includes(`
11
+ `)){const k=S?`${O.slice(O.lastIndexOf(`
12
+ `)+1)} `:((g=/^\s*/.exec(x.slice(x.lastIndexOf(`
13
+ `)+1)))==null?void 0:g[0])??"",_=`${S?"":","}
14
+ ${k}${A}`;return{text:x+_+e.slice(x.length),caret:x.length+_.length}}const j=`${S?"":","} ${A} `,N=x.length;return{text:e.slice(0,N)+j+e.slice(y),caret:N+j.length-1}}return l(t,i)}const ku=/^\{\{\s*((?:var|vars|const|steps|nodes|trigger|foreach|inputs|output|documents)(?:\.[^\s{}]+)?)\s*\}\}$/;function Nu(e){const t=ku.exec(e.trim());return t?`{{ ${t[1]} }}`:null}function ht(e){if(typeof e=="string"){if(!e.includes("{{"))return null;const t=ft(e);return t.length===1&&t[0].kind==="var"?t[0].ref??null:null}return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$=="string"?e.$:null}function Su(e){var s;const t={};for(const[o,r]of Object.entries(e??{})){const a=/^(?:steps|nodes)\.([^.]+)\.output$/.exec(o);if(a){t[a[1]]={...t[a[1]],output:r};continue}const i=/^(?:steps|nodes)\.([^.]+)\.meta\.([^.]+)$/.exec(o);if(i){t[s=i[1]]??(t[s]={});const l=t[i[1]];l.meta={...l.meta,[i[2]]:r}}}return{steps:t}}function Cs(e,t){if(typeof e=="string"){const s=Jn(e);return s?s.length===1&&s[0].kind==="var"?t({$:s[0].ref}):t({type:"expr",parts:s}):e}if(Array.isArray(e))return e.map(s=>Cs(s,t));if(e!==null&&typeof e=="object"){const s=Object.keys(e);return s.length===1&&s[0]==="$"&&typeof e.$=="string"?t(e):Object.fromEntries(Object.entries(e).map(([o,r])=>[o,Cs(r,t)]))}return e}function mn({value:e,masked:t,multiline:s,options:o,fieldLabel:r,onSave:a,onClose:i,mode:l,jsonValue:c,onSaveJson:u,whole:d,startingState:f,jsonProblem:p,title:m}){var ce;const h=l==="json-binding",w=h&&f===!0,[g,y]=b.useState("ref"),[x,S]=b.useState(()=>c===void 0?"":JSON.stringify(c,null,2)),A=b.useRef(null),O=b.useRef(!1),j=b.useMemo(()=>{if(x.trim()==="")return{ok:!1};try{return{ok:!0,value:JSON.parse(x)}}catch{return{ok:!1}}},[x]),N=w?(p==null?void 0:p(x))??null:null,k=w?(x.trim()===""||j.ok)&&N===null:j.ok,_=()=>Qs(o.sampleValues,Su(o.sampleValues),o.nodeConfig,o.nodeMeta),U=h?j.ok?JSON.stringify(Cs(j.value,v=>an(v,_())),null,2):x.trim()===""?"":"Invalid JSON":"",T=v=>{const L=A.current,H=L?L.state.doc.toString():x;if(w){const Ae=g==="value"?{value:an(`{{ ${v} }}`,_())??null}:void 0,yt=H.trim()===""?"{}":H,dl=O.current&&L?L.state.selection.main.head:yt.length,os=mr(yt,dl,v,Ae);if(!L){S(os.text);return}L.dispatch({changes:{from:0,to:H.length,insert:os.text},selection:{anchor:os.caret}}),L.focus();return}let oe=null;try{oe=H.trim()===""?null:ht(JSON.parse(H))}catch{oe=null}let we=!1;if(d)try{const Ae=JSON.parse(H);we=Array.isArray(Ae)?Ae.length===0:typeof Ae=="object"&&Ae!==null&&Object.keys(Ae).length===0}catch{we=!1}if(H.trim()===""||oe!==null||we){u==null||u(`{{ ${v} }}`),i();return}if(!L)return;const fe=O.current?L.state.selection.main.head:H.length,Z=mr(H,fe,v);L.dispatch({changes:{from:0,to:H.length,insert:Z.text},selection:{anchor:Z.caret}}),L.focus()},[F,E]=b.useState(()=>Qt(xs(e).parts,o).parts),P=b.useMemo(()=>Qt(F,o),[F,o]),[I,G]=b.useState(0),W=b.useRef(null),$=b.useRef(!1),[R,z]=b.useState({}),[K,ne]=b.useState(null),[B,Y]=b.useState(()=>new Set),J=v=>{Y(L=>{const H=new Set(L);return H.has(v)?H.delete(v):H.add(v),H})},[M,te]=b.useState("auto");b.useLayoutEffect(()=>{const v=W.current;v&&(Ta(v,F,{renderToggle:!0}),$.current&&($.current=!1,ro(v),v.focus()))},[I]);const ee=()=>{const v=W.current;v&&E(en(v))},C=v=>{const L=W.current;L&&(Fn(L,ln(L.ownerDocument,v,{renderToggle:!0})),E(en(L)))},V=F.some(v=>v.kind==="render"),Q=(v,{restoreFocus:L})=>{E(Qt(ft(v),o).parts),G(H=>H+1)},ae=()=>{const v=W.current,L=Qt(v?en(v):F,o);L.error||(a==null||a(kn(L.parts)),i())},X=()=>{ne(null),$.current=!0,G(v=>v+1)},ke=o.vars??[],be=o.constants??[],ye=w?[]:o.connections??[],ge=o.secrets??[],xe=o.inputs??[],ue=o.documents??[],D=o.steps??[],re=o.nodeConfigs??[],me=o.loop,Oe=new Map(re.map(v=>[v.id,v.keys.filter(Mt)]).filter(([,v])=>v.length>0)),Ie=o.nodeMeta??{},_e=v=>Cu.filter(([L])=>Au.has(L)?We(v):Object.hasOwn(Ie[v]??{},L)),de=D.filter(v=>v.hasMeta===!0).map(v=>v.id),We=v=>{var H;if(de.includes(v))return!0;const L=(H=Ie[v])==null?void 0:H.app;return typeof L=="string"&&!it(L)},Gt=v=>_e(v).map(([L,H])=>pe(H,{kind:"var",ref:`nodes.${v}.meta.${L}`},"w6w-exprmodal-field",null)),He=[...new Set([...Object.keys(Ie),...de,...Oe.keys()])],Rt=D.length>0,Ke=!w&&(Rt||!!me),mt=w?[]:(((ce=o.stateShape)==null?void 0:ce.fields)??[]).filter(v=>xn(v.key)),$t=[...Ke?["state"]:[],...mt.length>0?["runstate"]:[],...He.length>0?["meta"]:[],...ye.length>0?["conns"]:[],...o.inputs!==void 0?["inputs"]:[],"vars",...be.length>0?["consts"]:[],...!h||w?["docs"]:[],...h?[]:["secrets"]],wt=M==="auto"||M!==null&&!$t.includes(M)?$t.find(v=>v!=="meta")??null:M,Re=v=>({open:wt===v,onToggle:()=>te(wt===v?null:v)}),ve=((me==null?void 0:me.itemOutputs)??[]).filter(v=>v.path?xn(v.key):Mt(v.key)),Pe=ie.serializeTemplate(P.parts),_t=b.useMemo(()=>{const v={};for(const[L,H]of Object.entries(o.sampleValues??{}))v[L]=typeof H=="string"?H:JSON.stringify(H);return{...v,...R}},[o.sampleValues,R]),Fe=b.useMemo(()=>lu(P.parts),[P.parts]),Me=b.useMemo(()=>{if(P.error)return"";try{return du(P.parts,o.sampleValues,R)}catch{return Pe}},[P,o.sampleValues,R,Pe]),Ge=b.useMemo(()=>{var L;const v=new Set;for(const H of Fe){if(R[H]!==void 0)continue;const oe=(L=o.valueSources)==null?void 0:L[H];oe==="sample"?v.add("example from the app"):oe==="persisted"&&v.add("from last test")}return[...v]},[Fe,R,o.valueSources]),pe=(v,L,H,oe,we=!1,fe,Z)=>n.jsxs("div",{className:"w6w-exprmodal-item",style:{display:"flex",alignItems:"center",gap:4,minWidth:0,...Z&&Z.depth>0?{paddingLeft:Z.depth*14}:{}},children:[n.jsxs("button",{type:"button",className:`w6w-exprmodal-source ${H}${Z!=null&&Z.declaredOnly?" is-declared-only":""}`,style:{flex:1,minWidth:0,...Z!=null&&Z.declaredOnly?{opacity:.6}:{}},title:`Insert ${(Z==null?void 0:Z.name)??v}`,"aria-label":fe,onClick:()=>h?L.kind==="var"&&T(L.ref??""):C(L),children:[oe!==null&&n.jsx("span",{className:"w6w-expr-chip-sigil",children:oe}),n.jsx("span",{className:"w6w-exprmodal-source-label",children:v}),(Z==null?void 0:Z.declaredOnly)&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-declared-only",style:{marginLeft:6},children:"declared by the app"}),(Z==null?void 0:Z.somePaths)&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-state-some-paths",title:"Set on some paths into this step, not all",style:{marginLeft:6},children:"some paths"})]}),Z==null?void 0:Z.toggle,!h&&n.jsx(Kn,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>C(L)})]},`${L.kind}:${L.ref??v}`),st=B.has("loop:item"),Be=pe("Current item",{kind:"var",ref:"foreach.item"},"w6w-expr-chip-var","↻"),De=(v,L)=>{if(L.length===0)return null;const H=B.has(`mcfg:${v}`);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-exprmodal-source-row",children:n.jsxs("button",{type:"button",className:"w6w-exprmodal-tree-toggle","data-testid":"expr-config-toggle","aria-expanded":H,title:H?"Hide config":"Show config",onClick:()=>J(`mcfg:${v}`),children:[n.jsx("span",{className:"w6w-exprmodal-tree-caret","aria-hidden":"true",children:H?"▾":"▸"}),"config"]})}),H&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-config-fields",children:L.map(oe=>pe(oe,{kind:"var",ref:`nodes.${v}.meta.config.${oe}`},"w6w-exprmodal-field",null))})]})},bt=(v,L,H=`nodes.${v}.output`)=>Ne(L,H,oe=>({declaredOnly:oe.declaredOnly===!0})),se=v=>hr(v,()=>!1).length,Ne=(v,L,H=()=>({}))=>hr(v,oe=>B.has(`tree:${L}.${oe}`)).map(({field:oe,depth:we,name:fe,children:Z})=>{const Ae=`${L}.${oe.key}`,yt=B.has(`tree:${Ae}`);return pe(fe,{kind:"var",ref:Ae},"w6w-exprmodal-field",null,!1,void 0,{name:Nt(Ae),depth:we,...H(oe),toggle:Z>0?n.jsx(Lt,{count:Z,open:yt,onToggle:()=>J(`tree:${Ae}`)}):void 0})}),$e=v=>v==="fresh"||v==="persisted"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:v==="fresh"?"Fields from the last test run":"Fields from last test"}):v==="declared"||v==="sample"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":`expr-fields-from-${v}`,children:v==="declared"?"declared by the app":"example from the app"}):null,q=v=>{const L=`mnode:${v}`,H=B.has(L);return n.jsxs(b.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row","data-testid":"expr-metadata-node",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-metadata-node-toggle","aria-expanded":H,"aria-label":H?`Hide ${v} metadata`:`Show ${v} metadata`,title:H?"Hide metadata":"Show metadata",onClick:()=>J(L),children:H?"▾":"▸"}),pe(v,{kind:"var",ref:`nodes.${v}.meta`},"w6w-expr-chip-var w6w-exprmodal-node",null,!0)]}),H&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-metadata-fields",children:[Gt(v),De(v,Oe.get(v)??[])]})]},L)};return n.jsxs(Ee,{title:m??(h?"Edit JSON value":"Edit expression"),subtitle:r?n.jsx("code",{children:r}):void 0,onClose:i,size:"full",headerRight:h?n.jsxs("div",{className:"w6w-exprmodal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:i,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-json-save",disabled:!k,title:k?"Save the composed JSON":N??"Compose valid JSON to save",onClick:()=>{k&&(u==null||u(j.ok?j.value:void 0),i())},children:"Save"})]}):n.jsxs("div",{className:"w6w-exprmodal-actions",children:[!t&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:V,title:V?"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(ie.serializeTemplate(F)),i()},children:"Use a plain value"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:i,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:ae,"data-testid":"expr-save",disabled:P.error!==null,children:"Save"})]}),children:[n.jsxs("div",{className:"w6w-exprmodal",children:[n.jsxs("aside",{className:"w6w-exprmodal-sources",children:[w&&n.jsxs("fieldset",{className:"w6w-exprmodal-insert-as","aria-label":"Insert as",style:{display:"flex",gap:4,alignItems:"center",marginBottom:8},children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Insert as"}),[["ref","Reference","Insert {{ ref }}: resolved when each run starts"],["value","Value","Insert the current value, copied in as it is now"]].map(([v,L,H])=>n.jsx("button",{type:"button","aria-pressed":g===v,"data-testid":`expr-insert-as-${v}`,title:H,className:`w6w-btn w6w-btn-sm${g===v?"":" w6w-btn-ghost"}`,onClick:()=>y(v),children:L},v))]}),h&&!w&&!Ke&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),Ke&&n.jsxs(Ye,{label:"Previous steps",...Re("state"),children:[me&&n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":"expr-loop-group",children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:"Loop"}),ve.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[Be,n.jsx(Lt,{count:se(ve),open:st,onToggle:()=>J("loop:item")})]}):Be,ve.length>0&&st&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-loop-fields",children:Ne(ve,"foreach.item")}),pe("Index",{kind:"var",ref:"foreach.index"},"w6w-expr-chip-var","#"),(me.outer??[]).map(v=>{const L=v.name??v.foreachId,H=`foreach.loops.${v.foreachId}`;return n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":`expr-loop-outer-${v.foreachId}`,children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:L}),pe(`${L} item`,{kind:"var",ref:`${H}.item`},"w6w-expr-chip-var","↻"),pe(`${L} index`,{kind:"var",ref:`${H}.index`},"w6w-expr-chip-var","#")]},v.foreachId)})]}),D.map(v=>{const L=(v.outputs??[]).filter(fe=>fe.path?xn(fe.key):Mt(fe.key)),H=`step:${v.id}`,oe=B.has(H),we=pe(v.label??v.id,{kind:"var",ref:`nodes.${v.id}.output`},"w6w-expr-chip-var w6w-exprmodal-node",v.trigger?"⚡":null,L.length>0);return h?n.jsxs(b.Fragment,{children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:v.label??v.id}),pe("Entire output",{kind:"var",ref:`nodes.${v.id}.output`},"w6w-expr-chip-var",null,!1,`Entire output of ${v.label??v.id}`),v.needsTest&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),L.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":oe,"aria-label":oe?"Hide fields":"Show fields",title:oe?"Hide fields":"Show fields",onClick:()=>J(H),children:oe?"▾":"▸"}),n.jsx(Lt,{count:se(L),open:oe,onToggle:()=>J(H)})]}),oe&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[$e(v.outputsFrom),bt(v.id,L)]})]})]},v.id):n.jsxs(b.Fragment,{children:[L.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":oe,"aria-label":oe?"Hide fields":"Show fields",title:oe?"Hide fields":"Show fields",onClick:()=>J(H),children:oe?"▾":"▸"}),we,n.jsx(Lt,{count:se(L),open:oe,onToggle:()=>J(H)})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),we]}),v.needsTest&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),L.length>0&&oe&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[$e(v.outputsFrom),bt(v.id,L)]})]},v.id)})]}),mt.length>0&&n.jsxs(Ye,{label:"State",testId:"expr-state-group",...Re("runstate"),children:[pe("state",{kind:"var",ref:"state"},"w6w-expr-chip-var","◇",!0),n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-state-fields",children:Ne(mt,"state",v=>({somePaths:v.paths==="some"}))})]}),He.length>0&&n.jsx(Ye,{label:"Metadata",testId:"expr-metadata-group",...Re("meta"),children:He.map(v=>q(v))}),ye.length>0&&n.jsx(Ye,{label:"Connections",testId:"expr-connections-group",...Re("conns"),children:ye.map(v=>{const L=`connections.${v.name}`,H=`conn:${v.name}`,oe=B.has(H),we=v.fields.filter(Z=>Z.path?xn(Z.key):Mt(Z.key)),fe=we.filter(Z=>!Z.key.includes(".")).length;return n.jsxs(b.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row","data-testid":"expr-connection",children:[pe(v.name,{kind:"var",ref:L},"w6w-expr-chip-var","⚿",!0),n.jsx(Lt,{count:fe,open:oe,onToggle:()=>J(H)})]}),n.jsx("div",{className:"w6w-exprmodal-connection-note w6w-muted w6w-small",children:v.label?`${v.appName} · ${v.label}`:v.appName}),oe&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-connection-fields",children:Ne(we,L)})]},H)})}),n.jsxs(n.Fragment,{children:[o.inputs!==void 0&&n.jsxs(Ye,{label:"Inputs",...Re("inputs"),children:[xe.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),xe.map(v=>pe(v,{kind:"var",ref:`inputs.${v}`},"w6w-expr-chip-var","⇥"))]}),n.jsxs(Ye,{label:"Variables",...Re("vars"),action:o.createVar&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-var",onClick:()=>ne("var"),children:"+ Add"}),children:[ke.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),ke.map(v=>pe(v,{kind:"var",ref:`var.${v}`},"w6w-expr-chip-var","◆"))]}),be.length>0&&n.jsx(Ye,{label:"Constants",testId:"expr-constants-group",...Re("consts"),children:be.map(v=>pe(v,{kind:"var",ref:`const.${v}`},"w6w-expr-chip-var","◈"))})]}),(!h||w)&&n.jsxs(Ye,{label:"Documents",...Re("docs"),children:[ue.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),ue.map(v=>{const L=(v.fields??[]).filter(fe=>Mt(fe.key)),H=`doc:${v.key}`,oe=B.has(H),we=pe(v.key,{kind:"var",ref:`documents.${v.key}`},"w6w-expr-chip-var","▦",L.length>0);return n.jsxs(b.Fragment,{children:[L.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[we,n.jsx(Lt,{count:L.length,open:oe,onToggle:()=>J(H)})]}):we,L.length>0&&oe&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:L.map(fe=>{const Z=`documents.${v.key}.${fe.key}`;return n.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[pe(fe.key,{kind:"var",ref:Z},"w6w-expr-chip-var","·"),!h&&n.jsx("button",{type:"button",className:"w6w-exprmodal-render-btn","data-testid":"expr-insert-render",title:`Insert ${Z} and render its {{ }} placeholders`,"aria-label":`Insert ${Z} and render its {{ }} placeholders`,onClick:()=>C({kind:"render",ref:Z}),children:"▤"})]},Z)})})]},v.key)})]}),!h&&n.jsxs(Ye,{label:"Secrets",...Re("secrets"),action:o.createSecret&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-secret",onClick:()=>ne("secret"),children:"+ Add"}),children:[ge.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),ge.map(v=>pe(v,{kind:"secret",ref:v},"w6w-expr-chip-secret","🔒"))]})]}),h&&n.jsxs("div",{className:"w6w-exprmodal-main",children:[n.jsxs("div",{className:"w6w-exprmodal-editor",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["JSON",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— type JSON, or click a source on the left to insert it at the cursor"]})]}),n.jsx("div",{className:"w6w-exprmodal-json",onFocus:()=>{O.current=!0},children:n.jsx(Ze,{value:x,onChange:S,height:"100%",minHeight:"0px","aria-label":"Compose JSON",placeholder:w?'{ "region": "us", "template": "{{ documents.welcome }}" }':'{ "key": "{{ nodes.step_1.output }}" }',onCreateEditor:v=>{A.current=v}})})]}),n.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ",w?" — the state each run starts with, against the sample values":" — live preview against the sample values"]})]}),N&&n.jsx("span",{className:"w6w-muted w6w-small",role:"alert","data-testid":"expr-json-problem",children:N}),n.jsx(le.Copyable,{value:U??"",label:"Copy result",children:n.jsx("pre",{className:"w6w-exprmodal-result","data-testid":"expr-json-result",children:U})})]})]}),!h&&n.jsxs("div",{className:"w6w-exprmodal-main",children:[n.jsxs("div",{className:"w6w-exprmodal-editor",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Expression",n.jsx("span",{className:"w6w-muted w6w-small",children:" — click a source on the left, or type"})]}),n.jsx("div",{ref:W,className:`w6w-exprmodal-chips${t?" is-masked":""}${F.length===0?" is-empty":""}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":s?"true":"false","aria-label":"Expression","data-placeholder":'Pick a field, then type == "value"',"aria-invalid":P.error!==null,"aria-describedby":P.error?"expression-problem":void 0,spellCheck:!1,onInput:()=>{const v=W.current;v&&Ia(v,{renderToggle:!0}),ee()},onDoubleClick:v=>{const L=v.target;if(L.closest("[data-x]")||L.closest("[data-render-toggle]"))return;const H=L.closest(".w6w-expr-chip");if(!H)return;v.preventDefault();const oe=Ra(H);if(oe){const we=oe.ownerDocument,fe=we.createRange();fe.setStartAfter(oe),fe.collapse(!0);const Z=we.getSelection();Z==null||Z.removeAllRanges(),Z==null||Z.addRange(fe)}ee()},onBlur:()=>{const v=W.current;v&&Q(ie.serializeTemplate(en(v)),{restoreFocus:!1})},onPaste:v=>{var H;v.preventDefault();const L=W.current;L&&(Oa(L,((H=v.clipboardData)==null?void 0:H.getData("text/plain"))??"",{renderToggle:!0}),ee())},onClick:v=>{var we;const L=v.target,H=L.closest("[data-x]");if(H){v.preventDefault(),(we=H.closest(".w6w-expr-chip"))==null||we.remove(),ee();return}const oe=L.closest("[data-render-toggle]");if(oe){v.preventDefault();const fe=oe.closest(".w6w-expr-chip");if(fe){const Z=fe.getAttribute("data-ref")??"",Ae=fe.getAttribute("data-kind")==="render"?"var":"render";fe.replaceWith(ln(fe.ownerDocument,{kind:Ae,ref:Z},{renderToggle:!0}))}ee()}},onKeyDown:v=>{if(v.key!=="Enter"||(v.preventDefault(),!s))return;const L=W.current;L&&(Fn(L,L.ownerDocument.createTextNode(`
15
+ `)),oo(L),ee())}}),n.jsxs("span",{className:"w6w-muted w6w-small",children:["Pick a field, then type ",n.jsx("code",{children:'== "value"'}),". Combine conditions with"," ",n.jsx("code",{children:"&&"})," or ",n.jsx("code",{children:"||"}),". Double-click a chip to edit it."]}),P.error&&n.jsx("span",{id:"expression-problem",role:"alert",className:"w6w-error",children:P.error})]}),Fe.length>0&&n.jsxs("div",{className:"w6w-exprmodal-preview",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Sample values",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— try the expression against example data"]})]}),Fe.map(v=>n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:v}),n.jsx("input",{type:"text",value:R[v]??_t[v]??"",placeholder:"sample value",onChange:L=>z(H=>({...H,[v]:L.target.value}))})]},v))]}),n.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— live preview against the sample values"]})]}),n.jsx(le.Copyable,{value:Me,readOnly:!0,children:n.jsx("pre",{className:"w6w-exprmodal-result",children:Me||" "})}),Ge.length>0&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-result-source",children:Ge.join(" · ")})]})]})]}),K==="var"&&o.createVar&&n.jsx(wr,{kind:"var",onCreate:o.createVar,onClose:X}),K==="secret"&&o.createSecret&&n.jsx(wr,{kind:"secret",onCreate:o.createSecret,onClose:X})]})}function Ye({label:e,open:t,onToggle:s,action:o,testId:r,children:a}){const i=b.useId(),l=b.useRef(null);return b.useLayoutEffect(()=>{l.current&&(l.current.inert=!t)},[t]),n.jsxs("div",{className:`w6w-exprmodal-group${t?" is-open":""}`,"data-testid":r,"data-section-open":t?"true":"false",children:[n.jsxs("div",{className:"w6w-exprmodal-group-head",children:[n.jsxs("button",{type:"button",className:"w6w-exprmodal-group-toggle","data-testid":"expr-section-toggle","aria-expanded":t,"aria-controls":i,onClick:s,children:[n.jsx("span",{className:"w6w-exprmodal-group-label",children:e}),n.jsx("span",{className:"w6w-exprmodal-group-caret","aria-hidden":"true",children:"›"})]}),o]}),n.jsx("div",{id:i,ref:l,className:"w6w-exprmodal-group-body","aria-hidden":!t,children:n.jsx("div",{className:"w6w-exprmodal-group-inner",children:a})})]})}function Lt({count:e,open:t,onToggle:s}){return n.jsxs("button",{type:"button",className:"w6w-exprmodal-toggle-btn","data-testid":"expr-toggle-fields","aria-expanded":t,title:t?"Hide fields":"Show fields",onClick:s,children:[e," ",e===1?"field":"fields"," ",t?"⌄":"›"]})}const Cu=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"],["subscriptionId","Subscription ID"],["url","Webhook URL"]],Au=new Set(["app","version","action","connectionId"]);function wr({kind:e,onCreate:t,onClose:s}){const[o,r]=b.useState(""),[a,i]=b.useState(""),[l,c]=b.useState(""),[u,d]=b.useState(null),[f,p]=b.useState(!1),m=e==="var"?"variable":"secret";async function h(){d(null),p(!0);try{await t({name:o,value:a,description:l||void 0}),s()}catch(w){d(w.message)}finally{p(!1)}}return n.jsxs(Ee,{title:`Add ${m}`,onClose:s,children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Name"}),n.jsx("input",{type:"text",value:o,onChange:w=>r(w.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}),n.jsx("span",{className:"w6w-muted w6w-small",children:"Letters, digits, and underscores. Must start with a letter or underscore. Case-sensitive."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Value"}),n.jsx("input",{type:e==="secret"?"password":"text",value:a,onChange:w=>i(w.target.value),autoComplete:"off","data-testid":"expr-add-value-value"}),e==="secret"&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Stored encrypted at rest. Once saved, it is not readable through the UI."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Description"}),n.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value),placeholder:"Optional",autoComplete:"off"})]}),u&&n.jsx("div",{className:"w6w-result w6w-error",children:u})]})}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"expr-add-value-cancel",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-add-value-save",disabled:!o||!a||f,onClick:h,children:f?"Saving…":"Save"})]})]})}function Eu(e,t){return t?e.filter(s=>s.id!==t):e}const As=b.createContext({});function Tu({value:e,children:t}){const s=b.useContext(As),o=b.useMemo(()=>({...s,...e}),[s,e]);return n.jsx(As.Provider,{value:o,children:t})}function nt(){return b.useContext(As)}function cn({value:e,onChange:t,placeholder:s,masked:o,multiline:r,readOnly:a,options:i,"aria-label":l}){const[c,u]=b.useState(()=>xs(e)),{parts:d,sealed:f}=c,[p,m]=b.useState(0),[h,w]=b.useState(!1),[g,y]=b.useState(!1),x=b.useRef(!1),S=b.useRef(null),A=b.useRef(null),O=nt(),j={...O,...i??{}},N=O.sealSecret;b.useLayoutEffect(()=>{const F=S.current;!F||f||(Ta(F,d),(x.current||F.ownerDocument.activeElement===F)&&(F.focus(),ro(F),x.current=!1))},[p,f]);const k=()=>{const F=S.current;if(!F)return;const E=en(F);u(I=>({...I,parts:E}));const P=Qt(E,j);t(kn(P.parts))},_=async F=>{if(!N)return!1;w(!0);try{const E=await N(F);return x.current=!1,u({parts:[],sealed:E}),m(P=>P+1),t(E),!0}catch{return!1}finally{w(!1)}},U=F=>{var I;if(g||!o||a||h)return;const E=F.relatedTarget;if(E&&((I=A.current)!=null&&I.contains(E)))return;const P=kn(d);typeof P=="string"&&P!==""&&!ct(P)&&_(P)},T=F=>{if(o&&typeof F=="string"&&F.trim()!==""&&!ct(F)){_(F);return}x.current=!1,u(xs(F)),m(E=>E+1),t(F)};return f?n.jsxs("div",{className:`w6w-expr-sealed${a?" is-readonly":""}`,"aria-label":l,children:[n.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-secret",title:"Encrypted secret",children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"🔒"}),n.jsx("span",{className:"w6w-expr-chip-label",children:"••••••"})]}),!a&&n.jsx("button",{type:"button",className:"w6w-expr-replace",onClick:()=>{x.current=!0,u({parts:[],sealed:null}),m(F=>F+1),t("")},children:"Replace"})]}):n.jsxs("div",{className:"w6w-expr",ref:A,onBlur:U,children:[n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{ref:S,className:`w6w-expr-editor${o?" is-masked":""}${d.length===0?" is-empty":""}${a?" is-readonly":""}`,contentEditable:!a,suppressContentEditableWarning:!0,role:"textbox",tabIndex:a?-1:0,"aria-multiline":r?"true":"false","aria-label":l,"data-placeholder":s??"",spellCheck:!1,onInput:()=>{const F=S.current;F&&Ia(F),k()},onPaste:F=>{var P;F.preventDefault();const E=S.current;E&&(Oa(E,((P=F.clipboardData)==null?void 0:P.getData("text/plain"))??""),k())},onClick:F=>{var P;const E=F.target.closest("[data-x]");E&&(F.preventDefault(),(P=E.closest(".w6w-expr-chip"))==null||P.remove(),k())},onDoubleClick:F=>{const E=F.target;if(E.closest("[data-x]"))return;const P=E.closest(".w6w-expr-chip");if(!P)return;F.preventDefault();const I=Ra(P);if(I){const G=I.ownerDocument,W=G.createRange();W.setStartAfter(I),W.collapse(!0);const $=G.getSelection();$==null||$.removeAllRanges(),$==null||$.addRange(W)}k()},onKeyDown:F=>{if(F.key!=="Enter"||(F.preventDefault(),!r))return;const E=S.current;E&&(Fn(E,E.ownerDocument.createTextNode(`
16
+ `)),oo(E),k())}}),!a&&n.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"})]}),g&&n.jsx(mn,{value:kn(d),masked:o,multiline:r,options:j,fieldLabel:l,onSave:T,onClose:()=>y(!1)})]})}const Ou=/\{\{\s*([^{}]*?)\s*\}\}/g;function $a(e,t="javascript"){const s=t==="python",o=[],r=[];let a=0;for(;a<e.length;){const l=e[a],c=e.slice(a,a+2),u=e.slice(a,a+3);if(s&&l==="#"||!s&&c==="//"){const d=e.indexOf(`
17
+ `,a),f=d===-1?e.length:d;r.push({start:a,end:f}),a=f}else if(!s&&c==="/*"){const d=e.indexOf("*/",a+2),f=d===-1?e.length:d+2;r.push({start:a,end:f}),a=f}else if(s&&(u==='"""'||u==="'''")){const d=e.indexOf(u,a+3),f=d===-1?e.length:d+3;o.push({start:a,end:f,quote:u}),a=f}else if(l==="'"||l==='"'||!s&&l==="`"){let d=a+1;for(;d<e.length&&e[d]!==l;){if(e[d]==="\\")d++;else if(l!=="`"&&e[d]===`
18
+ `)break;d++}const f=Math.min(d+1,e.length);o.push({start:a,end:f,quote:l}),a=f}else a++}const i=[];for(const l of e.matchAll(Ou)){const c=l.index??0,u=c+l[0].length;if(r.some(f=>c>=f.start&&c<f.end))continue;const d=o.find(f=>c>f.start&&c<f.end);i.push({start:c,end:u,ref:l[1],context:d?{kind:"string",...d}:{kind:"code"}})}return i}const Iu=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$-]*|\[\d+\]|\["[^"\\]*"\]|\['[^'\\]*'\])*$/,Ru=/\.([A-Za-z_$][\w$-]*)|\[(\d+)\]|\["([^"\\]*)"\]|\['([^'\\]*)'\]/g,$u={nodes:["run","nodes"],steps:["run","nodes"],trigger:["run","trigger"],foreach:["run","foreach"],state:["state"],var:["state"],vars:["state"],const:["consts"],consts:["consts"]};function Sn(e,t="javascript"){var c;const s=e.trim();if(!Iu.test(s))return null;const o=((c=/^[A-Za-z_$][\w$]*/.exec(s))==null?void 0:c[0])??"",r=$u[o];if(!r)return null;const a=[...r.slice(1)];for(const u of s.slice(o.length).matchAll(Ru))a.push(u[2]!==void 0?Number(u[2]):u[1]??u[3]??u[4]);const i=r[0]==="run"?a.shift():r[0];return`${t==="python"?"ctx":"$"}.get(${[i,...a].map(u=>JSON.stringify(u)).join(", ")})`}function _u(e,t="javascript"){const s=t==="python";let o="",r=0,a=0,i=0;for(const l of $a(e,t)){const c=Sn(l.ref,t);if(c===null){i++;continue}const u=l.context;if(u.kind==="code"){o+=e.slice(r,l.start)+c,r=l.end,a++;continue}const d=u.quote,f=l.start===u.start+d.length,p=l.end===u.end-d.length;if(f&&p)o+=e.slice(r,u.start)+c,r=u.end,a++;else if(!s&&d==="`")o+=`${e.slice(r,l.start)}\${${c}}`,r=l.end,a++;else if(d.length===1&&!(s&&/[A-Za-z]/.test(e[u.start-1]??""))){const m=s?`str(${c})`:c;o+=f?`${e.slice(r,u.start)}${m} + ${d}`:`${e.slice(r,l.start)}${d} + ${m}`,p?r=u.end:(f||(o+=` + ${d}`),r=l.end),a++}else i++}return o+=e.slice(r),{code:o,converted:a,left:i}}function Pu({param:e,value:t,language:s,label:o,req:r,readOnly:a,onChange:i}){var O;const l=b.useRef(null),[c,u]=b.useState(!1),d=nt(),f=b.useMemo(()=>pa(d),[d]),p=d.steps??[],m=s==="python",h=j=>{const N=l.current;if(!N){i(t+j);return}N.dispatch(N.state.replaceSelection(j)),N.focus()},w=j=>{const N=ht(j);if(N!==null){const k=Sn(N,s);k&&h(k);return}j===void 0||j===""||h(JSON.stringify(j,null,2).replace(/"\{\{\s*([^{}"]*?)\s*\}\}"/g,(k,_)=>Sn(_,s)??k))},g=((O=p[0])==null?void 0:O.id)??"<step-id>",y=m?"ctx":"$",x=[[`${y}.get("nodes", ${JSON.stringify(g)}, "output")`,"a step's output"],[`${y}.get("state", "region")`,"a workflow state value"],[`${y}.get("consts", "api_base")`,"a constant"]],S=Math.max(...x.map(([j])=>j.length)),A=m?"#":"//";return n.jsxs("div",{className:"w6w-field w6w-script-code",children:[n.jsxs("span",{children:[o,r]}),n.jsx(Zs,{value:t,readOnly:a,minHeight:"180px",language:s,scriptScope:f,"aria-label":`${e.key} code`,onChange:i,onCreateEditor:j=>{l.current=j}}),!a&&n.jsxs("div",{className:"w6w-seed-chips w6w-script-insert",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Insert"}),p.map(j=>{const N=Sn(`nodes[${JSON.stringify(j.id)}].output`,s)??"";return n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Insert ${N}`,onClick:()=>h(N),children:n.jsx("code",{children:j.id})},j.id)}),n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:"Pick a step field, variable or constant to insert as code","aria-label":`Insert a value into ${o}`,onClick:()=>u(!0),children:"ƒx"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),n.jsxs("details",{className:"w6w-script-help",children:[n.jsx("summary",{className:"w6w-muted w6w-small",children:"How to read data"}),n.jsx("pre",{className:"w6w-script-help-examples",children:x.map(([j,N])=>`${j.padEnd(S)} ${A} ${N}`).join(`
19
+ `)}),n.jsxs("span",{className:"w6w-hint",children:[n.jsx("code",{children:"input"})," is the same as ",n.jsx("code",{children:"run"})," unless you set Custom input."]}),n.jsx("span",{className:"w6w-hint",children:m?n.jsxs(n.Fragment,{children:["Use ",n.jsx("code",{children:"ctx.state"})," and ",n.jsx("code",{children:"ctx.nodes"})," directly, or"," ",n.jsx("code",{children:"ctx.get(root, *keys)"})," for literal keys. Missing paths return"," ",n.jsx("code",{children:"None"}),". Existing globals still work. Type a bracket or a key in"," ",n.jsx("code",{children:"ctx.get(...)"})," for suggestions, or press Ctrl+Space."]}):n.jsxs(n.Fragment,{children:["Use ",n.jsx("code",{children:"$.state"})," and ",n.jsx("code",{children:"$.nodes"})," directly, or"," ",n.jsx("code",{children:"$.get(root, ...keys)"})," for literal keys. Existing ",n.jsx("code",{children:"run"}),","," ",n.jsx("code",{children:"state"}),", ",n.jsx("code",{children:"vars"})," and ",n.jsx("code",{children:"consts"})," reads still work. Type a dot for suggestions, or press Ctrl+Space."]})})]}),c&&n.jsx(mn,{mode:"json-binding",value:void 0,jsonValue:void 0,options:d,fieldLabel:o,whole:!0,onSaveJson:w,onClose:()=>u(!1)})]})}function Gn(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...Gn(s.children));return t}function _a(e){return ct(e)||pt(e)?!0:typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"$")}function Ln(e){var t;return((t=e.config)==null?void 0:t.allowCustom)===!0}function Es(e){return Gn(e).filter(t=>Vn(t.options))}function ao(e){return Vn(e.options)?e.options.refreshOn??[]:[]}function Ts(e,t){const s={},o=[];for(const r of Gn(e)){if(r.type==="section")continue;const a=t[r.key]!==void 0?t[r.key]:r.default;a!==void 0&&(_a(a)?o.push(r.key):s[r.key]=a)}return{form:s,unresolved:o}}function Fu(e,t,s,o,r){const{form:a,unresolved:i}=Ts(e,t),l=new Set(i),c=Es(e).filter(d=>{const f=ao(d);return s==="change"&&!(o??[]).some(p=>f.includes(p))?!1:f.every(p=>!l.has(p))}).map(d=>d.key);if(c.length===0)return null;const u={reason:s,form:a,fields:c,unresolved:i};return s==="change"&&(u.changed=[...o??[]],u.previous=Ts(e,r??{}).form),u}function br(e,t,s){return JSON.stringify([e.appId,e.version??null,e.kind??"action",e.actionKey,e.connectionId??null,t.key,ao(t).map(o=>s[o]??null)])}function yr(e){return!(Vn(e.options)&&e.options.cache==="none")}function Lu(e,t){return e.some(s=>t.includes(s))}function Mu(e,t,s,o){var l;if(!o.connectionId)return{reason:"no-connection",hint:"Connect an account to load choices"};const r=new Set(Ts(t,s).unresolved),a=ao(e).find(c=>r.has(c));return a===void 0?null:{reason:"unresolved-dependency",hint:`Options unavailable while ${((l=Gn(t).find(c=>c.key===a))==null?void 0:l.label)??a} is an expression`}}function gr(e,t,s){return e==null||e===""?{action:"keep"}:_a(e)?{action:"keep"}:t.some(o=>o.value===e||String(o.value)===String(e))?{action:"keep"}:s.reason==="change"&&!s.allowCustom?{action:"clear"}:{action:"flag",message:`Not in the list returned by ${s.appLabel}`}}function Du(e,t,s,o){const r=Zt(),a=(s==null?void 0:s.kind)==="trigger"?r==null?void 0:r.resolveTriggerFields:r==null?void 0:r.resolveActionFields,i=!!(s&&a),[l,c]=b.useState({}),u=b.useRef({params:e,values:t,dynamic:s,onChange:o,resolve:a});u.current={params:e,values:t,dynamic:s,onChange:o,resolve:a};const d=b.useRef(new Map),f=b.useRef([]),p=b.useCallback((A,O,j,N,k)=>{const{params:_,values:U,dynamic:T,resolve:F}=u.current,E=k??U;if(!T||!F||!T.connectionId)return;const P=Fu(_,E,A,O,j);if(!P)return;const I=new Map(Es(_).map(M=>[M.key,M])),G=[],W={},$=[],R=T.appName??T.appId,z=(M,te)=>{const ee=I.get(M);if(!ee)return;gr(E[M],te,{allowCustom:Ln(ee),reason:A,appLabel:R}).action==="clear"&&G.push(M)};for(const M of P.fields){if(N!==void 0&&M!==N)continue;const te=I.get(M);if(!te)continue;const ee=N===void 0&&yr(te)?d.current.get(br(T,te,P.form)):void 0;ee?(W[M]={options:ee,loading:!1},z(M,ee)):$.push(M)}const K=(M=!1)=>{if(G.length===0)return;const te={...M?E:u.current.values};for(const ee of G)delete te[ee];u.current.onChange(te)};if(Object.keys(W).length>0&&c(M=>({...M,...W})),$.length===0){K(!0);return}for(const M of f.current)Lu(M.fields,$)&&M.controller.abort();const ne=new AbortController,B={fields:$,controller:ne};f.current=[...f.current.filter(M=>!M.controller.signal.aborted),B],c(M=>{var ee;const te={...M};for(const C of $)te[C]={options:(ee=M[C])==null?void 0:ee.options,loading:!0};return te});const Y={...P,fields:$,connectionId:T.connectionId,...T.version!==void 0?{version:T.version}:{}},J=M=>{f.current=f.current.filter(te=>te!==B),c(te=>({...te,...M}))};Promise.resolve().then(()=>F(T.appId,T.actionKey,Y,{signal:ne.signal})).then(M=>{var ee;if(ne.signal.aborted)return;const te={};for(const C of $){const V=(ee=M==null?void 0:M.fields)==null?void 0:ee[C],Q=I.get(C);if(!V||!Q)te[C]={loading:!1};else if(V.error)te[C]={loading:!1,error:V.error};else{const ae=Array.isArray(V.options)?V.options:[];te[C]={loading:!1,options:ae},yr(Q)&&d.current.set(br(T,Q,P.form),ae),z(C,ae)}}J(te),K()}).catch(M=>{if(ne.signal.aborted)return;const te=M instanceof Error?M.message:String(M),ee={};for(const C of $)ee[C]={loading:!1,error:te||"Request failed"};J(ee)})},[]),m=s?JSON.stringify([s.appId,s.actionKey,s.version,s.connectionId]):"";b.useEffect(()=>{if(i)return c({}),p("init"),()=>{for(const A of f.current)A.controller.abort();f.current=[]}},[m,i,p]);const h=b.useRef(new Map),w=b.useCallback((A,O)=>{const j=h.current.get(A)??u.current.values;h.current.delete(A),p("change",[A],j,void 0,{...u.current.values,[A]:O})},[p]),g=b.useCallback(A=>{h.current.has(A)||h.current.set(A,u.current.values)},[]),y=b.useCallback(A=>{const O=h.current.get(A);if(h.current.delete(A),!O)return;const j=u.current.values;JSON.stringify(O[A])!==JSON.stringify(j[A])&&p("change",[A],O)},[p]),x=b.useCallback(A=>p("init",void 0,void 0,A),[p]);return{fields:b.useMemo(()=>{const A={};if(!i||!s)return A;const O=s.appName??s.appId;for(const j of Es(e)){const N=Mu(j,e,t,s);if(N){A[j.key]={loading:!1,hint:N.hint};continue}const k=l[j.key]??{loading:!0},_={...k};if(k.options){const U=gr(t[j.key],k.options,{allowCustom:Ln(j),reason:"init",appLabel:O});U.action==="flag"&&(_.notInList=U.message)}A[j.key]=_}return A},[i,s,e,t,l]),commit:w,focus:g,blur:y,retry:x}}function wn(e,t){return e.hidden===!0?!1:e.showIf?ie.matchesParamCondition(e.showIf,t):!0}function Wt(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...Wt(s.children));return t}function un(e,t){const s=[];for(let o=0;o<e.length;){const r=e[o].row;if(r){const a=[];for(;o<e.length&&e[o].row===r;)a.push(e[o++]);s.push(n.jsx("div",{className:"w6w-field-row",children:a.map(t)},`row:${r}`))}else s.push(t(e[o])),o++}return s}function Pa(e,t,s,o){const r=a=>a.type==="section"?n.jsx(qu,{param:a,effective:s,renderOne:r},a.key):a.repeat&&a.type!=="array"?n.jsx(Bu,{param:a,value:e[a.key],onChange:t,readOnly:o},a.key):a.type==="group"&&a.children&&a.children.length>0?n.jsx(Hu,{param:a,value:e[a.key],onChange:t,effective:s,readOnly:o},a.key):n.jsx(zu,{param:a,value:e[a.key],onChange:t,effective:s,readOnly:o},a.key);return r}const Yn=b.createContext(null);function Ue({params:e,values:t,onChange:s,readOnly:o,dynamic:r}){const a=Du(e,t,r,s),i=Wt(e),l=m=>{var h;return t[m]!==void 0?t[m]:(h=i.find(w=>w.key===m))==null?void 0:h.default},c=e.filter(m=>wn(m,l)).map(m=>ie.effectiveParam(m,l)),u=c.filter(m=>m.required||!m.advanced),d=c.filter(m=>!m.required&&m.advanced),f=(m,h)=>{if(m==="language"){const w={...t,[m]:h};for(const g of i){if(g.type!=="code")continue;const y=t[g.key];(y===void 0||y===g.default||y===Os||Vu.includes(y))&&(w[g.key]=h==="python"?Os:g.default)}s(w);return}s({...t,[m]:h})};if(e.length===0)return n.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."});const p=Pa(t,f,l,o);return n.jsx(Yn.Provider,{value:a,children:n.jsxs("div",{className:"w6w-stack",children:[un(u,p),d.length>0&&n.jsxs("details",{className:"w6w-params-optional",children:[n.jsxs("summary",{className:"w6w-muted w6w-small",children:["Additional parameters (",d.length,")"]}),n.jsx("div",{className:"w6w-stack",style:{marginTop:8},children:un(d,p)})]})]})})}function qu({param:e,effective:t,renderOne:s}){const o=(e.children??[]).filter(r=>wn(r,t)).map(r=>ie.effectiveParam(r,t));return e.section==="collapsible"?n.jsxs("details",{className:"w6w-section",open:e.collapsed===!1||e.openWhenSet===!0&&o.some(r=>{const a=t(r.key);return a!=null&&a!==""}),children:[n.jsxs("summary",{className:"w6w-section-summary",children:[n.jsx("span",{className:"w6w-section-title",children:e.title??e.label??e.key}),e.subtitle&&n.jsx("span",{className:"w6w-section-subtitle",children:e.subtitle})]}),n.jsx("div",{className:"w6w-stack w6w-section-body",children:un(o,s)})]}):e.layout==="row"?n.jsx("div",{className:"w6w-field-row",children:o.map(s)}):n.jsx("div",{className:"w6w-stack",children:un(o,s)})}const Uu=new Set(["string","text","number","boolean","select"]);function Wu(e){return e.length>0&&e.every(t=>Uu.has(t.type)&&!t.children)}function Hu({param:e,value:t,onChange:s,effective:o,readOnly:r}){const a=e.children??[],i=t??{},l=(p,m)=>s(e.key,{...i,[p]:m}),c=Wt(a),u=p=>{const m=c.find(h=>h.key===p);return m?i[p]!==void 0?i[p]:m.default:o(p)},d=a.filter(p=>wn(p,u)).map(p=>ie.effectiveParam(p,u)),f=Pa(i,l,u,r);return n.jsx(Yn.Provider,{value:null,children:n.jsxs("div",{className:"w6w-stack",children:[n.jsx("span",{className:"w6w-section-title",children:e.label??e.key}),n.jsx("div",{className:"w6w-stack w6w-section-body",children:un(d,f)})]})})}function Bu({param:e,value:t,onChange:s,readOnly:o}){if(e.type==="group"){const a=e.children??[];if(!Wu(a))return n.jsx(io,{param:e,value:t,onChange:s,readOnly:o});const i={...e,item:{type:"object",fields:a}};return n.jsx(Is,{param:i,value:t,onChange:s,readOnly:o})}const r={...e,item:{type:e.type,options:Array.isArray(e.options)?e.options:void 0}};return n.jsx(Is,{param:r,value:t,onChange:s,readOnly:o})}const Os=`# Runs as a function body. Return the step's output.
20
+ return input`,Vu=["// Read `input` (bound under Input), plus `vars`, `consts` and `state.nodes.<step-id>.output`.\n// Runs as a function body. Return the step's output.\nreturn input;",'# Read `input` (bound under Input), plus `vars`, `consts` and `state["nodes"][<step-id>]["output"]`.\n# Runs as a function body. Return the step\'s output.\nreturn input',"// `input` holds the data bound under Input (e.g. an upstream step's output).\n// Runs as a function body. Return the step's output.\nreturn input;","# `input` holds the data bound under Input (e.g. an upstream step's output).\n# Runs as a function body. Return the step's output.\nreturn input"];function zu(e){const t=b.useContext(Yn),s=e.param.key;return n.jsx("div",{style:{display:"contents"},onFocusCapture:t?()=>t.focus(s):void 0,onBlurCapture:t?()=>t.blur(s):void 0,children:n.jsx(Ju,{...e})})}function Ju({param:e,value:t,onChange:s,effective:o,readOnly:r}){var O,j,N,k,_,U;const a=(O=Zt())==null?void 0:O.listModelRoutes,i=(j=Zt())==null?void 0:j.listDataStores,l=(N=Zt())==null?void 0:N.listAgents,c=(k=Zt())==null?void 0:k.listDataStoreEntries,u=Ys(),d=b.useContext(Yn),f=d==null?void 0:d.fields[e.key],p=(T,F)=>{s(T,F),d==null||d.commit(T,F)},m=s,h=e.label??e.key,w=e.required&&e.type!=="boolean"?" *":"",g=b.useId();if(e.type==="boolean"){const T=!!(t??e.default??!1);return n.jsx(Le,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,variant:"inline",controlId:g,children:n.jsx("input",{id:g,type:"checkbox",checked:T,disabled:r,onChange:F=>p(e.key,F.target.checked)})})}if(e.type==="json"||e.type==="group")return n.jsx(io,{param:e,value:t,onChange:m,readOnly:r});if(e.type==="code"){const T=o==null?void 0:o("language"),F=T==="python"||T==="javascript"||T==="typescript"?T:void 0,E=F==="python"?Os:e.default,P=t??E??"";return e.scriptReads?n.jsx(Pu,{param:e,value:String(P),language:T==="python"?"python":"javascript",label:h,req:w,readOnly:r,onChange:I=>m(e.key,I)}):n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[h,w]}),n.jsx(Zs,{value:String(P),readOnly:r,minHeight:"180px",language:F,"aria-label":`${e.key} code`,onChange:I=>m(e.key,I)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="model-route"&&a)return n.jsx(Ku,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,listModelRoutes:a,project:u});if(e.type==="agent"&&l)return n.jsx(Gu,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,listAgents:l});if(e.type==="data-store"&&i)return n.jsx(Yu,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,listDataStores:i,project:u});const y=o==null?void 0:o("store");if(e.type==="data-store-key"&&c&&typeof y=="string"&&y.trim()!=="")return n.jsx(ed,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,store:y,listDataStoreEntries:c,project:u});if(e.type==="vars")return n.jsx(cd,{param:e,value:t,onChange:m,readOnly:r});if(e.type==="text"||(_=e.config)!=null&&_.multiline){const T=t??e.default??"";return n.jsx(Le,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,children:n.jsx("textarea",{rows:3,value:String(T),readOnly:r,"aria-label":h,onChange:F=>m(e.key,F.target.value)})})}if(e.type==="multiselect")return n.jsx(td,{param:e,value:t,onChange:p,readOnly:r});if(e.type==="array")return n.jsx(Is,{param:e,value:t,onChange:m,readOnly:r});if(d&&f&&!f.hint)return n.jsx(xr,{param:e,value:t,onChange:p,readOnly:r,label:h,req:w,state:f,retry:()=>d.retry(e.key)});if(Array.isArray(e.options)&&e.options.length>0&&Ln(e))return n.jsx(xr,{param:e,value:t,onChange:p,readOnly:r,label:h,req:w,state:{loading:!1,options:e.options}});if(Array.isArray(e.options)&&e.options.length>0){const T=!e.required&&e.default===void 0&&typeof e.placeholder=="string"&&e.placeholder?e.placeholder:void 0,F=t??e.default??(T!==void 0?"":(U=e.options[0])==null?void 0:U.value)??"",E=e.type==="number";return n.jsx(Le,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,children:n.jsxs("select",{value:String(F),disabled:r,"aria-label":h,onChange:P=>{const I=P.target.value;T!==void 0&&I===""?p(e.key,void 0):p(e.key,E?Number(I):I)},children:[T!==void 0&&n.jsx("option",{value:"",children:T}),e.options.map(P=>n.jsx("option",{value:String(P.value),children:P.label},String(P.value)))]})})}if(e.type==="secret"){const T=t??e.default;return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[h,w]}),n.jsx(cn,{value:T,masked:!0,readOnly:r,"aria-label":h,onChange:F=>m(e.key,F)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const x=e.type==="number"?"number":"text",S=t??e.default??"",A=typeof S=="object"&&S!==null?JSON.stringify(S):String(S??"");return n.jsxs(Le,{param:e,value:t,onChange:m,readOnly:r,label:h,req:w,children:[n.jsx("input",{type:x,value:A,readOnly:r,"aria-label":h,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",onChange:T=>m(e.key,e.type==="number"?Number(T.target.value):T.target.value)}),(f==null?void 0:f.hint)&&n.jsx("span",{className:"w6w-hint",children:f.hint})]})}function xr({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,state:i,retry:l}){const c=t??e.default??"",u=typeof c=="string"||typeof c=="number"?String(c):"";return n.jsxs(Le,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:[n.jsx("div",{className:"w6w-fx-grow","aria-busy":i.loading?"true":"false",children:n.jsx(et,{mode:"combobox",forceSelection:!Ln(e),"aria-label":r,disabled:o,value:u,placeholder:i.loading?"Loading…":e.placeholder,options:(i.options??[]).map(d=>({value:String(d.value),label:d.label})),onChange:d=>s(e.key,d)})}),i.notInList&&n.jsx("span",{className:"w6w-hint",children:i.notInList}),i.error&&n.jsxs("span",{role:"alert",className:"w6w-hint",children:[i.error,l&&n.jsx("button",{type:"button",onClick:l,children:"Retry"})]})]})}function Ku({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,listModelRoutes:i,project:l}){const[c,u]=b.useState([]);b.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>i(l)).then(m=>p&&u(Array.isArray(m)?m:[])).catch(()=>p&&u([])),()=>{p=!1}},[i,l]);const d=t??e.default??"",f=typeof d=="string"?d:"";return n.jsx(Le,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(et,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:f,placeholder:"Select a route…",options:c.map(p=>({value:p.name,label:p.status==="broken"?`${p.name} (broken)`:p.name})),onChange:p=>s(e.key,p)})})}function Gu({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,listAgents:i}){const[l,c]=b.useState(null);b.useEffect(()=>{let w=!0;return Promise.resolve().then(()=>i()).then(g=>w&&c(Array.isArray(g)?g:[])).catch(()=>w&&c([])),()=>{w=!1}},[i]);const u=t??e.default??"",d=typeof u=="string"?u:"",f=l??[],p=f.find(w=>w.id===d),m=f.map(w=>({value:w.id,label:w.name||w.id}));d&&!p&&l!==null&&m.unshift({value:d,label:`${d} (not found)`});const h=l!==null&&f.length===0?n.jsx("span",{className:"w6w-muted w6w-small",children:"Create an agent in the Agents dashboard first."}):p!=null&&p.href?n.jsxs("a",{className:"w6w-small",href:p.href,target:"_blank",rel:"noreferrer",children:["Open ",p.name||p.id," in the Agents dashboard ↗"]}):null;return n.jsxs("div",{className:"w6w-agent-field",children:[n.jsx(Le,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(et,{mode:"combobox","aria-label":r,disabled:o,value:d,placeholder:l===null?"Loading agents…":f.length===0?"No agents yet":"Select an agent…",options:m,onChange:w=>s(e.key,w)})}),h]})}function Yu({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,listDataStores:i,project:l}){const[c,u]=b.useState([]);b.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>i(l)).then(m=>p&&u(Array.isArray(m)?m:[])).catch(()=>p&&u([])),()=>{p=!1}},[i,l]);const d=t??e.default??"",f=typeof d=="string"?d:"";return n.jsx(Le,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(et,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:f,placeholder:"Select a store…",options:c.map(p=>({value:p.name,label:`${p.name} (${p.kind})`})),onChange:p=>s(e.key,p)})})}const Xu=25,Zu=200,vr=60;function Qu(e){let t="";if(e.value!==void 0){try{t=typeof e.value=="string"?e.value:JSON.stringify(e.value)}catch{t=String(e.value)}t=t.replace(/\s+/g," "),t.length>vr&&(t=`${t.slice(0,vr-1)}…`)}const s=typeof e.updatedAt=="string"&&e.updatedAt.length>=16?`updated ${e.updatedAt.slice(0,16).replace("T"," ")}`:"";return[t,s].filter(Boolean).join(" · ")}function ed({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,store:i,listDataStoreEntries:l,project:c}){const[u,d]=b.useState(""),[f,p]=b.useState({items:[]}),[m,h]=b.useState(!0);b.useEffect(()=>{const x=new AbortController;h(!0);const S=u.trim(),A=setTimeout(()=>{Promise.resolve().then(()=>l(i,{project:c,prefix:S===""?void 0:S,limit:Xu,signal:x.signal})).then(O=>{x.signal.aborted||(p(O&&Array.isArray(O.items)?O:{items:[]}),h(!1))}).catch(()=>{x.signal.aborted||(p({items:[]}),h(!1))})},S===""?0:Zu);return()=>{clearTimeout(A),x.abort()}},[l,i,c,u]);const w=t??e.default??"",g=typeof w=="string"?w:"",y=u.trim();return n.jsx(Le,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(et,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:g,placeholder:"Search entries or type a key…",options:f.items.map(x=>({value:x.key,label:x.key,detail:Qu(x)||void 0})),onInputChange:d,emptyText:m?"Searching…":y!==""?`No key starts with "${y}" — Enter keeps it as typed`:"No entries in this store",footer:f.more?"More entries — type to narrow by key":void 0,onChange:x=>s(e.key,x)})})}function Le({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,bare:i,variant:l="boxed",controlId:c,children:u}){var y;const d=ct(t),f=e.type==="text"||!!((y=e.config)!=null&&y.multiline),[p,m]=b.useState(!1),h=nt(),w=l==="inline"&&!d,g=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:w?"w6w-fx-inline":`w6w-fx-wrap${d?" is-fx":""}`,children:d?n.jsx(cn,{value:t,multiline:f,readOnly:o,"aria-label":r,onChange:x=>s(e.key,x)}):n.jsxs(n.Fragment,{children:[u,!o&&n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${r}`,onClick:()=>m(!0),children:"ƒx"}),w&&n.jsxs("label",{className:"w6w-fx-inline-label",htmlFor:c,children:[r,a]})]})}),p&&n.jsx(mn,{value:t,multiline:f,options:h,fieldLabel:r,onSave:x=>s(e.key,x),onClose:()=>m(!1)})]});return i?g:n.jsxs("div",{className:"w6w-field",children:[!w&&n.jsxs("span",{children:[r,a]}),g,e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}function io({param:e,value:t,onChange:s,readOnly:o,headerActions:r,onValidityChange:a}){var U;const i=ht(t)??"",l=i!=="",c=t??e.default,[u,d]=b.useState(()=>l||c===void 0?"":JSON.stringify(c,null,2)),[f,p]=b.useState(!1),[m,h]=b.useState(!1),[w,g]=b.useState(!1),y=nt(),x=y.steps??[],S=(((U=y.stateShape)==null?void 0:U.fields.length)??0)>0;b.useEffect(()=>{if(l)return;let T;try{T=u.trim()===""?void 0:JSON.parse(u)}catch{T=void 0}JSON.stringify(T)!==JSON.stringify(c)&&(d(c===void 0?"":JSON.stringify(c,null,2)),p(!1))},[c,e.key,l]);const A=T=>{d(T)},O=T=>{p(!1),a==null||a(!0),s(e.key,T)},j=({valid:T,error:F})=>{if(a==null||a(T||F==="Empty"),!T&&F==="Empty"){p(!1),s(e.key,void 0);return}p(!T)},N=()=>{const T=Nu(u);T&&(p(!1),s(e.key,T))},k=e.label??e.key,_=()=>{let T;try{T=u.trim()===""?void 0:JSON.parse(u)}catch{T=void 0}s(e.key,T)};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[k,e.required?" *":""]}),r,!l&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${k} in full view`,onClick:()=>h(!0),children:n.jsx(le.Icon,{name:"maximize",size:14})})]}),l?n.jsx("div",{className:"w6w-fx-wrap is-fx w6w-json-binding",children:n.jsx("div",{className:"w6w-expr",children:n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{className:`w6w-expr-editor${o?" is-readonly":""}`,"data-testid":"json-binding-ref",children:n.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-var","data-kind":"var","data-ref":i,title:`Variable: ${i}`,children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"◆"}),n.jsx("span",{className:"w6w-expr-chip-label",children:Nt(i)}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-chip-x","aria-label":`Remove the reference from ${k}`,style:{border:0,padding:0,font:"inherit"},onClick:_,children:"×"})]})}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse step outputs, metadata & variables","aria-label":`Edit expression for ${k}`,onClick:()=>g(!0),children:"ƒx"})]})})}):n.jsx(Ze,{value:u,onChange:A,onBlur:N,readOnly:o,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:O,onValidityChange:j,overlay:o?void 0:n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${k}`,onClick:()=>g(!0),children:"ƒx"})}),w&&n.jsx(mn,{mode:"json-binding",value:void 0,jsonValue:t,options:y,fieldLabel:k,whole:e.whole,onSaveJson:T=>s(e.key,T),onClose:()=>g(!1)}),!l&&f&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"}),e.whole&&!l&&!o&&(x.length>0||S)&&n.jsxs("div",{className:"w6w-seed-chips w6w-json-quickbind",children:[S&&n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${k} to {{ state }}, the run state upstream steps wrote`,onClick:()=>s(e.key,"{{ state }}"),children:n.jsx("code",{children:"state"})}),x.length>0&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Use the output of"}),x.map(T=>n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${k} to {{ nodes.${T.id}.output }}`,onClick:()=>s(e.key,`{{ nodes.${T.id}.output }}`),children:n.jsx("code",{children:T.id})},T.id))]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),m&&!l&&n.jsxs(Ee,{title:k,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>h(!1),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(Ze,{value:u,onChange:A,readOnly:o,height:"100%",minHeight:"360px","aria-label":`${e.key} JSON (full view)`,onValidChange:O,onValidityChange:j})}),f&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function td({param:e,value:t,onChange:s,readOnly:o}){var y;const r=Array.isArray(e.options)?e.options:[],a=((y=e.config)==null?void 0:y.valueFormat)==="csv",i=t??e.default,l=Array.isArray(i)?i:a&&typeof i=="string"?i.split(",").map(x=>x.trim()).filter(Boolean):[],c=new Set(l.map(String)),u=r.filter(x=>!c.has(String(x.value))),d=x=>{var S;return((S=r.find(A=>String(A.value)===String(x)))==null?void 0:S.label)??String(x)},f=x=>s(e.key,a?x.join(","):x),p=x=>{if(!x||c.has(x))return;const S=r.find(A=>String(A.value)===x);f([...l,S?S.value:x])},m=x=>f(l.filter(S=>String(S)!==String(x))),h=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",w=e.label??e.key,g=e.required?" *":"";return n.jsx(Le,{param:e,value:t,onChange:s,readOnly:o,label:w,req:g,children:e.ui==="checkboxes"?n.jsxs("div",{className:"w6w-multiselect-checks w6w-fx-grow",children:[n.jsxs("div",{className:"w6w-multiselect-checks-toolbar",children:[n.jsxs("span",{className:"w6w-muted w6w-small",children:[l.length," selected"]}),!o&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:u.length===0,onClick:()=>f([...l,...u.map(x=>x.value)]),children:"Select all"}),n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:l.length===0,onClick:()=>f([]),children:"Clear"})]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":w,children:[...r,...l.filter(x=>!r.some(S=>String(S.value)===String(x))).map(x=>({value:x,label:String(x)}))].map(x=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:c.has(String(x.value)),disabled:o,onChange:S=>S.target.checked?p(String(x.value)):m(x.value)}),n.jsx("span",{children:x.label})]},String(x.value)))})]}):n.jsx(n.Fragment,{children:n.jsxs("div",{className:`w6w-multiselect${o?" is-readonly":""}`,children:[l.map(x=>n.jsxs("span",{className:"w6w-chip",children:[d(x),!o&&n.jsx("button",{type:"button",className:"w6w-chip-x","aria-label":`Remove ${d(x)}`,title:"Remove",onClick:()=>m(x),children:"×"})]},String(x))),!o&&n.jsxs("select",{className:"w6w-multiselect-add",value:"",disabled:u.length===0,"aria-label":`Add to ${e.label??e.key}`,onChange:x=>p(x.target.value),children:[n.jsx("option",{value:"",children:u.length>0?l.length?"Add more…":h:"All selected"}),u.map(x=>n.jsx("option",{value:String(x.value),children:x.label},String(x.value)))]})]})})})}function nd(e,t){if(t==null||t==="")return!0;const s=String(t);if(e==="boolean")return s==="true"||s==="false";if(e==="number")return s.trim()!==""&&Number.isFinite(Number(s));if(e==="json"){if(typeof t=="object")return!0;try{return JSON.parse(s),!0}catch{return!1}}return!0}function sd({label:e,value:t,onChange:s,readOnly:o}){const r=typeof t=="string"?t:t==null?"":JSON.stringify(t),[a,i]=b.useState(null),l=()=>{let d=r;try{d=r.trim()?JSON.stringify(JSON.parse(r),null,2):""}catch{}i(d)};let c=!1,u;if(a!==null)if(a.trim()==="")c=!0;else try{u=JSON.parse(a),c=!0}catch{}return n.jsxs("span",{className:"w6w-array-json",children:[n.jsx("input",{className:"w6w-array-input",type:"text",value:r.replace(/\r?\n\s*/g," "),placeholder:"JSON","aria-label":e,readOnly:!0,onClick:l,onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),l())}}),n.jsx("button",{type:"button",className:"w6w-array-x",title:"Open JSON editor","aria-label":`Open ${e} JSON editor`,onClick:l,children:n.jsx(le.Icon,{name:"maximize",size:14})}),a!==null&&n.jsxs(Ee,{title:e,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>i(null),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(Ze,{value:a,onChange:i,height:"100%",minHeight:"360px",readOnly:o,"aria-label":`${e} JSON editor`})}),!c&&n.jsx("p",{className:"w6w-field-error",role:"alert",children:"Invalid JSON"}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>i(null),children:o?"Close":"Cancel"}),!o&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:!c,onClick:()=>{c&&(s(a.trim()===""?"":JSON.stringify(u)),i(null))},children:"Apply"})]})]})]})}function od({field:e,value:t,row:s,onChange:o,readOnly:r}){var u,d;const a=e.placeholder??e.label??e.key,i=(u=e.config)==null?void 0:u.valueTypeFrom,l=e.label??e.key;if(i){const f=String((s==null?void 0:s[i])??"string");if(f==="boolean"){const p=t===!0||t==="true"?"true":t===!1||t==="false"?"false":"";return n.jsxs("select",{className:"w6w-array-input",value:p,disabled:r,"aria-label":l,onChange:m=>o(m.target.value),children:[n.jsx("option",{value:"",children:"(none)"}),n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]})}if(f==="json")return n.jsx(sd,{label:l,value:t,onChange:o,readOnly:r});if(f==="number")return n.jsx("input",{className:"w6w-array-input",type:"number",value:t==null?"":String(t),placeholder:a,"aria-label":l,readOnly:r,onChange:p=>o(p.target.value)})}if(Array.isArray(e.options)&&e.options.length>0)return n.jsx("select",{className:"w6w-array-input",value:String(t??e.default??((d=e.options[0])==null?void 0:d.value)??""),disabled:r,"aria-label":e.label??e.key,onChange:f=>o(f.target.value),children:e.options.map(f=>n.jsx("option",{value:String(f.value),children:f.label},String(f.value)))});if(e.type==="boolean")return n.jsxs("label",{className:"w6w-array-check",title:e.label??e.key,children:[n.jsx("input",{type:"checkbox",checked:!!(t??e.default??!1),disabled:r,"aria-label":e.label??e.key,onChange:f=>o(f.target.checked)}),n.jsx("span",{children:e.label??e.key})]});const c=e.type==="number";return n.jsx("input",{className:"w6w-array-input",type:c?"number":"text",value:String(t??e.default??""),placeholder:a,"aria-label":e.label??e.key,readOnly:r,onChange:f=>o(c?Number(f.target.value):f.target.value)})}function Is({param:e,value:t,onChange:s,readOnly:o}){const r=e.item??{type:"string"},a=r.type==="object",i=Array.isArray(t)?t:Array.isArray(e.default)?e.default:[],l=p=>s(e.key,p),c=()=>a?Object.fromEntries((r.fields??[]).map(p=>{var m;return[p.key,p.default??(p.type==="boolean"&&!((m=p.config)!=null&&m.valueTypeFrom)?!1:"")]})):r.type==="number"?0:r.type==="boolean"?!1:"",u=(p,m)=>l(i.map((h,w)=>w===p?m:h)),d=p=>{const h={...p??{}};for(const w of r.fields??[])h[w.key]===void 0&&(h[w.key]=w.default);return h},f=(p,m,h)=>{var g;const w={...p??{},[m]:h};for(const y of r.fields??[])((g=y.config)==null?void 0:g.valueTypeFrom)===m&&!nd(String(h??""),w[y.key])&&(w[y.key]="");return w};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),n.jsxs("div",{className:"w6w-array",children:[i.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"None yet — add one below."}),a&&i.length>0&&n.jsxs("div",{className:"w6w-array-head","aria-hidden":"true",children:[n.jsx("div",{className:"w6w-array-head-cells",children:(r.fields??[]).map(p=>p.type==="boolean"&&!(Array.isArray(p.options)&&p.options.length>0)?n.jsxs("span",{className:"w6w-array-check w6w-array-head-ghost",children:[n.jsx("span",{className:"w6w-array-head-box"}),n.jsx("span",{children:p.label??p.key})]},p.key):n.jsxs("span",{className:"w6w-array-head-cell",children:[p.label??p.key,p.required?" *":""]},p.key))}),!o&&n.jsx("span",{className:"w6w-array-x w6w-array-head-ghost"})]}),i.map((p,m)=>n.jsxs("div",{className:"w6w-array-row",children:[a?n.jsx("div",{className:"w6w-array-cells",children:(r.fields??[]).map(h=>n.jsx(od,{field:h,value:p==null?void 0:p[h.key],row:d(p),readOnly:o,onChange:w=>u(m,f(p,h.key,w))},h.key))}):n.jsx("input",{className:"w6w-array-input",type:r.type==="number"?"number":"text",value:String(p??""),placeholder:r.placeholder,readOnly:o,onChange:h=>u(m,r.type==="number"?Number(h.target.value):h.target.value)}),!o&&n.jsx("button",{type:"button",className:"w6w-array-x","aria-label":"Remove item",title:"Remove",onClick:()=>l(i.filter((h,w)=>w!==m)),children:"×"})]},m)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-array-add",onClick:()=>l([...i,c()]),children:"+ Add"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const rd=["string","number","boolean","json"],ad=[];function Mn(e,t=[]){return Array.isArray(e)?e.every(s=>s&&typeof s=="object"&&typeof s.key=="string")?e:null:!e||typeof e!="object"||ct(e)||ht(e)||"$expr"in e?null:Object.entries(e).map(([s,o])=>{const r=t.find(i=>i.key===s),a=typeof o;return{key:s,type:r&&JSON.stringify(r.value)===JSON.stringify(o)?r.type:a==="string"||a==="number"||a==="boolean"?a:"json",value:o}})}function id(e){const t=Array.isArray(e)?Mn(e):null;return!t||t.some(s=>!s.key)||new Set(t.map(s=>s.key)).size!==t.length?e:Object.fromEntries(t.map(s=>[s.key,s.value]))}function jr(e,t){if(e==="number"){if(t.trim()==="")return"";const s=Number(t);return Number.isNaN(s)?t:s}if(e==="boolean")return t==="true";if(e==="json")try{return JSON.parse(t)}catch{return t}return t}function kr(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Nr(e,t=!1){if(typeof e=="string"&&/^[\[{]/.test(e.trim()))try{JSON.parse(e)}catch{return e}return e===void 0?"":JSON.stringify(e,null,t?2:void 0)}function ld({param:e,value:t,label:s,onChange:o,readOnly:r}){const[a,i]=b.useState(null),l=()=>i(Nr(t,!0));let c=!1,u;if(a!==null)try{u=JSON.parse(a),c=!0}catch{}return n.jsxs(n.Fragment,{children:[n.jsxs(Le,{bare:!0,param:e,value:t,onChange:(d,f)=>o(f),readOnly:r,label:s,req:"",children:[n.jsx("input",{type:"text",className:"w6w-datavar-json-preview",value:Nr(t).replace(/\r?\n\s*/g," "),placeholder:"JSON value","aria-label":`${s} JSON preview`,readOnly:!0,onClick:l,onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),l())}}),n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Open JSON editor","aria-label":`Open ${s} JSON editor`,onClick:l,children:n.jsx(le.Icon,{name:"maximize",size:14})})]}),a!==null&&n.jsxs(Ee,{title:s,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>i(null),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(Ze,{value:a,onChange:i,height:"100%",minHeight:"360px",readOnly:r,"aria-label":`${s} JSON editor`})}),!c&&a.trim()&&n.jsx("p",{className:"w6w-field-error",role:"alert",children:"Invalid JSON"}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>i(null),children:r?"Close":"Cancel"}),!r&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:!c,onClick:()=>{c&&(o(u),i(null))},children:"Apply"})]})]})]})}function cd({param:e,value:t,onChange:s,readOnly:o}){const r=t??e.default??ad,a=b.useMemo(()=>id(r),[r]),[i,l]=b.useState(()=>Array.isArray(r)?"fields":"json"),c=b.useRef([]),[u,d]=b.useState(!1),[f,p]=b.useState(null),m=Mn(r,c.current),h=m??[],w=i==="json"||m===null,g=e.label??e.key,y=n.jsxs("div",{className:"w6w-view-toggle w6w-datavar-modes",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${w?"":" active"}`,"aria-label":`Edit ${g} as fields`,"aria-pressed":!w,disabled:u||!!f||m===null,title:m===null?"Use a literal JSON object to edit individual fields":"Edit individual fields",onClick:()=>{!o&&!Array.isArray(r)&&s(e.key,h),l("fields")},children:"Fields"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${w?" active":""}`,"aria-label":`Edit ${g} as JSON`,"aria-pressed":w,onClick:()=>{c.current=h,l("json")},children:"JSON"})]});if(w)return n.jsxs("div",{className:"w6w-datavar-json",children:[n.jsx(io,{param:{...e,type:"json",whole:!0,default:{},hint:"Enter a JSON object or use ƒx to bind one. Switch to Fields to edit individual values."},value:a,readOnly:o,headerActions:y,onValidityChange:A=>d(!A),onChange:(A,O)=>{if(O!==void 0&&Mn(O)===null&&!ht(O)&&!ct(O)&&!(O&&typeof O=="object"&&"$expr"in O)){p("Use a JSON object, a typed key/value array, or an object binding.");return}p(null),d(!1),s(A,O)}}),f&&n.jsx("span",{className:"w6w-hint w6w-datavar-error","aria-live":"polite",children:f})]});const x=A=>s(e.key,A),S=(A,O)=>x(h.map((j,N)=>N===A?{...j,...O}:j));return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[g,e.required?" *":""]}),y]}),n.jsxs("div",{className:"w6w-stack",children:[h.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No variables yet — add one below."}),h.length>0&&n.jsxs("div",{className:"w6w-datavar-head","aria-hidden":"true",children:[n.jsx("span",{children:"Key"}),n.jsx("span",{children:"Type"}),n.jsx("span",{children:"Value"}),!o&&n.jsx("span",{})]}),h.map((A,O)=>n.jsxs("div",{className:"w6w-datavar-row",children:[n.jsx("input",{type:"text",placeholder:"key","aria-label":"Variable key",value:A.key,readOnly:o,onChange:j=>S(O,{key:j.target.value})}),n.jsx("select",{value:A.type,"aria-label":"Variable type",disabled:o,onChange:j=>{const N=j.target.value;S(O,{type:N,value:jr(N,kr(A.value))})},children:rd.map(j=>n.jsx("option",{value:j,children:j},j))}),A.type==="json"?n.jsx(ld,{param:e,value:A.value,label:A.key||"value",onChange:j=>S(O,{value:j}),readOnly:o}):n.jsx(Le,{bare:!0,param:e,value:A.value,onChange:(j,N)=>S(O,{value:N}),readOnly:o,label:A.key||"value",req:"",children:A.type==="boolean"?n.jsxs("select",{value:A.value===!0?"true":"false",disabled:o,onChange:j=>S(O,{value:j.target.value==="true"}),children:[n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:A.type==="number"?"number":"text",placeholder:"value",value:kr(A.value),readOnly:o,onChange:j=>S(O,{value:jr(A.type,j.target.value)})})}),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Remove variable ${A.key||O+1}`,title:"Remove",onClick:()=>x(h.filter((j,N)=>N!==O)),children:"×"})]},O)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>x([...h,{key:"",type:"string",value:""}]),children:"+ Add variable"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const Rs={onCopy:e=>{Sr(e)},onCut:e=>{const t=Sr(e);if(!t)return;const s=e.currentTarget;typeof document.execCommand=="function"&&document.execCommand("delete")||(s.setRangeText("",t[0],t[1],"end"),s.dispatchEvent(new Event("input",{bubbles:!0})))}};function Sr(e){const t=e.currentTarget,s=t.selectionStart,o=t.selectionEnd;return s===null||o===null||s===o||!e.clipboardData?null:(e.clipboardData.setData("text/plain",t.value.slice(s,o)),e.preventDefault(),[s,o])}function Fa(e,t){const s={...t};for(const o of e){const r=t[o.key];if(!(o.type!=="json"||typeof r!="string"||r.trim()===""))try{s[o.key]=JSON.parse(r)}catch{return{error:`${o.label} is not valid JSON. Check it and try again.`}}}return{values:s}}function Cn({fields:e,values:t,onChange:s,enterSubmitProps:o,mode:r="create"}){const a=(i,l)=>s({...t,[i]:l});return n.jsxs("div",{className:"w6w-stack",children:[e.length===0&&n.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(i=>{const l=r==="edit",c=t[i.key]??(l?void 0:i.default)??"";if(i.type==="boolean")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:!!c,onChange:f=>a(i.key,f.target.checked),...o}),i.label,i.required?" *":""]}),i.hint&&n.jsx("span",{className:"w6w-hint",children:i.hint})]},i.key);const u=i.type==="secret"||i.secret===!0;if(i.type==="json"&&u&&!l)return n.jsx(La,{field:i,value:String(c??""),onChange:f=>a(i.key,f)},i.key);if(i.type==="json"||i.type==="text")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[i.label,i.required?" *":""]}),n.jsx("textarea",{className:u&&i.type!=="json"?"w6w-secret-input":void 0,...u&&i.type!=="json"?Rs:{},rows:i.type==="json"?6:3,value:String(c??""),placeholder:l&&u?"•••••• (unchanged)":void 0,onChange:f=>a(i.key,f.target.value),name:`w6w-cred-${i.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other"}),i.hint&&n.jsx("span",{className:"w6w-hint",children:i.hint})]},i.key);const d=i.type==="number"?"number":"text";return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[i.label,i.required?" *":""]}),n.jsx("input",{type:d,className:u?"w6w-secret-input":void 0,...u?Rs:{},value:String(c??""),placeholder:l&&u?"•••••• (unchanged)":void 0,onChange:f=>a(i.key,i.type==="number"&&!(l&&f.target.value==="")?Number(f.target.value):f.target.value),name:`w6w-cred-${i.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...o}),i.hint&&n.jsx("span",{className:"w6w-hint",children:i.hint})]},i.key)})]})}const ud=/(^|_)(private_key|secret|password|token)$/i,Cr=["client_email","client_id","project_id","private_key_id","private_key"],dd=["type","universe_domain"];function pd(e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object"||Array.isArray(t))return null;const s=o=>{const r=Cr.indexOf(o);return r===-1?Cr.length:r};return Object.entries(t).filter(([o,r])=>typeof r=="string"&&r!==""&&!/^https?:\/\//.test(r)&&!dd.includes(o)).sort(([o],[r])=>s(o)-s(r)).map(([o,r])=>({key:o,label:(o.charAt(0).toUpperCase()+o.slice(1)).replace(/_/g," "),value:r,secret:ud.test(o)}))}function La({field:e,value:t,onChange:s}){const o=b.useRef(null),r=t.trim()===""?null:pd(t),a=n.jsxs("span",{children:[e.label,e.required?" *":""]}),i=n.jsx("input",{ref:o,type:"file",accept:"application/json,.json",hidden:!0,onChange:async l=>{var u;const c=(u=l.target.files)==null?void 0:u[0];c&&s(await c.text()),l.target.value=""}});return r?n.jsxs("div",{className:"w6w-field",children:[a,n.jsxs("div",{className:"w6w-keyfile","data-testid":`keyfile-${e.key}`,children:[n.jsx("dl",{children:r.map(l=>n.jsxs("div",{children:[n.jsx("dt",{children:l.label}),n.jsx("dd",{children:l.secret?n.jsx("span",{className:"w6w-keyfile-secret",children:"•••••••• encrypted when you save"}):n.jsx("code",{children:l.value})})]},l.key))}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>s(""),children:"Use a different key"})]})]}):n.jsxs("div",{className:"w6w-field",children:[a,n.jsx("textarea",{className:"w6w-keyfile-paste",rows:4,value:t,"aria-label":e.label,placeholder:"Paste the key file's contents here",onChange:l=>s(l.target.value),name:`w6w-cred-${e.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other"}),n.jsxs("span",{className:"w6w-hint",children:[t.trim()!==""?"That isn't complete JSON yet. ":"","Paste the whole file, or"," ",n.jsx("button",{type:"button",className:"w6w-linkbtn",onClick:()=>{var l;return(l=o.current)==null?void 0:l.click()},children:"choose the .json file"}),"."]}),i]})}function Ma({auth:e,scopes:t=!0,clientId:s=""}){const o=e.serviceAccount;return n.jsxs(n.Fragment,{children:[e.description&&n.jsx("p",{className:"w6w-muted w6w-small",children:e.description}),e.setup&&e.setup.length>0?n.jsx(fd,{steps:e.setup}):null,t&&o&&o.scopes.length>0&&o.impersonation!=="none"?n.jsx(lo,{scopes:o.scopes,clientId:s,required:o.impersonation==="required"}):t&&o&&o.scopes.length>0?n.jsx(qa,{scopes:o.scopes}):null]})}function fd({steps:e}){return n.jsxs("details",{className:"w6w-auth-setup",children:[n.jsx("summary",{className:"w6w-auth-setup-title",children:"Where do I get this?"}),n.jsx("ol",{children:e.map(t=>n.jsxs("li",{children:[t.text,t.url&&/^https:\/\//.test(t.url)?n.jsxs(n.Fragment,{children:[" ",n.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",children:"Open ↗"})]}):null]},t.text))})]})}const hd="https://admin.google.com/ac/owl/domainwidedelegation";function Da(e){let t=e;if(typeof t=="string")try{t=JSON.parse(t)}catch{return""}const s=t&&typeof t=="object"?t.client_id:void 0;return typeof s=="string"||typeof s=="number"?String(s):""}function lo({scopes:e,clientId:t,required:s}){return n.jsxs("section",{className:"w6w-delegation","data-testid":"delegation-steps","aria-label":"Allow this key in Google Workspace",children:[n.jsx("h4",{children:s?"Allow this key in Google Workspace":"To act as a Workspace user"}),n.jsxs("ol",{children:[n.jsxs("li",{children:["Sign in to the Google Admin console as a Workspace admin and open"," ",n.jsx("strong",{children:"Security → Access and data control → API controls → Domain-wide delegation"}),"."," ",n.jsx("a",{href:hd,target:"_blank",rel:"noopener noreferrer",children:"Open ↗"})]}),n.jsxs("li",{children:["Click ",n.jsx("strong",{children:"Add new"})," and paste this Client ID:",t?n.jsx(Ar,{label:"Client ID",text:t}):n.jsxs("span",{className:"w6w-muted",children:[" ","the key's Client ID (",n.jsx("code",{children:"client_id"})," in the key file, also on the credential's page). It appears here once a key is chosen or pasted."]})]}),n.jsxs("li",{children:["Paste these OAuth scopes, exactly, then ",n.jsx("strong",{children:"Authorize"}),":",n.jsx(Ar,{label:"Scopes",text:e.join(",")})]}),n.jsx("li",{children:"Enter the Workspace user to act as below (an address in that Workspace, not a personal @gmail.com). Google can take a few minutes to apply a new delegation; if Save is refused right away, wait and try again."})]})]})}function Ar({label:e,text:t}){const[s,o]=b.useState(!1);return n.jsxs("div",{className:"w6w-scopes",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:e}),n.jsx("code",{children:t}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","aria-label":`Copy ${e}`,onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})},children:s?"Copied":"Copy"})]})}function qa({scopes:e}){const[t,s]=b.useState(!1),o=e.join(",");return n.jsxs("div",{className:"w6w-scopes",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Scopes"}),n.jsx("code",{children:o}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(o).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},children:t?"Copied":"Copy"})]})}function Ua({credentials:e,mode:t,onModeChange:s,selectedId:o,onSelect:r,canUseExisting:a=!0,contract:i}){return!a||e.length===0?null:n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("div",{className:"w6w-field",role:"radiogroup","aria-label":"Credential",children:[n.jsxs("span",{children:["Credential",i?` (${i})`:""]}),n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"w6w-credential-mode",checked:t==="existing",onChange:()=>s("existing")})," ","Use existing"]}),n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"w6w-credential-mode",checked:t==="new",onChange:()=>s("new")})," ","Enter new"]})]}),t==="existing"&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Stored credential"}),n.jsx("select",{name:"w6w-credential-id",value:o,onChange:l=>r(l.target.value),children:e.map(l=>n.jsx("option",{value:l.id,children:l.name},l.id))})]})]})}function Wa(e){const t=(e.bindingFields??[]).filter(r=>r.key!=="delegatedUser");return e.impersonation==="none"?t:[{...(e.bindingFields??[]).find(r=>r.key==="delegatedUser")??{type:"string"},key:"delegatedUser",label:"Workspace user to act as",type:"string",required:e.impersonation==="required"},...t]}function Ha(e,t){const s={},o={};for(const r of e){const a=t[r.key];a==null||a===""||(r.key==="delegatedUser"?s.delegatedUser=String(a):o[r.key]=a)}return Object.keys(o).length>0&&(s.settings=o),Object.keys(s).length>0?s:void 0}const md="width=560,height=720,menubar=no,toolbar=no,location=no";function Ba(e){return new Promise((t,s)=>{const o=window.open(e,"w6w-oauth",md);if(!o){s(new Error("Popup blocked — allow popups for this site and try again."));return}let r=!1;const a=()=>{r=!0,window.removeEventListener("message",i),window.clearInterval(l)},i=c=>{const u=c.data;if((u==null?void 0:u.w6w)==="oauth-result"){a();try{o.close()}catch{}u.ok&&typeof u.connectionId=="string"?t({connectionId:u.connectionId}):s(new Error(u.error??"OAuth flow failed."))}};window.addEventListener("message",i);const l=window.setInterval(()=>{r||o.closed&&(a(),s(new Error("OAuth popup was closed before the flow completed.")))},500)})}const wd=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function bd(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function Va(e,t){return{onKeyDown:s=>{if((t==null?void 0:t.enabled)===!1||s.key!=="Enter"||s.shiftKey||s.altKey||s.ctrlKey||s.metaKey||s.nativeEvent.isComposing)return;const o=s.target;o.tagName!=="TEXTAREA"&&(bd(o)||o.tagName==="INPUT"&&wd.has(o.type)||(s.preventDefault(),e()))}}}function co(e){const t=Ce(),[s,o]=b.useState(null),[r,a]=b.useState(!!e.initialAppId);return b.useEffect(()=>{const i=e.initialAppId;if(!i)return;let l=!1;const c=f=>{l||(o(f),a(!1))},u=t.listAppsByIds;if(u)return u([i]).then(f=>c(f.find(p=>p.id===i)??null)).catch(()=>c(null)),()=>{l=!0};const d=t.listApps;return typeof d=="function"?d().then(f=>c(f.find(p=>p.id===i)??null)).catch(()=>c(null)):c(null),()=>{l=!0}},[t,e.initialAppId]),s?n.jsx(Ee,{title:s.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:s.id}),s.version&&` · v${s.version}`]}),onClose:e.onClose,size:"xl",titleIcon:n.jsx(It,{src:s.iconSvg,srcDark:s.iconSvgDark,brandColor:s.brandColor,name:s.displayName,theme:e.theme,size:22}),headerRight:e.initialAppId?void 0:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>o(null),children:"← Apps"}),children:n.jsx(za,{app:s,onCreated:e.onCreated,onClose:e.onClose})}):r?n.jsx(Ee,{title:"Add connection",onClose:e.onClose,size:"xl",children:n.jsx("div",{className:"w6w-stepbuilder-content",children:n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"})})}):n.jsx(Ee,{title:"Add connection",onClose:e.onClose,size:"xl",children:n.jsx("div",{className:"w6w-stepbuilder-content",children:n.jsx(lt,{onSelectApp:o,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function za({app:e,onCreated:t,onClose:s}){var xe,ue;const o=Ce(),[r,a]=b.useState(null),[i,l]=b.useState(""),[c,u]=b.useState(""),[d,f]=b.useState({}),[p,m]=b.useState(null),[h,w]=b.useState(!1),[g,y]=b.useState(null),[x,S]=b.useState(null),[A,O]=b.useState(""),[j,N]=b.useState({}),[k,_]=b.useState("account"),[U,T]=b.useState(!0),[F,E]=b.useState(!1);b.useEffect(()=>{let D=!1;return a(null),o.getAppAuth(e.id).then(re=>!D&&a(re.filter(me=>me.available!==!1))).catch(re=>!D&&m(re.message)),()=>{D=!0}},[o,e.id]);const P=r??[],I=P.find(D=>D.key===i)??P.find(D=>D.default===!0)??P[0],G=(I==null?void 0:I.fields)??[],W=(I==null?void 0:I.type)==="oauth2",$=I==null?void 0:I.serviceAccount,R=(I==null?void 0:I.accepts)??($==null?void 0:$.accepts)??[],z=o.listCredentials,K=!W&&R.length>0&&typeof z=="function",ne=(g??[]).filter(D=>D.status==="active"&&!D.private&&D.accessScope!=="user"&&R.includes(D.contract)),B=(I==null?void 0:I.userScope)===!0&&!W&&(I==null?void 0:I.key)!=="zero-credential",Y=B&&k==="user",J=(I==null?void 0:I.refreshable)===!0&&(I==null?void 0:I.key)!=="zero-credential",M=J&&!U,te=Y||ne.length===0?"new":x??"existing",ee=ne.some(D=>D.id===A)?A:((xe=ne[0])==null?void 0:xe.id)??"",C=K&&$?Wa($):[],V=te==="existing"?((ue=ne.find(D=>D.id===ee))==null?void 0:ue.display.client_id)??"":Object.values(d).map(Da).find(Boolean)??"",Q=(I==null?void 0:I.key)??"";b.useEffect(()=>{if(!K||!z)return;let D=!1;return y(null),S(null),z.call(o,{appId:e.id,authKey:Q}).then(re=>!D&&y(re)).catch(()=>!D&&y([])),()=>{D=!0}},[o,e.id,K,Q,z]);const ae=(I==null?void 0:I.key)==="zero-credential",X=D=>D===void 0||D==="",ke=!W&&!ae&&(K?g===null||C.some(D=>D.required&&X(j[D.key]))||(te==="existing"?ee==="":G.some(D=>D.required&&X(d[D.key]))):G.some(D=>D.required&&X(d[D.key]))),be=!I||!W&&!ae&&ke||h;async function ye(){if(I){m(null),w(!0);try{if(ae)t({connectionId:`zerocred:${e.id}`});else if(W){const{authorizationUrl:D}=await o.startAppOAuthFlow(e.id,I.key,{displayName:c||void 0,...M?{autoRefresh:!1}:{}}),{connectionId:re}=await Ba(D);t({connectionId:re})}else if(K&&te==="existing"){const D=Ha(C,j),re={authKey:I.key,credentialId:ee,...D?{binding:D}:{},...c?{displayName:c}:{},...M?{autoRefresh:!1}:{}},me=await o.createConnection(e.id,re);t({connectionId:me.id})}else{const D=Fa(G,d);if("error"in D){m(D.error);return}let re=D.values;if($){re={};for(const Oe of C){const Ie=j[Oe.key];Ie==null||Ie===""||(re[Oe.key]=Oe.key==="delegatedUser"?String(Ie):Ie)}Object.assign(re,d)}const me=await o.createConnection(e.id,{authKey:I.key,credential:re,displayName:c||void 0,...Y?{accessScope:"user"}:{},...M?{autoRefresh:!1}:{}});t({connectionId:me.id})}}catch(D){m(D.message)}finally{w(!1)}}}const ge=Va(ye,{enabled:!be});return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[r===null&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading auth methods…"}),r!==null&&P.length===0&&n.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."}),P.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Auth method"}),n.jsx("select",{value:(I==null?void 0:I.key)??"",onChange:D=>{l(D.target.value),f({}),N({}),S(null),_("account"),T(!0),m(null)},children:P.map(D=>n.jsxs("option",{value:D.key,children:[D.displayName??D.key," (",D.type,")"]},D.key))})]}),I&&n.jsxs(n.Fragment,{children:[!ae&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Display name"}),n.jsx("input",{type:"text",value:c,onChange:D=>u(D.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",...ge})]}),n.jsx(Ma,{auth:I,scopes:!1}),ae?null:W?n.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",n.jsx("strong",{children:I.displayName??I.key})," to authorize this connection."]}):K?n.jsxs(n.Fragment,{children:[g===null&&!Y&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading credentials…"}),!Y&&n.jsx(Ua,{credentials:ne,mode:te,onModeChange:S,selectedId:ee,onSelect:O}),te==="existing"&&ne.length>0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Reusable credential · This account"}),te==="new"&&(g!==null||Y)&&n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"w6w-muted w6w-small",children:["Saved for this app only. One connection ·"," ",Y?"Only me":"This account"]}),n.jsx(Cn,{fields:G,values:d,onChange:f,enterSubmitProps:ge})]}),$&&$.scopes.length>0&&$.impersonation!=="none"?n.jsx(lo,{scopes:$.scopes,clientId:V,required:$.impersonation==="required"}):$&&$.scopes.length>0?n.jsx(qa,{scopes:$.scopes}):null,C.length>0&&n.jsx(Cn,{fields:C,values:j,onChange:N,enterSubmitProps:ge})]}):n.jsx(Cn,{fields:G,values:d,onChange:f,enterSubmitProps:ge})]}),(B||J)&&n.jsx(gd,{open:F,onToggle:()=>E(D=>!D),owner:B?{value:k,onChange:_}:void 0,keepConnected:J?{value:U,onChange:T}:void 0}),p&&n.jsx("div",{className:"w6w-result w6w-error",children:p})]})}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:be,onClick:ye,children:h?ae?"Saving…":W?"Waiting for authorization…":"Saving…":ae?"Use this":W?`Sign in with ${(I==null?void 0:I.displayName)??(I==null?void 0:I.key)??"provider"}`:"Save connection"})]})]})}const yd=[{value:"account",label:"This account",hint:"Everyone authorized in the account can use it."},{value:"user",label:"Only me",hint:"Only you can use it. Others in the account cannot."}];function gd({open:e,onToggle:t,owner:s,keepConnected:o}){const r=[(s==null?void 0:s.value)==="user"?"Only me":null,o&&!o.value?"Not kept connected":null].filter(Boolean);return n.jsxs("div",{className:"w6w-advanced","data-testid":"connection-advanced",children:[n.jsxs("button",{type:"button",className:"w6w-advanced-toggle","aria-expanded":e,"aria-controls":"w6w-connection-advanced-panel",onClick:t,children:["Advanced",!e&&r.length>0&&n.jsxs("span",{className:"w6w-muted",children:[" · ",r.join(" · ")]})]}),e&&n.jsxs("div",{id:"w6w-connection-advanced-panel",className:"w6w-advanced-panel",children:[s&&n.jsxs("div",{className:"w6w-advanced-group",role:"radiogroup","aria-label":"Who can use it",children:[n.jsx("span",{className:"w6w-advanced-label",children:"Who can use it"}),yd.map(a=>n.jsxs("label",{className:"w6w-radio",children:[n.jsx("input",{type:"radio",name:"w6w-connection-owner",value:a.value,checked:s.value===a.value,onChange:()=>s.onChange(a.value)}),n.jsxs("span",{children:[n.jsx("strong",{children:a.label}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ",a.hint]})]})]},a.value))]}),o&&n.jsxs("label",{className:"w6w-checkbox",children:[n.jsx("input",{type:"checkbox",name:"w6w-connection-keepalive",checked:o.value,onChange:a=>o.onChange(a.target.checked)}),n.jsxs("span",{children:[n.jsx("strong",{children:"Keep connected"}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","Refresh the token automatically, even when nothing uses this connection."]})]})]})]})]})}const xd=za,Ht=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),uo=[["is-true","is true"],["is-false","is false"],["has-value","has a value"],["is-empty","is empty"],["===","equals"],["!==","does not equal"],[">","greater than"],[">=","at least"],["<","less than"],["<=","at most"],["in","in"],["includes","includes value"],["include-any","includes any of (list)"],["include-all","includes all of (list)"]],vn={"has-value":"True when the field holds something: not missing, null, empty text, an empty list, 0 or false.","is-empty":"True when the field is missing, null, empty text or an empty list (0 and false count as empty too).",in:"The right array contains the left value.",includes:"Check whether a list contains one value, or text contains a substring.","include-any":"Compare two lists for any shared value. For one value on the right, use includes value.","include-all":"Compare two lists: every value in the right list must be in the left list."},Ja=new Set(uo.map(([e])=>e)),Ka=new Set(["is-true","is-false","has-value","is-empty"]),vd=new Set(["and","or","xor","!","!!","==","!=",...Ja]);function Er(e){if(!Ht(e))return!0;const t=Object.keys(e);return!(t.length===1&&vd.has(t[0]))}function Tr(e){return Ka.has(e)}const Or={...Object.fromEntries(uo),"==":"equals","!=":"does not equal",in:"is in"};function jd(e){return e.startsWith("not:")?`Not (${Or[e.slice(4)]??e.slice(4)})`:Or[e]??e}const Ga=[["and","All of (AND)"],["or","Any of (OR)"],["xor","Exactly one of (XOR)"]],Ya=Object.fromEntries(Ga);function kd(e){return Ya[e]??e}function po(e,t=!0){if(!Ht(e))return;const s=Object.entries(e);if(s.length!==1)return;const[o,r]=s[0];if(o==="!!"&&Array.isArray(r)&&r.length===1&&Er(r[0]))return{left:r[0],operator:"has-value",right:!0};if(o==="!"&&Array.isArray(r)&&r.length===1){const a=po(r[0],!1);return a?t&&!a.negated?{...a,negated:!0}:void 0:Er(r[0])?{left:r[0],operator:"is-empty",right:!0}:void 0}if(!(!Ja.has(o)||!Array.isArray(r)||r.length!==2)){if(o==="==="&&typeof r[1]=="boolean")return{left:r[0],operator:r[1]?"is-true":"is-false",right:r[1]};if(!Ka.has(o))return{left:r[0],operator:o,right:r[1]}}}function Nd(e){if(!(!Ht(e)||Object.keys(e).length!==1))return po(e.$expr)}function Sd(e){const t=Nd(e);if(t)return{combinator:"and",rows:[t]};if(!Ht(e)||Object.keys(e).length!==1||!Ht(e.$expr))return;const s=Object.entries(e.$expr);if(s.length!==1)return;const[o,r]=s[0];if(!Object.hasOwn(Ya,o)||!Array.isArray(r)||r.length===0)return;const a=r.map(i=>po(i));if(!a.some(i=>i===void 0))return{combinator:o,rows:a}}function Ir(e){const t=e.rows.filter(s=>s.left!=="").map(s=>{const o=s.operator==="is-true"||s.operator==="is-false"?{"===":[s.left,s.operator==="is-true"]}:s.operator==="has-value"?{"!!":[s.left]}:s.operator==="is-empty"?{"!":[s.left]}:{[s.operator]:[s.left,s.right]};return s.negated?{"!":[o]}:o});return t.length===0?!1:{$expr:t.length===1?t[0]:{[e.combinator]:t}}}function $s(e){if(typeof e=="string")try{const s=JSON.parse(e);if(s===null||Array.isArray(s)||["string","number","boolean"].includes(typeof s))return s}catch{}const t=typeof e=="string"?Jn(e):tt(e)?e.parts:null;if(t){const s=t.map(o=>o.kind==="expr"?o.expr:o.kind==="var"?{var:o.ref}:o.kind==="secret"?{var:`secrets.${o.ref}`}:o.value??"");return s.length===1?s[0]:{cat:s}}return e}function Rr(e){return typeof e=="string"?$s(e)===e?e:JSON.stringify(e):Ht(e)?Object.keys(e).length===1&&typeof e.var=="string"?ie.serializeTemplate([{kind:"var",ref:e.var}]):ie.serializeTemplate([{kind:"expr",expr:e}]):JSON.stringify(e)??""}const Xa={left:"",operator:"is-true",right:!0},$r={combinator:"and",rows:[Xa]},Cd=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function Xn({values:e,onChange:t,readOnly:s,purpose:o="if"}){const r=nt(),a=e.condition===void 0?!0:e.condition,i=Sd(a),[l,c]=b.useState(!1),[u,d]=b.useState(i??$r),f=b.useRef(0),[p,m]=b.useState(()=>u.rows.map(()=>f.current++)),h=i!==void 0||typeof a=="boolean",w=Cd(Ir(u),a)?u:i??$r,g=w.rows.map((j,N)=>p[N]??-1-N),y=(j,N=g)=>{d(j),m(N),t({...e,condition:Ir(j)})},x=(j,N)=>y({...w,rows:w.rows.map((k,_)=>_===j?{...k,...N}:k)}),S=()=>y({...w,rows:[...w.rows,Xa]},[...g,f.current++]),A=j=>y({...w,rows:w.rows.filter((N,k)=>k!==j)},g.filter((N,k)=>k!==j)),O=w.rows.length>1;return n.jsxs("div",{className:"w6w-condition-editor",children:[l||!h?n.jsx(Ue,{params:[{key:"condition",label:"Condition",type:"json",required:!0}],values:e,onChange:t,readOnly:s}):n.jsxs("div",{className:"w6w-condition-rows",children:[O&&n.jsx("select",{className:"w6w-condition-comparison w6w-condition-combinator","aria-label":"Combine conditions",disabled:s,value:w.combinator,onChange:j=>y({...w,combinator:j.target.value}),children:Ga.map(([j,N])=>n.jsx("option",{value:j,children:N},j))}),w.rows.map((j,N)=>{const k=Tr(j.operator);return n.jsxs("div",{className:`w6w-condition-row${O?" w6w-condition-row-removable":""}${k?" w6w-condition-row-boolean":""}`,children:[n.jsxs("label",{className:"w6w-condition-negate",title:"Reverse this condition's result",children:[n.jsx("input",{type:"checkbox","aria-label":`Negate condition ${N+1}`,checked:j.negated??!1,disabled:s,onChange:_=>x(N,{negated:_.target.checked})}),"Not"]}),n.jsx(cn,{value:Rr(j.left),"aria-label":"Condition field",placeholder:"Field or expression",readOnly:s,onChange:_=>x(N,{left:$s(_)})}),n.jsx("select",{className:"w6w-condition-comparison","aria-label":"Condition comparison",title:vn[j.operator],disabled:s,value:j.operator,onChange:_=>x(N,{operator:_.target.value,right:_.target.value==="is-true"?!0:_.target.value==="is-false"?!1:Tr(_.target.value)?!0:k?"":j.right}),children:uo.map(([_,U])=>n.jsx("option",{value:_,title:vn[_],children:U},_))}),!k&&n.jsx(cn,{value:Rr(j.right),"aria-label":"Condition value",placeholder:"Value or expression",readOnly:s,onChange:_=>x(N,{right:$s(_)})}),O&&!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-remove",title:"Remove condition","aria-label":`Remove condition ${N+1}`,onClick:()=>A(N),children:n.jsx(le.Icon,{name:"trash",size:14})})]},g[N])}),!s&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-condition-add",onClick:S,children:"+ Add condition"}),n.jsx("p",{className:"w6w-muted w6w-small",children:"Not reverses a condition. Type true or false without quotes for booleans; use quotes for text."}),[...new Set(w.rows.map(j=>j.operator))].map(j=>vn[j]?n.jsx("p",{className:"w6w-muted w6w-small",children:vn[j]},j):null)]}),h&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-mode",title:l?"Use comparison fields":"Edit condition expression","aria-label":l?"Use comparison fields":"Edit condition expression",onClick:()=>c(!l),children:n.jsx(le.Icon,{name:l?"form":"code",size:14})}),o!=="router"&&n.jsx("p",{className:"w6w-muted w6w-small",children:o==="stop"?"End the workflow when this condition is true.":r.loop?"When false, skip the remaining steps for this item.":"Continue when this condition is true."})]})}const Ad={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 Za({value:e,onChange:t,readOnly:s,target:o="step"}){const r=!!e,a=(e==null?void 0:e.maxAttempts)??3,i=(e==null?void 0:e.delayMs)??1e3,l=(e==null?void 0:e.backoff)??"fixed",c=u=>t({maxAttempts:a,delayMs:i,backoff:l,...e,...u});return n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:r,disabled:s,onChange:u=>t(u.target.checked?{maxAttempts:a,delayMs:i,backoff:l}:void 0)})," ","Retry on failure"]}),n.jsx("span",{className:"w6w-hint",children:Ad[o]})]}),r&&n.jsxs("div",{className:"w6w-field-row",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Attempts"}),n.jsx("input",{type:"number",min:1,value:a,readOnly:s,onChange:u=>c({maxAttempts:Math.max(1,Number(u.target.value)||1)})})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Delay (ms)"}),n.jsx("input",{type:"number",min:0,value:i,readOnly:s,onChange:u=>c({delayMs:Math.max(0,Number(u.target.value)||0)})})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Backoff"}),n.jsxs("select",{value:l,disabled:s,onChange:u=>c({backoff:u.target.value}),children:[n.jsx("option",{value:"fixed",children:"Fixed"}),n.jsx("option",{value:"exponential",children:"Exponential"})]})]})]})]})}function Qa({config:e,onChange:t,readOnly:s,hasGraph:o=!0,failureHandling:r=!0,retryControls:a=!0,timeoutControl:i=a,reroute:l}){const c=e.onError??"fail";return n.jsxs("div",{className:"w6w-stack",children:[r&&n.jsxs(n.Fragment,{children:[a&&n.jsx(Za,{value:e.retry,onChange:u=>t({...e,retry:u}),readOnly:s}),i&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Timeout (seconds)"}),n.jsx("input",{type:"number",min:1,max:280,step:1,placeholder:"120",value:e.timeoutMs===void 0?"":e.timeoutMs/1e3,disabled:s,onChange:u=>{const d=u.target.valueAsNumber;t({...e,timeoutMs:u.target.value===""||!Number.isFinite(d)?void 0:Math.round(d*1e3)})}}),n.jsx("span",{className:"w6w-hint",children:"How long this step waits for the app before it fails. Default 120 seconds; up to 280."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"On error"}),n.jsxs("select",{value:c,disabled:s,onChange:u=>{const d=u.target.value;t({...e,onError:d==="fail"?void 0:d})},children:[n.jsx("option",{value:"fail",children:"Stop the run (default)"}),n.jsx("option",{value:"continue",children:"Continue to the next step"}),o&&n.jsx("option",{value:"continue-record",children:"Continue to the next step & record the error"})]}),o?n.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, ",n.jsx("strong",{children:"Continue"})," and"," ",n.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"," ",n.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."]}):n.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 ",n.jsx("strong",{children:"reroute"})," target below to send a failure somewhere else instead of stopping."]})]})]}),l&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Reroute on failure"}),n.jsxs("div",{className:"w6w-field-row",children:[l.picker,l.value&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:s,onClick:()=>l.onChange(void 0),children:"Clear"})]}),n.jsx("span",{className:"w6w-hint",children:"Invoked once, after retry is exhausted, if this step still fails; its output becomes this step's output."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Notes"}),n.jsx("textarea",{rows:3,value:e.notes??"",readOnly:s,placeholder:"A short description — shown under this step on the canvas. Not executed.",onChange:u=>t({...e,notes:u.target.value||void 0})})]})]})}function Zn(e){return e.$merge!==void 0}function ei(e){const t=e.$merge;if(t===void 0)return e;if(!(ht(t)||tt(t)||to(t)||typeof t=="string"&&Jn(t)))return t&&typeof t=="object"&&!Array.isArray(t)&&!pt(t)&&!("$merge"in t)?{...e,...t}:null}function ti(e,t,s=[]){if(tt(e)||pt(e)||eo(e)||to(e)||e===null||typeof e!="object")return an(e,t);const o=r=>ti(r,t);return Array.isArray(e)?e.map(o):Object.fromEntries(Object.entries(e).map(([r,a])=>[r,s.includes(r)?a:o(a)]))}function fo({values:e,onChange:t,readOnly:s}){return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Form values are applied first. This object adds or replaces top-level fields, including nested objects. Use ƒx to reuse an object from state or a previous step. You can still edit the form."}),n.jsx(Ue,{params:[{key:"$merge",label:"JSON customization",type:"json",required:!0,default:{},whole:!0}],values:e,onChange:t,readOnly:s}),ei(e)===null&&n.jsx("p",{role:"alert",className:"w6w-field-error",children:"JSON customization must be an object or an expression that returns an object."}),!s&&Zn(e)&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{const{$merge:o,...r}=e;t(r)},children:"Remove JSON customization"})]})}function ho(e){const{label:t,onClick:s,disabled:o,className:r,...a}=e;return n.jsx(Kn,{label:t,onClick:s,disabled:o,className:r,danger:!0,icon:"delete","data-testid":a["data-testid"]})}function ni({values:e,onChange:t,readOnly:s}){const o=Array.isArray(e.routes)?e.routes:Pn(Qe,"route").routes,r=o.filter(y=>!y.default),[a,i]=b.useState(null),[l,c]=b.useState(null),[u,d]=b.useState(null),[f,p]=b.useState(""),m=y=>t({...e,routes:[...y,...o.filter(x=>x.default)]}),h=(y,x)=>m(r.map(S=>S.id===y?{...S,...x}:S)),w=(y,x)=>{const S=r.findIndex(j=>j.id===y);if(S<0||x<0||x>=r.length||S===x)return;const A=[...r],[O]=A.splice(S,1);A.splice(x,0,O),m(A)},g=y=>{f.trim()&&h(y.id,{label:f.trim()}),d(null)};return n.jsxs("div",{className:"w6w-router-editor",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"First match wins. Drag routes to change their order."}),n.jsx("div",{className:"w6w-router-routes",children:r.map((y,x)=>n.jsxs("div",{className:`w6w-router-route${a===y.id?" is-dragging":""}${l===y.id?" is-drop-target":""}`,"data-route-id":y.id,onDragOver:S=>{s||!a||a===y.id||(S.preventDefault(),S.dataTransfer.dropEffect="move",c(y.id))},onDrop:S=>{S.preventDefault(),!s&&a&&w(a,x),i(null),c(null)},children:[n.jsxs("div",{className:"w6w-router-route-heading",children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-router-grip",draggable:!s,disabled:s,"aria-label":`Reorder ${y.label||y.id}`,title:"Drag to reorder · arrow keys to move",onDragStart:S=>{S.dataTransfer.effectAllowed="move",S.dataTransfer.setData("text/plain",y.id);const A=S.currentTarget.closest(".w6w-router-route");A&&S.dataTransfer.setDragImage(A,16,16),i(y.id)},onDragEnd:()=>{i(null),c(null)},onKeyDown:S=>{S.key!=="ArrowUp"&&S.key!=="ArrowDown"||(S.preventDefault(),w(y.id,x+(S.key==="ArrowUp"?-1:1)))},children:n.jsx(le.Icon,{name:"grip",size:14})}),n.jsx("span",{className:"w6w-step-rename",children:u===y.id&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Route name",value:f,onChange:S=>p(S.target.value),onBlur:()=>g(y),onKeyDown:S=>{S.key==="Enter"&&g(y),S.key==="Escape"&&d(null)}}):n.jsxs("button",{type:"button",className:"w6w-router-route-name",disabled:s,"aria-label":`Rename ${y.label||y.id}`,onClick:()=>{p(y.label||y.id),d(y.id)},children:[y.label||y.id,!s&&n.jsx(le.Icon,{name:"edit",size:12})]})}),n.jsx(ho,{label:`Remove ${y.label||y.id}`,disabled:s,onClick:()=>m(r.filter(S=>S.id!==y.id))})]}),n.jsx(Xn,{values:{condition:y.condition??!1},onChange:S=>h(y.id,{condition:S.condition}),readOnly:s,purpose:"router"})]},y.id))}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",disabled:s,onClick:()=>{let y=1;for(;o.some(x=>x.id===`route_${y}`);)y++;m([...r,{id:`route_${y}`,label:`Route ${y}`,condition:!1}])},children:[n.jsx("span",{"aria-hidden":"true",children:"+"})," Add route"]})]})}function si({value:e,onCommit:t,readOnly:s}){const[o,r]=b.useState(!1),[a,i]=b.useState(e),[l,c]=b.useState(null),u=()=>{const d=a.trim(),f=d&&d!==e?t(d):null;if(f){c(f);return}c(null),r(!1)};return n.jsxs("span",{className:"w6w-step-rename",children:[o&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Node name",value:a,onChange:d=>{i(d.target.value),c(null)},onBlur:u,onKeyDown:d=>{d.key==="Enter"&&u(),d.key==="Escape"&&(i(e),c(null),r(!1))}}):n.jsxs(n.Fragment,{children:[n.jsx("code",{children:e}),!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Rename node","aria-label":"Rename node",onClick:()=>{i(e),r(!0)},children:n.jsx(le.Icon,{name:"edit",size:15})})]}),l&&n.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:l})]})}function oi({values:e,onChange:t,readOnly:s}){const o=e.condition!==void 0&&e.condition!==!0;return n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Stop when"}),n.jsxs("select",{"aria-label":"Stop when",disabled:s,value:o?"condition":"always",onChange:r=>{const a=r.target.value==="condition";t({...e,condition:!a})},children:[n.jsx("option",{value:"always",children:"Always"}),n.jsx("option",{value:"condition",children:"A condition matches"})]})]}),o?n.jsx(Xn,{values:e,onChange:t,readOnly:s,purpose:"stop"}):n.jsx("p",{className:"w6w-muted w6w-small",children:"End the whole workflow successfully here, including any remaining loop iterations."})]})}const Ed=["props","code"];function Td(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ri({params:e,values:t,onChange:s,onValidityChange:o,readOnly:r,initialView:a="props"}){const i=e.length>0,[l,c]=b.useState(a),u=!i||l==="code",[d,f]=b.useState(()=>_r(t)),[p,m]=b.useState(!0),h=b.useRef(!0),w=x=>{x!==h.current&&(h.current=x,m(x),o==null||o(x))},g=x=>{x==="code"&&f(_r(t)),w(!0),c(x)},y=i?"Values (JSON)":"Payload";return n.jsxs("div",{className:"w6w-stack",children:[i&&n.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:n.jsx(ts,{view:l,views:[...Ed],onChange:x=>g(x)})}),u?n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:y}),n.jsx(Ze,{value:d,onChange:f,readOnly:r,minHeight:"140px","aria-label":`${y} JSON`,onValidChange:x=>{const S=Td(x);w(S),S&&s(x)},onValidityChange:x=>{x.valid||w(!1)}}),!p&&n.jsx("span",{className:"w6w-hint",children:"This draft isn’t a JSON object yet — the collected values are unchanged until it is."})]}):n.jsx(Ue,{params:e,values:t,onChange:s,readOnly:r})]})}function _r(e){return JSON.stringify(e??{},null,2)}function Od(e){return e===null||typeof e!="object"||Array.isArray(e)?null:e}function ai({app:e,trigger:t,onUse:s}){const o=Ce(),[r,a]=b.useState(null);return b.useEffect(()=>{var l;let i=!1;return a(null),(l=o.getAppTriggers)==null||l.call(o,e).then(c=>{var u;i||a(Od((u=c.find(d=>d.key===t))==null?void 0:u.sample))}).catch(()=>{}),()=>{i=!0}},[o,e,t]),r?n.jsx("div",{children:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","data-testid":"use-trigger-sample",onClick:()=>s(r),children:"Use sample event"})}):null}const Id=new Set(["http:","https:","mailto:"]);function Rd(e){try{return Id.has(new URL(e).protocol)?e:""}catch{return""}}const $d=["img"];function _d({node:e,href:t,children:s,...o}){return n.jsx("a",{...o,href:t||void 0,target:"_blank",rel:"noopener noreferrer nofollow",children:s})}function ii(e){const t=/^\uFEFF?---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(e);return t?{frontmatter:t[1],body:e.slice(t[0].length)}:{frontmatter:null,body:e}}function Pd({yaml:e}){return n.jsxs("details",{className:"w6w-md-frontmatter","data-testid":"md-frontmatter",children:[n.jsx("summary",{children:"Frontmatter"}),n.jsx("pre",{children:n.jsx("code",{children:e})})]})}function mo({content:e,className:t,copyable:s=!0}){const{frontmatter:o,body:r}=ii(e),a=n.jsxs("div",{className:t,children:[(o==null?void 0:o.trim())&&n.jsx(Pd,{yaml:o}),n.jsx(pl,{skipHtml:!0,urlTransform:Rd,disallowedElements:$d,unwrapDisallowed:!0,components:{a:_d},children:r})]});return s?n.jsx(le.Copyable,{value:e,label:"Copy Markdown",className:"w6w-copyable--document",children:a}):a}const Pr="w6w-data-table-actions";function Fd(e,t){return e.render?e.render(t):String(t[e.key]??"")}function li(e){const{columns:t,rows:s,rowKey:o,onRowClick:r,getRowHref:a,empty:i,loading:l,className:c,testId:u}=e;return s.length===0&&!l&&i!==void 0&&i!==null?n.jsx(n.Fragment,{children:i}):n.jsx("div",{className:"w6w-data-table-frame",children:n.jsxs("table",{className:c?`w6w-data-table ${c}`:"w6w-data-table","data-testid":u,"aria-busy":l?!0:void 0,children:[n.jsx("thead",{children:n.jsx("tr",{children:t.map(d=>n.jsx("th",{className:d.actions?Pr:void 0,style:{width:d.width,textAlign:d.align},scope:"col",children:d.header},d.key))})}),n.jsx("tbody",{children:s.map(d=>{var p;const f=a==null?void 0:a(d);return n.jsx("tr",{"data-testid":(p=e.rowTestId)==null?void 0:p.call(e,d),className:r?"w6w-data-table-row-clickable":void 0,onClick:r?m=>r(d,m):void 0,children:t.map(m=>{const h=Fd(m,d);return n.jsx("td",{className:m.actions?Pr:void 0,style:{textAlign:m.align},children:f!==void 0&&m.link!==!1?n.jsx("a",{className:"w6w-data-table-link",href:f,children:h}):m.actions&&h!==null&&h!==void 0?n.jsx("div",{className:"w6w-data-table-actions-row",children:h}):h},m.key)})},o(d))})})]})})}const ci="default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'";function ui(e){return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${ci}">${e}`}function di({html:e}){return n.jsx("iframe",{title:"HTML preview",className:"w6w-html-preview",sandbox:"",referrerPolicy:"no-referrer",srcDoc:ui(e)})}function pi(e){return typeof e=="string"?"string":typeof e=="number"?"number":typeof e=="boolean"?"boolean":"null"}function Ld(e){return pi(e)==="string"?JSON.stringify(e):String(e)}function Md(e){return typeof e=="object"&&e!==null}function Dd(e,t){return`${t} ${e?"item":"key"}${t===1?"":"s"}`}function qd({value:e,expandDepth:t=2}){return n.jsx(fi,{label:void 0,value:e,depth:0,expandDepth:t})}function fi(e){const{label:t,value:s,depth:o,expandDepth:r}=e,a=Md(s),i=Array.isArray(s),l=a?i?s.map((u,d)=>[d,u]):Object.entries(s):[],c=t===void 0?null:n.jsx("span",{className:"w6w-json-key",children:t});return a&&l.length>0?n.jsxs("details",{className:"w6w-json-node",open:o<r,children:[n.jsxs("summary",{children:[c,i?"[…]":"{…}"," ",n.jsx("span",{className:"w6w-json-count",children:Dd(i,l.length)})]}),n.jsx("div",{className:"w6w-json-children",children:l.map(([u,d])=>n.jsx(fi,{label:u,value:d,depth:o+1,expandDepth:r},String(u)))})]}):n.jsxs("div",{className:"w6w-json-leaf",children:[c,c===null?null:": ",n.jsx("span",{className:`w6w-json-${a?"null":pi(s)}`,children:a?i?"[]":"{}":Ld(s)})]})}const _s=262144,Ud=/^#{1,6}\s+\S/,Wd=/^```/,Hd=/^\s*(?:[-*+]|\d+\.)\s+\S/,Bd=/\[[^\]\n]+\]\(https?:\/\/[^)\s]+\)/;function hi(e){if(e===void 0)return{format:"text",text:""};if(typeof e!="string")return{format:"json",data:e};const t=e.trim();if(t.startsWith("{")||t.startsWith("["))try{const o=JSON.parse(t);if(o!==null&&typeof o=="object")return{format:"json",data:o}}catch{}if(/^<!doctype html/i.test(t)||/^<html[\s>]/i.test(t))return{format:"html",text:e};if(t.startsWith("<")&&t.endsWith(">"))return{format:"xml",text:e};const s=t.split(`
21
+ `);return s.some(o=>Ud.test(o)||Wd.test(o))||s.filter(o=>Hd.test(o)).length>=2||Bd.test(t)?{format:"markdown",text:e}:{format:"text",text:e}}function mi(e){return e.format==="json"?JSON.stringify(e.data,null,2)??"":e.text}function Fr(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Vd(e){if(!Fr(e))return!1;const t=Object.keys(e);if(t.length!==2||!t.includes("columns")||!t.includes("rows"))return!1;const{columns:s,rows:o}=e;return Array.isArray(s)&&s.every(r=>typeof r=="string")&&Array.isArray(o)&&o.every(Fr)}function zd(e){try{return JSON.stringify(e).length}catch{return Number.POSITIVE_INFINITY}}function Jd(e){return e===null?n.jsx("span",{className:"w6w-muted w6w-result-viewer-null",children:"null"}):typeof e=="object"?JSON.stringify(e):String(e)}const Kd=65536;function hs(e,t){return e.length>Kd?n.jsx("pre",{className:"w6w-result-viewer-text",children:e}):n.jsx(le.CodeBlock,{code:e,language:t,copyable:!1,wrap:!0})}function Te(e){const{value:t,format:s="auto",maxHeight:o=320,className:r}=e,a=b.useMemo(()=>s==="json"?{format:"json",data:t}:hi(t),[t,s]),[i,l]=b.useState("rendered"),[c,u]=b.useState("table"),[d,f]=b.useState(2),[p,m]=b.useState(0),h=a.format==="json"?"":a.text,w=a.format==="html"||a.format==="markdown",g=w&&h.length>_s,y=b.useMemo(()=>a.format!=="json"||!Vd(a.data)?null:{table:a.data,tooLarge:zd(a.data)>_s},[a]),x=y!==null&&!y.tooLarge&&c==="table",S=b.useMemo(()=>((y==null?void 0:y.table.columns)??[]).map((k,_)=>({key:`${_}:${k}`,header:k,render:({row:U})=>Jd(U[k])})),[y]),A=b.useMemo(()=>((y==null?void 0:y.table.rows)??[]).map((k,_)=>({i:_,row:k})),[y]),O=b.useMemo(()=>{try{return mi(a)}catch{return typeof t=="string"?t:String(t)}},[a,t]);let j;if(a.format==="json"){const k=n.jsx(qd,{value:a.data,expandDepth:d},p);x?j=n.jsx(li,{columns:S,rows:A,rowKey:_=>String(_.i),className:"w6w-result-viewer-table",testId:"result-viewer-table"}):y!=null&&y.tooLarge?j=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to show as a table — showing JSON."}),k]}):j=k}else if(a.format==="xml")j=hs(a.text,"markup");else if(a.format==="text")j=n.jsx("pre",{className:"w6w-result-viewer-text",children:a.text});else{const k=a.format==="html"?"markup":"markdown";g?j=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to render — showing source."}),hs(a.text,k)]}):i==="source"?j=hs(a.text,k):a.format==="html"?j=n.jsx(di,{html:a.text}):j=n.jsx(mo,{content:a.text,copyable:!1})}let N=null;if(a.format==="json"){const k=y!==null&&!y.tooLarge?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${c==="table"?" active":""}`,"data-mode":"table","aria-pressed":c==="table",onClick:()=>u("table"),children:"Table"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${c==="json"?" active":""}`,"data-mode":"json","aria-pressed":c==="json",onClick:()=>u("json"),children:"JSON"})]}):null;N=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[k,x?null:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{f(Number.POSITIVE_INFINITY),m(_=>_+1)},children:"Expand all"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{f(1),m(_=>_+1)},children:"Collapse all"})]})]})}else w&&!g&&(N=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${i==="rendered"?" active":""}`,"data-mode":"rendered","aria-pressed":i==="rendered",onClick:()=>l("rendered"),children:"Rendered"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${i==="source"?" active":""}`,"data-mode":"source","aria-pressed":i==="source",onClick:()=>l("source"),children:"Source"})]}));return n.jsxs("div",{className:["w6w-result-viewer",r??""].filter(Boolean).join(" "),"data-format":a.format,children:[N,n.jsx(le.Copyable,{value:O,label:"Copy result",className:"w6w-copyable--overlay",children:n.jsx("div",{className:"w6w-result-viewer-body",style:{maxHeight:o,overflow:"auto"},children:j})})]})}function wo(e,t){const s=e.filter(r=>r.appId===ut),o=r=>{var a;return typeof((a=r.params)==null?void 0:a.node)=="string"?r.params.node:r.nodeId??null};return s.find(r=>o(r)===t)??s.find(r=>!o(r))??null}function wi(e,t){const s=e.filter(o=>o.appId===ze);return s.find(o=>o.nodeId===t)??s.find(o=>!o.nodeId)??s[0]??null}const Gd=/auth|token|secret|passw|cookie|api[-_]?key|signature|session/i,Yd="••••••";function Xd(e){const t={};for(const[s,o]of Object.entries(e))t[s]=Gd.test(s)?Yd:o;return t}const Zd=20;function Qd({workflowId:e,stepId:t,stepWith:s,readOnly:o,onUse:r,using:a,appId:i=ze}){const l=Ce(),c=i===ut,u=c?"form":"webhook",[d,f]=b.useState(void 0),[p,m]=b.useState(!1),[h,w]=b.useState({phase:"idle"}),[g,y]=b.useState(()=>Date.now()),x=b.useRef(null);b.useEffect(()=>{const _=l.listSubscriptionsForWorkflow;if(!_)return;let U=!1;return _(e).then(T=>!U&&f(c?wo(T,t):wi(T,t))).catch(T=>!U&&w({phase:"error",message:T.message})),()=>{U=!0}},[l,e,t,c]);const S=b.useCallback(_=>{var T;const U=x.current;x.current=null,U&&(U.abort.abort(),_&&((T=l.stopWebhookListen)==null||T.call(l,U.subId,U.sessionId).catch(()=>{})))},[l]);b.useEffect(()=>()=>S(!0),[S]),b.useEffect(()=>{if(h.phase!=="waiting")return;const _=setInterval(()=>y(Date.now()),1e3);return()=>clearInterval(_)},[h.phase]);const A=()=>{const _=l.createSubscription;if(!_)return;m(!0),_(i,c?"submission":"webhook",c?{workflowId:e,connectionId:null,params:{node:t}}:{workflowId:e,connectionId:null,params:s??{}}).then(T=>f(T)).catch(T=>w({phase:"error",message:T.message})).finally(()=>m(!1))},O=async()=>{var P;const _=l.startWebhookListen,U=l.pollWebhookListen;if(!d||!_||!U)return;S(!0),w({phase:"starting"});let T;try{T=(await _(d.id)).session}catch(I){w({phase:"error",message:I.message});return}const F=new AbortController,E={subId:d.id,sessionId:T.id,abort:F};for(x.current=E,y(Date.now()),w({phase:"waiting",session:T});;){let I;try{I=await U(d.id,T.id,{waitSeconds:Zd,signal:F.signal})}catch(G){if(x.current!==E)return;x.current=null,w({phase:"error",message:G.message});return}if(x.current!==E)return;if(I.status==="captured"&&I.request){x.current=null,w({phase:"captured",session:I,request:I.request});return}if(I.status==="expired"){x.current=null,(P=l.stopWebhookListen)==null||P.call(l,d.id,T.id).catch(()=>{}),w({phase:"expired"});return}}},j=()=>{S(!0),w({phase:"idle"})};if(!l.startWebhookListen||!l.pollWebhookListen)return null;const N=(d==null?void 0:d.webhookUrl)??(d==null?void 0:d.formUrl),k=h.phase==="waiting"?Math.max(0,Math.ceil((Date.parse(h.session.expiresAt)-g)/1e3)):0;return n.jsxs("div",{className:"w6w-stack w6w-listen","data-testid":"webhook-listen",children:[d===void 0?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):N?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"w6w-listen-url",children:[n.jsx(le.Copyable,{value:N,readOnly:!0,children:n.jsx("input",{type:"text",readOnly:!0,value:N,"aria-label":c?"Form URL":"Webhook URL"})}),c&&n.jsx("a",{className:"w6w-btn w6w-btn-ghost w6w-btn-sm",href:N,target:"_blank",rel:"noreferrer","data-testid":"form-open",children:"Open form"})]}),h.phase==="waiting"||h.phase==="starting"?n.jsxs("div",{className:"w6w-listen-waiting",children:[n.jsx("span",{className:"w6w-listen-pulse","aria-hidden":"true"}),n.jsxs("output",{className:"w6w-small",children:[c?"Waiting for a submission on":"Waiting for a request to"," ",n.jsx("code",{children:N}),"…",h.phase==="waiting"&&n.jsxs("span",{className:"w6w-muted",children:[" ",ep(k)," left"]})]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:j,children:"Stop"})]}):n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:o,onClick:()=>void O(),children:h.phase==="captured"?"Listen again":"Listen for test event"}),h.phase==="idle"&&n.jsx("span",{className:"w6w-muted w6w-small",children:c?"Then open the form and submit it — it works before you publish, and the workflow runs on the test submission.":"Send a request to this URL — it works before you publish, and starts no run."})]})]}):n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("p",{className:"w6w-muted w6w-small",children:["This ",u," has no URL yet. Create one, then listen for a test"," ",c?"submission":"request","."]}),!o&&l.createSubscription&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:A,children:p?"Creating…":`Create ${u} URL`})]}),h.phase==="expired"&&n.jsx("p",{className:"w6w-muted w6w-small",children:c?"No submission arrived in time. Listen again, then submit the form.":"No request arrived in time. Listen again, then send the request."}),h.phase==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:h.message}),h.phase==="captured"&&c&&n.jsx(np,{submission:h.request,receivedAt:h.session.receivedAt,readOnly:o,using:a,onUse:()=>r(h.request),stepId:t}),h.phase==="captured"&&!c&&n.jsx(tp,{request:h.request,receivedAt:h.session.receivedAt,readOnly:o,using:a,onUse:()=>r(h.request),stepId:t})]})}function ep(e){const t=Math.floor(e/60);return t>0?`${t}:${String(e%60).padStart(2,"0")}`:`${e}s`}function tp({request:e,receivedAt:t,readOnly:s,using:o,onUse:r,stepId:a}){const i=Object.keys(e.query??{}).length>0;return n.jsxs("div",{className:"w6w-testout w6w-listen-captured","data-testid":"webhook-captured",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Request received",t&&n.jsxs("span",{className:"w6w-muted",children:[" · ",new Date(t).toLocaleTimeString()]})]}),n.jsxs("div",{className:"w6w-small",children:[n.jsx("code",{children:e.method})," ",n.jsx("code",{children:e.path})]}),i&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Query"}),n.jsx(Te,{value:e.query,maxHeight:120})]}),n.jsx("div",{className:"w6w-testout-label",children:"Headers"}),n.jsx(Te,{value:Xd(e.headers??{}),maxHeight:160}),n.jsx("div",{className:"w6w-testout-label",children:"Body"}),n.jsx(Te,{value:e.body,maxHeight:240}),!s&&n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:o,onClick:r,children:o?"Saving…":"Use as test data"}),n.jsxs("span",{className:"w6w-muted w6w-small",children:["Becomes this trigger's output, so later steps can use"," ",n.jsx("code",{children:`{{ nodes.${a}.output.body… }}`}),"."]})]})]})}function np({submission:e,receivedAt:t,readOnly:s,using:o,onUse:r,stepId:a}){var l;const i=(l=e.meta)==null?void 0:l.runId;return n.jsxs("div",{className:"w6w-testout w6w-listen-captured","data-testid":"form-captured",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Submission received",t&&n.jsxs("span",{className:"w6w-muted",children:[" · ",new Date(t).toLocaleTimeString()]})]}),i&&n.jsxs("div",{className:"w6w-small","data-testid":"form-captured-run",children:["The workflow is running on it: ",n.jsx("code",{children:i})]}),n.jsx("div",{className:"w6w-testout-label",children:"Answers"}),n.jsx(Te,{value:e.data??{},maxHeight:240}),!s&&n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:o,onClick:r,children:o?"Saving…":"Use as test data"}),n.jsxs("span",{className:"w6w-muted w6w-small",children:["Becomes this trigger's output, so later steps can use"," ",n.jsx("code",{children:`{{ nodes.${a}.output.data… }}`}),"."]})]})]})}function bo(e){return Array.isArray(e)?e:[]}function yo(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function go(e,t){if(!(t==null||t==="")){if(typeof t=="object")return t;if(e==="number"){const s=Number(t);return Number.isFinite(s)?s:void 0}if(e==="boolean")return t===!0||t==="true";if(e==="json")try{return JSON.parse(String(t))}catch{return}return String(t)}}function xo(e){return e.filter(t=>typeof t.key=="string"&&t.key.trim()!=="").map(t=>({key:t.key,label:t.key,type:yo(t.type),required:!!t.required}))}function Ps(e){const t={};for(const s of e){if(typeof s.key!="string"||s.key.trim()==="")continue;const o=go(s.type,s.default);o!==void 0&&(t[s.key]=o)}return t}function bi(e,t){const s=(e??[]).find(r=>r&&r.nodeId===t);if(!s)return;const o=s.input;return o&&typeof o=="object"&&!Array.isArray(o)?o:{}}function sp(e){return tt(e)||typeof e=="string"&&e.includes("{{")}function vo(e,t=[]){const s=new Set(t.filter(r=>r.type==="secret").map(r=>r.key)),o={};for(const[r,a]of Object.entries(e))a===void 0||pt(a)||s.has(r)&&!sp(a)||(o[r]=a);return o}const Fs=new Set;function yi(e){const t=e.then(()=>{},()=>{});return Fs.add(t),t.then(()=>Fs.delete(t)),e}async function gi(){await Promise.all([...Fs])}function xi(e,t){const s=Ce(),o=typeof s.loadTestInputs=="function"&&!!e&&!!t,[r,a]=b.useState(!o),[i,l]=b.useState(void 0);b.useEffect(()=>{if(!o||!e||!t||!s.loadTestInputs){a(!0);return}let f=!1;return a(!1),gi().then(()=>{var p;return((p=s.loadTestInputs)==null?void 0:p.call(s,e))??[]}).then(p=>{f||(l(bi(p,t)),a(!0))}).catch(()=>{f||a(!0)}),()=>{f=!0}},[s,o,e,t]);const c=b.useCallback(f=>{l(f),!(!e||!t||typeof s.saveTestInput!="function")&&yi(s.saveTestInput(e,t,f)).catch(p=>{console.error("test input save failed",p)})},[s,e,t]),u=b.useCallback((f,p)=>c(vo(f,p)),[c]),d=b.useCallback(()=>c({}),[c]);return{loaded:r,supported:o,input:i,save:u,clear:d}}function vi({onClear:e}){return n.jsxs("p",{className:"w6w-muted w6w-small","data-testid":"last-used-note",children:["last used values ·"," ",n.jsx("button",{type:"button",className:"w6w-linkbtn",onClick:e,children:"Clear"})]})}const op=600;function ji({app:e,action:t,fields:s,persist:o,listen:r,appTrigger:a=!1}){const i=Ce(),l=Ys(),c=b.useMemo(()=>bo(s),[s]),u=b.useMemo(()=>xo(c),[c]),d=u.length>0,[f,p]=b.useState(()=>Ps(c)),[m,h]=b.useState(null),w=o==null?void 0:o.workflowId,g=o==null?void 0:o.stepId,y=xi(w,g),[x,S]=b.useState(!1),[A,O]=b.useState(!1),[j,N]=b.useState(!w||!g);b.useEffect(()=>{if(!w||!g){N(!0);return}if(!y.loaded)return;if(y.input!==void 0){const J=y.input;Object.keys(J).length>0&&(p(M=>({...M,...J})),S(!0),O(!0)),N(!0);return}let Y=!1;return i.listStepTests(w,g).then(J=>{if(Y)return;const M=J.length?J[J.length-1]:null;M!=null&&M.with&&(p(te=>({...te,...M.with})),Object.keys(M.with).length>0&&O(!0)),N(!0)}).catch(()=>{Y||N(!0)}),()=>{Y=!0}},[i,w,g,y.loaded]);const[k,_]=b.useState(0),U=()=>{clearTimeout(F.current),T.current=null,y.clear(),S(!1),p(Ps(c)),_(Y=>Y+1)},T=b.useRef(null),F=b.useRef(void 0),E=b.useRef(()=>{});E.current=()=>{clearTimeout(F.current);const Y=T.current;T.current=null,Y&&y.save(Y,u)},b.useEffect(()=>()=>E.current(),[]);const P=Y=>{p(Y),!(!w||!g||!j)&&(T.current=Y,clearTimeout(F.current),F.current=setTimeout(()=>E.current(),op))},[I,G]=b.useState(!0),W=I&&Bt(u,f),$=async Y=>{const J=Y??f;clearTimeout(F.current),T.current=null,o&&y.save(J,u),h({status:"running"});let M;if(a)M={status:"done",value:J};else try{const te=await i.invokeAction(e,t,{input:J},{project:l});M={status:"done",value:te.value,logs:te.logs}}catch(te){const ee=te;M={status:"error",error:ee.message??String(te),errorCode:ee.code,logs:ee.logs}}if(h(M),o)try{const te=await i.saveStepTest(o.workflowId,o.stepId,{input:o.input,with:J});await i.recordStepTestRun(o.workflowId,o.stepId,{stepTestId:te.id,status:M.status==="done"?"succeeded":"failed",input:o.input,output:M.status==="done"?M.value:void 0,error:M.status==="error"?M.error:void 0})}catch(te){console.error("step test persist failed",te)}},R=m&&m.status!=="running"?m.logs:void 0,z=Y=>{const J={...Y};p(J),$(J)},K=r&&o&&n.jsx(Qd,{workflowId:o.workflowId,stepId:o.stepId,stepWith:r.stepWith,readOnly:r.readOnly,appId:r.appId,onUse:z,using:(m==null?void 0:m.status)==="running"});return n.jsxs("div",{className:"w6w-stack",children:[K,K?n.jsxs("details",{className:"w6w-listen-manual","data-testid":"trigger-sample-payload",open:A,onToggle:Y=>O(Y.currentTarget.open),children:[n.jsx("summary",{className:"w6w-small",children:"Or test with a sample payload"}),ne()]}):ne(),B()]});function ne(){return n.jsxs("div",{className:"w6w-stack",children:[j?n.jsxs(n.Fragment,{children:[x&&n.jsx(vi,{onClear:U}),n.jsx(ri,{params:u,values:f,onChange:P,onValidityChange:G},k),a?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"w6w-hint",children:"Paste an example event to test with. It becomes this trigger's output, so the steps after it can be tested and their fields picked. ▶ Run on this trigger uses it too. Publish the workflow to receive real events."}),n.jsx(ai,{app:e,trigger:t,onUse:Y=>{P(Y),_(J=>J+1)}})]}):!d&&n.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 (",n.jsx("code",{children:"input"}),")."]})]}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading saved values…"}),n.jsx("div",{className:"w6w-steptest",children:n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!j||!W||(m==null?void 0:m.status)==="running",onClick:()=>void $(),children:(m==null?void 0:m.status)==="running"?"Running…":"▶ Test run"}),j&&!W&&n.jsx("span",{className:"w6w-muted w6w-small",children:I?"Fill the required fields to test.":"The payload must be a JSON object to test."})]})})]})}function B(){return n.jsxs("div",{className:"w6w-steptest",children:[(m==null?void 0:m.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[m.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:m.errorCode})}),m.error]}),(m==null?void 0:m.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Output state (filled values)"}),n.jsx(Te,{value:m.value,maxHeight:220})]}),R&&R.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx(le.Copyable,{value:R.join(`
22
+ `),label:"Copy console output",children:n.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:R.join(`
23
+ `)})})]})]})}}const rp=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],ap=/^(?=\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 ki({values:e,onChange:t,readOnly:s}){const o=e.duration??"1s",r=typeof o=="string"?o.match(/^(\d+(?:\.\d+)?)([smhdw])$/i):null,[a,i]=b.useState("s"),[l,c]=b.useState("text"),[u,d]=b.useState(e.until?"until":"duration"),f=typeof o=="string"&&(!ap.test(o.trim())||/^P$/i.test(o.trim()));return n.jsxs("div",{className:"w6w-params-form",children:[n.jsxs("label",{children:["Wait for",n.jsxs("select",{"aria-label":"Wait for",disabled:s,value:u,onChange:p=>{const m=p.target.value;d(m),t({...e,duration:m==="duration"?"1s":"",until:""})},children:[n.jsx("option",{value:"duration",children:"A duration"}),n.jsx("option",{value:"until",children:"Until a timestamp"})]})]}),u==="until"?n.jsx(Ue,{params:[{key:"until",label:"Until",type:"string",hint:"ISO-8601 timestamp, e.g. 2026-10-08T09:00:00Z."}],values:e,onChange:t,readOnly:s}):n.jsxs(n.Fragment,{children:[n.jsxs("label",{children:["Duration input",n.jsxs("select",{"aria-label":"Duration input",disabled:s,value:l,onChange:p=>{r&&i((r==null?void 0:r[2].toLowerCase())??a),c(p.target.value)},children:[n.jsx("option",{value:"text",children:"Shorthand"}),n.jsx("option",{value:"value",disabled:!r,children:"Value and unit"})]})]}),l==="value"?n.jsxs("div",{className:"w6w-field-row",children:[n.jsxs("label",{children:["Value",n.jsx("input",{"aria-label":"Duration value",type:"number",min:"0",step:((r==null?void 0:r[2].toLowerCase())??a)==="s"?"any":"1",disabled:s,value:(r==null?void 0:r[1])??"",onChange:p=>t({...e,duration:`${p.target.value}${(r==null?void 0:r[2].toLowerCase())??a}`})})]}),n.jsxs("label",{children:["Unit",n.jsx("select",{"aria-label":"Duration unit",disabled:s,value:(r==null?void 0:r[2].toLowerCase())??a,onChange:p=>{i(p.target.value),t({...e,duration:`${(r==null?void 0:r[1])??""}${p.target.value}`})},children:rp.map(([p,m])=>n.jsx("option",{value:p,children:m},p))})]})]}):n.jsx(Ue,{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:t,readOnly:s}),f&&n.jsx("p",{role:"alert",children:"Enter a duration such as 30s or 1h30m30s, using units w, d, h, m, s in order."})]})]})}function Ni({anchorRef:e,onClose:t,children:s}){const o=b.useRef(null),[r,a]=b.useState(null),[i,l]=b.useState(null);return b.useEffect(()=>{const c=e.current;if(!c)return;const u=c.getBoundingClientRect();a({top:u.bottom+6,left:u.left,width:u.width}),l(c.closest("dialog")??document.body)},[e]),b.useEffect(()=>{function c(d){var p,m;const f=d.target;(p=o.current)!=null&&p.contains(f)||(m=e.current)!=null&&m.contains(f)||t()}function u(d){d.key==="Escape"&&t()}return document.addEventListener("mousedown",c),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",u)}},[t,e]),!r||!i?null:Rn.createPortal(n.jsx("div",{ref:o,className:"w6w-flyout",style:{top:r.top,left:r.left,width:r.width},children:s}),i)}function Si(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;const s=Object.keys(e),o=Object.keys(t);return s.length!==o.length?!1:s.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&Si(e[r],t[r]))}function ip(e,t){return e.map(s=>{const o=t&&Object.hasOwn(t,s.id)?t[s.id]:void 0,r=s.data.stepProblems;if(o===void 0||o.length===0){if(r===void 0&&!("stepProblems"in s.data))return s;const{stepProblems:a,...i}=s.data;return{...s,data:i}}return r&&Si(r,o)?s:{...s,data:{...s.data,stepProblems:structuredClone(o)}}})}const lp={body_not_literal:"This loop's body is not a list of step ids",body_unknown_step:"This loop's body names a step that doesn't exist",body_self:"This loop's body contains the For each itself",body_duplicate:"This loop's body lists a step twice",body_claimed_twice:"A step in this loop's body is also owned by another control step",body_contains_control:"This loop's body contains a control step (If, For each, Parallel…)",body_step_has_edges:"A step in this loop's body also has its own connections",legacy_not_linear:"The steps after this For each aren't one straight line, so they can't be read as its loop body"};function cp(e){switch(e.code){case"unknown_connection":return`Connection ${e.connection} no longer exists — open the step and choose another on the Setup tab`;case"foreach_wrapped_items":return"Items wraps a list in another list — this loops once";case"foreach_body_refs_output":return`Refers to the For each's output (${e.refs.join(", ")}) from inside its loop — use Current item instead`;case"loop_body_invalid":{const t=lp[e.reason.reason]??"This loop's body is not valid";return e.reason.stepId?`${t} (${e.reason.stepId})`:t}case"state_parallel_write":return`Writes ${`state${e.path.length?`.${e.path.join(".")}`:""}`} at the same time as ${e.with.join(", ")} — parallel branches don't see each other's writes; the final value follows the workflow's step order`;case"setup_incomplete":return`Setup incomplete — ${e.items.join(", ")}`}}function up(e,t){return(t==null?void 0:t.some(s=>s.code==="unknown_connection"&&e.uses.connection===s.connection))??!1}function Lr(e,t,s){if(!e)return"No connection";if(s)return"Couldn't load connections";if(t===null)return e;const o=t.find(r=>r.id===e);return o?o.builtIn?"Built-in":o.displayName??e:"Missing connection — choose another"}function An(e,t,s){if(s.type==="update"){const r=An(e,t,{type:"rename",ref:s.ref,name:s.name}),a=s.name.trim(),i=An(r.nodes,r.connections,{type:"replace",ref:a,connection:s.connection});return s.nodeIds?An(i.nodes,i.connections,{type:"assign",ref:a,nodeIds:s.nodeIds}):i}if(s.type==="add"||s.type==="rename"){const r=s.name.trim();if(!r)throw new Error("Give the workflow connection a name.");if(Object.hasOwn(t,r)&&(s.type==="add"||r!==s.ref))throw new Error("A workflow connection already uses that name.");if(s.type==="add")return{nodes:e,connections:{...t,[r]:{app:s.app,connection:s.connection}}}}if(!Object.hasOwn(t,s.ref))throw new Error("This workflow connection no longer exists.");const o=t[s.ref];switch(s.type){case"replace":return{nodes:e,connections:{...t,[s.ref]:{...o,connection:s.connection}}};case"rename":{const r=s.name.trim();return{connections:Object.fromEntries(Object.entries(t).map(([a,i])=>[a===s.ref?r:a,i])),nodes:e.map(a=>a.uses.connectionRef===s.ref?dn(a,r):a)}}case"remove":{if(e.some(i=>i.uses.connectionRef===s.ref))throw new Error("Choose another connection for its nodes before removing this resource.");const{[s.ref]:r,...a}=t;return{nodes:e,connections:a}}case"assign":{const r=new Set(s.nodeIds);if(e.some(a=>r.has(a.id)&&a.uses.app!==o.app))throw new Error("A connection can only be assigned to nodes for the same app.");return{connections:t,nodes:e.map(a=>r.has(a.id)?dn(a,s.ref):a)}}}}function Kt(e,t){const{connectionRef:s,connection:o,app:r}=e.uses;if(s===void 0)return o??void 0;const a=t&&Object.hasOwn(t,s)?t[s]:void 0;return(a==null?void 0:a.app)===r?a.connection??void 0:void 0}function jo(e,t){const o=(e.split(/[./]/).filter(Boolean).at(-1)??"connection").toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"connection";let r=1;for(;Object.hasOwn(t,`${o}_${r}`);)r++;return`${o}_${r}`}function Ci(e){let t=e.connections??{},s=!1;const o=(e.nodes??[]).map(r=>{if(!r.uses.connection||r.uses.connectionRef!==void 0)return r;const a=Object.hasOwn(t,r.id)?t[r.id]:void 0,i=(a==null?void 0:a.app)===r.uses.app&&a.connection===r.uses.connection?r.id:jo(r.uses.app,t);return t={...t,[i]:{app:r.uses.app,connection:r.uses.connection}},s=!0,dn(r,i)});return s?{...e,nodes:o,connections:t}:e}function dn(e,t){const{connection:s,...o}=e.uses;return{...e,uses:{...o,connectionRef:t}}}function dp(e,t,s,o){if(!t){const{connection:l,connectionRef:c,...u}=e.uses;return{step:{...e,uses:u},connections:o}}const r=e.uses.connectionRef,a=r&&s.some(l=>l.id!==e.id&&l.uses.connectionRef===r),i=r&&!a?r:jo(e.uses.app,o);return{step:dn(e,i),connections:{...o,[i]:{app:e.uses.app,connection:t}}}}function En(e,t,s,o){return t?s.filter(r=>r.uses.app===e&&Kt(r,o)===t):[]}function Ai(e,t,s,o,r){if(r)return{connection:r};for(const l of[...s].reverse()){if(l.id===e.id||l.uses.app!==e.uses.app)continue;const c=Kt(l,o);if(!(!c||!t.some(u=>u.id===c&&u.appId===e.uses.app)))return l.uses.connectionRef?{connectionRef:l.uses.connectionRef}:{connection:c}}for(const[l,c]of Object.entries(o))if(c.app===e.uses.app&&t.some(u=>u.appId===c.app&&u.id===c.connection))return{connectionRef:l};const a=t.filter(l=>l.appId===e.uses.app),i=a.find(l=>l.builtIn)??a[0];return i?{connection:i.id}:{}}function Mr(e,t,s){return s.some(r=>r.builtIn)||!t.some(r=>r.available!==!1&&(r.key==="zero-credential"||r.autoSatisfied===!0&&(r.type==="tenantAuth"||r.type==="jit")))?s:[...s,{id:`zerocred:${e}`,appId:e,authKey:"zero-credential",displayName:"Built-in",builtIn:!0,state:"connected"}]}function pp(e,t,s,o,r){const a=new Set(En(e,t,o,r).map(i=>i.uses.connectionRef));return Object.fromEntries(Object.entries(r).map(([i,l])=>[i,a.has(i)?{...l,connection:s}:l]))}function Ei(e,t=""){if(!e||typeof e!="object"||Array.isArray(e))return[];const s=[];for(const[o,r]of Object.entries(e)){const a=t?`${t}.${o}`:o;s.push(a,...Ei(r,a))}return s}function fp(e,t,s){var a,i;const o=[],r={};for(const[l,c]of Object.entries(e)){const u=c.connection?t.get(c.connection):void 0,d=(u==null?void 0:u.profile)??{};o.push({name:l,appName:((a=s.get(c.app))==null?void 0:a.displayName)??((i=u==null?void 0:u.app)==null?void 0:i.displayName)??c.app,...u!=null&&u.displayName?{label:u.displayName}:{},fields:[{key:"id"},{key:"app"},{key:"name"},{key:"state"},{key:"profile",path:!0},...Ei(d,"profile").map(f=>({key:f,path:!0}))]}),u&&(r[`connections.${l}`]={id:u.id,app:u.appId,name:u.displayName??"",state:u.state??"",profile:d})}return{sources:o,sampleValues:r}}const Ti=b.createContext(null);function ko(){return b.useContext(Ti)}function Oi({step:e,conns:t,failed:s=!1,readOnly:o,open:r,onOpenChange:a,anchorRef:i,onChangeConnection:l,onChangeConnectionRef:c,onConnectionCreated:u,createSignal:d}){var U,T,F;const f=ko(),p=o||(f==null?void 0:f.readOnly),m=(f==null?void 0:f.connections)??{},h=(f==null?void 0:f.nodes)??[],w=(t??[]).map(E=>({conn:E,users:En(e.uses.app,E.id,h,m)})).sort((E,P)=>+(P.users.length>0)-+(E.users.length>0)),g=Kt(e,m)??(e.uses.connectionRef===void 0?(U=t==null?void 0:t.find(E=>E.builtIn&&E.appId===e.uses.app))==null?void 0:U.id:void 0),y=En(e.uses.app,g,h,m).filter(E=>E.id!==e.id),[x,S]=b.useState(null),[A,O]=b.useState(!1),j=b.useRef(d);b.useEffect(()=>{const E=j.current;j.current=d,d!==void 0&&E!==void 0&&d>E&&O(!0)},[d]);const N=x||A?((F=(T=i.current)==null?void 0:T.closest("dialog"))==null?void 0:F.parentElement)??document.body:null,k=(E,P)=>{if(!p){if(P&&f&&g){f.setConnections(pp(e.uses.app,g,E,h,m));const I=h.find(G=>G.id===e.id)??e;I.uses.connectionRef?c(I.uses.connectionRef):l(E)}else{const I=En(e.uses.app,E,h,m).filter(W=>W.id!==e.id&&W.uses.connectionRef).at(-1),G=Object.entries(m).find(([,W])=>W.app===e.uses.app&&W.connection===E);I!=null&&I.uses.connectionRef?c(I.uses.connectionRef):G?c(G[0]):l(E)}S(null),a(!1)}},_=E=>{p||(a(!1),E!==g&&(y.length>0&&h.some(P=>P.id===e.id)?S(E):k(E,!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"Connection","aria-expanded":r,disabled:p||t===null&&!s,onClick:()=>a(!r),children:n.jsx("span",{className:"w6w-conn-label-name",children:t===null&&!s&&!g?"Loading connections…":Lr(g,t,s)})}),r&&n.jsx(Ni,{anchorRef:i,onClose:()=>a(!1),children:n.jsxs("div",{className:"w6w-stack",children:[s&&n.jsx("p",{role:"alert",className:"w6w-field-error",children:"Couldn’t load connections."}),Object.entries(m).some(([,E])=>E.app===e.uses.app)&&n.jsxs("div",{className:"w6w-stack",children:[n.jsx("strong",{className:"w6w-small",children:"Workflow connections"}),n.jsx("div",{className:"w6w-stepbuilder-list",children:Object.entries(m).filter(([,E])=>E.app===e.uses.app).map(([E,P])=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:p||!P.connection||!(t!=null&&t.some(I=>I.id===P.connection)),"aria-pressed":e.uses.connectionRef===E,"data-connection-ref":E,onClick:()=>{c(E),a(!1)},children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:E}),n.jsx("span",{className:"w6w-muted w6w-small",children:Lr(P.connection??void 0,t,s)})]})},E))})]}),n.jsx("div",{className:"w6w-stepbuilder-list",children:w.map(({conn:E,users:P})=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:p,"aria-pressed":E.id===g,"data-connection-id":E.id,onClick:()=>_(E.id),children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:E.builtIn?"Built-in":E.displayName||E.id}),n.jsx("span",{className:"w6w-muted w6w-small",children:P.length>0?`In use in this workflow · ${P.map(I=>I.id).join(", ")}`:E.builtIn?"Built-in connection":E.state})]})},E.id))}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:()=>{a(!1),O(!0)},children:"+ New connection"})]})}),A&&N&&Rn.createPortal(n.jsx(co,{initialAppId:e.uses.app,onClose:()=>O(!1),onCreated:({connectionId:E})=>{O(!1),u(),_(E)}}),N),x&&N&&Rn.createPortal(n.jsxs(Ee,{title:"Change connection",onClose:()=>S(null),children:[n.jsxs("div",{className:"w6w-modal-body",children:[n.jsx("p",{children:"Change the connection for all these nodes, or only this node?"}),n.jsxs("ul",{children:[n.jsx("li",{children:e.id||"New node"}),y.map(E=>n.jsx("li",{children:E.id},E.id))]})]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>S(null),children:"Cancel"}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:p,onClick:()=>k(x,!0),children:["All ",y.length+1," nodes"]}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:p,onClick:()=>k(x,!1),children:"Only this node"})]})]}),N)]})}function hp(e,t){return`${e.method}-${e.url??e.host}-${t}`}function Ii({calls:e,defaultOpen:t,keyOf:s,title:o}){if(e.length===0)return null;const r=s??hp;return n.jsxs("div",{className:"w6w-stack",style:{gap:4},children:[o!==!1&&n.jsx("strong",{className:"w6w-small",children:o??n.jsxs(n.Fragment,{children:["API ",e.length===1?"call":"calls"," (",e.length,")"]})}),e.map((a,i)=>n.jsxs("details",{open:t,className:"w6w-result",style:{padding:8},children:[n.jsx("summary",{style:{cursor:"pointer"},children:n.jsxs("span",{className:"w6w-small",children:[a.method," ",a.url??a.host," →"," ",n.jsx("strong",{children:a.error?"failed":a.status}),a.durationMs!==void 0&&n.jsxs("span",{className:"w6w-muted",children:[" · ",a.durationMs,"ms"]})]})}),n.jsxs("div",{className:"w6w-stack",style:{gap:6,marginTop:8},children:[a.error&&n.jsx("div",{className:"w6w-error w6w-small",children:a.error}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Request headers"}),n.jsx(Te,{value:a.requestHeaders??{},maxHeight:240}),a.requestBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Request body"}),n.jsx(Te,{value:a.requestBody,maxHeight:240})]}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Response headers"}),n.jsx(Te,{value:a.responseHeaders??{},maxHeight:240}),a.responseBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Response body"}),n.jsx(Te,{value:a.responseBody,maxHeight:240})]}),a.truncated&&n.jsx("div",{className:"w6w-muted w6w-small",children:"A captured body exceeded the size cap and was truncated."})]})]},r(a,i)))]})}function Ri({title:e,children:t,action:s,className:o,testId:r}){return n.jsx("div",{className:o?`w6w-empty-state ${o}`:"w6w-empty-state","data-testid":r,children:n.jsxs("div",{className:"w6w-empty-state-inner",children:[e!=null&&n.jsx("div",{className:"w6w-empty-state-title",children:e}),t!=null&&n.jsx("div",{className:"w6w-empty-state-body",children:t}),s!=null&&n.jsx("div",{className:"w6w-empty-state-action",children:s})]})})}function $i({choices:e,onChange:t,readOnly:s}){const o=new Set(e.selected),r=e.options.every(i=>o.has(i.value)),a=[...e.options,...e.selected.filter(i=>!e.options.some(l=>l.value===i)).map(i=>({value:i,label:i}))];return n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Triggers *"}),n.jsxs("div",{className:"w6w-multiselect-checks",children:[n.jsxs("div",{className:"w6w-multiselect-checks-toolbar",children:[n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:r,ref:i=>{i&&(i.indeterminate=!r&&o.size>0)},disabled:s,onChange:i=>t(i.target.checked?e.options.map(l=>l.value):[])}),n.jsx("span",{children:"All events"})]}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[o.size," selected"]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":"Eventbrite events",children:a.map(i=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:o.has(i.value),disabled:s,onChange:l=>t(l.target.checked?[...e.selected,i.value]:e.selected.filter(c=>c!==i.value))}),n.jsx("span",{children:i.label})]},i.value))})]}),n.jsx("span",{className:"w6w-hint",children:"Start this workflow when any selected event occurs."})]})}function Qn({icon:e,size:t=28}){return n.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:t,height:t,borderRadius:6,flexShrink:0,background:"var(--w6w-icon-swatch, var(--w6w-panel-2))",color:"var(--w6w-accent)"},children:n.jsx("svg",{width:Math.round(t*.6),height:Math.round(t*.6),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",dangerouslySetInnerHTML:{__html:e}})})}function _i(e,t,s,o){var c;if(e!=="io.w6w.eventbrite")return null;const r=t==null?void 0:t.find(u=>u.key==="activity"),a=(c=r==null?void 0:r.params)==null?void 0:c.find(u=>u.key==="actions"&&u.type==="multiselect");if(!r||!Array.isArray(a==null?void 0:a.options)||!a.options.length)return null;const i=a.options.map(u=>{var p;const d=String(u.value),f=d.replace(/[._]/g,"-");return{value:d,label:((p=t==null?void 0:t.find(m=>m.key===f))==null?void 0:p.title)??u.label,triggerKey:f}}),l=i.find(u=>u.triggerKey===s);return s&&s!==r.key&&!l||s===r.key&&o.actions!=null&&!Array.isArray(o.actions)?null:{triggerKey:r.key,options:i.sort((u,d)=>u.label.localeCompare(d.label)),selected:l?[l.value]:Array.isArray(o.actions)?o.actions.filter(u=>typeof u=="string"):[]}}const mp=["off","root","key","pick","append"],wp={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function bp(e){return ie.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function yp(e,t){return JSON.stringify(e)===JSON.stringify(t)}function gp(e,t){const{state:s,...o}=e,r=ie.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return yp(t,r)?o:{...o,state:t}}function xp(e,t){switch(t){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function Pi(e){return!Dt(e.uses.app)}function Se(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===qe&&e.uses.action==="foreach"}function Fi(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===qe}function Ls(e){var s,o;if((e==null?void 0:e.uses.app)===Qe)return!0;if((e==null?void 0:e.uses.app)===zt)return!1;if(!Fi(e))return!0;const t=e==null?void 0:e.uses.action;return t==="foreach"||t==="wait"?!0:t==="if"&&((s=e==null?void 0:e.with)==null?void 0:s.then)===void 0&&((o=e==null?void 0:e.with)==null?void 0:o.else)===void 0}function No(e){if(!Fi(e))return[];const t=e.with??{},s=[],o=r=>{if(typeof r=="string")s.push(r);else if(Array.isArray(r))for(const a of r)o(a)};return o(t.body),o(t.branches),o(t.then),o(t.else),s}function vp(e){const t=new Set;for(const s of e)for(const o of No(s))t.add(o);return t}function Tn(e,t,s,o){return{id:Tt(e,t,"each",o),source:e,target:t,sourceHandle:o!==void 0?Jt(o):s?Hn:void 0,animated:!1,data:{when:"each",...o===void 0?{}:{route:o}},...fn("each",void 0)}}const bn=e=>{var t;return typeof((t=e.data)==null?void 0:t.route)=="string"?e.data.route:void 0};function So(e,t,s,o){const r=new Set(t.map(w=>w.id)),a=new Set(t.filter(w=>{var g;return Se((g=w.data)==null?void 0:g.step)}).map(w=>w.id)),i=s.filter(w=>je(w)==="each"&&!(w.source!==e&&a.has(w.source)&&bn(w)===void 0)),l=new Set([e]),c=[],u=[e];for(let w=0;w<u.length;w++)for(const g of i)g.source===u[w]&&(!r.has(g.target)||l.has(g.target)||o!=null&&o.has(g.target)||(l.add(g.target),c.push(g.target),u.push(g.target)));const d=new Map(c.map((w,g)=>[w,g])),f=i.filter(w=>w.source!==e&&d.has(w.source)&&d.has(w.target)),p=new Map(c.map(w=>[w,0]));for(const w of f)p.set(w.target,(p.get(w.target)??0)+1);const m=[],h=new Set;for(;;){const w=c.find(g=>!h.has(g)&&p.get(g)===0);if(w===void 0)break;h.add(w),m.push(w);for(const g of f)g.source===w&&p.set(g.target,(p.get(g.target)??0)-1)}for(const w of c)h.has(w)||m.push(w);return m}function Li(e,t){const s=new Set(e);return t.filter(o=>je(o)==="each"&&s.has(o.source)&&s.has(o.target))}function jp(e,t){const s=Li(e,t),o=new Set;for(const r of s){if(bn(r)!==void 0||o.has(r.source))return!1;o.add(r.source)}return!0}function kp(e,t){const s=[];for(const o of es(e,t).values())if(!jp(o,t))for(const r of Li(o,t)){const a=bn(r);s.push({from:r.source,to:r.target,...a===void 0?{}:{route:a}})}return s}function es(e,t){var r;const s=new Map,o=new Set;for(const a of e){if(!Se((r=a.data)==null?void 0:r.step))continue;const i=So(a.id,e,t,o);for(const l of i)o.add(l);s.set(a.id,i)}return s}function Je(e,t){const s={};for(const[o,r]of es(e,t))for(const a of r)s[a]=o;return s}function Mi(e,t,s){const o=Je(t,s),r=[];let a=o[e];for(;a!==void 0&&!r.includes(a);)r.unshift(a),a=o[a];return r}function Np(e,t,s){const o=w=>w.source===e||w.target===e,r=s.filter(w=>!o(w)),i=Se((w=>{var g,y;return(y=(g=t.find(x=>x.id===w))==null?void 0:g.data)==null?void 0:y.step})(e)),l=Je(t,s),c=new Set(i?Object.keys(l).filter(w=>l[w]===e):[]),u=i?r.filter(w=>!(je(w)==="each"&&(w.source===e||c.has(w.source))&&c.has(w.target))):r,d=l[e];if(d===void 0)return u;const f=s.filter(w=>w.target===e&&je(w)==="each"),p=s.filter(w=>w.source===e&&je(w)==="each"&&!c.has(w.target));if(f.length!==1||p.length!==1)return u;const m=f[0].source,h=p[0].target;return u.some(w=>w.source===m&&w.target===h&&je(w)==="each")?u:[...u,Tn(m,h,m===d,bn(f[0]))]}function Co(e){if(!Se(e)||!e.with||!("body"in e.with))return e;const{body:t,...s}=e.with;return{...e,with:s}}function Di(e,t,s,o,r,a){const i=Je(o,r);if(s==="error")return i[e]!==void 0||i[t]!==void 0?"error_lane_in_body":null;if(s==="success")return i[t]!==void 0?"outside_inbound":null;const l=f=>{var p,m;return(m=(p=o.find(h=>h.id===f))==null?void 0:p.data)==null?void 0:m.step},u=Se(l(e))&&(a===void 0||i[e]===void 0)?e:i[e];if(u===void 0)return null;if(t===u||Mi(u,o,r).includes(t))return"loop_cycle";const d=()=>e!==u||!r.some(f=>f.source===e&&je(f)==="each"&&bn(f)===void 0);return i[t]===u?e===u||Sp(t,e,r)?"loop_cycle":d()?null:"body_branch":i[t]!==void 0?"already_in_loop":Ls(l(t))?d()?r.some(f=>f.source===t||f.target===t)?"body_exit":null:"body_branch":"control_in_body"}function Sp(e,t,s){const o=new Set([e]),r=[e];for(;r.length>0;){const a=r.pop();if(a===t)return!0;for(const i of s)i.source!==a||je(i)!=="each"||o.has(i.target)||(o.add(i.target),r.push(i.target))}return!1}const Cp={error_lane_in_body:"A step inside a loop can't have an error connection. Handle the failure outside the loop.",outside_inbound:"This step is inside a loop, so nothing outside it can connect into it. Connect from the loop's Each item side instead.",loop_cycle:"A loop body can't connect back to its own For each.",already_in_loop:"That step is already inside another loop.",control_in_body:"Parallel, Merge, Aggregate and Race join paths of the main workflow, so they can't run inside a loop body. Use an If, Router, Wait, Stop, Respond or another For each.",body_branch:"A For each's Each item port connects to one first step. Branch inside the loop from that step onward.",body_exit:"That step is already connected elsewhere in the workflow. Use a step with no connections, or disconnect it first."};function Ap(e){return Cp[e]}function Ep(e,t){const s=Je(e,t);let o=!1;const r=e.map(a=>{const i=s[a.id];if(a.data.loopOf===i)return a;if(o=!0,i===void 0){const{loopOf:l,...c}=a.data;return{...a,data:c}}return{...a,data:{...a.data,loopOf:i}}});return o?r:e}function Tp(e,t,s){var i,l;const o=`Delete node "${e}"? Its connections are removed too.`,r=(l=(i=t.find(c=>c.id===e))==null?void 0:i.data)==null?void 0:l.step;if(!Se(r))return o;const a=So(e,t,s);return a.length===0?o:`${o} Its loop body steps ${a.map(c=>`"${c}"`).join(", ")} stay as standalone steps.`}function Ao(e){if(e.edges)return e.edges;const t=vp(e.nodes),s=e.nodes.filter(r=>!t.has(r.id)),o=[];for(let r=0;r<s.length-1;r++)o.push({from:s[r].id,to:s[r+1].id});return o}const On=e=>(e.when??"success")==="success",Dn=e=>e.route===ta&&On(e);function Eo(e){const t=new Map(e.nodes.map(u=>[u.id,u])),s=new Map;for(const u of e.nodes)for(const d of No(u)){const f=s.get(d)??new Set;f.add(u.id),s.set(d,f)}const o=Ao(e),r=e.edges??[],a={};for(const u of e.nodes){if(!Se(u))continue;const d=u.with??{};if("body"in d){a[u.id]=i(u.id,d.body);continue}a[u.id]=c(u.id)}return a;function i(u,d){const f=(g,y)=>({invalid:y===void 0?{reason:g}:{reason:g,stepId:y}});if(!Array.isArray(d)||d.some(g=>typeof g!="string"))return f("body_not_literal");const p=d,m=new Set(p),h=new Set;for(const g of p){if(!t.has(g))return f("body_unknown_step",g);if(g===u)return f("body_self",g);if(h.has(g))return f("body_duplicate",g);if(h.add(g),!Ls(t.get(g)))return f("body_contains_control",g);const y=s.get(g);if(y&&[...y].some(x=>x!==u))return f("body_claimed_twice",g)}const w=[];for(const g of r){if(Dn(g)&&g.from===u&&g.to===p[0]||Dn(g)&&m.has(g.from)&&!m.has(g.to)&&l(g.from,g.to)||!(m.has(g.from)||m.has(g.to)))continue;if(!(m.has(g.from)&&m.has(g.to)&&On(g)&&g.to!==p[0]))return f("body_step_has_edges",m.has(g.from)?g.from:g.to);w.push(g)}return w.length>0?{body:p,source:"body",edges:w}:{body:p,source:"body"}}function l(u,d){var p,m;const f=(m=(p=t.get(u))==null?void 0:p.with)==null?void 0:m.body;return Se(t.get(u))&&Array.isArray(f)&&f[0]===d}function c(u){var g;const d=o.filter(y=>y.from===u&&On(y)&&y.route===void 0);if(d.length===0)return{body:[],source:"body"};const f=y=>({invalid:{reason:"legacy_not_linear",stepId:y}});if(d.length>1)return f(u);const p=[],m=new Set([u]);let h=u,w=d[0].to;for(;w!==void 0;){const y=w,x=t.get(y);if(!x||m.has(y)||!Ls(x)||s.has(y))return f(y);const S=o.filter(O=>O.to===y);if(S.length!==1||S[0].from!==h)return f(y);const A=o.filter(O=>O.from===y);if(A.length>1||A.length===1&&!On(A[0]))return f(y);m.add(y),p.push(y),h=y,w=(g=A[0])==null?void 0:g.to}return{body:p,source:"legacy"}}}function je(e){var s;const t=(s=e.data)==null?void 0:s.when;return t==="error"?"error":t==="each"?"each":"success"}function qi(e,t){var s;return((s=e.find(o=>o.id===t))==null?void 0:s.id)??null}function Ui(e,t,s,o,r,a){var d,f;if(!e||!t||e===t||o.some(p=>{var m;return p.source===e&&p.target===t&&((m=p.data)==null?void 0:m.route)===a}))return!1;const i=(d=s.find(p=>p.id===e))==null?void 0:d.data.step,l=(f=s.find(p=>p.id===t))==null?void 0:f.data.step;if(!i||!l)return!1;const c=rn(i,r),u=rn(l,r);return c.out>=1&&u.in>=1}function To(e,t,s,o,r,a,i){var O,j,N;const l=r==="success"&&Se((O=s.find(k=>k.id===e))==null?void 0:O.data.step),c=l&&i===void 0?Ct:i;if(!Ui(e,t,s,o,a,c)||!e||!t)return null;const u=(j=s.find(k=>k.id===e))==null?void 0:j.data.step,d=(N=s.find(k=>k.id===t))==null?void 0:N.data.step;if(!u||!d)return null;const f=Ks(u);if(l){if(c!==Ct)return null}else if(u.uses.app===Qe&&r==="success"){if(!Js(u).some(k=>k.id===c))return null}else if(f&&r==="success"){if(c!==void 0&&c!==$n)return null}else if(c!==void 0)return null;const p=Je(s,o)[e]!==void 0,m=r==="success"&&p?"each":r;if(m==="each"&&!p&&!Se(u))return null;const h=Di(e,t,m,s,o,c);if(h)return{next:o,conflict:null,refusal:{refused:"loop",reason:h}};const w=rn(u,a),g=o,y=g.filter(k=>{var _;return k.source===e&&je(k)===m&&((_=k.data)==null?void 0:_.route)===c}),x=c===void 0||f||l?w.out:1;if(y.length>=x)return{next:o,conflict:null,refusal:{refused:"out_cap",cap:x}};const S=Tt(e,t,m,c),A=m==="each"&&p&&!Se(u)?void 0:Hs(m);return{next:bs.addEdge({source:e,target:t,id:S,sourceHandle:c===void 0?A:Jt(c),data:{when:m,...c===void 0?{}:{route:c}},...fn(m,void 0)},g),conflict:qi(g,S),refusal:null}}function Op(e,t,s,o,r="success",a,i){const l=To(e,t,s,o,r,a,i);return!l||l.conflict||l.refusal?null:l.next}function Ip(e,t,s,o,r="success",a,i){var l;return((l=To(e,t,s,o,r,a,i))==null?void 0:l.conflict)??null}function Rp(e,t,s,o,r="success",a,i){var l;return((l=To(e,t,s,o,r,a,i))==null?void 0:l.refusal)??null}function Oo(e,t,s,o,r){var x;const a=e.filter(S=>S.id===t);if(a.length!==1)return null;const i=a[0];if(je(i)==="each")return null;const l=(x=o.find(S=>S.id===i.source))==null?void 0:x.data.step;if(!l||l.uses.app===Qe||l.uses.app===zt)return null;const c=rn(l,r).out,u=e.filter(S=>S.id!==t);if((je(i)===s?[]:u.filter(S=>S.source===i.source&&je(S)===s)).length>=c)return{next:e,conflict:null,refusal:{refused:"out_cap",cap:c}};const f=fn(s,void 0),p=Se(l),m=p&&s==="success"?Ct:void 0,{route:h,...w}=i.data??{},g={...i,id:Tt(i.source,i.target,s,m),data:p?{...w,when:s,...m?{route:m}:{}}:{...i.data,when:s},className:f.className,label:f.label,sourceHandle:m?Jt(m):Hs(s)},y=qi(u,g.id);return{next:e.map(S=>S.id===t?g:S),conflict:y,refusal:null}}function $p(e,t,s,o,r){const a=Oo(e,t,s,o,r);return!a||a.conflict||a.refusal?null:a.next}function _p(e,t,s,o,r){var a;return((a=Oo(e,t,s,o,r))==null?void 0:a.conflict)??null}function Pp(e,t,s,o,r){var a;return((a=Oo(e,t,s,o,r))==null?void 0:a.refusal)??null}function Fp(e,t,s){return e.map(o=>{var i;const r=o.source===t?s:o.source,a=o.target===t?s:o.target;return{...o,source:r,target:a,id:Tt(r,a,je(o),typeof((i=o.data)==null?void 0:i.route)=="string"?o.data.route:void 0)}})}function Tt(e,t,s,o){const r=s==="error"?`${e}->${t}:error`:`${e}->${t}`;return o===void 0?r:`${r}:route:${encodeURIComponent(o)}`}function Lp(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function Wi(e,t){const s=Lp(e);if(s)return s;for(const o of t)if(o===e)return`A step named "${e}" already exists.`;return null}function Mp(e,t,s){const o=(f,p)=>!f||!p?void 0:Tt(f,p)===t?"success":Tt(f,p,"error")===t?"error":void 0,r=o(s[0],s[1]),a=o(s[2],s[3]),i=r!==void 0&&r===a,l=r!==void 0&&a!==void 0&&r!==a,c=r==="success"?s[1]:s[3],u=i?s.find(f=>!!f&&f.includes("->")):l&&(c!=null&&c.endsWith(":error"))?c:void 0,d=u===void 0?"Rename one of the steps it connects, then try again.":i?`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 “${t}” is already taken by another edge. ${d}`}const Dp=240,qp=100,Up=40,Wp=40;function Io(e,t){return{x:Up+e*Dp,y:Wp+t*qp}}function Hp(e,t){var l;const s=new Map,o=new Map;for(const c of e)s.set(c.id,0),o.set(c.id,[]);for(const c of t)(l=o.get(c.to))==null||l.push(c.from);const r=e.length+1;let a=0,i=!0;for(;i&&a<r;){a++,i=!1;for(const c of e){const u=o.get(c.id)??[];if(u.length===0)continue;const d=u.reduce((f,p)=>Math.max(f,(s.get(p)??0)+1),0);(s.get(c.id)??0)<d&&(s.set(c.id,d),i=!0)}}if(i){const c=Math.max(0,e.length-1);for(const[u,d]of s)d>c&&s.set(u,c)}return s}function Hi(e,t){var c;const s=Hp(e,t),o=new Map(e.map((u,d)=>[u.id,d])),r=new Map;for(const{from:u,to:d}of t){const f=s.get(u),p=s.get(d);if(f===void 0||p===void 0||f>=p)continue;const m=r.get(d);(m===void 0||f<(s.get(m)??0)||f===s.get(m)&&(o.get(u)??0)<(o.get(m)??0))&&r.set(d,u)}const a=new Map(e.map(u=>[u.id,[]]));for(const[u,d]of r)(c=a.get(d))==null||c.push(u);for(const u of a.values())u.sort((d,f)=>(s.get(f)??0)-(s.get(d)??0)||(o.get(d)??0)-(o.get(f)??0));const i=new Map;let l=0;for(const u of e.filter(d=>!r.has(d.id))){const d=[u.id];for(;d.length;){const f=d.pop();if(f===void 0)continue;i.set(f,Io(s.get(f)??0,l));const p=a.get(f)??[];if(p.length===0)l++;else for(let m=p.length-1;m>=0;m--)d.push(p[m])}}return i}function Bp(e){const t=e.position;if(!(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function Ro(e){const t=e;if(t.nodes!==void 0&&t.steps!==void 0)throw new Error("workflow carries both nodes and steps");const{steps:s,...o}=e;return{...o,nodes:t.nodes??t.steps??[]}}function Vp(e){const t=Ro(e),s=t.nodes;let o=Ao(t);const r=[],a=new Set(s.filter(Se).map(h=>h.id)),i=new Map,l=new Set,c=new Set;for(const[h,w]of Object.entries(Eo(t))){if("invalid"in w)continue;let g=h;if(w.edges&&w.body.length>0){r.push(Tn(h,w.body[0],!0));for(const y of w.edges)c.add(y),r.push(Tn(y.from,y.to,!1,y.route));for(const y of w.body)i.set(y,h);continue}for(const y of w.body){if(w.source==="legacy"){const x=o.find(S=>S.from===g&&S.to===y&&(S.when??"success")==="success");x&&c.add(x)}r.push(Tn(g,y,g===h,g!==h&&a.has(g)?Ct:void 0)),i.set(y,h),g=y}w.source==="legacy"&&l.add(h)}const u=new Set(s.filter(Se).map(h=>h.id));for(const h of o)u.has(h.from)&&Dn(h)&&c.add(h);c.size>0&&(o=o.filter(h=>!c.has(h)));const d=Hi(s,[...o,...r.map(h=>({from:h.source,to:h.target}))]),f=s.map(h=>{const w=it(h.uses.app);return{id:h.id,type:w?"control":"step",position:Bp(h)??d.get(h.id)??Io(0,0),data:{step:h,isInternal:w,...i.has(h.id)?{loopOf:i.get(h.id)}:{},...l.has(h.id)?{legacyLoop:!0}:{}}}}),p=new Set(s.filter(Ks).map(h=>h.id)),m=o.map(h=>{const w=h.when==="error"&&h.route===void 0&&p.has(h.from)?{from:h.from,to:h.to,route:$n}:u.has(h.from)&&h.route===void 0&&h.when!=="error"?{...h,route:Ct}:h,g=w.when??"success";return{id:Tt(w.from,w.to,g,w.route),source:w.from,target:w.to,sourceHandle:w.route===void 0?Hs(g):`route:${w.route}`,animated:!1,data:{when:g,...w.route===void 0?{}:{route:w.route}},...fn(g,void 0)}});return{nodes:f,edges:[...m,...r]}}function zp(e,t){const s=e.map(r=>({...r.data.step,id:r.id})),o=Hi(s,t.map(r=>({from:r.source,to:r.target})));return e.map(r=>({...r,position:o.get(r.id)??Io(0,0)}))}function Jp(e,t,s){var O,j;const o=Ro(e),r=((O=o.settings)==null?void 0:O.savePosition)!==!1,a=new Map(t.map(N=>[N.id,N])),i=N=>{var _;if(!r)return N;const k=(_=a.get(N.id))==null?void 0:_.position;return!k||!Number.isFinite(k.x)||!Number.isFinite(k.y)?N:{...N,position:{x:Math.round(k.x),y:Math.round(k.y)}}},l=new Map;for(const N of o.nodes)l.set(N.id,N);for(const N of t)(j=N.data)!=null&&j.step&&l.set(N.id,N.data.step);const c=es(t,s),u=Eo(o),d=new Map(o.nodes.map(N=>[N.id,N])),f=new Set;for(const N of s)je(N)==="success"&&f.add(N.source);const p=N=>{if(!Se(N))return N;const k=c.get(N.id)??[],_=d.get(N.id),U=u[N.id];let T;k.length>0?T={value:k}:U&&"invalid"in U&&U.invalid.reason!=="legacy_not_linear"?T=_!=null&&_.with&&"body"in _.with?{value:_.with.body}:null:U&&"invalid"in U?T=null:f.has(N.id)||_!=null&&_.with&&"body"in _.with?T={value:[]}:T=null;const F=N.with??{};return T===null?"body"in F?Co(N):N:{...N,with:{...F,body:T.value}}},m=N=>i(p(N)),h=[],w=new Set;for(const N of o.nodes){const k=l.get(N.id);k&&t.some(_=>_.id===N.id)&&(h.push(m(k)),w.add(N.id))}for(const N of t){if(w.has(N.id))continue;const k=l.get(N.id);k&&h.push(m(k))}const g=new Set;for(const N of c.values())for(const k of N)g.add(k);const y=new Set(t.filter(N=>{var k;return Se((k=N.data)==null?void 0:k.step)}).map(N=>N.id)),x=s.filter(N=>je(N)!=="each"&&!g.has(N.source)&&!g.has(N.target)).map(N=>{var _;const k=typeof((_=N.data)==null?void 0:_.route)=="string"?N.data.route:y.has(N.source)&&je(N)==="success"?Ct:void 0;return{from:N.source,to:N.target,...je(N)==="error"?{when:"error"}:{},...k===void 0?{}:{route:k}}}),S=[];for(const[N,k]of c)k.length>0&&S.push({from:N,to:k[0],route:ta});const A=[...x,...S,...kp(t,s)];return Ci({...o,nodes:h,edges:A})}function Bi(e){var s;const t=(s=e.settings)==null?void 0:s.viewport;if(!(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(t.zoom)))return{x:t.x,y:t.y,zoom:t.zoom}}function Kp(e,t){var i;if(!(((i=e.settings)==null?void 0:i.savePosition)!==!1)||!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(t.zoom))return e;const o={x:Math.round(t.x),y:Math.round(t.y),zoom:Math.round(t.zoom*1e3)/1e3},r=Bi(e);if(r&&r.x===o.x&&r.y===o.y&&r.zoom===o.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:o}}}function Gp(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function Yp(e,t){const s=new Set(t.map(o=>o.target));return e.find(o=>!s.has(o.id))}function Xp(e,t){const s=new Set(t.map(o=>o.source));for(let o=e.length-1;o>=0;o--)if(!s.has(e[o].id))return e[o]}function Zp(e,t="step"){const s=new Set(e);for(let o=1;o<1e3;o++){const r=`${t}_${o}`;if(!s.has(r))return r}return`${t}_${crypto.randomUUID().slice(0,8)}`}function $o(e){return JSON.stringify(Co(e),null,2)}const Qp=3,ef=100;function Ot(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Vi(e){if(!Array.isArray(e))return;const t=[],s=new Set,o=r=>{s.has(r.key)||(s.add(r.key),t.push(r))};for(const r of e){if(!Ot(r)||typeof r.key!="string"||r.key==="")continue;const a=typeof r.label=="string"&&r.label!==""?r.label:void 0;if(o({key:r.key,...a?{label:a}:{},path:!0}),r.type==="array"&&Array.isArray(r.items))for(const i of r.items){if(!Ot(i)||typeof i.key!="string"||i.key==="")continue;const l=typeof i.label=="string"&&i.label!==""?i.label:void 0;o({key:`${r.key}.0.${i.key}`,...l?{label:l}:{},path:!0})}}return t.length>0?t:void 0}function tf(e,t){var o;if(!Array.isArray(e))return;const s=e.find(r=>Ot(r)&&r.key===t);if(!(!Ot(s)||!Array.isArray(s.items)))return(o=Vi([{key:t,type:"array",items:s.items}]))==null?void 0:o.filter(r=>r.key!==t).map(r=>({...r,key:r.key.slice(t.length+3)}))}function St(e){if(!Ot(e))return;const t=[],s=(o,r,a)=>{for(const[i,l]of Object.entries(o)){if(t.length>=ef)return;const c=r?`${r}.${i}`:i;t.push({key:c,path:!0}),Ot(l)&&a<Qp&&s(l,c,a+1)}};return s(e,"",1),t.length>0?t:void 0}function tn(e,t){let s=e;for(const o of t.split(".")){if(!Ot(s)||!(o in s))return;s=s[o]}return s}function kt(e,t,s){const o=Vi(e==null?void 0:e.output),r=St(t),a=r??St(s);if(a){const l=new Map((o??[]).map(d=>[d.key,d])),c=new Set(a.map(d=>d.key)),u=a.map(d=>{const f=l.get(d.key);return f!=null&&f.label?{...d,label:f.label}:d});for(const d of o??[])c.has(d.key)||u.push({...d,declaredOnly:!0});return{fields:u,from:r?"fresh":"persisted"}}if(o)return{fields:o,from:"declared"};const i=St(e==null?void 0:e.sample);if(i)return{fields:i,from:"sample"}}function _o(e,t){const s=new Map;for(const a of t){const i=s.get(a.target)??[];i.push(a.source),s.set(a.target,i)}const o=new Set,r=[e];for(;r.length;){const a=r.pop();for(const i of s.get(a)??[])o.has(i)||(o.add(i),r.push(i))}return o}function zi(e,t,s={}){var i,l,c,u,d,f,p;const o=[];let r=!1,a;for(const m of t){if(!e.has(m.id))continue;const h=m.data.step;if(h.uses.app===zs)continue;const w=((i=At(h.uses.app,h.uses.action))==null?void 0:i.group)==="trigger",g=(l=s.testOutputs)==null?void 0:l[h.id],y=(c=s.persistedOutputs)==null?void 0:c[h.id];if(h.uses.trigger===!0){r=!0;const k=kt((u=s.triggerDef)==null?void 0:u.call(s,h.uses.app,h.uses.action),g,y);if(a??(a=k),k){o.push({id:h.id,label:h.id,outputs:k.fields,outputsFrom:k.from,trigger:!0});continue}}w&&(r=!0);const x=w&&h.uses.app===Vt,S=x?xo(bo((d=h.with)==null?void 0:d.fields)).map(k=>({key:k.key,label:k.label})):((f=At(h.uses.app,h.uses.action))==null?void 0:f.output)??[],A={id:h.id,label:h.id,...h.uses.trigger===!0?{trigger:!0}:{}};if(S.length>0){o.push({...A,outputs:S});continue}if(w){const k=kt(void 0,g,y);k&&!x&&(a??(a=k)),o.push(k?{...A,outputs:k.fields,outputsFrom:k.from}:A);continue}if(it(h.uses.app)){const k=kt(void 0,g,y);o.push(k?{...A,outputs:k.fields,outputsFrom:k.from}:A);continue}const O=(p=s.actionDef)==null?void 0:p.call(s,h.uses.app,h.uses.action),j=kt(O,g,y),N=h.uses.app.trim()!==""?{hasMeta:!0}:{};j?o.push({...A,outputs:j.fields,outputsFrom:j.from,...N}):o.push(O?{...A,needsTest:!0,...N}:{...A,...N})}return{steps:o,hasTrigger:r,...a?{eventOutputs:a.fields,eventOutputsFrom:a.from}:{}}}function nf(e,t){const s={};for(const[o,r]of Object.entries(t))s[o]={output:r};return Ji(e,{steps:s})}function Ji(e,t){if(ht(e)!==null){const s=no(e,Qs(void 0,t)),o=s.length===1?s[0]:void 0;return(o==null?void 0:o.status)==="resolved"&&Array.isArray(o.value)?o.value:void 0}return Array.isArray(e)?e:void 0}const sf=10;function of(e,t){return{input:t,with:{items:e.slice(0,sf),itemCount:e.length}}}function rf(e){var s;const t=(s=e==null?void 0:e.with)==null?void 0:s.items;return Array.isArray(t)&&t.length>0?t:void 0}function Ki(e,t,s,o,r={}){const a=Je(s,o),i=new Set;for(const f of e){if(f===t)continue;const p=a[f];p!==void 0&&p!==t||i.add(f)}const l=zi(i,s,r),c=es(s,o),u=[];return{steps:l.steps.map(f=>{var x,S,A;const p=c.get(f.id);if(!p||p.length===0)return f;const m=p[p.length-1],h=(x=s.find(O=>O.id===m))==null?void 0:x.data.step,w=r.testOutputs??{},g=h?kt((S=r.actionDef)==null?void 0:S.call(r,h.uses.app,h.uses.action),w[m],(A=r.persistedOutputs)==null?void 0:A[m]):void 0;u.includes(m)||u.push(m);const y=((g==null?void 0:g.fields)??[]).map(O=>({key:`items.0.${O.key}`,path:!0,...O.declaredOnly?{declaredOnly:!0}:{}}));return{id:f.id,label:f.label,outputs:[{key:"items",path:!0},...y],...g?{outputsFrom:g.from}:{}}}),hasTrigger:l.hasTrigger,extraSampleIds:u,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{}}}function af(e){const t=e.trim().split(".");if(!(t[0]!=="nodes"&&t[0]!=="steps"||t.length<4||t[2]!=="output"))return{id:t[1],path:t.slice(3).join(".")}}function lf(e,t,s){var f,p;const o=ht(e),r=o?af(o):void 0,a=r?(f=t.find(m=>m.id===r.id))==null?void 0:f.data.step:void 0;if(!r||!a)return;const i=(p=s.actionDef)==null?void 0:p.call(s,a.uses.app,a.uses.action),l=tn(i==null?void 0:i.sample,r.path),c=Array.isArray(l)&&l.length>0?l[0]:void 0,d=tf(i==null?void 0:i.output,r.path)??St(c);if(!(c===void 0&&!d))return{...c!==void 0?{itemSample:c}:{},...d?{itemOutputs:d}:{}}}function Gi(e,t,s={},o=[]){const r=Dr(e,t,s),a=Mi(e,t,o);return a.length===0?r:{...r,outer:a.map(i=>({...Dr(i,t,s),name:i}))}}function Dr(e,t,s={}){var u,d,f;const o={foreachId:e},r=(d=(u=t.find(p=>p.id===e))==null?void 0:u.data.step.with)==null?void 0:d.items,a={...s.persistedOutputs??{},...s.testOutputs??{}},i=nf(r,a),l=i&&i.length>0?i:(f=s.loopSamples)==null?void 0:f[e];if(l&&l.length>0){o.itemSample=l[0];const p=St(l[0]);return p&&(o.itemOutputs=p),o}const c=lf(r,t,s);return(c==null?void 0:c.itemSample)!==void 0&&(o.itemSample=c.itemSample),c!=null&&c.itemOutputs&&(o.itemOutputs=c.itemOutputs),o}function Yi(e,t,s,o){return!e&&!!t&&!o.some(r=>r.target===t)&&Je(s,o)[t]===void 0}function cf(e,t,s,o,r){let a=e;if(!a&&r&&!Yi(e,r,t,s)&&(a=r),!a)return zi(new Set(t.map(c=>c.id)),t,o);const i=Je(t,s)[a],l=Ki(_o(a,s),i,t,s,o);return i&&!l.extraSampleIds.includes(i)&&l.extraSampleIds.push(i),{steps:l.steps,hasTrigger:l.hasTrigger,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{},...i?{loop:Gi(i,t,o,s)}:{},...l.extraSampleIds.length>0?{extraSampleIds:l.extraSampleIds}:{}}}function uf(e,t,s,o){if(!e||e.handleType==="target")return[];const r=_o(e.nodeId,s);r.add(e.nodeId);const a=Xi(e,t,s);return Ki(r,a,t,s,o).steps}function Xi(e,t,s){const o=t.find(r=>r.id===e.nodeId);return e.lane==="each"&&Se(o==null?void 0:o.data.step)?e.nodeId:Je(t,s)[e.nodeId]}function df(e,t,s,o){if(!e||e.handleType==="target")return;const r=Xi(e,t,s);return r?Gi(r,t,o,s):void 0}async function pf(e,t){return(await Promise.all(t.map(async o=>{try{const r=await e(o.id),a=r.length?r[r.length-1]:null;return a?{stepId:o.id,label:o.label??o.id,test:a}:null}catch{return null}}))).filter(o=>o!==null)}function Po(e,t,s){const o=ff(e,t);return!s||Object.keys(s).length===0?o:{...o??{},state:s}}function ff(e,t){const s={};for(const r of e){const a=r.test.lastRunOutput,i=a!=null;if(!i&&r.test.lastRunStatus!=="succeeded")continue;const l=r.test.lastRunMeta;s[r.stepId]={output:i?a:null,...l?{meta:l}:{}}}const o=Object.keys(s).length>0;return t?{...o?{steps:s}:{},foreach:{...t.item!==void 0?{item:t.item}:{},index:t.index??0,...t.loops?{loops:t.loops}:{}}}:o?{steps:s}:void 0}function Zi(e){if(!e)return;const t=o=>({..."itemSample"in o?{item:o.itemSample}:{},index:0}),s=[...e.outer??[],e];return{...t(e),loops:Object.fromEntries(s.map(o=>[o.foreachId,t(o)]))}}function hf(e){return!e||!("itemSample"in e)?"":JSON.stringify(e.itemSample,null,2)??""}function mf(e,t){let s;if(e.trim()!=="")try{s=JSON.parse(e)}catch{return{ok:!1,error:"The current item must be valid JSON."}}const o=t.trim()===""?0:Number(t.trim());return!Number.isInteger(o)||o<0?{ok:!1,error:"The index must be a whole number, 0 or more."}:{ok:!0,value:{...s!==void 0?{item:s}:{},index:o}}}function wf(e,t){if(!t)return{};const s={};for(const o of["nodes","steps"]){const r=`${o}.${e}.meta`;s[`${r}.app`]=t.app,s[`${r}.version`]=t.version,s[`${r}.action`]=t.action,s[`${r}.connectionId`]=t.connectionId}return s}function bf(e,t,s,o,r){return Qi(e,t,s,o,r).values}function yf(e,t,s,o,r){return Qi(e,t,s,o,r).sources}function gf(e,t){var r,a,i,l;const s={};let o;for(const c of e){const u=c.data.step.uses;if(u.trigger===!0){const f=(a=(r=t.triggerDef)==null?void 0:r.call(t,u.app,u.action))==null?void 0:a.sample;o===void 0&&f!==void 0&&(o=f);continue}if(it(u.app))continue;const d=(l=(i=t.actionDef)==null?void 0:i.call(t,u.app,u.action))==null?void 0:l.sample;d!==void 0&&(s[c.id]=d)}return{samples:s,...o!==void 0?{event:o}:{}}}function Qi(e,t,s,o,r={}){var l,c;const a={},i={};for(const u of e){Object.assign(a,wf(u.id,s[u.id]));const d=[["sample",(l=r.samples)==null?void 0:l[u.id]],["persisted",(c=r.persisted)==null?void 0:c[u.id]],["fresh",t[u.id]]];for(const[f,p]of d){if(p===void 0)continue;const m=(h,w)=>{for(const g of["nodes","steps"])a[`${g}.${h}`]=w,i[`${g}.${h}`]=f};if(m(`${u.id}.output`,p),typeof p=="object"&&p!==null&&!Array.isArray(p))for(const[h,w]of Object.entries(p))m(`${u.id}.output.${h}`,w);for(const h of u.outputs??[]){if(!h.path||!h.key.includes("."))continue;const w=tn(p,h.key);w!==void 0&&m(`${u.id}.output.${h.key}`,w)}}}if(r.event!==void 0){const u=(d,f)=>{a[d]=f,i[d]="sample"};if(u("trigger.event",r.event),typeof r.event=="object"&&r.event!==null&&!Array.isArray(r.event))for(const[d,f]of Object.entries(r.event))u(`trigger.event.${d}`,f);for(const d of St(r.event)??[]){const f=tn(r.event,d.key);f!==void 0&&u(`trigger.event.${d.key}`,f)}}if(o&&"itemSample"in o){a["foreach.item"]=o.itemSample;for(const u of o.itemOutputs??[]){const d=tn(o.itemSample,u.key);d!==void 0&&(a[`foreach.item.${u.key}`]=d)}a["foreach.index"]=0}return{values:a,sources:i}}function xf(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=e;if(t.type==="secret"||t.type==="expr")return!0;const s=Object.keys(t);return s.length===1&&s[0]==="$"}function vf(e){const t=[];for(const s of e){const o=s.data.step,r=Object.entries(o.with??{}).filter(([,i])=>i!==void 0&&!xf(i)).map(([i])=>i);(o.uses.app===ze||o.uses.app===ut||o.uses.trigger===!0)&&!r.includes("url")&&r.unshift("url"),r.length>0&&t.push({id:o.id,keys:r})}return t}function Ms(e){if(!(tt(e)||pt(e))){if(Array.isArray(e))return e.map(Ms).filter(t=>t!==void 0);if(typeof e=="object"&&e!==null){const t=e,s=Object.keys(t);if(s.length===1&&s[0]==="$"&&typeof t.$=="string")return;const o={};for(const[r,a]of Object.entries(t)){const i=Ms(a);i!==void 0&&(o[r]=i)}return o}return e}}function jf(e,t){const s={};for(const o of e){const r=o.data.step,a={...Ms(r.with??{})??{}},i=el(r,t),l=(i==null?void 0:i.webhookUrl)??(i==null?void 0:i.formUrl);l&&(a.url=l),Object.keys(a).length>0&&(s[r.id]=a)}return s}function el(e,t){if(e.uses.app===ut)return wo(t,e.id)??void 0;if(!(e.uses.app!==ze&&e.uses.trigger!==!0))return t.find(s=>s.nodeId===e.id)??(e.uses.app===ze?t.find(s=>s.appId===ze):void 0)}function kf(e,t,s,o){var a;const r={};for(const i of e){const l=i.data.step;if(!l.uses.app)continue;const c={app:l.uses.app,action:l.uses.action,connectionId:Kt(l,o)??null},u=(a=s==null?void 0:s.get(l.uses.app))==null?void 0:a.version;u&&(c.version=u);const d=el(l,t);d&&(c.subscriptionId=d.id),d!=null&&d.webhookUrl&&(c.url=d.webhookUrl),r[l.id]=c}return r}function Nf(e){const t={};for(const[s,o]of Object.entries(e))for(const[r,a]of Object.entries(o))t[`nodes.${s}.meta.${r}`]=a,t[`steps.${s}.meta.${r}`]=a;return t}function Sf(e,t){const s={success:0,error:0};for(const r of t){if(r.source!==e)continue;const a=je(r);a!=="each"&&s[a]++}const o=Math.max(s.success,s.error);return{enabled:o>=2,count:o}}function Cf(e,t){const{fanOut:s,...o}=e;return t==="parallel"?{...o,fanOut:"parallel"}:o}function Af(e,t){return`Runs these ${e} nodes in ${t==="parallel"?"parallel":"sequence"}`}function tl({step:e,count:t,readOnly:s,onChange:o}){const r=t>=2,a=e.fanOut==="parallel"?"parallel":"sequential";return n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Run next nodes"}),n.jsxs("select",{"aria-label":"Run next nodes",value:a,disabled:s||!r,onChange:i=>o(Cf(e,i.target.value)),children:[n.jsx("option",{value:"sequential",children:"In sequence"}),n.jsx("option",{value:"parallel",children:"In parallel"})]}),!r&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function qr({to:e}){return n.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[n.jsx("span",{children:"From this step output"}),n.jsx("span",{}),n.jsx("span",{children:e})]})}function Ur(){return n.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function Wr({label:e,fields:t,value:s,readOnly:o,onChange:r}){const a=b.useMemo(()=>(t??[]).map(i=>({value:i,label:i})),[t]);return n.jsx(et,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:a,value:s,disabled:o,emptyText:a.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:r})}function nl({step:e,inLoop:t,outputFields:s,readOnly:o,onChange:r}){const a=bp(e),i=ie.validateStateConfig(a),l=f=>r(gp(e,f)),c=a.mode==="pick"&&Array.isArray(a.map)?a.map:[],u=(f,p)=>l({mode:"pick",map:c.map((m,h)=>h===f?{...m,...p}:m)}),d=f=>{if(a.mode!=="append")return;const p=f.path??a.path,m="from"in f?f.from:a.from;l({mode:"append",path:p,...m?{from:m}:{}})};return n.jsxs("div",{className:"w6w-field w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Write to state"}),n.jsx("select",{"aria-label":"Write to state",value:a.mode,disabled:o,onChange:f=>l(xp(e,f.target.value)),children:mp.map(f=>n.jsx("option",{value:f,children:wp[f]},f))})]}),a.mode==="key"&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"To state key"}),n.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:a.key,disabled:o,onChange:f=>l({mode:"key",key:f.target.value})}),n.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",n.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",n.jsx("code",{children:"order.id"})," nests."]})]}),a.mode==="pick"&&n.jsxs("div",{className:"w6w-stack",children:[n.jsx(qr,{to:"To state key"}),c.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),c.map((f,p)=>n.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[n.jsx(Wr,{label:"From output field",fields:s,value:f.from,readOnly:o,onChange:m=>u(p,{from:m})}),n.jsx(Ur,{}),n.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:f.to,disabled:o,onChange:m=>u(p,{to:m.target.value})}),!o&&n.jsx(ho,{label:"Remove field",onClick:()=>l({mode:"pick",map:c.filter((m,h)=>h!==p)})})]},p)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>l({mode:"pick",map:[...c,{from:"",to:""}]}),children:"+ Add field"}),n.jsxs("span",{className:"w6w-hint",children:["Copies ",n.jsx("code",{children:"output.<path>"})," into ",n.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),a.mode==="append"&&n.jsxs("div",{className:"w6w-stack",children:[n.jsx(qr,{to:"Append to state list"}),n.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[n.jsx(Wr,{label:"Output field to append",fields:s,value:a.from??"",readOnly:o,onChange:f=>d({from:f})}),n.jsx(Ur,{}),n.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:a.path,disabled:o,onChange:f=>d({path:f.target.value})})]}),n.jsxs("span",{className:"w6w-hint",children:["Appends ",n.jsx("code",{children:"output.<path>"})," to the list at ",n.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),i.length>0&&n.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:i.map(f=>n.jsx("div",{children:f.message},`${f.code}:${f.message}`))}),a.mode!=="off"&&n.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",n.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),t&&n.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function Fo(e,t,s){const o=Ce(),[r,a]=b.useState([]),i=JSON.stringify(t.map(l=>[l.id,l.label]));return b.useEffect(()=>{const l=JSON.parse(i);if(!s||l.length===0){a([]);return}let c=!1;return pf(u=>o.listStepTests(e,u),l.map(([u,d])=>({id:u,label:d}))).then(u=>{c||a(u)}),()=>{c=!0}},[o,e,i,s]),r}function Lo(e){return(e.nodes??e.steps??[]).filter(t=>t.uses.app===Vt&&t.uses.action==="manual")}function Ef(e,t){var a;const s=Lo(e),o=t?s.find(i=>i.id===t):s[0],r=(a=o==null?void 0:o.with)==null?void 0:a.fields;return Array.isArray(r)?r.flatMap(i=>!i||typeof i!="object"||typeof i.key!="string"||!i.key.trim()?[]:[{key:i.key,label:i.key,type:yo(i.type),default:go(i.type,i.default),required:!!i.required}]):[]}const Tf=["function","workflow"],Of={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"/>'},ms={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},If=["props","code","params-code","config"];function ts({view:e,onChange:t,disabled:s,views:o=If,customized:r=!1}){const a=i=>n.jsx("button",{type:"button",title:ms[i].label,"aria-label":ms[i].label,"aria-pressed":e===i,disabled:s,className:`w6w-icon-btn${e===i&&!s?" active":""}`,onClick:()=>t(i),children:n.jsx(le.Icon,{name:ms[i].icon,size:15})},i);return n.jsxs("div",{className:"w6w-view-toggle",children:[r&&n.jsx("button",{type:"button",className:"w6w-json-customized",disabled:s,onClick:()=>t("params-code"),title:"JSON customization adds or overrides form values",children:"JSON customized"}),o.map(a)]})}function Rf({onClose:e,onDone:t,onAdd:s,onDraftChange:o,theme:r,appsOnly:a,callables:i=Tf,initialTab:l,title:c,workflowId:u,stepId:d,upstreamSteps:f=[],loop:p,initialApp:m,initialAction:h,initialConnection:w,initialWith:g,appsFilter:y,appsIds:x,connectionOnly:S,setupOnly:A,addLabel:O,onConnected:j,excludeCallableIds:N,onOpenStep:k,stepIds:_=[]}){const[U,T]=b.useState(null),[F,E]=b.useState(null),P=b.useRef(null),I=D=>{const re=s(D);return typeof re=="string"&&(P.current=D,T(re),E(null)),re},G=o?(D,re)=>{P.current=re,o(D,re)}:void 0,W=()=>{U&&F&&F!==U&&G&&P.current&&G(U,{...P.current,id:F}),(t??e)()},$=D=>U&&o?n.jsxs("span",{className:"w6w-stepbuilder-title",children:[D,n.jsx(si,{value:F??U,onCommit:re=>{const me=Wi(re,_.filter(Oe=>Oe!==U));return me||E(re),me}})]}):D,[R,z]=b.useState(l??"connected"),[K,ne]=b.useState(""),[B,Y]=b.useState(!1),J=K.trim()!==""&&!B,M=D=>{z(D),Y(!0)},[te,ee]=b.useState(m??null),[C,V]=b.useState(null),[Q,ae]=b.useState(null),[X,ke]=b.useState(null),be=D=>{if(!A)return ke(D);s({uses:{app:hn,action:"call"},with:{targetKind:D.family,targetId:D.id}})},ye=!!x&&x.length>0,ge=rl(i,y,N,x),xe=ge.state!=="empty";if(b.useEffect(()=>{!xe&&R==="connected"&&z("apps")},[xe,R]),X)return n.jsx(Ee,{title:$(X.label),ariaLabel:X.label,subtitle:n.jsx("code",{children:X.id}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>ke(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(Df,{family:X.family,targetId:X.id,targetLabel:X.label,onAdd:I,onClose:e,onDone:W,onDraftChange:G})})});if(C)return n.jsx(Ee,{title:$(C.groupActions?C.displayName:C.label),ariaLabel:C.groupActions?C.displayName:C.label,titleIcon:n.jsx(Qn,{icon:C.icon,size:22}),subtitle:n.jsxs("code",{children:[C.app,!C.groupActions&&` · ${C.action}`]}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>V(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(Mf,{node:C,onAdd:I,onClose:e,onDone:W,onDraftChange:G,onOpenStep:k,workflowId:u,upstreamSteps:f,loop:p})})});const ue=Q??te;if(ue){const D=Q?"trigger":"action",re=()=>{ee(null),ae(null)};return n.jsx(Ee,{title:$(ue.displayName),ariaLabel:ue.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:ue.id}),ue.version&&` · v${ue.version}`]}),onClose:e,size:"xl",titleIcon:n.jsx(It,{src:ue.iconSvg,srcDark:ue.iconSvgDark,brandColor:ue.brandColor,name:ue.displayName,theme:r,size:22}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:S&&D==="action"?n.jsx(Gf,{appId:ue.id,app:ue,onClose:e,onChangeApp:re,theme:r,initialConnection:w,onConnected:(me,Oe)=>j==null?void 0:j(me,Oe)}):n.jsx(Kf,{kind:D,onOpenStep:k,appId:ue.id,app:ue,onAdd:I,onClose:e,onDone:W,onDraftChange:G,onChangeApp:re,theme:r,workflowId:u,stepId:d,upstreamSteps:f,loop:p,...D==="action"?{initialAction:h,initialConnection:w,initialWith:g}:{},setupOnly:A&&D==="action",addLabel:O})})})}return n.jsx(Ee,{title:c??"Add a node",onClose:e,size:"xl",children:n.jsxs("div",{className:"w6w-stepbuilder-picker",children:[n.jsx("input",{type:"search",className:"w6w-stepbuilder-search","aria-label":"Search nodes and apps",placeholder:"Search apps, workflows and nodes…",value:K,onChange:D=>{ne(D.target.value),Y(!1)}}),n.jsxs("div",{className:"w6w-stepbuilder",children:[n.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[xe&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="connected"?" active":""}`,onClick:()=>M("connected"),children:"Ready to use"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="apps"?" active":""}`,onClick:()=>M("apps"),children:"Apps"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="ai"?" active":""}`,onClick:()=>M("ai"),children:"AI"}),i.includes("workflow")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="workflows"?" active":""}`,onClick:()=>M("workflows"),children:"Workflows"}),i.includes("function")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="functions"?" active":""}`,onClick:()=>M("functions"),children:"Functions"}),!a&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="triggers"?" active":""}`,onClick:()=>M("triggers"),children:"Triggers"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="controls"?" active":""}`,onClick:()=>M("controls"),children:"Controls"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="utilities"?" active":""}`,onClick:()=>M("utilities"),children:"Utilities"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&R==="data"?" active":""}`,onClick:()=>M("data"),children:"Data"})]})]}),n.jsx("div",{className:"w6w-stepbuilder-content",children:J?n.jsx($f,{query:K,builtIns:!a,callables:i,excludeCallableIds:N,appsFilter:y,appsIds:x,theme:r,onSelectNode:V,onSelectApp:ee,onSelectCallable:be}):R==="connected"?n.jsx(zf,{data:ge,query:K,appsFilter:y,onSelectApp:ee,onSelectCallable:be,theme:r}):R==="functions"?n.jsx(qn,{family:"function",query:K,excludeIds:N,onSelect:D=>be({family:"function",...D})}):R==="workflows"?n.jsx(qn,{family:"workflow",query:K,excludeIds:N,onSelect:D=>be({family:"workflow",...D})}):R==="apps"?n.jsx(lt,{search:!1,searchValue:K,onSelectApp:ee,theme:r,filter:y,ids:x}):R==="ai"?n.jsx(lt,{search:!1,searchValue:K,onSelectApp:ee,theme:r,category:ye?void 0:"ai",ids:x,filter:D=>{var re;return((y==null?void 0:y(D))??!0)&&(ye||(((re=D.categories)==null?void 0:re.includes("ai"))??!1))},emptyMessage:"No AI apps registered yet."}):R==="triggers"?n.jsx(_f,{query:K,onSelect:V,onSelectApp:ae,theme:r,appsFilter:y,appsIds:x}):R==="controls"?n.jsx(Pf,{query:K,onSelect:V}):R==="data"?n.jsx(Lf,{query:K,onSelect:V}):n.jsx(Ff,{query:K,onSelect:V})})]})]})})}function nn(e,...t){const s=t.filter(Boolean).join(" ").toLowerCase();return e.trim().toLowerCase().split(/\s+/).every(o=>s.includes(o))}function Mo(e,t){return nn(t,e.label,e.displayName,e.app,e.action)}function $f({query:e,builtIns:t,callables:s,excludeCallableIds:o,appsFilter:r,appsIds:a,theme:i,onSelectNode:l,onSelectApp:c,onSelectCallable:u}){const d=new Set,f=t?dt.filter(p=>p.hidden||!Mo(p,e)?!1:p.groupActions?d.has(p.app)?!1:(d.add(p.app),!0):!0):[];return n.jsxs("div",{className:"w6w-stepbuilder-results","data-testid":"stepbuilder-search-all",children:[f.length>0?n.jsxs("section",{className:"w6w-stepbuilder-results-section",children:[n.jsx("h4",{children:"Built-in"}),n.jsx("div",{className:"w6w-stepbuilder-list",children:f.map(p=>n.jsx(qo,{node:p,onSelect:l},`${p.app}:${p.action}`))})]}):null,n.jsxs("section",{className:"w6w-stepbuilder-results-section",children:[n.jsx("h4",{children:"Apps"}),n.jsx(lt,{search:!1,searchValue:e,onSelectApp:c,theme:i,filter:r,ids:a})]}),s.includes("workflow")?n.jsx(qn,{section:!0,family:"workflow",query:e,excludeIds:o,onSelect:p=>u({family:"workflow",...p})}):null,s.includes("function")?n.jsx(qn,{section:!0,family:"function",query:e,excludeIds:o,onSelect:p=>u({family:"function",...p})}):null]})}function Do({nodes:e,onSelect:t,query:s}){const o=new Set,r=e.filter(a=>Mo(a,s)?a.groupActions?o.has(a.app)?!1:(o.add(a.app),!0):!0:!1);return r.length?n.jsx("div",{className:"w6w-stepbuilder-list",children:r.map(a=>n.jsx(qo,{node:a,onSelect:t},`${a.app}:${a.action}`))}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No nodes match “",s,"”."]})}function qo({node:e,onSelect:t}){return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>t(e),children:[n.jsx(Qn,{icon:e.icon,size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:e.groupActions?e.displayName:e.label}),n.jsxs("code",{className:"w6w-muted w6w-small",children:[e.app,!e.groupActions&&` · ${e.action}`]})]})]})}function _f({query:e,onSelect:t,onSelectApp:s,theme:o,appsFilter:r,appsIds:a}){var h;const i=Ce(),l=dt.filter(w=>w.group==="trigger"&&Mo(w,e)),[c,u]=b.useState(!1),d=rl([],r,void 0,a,{resolveInline:!0});if(c)return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>u(!1),children:"← Back"}),n.jsx(lt,{onSelectApp:s,theme:o,filter:r,ids:a?[...a]:void 0,hasTriggers:!0,search:!1,searchValue:e,emptyMessage:"No apps declare triggers yet."})]});const p=d.apps.filter(w=>(w.triggerCount??0)>0&&nn(e,w.displayName,w.id)).sort(sn(w=>w.displayName)).map(w=>n.jsx(al,{app:w,theme:o,onSelect:s},w.id));d.moreApps&&p.push(n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:d.loadMoreApps,children:"Load more"},"__load_more_apps"));let m;return d.state==="error"?m=n.jsx("div",{className:"w6w-result w6w-error",children:d.error}):d.state==="loading"?m=n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):e.trim()&&((h=d.appIds)!=null&&h.length)&&typeof i.listAppsPage=="function"?m=n.jsx(lt,{search:!1,searchValue:e,ids:d.appIds,hasTriggers:!0,filter:r,onSelectApp:s,theme:o}):p.length===0?m=n.jsxs("p",{className:"w6w-muted w6w-small w6w-readytouse-empty",children:[e.trim()?`No connected apps match “${e}”.`:"No connected apps with triggers yet"," ","·"," ",n.jsx("button",{type:"button",className:"w6w-linkbtn",onClick:()=>u(!0),children:"Search all apps"})]}):m=n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:p}),n.jsxs("div",{className:"w6w-apppicker-host",children:[n.jsxs("div",{className:"w6w-readytouse","data-cols":2,children:[n.jsxs("section",{className:"w6w-readytouse-col","data-col":"your-apps",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Your apps"}),m]}),n.jsx("div",{className:"w6w-readytouse-stack",children:n.jsxs("section",{className:"w6w-readytouse-col","data-col":"built-in",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Built-in"}),n.jsxs("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:[l.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:["No built-in triggers match “",e,"”."]}),l.map(w=>n.jsx(qo,{node:w,onSelect:t},`${w.app}:${w.action}`))]})]})})]}),n.jsx("div",{className:"w6w-readytouse-footer",children:n.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>u(!0),children:"Search all apps"})})]})}function Pf({onSelect:e,query:t}){const s=dt.filter(o=>o.group==="control"&&!o.hidden);return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes branch, route, join paths, loop, parallelize, pause, or stop the run."}),n.jsx(Do,{nodes:s,onSelect:e,query:t})]})}function Ff({onSelect:e,query:t}){const s=dt.filter(o=>o.group!=="control"&&o.group!=="trigger"&&o.app!==on&&o.app!==Vs&&o.app!==Ve&&!o.hidden);return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Run scripts, work with regular expressions, render templates, call models, or make HTTP requests."}),n.jsx(Do,{nodes:s,onSelect:e,query:t})]})}function Lf({onSelect:e,query:t}){const s=dt.filter(o=>(o.app===on||o.app===Ve||o.app===Vs)&&!o.hidden);return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Set data, read documents, read and write store entries, or query stored rows."}),n.jsx(Do,{nodes:s,onSelect:e,query:t})]})}function Mf({node:e,onAdd:t,onClose:s,onDone:o,onDraftChange:r,onOpenStep:a,workflowId:i,upstreamSteps:l=[],loop:c}){var W,$;const[u,d]=b.useState(e),f=e.groupActions?dt.filter(R=>R.app===e.app&&!R.hidden):[],[p,m]=b.useState(()=>Pn(u.app,u.action)),h=!Dt(u.app),w=Fo(i??"",l,h&&!!i),g=(W=nt().stateShape)==null?void 0:W.written,y=Po(w,Zi(c),g),[x,S]=b.useState("configure"),[A,O]=b.useState("props"),[j,N]=b.useState("{}"),[k,_]=b.useState({}),U=Bt(u.params,p),[T,F]=b.useState(null),E=()=>({uses:{app:u.app,action:u.action},with:p,...k});b.useEffect(()=>{if(!r)return;const R=t(E());R&&F(R),R&&(u.app===ze||u.app===ut)&&(a==null||a(R))},[]),b.useEffect(()=>{!r||T===null||r(T,E())},[T,p,k,u]);const P=R=>{R==="code"&&N($o(E())),O(R)},I=()=>t(E()),G=i&&T!==null?{workflowId:i,stepId:T,input:{}}:void 0;return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsxs("div",{className:"w6w-tabsbar",children:[n.jsxs("div",{className:"w6w-subtabs",children:[n.jsx("button",{type:"button",className:`w6w-subtab${x==="configure"?" active":""}`,onClick:()=>S("configure"),children:"Configure"}),h&&n.jsx("button",{type:"button",disabled:!U,title:U?void 0:"Fill the required fields first",className:`w6w-subtab${x==="test"?" active":""}`,onClick:()=>U&&S("test"),children:"Test"})]}),n.jsx(ts,{view:A,customized:Zn(p),onChange:P,disabled:x!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[x==="configure"&&A==="props"&&f.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Action"}),n.jsx("select",{className:"w6w-input","aria-label":"Action",value:u.action,onChange:R=>{const z=f.find(ne=>ne.action===R.target.value);if(!z)return;const K=Pn(z.app,z.action);m(Object.fromEntries(z.params.flatMap(ne=>ne.key in p?[[ne.key,p[ne.key]]]:ne.key in K?[[ne.key,K[ne.key]]]:[]))),d(z)},children:f.map(R=>n.jsx("option",{value:R.action,children:R.label},R.action))})]}),x==="configure"&&(A==="props"?u.app===zt?n.jsx("p",{className:"w6w-muted w6w-small",children:sa}):u.action==="wait"&&Dt(u.app)?n.jsx(ki,{values:p,onChange:m}):u.action==="if"&&Dt(u.app)?n.jsx(Xn,{values:p,onChange:m}):u.app===zs?n.jsx(oi,{values:p,onChange:m}):u.app===Qe?n.jsx(ni,{values:p,onChange:m}):n.jsx(Ue,{params:u.params,values:p,onChange:m}):A==="code"?n.jsx(Ze,{value:j,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):A==="params-code"?n.jsx(fo,{values:p,onChange:m}):n.jsx(ol,{step:{id:T??"",...E()},config:k,onChange:_,inLoop:c!==void 0,outputFields:($=u.output)==null?void 0:$.map(R=>R.key),failureHandling:!_n(u.app),retryControls:!Dt(u.app)&&u.app!==hn})),x==="test"&&h&&(_n(u.app)?n.jsx(ji,{app:u.app,action:u.action,fields:p.fields,persist:G},(G==null?void 0:G.stepId)??""):n.jsx(Uo,{app:u.app,action:u.action,values:p,timeoutMs:k.timeoutMs,canRun:U,state:y,persist:G},(G==null?void 0:G.stepId)??""))]}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),x==="configure"&&h?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!U,onClick:()=>S("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:T!==null?o??s:I,children:T!==null?"Done":"Add node"})]})]})}function qn({family:e,query:t,excludeIds:s,onSelect:o,section:r=!1}){const a=Ce(),[i,l]=b.useState(null),[c,u]=b.useState(null),d=e==="function"?"Functions":"Workflows";b.useEffect(()=>{let g=!1;return(e==="function"?a.listFunctions():a.listWorkflows()).then(x=>!g&&l(x)).catch(x=>!g&&u(x.message)),()=>{g=!0}},[a,e]);const f=g=>n.jsx("div",{className:"w6w-apppicker-host",children:g});if(r&&(c||i===null||i.length===0))return null;if(c)return f(n.jsx("div",{className:"w6w-result w6w-error",children:c}));if(i===null)return f(n.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",d.toLowerCase(),"…"]}));if(i.length===0)return f(n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",d.toLowerCase()," registered yet."]}));const p=qt,m=t.trim().toLowerCase(),h=Ds(i,s).sort(sn(p)),w=m?h.filter(g=>p(g).toLowerCase().includes(m)||g.id.toLowerCase().includes(m)):h;return r?w.length===0?null:n.jsxs("section",{className:"w6w-stepbuilder-results-section",children:[n.jsx("h4",{children:d}),n.jsx("div",{className:"w6w-stepbuilder-list",children:w.map(g=>n.jsx(Un,{family:e,item:g,onSelect:o},g.id))})]}):f(n.jsx("div",{className:"w6w-stepbuilder-apps",children:w.length===0?n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",d.toLowerCase()," match “",t,"”."]}):n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:w.map(g=>n.jsx(Un,{family:e,item:g,onSelect:o},g.id))})}))}function Df({family:e,targetId:t,targetLabel:s,onAdd:o,onClose:r,onDone:a,onDraftChange:i}){const[l,c]=b.useState({targetKind:e,targetId:t,inputs:{},wait:!0}),[u,d]=b.useState(!1),[f,p]=b.useState("configure"),[m,h]=b.useState(null),w=()=>({uses:{app:hn,action:"call"},with:l});b.useEffect(()=>{if(!i)return;const y=o(w());y&&h(y)},[]),b.useEffect(()=>{!i||m===null||i(m,w())},[m,l]);const g=()=>o(w());return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-tabsbar",children:n.jsxs("div",{className:"w6w-subtabs",children:[n.jsx("button",{type:"button",className:`w6w-subtab${f==="configure"?" active":""}`,onClick:()=>p("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!u,title:u?void 0:"Fill the required fields first",className:`w6w-subtab${f==="test"?" active":""}`,onClick:()=>u&&p("test"),children:"Test"})]})}),n.jsx("div",{className:"w6w-stepconfig-body",children:f==="configure"?n.jsx(ll,{fixedTarget:!0,values:l,onChange:c,onValidityChange:d,targetLabel:s}):n.jsx(qf,{family:l.targetKind==="function"?"function":"workflow",targetId:String(l.targetId),inputs:l.inputs,entry:typeof l.entry=="string"?l.entry:void 0,canRun:u})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:r,children:"Cancel"}),f==="configure"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!u,onClick:()=>p("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:m!==null?a??r:g,children:m!==null?"Done":"Add node"})]})]})}function qf({family:e,targetId:t,inputs:s,entry:o,canRun:r}){const a=Ce(),[i,l]=b.useState(null),c=async()=>{if(!(!r||(i==null?void 0:i.status)==="running")){l({status:"running"});try{if(e==="function"){const u=await a.invokeFunction(t,s);l({status:"done",output:u,terminal:!0})}else{const u=await a.runWorkflow(t,{input:s,variables:s,entry:o});l({status:"done",output:u.output,runId:u.runId,terminal:u.terminal,error:u.error})}}catch(u){l({status:"error",error:u.message??String(u)})}}};return n.jsxs("div",{className:"w6w-steptest",children:[n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!r||(i==null?void 0:i.status)==="running",onClick:c,children:(i==null?void 0:i.status)==="running"?"Running…":"▶ Test run"}),!r&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(i==null?void 0:i.status)==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:i.error}),(i==null?void 0:i.status)==="done"&&!i.terminal&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Still running"}),n.jsxs("div",{className:"w6w-result",children:["Run ",n.jsx("code",{children:i.runId})," has not finished yet — check its status from the workflow's run history."]})]}),(i==null?void 0:i.status)==="done"&&i.terminal&&i.error!==void 0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Run failed"}),n.jsx(le.Copyable,{value:JSON.stringify(i.error,null,2),label:"Copy error",children:n.jsx("pre",{className:"w6w-result w6w-error",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(i.error,null,2)})})]}),(i==null?void 0:i.status)==="done"&&i.terminal&&i.error===void 0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result"}),n.jsx(Te,{value:i.output,maxHeight:220})]})]})}function Uf(e){const t={};for(const s of e)ct(s.default)&&(t[s.key]=s.default);return t}function Bt(e,t){const s=ei(t);if(s===null)return!1;if(s===void 0)return!0;const o=Wt(e),r=i=>{var l;return s[i]!==void 0?s[i]:(l=o.find(c=>c.key===i))==null?void 0:l.default},a=(i,l,c)=>i.every(u=>{const d=ie.effectiveParam(u,c);if(d.type==="section")return a(d.children??[],l,c);if(d.type==="group"){const p=d.children??[],m=Wt(p),h=g=>y=>{const x=m.find(S=>S.key===y);return x?g[y]!==void 0?g[y]:x.default:c(y)};if(d.repeat){const g=Array.isArray(l[d.key])?l[d.key]:[];return g.length===0?!d.required:g.every(y=>{const x=y??{};return a(p,x,h(x))})}const w=l[d.key]??{};return a(p,w,h(w))}if(!d.required||!wn(u,c))return!0;const f=l[d.key]??d.default;return f==null?!1:typeof f=="string"?f.trim()!=="":!0});return a(e,s,r)}function sl(e){const t=e==null?void 0:e.testRequired;return typeof t=="boolean"?t:!0}function Wf(e){const t=e;return(t==null?void 0:t.body)??(t==null?void 0:t.raw)??{error:t==null?void 0:t.code,message:(t==null?void 0:t.message)??String(e)}}function Hf(e){const t=e==null?void 0:e.apiCalls;return Array.isArray(t)?t:[]}function Bf({log:e,onClose:t}){return n.jsx(Ee,{title:"Test run log",subtitle:e.startedAt,size:"wide",onClose:t,children:n.jsxs("div",{className:"w6w-modal-body w6w-stack",style:{gap:12},children:[n.jsxs("div",{className:"w6w-testout",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Request to w6w · ",e.request.method," ",e.request.path]}),n.jsx(Te,{value:e.request.body,maxHeight:320})]}),n.jsxs("div",{className:"w6w-testout",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Response from w6w ·"," ",e.response.ok?"ok":`failed${e.response.status?` (HTTP ${e.response.status})`:""}`," ","· ",e.durationMs,"ms"]}),n.jsx(Te,{value:e.response.body,maxHeight:320})]}),n.jsxs("div",{className:"w6w-testout",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Outbound API calls (",e.apiCalls.length,")"]}),e.apiCalls.length>0?n.jsx(Ii,{calls:e.apiCalls,title:!1,defaultOpen:!0}):n.jsxs("div",{className:"w6w-muted w6w-small",children:["No HTTP request reached the vendor API — the action",e.response.ok?" made no outbound call":" failed before sending one","."]})]})]})})}function ol({step:e,config:t,onChange:s,inLoop:o,outputFields:r,failureHandling:a,retryControls:i}){const l=c=>{const{state:u,fanOut:d,...f}=t;s({...f,...c.state!==void 0?{state:c.state}:{},...c.fanOut!==void 0?{fanOut:c.fanOut}:{}})};return n.jsxs("div",{className:"w6w-stack",children:[n.jsx(Qa,{config:t,onChange:c=>s({...t,...c}),failureHandling:a,retryControls:i}),n.jsx(tl,{step:e,count:0,onChange:l}),Pi(e)&&n.jsx(nl,{step:e,inLoop:o,outputFields:r,onChange:l})]})}const Uo=b.forwardRef(function({app:t,action:s,connectionId:o,values:r,timeoutMs:a,canRun:i,hideRunButton:l,persist:c,state:u,onBusyChange:d,onResult:f},p){const m=Ce(),h=Ys(),w=Ac(),[g,y]=b.useState(null),[x,S]=b.useState(null),[A,O]=b.useState(!1),j=b.useRef(!1),[N,k]=b.useState(null),_=c==null?void 0:c.workflowId,U=c==null?void 0:c.stepId,T=nt().nodeMeta,F=U?T==null?void 0:T[U]:void 0;b.useEffect(()=>{if(!_||!U)return;let I=!1;return m.listStepTests(_,U).then(G=>{let W;for(const $ of G)!$.lastRunAt||!$.lastRunStatus||(!W||Date.parse($.lastRunAt)>Date.parse(W.lastRunAt))&&(W=$);!W||!W.lastRunAt||I||j.current||(W.lastRunStatus==="succeeded"?y({status:"done",value:W.lastRunOutput,...W.lastRunMeta?{meta:W.lastRunMeta}:{}}):y({status:"error",error:typeof W.lastRunError=="string"?W.lastRunError:W.lastRunError==null?"Test failed":JSON.stringify(W.lastRunError)}),k(W.lastRunAt))}).catch(()=>{}),()=>{I=!0}},[m,_,U]);const E=async()=>{var R;if(!i||(g==null?void 0:g.status)==="running")return;j.current=!0,k(null),y({status:"running"}),d==null||d(!0);let I;const G=new Date,W={method:"POST",path:`/apps/${encodeURIComponent(t)}/actions/${encodeURIComponent(s)}/invoke`,body:{params:r,...o?{connectionId:o}:{},...h?{project:h}:{},...u?{state:u}:{},...w?{workflowId:w}:{},...a?{timeoutMs:a}:{}}},$=z=>S({startedAt:G.toLocaleString(),durationMs:Date.now()-G.getTime(),request:W,response:z,apiCalls:Hf(z.body)});try{const z=await m.invokeAction(t,s,r,{...o?{connectionId:o}:{},project:h,...u?{state:u}:{},...w?{workflowId:w}:{},...a?{timeoutMs:a}:{}});$({ok:!0,body:z}),I={status:"done",value:z.value,logs:z.logs,...z.meta?{meta:z.meta}:{}}}catch(z){const K=z;$({ok:!1,...typeof K.status=="number"?{status:K.status}:{},body:Wf(z)}),I={status:"error",error:K.message??String(z),errorCode:K.code,logs:K.logs}}if(y(I),f==null||f(I.status==="done"),c){(R=m.saveTestInput)==null||R.call(m,c.workflowId,c.stepId,vo(c.input)).catch(z=>console.error("test input save failed",z));try{const z=await m.saveStepTest(c.workflowId,c.stepId,{input:c.input,with:r});await m.recordStepTestRun(c.workflowId,c.stepId,{stepTestId:z.id,status:I.status==="done"?"succeeded":"failed",input:c.input,output:I.status==="done"?I.value:void 0,error:I.status==="error"?I.error:void 0,...I.status==="done"&&I.meta?{meta:I.meta}:{}})}catch(z){console.error("step test persist failed",z)}}d==null||d(!1)};b.useImperativeHandle(p,()=>({run:E}));const P=g&&g.status!=="running"?g.logs:void 0;return n.jsxs("div",{className:"w6w-steptest",children:[(!l||x)&&n.jsxs("div",{className:"w6w-steptest-bar",children:[!l&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!i||(g==null?void 0:g.status)==="running",onClick:E,children:(g==null?void 0:g.status)==="running"?"Running…":"▶ Test run"}),x&&(g==null?void 0:g.status)!=="running"&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>O(!0),title:"The full request and response of the last test run",children:["Log",x.apiCalls.length>0?` (${x.apiCalls.length})`:""]}),!l&&!i&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),A&&x&&n.jsx(Bf,{log:x,onClose:()=>O(!1)}),N&&((g==null?void 0:g.status)==="done"||(g==null?void 0:g.status)==="error")&&n.jsxs("div",{className:"w6w-muted w6w-small w6w-testout-restored",children:["Last run · ",new Date(N).toLocaleString()]}),(g==null?void 0:g.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[g.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:g.errorCode})}),g.error]}),(g==null?void 0:g.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result (return value)"}),n.jsx(Te,{value:g.value,maxHeight:220}),(g.meta||F)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Te,{value:{...F,...g.meta},maxHeight:220})]})]}),(g==null?void 0:g.status)!=="done"&&(g==null?void 0:g.status)!=="running"&&F&&n.jsxs("div",{className:"w6w-testout","data-testid":"steptest-static-meta",children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Te,{value:F,maxHeight:220})]}),P&&P.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx(le.Copyable,{value:P.join(`
24
+ `),label:"Copy console output",children:n.jsx("pre",{className:"w6w-result w6w-testout-console",style:{whiteSpace:"pre-wrap",maxHeight:160,overflow:"auto",margin:0},children:P.join(`
25
+ `)})})]})]})}),Hr=12,jn=new Set;function rl(e,t,s,o,r){const a=o&&o.length>0?new Set(o):null,i=B=>(a?a.has(B.id):!0)&&((t==null?void 0:t(B))??!0),l=Ce(),[c,u]=b.useState(null),[d,f]=b.useState(null),[p,m]=b.useState(null),[h,w]=b.useState(null),[g,y]=b.useState(null),[x,S]=b.useState(()=>new Map),[A,O]=b.useState(()=>new Set),[j,N]=b.useState(jn),k=b.useRef(jn),_=b.useCallback(B=>{k.current=B,N(B)},[]),U=b.useRef(jn),T=e.includes("function"),F=e.includes("workflow"),E=typeof l.listAppsByIds=="function";b.useEffect(()=>{let B=!1;const Y=J=>!B&&y(J.message);return l.listConnections().then(J=>{if(B)return;const M=[],te=new Set,ee=new Map;for(const C of J)it(C.appId)||(E&&!(r!=null&&r.resolveInline)&&C.app&&!ee.has(C.appId)&&ee.set(C.appId,{...C.app,id:C.appId}),!te.has(C.appId)&&(te.add(C.appId),M.push(C.appId)));ee.size>0&&(U.current=new Set(ee.keys()),S(C=>new Map([...C,...ee])),O(C=>new Set([...C,...ee.keys()]))),u(M)}).catch(Y),T?l.listFunctions().then(J=>!B&&m(J)).catch(Y):m([]),F?l.listWorkflows().then(J=>!B&&w(J)).catch(Y):w([]),()=>{B=!0}},[l,E,T,F,r==null?void 0:r.resolveInline]),b.useEffect(()=>{if(E)return;const B=l.listApps;if(typeof B!="function"){f([]);return}let Y=!1;return B().then(J=>!Y&&f(J)).catch(J=>!Y&&y(J.message)),()=>{Y=!0}},[l,E]);const P=b.useRef(!0);b.useEffect(()=>(P.current=!0,()=>{P.current=!1}),[]);const I=b.useCallback(B=>{const Y=l.listAppsByIds;!Y||B.length===0||k.current.size>0||(_(new Set(B)),Y(B).then(J=>{P.current&&(_(jn),S(M=>{const te=new Map(M);for(const ee of J)te.set(ee.id,ee);return te}),O(M=>new Set([...M,...B])))}).catch(J=>P.current&&y(J.message)))},[l,_]),G=b.useRef(!1);b.useEffect(()=>{if(!E||c===null||G.current)return;const B=ds(c,U.current,Hr);B.length!==0&&(G.current=!0,I(B))},[E,c,I]);const W=()=>{if(!E||c===null||k.current.size>0)return;const B=new Set([...A,...k.current]);I(ds(c,B,Hr))};if(g)return{state:"error",error:g,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:W};if(p===null||h===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:W};const $=Ds(p,s),R=Ds(h,s);if(E){if(c===null)return{state:"loading",apps:[],fns:$,wfs:R,moreApps:!1,loadMoreApps:W};if(c.length>0&&A.size===0)return{state:"loading",apps:[],fns:$,wfs:R,moreApps:!1,loadMoreApps:W};const B=kc(c,x).filter(i),Y=j.size===0&&ds(c,new Set([...A,...j]),1).length>0;return{state:B.length===0&&$.length===0&&R.length===0&&!Y?"empty":"ready",apps:B,appIds:c.filter(M=>!a||a.has(M)),fns:$,wfs:R,moreApps:Y,loadMoreApps:W}}if(d===null)return{state:"loading",apps:[],fns:$,wfs:R,moreApps:!1,loadMoreApps:W};const z=new Set(c??[]),K=d.filter(B=>!it(B.id)&&i(B)&&(z.has(B.id)||B.zeroCredential===!0));return{state:K.length===0&&$.length===0&&R.length===0?"empty":"ready",apps:K,fns:$,wfs:R,moreApps:!1,loadMoreApps:W}}function Ds(e,t){return t&&t.length>0?e.filter(s=>!t.includes(s.id)):[...e]}function sn(e){return(t,s)=>e(t).localeCompare(e(s),void 0,{sensitivity:"base"})}function qt(e){const t=e.displayName;return t!=null&&t.trim()?t:"name"in e?e.name:e.id}function Un({family:e,item:t,onSelect:s}){const o=qt(t);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-stepbuilder-item--callable","data-kind":e,onClick:()=>s({id:t.id,label:o}),children:[n.jsx(Qn,{icon:Of[e],size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:o}),n.jsx("code",{className:"w6w-muted w6w-small",children:t.id})]})]})}function Vf(e,t){return t.length===0?null:n.jsxs("section",{className:"w6w-readytouse-col",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:e}),n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:t})]},e)}function al({app:e,theme:t,onSelect:s}){return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item","data-kind":"app",onClick:()=>s(e),children:[n.jsx(It,{src:e.iconSvg,srcDark:e.iconSvgDark,brandColor:e.brandColor,name:e.displayName,theme:t,size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:e.displayName}),n.jsx("code",{className:"w6w-muted w6w-small",children:e.id})]})]})}function zf({data:e,query:t,appsFilter:s,onSelectApp:o,onSelectCallable:r,theme:a}){var g;const i=Ce(),l=y=>n.jsx("div",{className:"w6w-apppicker-host",children:y});if(e.state==="error")return l(n.jsx("div",{className:"w6w-result w6w-error",children:e.error}));if(e.state==="loading")return l(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}));const c=e.apps.filter(y=>nn(t,y.displayName,y.id)).sort(sn(y=>y.displayName)),u=e.fns.filter(y=>nn(t,qt(y),y.id)).sort(sn(qt)),d=e.wfs.filter(y=>nn(t,qt(y),y.id)).sort(sn(qt)),f=Vf,p=c.map(y=>n.jsx(al,{app:y,theme:a,onSelect:o},y.id));e.moreApps&&p.push(n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:e.loadMoreApps,children:"Load more"},"__load_more_apps"));const m=t.trim()&&((g=e.appIds)!=null&&g.length)&&typeof i.listAppsPage=="function"?n.jsxs("section",{className:"w6w-readytouse-col",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Connected apps"}),n.jsx(lt,{search:!1,searchValue:t,ids:e.appIds,filter:s,onSelectApp:o,theme:a})]}):f("Connected apps",p),h=[f("Functions",u.map(y=>n.jsx(Un,{family:"function",item:y,onSelect:x=>r({family:"function",...x})},y.id))),f("Workflows",d.map(y=>n.jsx(Un,{family:"workflow",item:y,onSelect:x=>r({family:"workflow",...x})},y.id)))].filter(Boolean),w=(m?1:0)+(h.length>0?1:0);return l(w?n.jsxs("div",{className:"w6w-readytouse","data-cols":w,children:[m,h.length>0&&n.jsx("div",{className:"w6w-readytouse-stack",children:h})]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Nothing ready to use matches “",t,"”."]}))}function il(e,t){var s;return(((s=e.getAppTriggers)==null?void 0:s.call(e,t))??Promise.resolve([])).then(o=>o.map(r=>({key:r.key,title:r.title,description:r.description,params:r.params??[],...r.webhook?{webhook:r.webhook}:{}})))}function Jf({title:e,app:t}){return n.jsxs("p",{className:"w6w-muted w6w-small",children:[n.jsx("strong",{children:e})," runs when ",t," reports it, so there is nothing to run by hand. Publish the workflow to start listening."]})}function Kf({kind:e="action",onOpenStep:t,appId:s,app:o,onAdd:r,onClose:a,onDone:i,onDraftChange:l,onChangeApp:c,theme:u,workflowId:d,stepId:f,upstreamSteps:p=[],loop:m,initialAction:h,initialConnection:w,initialWith:g,setupOnly:y=!1,addLabel:x="Add"}){var De,bt;const S=Ce(),A=e==="trigger",O=A?"a trigger":"an action",[j,N]=b.useState(null),[k,_]=b.useState(null),[U,T]=b.useState(null),[F,E]=b.useState(null),[P,I]=b.useState(w??""),[G,W]=b.useState(),$=ko(),R=b.useRef($);R.current=$;const z=G?Kt({uses:{app:s,action:"",connectionRef:G}},$==null?void 0:$.connections)??"":P,K=b.useCallback(se=>{W(void 0),I(se)},[]),[ne,B]=b.useState(h??""),[Y,J]=b.useState(g??{}),M=b.useRef(null),[te,ee]=b.useState(!1),[C,V]=b.useState(!y&&h&&g?"configure":"setup"),[Q,ae]=b.useState("props"),[X,ke]=b.useState("{}"),[be,ye]=b.useState({});b.useEffect(()=>{let se=!1;E(null);const Ne=A?il(S,s):S.getAppActions(s);return Promise.all([S.getAppAuth(s),S.listConnectionsForApp(s),Ne]).then(([$e,q,ce])=>{if(se)return;const v=Mr(s,$e,q);N($e),_(v),T(ce);const L=R.current,H=Ai({id:f??"",uses:{app:s,action:""}},v,(L==null?void 0:L.nodes)??[],(L==null?void 0:L.connections)??{},w);H.connectionRef?W(H.connectionRef):K(H.connection??"")}).catch($e=>!se&&E($e.message)),()=>{se=!0}},[S,s,A,K,w,f]);const ge=async()=>{const se=await S.listConnectionsForApp(s);_(Mr(s,j??[],se))},xe=(j??[]).filter(se=>se.available!==!1),ue=xe.some(se=>se.autoSatisfied===!0&&(se.type==="tenantAuth"||se.type==="jit")),D=ue&&!xe.some(se=>se.autoSatisfied===!0&&se.type==="tenantAuth"),re=xe.length>0&&!ue,me=(k??[]).length>0,Oe=j!==null&&k!==null&&re&&!me,[Ie,_e]=b.useState(0),de=(U??[]).find(se=>se.key===ne),We=A?_i(s,U,ne,Y):null,Gt=[...U??[]].sort((se,Ne)=>(se.title??se.key).localeCompare(Ne.title??Ne.key,void 0,{sensitivity:"base"})),He=sl(o),[Rt,Ke]=b.useState(!1);b.useEffect(()=>{if(!He||!d||!f)return;let se=!1;return S.listStepTests(d,f).then(Ne=>{!se&&Ne.some($e=>$e.lastRunStatus==="succeeded")&&Ke(!0)}).catch(()=>{}),()=>{se=!0}},[S,He,d,f]);const mt=Fo(d??"",p,!!d),$t=(De=nt().stateShape)==null?void 0:De.written,wt=Po(mt,Zi(m),$t),ve=!!ne&&(!re||me&&!!z)&&(!We||We.selected.length>0),Pe=ve&&!!de&&Bt(de.params??[],Y),_t=ve,Fe=(k??[]).find(se=>se.id===z);function Me(){return{uses:{app:s,action:(de==null?void 0:de.key)??ne,...G?{connectionRef:G}:z?{connection:z}:{},...A?{trigger:!0}:{}},with:Y,...be}}function Ge(){de&&r(Me())}const[pe,st]=b.useState(null);b.useEffect(()=>{if(!l||pe!==null||!ve||We&&C==="setup")return;const se=r(Me());se&&st(se),se&&A&&(t==null||t(se))},[l,pe,ve,C]),b.useEffect(()=>{!l||pe===null||l(pe,Me())},[pe,Y,be,z,G]);const Be=se=>{se==="code"&&ke($o(Me())),ae(se)};return n.jsxs("div",{className:"w6w-stepconfig",children:[!y&&n.jsxs("div",{className:"w6w-tabsbar",children:[n.jsxs("div",{className:"w6w-subtabs",children:[n.jsx("button",{type:"button",className:`w6w-subtab${C==="setup"?" active":""}`,onClick:()=>V("setup"),children:"Setup"}),n.jsx("button",{type:"button",disabled:!ve,title:ve?void 0:"Complete Setup first",className:`w6w-subtab${C==="configure"?" active":""}`,onClick:()=>ve&&V("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!Pe,title:Pe?void 0:"Fill the required fields first",className:`w6w-subtab${C==="test"?" active":""}`,onClick:()=>Pe&&V("test"),children:"Test"})]}),n.jsx(ts,{view:Q,customized:Zn(Y),onChange:Be,disabled:C!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[C==="setup"&&n.jsxs("div",{className:"w6w-stack",children:[F&&n.jsx("div",{className:"w6w-result w6w-error",children:F}),j===null&&!F&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"App"}),n.jsxs("div",{className:"w6w-app-conn-row",ref:M,children:[n.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App",onClick:c,disabled:!c,children:[o&&n.jsx(It,{src:o.iconSvg,srcDark:o.iconSvgDark,brandColor:o.brandColor,name:o.displayName,theme:u,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(o==null?void 0:o.displayName)??s})]}),n.jsx(Oi,{step:{id:pe??f??"",uses:{app:s,action:ne,...G?{connectionRef:G}:{connection:z||void 0}}},conns:k,failed:!!F,open:te,onOpenChange:ee,anchorRef:M,onChangeConnection:K,onChangeConnectionRef:W,onConnectionCreated:()=>{ge()},createSignal:Ie})]}),D&&(Fe==null?void 0:Fe.builtIn)&&n.jsx("span",{className:"w6w-hint",children:"Scheduled or queued runs need a stored connection. Choose one from the connection menu."})]}),Oe?n.jsxs(Ri,{testId:"step-needs-connection",className:"w6w-sb-connect-gate",action:n.jsxs("button",{type:"button",className:"w6w-btn",onClick:()=>_e(se=>se+1),children:["Connect ",(o==null?void 0:o.displayName)??s]}),children:["Connect ",(o==null?void 0:o.displayName)??s," to choose ",O,"."]}):U!==null&&(U.length===0?n.jsx("p",{className:"w6w-muted w6w-small",children:A?"This app declares no triggers.":"This app exposes no actions."}):We?n.jsx($i,{choices:We,onChange:se=>{B(We.triggerKey),J(Ne=>({...Ne,actions:se}))}}):n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[A?"Trigger":"Action",ne?"":" *"]}),n.jsx(et,{value:ne,placeholder:`— pick ${O} —`,mode:"combobox",listMaxHeight:200,onChange:se=>{var Ne;B(se),J(Uf(((Ne=(U??[]).find($e=>$e.key===se))==null?void 0:Ne.params)??[])),Ke(!1)},options:Gt.map(se=>({value:se.key,label:`${se.title??se.key} (${se.key})`}))}),(de==null?void 0:de.description)&&n.jsx("span",{className:"w6w-hint",children:de.description})]}))]}),C==="configure"&&(de?Q==="props"?n.jsx(Ue,{params:de.params??[],values:Y,onChange:J,dynamic:{appId:s,actionKey:de.key,kind:A?"trigger":"action",connectionId:z||void 0,appName:o==null?void 0:o.displayName}}):Q==="code"?n.jsx(Ze,{value:X,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):Q==="params-code"?n.jsx(fo,{values:Y,onChange:J}):n.jsx(ol,{step:{id:f??"",...Me()},config:be,onChange:ye,inLoop:m!==void 0,outputFields:(bt=kt(de,void 0))==null?void 0:bt.fields.map(se=>se.key),failureHandling:!A}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Pick ",O," in Setup first."]})),C==="test"&&(de&&A?n.jsx(Jf,{title:de.title??de.key,app:(o==null?void 0:o.displayName)??s}):de?n.jsx(Uo,{app:s,action:de.key,connectionId:z||void 0,values:Y,canRun:ve&&Bt(de.params??[],Y),state:wt,onResult:Ke}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),C==="test"&&n.jsx("div",{className:"w6w-stepconfig-testnote",children:He&&!Rt&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Not yet tested. You can publish without running a test."})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),y?n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"stepbuilder-setup-add",disabled:!ve,onClick:Ge,children:x}):C==="test"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:pe===null&&!_t,onClick:pe!==null?i??a:Ge,children:pe!==null?"Done":"Add node"}):n.jsx("button",{type:"button",className:"w6w-btn",disabled:C==="setup"?!ve:!Pe,onClick:()=>V(C==="setup"?"configure":"test"),children:"Next →"})]})]})}function Gf({appId:e,app:t,onClose:s,onChangeApp:o,theme:r,initialConnection:a,onConnected:i}){const l=Ce(),[c,u]=b.useState(null),[d,f]=b.useState(null),[p,m]=b.useState(null),[h,w]=b.useState(a??""),[g,y]=b.useState(!1),[x,S]=b.useState(!1);b.useEffect(()=>{let E=!1;return m(null),Promise.all([l.getAppAuth(e),l.listConnectionsForApp(e)]).then(([P,I])=>{if(E)return;u(P),f(I),!(P??[]).some(W=>W.autoSatisfied===!0)&&I.length>0&&w(I[0].id)}).catch(P=>!E&&m(P.message)),()=>{E=!0}},[l,e]);const A=async()=>{const E=await l.listConnectionsForApp(e);f(E),E.length>0&&w(P=>P||E[0].id)},O=(c??[]).filter(E=>E.available!==!1),j=O.some(E=>E.autoSatisfied===!0&&(E.type==="tenantAuth"||E.type==="jit")),N=j&&!O.some(E=>E.autoSatisfied===!0&&E.type==="tenantAuth"),k=O.length>0&&!j,_=(d??[]).length>0,U=!k||_&&!!h,T=(d??[]).find(E=>E.id===h),F=x||!h;return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-stepconfig-body",children:n.jsxs("div",{className:"w6w-stack",children:[p&&n.jsx("div",{className:"w6w-result w6w-error",children:p}),c===null&&!p&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"App"}),n.jsxs("div",{className:"w6w-conn-label",children:[t&&n.jsx(It,{src:t.iconSvg,srcDark:t.iconSvgDark,brandColor:t.brandColor,name:t.displayName,theme:r,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(t==null?void 0:t.displayName)??e}),o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:o,children:"Change"})]})]}),c!==null&&j&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"Create connection"})]}),N&&n.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&&k&&(_?F?n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{style:{display:"flex",gap:6},children:[n.jsx("select",{value:h,onChange:E=>{w(E.target.value),S(!1)},style:{flex:1},children:(d??[]).map(E=>n.jsxs("option",{value:E.id,children:[E.displayName||E.id," ",E.state?`(${E.state})`:""]},E.id))}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y(!0),children:"+ New"})]})]}):n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsxs("span",{className:"w6w-conn-label-name",children:[(T==null?void 0:T.displayName)||(T==null?void 0:T.id)||h,T!=null&&T.state?` (${T.state})`:""]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>S(!0),children:"Change"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"+ New"})]})]}):n.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[n.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>y(!0),children:"Create connection"})]}))]})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:!U||!t,onClick:()=>t&&i(h,t),children:"Next →"})]}),g&&n.jsx(co,{theme:r,initialAppId:e,onClose:()=>y(!1),onCreated:async({connectionId:E})=>{y(!1),w(E),S(!1),await A()}})]})}function ll({values:e,onChange:t,readOnly:s,setupOnly:o,onValidityChange:r,targetLabel:a,fixedTarget:i}){var W,$;const l=Ce(),c=e.targetKind==="function"?"function":"workflow",u=typeof e.targetId=="string"?e.targetId:"",d=typeof e.entry=="string"?e.entry:void 0,f=e.inputs&&typeof e.inputs=="object"&&!Array.isArray(e.inputs)?e.inputs:{},p=ct(e.inputs)||typeof f.$=="string",[m,h]=b.useState([]),[w,g]=b.useState(),[y,x]=b.useState(),[S,A]=b.useState(),O=`${c}:${u}`;b.useEffect(()=>{if(i)return;let R=!1;return h([]),g(void 0),(c==="workflow"?l.listWorkflows():l.listFunctions()).then(z=>{R||h(z)}).catch(z=>{R||g(String(z.message??z))}),()=>{R=!0}},[l,c,i]),b.useEffect(()=>{let R=!1;return x(void 0),A(void 0),u?((c==="workflow"?l.getWorkflow(u).then(K=>({key:O,workflow:K,fields:[],label:K.displayName||K.name||u})):l.getFunction(u).then(K=>({key:O,fields:K.inputs,label:K.displayName||K.id}))).then(K=>{R||x(K)}).catch(K=>{R||A(String(K.message??K))}),()=>{R=!0}):void 0},[l,u,c,O]);const j=(y==null?void 0:y.key)===O?y:void 0,N=j!=null&&j.workflow?Lo(j.workflow):[],k=d??((W=N[0])==null?void 0:W.id),_=j!=null&&j.workflow?Ef(j.workflow,k):(j==null?void 0:j.fields)??[],T={...Object.fromEntries(_.filter(R=>R.default!==void 0).map(R=>[R.key,R.default])),...f},F=c==="function"||!d||N.some(R=>R.id===d),E=!!j&&F&&(p||Bt(_,T));b.useEffect(()=>{r==null||r(E)},[E,r]),b.useEffect(()=>{if(!j||s||o)return;const R=!p&&_.some(z=>z.default!==void 0&&!(z.key in f));(!d&&k||R)&&t({...e,...k?{entry:k}:{},inputs:p?e.inputs:T})});const P=m.map(R=>({value:R.id,label:R.displayName||("name"in R?R.name:R.id)||R.id})).sort((R,z)=>R.label.localeCompare(z.label));u&&!P.some(R=>R.value===u)&&P.unshift({value:u,label:(j==null?void 0:j.label)||a||u});const I=u?($=l.callableHref)==null?void 0:$.call(l,c,u):void 0,G=(R,z)=>{const{target:K,entry:ne,...B}=e;t({...B,targetKind:R,targetId:z,inputs:{}})};return n.jsxs("div",{className:"w6w-stack",children:[!i&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Target kind"}),n.jsxs("select",{className:"w6w-input",value:c,disabled:s,onChange:R=>G(R.target.value,""),children:[n.jsx("option",{value:"workflow",children:"Workflow"}),n.jsx("option",{value:"function",children:"Function"})]})]}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:c==="workflow"?"Workflow":"Function"}),i?n.jsx("span",{children:(j==null?void 0:j.label)||a||u}):n.jsx(et,{"aria-label":c==="workflow"?"Workflow":"Function",options:P,value:u,disabled:s,placeholder:`Choose a ${c}…`,onChange:R=>G(c,R)}),I&&n.jsxs("a",{className:"w6w-btn w6w-btn-ghost",href:I,target:"_blank",rel:"noopener noreferrer",children:["Open ",c," in new tab ↗"]})]}),w&&n.jsx("div",{className:"w6w-result w6w-error",children:w}),!o&&u&&n.jsxs(n.Fragment,{children:[S?n.jsx("div",{className:"w6w-result w6w-error",children:S}):j?n.jsxs(n.Fragment,{children:[c==="workflow"&&N.length>0&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Trigger"}),n.jsxs("select",{className:"w6w-input","aria-label":"Trigger",value:k,disabled:s,onChange:R=>t({...e,entry:R.target.value,inputs:{}}),children:[d&&!F&&n.jsxs("option",{value:d,children:[d," (unavailable)"]}),N.map(R=>n.jsxs("option",{value:R.id,children:[R.id," (",R.uses.app===Vt?"Manual":R.uses.action,")"]},R.id))]})]}),!F&&n.jsx("div",{className:"w6w-result w6w-error",children:"The selected trigger is unavailable. Choose another trigger."}),c==="workflow"&&N.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:[j.label," has no manual trigger. Add a manual trigger to that workflow to define its input fields."]}),n.jsx("span",{className:"w6w-small",children:"Inputs"}),_.length>0&&!p?n.jsx(Ue,{params:_,values:T,readOnly:s,onChange:R=>t({...e,inputs:R})}):n.jsx(Ue,{params:[{key:"inputs",label:"Input payload",type:"json"}],values:{inputs:e.inputs??{}},readOnly:s,onChange:R=>t({...e,inputs:R.inputs})})]}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading inputs…"}),n.jsx(Ue,{params:[{key:"wait",label:"Wait for completion",type:"boolean",default:!0,hint:"On: wait for the workflow or function to finish and return its output. Off: return a run handle and continue."}],values:e,readOnly:s,onChange:t})]})]})}const Yf=/^(#{1,6})\s+(.*)$/,Xf=new RegExp("\\*\\*(?=\\S)(.+?)(?<=\\S)\\*\\*","g");function Zf(e,t){const s=e.ownerDocument;e.replaceChildren();for(const o of t.split(`
26
+ `)){const r=Yf.exec(o),a=s.createElement(r?`h${r[1].length}`:"div"),i=r?r[2]:o;let l=0;for(const c of i.matchAll(Xf)){c.index>l&&a.append(s.createTextNode(i.slice(l,c.index)));const u=s.createElement("strong");u.textContent=c[1],a.append(u),l=c.index+c[0].length}l<i.length&&a.append(s.createTextNode(i.slice(l))),a.firstChild||a.append(s.createElement("br")),e.append(a)}}function Qf(e){var o;const t=(o=e.style)==null?void 0:o.fontWeight;if(!t)return;if(t==="bold"||t==="bolder")return!0;const s=Number(t);return Number.isFinite(s)?s>=600:!1}function eh(e){const t=[];for(const s of e){const o=t[t.length-1];o&&o.bold===s.bold?o.text+=s.text:t.push({...s})}return t.map(({text:s,bold:o})=>{const r=s.trim();if(!o||!r)return s;const a=s.slice(0,s.indexOf(r)),i=s.slice(a.length+r.length);return`${a}**${r}**${i}`}).join("")}function th(e){const t=[];let s=null;const o=i=>(s={level:i,runs:[]},t.push(s),s),r=(i,l,c)=>{if(i.nodeType===3){const w=(i.textContent??"").replace(/ /g," ").replace(/\n/g,"");w&&(s??o(l)).runs.push({text:w,bold:c});return}if(i.nodeType!==1)return;const u=i,d=u.tagName.toLowerCase();if(d==="br"){s||o(l),s=null;return}const f=/^h([1-6])$/.exec(d),p=f||["div","p","li","ul","ol","blockquote","pre"].includes(d);p&&(s=null);const m=f?Number(f[1]):l,h=d==="b"||d==="strong"?!0:Qf(u)??c;for(const w of u.childNodes)r(w,m,h);p&&(s=null)};for(const i of e.childNodes)r(i,0,!1);const a=t.map(i=>{const l=eh(i.runs);return i.level>0?`${"#".repeat(i.level)} ${l.trimStart()}`:l});for(;a.length&&a[a.length-1].trim()==="";)a.pop();return a.join(`
27
+ `)}function nh(e){return e.replace(/([^\n])\n(?=[^\n])/g,`$1
28
+ `)}const sh=-2,oh=-1,Br=1e3,rh=["#facc15","#fb923c","#f87171","#f472b6","#a78bfa","#60a5fa","#2dd4bf","#4ade80","#9ca3af"],ah=[{level:1,label:"Title"},{level:2,label:"Heading"},{level:3,label:"Subheading"},{level:0,label:"Body"}],ih=80,lh=48,Vr=10,ch=4,ws=e=>e.stopPropagation();function uh(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),t.removeAllRanges(),t.addRange(s)}function dh(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),s.collapse(!1),t.removeAllRanges(),t.addRange(s)}function cl({canvas:e,className:t,viewport:s,readOnly:o,zoom:r=1,onChange:a,onSectionDrop:i,onRequestDelete:l}){const[c,u]=b.useState({}),[d,f]=b.useState(null),[p,m]=b.useState(null),[h,w]=b.useState(null),[g,y]=b.useState(null),x=b.useRef(null),S=b.useRef(null),A=b.useRef(null);if(b.useEffect(()=>{if(!d&&!p)return;const C=d?`[data-note-id="${d}"], [data-note-toolbar="${d}"]`:`[data-section-label="${p}"], [data-section-toolbar="${p}"]`,V=Q=>{var ke,be;const ae=Q.target;if((ke=ae==null?void 0:ae.closest)!=null&&ke.call(ae,C))return;const X=document.activeElement;(be=X==null?void 0:X.closest)!=null&&be.call(X,"[data-section-toolbar]")&&X.blur(),f(null),m(null),y(null)};return window.addEventListener("pointerdown",V,!0),()=>window.removeEventListener("pointerdown",V,!0)},[d,p]),!s)return null;const O=!o&&!!a,j=e.sections??[],N=e.notes??[],k=C=>c[C.id]??{x:C.position.x,y:C.position.y,w:C.size.width,h:C.size.height},_=C=>{const V=k(C);return{left:V.x,top:V.y,width:V.w,height:V.h,"--w6w-canvas-color":C.color}},U=(C,V)=>a==null?void 0:a({...e,notes:N.map(Q=>Q.id===C?{...Q,...V}:Q)}),T=(C,V)=>a==null?void 0:a({...e,sections:j.map(Q=>Q.id===C?{...Q,...V}:Q)}),F=C=>{const V=S.current,Q=N.find(X=>X.id===C);if(!(V!=null&&V.isConnected)||!Q)return;const ae=th(V);ae!==Q.content&&U(C,{content:ae})},E=C=>{m(null),f(C)},P=C=>{f(null),m(C)},I=(C,V)=>{A.current=V??null,E(C),w(C),y(null)},G=C=>V=>{if(!V||V.dataset.ready==="1")return;V.dataset.ready="1",S.current=V,Zf(V,C.content),V.focus();const Q=A.current;A.current=null,Q?(uh(V),Q(),F(C.id)):dh(V)},W=(C,V,Q)=>{var X;y(null);const ae=()=>document.execCommand(V,!1,Q);h===C&&((X=S.current)!=null&&X.isConnected)?(ae(),F(C)):I(C,ae)},$=C=>C.mode==="move"?{...C.base,x:C.base.x+C.dx,y:C.base.y+C.dy}:{...C.base,w:Math.max(ih,C.base.w+C.dx),h:Math.max(lh,C.base.h+C.dy)},R=(C,V,Q,ae)=>{if(!O||C.button!==0)return;C.stopPropagation(),C.preventDefault();const X={kind:Q,id:V.id,mode:ae,sx:C.clientX,sy:C.clientY,base:k(V),dx:0,dy:0};x.current=X;const ke=ye=>{X.dx=(ye.clientX-X.sx)/(r||1),X.dy=(ye.clientY-X.sy)/(r||1),u(ge=>({...ge,[X.id]:$(X)}))},be=()=>{if(window.removeEventListener("pointermove",ke),window.removeEventListener("pointerup",be),x.current=null,u(xe=>{const{[X.id]:ue,...D}=xe;return D}),X.dx===0&&X.dy===0)return;const ye=$(X),ge={position:{x:ye.x,y:ye.y},size:{width:ye.w,height:ye.h}};X.kind==="section"&&X.mode==="move"&&i?i(X.id,{dx:X.dx,dy:X.dy}):X.kind==="note"?U(X.id,ge):T(X.id,ge)};window.addEventListener("pointermove",ke),window.addEventListener("pointerup",be)},z=t?` ${t}`:"",K="nopan nodrag nowheel",ne=O?N.find(C=>C.id===d):void 0,B=O?j.find(C=>C.id===p):void 0,Y=r||1,J=C=>{const V=k(C);return{left:V.x+V.w/2,top:V.y,transform:`translate(-50%, calc(-100% - ${Vr/Y}px)) scale(${1/Y})`,transformOrigin:"50% 100%","--w6w-canvas-color":C.color}},M=(C,V)=>{const Q=k(C);return{left:Q.x,top:Q.y,transform:`translate(0, calc(-100% - ${V/Y}px)) scale(${1/Y})`,transformOrigin:"0 100%","--w6w-canvas-color":C.color}},te=(C,V,Q,ae)=>n.jsxs("div",{className:"w6w-note-menu w6w-note-menu-colors",role:"menu",children:[rh.map(X=>n.jsx("button",{type:"button",role:"menuitemradio","aria-checked":X===C,"aria-label":`Colour ${X}`,title:X,className:`w6w-note-swatch-btn${X===C?" active":""}`,style:{"--w6w-canvas-color":X},"data-testid":`${Q}-option`,"data-color":X,onClick:()=>{y(null),X!==C&&ae(X)}},X)),n.jsx("label",{className:"w6w-note-swatch-btn w6w-note-swatch-custom",title:"Custom",children:n.jsx("input",{type:"color","aria-label":`Custom ${V} colour`,"data-testid":`${Q}-input`,value:C,onChange:X=>ae(X.currentTarget.value)})})]}),ee=C=>{C.target.closest("input")||C.preventDefault()};return Rn.createPortal(n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`w6w-canvas-layer w6w-canvas-sections${z}`,style:{zIndex:sh},"data-testid":"w6w-canvas-sections",children:[j.map(C=>n.jsx("div",{className:`w6w-canvas-section${p===C.id?" selected":""}`,style:_(C),"data-section-id":C.id,"data-testid":"section",children:O&&n.jsx("div",{className:`w6w-note-resize ${K}`,"data-testid":"section-resize",onPointerDown:V=>R(V,C,"section","resize")})},C.id)),j.map(C=>(B==null?void 0:B.id)===C.id?null:n.jsx("div",{className:`w6w-canvas-section-title${O?` editable ${K}`:""}`,style:M(C,ch),"data-section-label":C.id,"data-testid":"section-label",title:O?"Click to edit · drag to move":void 0,onPointerDown:O?V=>{P(C.id),R(V,C,"section","move")}:void 0,children:C.title||(O?"Untitled section":"")},C.id))]}),n.jsx("div",{className:`w6w-canvas-layer w6w-canvas-notes${z}`,style:{zIndex:oh},"data-testid":"w6w-canvas-notes",children:N.map(C=>{const V=O&&h===C.id;return n.jsxs("div",{className:`w6w-canvas-note${d===C.id?" selected":""}`,style:_(C),"data-note-id":C.id,"data-testid":"note",children:[V?n.jsx("div",{ref:G(C),className:`w6w-canvas-note-body w6w-canvas-note-editor ${K}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":"true","aria-label":"Note content","data-testid":"note-content",onPointerDown:ws,onBlur:()=>{F(C.id),S.current=null,w(null)},onKeyDown:Q=>{Q.key==="Escape"&&Q.currentTarget.blur()},onPaste:Q=>{Q.preventDefault(),document.execCommand("insertText",!1,Q.clipboardData.getData("text/plain"))}},"editor"):n.jsx("div",{className:`w6w-canvas-note-body ${K}`,"data-testid":"note-view",style:O?{cursor:"grab",touchAction:"none"}:void 0,onPointerDown:O?Q=>{E(C.id),R(Q,C,"note","move")}:void 0,onDoubleClick:O?()=>I(C.id):void 0,children:C.content.trim()?n.jsx(mo,{content:nh(C.content)}):O&&n.jsx("span",{className:"w6w-canvas-note-empty",children:"Double-click to write"})},"view"),O&&n.jsx("div",{className:`w6w-note-resize ${K}`,"data-testid":"note-resize",onPointerDown:Q=>R(Q,C,"note","resize")})]},C.id)})}),B&&n.jsx("div",{className:`w6w-canvas-layer${z}`,style:{zIndex:Br},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar w6w-section-toolbar ${K}`,role:"toolbar","aria-label":"Section","data-testid":"section-toolbar","data-section-toolbar":B.id,style:M(B,Vr),onPointerDown:ws,onMouseDown:ee,children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-grip","aria-label":"Move section",title:"Drag to move","data-testid":"section-drag",onPointerDown:C=>R(C,B,"section","move"),children:n.jsx(le.Icon,{name:"grip"})}),n.jsx("input",{type:"text",className:"w6w-section-title-input","aria-label":"Section title",placeholder:"Untitled section","data-testid":"section-title",defaultValue:B.title,size:Math.max(8,Math.min(32,B.title.length+1)),onBlur:C=>{const V=C.currentTarget.value;V!==B.title&&T(B.id,{title:V})},onKeyDown:C=>{(C.key==="Enter"||C.key==="Escape")&&C.currentTarget.blur()}},`${B.id}:${B.title}`),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn${g==="color"?" active":""}`,"aria-label":"Section colour","aria-expanded":g==="color",title:"Colour","data-testid":"section-color",onClick:()=>y(g==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(le.Icon,{name:"chevron-down",size:12})]}),g==="color"&&te(B.color,"section","section-color",C=>T(B.id,{color:C}))]}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-delete","aria-label":"Delete section",title:"Delete section","data-testid":"section-delete",onClick:()=>{y(null),l==null||l("section",B.id)},children:n.jsx(le.Icon,{name:"trash"})})]})}),ne&&n.jsx("div",{className:`w6w-canvas-layer${z}`,style:{zIndex:Br},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar ${K}`,role:"toolbar","aria-label":"Note","data-testid":"note-toolbar","data-note-toolbar":ne.id,style:J(ne),onPointerDown:ws,onMouseDown:ee,children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-grip","aria-label":"Move note",title:"Drag to move","data-testid":"note-drag",onPointerDown:C=>R(C,ne,"note","move"),children:n.jsx(le.Icon,{name:"grip"})}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn${g==="color"?" active":""}`,"aria-label":"Note colour","aria-expanded":g==="color",title:"Colour","data-testid":"note-color",onClick:()=>y(g==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(le.Icon,{name:"chevron-down",size:12})]}),g==="color"&&te(ne.color,"note","note-color",C=>U(ne.id,{color:C}))]}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn w6w-note-size-btn${g==="size"?" active":""}`,"aria-label":"Text size","aria-expanded":g==="size",title:"Text size","data-testid":"note-size",onClick:()=>y(g==="size"?null:"size"),children:["Aa",n.jsx(le.Icon,{name:"chevron-down",size:12})]}),g==="size"&&n.jsx("div",{className:"w6w-note-menu w6w-note-menu-sizes",role:"menu",children:ah.map(C=>n.jsx("button",{type:"button",role:"menuitem",className:`w6w-note-menu-item w6w-note-size-${C.level}`,"data-testid":`note-size-${C.level}`,onClick:()=>W(ne.id,"formatBlock",C.level?`<h${C.level}>`:"<div>"),children:C.label},C.level))})]}),n.jsx("button",{type:"button",className:"w6w-icon-btn","aria-label":"Bold",title:"Bold","data-testid":"note-bold",onClick:()=>W(ne.id,"bold"),children:n.jsx(le.Icon,{name:"bold"})}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-delete","aria-label":"Delete note",title:"Delete note","data-testid":"note-delete",onClick:()=>{y(null),l==null||l("note",ne.id)},children:n.jsx(le.Icon,{name:"trash"})})]})})]}),s)}function ph(e){const t=bs.useStore(o=>{var r;return((r=o.domNode)==null?void 0:r.querySelector(".react-flow__viewport"))??null}),s=bs.useStore(o=>o.transform[2]);return n.jsx(cl,{...e,zoom:e.zoom??s,viewport:t})}function fh(e){return e.viewport!==void 0?n.jsx(cl,{...e,viewport:e.viewport}):n.jsx(ph,{...e})}function hh({title:e,message:t,onConfirm:s,onClose:o,confirmLabel:r="Confirm",cancelLabel:a="Cancel",destructive:i=!0,pending:l=!1,autoFocusConfirm:c=!1,children:u}){const d=b.useRef(null);return b.useEffect(()=>{var f;c&&((f=d.current)==null||f.focus())},[c]),n.jsxs(Ee,{title:e,onClose:()=>{l||o()},children:[n.jsxs("div",{className:"w6w-modal-body",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:t}),u]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:o,disabled:l,children:a}),n.jsx("button",{ref:d,type:"button",className:i?"w6w-btn w6w-btn-danger":"w6w-btn",onClick:s,disabled:l,children:r})]})]})}function pn(e){if(!e||typeof e!="object")return null;switch(e.type){case"string":return"";case"number":return 0;case"boolean":return!1;case"object":{const t={};for(const[s,o]of Object.entries(e.fields??{}))t[s]=pn(o);return t}case"array":return e.items?[pn(e.items)]:[];default:return null}}function mh(e){const t={};for(const s of e??[])s&&typeof s.nodeId=="string"&&s.nodeId!==""&&(t[s.nodeId]=s);return t}function ns(e){return e.sampleOmitted!==!0&&"sample"in e&&e.sample!==void 0}function ss(e,t){if(!t)return!1;const s=Date.parse(e.updatedAt),o=Date.parse(t);return Number.isFinite(s)&&Number.isFinite(o)&&s>o}function ul(e,t,s,o){const r=t[e],a=s[e];return r!==void 0&&(!a||!ss(a,o==null?void 0:o[e]))||!a?r:ns(a)?a.sample:pn(a.shape)}function wh(e,t,s){const o={};for(const r of new Set([...Object.keys(e),...Object.keys(t)])){const a=ul(r,e,t,s);a!==void 0&&(o[r]=a)}return o}function bh(e,t,s){const o={...e};for(const[r,a]of Object.entries(t))ns(a)&&(e[r]===void 0||ss(a,s==null?void 0:s[r]))&&(o[r]=a.sample);return o}function yh(e,t,s){const o={...e},r={};for(const[a,i]of Object.entries(t))e[a]!==void 0&&!ss(i,s==null?void 0:s[a])||(delete o[a],r[a]=ns(i)?i.sample:pn(i.shape));return{fresh:o,persisted:r}}function gh(e,t,s){const o={...e},r={};for(const[a,i]of Object.entries(t))ns(i)&&(e[a]===void 0||ss(i,s==null?void 0:s[a]))&&(delete o[a],r[a]=i.sample);return{fresh:o,persisted:r}}function xh(e,t){if(e.app)return e.app;if(e.app!==null)return t.get(e.appId)}function vh(e){const t=new Set;for(const s of e)s.app===void 0&&t.add(s.appId);return[...t]}exports.AddConnectionModal=co;exports.AnchoredFlyout=Ni;exports.ApiCallsPanel=Ii;exports.AppConnectionForm=xd;exports.AppIcon=It;exports.AppPicker=lt;exports.AuthFieldsForm=Cn;exports.AuthGuide=Ma;exports.CALL_APP=hn;exports.CHOICE_FIELD_TYPES=Wn;exports.CONDITION_OPS=Yr;exports.CONTROL_APP=qe;exports.CallTargetForm=ll;exports.CanvasLayer=fh;exports.CodeEditor=Zs;exports.Combobox=et;exports.ConditionEditor=Xn;exports.ConfigViewToggle=ts;exports.ConfirmModal=hh;exports.CredentialPicker=Ua;exports.DATA_APP=on;exports.DataTable=li;exports.DelegationSteps=lo;exports.DeleteButton=ho;exports.EACH_SOURCE_HANDLE=Hn;exports.EDITOR_THEME_SPEC=Xs;exports.ERROR_SOURCE_HANDLE=Ws;exports.EmptyState=Ri;exports.EventbriteTriggerPicker=$i;exports.ExpressionEditorModal=mn;exports.ExpressionInput=cn;exports.ExpressionOptionsProvider=Tu;exports.FIELD_TYPE_LABELS=Qr;exports.FOREACH_DONE_ROUTE=Ct;exports.FORM_APP=ut;exports.HTML_PREVIEW_CSP=ci;exports.HtmlPreview=di;exports.INTERNAL_NODES=dt;exports.IconButton=Kn;exports.InternalIcon=Qn;exports.JsonEditor=Ze;exports.LastUsedNote=vi;exports.Markdown=mo;exports.Modal=Ee;exports.NodeConfigForm=Qa;exports.ParamCustomization=fo;exports.ParamsForm=Ue;exports.PropertyEntryForm=ri;exports.PublisherBadge=ca;exports.RACE_APP=zt;exports.RACE_DESCRIPTION=sa;exports.RESULT_RENDER_MAX_CHARS=_s;exports.ROUTER_APP=Qe;exports.ResultViewer=Te;exports.RetryPolicyFields=Za;exports.RouterEditor=ni;exports.SCHEDULER_APP=Bs;exports.SCRIPT_APP=na;exports.SecretJsonField=La;exports.StepBuilderModal=Rf;exports.StepFanOutControl=tl;exports.StepNameEditor=si;exports.StepStateControl=nl;exports.StepTestRun=Uo;exports.StopEditor=oi;exports.TEXT_FIELD_TYPES=gl;exports.TRIGGER_APP=Vt;exports.TriggerFillForm=ji;exports.TriggerSampleButton=ai;exports.W6WUIProvider=Sc;exports.WEBHOOK_APP=ze;exports.WaitEditor=ki;exports.WorkflowConnectionPicker=Oi;exports.WorkflowConnectionsContext=Ti;exports.WorkflowProjectProvider=Cc;exports.ancestorIds=_o;exports.applyConnect=Op;exports.applyStepProblems=ip;exports.asFieldDefs=bo;exports.bindingFieldsFor=Wa;exports.bridgeDeletedBodyStep=Np;exports.buildBinding=Ha;exports.buildResolveScope=Qs;exports.callableTriggers=Lo;exports.canConnect=Ui;exports.centralizeConnections=Ci;exports.coerceDefault=go;exports.conditionCombinatorLabel=kd;exports.conditionOperatorLabel=jd;exports.connectConflict=Ip;exports.connectRefusal=Rp;exports.connectionAppIdsToLookUp=vh;exports.connectionExpressionSources=fp;exports.connectionIdFor=Kt;exports.controlOwnedIds=No;exports.convertCodeBindingsToReads=_u;exports.customCssTemplate=Sl;exports.dataVarRows=Mn;exports.declaredSamples=gf;exports.deepEqual=Ns;exports.defaultConnectionFor=Ai;exports.defaultFormDefinition=Zr;exports.definitionLoops=Eo;exports.deleteStepMessage=Tp;exports.detectResultFormat=hi;exports.edgeLane=je;exports.edgeVisuals=fn;exports.edgeWhenConflict=_p;exports.editConnectionResources=An;exports.effectiveEdges=Ao;exports.effectiveNodeOutput=ul;exports.effectiveNodeOutputs=wh;exports.eventbriteTriggerChoices=_i;exports.excludeSelfStep=Eu;exports.fanOutLabel=Af;exports.fanOutState=Sf;exports.fieldWidget=yo;exports.fieldsToParams=xo;exports.filterOptions=ma;exports.findChainRoot=Yp;exports.findChainTail=Xp;exports.findCodeBindings=$a;exports.findTestInput=bi;exports.flattenParams=Wt;exports.flowToWorkflow=Jp;exports.foreachTestFixture=of;exports.foreachTestSample=rf;exports.getTriggerDefs=il;exports.hasParamCustomization=Zn;exports.htmlPreviewSrcDoc=ui;exports.idClashMessage=Mp;exports.ifPortLayout=Bl;exports.indexNodeSamples=mh;exports.inferOutputFields=St;exports.internalNodeDef=At;exports.internalNodeDefaults=Pn;exports.internalNodeIcon=yc;exports.internalNodeLabel=bc;exports.internalNodeParams=aa;exports.isConnectionBlocked=up;exports.isControlApp=Dt;exports.isDollarPath=eo;exports.isEachLink=Dn;exports.isExprValue=tt;exports.isFloatingDraft=Yi;exports.isForeachStep=Se;exports.isFormResolvedOptions=Vn;exports.isIfStep=Ks;exports.isInputField=Gr;exports.isInternalApp=it;exports.isParamVisible=wn;exports.isSecretValue=pt;exports.isTestRequired=sl;exports.isTriggerApp=_n;exports.isTriggerStep=Vl;exports.keyClientId=Da;exports.laneForSourceHandle=Il;exports.loopBody=So;exports.loopItemText=hf;exports.loopMembership=Je;exports.loopRefusal=Di;exports.loopRefusalMessage=Ap;exports.newField=Cl;exports.nextWorkflowConnectionName=jo;exports.nodeConfigSources=vf;exports.nodeConfigValues=jf;exports.nodeMetaSampleValues=Nf;exports.nodeMetaValues=kf;exports.nodePortsForStep=rn;exports.normalizeInput=Ro;exports.parseFormDefinition=Al;exports.parseJsonFields=Fa;exports.parseLoopSeed=mf;exports.parseRootAnchoredTemplate=ft;exports.pickFormSubscription=wo;exports.pickWebhookSubscription=wi;exports.previewCustomization=ti;exports.previewNodeOutputs=bh;exports.relaneRefusal=Pp;exports.relayoutNodes=zp;exports.rememberableInput=vo;exports.renameStepInEdges=Fp;exports.requiredParamsFilled=Bt;exports.resolveConnectionAppMeta=xh;exports.resolveLoopItemsInState=Ji;exports.resolveOutputShape=kt;exports.resolveParamJson=an;exports.resolveParamValue=no;exports.resolveVarsJson=nu;exports.resultCopyText=mi;exports.routeFromHandle=ql;exports.routeHandle=Jt;exports.routerPortLayout=Hl;exports.routesForStep=Js;exports.secretClipboard=Rs;exports.seedValues=Ps;exports.selectNodeConnection=dp;exports.setEdgeWhen=$p;exports.shapeToSkeleton=pn;exports.shouldUseCombobox=ha;exports.slugName=ea;exports.slugifyLabel=Gp;exports.splitFrontmatter=ii;exports.splitNodeOutputs=yh;exports.splitPreviewOutputs=gh;exports.stampLoopOf=Ep;exports.startOAuthPopup=Ba;exports.startStateFromSeeds=Po;exports.stateWriteVisible=Pi;exports.stepBuilderLoop=df;exports.stepBuilderUpstreamSteps=uf;exports.stepNameError=Wi;exports.stepProblemTooltip=cp;exports.stepToJson=$o;exports.storedViewport=Bi;exports.stripBody=Co;exports.suggestStepId=Zp;exports.testInputSavesSettled=gi;exports.trackTestInputSave=yi;exports.uniqueName=Us;exports.upstreamSampleValueSources=yf;exports.upstreamSampleValues=bf;exports.upstreamStateSources=cf;exports.useEffectiveTheme=Bn;exports.useEnterSubmit=Va;exports.useExpressionOptions=nt;exports.useRememberedTestInput=xi;exports.useSeedSources=Fo;exports.useW6WApi=Ce;exports.useWorkflowConnections=ko;exports.valueAtPath=tn;exports.varLabel=Nt;exports.withConnectionRef=dn;exports.withViewport=Kp;exports.workflowToFlow=Vp;
29
+ //# sourceMappingURL=connection-app-meta-DID4zDg-.cjs.map