@w6w/ui 0.2.58 → 0.2.59

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.
@@ -1,24 +0,0 @@
1
- "use strict";const n=require("react/jsx-runtime"),b=require("react"),le=require("@w6w/expr"),Un=require("@codemirror/lang-javascript"),Bi=require("@codemirror/lang-python"),ds=require("@codemirror/view"),Vr=require("@uiw/react-codemirror"),ae=require("./CodeBlock-BSX1pi6W.cjs"),zr=require("@codemirror/lang-json"),ar=require("@codemirror/lint"),pn=require("react-dom"),Jn=require("@xyflow/react"),Ui=require("react-markdown");var Fn=typeof document<"u"?document.currentScript:null;const Ji={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function Vi(e){if(typeof e!="string"||e.trim()==="")return"";const t=Ji[e];return t||e.split(/[-_\s]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function zi(e){const t=new Map;for(const s of e)for(const r of s.categories??[])t.set(r,(t.get(r)??0)+1);return[...t.entries()].map(([s,r])=>({slug:s,label:Vi(s),count:r})).sort((s,r)=>r.count-s.count||s.label.localeCompare(r.label,void 0,{sensitivity:"base"}))}function Ki(e,t){if(t.length===0)return!0;const s=e.categories??[];return t.some(r=>s.includes(r))}function zt(e,t){const s=e==="error"?{className:"w6w-edge-error",label:"on error"}:e==="each"?{className:"w6w-edge-each"}:{};if(!t)return s;const r=t==="taken"?"w6w-edge-taken":"w6w-edge-skipped";return{className:s.className?`${s.className} ${r}`:r,...s.label?{label:s.label}:{}}}const ps="out-error",gn="out-each",jt="done",Kr="each";function fs(e){return e==="error"?ps:e==="each"?gn:void 0}function Gi(e){return e===ps?"error":e===gn?"each":"success"}const Yi="@w6w/",Te="@w6w/control",Gr="@w6w/script",Ht="@w6w/data",At="@w6w/trigger",Xi="@w6w/http",_e="@w6w/webhook",hs="@w6w/scheduler",Zi="@w6w/respond",yn="@w6w/call",ws="@w6w/document",Ln="@w6w/model",Qi="@w6w/template",Xt="@w6w/regex",De="@w6w/store",ms="@w6w/stop",We="@w6w/router",Kt="@w6w/race",Yr="Continue once with the first arriving path’s output. Later arrivals are ignored for this run. Other paths keep running.";function bs(e){var t;return e.uses.app!==We||!Array.isArray((t=e.with)==null?void 0:t.routes)?[]:e.with.routes.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string")}const Et=e=>`route:${e}`,ea=e=>e!=null&&e.startsWith("route:")?e.slice(6):void 0,ta=3,na=16;function sa(e){const t=e.find(o=>o.default),s=o=>({id:o.id,handleId:Et(o.id),label:o.default?"Fallback":o.label||o.id}),r=e.filter(o=>o!==t);return{right:r.map((o,i)=>({...s(o),top:`${(i+.5)/r.length*100}%`})),...t?{bottom:s(t)}:{},...r.length>ta?{minHeight:r.length*na}:{}}}const fn="false";function gs(e){return e.uses.app===Te&&e.uses.action==="if"}function ra(){return{right:[{id:"true",label:"True",top:"50%"}],bottom:{id:fn,handleId:Et(fn),label:"False"}}}function Ze(e){return e.startsWith(Yi)}function It(e){return e===Te||e===Kt}function hn(e){return e===At||e===_e||e===hs}function oa(e){return hn(e.app)||e.trigger===!0}const lr={in:1,out:Number.POSITIVE_INFINITY};function cr(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function ia(...e){let t,s;for(const r of e)t??(t=cr(r==null?void 0:r.in)),s??(s=cr(r==null?void 0:r.out));return{in:t??lr.in,out:s??lr.out}}function Wt(e,t){var i;if(e.uses.app===We)return{in:1,out:bs(e).length};const{app:s,action:r}=e.uses,o=e.uses.trigger?{in:0,out:1}:void 0;return ia(e.ports,t==null?void 0:t(s,r),((i=ct(s,r))==null?void 0:i.ports)??o)}const aa='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',ur='<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" />',la='<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" />',ca='<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" />',ua='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',da='<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" />',pa='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',dr='<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" />',fa='<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" />',ha='<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" />',wa='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',pr='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',ma='<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" />',ba='<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" />',Mn='<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" />',ga='<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" />',at='<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" />',ya=[{app:Xt,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:Xt,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:Xt,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:Xt,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"}]}],ft=[...ya,{app:Kt,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:We,action:"route",label:"Router",displayName:"Router",group:"control",icon:ur,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:ms,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."}],output:[{key:"stopped",label:"Stopped"}]},{app:At,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:aa,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:_e,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:ha,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:hs,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:da,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:Te,action:"if",label:"If",displayName:"If",group:"control",icon:ur,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:"A boolean, or an expression like {{ nodes.x.output.ok }}."}]},{app:Te,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:la,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:Te,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:ca,params:[]},{app:Te,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:ua,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:Gr,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:pa,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.
2
- 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:Qi,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:ga,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:Ht,action:"set",label:"Data",displayName:"Data set",group:"compute",icon:dr,params:[{key:"vars",type:"vars",label:"Variables",required:!0,default:[],hint:"Set values for downstream steps using individual fields or a JSON object."}]},{app:Ht,action:"update",label:"Update object",displayName:"Update object",group:"compute",icon:dr,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:Xi,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:fa,output:[{key:"status"},{key:"statusText"},{key:"ok"},{key:"headers"},{key:"body"}],params:[{key:"method",type:"string",label:"Method",required:!0,default:"GET",options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"PATCH",label:"PATCH"},{value:"DELETE",label:"DELETE"}],hint:"HTTP method for the request."},{key:"url",type:"string",label:"URL",required:!0,default:"",hint:"Full request URL, e.g. https://api.example.com/v1/things."},{key:"headers",type:"json",label:"Headers",default:{},hint:"Object of header name → value."},{key:"query",type:"json",label:"Query params",default:{},hint:"Object of query-string name → value, appended to the URL."},{key:"body",type:"text",label:"Body",default:"",hint:"Request body (raw text or a JSON string). Ignored for GET/HEAD."}]},{app:Zi,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:wa,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:Te,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:pr,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:Te,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:pr,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:yn,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:ma,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:ws,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:ba,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:Ln,action:"complete",label:"Complete with model",displayName:"Model",group:"compute",icon:Mn,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:Ln,action:"list-models",label:"List models",displayName:"Model",group:"compute",icon:Mn,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:Ln,action:"allowance",label:"Model allowance",displayName:"Model",group:"compute",icon:Mn,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:De,action:"get",label:"Get entry",displayName:"Store",group:"compute",icon:at,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:De,action:"set",label:"Set entry",displayName:"Store",group:"compute",icon:at,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:De,action:"delete",label:"Delete entry",displayName:"Store",group:"compute",icon:at,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:De,action:"increment",label:"Increment counter",displayName:"Store",group:"compute",icon:at,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:De,action:"list",label:"List entries",displayName:"Store",group:"compute",icon:at,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:De,action:"query",label:"Query rows",displayName:"Store",group:"compute",icon:at,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:De,action:"insert",label:"Insert row",displayName:"Store",group:"compute",icon:at,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"}]}];function ct(e,t){return ft.find(s=>s.app===e&&s.action===t)}function xa(e,t){var s;return((s=ct(e,t))==null?void 0:s.label)??t}function va(e,t){var s;return((s=ct(e,t))==null?void 0:s.icon)??""}function Xr(e,t){var s;return((s=ct(e,t))==null?void 0:s.params)??[]}function wn(e,t){const s={};for(const r of Xr(e,t))r.default!==void 0&&(s[r.key]=r.default);return s}function ja(e,t){return e.q===t.q&&(e.category??"")===(t.category??"")&&(e.ids??[]).join(",")===(t.ids??[]).join(",")}function Zr(e,t=0){return{query:e,generation:t,status:"loading",apps:[],hasMore:!1}}function Na(e,t){const s=new Set(e.map(o=>o.id)),r=[];for(const o of t)s.has(o.id)||(s.add(o.id),r.push(o));return r.length===0?e:[...e,...r]}function ka(e,t){switch(t.type){case"query-changed":return t.generation===e.generation&&ja(t.query,e.query)?e:Zr(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=Na(e.apps,t.apps),r=t.nextCursor!==void 0&&t.nextCursor===t.requestedCursor,o=!!t.nextCursor&&!r;return{...e,status:"ready",apps:s,cursor:o?t.nextCursor:void 0,hasMore:o,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 Sa(e){return e.filter(t=>!Ze(t.id))}function Dn(e,t,s){if(s<=0)return[];const r=[];for(const o of e)if(!t.has(o)&&(r.push(o),r.length>=s))break;return r}function Ca(e,t){const s=[];for(const r of e){const o=t.get(r);o&&s.push(o)}return s}const Qr=b.createContext(void 0);function fr(e,t){var r;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:(r=window.matchMedia)!=null&&r.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"}function xn(e){const t=b.useContext(Qr),[s,r]=b.useState(()=>fr(e,t));return b.useEffect(()=>{if(e){r(e);return}if(t){r(t);return}if(typeof window>"u")return;const o=()=>r(fr(void 0,t)),i=window.matchMedia("(prefers-color-scheme: dark)");i.addEventListener("change",o);const a=new MutationObserver(o);return a.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),o(),()=>{i.removeEventListener("change",o),a.disconnect()}},[e,t]),s}function ht({src:e,srcDark:t,brandColor:s,name:r,size:o=32,theme:i}){const l=xn(i)==="dark"?t??e:e,[u,c]=b.useState(void 0);if(l&&l!==u)return n.jsx("img",{src:l,width:o,height:o,alt:"",onError:()=>c(l),style:{width:o,height:o,borderRadius:6,flexShrink:0,objectFit:"contain",padding:Math.max(1,Math.round(o*.06)),boxSizing:"border-box",background:"var(--w6w-icon-swatch, var(--w6w-panel-2))"}});const d=(r??"?").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:o,height:o,borderRadius:6,background:s??"var(--w6w-accent)",color:"#fff",fontWeight:700,fontSize:Math.round(o*.42),flexShrink:0},children:d})}const ys=b.createContext(null);function Aa({api:e,theme:t,children:s}){const r=n.jsx(ys.Provider,{value:e,children:n.jsx(Qr.Provider,{value:t,children:s})});return t?n.jsx("div",{"data-theme":t,style:{display:"contents"},children:r}):r}function ye(){const e=b.useContext(ys);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}function nn(){return b.useContext(ys)??void 0}const eo=b.createContext(void 0),to=b.createContext(void 0);function Ea({project:e,workflowId:t,children:s}){return n.jsx(eo.Provider,{value:e,children:n.jsx(to.Provider,{value:t,children:s})})}function xs(){return b.useContext(eo)}function Ra(){return b.useContext(to)}const Hn=8,Ta=60,Oa=300;function hr(e){const t=e.modelProvider;return!t||typeof t!="object"?null:t}function Ia(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 ut({onSelectApp:e,theme:t,filter:s,searchPlaceholder:r,emptyMessage:o,search:i=!0,searchValue:a,onSearchChange:l,emptyAction:u,apps:c,categoryFilter:d=!1,providerFilter:f=!1,bridgeSupport:p,category:h,hasTriggers:m,ids:w,pageLimit:x=Ta,loadPage:g}){const y=ye(),A=c!==void 0,R=w&&w.length>0?w.join(","):"",S=!A&&(g!==void 0||typeof y.listAppsPage=="function"),v=b.useRef(g);v.current=g;const[j,C]=b.useState(null),[$,M]=b.useState(null);b.useEffect(()=>{if(A||S)return;const U=y.listApps;if(typeof U!="function"){C([]);return}let V=!1;return U().then(ne=>!V&&C(ne)).catch(ne=>!V&&M(ne.message)),()=>{V=!0}},[y,A,S]);const[k,T]=b.useReducer(ka,Zr({q:"",category:h,ids:w},0)),[I,F]=b.useState(""),q=a??I,z=U=>{a===void 0&&F(U),l==null||l(U)},[W,P]=b.useState(q.trim()),O=b.useRef(0),Z=b.useRef(null),Q=b.useCallback((U,V,ne)=>{var Ee;const Ne=v.current,ot=y.listAppsPage;if(!Ne&&!ot)return;(Ee=Z.current)==null||Ee.abort();const it=new AbortController;Z.current=it;let Pe;try{Pe=Ne?Ne({q:U.q||void 0,cursor:ne,limit:x,...U.ids?{ids:U.ids}:{},signal:it.signal}):ot({q:U.q||void 0,category:U.category,...m?{hasTriggers:!0}:{},...U.ids?{ids:U.ids}:{},cursor:ne,limit:x,compact:!0,signal:it.signal})}catch(he){Pe=Promise.reject(he)}Pe.then(he=>{if(O.current===V){if(!he||!Array.isArray(he.apps)){T({type:"page-failed",generation:V,error:"The server returned a malformed apps page."});return}T({type:"page-loaded",generation:V,apps:he.apps,nextCursor:he.nextCursor,requestedCursor:ne,total:typeof he.total=="number"?he.total:void 0})}}).catch(he=>{if(O.current!==V||he instanceof Error&&he.name==="AbortError")return;const Ot=he==null?void 0:he.code;if(ne!==void 0&&(Ot==="snapshot_expired"||Ot==="unknown_snapshot")){const N=++O.current;T({type:"query-changed",query:U,generation:N}),Q(U,N,void 0);return}T({type:"page-failed",generation:V,error:he.message})})},[y,x,m]);b.useEffect(()=>{if(!S)return;const U=setTimeout(()=>P(q.trim()),Oa);return()=>clearTimeout(U)},[q,S]),b.useEffect(()=>{if(!S)return;const U=++O.current,V={q:W,category:h,...R?{ids:R.split(",")}:{}};return T({type:"query-changed",query:V,generation:U}),Q(V,U,void 0),()=>{var ne;(ne=Z.current)==null||ne.abort()}},[S,W,h,R,Q]),b.useEffect(()=>{if(S)return()=>{var U;return(U=Z.current)==null?void 0:U.abort()}},[S]);const re=()=>{if(!S||k.status!=="ready"||!k.hasMore)return;const U=O.current;T({type:"load-more"}),Q(k.query,U,k.cursor)},_=()=>{!S||k.status!=="error"||(T({type:"retry"}),Q(k.query,O.current,k.cursor))},[Y,X]=b.useState([]),[B,G]=b.useState(!1),[te,E]=b.useState(!1),J=U=>n.jsx("div",{className:"w6w-apppicker-host",children:U});let ee,L=null,H=!1,ie=!1,pe=null,ue=!1;if(A?ee=c??null:S?(ee=k.apps,ue=k.status==="loading",H=k.status==="loading-more",ie=k.hasMore,k.status==="error"&&(k.apps.length===0?L=k.error??"Failed to load apps.":pe=k.error??"Failed to load apps.")):(ee=j,L=$),!S&&L)return J(n.jsx("div",{className:"w6w-result w6w-error",children:L}));if(!S&&ee===null)return J(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));ee??(ee=[]);const me=Sa(ee),Se=s?me.filter(s):me;if(!S&&Se.length===0)return J(n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:o??"No apps registered yet. Register one from the Apps page first."}),u]}));const je=d?zi(Se):[],Je=je.slice(0,Hn),ce=je.slice(Hn).filter(U=>Y.includes(U.slug)),Re=[...Je,...ce],Ve=je.length-Re.length,st=B?je:Re,mt=U=>X(V=>V.includes(U)?V.filter(ne=>ne!==U):[...V,U]),rt=()=>X([]),bt=Se.filter(U=>hr(U)!==null).length,Fe=f&&bt>0,ze=Fe&&te,Le=ze?Se.filter(U=>hr(U)!==null):Se,be=d&&Y.length>0?Le.filter(U=>Ki(U,Y)):Le,$e=S?be:[...be].sort((U,V)=>U.displayName.localeCompare(V.displayName,void 0,{sensitivity:"base"})),Ke=S?"":q.trim().toLowerCase(),ge=q.trim().length>0,xe=Ke?$e.filter(U=>U.displayName.toLowerCase().includes(Ke)||U.id.toLowerCase().includes(Ke)):$e,gt=s!==void 0&&Se.length!==me.length||ze&&Le.length!==Se.length||d&&Y.length>0&&be.length!==Le.length,Ce=(d&&Y.length>0||ze)&&xe.length===0,Tt=ze&&Y.length===0,Ge=()=>{X([]),E(!1),z("")};return J(n.jsxs("div",{className:"w6w-stepbuilder-apps",children:[i&&n.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:r??"Search apps…",value:q,onChange:U=>z(U.target.value),"aria-label":"Search apps"}),(Fe||d&&je.length>0)&&n.jsxs("div",{className:"w6w-apppicker-cats",children:[Fe&&n.jsxs("button",{type:"button",className:"w6w-apppicker-chip w6w-apppicker-provider-toggle","aria-pressed":te,"aria-label":"Filter to model providers",onClick:()=>E(U=>!U),children:["Model providers ",n.jsxs("span",{className:"w6w-muted",children:["(",bt,")"]})]}),d&&je.length>0&&n.jsxs(n.Fragment,{children:[st.map(U=>n.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":Y.includes(U.slug),"aria-label":`Filter by ${U.label}`,onClick:()=>mt(U.slug),children:[U.label," ",n.jsxs("span",{className:"w6w-muted",children:["(",U.count,")"]})]},U.slug)),!B&&Ve>0&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>G(!0),children:["+",Ve," more"]}),B&&je.length>Hn&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>G(!1),children:"Show less"}),Y.length>0&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:rt,children:"Clear"})]})]}),S&&ue?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):S&&L?n.jsxs("div",{className:"w6w-result w6w-error",children:[L," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:_,children:"Retry"})]}):xe.length===0&&!ie?Ce?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:Tt?ge?`No model providers match “${q}”.`:"No apps declare a model provider.":ge?`No apps match “${q}” 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:Ge,children:"Clear filters"})]}):S?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:ge?`No apps match “${q}”.`:o??"No apps registered yet. Register one from the Apps page first."}),!ge&&u]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No apps match “",q,"”."]}):n.jsxs(n.Fragment,{children:[xe.length===0&&ie?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:xe.map(U=>{const V=p==null?void 0:p.get(U.id),ne=Ia(V);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(U),children:[n.jsx(ht,{src:U.iconSvg,srcDark:U.iconSvgDark,brandColor:U.brandColor,name:U.displayName,theme:t,size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:U.displayName}),n.jsx("code",{className:"w6w-apppicker-card-id",children:U.id}),U.version&&n.jsxs("span",{className:"w6w-apppicker-card-version",children:["v",U.version]}),ne&&n.jsx("span",{className:V!=null&&V.supported?"w6w-chip w6w-apppicker-card-bridge":"w6w-chip w6w-apppicker-card-bridge w6w-apppicker-card-bridge-unsupported",title:ne.title,children:ne.text})]})]},U.id)})}),S&&typeof k.total=="number"&&n.jsx("div",{className:"w6w-small w6w-apppicker-count",children:gt?`${xe.length} ${xe.length===1?"app":"apps"}`:`${k.apps.length} of ${k.total}`}),S&&pe&&n.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[pe," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:_,children:"Retry"})]}),S&&ie&&!pe&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:re,disabled:H,children:H?"Loading more…":"Load more"})]})]}))}const vs={"&":{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 $a(){let e,t=0,s=!1;const r=new Map,o=()=>{e==null||e.terminate(),e=void 0;for(const a of r.values())a([]);r.clear()},i=async a=>{const l=a.matchBefore(/[\w$]*/);if(s||!l||!a.explicit&&l.from===l.to&&a.state.sliceDoc(a.pos-1,a.pos)!==".")return null;e||(e=new Worker(new URL(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/script-completion.worker-DDJKkj5M.js").href:new URL("assets/script-completion.worker-DDJKkj5M.js",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),typeof document>"u"?require("url").pathToFileURL(__filename).href:Fn&&Fn.tagName.toUpperCase()==="SCRIPT"&&Fn.src||new URL("connection-app-meta-CKTmUX08.cjs",document.baseURI).href),{type:"module"}),e.onmessage=c=>{var d;(d=r.get(c.data.id))==null||d(c.data.options),r.delete(c.data.id)},e.onerror=o);const u=await new Promise(c=>{const d=++t;r.set(d,c),a.addEventListener("abort",()=>{r.delete(d),c([])},{onDocChange:!0}),e==null||e.postMessage({id:d,code:a.state.doc.toString(),position:a.pos})});return a.aborted||!u.length?null:{from:l.from,options:u}};return[Un.javascriptLanguage.data.of({autocomplete:i}),ds.ViewPlugin.define(()=>(s=!1,{destroy(){s=!0,o()}}))]}function Pa(e){switch(e){case"javascript":return Un.javascript();case"typescript":return Un.javascript({typescript:!0});case"python":return Bi.python()}}function js(e){const t=xn(e.theme),{copied:s,copy:r}=ae.useCopyToClipboard(e.value),o=b.useMemo(()=>[...e.language?[Pa(e.language)]:[],...e.language==="javascript"||e.language==="typescript"?[$a()]:[],ds.EditorView.theme(vs)],[e.language]);return n.jsxs("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:[n.jsx(Vr,{value:e.value,onChange:e.onChange,extensions:o,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 r(),children:s?n.jsx(ae.CheckGlyph,{}):n.jsx(ae.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function _a(){const e=zr.jsonParseLinter();return t=>t.state.doc.toString().trim()===""?[]:e(t)}function He(e){const t=xn(e.theme),{copied:s,copy:r}=ae.useCopyToClipboard(e.value),o=b.useMemo(()=>[zr.json(),...e.showDiagnostics===!1?[]:[ar.linter(_a()),ar.lintGutter()],ds.EditorView.theme(vs)],[e.showDiagnostics]);function i(a){var l,u,c,d;if(e.onChange(a),!(!e.onValidChange&&!e.onValidityChange)){if(a.trim().length===0){(l=e.onValidityChange)==null||l.call(e,{valid:!1,error:"Empty"});return}try{const f=JSON.parse(a);(u=e.onValidChange)==null||u.call(e,f),(c=e.onValidityChange)==null||c.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(Vr,{value:e.value,onChange:i,extensions:o,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 r(),children:s?n.jsx(ae.CheckGlyph,{}):n.jsx(ae.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function no(e,t,s){return e*t>.6*s}function so(e,t){const s=t.trim().toLowerCase();return s?e.filter(r=>r.label.toLowerCase().includes(s)||r.value.toLowerCase().includes(s)):e}const Fa=240,La={display:"block",fontSize:"0.85em",opacity:.65,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},Ma={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 wt({options:e,value:t,onChange:s,placeholder:r,disabled:o,"aria-label":i,mode:a="auto",forceSelection:l=!0,optionHeight:u=32,listMaxHeight:c=Fa,className:d,onInputChange:f,emptyText:p="No matches",footer:h}){var W;const m=a==="combobox"||a==="auto"&&no(e.length,u,typeof window>"u"?0:window.innerHeight),w=b.useId(),x=((W=e.find(P=>P.value===t))==null?void 0:W.label)??(l?"":t),[g,y]=b.useState(x),[A,R]=b.useState(!1),[S,v]=b.useState(!1),[j,C]=b.useState(0),$=b.useRef(null);b.useEffect(()=>{y(x)},[x]);const M=b.useMemo(()=>S?so(e,g):e,[e,g,S]),k=b.useMemo(()=>({...Ma,maxHeight:c}),[c]);if(!m)return n.jsxs("select",{className:d,value:t,disabled:o,"aria-label":i,onChange:P=>s(P.target.value),children:[r!==void 0&&t===""&&n.jsx("option",{value:"",disabled:!0,children:r}),e.map(P=>n.jsx("option",{value:P.value,children:P.label},P.value))]});const T=P=>`${w}-opt-${P}`,I=()=>{R(!1),v(!1)},F=P=>{y(P.label),s(P.value),I()},q=P=>{P.key==="ArrowDown"?(P.preventDefault(),A?C(O=>Math.min(O+1,M.length-1)):R(!0)):P.key==="ArrowUp"?(P.preventDefault(),A?C(O=>Math.max(O-1,0)):R(!0)):P.key==="Enter"?A&&M[j]?(P.preventDefault(),F(M[j])):l||(g!==x&&s(g),I()):P.key==="Escape"&&(A&&P.stopPropagation(),y(x),I())},z=()=>{l?y(x):g!==x&&s(g),I()};return n.jsxs("div",{ref:$,className:"w6w-combobox",style:{position:"relative"},children:[n.jsx("input",{type:"text",role:"combobox",className:d,value:g,disabled:o,placeholder:r,"aria-label":i,"aria-expanded":A,"aria-controls":`${w}-list`,"aria-autocomplete":"list","aria-activedescendant":A&&M[j]?T(j):void 0,autoComplete:"off",onFocus:()=>R(!0),onChange:P=>{y(P.target.value),f==null||f(P.target.value),v(!0),C(0),R(!0)},onKeyDown:q,onBlur:z}),A&&n.jsxs("div",{id:`${w}-list`,role:"listbox",tabIndex:-1,"aria-label":i,style:k,children:[M.map((P,O)=>n.jsxs("div",{id:T(O),role:"option",tabIndex:-1,"aria-selected":P.value===t,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:O===j?"var(--w6w-panel-2)":void 0},onMouseDown:Z=>{Z.preventDefault(),F(P)},onMouseEnter:()=>C(O),children:[P.label,P.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:La,children:P.detail})]},P.value)),M.length===0&&n.jsx("div",{role:"presentation",style:{padding:"6px 8px",opacity:.6},children:p}),h!==void 0&&n.jsx("div",{role:"presentation",className:"w6w-combobox-footer",style:{padding:"6px 8px",opacity:.6,fontSize:"0.85em"},children:h})]})]})}function vn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.source==="resolveFields"}function qe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="expr"&&Array.isArray(e.parts)}function tt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function wr(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 sn(e){const t=e.filter(r=>r.kind!=="text"||(r.value??"")!=="");if(t.length===0)return"";if(t.some(r=>r.kind==="render"))return{type:"expr",parts:t.map(wr)};let s="";for(const r of t){if(r.kind==="text"){s+=r.value??"";continue}Da(s)%2===1&&(s+="\\"),s+=le.serializeTemplate([wr(r)])}return s}function Da(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t+=1;return t}const ro={var:!0,vars:!0,state:!0,steps:!0,nodes:!0,trigger:!0,foreach:!0,inputs:!0,output:!0,secrets:!0,documents:!0,const:!0};Object.freeze(Object.keys(ro));const mr=e=>Object.prototype.hasOwnProperty.call(ro,e),br=["state","var","vars"];function oo(e){for(const t of br)if(e===t||e.startsWith(`${t}.`)){const s=e.slice(t.length);return[...new Set([e,...br.map(r=>r+s)])]}return[e]}function gr(e){const t=e.indexOf(".");return t===-1?e:e.slice(0,t)}function Qe(e){const t=le.parseTemplate(e,"editor",Ha);return t.every(jn)?t:[{kind:"text",value:e}]}function jn(e){if(e.kind==="var"){const t=e.ref??"";return!le.hasRefusedChainToken(t)&&mr(gr(t))}if(e.kind==="expr"){const t=le.coalesceOperandRefs(e.expr);return t===null?!0:t.every(s=>mr(gr(s)))}return!0}const Ha={isOurs:jn,backslash:"keep"},io={isOurs:jn,backslash:"strip"};function et(e){return qe(e)?!0:typeof e=="string"&&e.includes("{{")&&Qe(e).some(t=>t.kind!=="text")}function Nn(e){if(!e.includes("{{"))return null;const t=le.parseTemplate(e,"editor",io);return t.every(jn)&&(t.some(s=>s.kind!=="text")||t.map(s=>s.value??"").join("")!==e)?t:null}function Wa(e){return e.includes("{{")?le.parseTemplate(e,"editor",io).map(t=>t.kind==="text"?t.value??"":le.serializeTemplate([t])).join(""):e}function Vn(e){if(tt(e))return{parts:[],sealed:e};if(qe(e))return{parts:e.parts.map(s=>({...s})),sealed:null};const t=typeof e=="string"?e:"";return{parts:t?Qe(t):[],sealed:null}}function qa(e,t){let s="";for(const r of e)switch(r.kind){case"text":s+=Wa(r.value??"");break;case"var":case"render":{const o=oo(r.ref??"").find(i=>i in t);s+=o===void 0?"":t[o];break}case"secret":s+="•••";break;case"expr":s+=le.serializeTemplate([r]);break}return s}const Nt="var.",yr="vars.",zn="documents.",Kn="const.",Gn="state.";function ao(e){return e==="state"||e==="vars"?"var":e.startsWith(yr)?Nt+e.slice(yr.length):e.startsWith(Gn)?Nt+e.slice(Gn.length):e}function Ba(e){return e.startsWith(Gn)?3:e.startsWith(Nt)?2:1}function lo(e){return e.rank>0?e.value:Object.fromEntries(Array.from(e.children,([t,s])=>[t,lo(s)]))}function Ns(e,t,s,r){const o={children:new Map,rank:0},i={},a={};for(const[m,w]of Object.entries(e??{})){const x=ao(m);if(x.startsWith(Nt)){const g=x.slice(Nt.length),y=Ba(m);let A=o;for(const R of g.split(".")){let S=A.children.get(R);S||(S={children:new Map,rank:0},A.children.set(R,S)),A=S}y>=A.rank&&(A.value=w,A.rank=y)}else x.startsWith(zn)?i[x.slice(zn.length)]=w:x.startsWith(Kn)&&(a[x.slice(Kn.length)]=w)}const l=lo(o),u=(t==null?void 0:t.steps)??{},c=e??{},d=Object.hasOwn(c,"foreach.item"),f=typeof c["foreach.index"]=="number",p=t==null?void 0:t.foreach,h=p?{...p}:d||f?{...d?{item:c["foreach.item"]}:{},...f?{index:c["foreach.index"]}:{}}:void 0;return{...h?{foreach:h}:{},vars:l,state:l,documents:i,constants:a,steps:u,nodes:u,trigger:(t==null?void 0:t.trigger)??{},flat:e??{},...s?{config:s}:{},...r?{meta:r}:{}}}function Ua(e,t){const s=t.split(".");let r=e;for(const o of s){if(r===null||typeof r!="object")return{present:!1,value:void 0};if(!(o in r))return{present:!1,value:void 0};r=r[o]}return{present:!0,value:r}}const Ja=/^(?:nodes|steps)\.[^.]+\.(?:meta\.)?config(?:\.|$)/,Va=/^(?:nodes|steps)\.([^.]+)\.meta(?:\.|$)/;function za(e,t,s){var o;if(!t&&!s)return e;const r={...e};for(const i of new Set([...Object.keys(s??{}),...Object.keys(t??{})])){const a=t==null?void 0:t[i];r[i]={...e[i],meta:{...s==null?void 0:s[i],...(o=e[i])==null?void 0:o.meta,...a?{config:a}:{}},...a?{config:a}:{}}}return r}function co(e,t){var p;const s=ao(e);if(t.flat&&(s.startsWith(Nt)||s.startsWith(zn)||s.startsWith(Kn))){const h=oo(e).find(m=>Object.hasOwn(t.flat,m));if(h!==void 0)return{status:"resolved",ref:e,value:t.flat[h]}}const{vars:r,constants:o,config:i,meta:a,...l}=t,u=za(t.nodes??t.steps,i,a),c={...l,var:r,...o?{const:o}:{},nodes:u,steps:u},d=Ua(c,s);if(d.present)return{status:"resolved",ref:e,value:d.value};if(Ja.test(s))return{status:"at-run",ref:e};const f=(p=Va.exec(s))==null?void 0:p[1];return f!==void 0&&(a!=null&&a[f])?{status:"at-run",ref:e}:{status:"unresolved",ref:e}}function xr(e,t){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return co(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 ks(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function Ss(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function Cs(e,t){if(tt(e))return[{status:"masked"}];if(qe(e))return e.parts.map(s=>xr(s,t));if(typeof e=="string"){const s=Nn(e);if(s)return s.map(r=>xr(r,t))}return ks(e)?[co(String(e.$),t)]:Ss(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function Yn(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),r=Array.isArray(t);if(s!==r)return!1;if(s){const u=e,c=t;return u.length===c.length&&u.every((d,f)=>Yn(d,c[f]))}const o=e,i=t,a=Object.keys(o),l=Object.keys(i);return a.length===l.length&&a.every(u=>u in i&&Yn(o[u],i[u]))}function uo(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 Ka(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(uo(e))}function Ga(e){return e.length===1?uo(e[0]):e.map(Ka).join("")}function qt(e,t){return Ga(Cs(e,t))}function Ya(e,t){const s={};for(const r of e)s[r.key||"(no key)"]=qt(r.value,t);return s}const kn=b.forwardRef(function(t,s){const{label:r,children:o,icon:i,iconSize:a,title:l,onClick:u,disabled:c,className:d,danger:f,...p}=t,h=o??(i?n.jsx(ae.Icon,{name:i,size:a??16}):null);return n.jsx("button",{ref:s,type:"button",className:["w6w-icon-button",f?"w6w-icon-button-danger":"",d??""].filter(Boolean).join(" "),title:l??r,"aria-label":r,"aria-pressed":p["aria-pressed"],"aria-expanded":p["aria-expanded"],"aria-controls":p["aria-controls"],disabled:c,onClick:u,"data-testid":p["data-testid"],children:h})});kn.displayName="IconButton";const Xa={default:"",wide:" w6w-modal-wide",xl:" w6w-modal-xl",full:" w6w-modal-full",fullscreen:" w6w-modal-fullscreen"};function ve({title:e,ariaLabel:t,onClose:s,children:r,size:o="default",titleIcon:i,subtitle:a,headerRight:l}){const u=b.useRef(null),c=b.useRef(null);return b.useEffect(()=>()=>{var d;(d=c.current)!=null&&d.isConnected&&c.current.focus({preventScroll:!0})},[]),b.useEffect(()=>{const d=u.current;if(!d)return;d.open||(c.current=document.activeElement,d.showModal());const f=h=>{h.preventDefault(),s()},p=h=>{if(h.target!==d)return;const m=d.getBoundingClientRect();(h.clientX<m.left||h.clientX>m.right||h.clientY<m.top||h.clientY>m.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:u,className:`w6w-modal${Xa[o]}`,"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:[i,n.jsx("span",{children:e}),a&&n.jsx("span",{className:"w6w-modal-subtitle",children:a})]}),l]}),r]})})}const As=new Set(["nodes","steps","state","var","vars","const","inputs","output","trigger","foreach","documents"]),Za=/[=<>]|!=|&&|\|\||\?\?/,rn=e=>Za.test(e)||/^\s*\(*\s*!/.test(e),vr=e=>le.expressionReferences(e).some(rn);function Qa(e,t){var i,a,l;const[s,...r]=e.split(".");if(s==="secrets")throw new Error("Secrets can be inserted into text, but cannot be used in comparisons.");if(As.has(s))return e;const o=[...(i=t.steps)!=null&&i.some(u=>u.id===s)?[`nodes.${s}.output`]:[],...(a=t.vars)!=null&&a.includes(s)?[`var.${s}`]:[],...(l=t.constants)!=null&&l.includes(s)?[`const.${s}`]:[]];if(o.length>1)throw new Error(`“${s}” is ambiguous. Select the field from the sources.`);if(o.length===0)throw new Error(`Unknown field “${s}”. Select a source, or put text values in quotes.`);return[o[0],...r].join(".")}function $t(e,t){var c,d,f,p,h;const s={parts:e,error:null},r=e.flatMap(m=>m.kind==="text"?Qe(m.value??""):[m]);if(r.some(m=>m.kind==="render"))return s;if(r.length===1&&r[0].kind==="expr"&&!vr(r[0].expr))return{parts:r,error:null};let o=r.map(m=>{if(m.kind==="text")return m.value??"";if(m.kind==="secret")return`{{ secrets.${m.ref??""} }}`;if(m.kind==="expr"){if(vr(m.expr)){const x=le.serializeTemplate([m]);if(!x.startsWith("{{ ="))return`(${x.slice(2,-2).trim()})`}const w=le.formatReadableExpression(m.expr);return w===null?le.serializeTemplate([m]):`(${w})`}return rn(m.ref??"")?m.ref??"":`{{ ${m.ref??""} }}`}).join("").trim();if(!rn(o))return s;const i=/^\{\{([^{}]+)\}\}$/.exec(o);i&&rn(i[1])&&(o=i[1].trim());const a=o.replace(/^[\s(!]+/,""),l=(c=/^(?:\{\{\s*)?([A-Za-z_$][\w$-]*)/.exec(a))==null?void 0:c[1],u=a.startsWith("{{")||l!==void 0&&(As.has(l)||l==="secrets"||((d=t.steps)==null?void 0:d.some(m=>m.id===l))||((f=t.vars)==null?void 0:f.includes(l))||((p=t.constants)==null?void 0:p.includes(l)));if(!u&&!/^(?:["']|-?\d|true\b|false\b|null\b)/.test(a))return s;if(u&&!/^\s*\(*\s*!/.test(o)){const m=(h=/^(?:\{\{[^{}]+\}\}|[A-Za-z_$][\w$-]*(?:\.[\w$-]+)*)/.exec(a))==null?void 0:h[0];if(m){const w=a.slice(m.length).replace(/^[\s)]+/,"");if(!/^(?:[=<>(]|!=|&&|\|\||\?\?)/.test(w)||/^<\/?[A-Za-z][^>]*>/.test(w))return s}}try{return{parts:[{kind:"expr",expr:le.parseReadableExpression(o,w=>Qa(w,t))}],error:null}}catch(m){return{parts:r,error:m instanceof Error?m.message:"Check the expression."}}}function el(e){return[...new Set(e.flatMap(t=>t.kind==="expr"?le.expressionReferences(t.expr):(t.kind==="var"||t.kind==="render")&&t.ref?[t.ref]:[]))]}function tl(e){return e.replace(/^(?:vars|state)(?=\.|$)/,"var").replace(/^steps(?=\.|$)/,"nodes")}function nl(e){const t=Object.create(null);for(const[s,r]of Object.entries(e).sort(([o],[i])=>o.split(".").length-i.split(".").length)){const o=tl(s).split(".");if(!As.has(o[0])||o.some(a=>["__proto__","constructor","prototype"].includes(a)))continue;let i=t;for(const a of o.slice(0,-1)){const l=i[a],u=l&&typeof l=="object"?{...l}:{};i[a]=u,i=u}i[o[o.length-1]]=r}return t.steps=t.nodes,t.vars=t.var,t.state=t.var,t}function sl(e,t={},s={}){const r={...t};for(const[a,l]of Object.entries(s))try{r[a]=JSON.parse(l)}catch{r[a]=l}const o=nl(r),i=Object.fromEntries(Object.entries(r).map(([a,l])=>[a,typeof l=="string"?l:JSON.stringify(l)]));return e.map(a=>{if(a.kind!=="expr"||le.formatReadableExpression(a.expr)===null)return qa([a],i);if(le.expressionReferences(a.expr).some(c=>!c||c.split(".")[0]==="secrets"))return"••••";const u=le.evaluate(a.expr,o);return typeof u=="string"?u:JSON.stringify(u)??""}).join("")}const rl=/^(?:nodes|steps)\.([^.]+)\.output(?:\.(.+))?$/,ol=/^(?:nodes|steps)\.([^.]+)\.meta\.(app|version|action|connectionId)$/,Xe=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=rl.exec(e);if(t)return t[2]?`${t[1]}.${t[2]}`:t[1];const s=ol.exec(e);return s?`${s[1]} meta · ${s[2]}`:e};function il(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 al(e){const t=e.op==="or"?"||":"??",s=e.operands.map(r=>{const o=il(r);return o!==void 0?Xe(o):JSON.stringify(r)}).join(` ${t} `);return s.length>40?`${s.slice(0,40)}…`:s}const ll=/[.{}]/;function yt(e){return e===""||e!==e.trim()?!1:!ll.test(e)}function Zt(e){return e.split(".").every(yt)}function jr(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};const r=s.key.split(".");let o=0,i=0;for(let a=1;a<r.length;a++)t.has(r.slice(0,a).join("."))&&(o++,i=a);return{field:s,depth:o,name:r.slice(i).join(".")}})}function Ft(e,t,{renderToggle:s}={}){const r=e.createElement("span");r.contentEditable="false",r.className=`w6w-expr-chip w6w-expr-chip-${t.kind}`,r.setAttribute("data-kind",t.kind);const o=e.createElement("span");o.className="w6w-expr-chip-sigil";const i=e.createElement("span");if(i.className="w6w-expr-chip-label",t.kind==="var")r.setAttribute("data-ref",t.ref??""),o.textContent="◆",i.textContent=Xe(t.ref??""),r.title=`Variable: ${t.ref??""}`;else if(t.kind==="render")r.setAttribute("data-ref",t.ref??""),o.textContent="▤",i.textContent=Xe(t.ref??""),r.title=`Render as template: ${t.ref??""}`;else if(t.kind==="secret")r.setAttribute("data-ref",t.ref??""),o.textContent="🔒",i.textContent=t.ref??"",r.title=`Secret: ${t.ref??""}`;else{const l=typeof t.expr=="string"?t.expr:JSON.stringify(t.expr??"");r.setAttribute("data-expr",l),o.textContent="ƒ";const u=le.parseCoalesceChain(t.expr);if(u)i.textContent=al(u),r.title=`Expression: ${le.serializeTemplate([t])}`;else{const c=le.formatReadableExpression(t.expr,Xe);i.textContent=c??(l.length>24?`${l.slice(0,24)}…`:l||"expr"),r.title=`Expression: ${c??l}`}}if(r.append(o,i),(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 u=t.kind==="render"?"Stop rendering as a template":"Render this as a template";l.setAttribute("aria-label",u),l.title=u,l.textContent="⇄",r.append(l)}const a=e.createElement("span");return a.className="w6w-expr-chip-x",a.setAttribute("data-x","1"),a.setAttribute("role","button"),a.setAttribute("aria-label","Remove"),a.textContent="×",r.append(a),r}const po=new Set(["div","p"]);function fo(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 r=s;try{r=JSON.parse(s)}catch{r=s}return{kind:"expr",expr:r}}return null}function Pt(e){const t=[],s=i=>{if(!i)return;const a=t[t.length-1];a&&a.kind==="text"?a.value=(a.value??"")+i:t.push({kind:"text",value:i})},r=(i,a)=>{if(i.nodeType===Node.TEXT_NODE){s(i.textContent??"");return}if(i.nodeType!==Node.ELEMENT_NODE)return;const l=i,u=fo(l);if(u){t.push(u);return}const c=(l.tagName??"").toLowerCase();if(c==="br"){a||s(`
3
- `);return}const d=po.has(c);d&&t.length>0&&s(`
4
- `),o(l,d)},o=(i,a)=>{const l=Array.from(i.childNodes);l.forEach((u,c)=>r(u,a&&c===l.length-1))};return o(e,!0),t}const ho=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function wo(e){ho(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function cl(e){const t=e.ownerDocument.getSelection(),s=t!=null&&t.rangeCount?t.getRangeAt(0):null;if(!s||!e.contains(s.endContainer))return e;let r=s.endContainer;for(;r&&r!==e;){if(r.nodeType===Node.ELEMENT_NODE){const o=r;if(po.has((o.tagName??"").toLowerCase()))return o}r=r.parentNode}return e}function mo(e){wo(cl(e))}const ul=e=>e.getAttribute("aria-multiline")!=="false";function bo(e,t,s){var i;const r=e.ownerDocument;e.textContent="";for(const a of t)a.kind==="text"?a.value&&e.appendChild(r.createTextNode(a.value)):e.appendChild(Ft(r,a,s));const o=t[t.length-1];(o==null?void 0:o.kind)==="text"&&((i=o.value)!=null&&i.endsWith(`
5
- `))&&ul(e)&&wo(e)}function Es(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 _t(e,t){const s=e.ownerDocument,r=s.getSelection(),o=r!=null&&r.rangeCount?r.getRangeAt(0):null;if(o&&e.contains(o.commonAncestorContainer)){o.deleteContents(),o.insertNode(t);const i=s.createRange();i.setStartAfter(t),i.collapse(!0),r==null||r.removeAllRanges(),r==null||r.addRange(i)}else ho(e.lastChild)?e.insertBefore(t,e.lastChild):e.appendChild(t),Es(e);e.focus()}function go(e,t={}){const s=e.ownerDocument,r=s.getSelection();if(!r||r.rangeCount===0||!r.isCollapsed)return!1;const o=r.getRangeAt(0),i=o.startContainer;if(i.nodeType!==Node.TEXT_NODE||!e.contains(i))return!1;const a=o.startOffset,l=i.textContent??"";if(a<2||l.slice(a-2,a)!=="}}")return!1;const u=l.lastIndexOf("{{",a-2);if(u===-1)return!1;const c=l.slice(u,a),d=Qe(c);if(d.length!==1||d[0].kind==="text")return!1;let f=0;for(;u-1-f>=0&&l[u-1-f]==="\\";)f+=1;if(f%2===1)return!1;const p=s.createRange();p.setStart(i,u),p.setEnd(i,a),p.deleteContents();const h=Ft(s,d[0],t);p.insertNode(h);const m=s.createRange();return m.setStartAfter(h),m.collapse(!0),r.removeAllRanges(),r.addRange(m),!0}function yo(e){const t=fo(e);if(!t)return null;const s=t.kind==="expr"&&!le.parseCoalesceChain(t.expr)?le.formatReadableExpression(t.expr):null,r=e.ownerDocument.createTextNode(s??le.serializeTemplate([t]));return e.replaceWith(r),r}function dl(e,t){let s=!1;for(let r=0;r<t&&r<e.length;r++){const o=e[r];if(s&&o==="\\"){r++;continue}o==='"'&&(s=!s)}return s}function pl(e){const t=e.split(".").filter(r=>r!==""),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 fl(e,t){const s=[];let r=!1;for(let i=0;i<t&&i<e.length;i++){const a=e[i];if(r){a==="\\"?i++:a==='"'&&(r=!1);continue}a==='"'?r=!0:a==="{"||a==="["?s.push(a):(a==="}"||a==="]")&&s.pop()}const o=s[s.length-1];return o==="{"||o==="["?o:null}function hl(e,t){if(!e||!Object.hasOwn(e,t))return t;let s=2;for(;Object.hasOwn(e,`${t}_${s}`);)s++;return`${t}_${s}`}function Nr(e,t,s,r){var x;const o=r?JSON.stringify(r.value)??"null":"",i=r?JSON.stringify(typeof r.value=="string"?r.value:o).slice(1,-1):`{{ ${s} }}`,a=r?o:JSON.stringify(i),l=(g,y)=>({text:e.slice(0,g)+y+e.slice(g),caret:g+y.length});if(dl(e,t))return l(t,i);let u,c=!0;try{u=JSON.parse(e)}catch{c=!1}const d=c&&u!==null&&typeof u=="object"&&!Array.isArray(u)?u:null,f=()=>`${JSON.stringify(hl(d,pl(s)))}: ${a}`,p=e.slice(0,t).trimEnd(),h=p[p.length-1],m=e.slice(t).trimStart()[0],w=fl(e,t);if(h===":"||h==="["||h===","&&w==="[")return l(t,a+(h!==":"&&m!==void 0&&m!=="]"?", ":""));if(h==="{"||h===","&&w==="{"){const g=m!==void 0&&m!=="}"?", ":"";return l(t,(h===","?" ":"")+f()+g)}if(c&&(d||Array.isArray(u))){const g=e.lastIndexOf(d?"}":"]"),y=e.slice(0,g).trimEnd(),A=y.endsWith(d?"{":"["),R=d?f():a,S=e.slice(y.length,g);if(S.includes(`
6
- `)){const C=A?`${S.slice(S.lastIndexOf(`
7
- `)+1)} `:((x=/^\s*/.exec(y.slice(y.lastIndexOf(`
8
- `)+1)))==null?void 0:x[0])??"",$=`${A?"":","}
9
- ${C}${R}`;return{text:y+$+e.slice(y.length),caret:y.length+$.length}}const v=`${A?"":","} ${R} `,j=y.length;return{text:e.slice(0,j)+v+e.slice(g),caret:j+v.length-1}}return l(t,a)}const wl=/^\{\{\s*((?:var|vars|const|steps|nodes|trigger|foreach|inputs|output|documents)(?:\.[^\s{}]+)?)\s*\}\}$/;function ml(e){const t=wl.exec(e.trim());return t?`{{ ${t[1]} }}`:null}function nt(e){if(typeof e=="string"){if(!e.includes("{{"))return null;const t=Qe(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 bl(e){var s;const t={};for(const[r,o]of Object.entries(e??{})){const i=/^(?:steps|nodes)\.([^.]+)\.output$/.exec(r);if(i){t[i[1]]={...t[i[1]],output:o};continue}const a=/^(?:steps|nodes)\.([^.]+)\.meta\.([^.]+)$/.exec(r);if(a){t[s=a[1]]??(t[s]={});const l=t[a[1]];l.meta={...l.meta,[a[2]]:o}}}return{steps:t}}function Xn(e,t){if(typeof e=="string"){const s=Nn(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=>Xn(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(([r,o])=>[r,Xn(o,t)]))}return e}function Gt({value:e,masked:t,multiline:s,options:r,fieldLabel:o,onSave:i,onClose:a,mode:l,jsonValue:u,onSaveJson:c,whole:d,startingState:f,jsonProblem:p,title:h}){var Ot;const m=l==="json-binding",w=m&&f===!0,[x,g]=b.useState("ref"),[y,A]=b.useState(()=>u===void 0?"":JSON.stringify(u,null,2)),R=b.useRef(null),S=b.useRef(!1),v=b.useMemo(()=>{if(y.trim()==="")return{ok:!1};try{return{ok:!0,value:JSON.parse(y)}}catch{return{ok:!1}}},[y]),j=w?(p==null?void 0:p(y))??null:null,C=w?(y.trim()===""||v.ok)&&j===null:v.ok,$=()=>Ns(r.sampleValues,bl(r.sampleValues),r.nodeConfig,r.nodeMeta),M=m?v.ok?JSON.stringify(Xn(v.value,N=>qt(N,$())),null,2):y.trim()===""?"":"Invalid JSON":"",k=N=>{const D=R.current,K=D?D.state.doc.toString():y;if(w){const Me=x==="value"?{value:qt(`{{ ${N} }}`,$())??null}:void 0,ir=K.trim()===""?"{}":K,qi=S.current&&D?D.state.selection.main.head:ir.length,_n=Nr(ir,qi,N,Me);if(!D){A(_n.text);return}D.dispatch({changes:{from:0,to:K.length,insert:_n.text},selection:{anchor:_n.caret}}),D.focus();return}let se=null;try{se=K.trim()===""?null:nt(JSON.parse(K))}catch{se=null}let fe=!1;if(d)try{const Me=JSON.parse(K);fe=Array.isArray(Me)?Me.length===0:typeof Me=="object"&&Me!==null&&Object.keys(Me).length===0}catch{fe=!1}if(K.trim()===""||se!==null||fe){c==null||c(`{{ ${N} }}`),a();return}if(!D)return;const de=S.current?D.state.selection.main.head:K.length,oe=Nr(K,de,N);D.dispatch({changes:{from:0,to:K.length,insert:oe.text},selection:{anchor:oe.caret}}),D.focus()},[T,I]=b.useState(()=>$t(Vn(e).parts,r).parts),F=b.useMemo(()=>$t(T,r),[T,r]),[q,z]=b.useState(0),W=b.useRef(null),P=b.useRef(!1),[O,Z]=b.useState({}),[Q,re]=b.useState(null),[_,Y]=b.useState(()=>new Set),X=N=>{Y(D=>{const K=new Set(D);return K.has(N)?K.delete(N):K.add(N),K})},[B,G]=b.useState("auto");b.useLayoutEffect(()=>{const N=W.current;N&&(bo(N,T,{renderToggle:!0}),P.current&&(P.current=!1,Es(N),N.focus()))},[q]);const te=()=>{const N=W.current;N&&I(Pt(N))},E=N=>{const D=W.current;D&&(_t(D,Ft(D.ownerDocument,N,{renderToggle:!0})),I(Pt(D)))},J=T.some(N=>N.kind==="render"),ee=(N,{restoreFocus:D})=>{I($t(Qe(N),r).parts),z(K=>K+1)},L=()=>{const N=W.current,D=$t(N?Pt(N):T,r);D.error||(i==null||i(sn(D.parts)),a())},H=()=>{re(null),P.current=!0,z(N=>N+1)},ie=r.vars??[],pe=r.constants??[],ue=r.secrets??[],me=r.inputs??[],Se=r.documents??[],je=r.steps??[],Je=r.nodeConfigs??[],ce=r.loop,Re=new Map(Je.map(N=>[N.id,N.keys.filter(yt)]).filter(([,N])=>N.length>0)),Ve=r.nodeMeta??{},st=N=>gl.filter(([D])=>yl.has(D)?rt(N):Object.hasOwn(Ve[N]??{},D)),mt=je.filter(N=>N.hasMeta===!0).map(N=>N.id),rt=N=>{var K;if(mt.includes(N))return!0;const D=(K=Ve[N])==null?void 0:K.app;return typeof D=="string"&&!Ze(D)},bt=N=>st(N).map(([D,K])=>ne(K,{kind:"var",ref:`nodes.${N}.meta.${D}`},"w6w-exprmodal-field",null)),Fe=[...new Set([...Object.keys(Ve),...mt,...Re.keys()])],ze=je.length>0||!!r.hasTrigger,Le=!w&&(ze||!!ce),be=w?[]:(((Ot=r.stateShape)==null?void 0:Ot.fields)??[]).filter(N=>Zt(N.key)),$e=[...Le?["state"]:[],...be.length>0?["runstate"]:[],...Fe.length>0?["meta"]:[],...r.inputs!==void 0?["inputs"]:[],"vars",...pe.length>0?["consts"]:[],...!m||w?["docs"]:[],...m?[]:["secrets"]],Ke=B==="auto"||B!==null&&!$e.includes(B)?$e.find(N=>N!=="meta")??null:B,ge=N=>({open:Ke===N,onToggle:()=>G(Ke===N?null:N)}),xe=((ce==null?void 0:ce.itemOutputs)??[]).filter(N=>N.path?Zt(N.key):yt(N.key)),gt=(r.eventOutputs??[]).filter(N=>N.path?Zt(N.key):yt(N.key)),Ce=le.serializeTemplate(F.parts),Tt=b.useMemo(()=>{const N={};for(const[D,K]of Object.entries(r.sampleValues??{}))N[D]=typeof K=="string"?K:JSON.stringify(K);return{...N,...O}},[r.sampleValues,O]),Ge=b.useMemo(()=>el(F.parts),[F.parts]),U=b.useMemo(()=>{if(F.error)return"";try{return sl(F.parts,r.sampleValues,O)}catch{return Ce}},[F,r.sampleValues,O,Ce]),V=b.useMemo(()=>{var D;const N=new Set;for(const K of Ge){if(O[K]!==void 0)continue;const se=(D=r.valueSources)==null?void 0:D[K];se==="sample"?N.add("example from the app"):se==="persisted"&&N.add("from last test")}return[...N]},[Ge,O,r.valueSources]),ne=(N,D,K,se,fe=!1,de,oe)=>n.jsxs("div",{className:"w6w-exprmodal-item",style:{display:"flex",alignItems:"center",gap:4,minWidth:0,...oe&&oe.depth>0?{paddingLeft:oe.depth*14}:{}},children:[n.jsxs("button",{type:"button",className:`w6w-exprmodal-source ${K}${oe!=null&&oe.declaredOnly?" is-declared-only":""}`,style:{flex:1,minWidth:0,...oe!=null&&oe.declaredOnly?{opacity:.6}:{}},title:`Insert ${(oe==null?void 0:oe.name)??N}`,"aria-label":de,onClick:()=>m?D.kind==="var"&&k(D.ref??""):E(D),children:[se!==null&&n.jsx("span",{className:"w6w-expr-chip-sigil",children:se}),n.jsx("span",{className:"w6w-exprmodal-source-label",children:N}),(oe==null?void 0:oe.declaredOnly)&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-declared-only",style:{marginLeft:6},children:"declared by the app"}),(oe==null?void 0:oe.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"})]}),!m&&n.jsx(kn,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>E(D)})]},`${D.kind}:${D.ref??N}`),Ne=_.has("loop:item"),ot=ne("Current item",{kind:"var",ref:"foreach.item"},"w6w-expr-chip-var","↻"),it=(N,D)=>{if(D.length===0)return null;const K=_.has(`mcfg:${N}`);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":K,title:K?"Hide config":"Show config",onClick:()=>X(`mcfg:${N}`),children:[n.jsx("span",{className:"w6w-exprmodal-tree-caret","aria-hidden":"true",children:K?"▾":"▸"}),"config"]})}),K&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-config-fields",children:D.map(se=>ne(se,{kind:"var",ref:`nodes.${N}.meta.config.${se}`},"w6w-exprmodal-field",null))})]})},Pe=(N,D,K=`nodes.${N}.output`)=>jr(D).map(({field:se,depth:fe,name:de})=>{const oe=`${K}.${se.key}`;return ne(de,{kind:"var",ref:oe},"w6w-exprmodal-field",null,!1,void 0,{name:Xe(oe),depth:fe,declaredOnly:se.declaredOnly===!0})}),Ee=N=>N==="fresh"||N==="persisted"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:N==="fresh"?"Fields from the last test run":"Fields from last test"}):N==="declared"||N==="sample"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":`expr-fields-from-${N}`,children:N==="declared"?"declared by the app":"example from the app"}):null,he=N=>{const D=`mnode:${N}`,K=_.has(D);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":K,"aria-label":K?`Hide ${N} metadata`:`Show ${N} metadata`,title:K?"Hide metadata":"Show metadata",onClick:()=>X(D),children:K?"▾":"▸"}),ne(N,{kind:"var",ref:`nodes.${N}.meta`},"w6w-expr-chip-var w6w-exprmodal-node",null,!0)]}),K&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-metadata-fields",children:[bt(N),it(N,Re.get(N)??[])]})]},D)};return n.jsxs(ve,{title:h??(m?"Edit JSON value":"Edit expression"),subtitle:o?n.jsx("code",{children:o}):void 0,onClose:a,size:"full",headerRight:m?n.jsxs("div",{className:"w6w-exprmodal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-json-save",disabled:!C,title:C?"Save the composed JSON":j??"Compose valid JSON to save",onClick:()=>{C&&(c==null||c(v.ok?v.value:void 0),a())},children:"Save"})]}):n.jsxs("div",{className:"w6w-exprmodal-actions",children:[!t&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:J,title:J?"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:()=>{i==null||i(le.serializeTemplate(T)),a()},children:"Use a plain value"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:L,"data-testid":"expr-save",disabled:F.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(([N,D,K])=>n.jsx("button",{type:"button","aria-pressed":x===N,"data-testid":`expr-insert-as-${N}`,title:K,className:`w6w-btn w6w-btn-sm${x===N?"":" w6w-btn-ghost"}`,onClick:()=>g(N),children:D},N))]}),m&&!w&&!Le&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),Le&&n.jsxs(Ye,{label:"Previous steps",...ge("state"),children:[ce&&n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":"expr-loop-group",children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:"Loop"}),xe.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[ot,n.jsx(Qt,{count:xe.length,open:Ne,onToggle:()=>X("loop:item")})]}):ot,xe.length>0&&Ne&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-loop-fields",children:xe.map(N=>{const D=`foreach.item.${N.key}`;return ne(N.key,{kind:"var",ref:D},"w6w-exprmodal-field",null)})}),ne("Index",{kind:"var",ref:"foreach.index"},"w6w-expr-chip-var","#")]}),r.hasTrigger&&(gt.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-event","aria-expanded":_.has("event"),"aria-label":_.has("event")?"Hide fields":"Show fields",title:_.has("event")?"Hide fields":"Show fields",onClick:()=>X("event"),children:_.has("event")?"▾":"▸"}),ne("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡",!0)]}),_.has("event")&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-event-fields",children:[Ee(r.eventOutputsFrom),Pe("",gt,"trigger.event")]})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),ne("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡")]})),je.map(N=>{const D=(N.outputs??[]).filter(de=>de.path?Zt(de.key):yt(de.key)),K=`step:${N.id}`,se=_.has(K),fe=ne(N.label??N.id,{kind:"var",ref:`nodes.${N.id}.output`},"w6w-expr-chip-var w6w-exprmodal-node",null,D.length>0);return m?n.jsxs(b.Fragment,{children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:N.label??N.id}),ne("Entire output",{kind:"var",ref:`nodes.${N.id}.output`},"w6w-expr-chip-var",null,!1,`Entire output of ${N.label??N.id}`),N.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"})}),D.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":se,"aria-label":se?"Hide fields":"Show fields",title:se?"Hide fields":"Show fields",onClick:()=>X(K),children:se?"▾":"▸"}),n.jsx(Qt,{count:D.length,open:se,onToggle:()=>X(K)})]}),se&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[Ee(N.outputsFrom),Pe(N.id,D)]})]})]},N.id):n.jsxs(b.Fragment,{children:[D.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":se,"aria-label":se?"Hide fields":"Show fields",title:se?"Hide fields":"Show fields",onClick:()=>X(K),children:se?"▾":"▸"}),fe,n.jsx(Qt,{count:D.length,open:se,onToggle:()=>X(K)})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),fe]}),N.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"})}),D.length>0&&se&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[Ee(N.outputsFrom),Pe(N.id,D)]})]},N.id)})]}),be.length>0&&n.jsxs(Ye,{label:"State",testId:"expr-state-group",...ge("runstate"),children:[ne("state",{kind:"var",ref:"state"},"w6w-expr-chip-var","◇",!0),n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-state-fields",children:jr(be).map(({field:N,depth:D,name:K})=>{const se=`state.${N.key}`;return ne(K,{kind:"var",ref:se},"w6w-exprmodal-field",null,!1,void 0,{name:Xe(se),depth:D,somePaths:N.paths==="some"})})})]}),Fe.length>0&&n.jsx(Ye,{label:"Metadata",testId:"expr-metadata-group",...ge("meta"),children:Fe.map(N=>he(N))}),n.jsxs(n.Fragment,{children:[r.inputs!==void 0&&n.jsxs(Ye,{label:"Inputs",...ge("inputs"),children:[me.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),me.map(N=>ne(N,{kind:"var",ref:`inputs.${N}`},"w6w-expr-chip-var","⇥"))]}),n.jsxs(Ye,{label:"Variables",...ge("vars"),action:r.createVar&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-var",onClick:()=>re("var"),children:"+ Add"}),children:[ie.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),ie.map(N=>ne(N,{kind:"var",ref:`var.${N}`},"w6w-expr-chip-var","◆"))]}),pe.length>0&&n.jsx(Ye,{label:"Constants",testId:"expr-constants-group",...ge("consts"),children:pe.map(N=>ne(N,{kind:"var",ref:`const.${N}`},"w6w-expr-chip-var","◈"))})]}),(!m||w)&&n.jsxs(Ye,{label:"Documents",...ge("docs"),children:[Se.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),Se.map(N=>{const D=(N.fields??[]).filter(de=>yt(de.key)),K=`doc:${N.key}`,se=_.has(K),fe=ne(N.key,{kind:"var",ref:`documents.${N.key}`},"w6w-expr-chip-var","▦",D.length>0);return n.jsxs(b.Fragment,{children:[D.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[fe,n.jsx(Qt,{count:D.length,open:se,onToggle:()=>X(K)})]}):fe,D.length>0&&se&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:D.map(de=>{const oe=`documents.${N.key}.${de.key}`;return n.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[ne(de.key,{kind:"var",ref:oe},"w6w-expr-chip-var","·"),!m&&n.jsx("button",{type:"button",className:"w6w-exprmodal-render-btn","data-testid":"expr-insert-render",title:`Insert ${oe} and render its {{ }} placeholders`,"aria-label":`Insert ${oe} and render its {{ }} placeholders`,onClick:()=>E({kind:"render",ref:oe}),children:"▤"})]},oe)})})]},N.key)})]}),!m&&n.jsxs(Ye,{label:"Secrets",...ge("secrets"),action:r.createSecret&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-secret",onClick:()=>re("secret"),children:"+ Add"}),children:[ue.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),ue.map(N=>ne(N,{kind:"secret",ref:N},"w6w-expr-chip-secret","🔒"))]})]}),m&&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:()=>{S.current=!0},children:n.jsx(He,{value:y,onChange:A,height:"100%",minHeight:"0px","aria-label":"Compose JSON",placeholder:w?'{ "region": "us", "template": "{{ documents.welcome }}" }':'{ "key": "{{ nodes.step_1.output }}" }',onCreateEditor:N=>{R.current=N}})})]}),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"]})]}),j&&n.jsx("span",{className:"w6w-muted w6w-small",role:"alert","data-testid":"expr-json-problem",children:j}),n.jsx(ae.Copyable,{value:M??"",label:"Copy result",children:n.jsx("pre",{className:"w6w-exprmodal-result","data-testid":"expr-json-result",children:M})})]})]}),!m&&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":""}${T.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":F.error!==null,"aria-describedby":F.error?"expression-problem":void 0,spellCheck:!1,onInput:()=>{const N=W.current;N&&go(N,{renderToggle:!0}),te()},onDoubleClick:N=>{const D=N.target;if(D.closest("[data-x]")||D.closest("[data-render-toggle]"))return;const K=D.closest(".w6w-expr-chip");if(!K)return;N.preventDefault();const se=yo(K);if(se){const fe=se.ownerDocument,de=fe.createRange();de.setStartAfter(se),de.collapse(!0);const oe=fe.getSelection();oe==null||oe.removeAllRanges(),oe==null||oe.addRange(de)}te()},onBlur:()=>{const N=W.current;N&&ee(le.serializeTemplate(Pt(N)),{restoreFocus:!1})},onPaste:N=>{var se;N.preventDefault();const D=W.current;if(!D)return;const K=((se=N.clipboardData)==null?void 0:se.getData("text/plain"))??"";for(const fe of Qe(K))fe.kind==="text"?_t(D,D.ownerDocument.createTextNode(fe.value??"")):_t(D,Ft(D.ownerDocument,fe,{renderToggle:!0}));te()},onClick:N=>{var fe;const D=N.target,K=D.closest("[data-x]");if(K){N.preventDefault(),(fe=K.closest(".w6w-expr-chip"))==null||fe.remove(),te();return}const se=D.closest("[data-render-toggle]");if(se){N.preventDefault();const de=se.closest(".w6w-expr-chip");if(de){const oe=de.getAttribute("data-ref")??"",Me=de.getAttribute("data-kind")==="render"?"var":"render";de.replaceWith(Ft(de.ownerDocument,{kind:Me,ref:oe},{renderToggle:!0}))}te()}},onKeyDown:N=>{if(N.key!=="Enter"||(N.preventDefault(),!s))return;const D=W.current;D&&(_t(D,D.ownerDocument.createTextNode(`
10
- `)),mo(D),te())}}),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."]}),F.error&&n.jsx("span",{id:"expression-problem",role:"alert",className:"w6w-error",children:F.error})]}),Ge.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"]})]}),Ge.map(N=>n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:N}),n.jsx("input",{type:"text",value:O[N]??Tt[N]??"",placeholder:"sample value",onChange:D=>Z(K=>({...K,[N]:D.target.value}))})]},N))]}),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(ae.Copyable,{value:U,readOnly:!0,children:n.jsx("pre",{className:"w6w-exprmodal-result",children:U||" "})}),V.length>0&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-result-source",children:V.join(" · ")})]})]})]}),Q==="var"&&r.createVar&&n.jsx(kr,{kind:"var",onCreate:r.createVar,onClose:H}),Q==="secret"&&r.createSecret&&n.jsx(kr,{kind:"secret",onCreate:r.createSecret,onClose:H})]})}function Ye({label:e,open:t,onToggle:s,action:r,testId:o,children:i}){const a=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":o,"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":a,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:"›"})]}),r]}),n.jsx("div",{id:a,ref:l,className:"w6w-exprmodal-group-body","aria-hidden":!t,children:n.jsx("div",{className:"w6w-exprmodal-group-inner",children:i})})]})}function Qt({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 gl=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"],["subscriptionId","Subscription ID"],["url","Webhook URL"]],yl=new Set(["app","version","action","connectionId"]);function kr({kind:e,onCreate:t,onClose:s}){const[r,o]=b.useState(""),[i,a]=b.useState(""),[l,u]=b.useState(""),[c,d]=b.useState(null),[f,p]=b.useState(!1),h=e==="var"?"variable":"secret";async function m(){d(null),p(!0);try{await t({name:r,value:i,description:l||void 0}),s()}catch(w){d(w.message)}finally{p(!1)}}return n.jsxs(ve,{title:`Add ${h}`,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:r,onChange:w=>o(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:i,onChange:w=>a(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=>u(w.target.value),placeholder:"Optional",autoComplete:"off"})]}),c&&n.jsx("div",{className:"w6w-result w6w-error",children:c})]})}),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:!r||!i||f,onClick:m,children:f?"Saving…":"Save"})]})]})}function xl(e,t){return t?e.filter(s=>s.id!==t):e}const Zn=b.createContext({});function vl({value:e,children:t}){const s=b.useContext(Zn),r=b.useMemo(()=>({...s,...e}),[s,e]);return n.jsx(Zn.Provider,{value:r,children:t})}function Be(){return b.useContext(Zn)}function Bt({value:e,onChange:t,placeholder:s,masked:r,multiline:o,readOnly:i,options:a,"aria-label":l}){const[u,c]=b.useState(()=>Vn(e)),{parts:d,sealed:f}=u,[p,h]=b.useState(0),[m,w]=b.useState(!1),[x,g]=b.useState(!1),y=b.useRef(!1),A=b.useRef(null),R=b.useRef(null),S=Be(),v={...S,...a??{}},j=S.sealSecret;b.useLayoutEffect(()=>{const T=A.current;!T||f||(bo(T,d),(y.current||T.ownerDocument.activeElement===T)&&(T.focus(),Es(T),y.current=!1))},[p,f]);const C=()=>{const T=A.current;if(!T)return;const I=Pt(T);c(q=>({...q,parts:I}));const F=$t(I,v);t(sn(F.parts))},$=async T=>{if(!j)return!1;w(!0);try{const I=await j(T);return y.current=!1,c({parts:[],sealed:I}),h(F=>F+1),t(I),!0}catch{return!1}finally{w(!1)}},M=T=>{var q;if(x||!r||i||m)return;const I=T.relatedTarget;if(I&&((q=R.current)!=null&&q.contains(I)))return;const F=sn(d);typeof F=="string"&&F!==""&&!et(F)&&$(F)},k=T=>{if(r&&typeof T=="string"&&T.trim()!==""&&!et(T)){$(T);return}y.current=!1,c(Vn(T)),h(I=>I+1),t(T)};return f?n.jsxs("div",{className:`w6w-expr-sealed${i?" 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:"••••••"})]}),!i&&n.jsx("button",{type:"button",className:"w6w-expr-replace",onClick:()=>{y.current=!0,c({parts:[],sealed:null}),h(T=>T+1),t("")},children:"Replace"})]}):n.jsxs("div",{className:"w6w-expr",ref:R,onBlur:M,children:[n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{ref:A,className:`w6w-expr-editor${r?" is-masked":""}${d.length===0?" is-empty":""}${i?" is-readonly":""}`,contentEditable:!i,suppressContentEditableWarning:!0,role:"textbox",tabIndex:i?-1:0,"aria-multiline":o?"true":"false","aria-label":l,"data-placeholder":s??"",spellCheck:!1,onInput:()=>{const T=A.current;T&&go(T),C()},onClick:T=>{var F;const I=T.target.closest("[data-x]");I&&(T.preventDefault(),(F=I.closest(".w6w-expr-chip"))==null||F.remove(),C())},onDoubleClick:T=>{const I=T.target;if(I.closest("[data-x]"))return;const F=I.closest(".w6w-expr-chip");if(!F)return;T.preventDefault();const q=yo(F);if(q){const z=q.ownerDocument,W=z.createRange();W.setStartAfter(q),W.collapse(!0);const P=z.getSelection();P==null||P.removeAllRanges(),P==null||P.addRange(W)}C()},onKeyDown:T=>{if(T.key!=="Enter"||(T.preventDefault(),!o))return;const I=A.current;I&&(_t(I,I.ownerDocument.createTextNode(`
11
- `)),mo(I),C())}}),!i&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse variables, secrets & step outputs","aria-label":"Edit expression",onClick:()=>g(!0),children:"ƒx"})]}),x&&n.jsx(Gt,{value:sn(d),masked:r,multiline:o,options:v,fieldLabel:l,onSave:k,onClose:()=>g(!1)})]})}const jl=/\{\{\s*([^{}]*?)\s*\}\}/g;function xo(e,t="javascript"){const s=t==="python",r=[],o=[];let i=0;for(;i<e.length;){const l=e[i],u=e.slice(i,i+2),c=e.slice(i,i+3);if(s&&l==="#"||!s&&u==="//"){const d=e.indexOf(`
12
- `,i),f=d===-1?e.length:d;o.push({start:i,end:f}),i=f}else if(!s&&u==="/*"){const d=e.indexOf("*/",i+2),f=d===-1?e.length:d+2;o.push({start:i,end:f}),i=f}else if(s&&(c==='"""'||c==="'''")){const d=e.indexOf(c,i+3),f=d===-1?e.length:d+3;r.push({start:i,end:f,quote:c}),i=f}else if(l==="'"||l==='"'||!s&&l==="`"){let d=i+1;for(;d<e.length&&e[d]!==l;){if(e[d]==="\\")d++;else if(l!=="`"&&e[d]===`
13
- `)break;d++}const f=Math.min(d+1,e.length);r.push({start:i,end:f,quote:l}),i=f}else i++}const a=[];for(const l of e.matchAll(jl)){const u=l.index??0,c=u+l[0].length;if(o.some(f=>u>=f.start&&u<f.end))continue;const d=r.find(f=>u>f.start&&u<f.end);a.push({start:u,end:c,ref:l[1],context:d?{kind:"string",...d}:{kind:"code"}})}return a}const Nl=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$-]*|\[\d+\]|\["[^"\\]*"\]|\['[^'\\]*'\])*$/,kl=/\.([A-Za-z_$][\w$-]*)|\[(\d+)\]|\["([^"\\]*)"\]|\['([^'\\]*)'\]/g,Sl={nodes:["run","nodes"],steps:["run","nodes"],trigger:["run","trigger"],foreach:["run","foreach"],state:["state"],var:["state"],vars:["state"],const:["consts"],consts:["consts"]};function on(e,t="javascript"){var u;const s=e.trim();if(!Nl.test(s))return null;const r=((u=/^[A-Za-z_$][\w$]*/.exec(s))==null?void 0:u[0])??"",o=Sl[r];if(!o)return null;const i=[...o.slice(1)];for(const c of s.slice(r.length).matchAll(kl))i.push(c[2]!==void 0?Number(c[2]):c[1]??c[3]??c[4]);const a=o[0]==="run"?i.shift():o[0];return`${t==="python"?"ctx":"$"}.get(${[a,...i].map(c=>JSON.stringify(c)).join(", ")})`}function Cl(e,t="javascript"){const s=t==="python";let r="",o=0,i=0,a=0;for(const l of xo(e,t)){const u=on(l.ref,t);if(u===null){a++;continue}const c=l.context;if(c.kind==="code"){r+=e.slice(o,l.start)+u,o=l.end,i++;continue}const d=c.quote,f=l.start===c.start+d.length,p=l.end===c.end-d.length;if(f&&p)r+=e.slice(o,c.start)+u,o=c.end,i++;else if(!s&&d==="`")r+=`${e.slice(o,l.start)}\${${u}}`,o=l.end,i++;else if(d.length===1&&!(s&&/[A-Za-z]/.test(e[c.start-1]??""))){const h=s?`str(${u})`:u;r+=f?`${e.slice(o,c.start)}${h} + ${d}`:`${e.slice(o,l.start)}${d} + ${h}`,p?o=c.end:(f||(r+=` + ${d}`),o=l.end),i++}else a++}return r+=e.slice(o),{code:r,converted:i,left:a}}function Al({param:e,value:t,language:s,label:r,req:o,readOnly:i,onChange:a}){var R;const l=b.useRef(null),[u,c]=b.useState(!1),d=Be(),f=d.steps??[],p=s==="python",h=S=>{const v=l.current;if(!v){a(t+S);return}v.dispatch(v.state.replaceSelection(S)),v.focus()},m=S=>{const v=nt(S);if(v!==null){const j=on(v,s);j&&h(j);return}S===void 0||S===""||h(JSON.stringify(S,null,2).replace(/"\{\{\s*([^{}"]*?)\s*\}\}"/g,(j,C)=>on(C,s)??j))},w=((R=f[0])==null?void 0:R.id)??"<step-id>",x=p?"ctx":"$",g=[[`${x}.get("nodes", ${JSON.stringify(w)}, "output")`,"a step's output"],[`${x}.get("state", "region")`,"a workflow state value"],[`${x}.get("consts", "api_base")`,"a constant"]],y=Math.max(...g.map(([S])=>S.length)),A=p?"#":"//";return n.jsxs("div",{className:"w6w-field w6w-script-code",children:[n.jsxs("span",{children:[r,o]}),n.jsx(js,{value:t,readOnly:i,minHeight:"180px",language:s,"aria-label":`${e.key} code`,onChange:a,onCreateEditor:S=>{l.current=S}}),!i&&n.jsxs("div",{className:"w6w-seed-chips w6w-script-insert",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Insert"}),f.map(S=>{const v=on(`nodes[${JSON.stringify(S.id)}].output`,s)??"";return n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Insert ${v}`,onClick:()=>h(v),children:n.jsx("code",{children:S.id})},S.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 ${r}`,onClick:()=>c(!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:g.map(([S,v])=>`${S.padEnd(y)} ${A} ${v}`).join(`
14
- `)}),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:p?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."]}):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."]})})]}),u&&n.jsx(Gt,{mode:"json-binding",value:void 0,jsonValue:void 0,options:d,fieldLabel:r,whole:!0,onSaveJson:m,onClose:()=>c(!1)})]})}function Sn(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...Sn(s.children));return t}function vo(e){return et(e)||tt(e)?!0:typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"$")}function mn(e){var t;return((t=e.config)==null?void 0:t.allowCustom)===!0}function Qn(e){return Sn(e).filter(t=>vn(t.options))}function Rs(e){return vn(e.options)?e.options.refreshOn??[]:[]}function es(e,t){const s={},r=[];for(const o of Sn(e)){if(o.type==="section")continue;const i=t[o.key]!==void 0?t[o.key]:o.default;i!==void 0&&(vo(i)?r.push(o.key):s[o.key]=i)}return{form:s,unresolved:r}}function El(e,t,s,r,o){const{form:i,unresolved:a}=es(e,t),l=new Set(a),u=Qn(e).filter(d=>{const f=Rs(d);return s==="change"&&!(r??[]).some(p=>f.includes(p))?!1:f.every(p=>!l.has(p))}).map(d=>d.key);if(u.length===0)return null;const c={reason:s,form:i,fields:u,unresolved:a};return s==="change"&&(c.changed=[...r??[]],c.previous=es(e,o??{}).form),c}function Sr(e,t,s){return JSON.stringify([e.appId,e.version??null,e.actionKey,e.connectionId??null,t.key,Rs(t).map(r=>s[r]??null)])}function Cr(e){return!(vn(e.options)&&e.options.cache==="none")}function Rl(e,t){return e.some(s=>t.includes(s))}function Tl(e,t,s,r){var l;if(!r.connectionId)return{reason:"no-connection",hint:"Connect an account to load choices"};const o=new Set(es(t,s).unresolved),i=Rs(e).find(u=>o.has(u));return i===void 0?null:{reason:"unresolved-dependency",hint:`Options unavailable while ${((l=Sn(t).find(u=>u.key===i))==null?void 0:l.label)??i} is an expression`}}function Ar(e,t,s){return e==null||e===""?{action:"keep"}:vo(e)?{action:"keep"}:t.some(r=>r.value===e||String(r.value)===String(e))?{action:"keep"}:s.reason==="change"&&!s.allowCustom?{action:"clear"}:{action:"flag",message:`Not in the list returned by ${s.appLabel}`}}function Ol(e,t,s,r){var A;const o=(A=nn())==null?void 0:A.resolveActionFields,i=!!(s&&o),[a,l]=b.useState({}),u=b.useRef({params:e,values:t,dynamic:s,onChange:r,resolve:o});u.current={params:e,values:t,dynamic:s,onChange:r,resolve:o};const c=b.useRef(new Map),d=b.useRef([]),f=b.useCallback((R,S,v,j,C)=>{const{params:$,values:M,dynamic:k,resolve:T}=u.current,I=C??M;if(!k||!T||!k.connectionId)return;const F=El($,I,R,S,v);if(!F)return;const q=new Map(Qn($).map(B=>[B.key,B])),z=[],W={},P=[],O=k.appName??k.appId,Z=(B,G)=>{const te=q.get(B);if(!te)return;Ar(I[B],G,{allowCustom:mn(te),reason:R,appLabel:O}).action==="clear"&&z.push(B)};for(const B of F.fields){if(j!==void 0&&B!==j)continue;const G=q.get(B);if(!G)continue;const te=j===void 0&&Cr(G)?c.current.get(Sr(k,G,F.form)):void 0;te?(W[B]={options:te,loading:!1},Z(B,te)):P.push(B)}const Q=(B=!1)=>{if(z.length===0)return;const G={...B?I:u.current.values};for(const te of z)delete G[te];u.current.onChange(G)};if(Object.keys(W).length>0&&l(B=>({...B,...W})),P.length===0){Q(!0);return}for(const B of d.current)Rl(B.fields,P)&&B.controller.abort();const re=new AbortController,_={fields:P,controller:re};d.current=[...d.current.filter(B=>!B.controller.signal.aborted),_],l(B=>{var te;const G={...B};for(const E of P)G[E]={options:(te=B[E])==null?void 0:te.options,loading:!0};return G});const Y={...F,fields:P,connectionId:k.connectionId,...k.version!==void 0?{version:k.version}:{}},X=B=>{d.current=d.current.filter(G=>G!==_),l(G=>({...G,...B}))};Promise.resolve().then(()=>T(k.appId,k.actionKey,Y,{signal:re.signal})).then(B=>{var te;if(re.signal.aborted)return;const G={};for(const E of P){const J=(te=B==null?void 0:B.fields)==null?void 0:te[E],ee=q.get(E);if(!J||!ee)G[E]={loading:!1};else if(J.error)G[E]={loading:!1,error:J.error};else{const L=Array.isArray(J.options)?J.options:[];G[E]={loading:!1,options:L},Cr(ee)&&c.current.set(Sr(k,ee,F.form),L),Z(E,L)}}X(G),Q()}).catch(B=>{if(re.signal.aborted)return;const G=B instanceof Error?B.message:String(B),te={};for(const E of P)te[E]={loading:!1,error:G||"Request failed"};X(te)})},[]),p=s?JSON.stringify([s.appId,s.actionKey,s.version,s.connectionId]):"";b.useEffect(()=>{if(i)return l({}),f("init"),()=>{for(const R of d.current)R.controller.abort();d.current=[]}},[p,i,f]);const h=b.useRef(new Map),m=b.useCallback((R,S)=>{const v=h.current.get(R)??u.current.values;h.current.delete(R),f("change",[R],v,void 0,{...u.current.values,[R]:S})},[f]),w=b.useCallback(R=>{h.current.has(R)||h.current.set(R,u.current.values)},[]),x=b.useCallback(R=>{const S=h.current.get(R);if(h.current.delete(R),!S)return;const v=u.current.values;JSON.stringify(S[R])!==JSON.stringify(v[R])&&f("change",[R],S)},[f]),g=b.useCallback(R=>f("init",void 0,void 0,R),[f]);return{fields:b.useMemo(()=>{const R={};if(!i||!s)return R;const S=s.appName??s.appId;for(const v of Qn(e)){const j=Tl(v,e,t,s);if(j){R[v.key]={loading:!1,hint:j.hint};continue}const C=a[v.key]??{loading:!0},$={...C};if(C.options){const M=Ar(t[v.key],C.options,{allowCustom:mn(v),reason:"init",appLabel:S});M.action==="flag"&&($.notInList=M.message)}R[v.key]=$}return R},[i,s,e,t,a]),commit:m,focus:w,blur:x,retry:g}}function Yt(e,t){return e.hidden===!0?!1:e.showIf?le.matchesParamCondition(e.showIf,t):!0}function kt(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...kt(s.children));return t}function Ut(e,t){const s=[];for(let r=0;r<e.length;){const o=e[r].row;if(o){const i=[];for(;r<e.length&&e[r].row===o;)i.push(e[r++]);s.push(n.jsx("div",{className:"w6w-field-row",children:i.map(t)},`row:${o}`))}else s.push(t(e[r])),r++}return s}function jo(e,t,s,r){const o=i=>i.type==="section"?n.jsx(Il,{param:i,effective:s,renderOne:o},i.key):i.repeat&&i.type!=="array"?n.jsx(Fl,{param:i,value:e[i.key],onChange:t,readOnly:r},i.key):i.type==="group"&&i.children&&i.children.length>0?n.jsx(_l,{param:i,value:e[i.key],onChange:t,effective:s,readOnly:r},i.key):n.jsx(Ml,{param:i,value:e[i.key],onChange:t,effective:s,readOnly:r},i.key);return o}const Cn=b.createContext(null);function Ie({params:e,values:t,onChange:s,readOnly:r,dynamic:o}){const i=Ol(e,t,o,s),a=kt(e),l=h=>{var m;return t[h]!==void 0?t[h]:(m=a.find(w=>w.key===h))==null?void 0:m.default},u=e.filter(h=>Yt(h,l)).map(h=>le.effectiveParam(h,l)),c=u.filter(h=>h.required||!h.advanced),d=u.filter(h=>!h.required&&h.advanced),f=(h,m)=>{if(h==="language"){const w={...t,[h]:m};for(const x of a){if(x.type!=="code")continue;const g=t[x.key];(g===void 0||g===x.default||g===ts||Ll.includes(g))&&(w[x.key]=m==="python"?ts:x.default)}s(w);return}s({...t,[h]:m})};if(e.length===0)return n.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."});const p=jo(t,f,l,r);return n.jsx(Cn.Provider,{value:i,children:n.jsxs("div",{className:"w6w-stack",children:[Ut(c,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:Ut(d,p)})]})]})})}function Il({param:e,effective:t,renderOne:s}){const r=(e.children??[]).filter(o=>Yt(o,t)).map(o=>le.effectiveParam(o,t));return e.section==="collapsible"?n.jsxs("details",{className:"w6w-section",open:e.collapsed===!1||e.openWhenSet===!0&&r.some(o=>{const i=t(o.key);return i!=null&&i!==""}),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:Ut(r,s)})]}):e.layout==="row"?n.jsx("div",{className:"w6w-field-row",children:r.map(s)}):n.jsx("div",{className:"w6w-stack",children:Ut(r,s)})}const $l=new Set(["string","text","number","boolean","select"]);function Pl(e){return e.length>0&&e.every(t=>$l.has(t.type)&&!t.children)}function _l({param:e,value:t,onChange:s,effective:r,readOnly:o}){const i=e.children??[],a=t??{},l=(p,h)=>s(e.key,{...a,[p]:h}),u=kt(i),c=p=>{const h=u.find(m=>m.key===p);return h?a[p]!==void 0?a[p]:h.default:r(p)},d=i.filter(p=>Yt(p,c)).map(p=>le.effectiveParam(p,c)),f=jo(a,l,c,o);return n.jsx(Cn.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:Ut(d,f)})]})})}function Fl({param:e,value:t,onChange:s,readOnly:r}){if(e.type==="group"){const i=e.children??[];if(!Pl(i))return n.jsx(Ts,{param:e,value:t,onChange:s,readOnly:r});const a={...e,item:{type:"object",fields:i}};return n.jsx(ns,{param:a,value:t,onChange:s,readOnly:r})}const o={...e,item:{type:e.type,options:Array.isArray(e.options)?e.options:void 0}};return n.jsx(ns,{param:o,value:t,onChange:s,readOnly:r})}const ts=`# Runs as a function body. Return the step's output.
15
- return input`,Ll=["// 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 Ml(e){const t=b.useContext(Cn),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(Dl,{...e})})}function Dl({param:e,value:t,onChange:s,effective:r,readOnly:o}){var R,S,v,j,C;const i=(R=nn())==null?void 0:R.listModelRoutes,a=(S=nn())==null?void 0:S.listDataStores,l=(v=nn())==null?void 0:v.listDataStoreEntries,u=xs(),c=b.useContext(Cn),d=c==null?void 0:c.fields[e.key],f=($,M)=>{s($,M),c==null||c.commit($,M)},p=s,h=e.label??e.key,m=e.required&&e.type!=="boolean"?" *":"",w=b.useId();if(e.type==="boolean"){const $=!!(t??e.default??!1);return n.jsx(Oe,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,variant:"inline",controlId:w,children:n.jsx("input",{id:w,type:"checkbox",checked:$,disabled:o,onChange:M=>f(e.key,M.target.checked)})})}if(e.type==="json"||e.type==="group")return n.jsx(Ts,{param:e,value:t,onChange:p,readOnly:o});if(e.type==="code"){const $=r==null?void 0:r("language"),M=$==="python"||$==="javascript"||$==="typescript"?$:void 0,k=M==="python"?ts:e.default,T=t??k??"";return e.scriptReads?n.jsx(Al,{param:e,value:String(T),language:$==="python"?"python":"javascript",label:h,req:m,readOnly:o,onChange:I=>p(e.key,I)}):n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[h,m]}),n.jsx(js,{value:String(T),readOnly:o,minHeight:"180px",language:M,"aria-label":`${e.key} code`,onChange:I=>p(e.key,I)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="model-route"&&i)return n.jsx(Hl,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,listModelRoutes:i,project:u});if(e.type==="data-store"&&a)return n.jsx(Wl,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,listDataStores:a,project:u});const x=r==null?void 0:r("store");if(e.type==="data-store-key"&&l&&typeof x=="string"&&x.trim()!=="")return n.jsx(Jl,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,store:x,listDataStoreEntries:l,project:u});if(e.type==="vars")return n.jsx(ec,{param:e,value:t,onChange:p,readOnly:o});if(e.type==="text"||(j=e.config)!=null&&j.multiline){const $=t??e.default??"";return n.jsx(Oe,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,children:n.jsx("textarea",{rows:3,value:String($),readOnly:o,"aria-label":h,onChange:M=>p(e.key,M.target.value)})})}if(e.type==="multiselect")return n.jsx(Vl,{param:e,value:t,onChange:f,readOnly:o});if(e.type==="array")return n.jsx(ns,{param:e,value:t,onChange:p,readOnly:o});if(c&&d&&!d.hint)return n.jsx(Er,{param:e,value:t,onChange:f,readOnly:o,label:h,req:m,state:d,retry:()=>c.retry(e.key)});if(Array.isArray(e.options)&&e.options.length>0&&mn(e))return n.jsx(Er,{param:e,value:t,onChange:f,readOnly:o,label:h,req:m,state:{loading:!1,options:e.options}});if(Array.isArray(e.options)&&e.options.length>0){const $=!e.required&&e.default===void 0&&typeof e.placeholder=="string"&&e.placeholder?e.placeholder:void 0,M=t??e.default??($!==void 0?"":(C=e.options[0])==null?void 0:C.value)??"",k=e.type==="number";return n.jsx(Oe,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,children:n.jsxs("select",{value:String(M),disabled:o,"aria-label":h,onChange:T=>{const I=T.target.value;$!==void 0&&I===""?f(e.key,void 0):f(e.key,k?Number(I):I)},children:[$!==void 0&&n.jsx("option",{value:"",children:$}),e.options.map(T=>n.jsx("option",{value:String(T.value),children:T.label},String(T.value)))]})})}if(e.type==="secret"){const $=t??e.default;return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[h,m]}),n.jsx(Bt,{value:$,masked:!0,readOnly:o,"aria-label":h,onChange:M=>p(e.key,M)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const g=e.type==="number"?"number":"text",y=t??e.default??"",A=typeof y=="object"&&y!==null?JSON.stringify(y):String(y??"");return n.jsxs(Oe,{param:e,value:t,onChange:p,readOnly:o,label:h,req:m,children:[n.jsx("input",{type:g,value:A,readOnly:o,"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:$=>p(e.key,e.type==="number"?Number($.target.value):$.target.value)}),(d==null?void 0:d.hint)&&n.jsx("span",{className:"w6w-hint",children:d.hint})]})}function Er({param:e,value:t,onChange:s,readOnly:r,label:o,req:i,state:a,retry:l}){const u=t??e.default??"",c=typeof u=="string"||typeof u=="number"?String(u):"";return n.jsxs(Oe,{param:e,value:t,onChange:s,readOnly:r,label:o,req:i,children:[n.jsx("div",{className:"w6w-fx-grow","aria-busy":a.loading?"true":"false",children:n.jsx(wt,{mode:"combobox",forceSelection:!mn(e),"aria-label":o,disabled:r,value:c,placeholder:a.loading?"Loading…":e.placeholder,options:(a.options??[]).map(d=>({value:String(d.value),label:d.label})),onChange:d=>s(e.key,d)})}),a.notInList&&n.jsx("span",{className:"w6w-hint",children:a.notInList}),a.error&&n.jsxs("span",{role:"alert",className:"w6w-hint",children:[a.error,l&&n.jsx("button",{type:"button",onClick:l,children:"Retry"})]})]})}function Hl({param:e,value:t,onChange:s,readOnly:r,label:o,req:i,listModelRoutes:a,project:l}){const[u,c]=b.useState([]);b.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>a(l)).then(h=>p&&c(Array.isArray(h)?h:[])).catch(()=>p&&c([])),()=>{p=!1}},[a,l]);const d=t??e.default??"",f=typeof d=="string"?d:"";return n.jsx(Oe,{param:e,value:t,onChange:s,readOnly:r,label:o,req:i,children:n.jsx(wt,{mode:"combobox",forceSelection:!1,"aria-label":o,disabled:r,value:f,placeholder:"Select a route…",options:u.map(p=>({value:p.name,label:p.status==="broken"?`${p.name} (broken)`:p.name})),onChange:p=>s(e.key,p)})})}function Wl({param:e,value:t,onChange:s,readOnly:r,label:o,req:i,listDataStores:a,project:l}){const[u,c]=b.useState([]);b.useEffect(()=>{let p=!0;return Promise.resolve().then(()=>a(l)).then(h=>p&&c(Array.isArray(h)?h:[])).catch(()=>p&&c([])),()=>{p=!1}},[a,l]);const d=t??e.default??"",f=typeof d=="string"?d:"";return n.jsx(Oe,{param:e,value:t,onChange:s,readOnly:r,label:o,req:i,children:n.jsx(wt,{mode:"combobox",forceSelection:!1,"aria-label":o,disabled:r,value:f,placeholder:"Select a store…",options:u.map(p=>({value:p.name,label:`${p.name} (${p.kind})`})),onChange:p=>s(e.key,p)})})}const ql=25,Bl=200,Rr=60;function Ul(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>Rr&&(t=`${t.slice(0,Rr-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 Jl({param:e,value:t,onChange:s,readOnly:r,label:o,req:i,store:a,listDataStoreEntries:l,project:u}){const[c,d]=b.useState(""),[f,p]=b.useState({items:[]}),[h,m]=b.useState(!0);b.useEffect(()=>{const y=new AbortController;m(!0);const A=c.trim(),R=setTimeout(()=>{Promise.resolve().then(()=>l(a,{project:u,prefix:A===""?void 0:A,limit:ql,signal:y.signal})).then(S=>{y.signal.aborted||(p(S&&Array.isArray(S.items)?S:{items:[]}),m(!1))}).catch(()=>{y.signal.aborted||(p({items:[]}),m(!1))})},A===""?0:Bl);return()=>{clearTimeout(R),y.abort()}},[l,a,u,c]);const w=t??e.default??"",x=typeof w=="string"?w:"",g=c.trim();return n.jsx(Oe,{param:e,value:t,onChange:s,readOnly:r,label:o,req:i,children:n.jsx(wt,{mode:"combobox",forceSelection:!1,"aria-label":o,disabled:r,value:x,placeholder:"Search entries or type a key…",options:f.items.map(y=>({value:y.key,label:y.key,detail:Ul(y)||void 0})),onInputChange:d,emptyText:h?"Searching…":g!==""?`No key starts with "${g}" — Enter keeps it as typed`:"No entries in this store",footer:f.more?"More entries — type to narrow by key":void 0,onChange:y=>s(e.key,y)})})}function Oe({param:e,value:t,onChange:s,readOnly:r,label:o,req:i,bare:a,variant:l="boxed",controlId:u,children:c}){var g;const d=et(t),f=e.type==="text"||!!((g=e.config)!=null&&g.multiline),[p,h]=b.useState(!1),m=Be(),w=l==="inline"&&!d,x=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:w?"w6w-fx-inline":`w6w-fx-wrap${d?" is-fx":""}`,children:d?n.jsx(Bt,{value:t,multiline:f,readOnly:r,"aria-label":o,onChange:y=>s(e.key,y)}):n.jsxs(n.Fragment,{children:[c,!r&&n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${o}`,onClick:()=>h(!0),children:"ƒx"}),w&&n.jsxs("label",{className:"w6w-fx-inline-label",htmlFor:u,children:[o,i]})]})}),p&&n.jsx(Gt,{value:t,multiline:f,options:m,fieldLabel:o,onSave:y=>s(e.key,y),onClose:()=>h(!1)})]});return a?x:n.jsxs("div",{className:"w6w-field",children:[!w&&n.jsxs("span",{children:[o,i]}),x,e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}function Ts({param:e,value:t,onChange:s,readOnly:r,headerActions:o,onValidityChange:i}){var M;const a=nt(t)??"",l=a!=="",u=t??e.default,[c,d]=b.useState(()=>l||u===void 0?"":JSON.stringify(u,null,2)),[f,p]=b.useState(!1),[h,m]=b.useState(!1),[w,x]=b.useState(!1),g=Be(),y=g.steps??[],A=(((M=g.stateShape)==null?void 0:M.fields.length)??0)>0;b.useEffect(()=>{if(l)return;let k;try{k=c.trim()===""?void 0:JSON.parse(c)}catch{k=void 0}JSON.stringify(k)!==JSON.stringify(u)&&(d(u===void 0?"":JSON.stringify(u,null,2)),p(!1))},[u,e.key,l]);const R=k=>{d(k)},S=k=>{p(!1),i==null||i(!0),s(e.key,k)},v=({valid:k,error:T})=>{if(i==null||i(k||T==="Empty"),!k&&T==="Empty"){p(!1),s(e.key,void 0);return}p(!k)},j=()=>{const k=ml(c);k&&(p(!1),s(e.key,k))},C=e.label??e.key,$=()=>{let k;try{k=c.trim()===""?void 0:JSON.parse(c)}catch{k=void 0}s(e.key,k)};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[C,e.required?" *":""]}),o,!l&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${C} in full view`,onClick:()=>m(!0),children:n.jsx(ae.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${r?" is-readonly":""}`,"data-testid":"json-binding-ref",children:n.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-var","data-kind":"var","data-ref":a,title:`Variable: ${a}`,children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"◆"}),n.jsx("span",{className:"w6w-expr-chip-label",children:Xe(a)}),!r&&n.jsx("button",{type:"button",className:"w6w-expr-chip-x","aria-label":`Remove the reference from ${C}`,style:{border:0,padding:0,font:"inherit"},onClick:$,children:"×"})]})}),!r&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse step outputs, metadata & variables","aria-label":`Edit expression for ${C}`,onClick:()=>x(!0),children:"ƒx"})]})})}):n.jsx(He,{value:c,onChange:R,onBlur:j,readOnly:r,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:S,onValidityChange:v,overlay:r?void 0:n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${C}`,onClick:()=>x(!0),children:"ƒx"})}),w&&n.jsx(Gt,{mode:"json-binding",value:void 0,jsonValue:t,options:g,fieldLabel:C,whole:e.whole,onSaveJson:k=>s(e.key,k),onClose:()=>x(!1)}),!l&&f&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"}),e.whole&&!l&&!r&&(y.length>0||A)&&n.jsxs("div",{className:"w6w-seed-chips w6w-json-quickbind",children:[A&&n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${C} to {{ state }}, the run state upstream steps wrote`,onClick:()=>s(e.key,"{{ state }}"),children:n.jsx("code",{children:"state"})}),y.length>0&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Use the output of"}),y.map(k=>n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${C} to {{ nodes.${k.id}.output }}`,onClick:()=>s(e.key,`{{ nodes.${k.id}.output }}`),children:n.jsx("code",{children:k.id})},k.id))]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),h&&!l&&n.jsxs(ve,{title:C,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>m(!1),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(He,{value:c,onChange:R,readOnly:r,height:"100%",minHeight:"360px","aria-label":`${e.key} JSON (full view)`,onValidChange:S,onValidityChange:v})}),f&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function Vl({param:e,value:t,onChange:s,readOnly:r}){var g;const o=Array.isArray(e.options)?e.options:[],i=((g=e.config)==null?void 0:g.valueFormat)==="csv",a=t??e.default,l=Array.isArray(a)?a:i&&typeof a=="string"?a.split(",").map(y=>y.trim()).filter(Boolean):[],u=new Set(l.map(String)),c=o.filter(y=>!u.has(String(y.value))),d=y=>{var A;return((A=o.find(R=>String(R.value)===String(y)))==null?void 0:A.label)??String(y)},f=y=>s(e.key,i?y.join(","):y),p=y=>{if(!y||u.has(y))return;const A=o.find(R=>String(R.value)===y);f([...l,A?A.value:y])},h=y=>f(l.filter(A=>String(A)!==String(y))),m=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",w=e.label??e.key,x=e.required?" *":"";return n.jsx(Oe,{param:e,value:t,onChange:s,readOnly:r,label:w,req:x,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"]}),!r&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:c.length===0,onClick:()=>f([...l,...c.map(y=>y.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:[...o,...l.filter(y=>!o.some(A=>String(A.value)===String(y))).map(y=>({value:y,label:String(y)}))].map(y=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:u.has(String(y.value)),disabled:r,onChange:A=>A.target.checked?p(String(y.value)):h(y.value)}),n.jsx("span",{children:y.label})]},String(y.value)))})]}):n.jsx(n.Fragment,{children:n.jsxs("div",{className:`w6w-multiselect${r?" is-readonly":""}`,children:[l.map(y=>n.jsxs("span",{className:"w6w-chip",children:[d(y),!r&&n.jsx("button",{type:"button",className:"w6w-chip-x","aria-label":`Remove ${d(y)}`,title:"Remove",onClick:()=>h(y),children:"×"})]},String(y))),!r&&n.jsxs("select",{className:"w6w-multiselect-add",value:"",disabled:c.length===0,"aria-label":`Add to ${e.label??e.key}`,onChange:y=>p(y.target.value),children:[n.jsx("option",{value:"",children:c.length>0?l.length?"Add more…":m:"All selected"}),c.map(y=>n.jsx("option",{value:String(y.value),children:y.label},String(y.value)))]})]})})})}function zl(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 Kl({label:e,value:t,onChange:s,readOnly:r}){const o=typeof t=="string"?t:t==null?"":JSON.stringify(t),[i,a]=b.useState(null),l=()=>{let d=o;try{d=o.trim()?JSON.stringify(JSON.parse(o),null,2):""}catch{}a(d)};let u=!1,c;if(i!==null)if(i.trim()==="")u=!0;else try{c=JSON.parse(i),u=!0}catch{}return n.jsxs("span",{className:"w6w-array-json",children:[n.jsx("input",{className:"w6w-array-input",type:"text",value:o.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(ae.Icon,{name:"maximize",size:14})}),i!==null&&n.jsxs(ve,{title:e,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>a(null),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(He,{value:i,onChange:a,height:"100%",minHeight:"360px",readOnly:r,"aria-label":`${e} JSON editor`})}),!u&&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:()=>a(null),children:r?"Close":"Cancel"}),!r&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:!u,onClick:()=>{u&&(s(i.trim()===""?"":JSON.stringify(c)),a(null))},children:"Apply"})]})]})]})}function Gl({field:e,value:t,row:s,onChange:r,readOnly:o}){var c,d;const i=e.placeholder??e.label??e.key,a=(c=e.config)==null?void 0:c.valueTypeFrom,l=e.label??e.key;if(a){const f=String((s==null?void 0:s[a])??"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:o,"aria-label":l,onChange:h=>r(h.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(Kl,{label:l,value:t,onChange:r,readOnly:o});if(f==="number")return n.jsx("input",{className:"w6w-array-input",type:"number",value:t==null?"":String(t),placeholder:i,"aria-label":l,readOnly:o,onChange:p=>r(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:o,"aria-label":e.label??e.key,onChange:f=>r(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:o,"aria-label":e.label??e.key,onChange:f=>r(f.target.checked)}),n.jsx("span",{children:e.label??e.key})]});const u=e.type==="number";return n.jsx("input",{className:"w6w-array-input",type:u?"number":"text",value:String(t??e.default??""),placeholder:i,"aria-label":e.label??e.key,readOnly:o,onChange:f=>r(u?Number(f.target.value):f.target.value)})}function ns({param:e,value:t,onChange:s,readOnly:r}){const o=e.item??{type:"string"},i=o.type==="object",a=Array.isArray(t)?t:Array.isArray(e.default)?e.default:[],l=p=>s(e.key,p),u=()=>i?Object.fromEntries((o.fields??[]).map(p=>[p.key,p.default??""])):o.type==="number"?0:"",c=(p,h)=>l(a.map((m,w)=>w===p?h:m)),d=p=>{const m={...p??{}};for(const w of o.fields??[])m[w.key]===void 0&&(m[w.key]=w.default);return m},f=(p,h,m)=>{var x;const w={...p??{},[h]:m};for(const g of o.fields??[])((x=g.config)==null?void 0:x.valueTypeFrom)===h&&!zl(String(m??""),w[g.key])&&(w[g.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:[a.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"None yet — add one below."}),i&&a.length>0&&n.jsxs("div",{className:"w6w-array-head","aria-hidden":"true",children:[n.jsx("div",{className:"w6w-array-head-cells",children:(o.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))}),!r&&n.jsx("span",{className:"w6w-array-x w6w-array-head-ghost"})]}),a.map((p,h)=>n.jsxs("div",{className:"w6w-array-row",children:[i?n.jsx("div",{className:"w6w-array-cells",children:(o.fields??[]).map(m=>n.jsx(Gl,{field:m,value:p==null?void 0:p[m.key],row:d(p),readOnly:r,onChange:w=>c(h,f(p,m.key,w))},m.key))}):n.jsx("input",{className:"w6w-array-input",type:o.type==="number"?"number":"text",value:String(p??""),placeholder:o.placeholder,readOnly:r,onChange:m=>c(h,o.type==="number"?Number(m.target.value):m.target.value)}),!r&&n.jsx("button",{type:"button",className:"w6w-array-x","aria-label":"Remove item",title:"Remove",onClick:()=>l(a.filter((m,w)=>w!==h)),children:"×"})]},h)),!r&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-array-add",onClick:()=>l([...a,u()]),children:"+ Add"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const Yl=["string","number","boolean","json"],Xl=[];function bn(e,t=[]){return Array.isArray(e)?e.every(s=>s&&typeof s=="object"&&typeof s.key=="string")?e:null:!e||typeof e!="object"||et(e)||nt(e)||"$expr"in e?null:Object.entries(e).map(([s,r])=>{const o=t.find(a=>a.key===s),i=typeof r;return{key:s,type:o&&JSON.stringify(o.value)===JSON.stringify(r)?o.type:i==="string"||i==="number"||i==="boolean"?i:"json",value:r}})}function Zl(e){const t=Array.isArray(e)?bn(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 Tr(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 Or(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Ir(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 Ql({param:e,value:t,label:s,onChange:r,readOnly:o}){const[i,a]=b.useState(null),l=()=>a(Ir(t,!0));let u=!1,c;if(i!==null)try{c=JSON.parse(i),u=!0}catch{}return n.jsxs(n.Fragment,{children:[n.jsxs(Oe,{bare:!0,param:e,value:t,onChange:(d,f)=>r(f),readOnly:o,label:s,req:"",children:[n.jsx("input",{type:"text",className:"w6w-datavar-json-preview",value:Ir(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(ae.Icon,{name:"maximize",size:14})})]}),i!==null&&n.jsxs(ve,{title:s,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>a(null),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(He,{value:i,onChange:a,height:"100%",minHeight:"360px",readOnly:o,"aria-label":`${s} JSON editor`})}),!u&&i.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:()=>a(null),children:o?"Close":"Cancel"}),!o&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:!u,onClick:()=>{u&&(r(c),a(null))},children:"Apply"})]})]})]})}function ec({param:e,value:t,onChange:s,readOnly:r}){const o=t??e.default??Xl,i=b.useMemo(()=>Zl(o),[o]),[a,l]=b.useState(()=>Array.isArray(o)?"fields":"json"),u=b.useRef([]),[c,d]=b.useState(!1),[f,p]=b.useState(null),h=bn(o,u.current),m=h??[],w=a==="json"||h===null,x=e.label??e.key,g=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 ${x} as fields`,"aria-pressed":!w,disabled:c||!!f||h===null,title:h===null?"Use a literal JSON object to edit individual fields":"Edit individual fields",onClick:()=>{!r&&!Array.isArray(o)&&s(e.key,m),l("fields")},children:"Fields"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${w?" active":""}`,"aria-label":`Edit ${x} as JSON`,"aria-pressed":w,onClick:()=>{u.current=m,l("json")},children:"JSON"})]});if(w)return n.jsxs("div",{className:"w6w-datavar-json",children:[n.jsx(Ts,{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:i,readOnly:r,headerActions:g,onValidityChange:R=>d(!R),onChange:(R,S)=>{if(S!==void 0&&bn(S)===null&&!nt(S)&&!et(S)&&!(S&&typeof S=="object"&&"$expr"in S)){p("Use a JSON object, a typed key/value array, or an object binding.");return}p(null),d(!1),s(R,S)}}),f&&n.jsx("span",{className:"w6w-hint w6w-datavar-error","aria-live":"polite",children:f})]});const y=R=>s(e.key,R),A=(R,S)=>y(m.map((v,j)=>j===R?{...v,...S}:v));return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[x,e.required?" *":""]}),g]}),n.jsxs("div",{className:"w6w-stack",children:[m.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No variables yet — add one below."}),m.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"}),!r&&n.jsx("span",{})]}),m.map((R,S)=>n.jsxs("div",{className:"w6w-datavar-row",children:[n.jsx("input",{type:"text",placeholder:"key","aria-label":"Variable key",value:R.key,readOnly:r,onChange:v=>A(S,{key:v.target.value})}),n.jsx("select",{value:R.type,"aria-label":"Variable type",disabled:r,onChange:v=>{const j=v.target.value;A(S,{type:j,value:Tr(j,Or(R.value))})},children:Yl.map(v=>n.jsx("option",{value:v,children:v},v))}),R.type==="json"?n.jsx(Ql,{param:e,value:R.value,label:R.key||"value",onChange:v=>A(S,{value:v}),readOnly:r}):n.jsx(Oe,{bare:!0,param:e,value:R.value,onChange:(v,j)=>A(S,{value:j}),readOnly:r,label:R.key||"value",req:"",children:R.type==="boolean"?n.jsxs("select",{value:R.value===!0?"true":"false",disabled:r,onChange:v=>A(S,{value:v.target.value==="true"}),children:[n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:R.type==="number"?"number":"text",placeholder:"value",value:Or(R.value),readOnly:r,onChange:v=>A(S,{value:Tr(R.type,v.target.value)})})}),!r&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Remove variable ${R.key||S+1}`,title:"Remove",onClick:()=>y(m.filter((v,j)=>j!==S)),children:"×"})]},S)),!r&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y([...m,{key:"",type:"string",value:""}]),children:"+ Add variable"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}function ss(e,t){const s={...t};for(const r of e){const o=t[r.key];if(!(r.type!=="json"||typeof o!="string"||o.trim()===""))try{s[r.key]=JSON.parse(o)}catch{return{error:`${r.label} is not valid JSON. Check it and try again.`}}}return{values:s}}function an({fields:e,values:t,onChange:s,enterSubmitProps:r,mode:o="create"}){const i=(a,l)=>s({...t,[a]: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(a=>{const l=o==="edit",u=t[a.key]??(l?void 0:a.default)??"";if(a.type==="boolean")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:!!u,onChange:f=>i(a.key,f.target.checked),...r}),a.label,a.required?" *":""]}),a.hint&&n.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key);const c=a.type==="secret"||a.secret===!0;if(a.type==="json"||a.type==="text")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[a.label,a.required?" *":""]}),n.jsx("textarea",{className:c?"w6w-secret-input":void 0,rows:a.type==="json"?6:3,value:String(u??""),placeholder:l&&c?"•••••• (unchanged)":void 0,onChange:f=>i(a.key,f.target.value),name:`w6w-cred-${a.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other"}),a.hint&&n.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key);const d=a.type==="number"?"number":"text";return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[a.label,a.required?" *":""]}),n.jsx("input",{type:d,className:c?"w6w-secret-input":void 0,value:String(u??""),placeholder:l&&c?"•••••• (unchanged)":void 0,onChange:f=>i(a.key,a.type==="number"&&!(l&&f.target.value==="")?Number(f.target.value):f.target.value),name:`w6w-cred-${a.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...r}),a.hint&&n.jsx("span",{className:"w6w-hint",children:a.hint})]},a.key)})]})}function No({credentials:e,mode:t,onModeChange:s,selectedId:r,onSelect:o,canUseExisting:i=!0,contract:a}){const l=u=>{const c=Object.values(u.display??{}).filter(Boolean);return c.length>0?`${u.name} (${c.join(", ")})`:u.name};return n.jsxs("div",{className:"w6w-stack",children:[i&&n.jsxs("div",{className:"w6w-field",role:"radiogroup","aria-label":"Credential",children:[n.jsxs("span",{children:["Credential",a?` (${a})`:""]}),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")})," ","Create new"]})]}),i&&t==="existing"&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Stored credential"}),n.jsx("select",{name:"w6w-credential-id",value:r,onChange:u=>o(u.target.value),children:e.map(u=>n.jsx("option",{value:u.id,children:l(u)},u.id))})]})]})}function ko(e){const t=(e.bindingFields??[]).filter(o=>o.key!=="delegatedUser");return e.impersonation==="none"?t:[{...(e.bindingFields??[]).find(o=>o.key==="delegatedUser")??{type:"string"},key:"delegatedUser",label:"Impersonated user",type:"string",required:e.impersonation==="required"},...t]}function So(e,t){const s={},r={};for(const o of e){const i=t[o.key];i==null||i===""||(o.key==="delegatedUser"?s.delegatedUser=String(i):r[o.key]=i)}return Object.keys(r).length>0&&(s.settings=r),Object.keys(s).length>0?s:void 0}const tc="width=560,height=720,menubar=no,toolbar=no,location=no";function Co(e){return new Promise((t,s)=>{const r=window.open(e,"w6w-oauth",tc);if(!r){s(new Error("Popup blocked — allow popups for this site and try again."));return}let o=!1;const i=()=>{o=!0,window.removeEventListener("message",a),window.clearInterval(l)},a=u=>{const c=u.data;if((c==null?void 0:c.w6w)==="oauth-result"){i();try{r.close()}catch{}c.ok&&typeof c.connectionId=="string"?t({connectionId:c.connectionId}):s(new Error(c.error??"OAuth flow failed."))}};window.addEventListener("message",a);const l=window.setInterval(()=>{o||r.closed&&(i(),s(new Error("OAuth popup was closed before the flow completed.")))},500)})}const nc=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function sc(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function Ao(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 r=s.target;r.tagName!=="TEXTAREA"&&(sc(r)||r.tagName==="INPUT"&&nc.has(r.type)||(s.preventDefault(),e()))}}}function Os(e){const t=ye(),[s,r]=b.useState(null),[o,i]=b.useState(!!e.initialAppId);return b.useEffect(()=>{const a=e.initialAppId;if(!a)return;let l=!1;const u=f=>{l||(r(f),i(!1))},c=t.listAppsByIds;if(c)return c([a]).then(f=>u(f.find(p=>p.id===a)??null)).catch(()=>u(null)),()=>{l=!0};const d=t.listApps;return typeof d=="function"?d().then(f=>u(f.find(p=>p.id===a)??null)).catch(()=>u(null)):u(null),()=>{l=!0}},[t,e.initialAppId]),s?n.jsx(ve,{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(ht,{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:()=>r(null),children:"← Apps"}),children:n.jsx(rc,{app:s,onCreated:e.onCreated,onClose:e.onClose})}):o?n.jsx(ve,{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(ve,{title:"Add connection",onClose:e.onClose,size:"xl",children:n.jsx("div",{className:"w6w-stepbuilder-content",children:n.jsx(ut,{onSelectApp:r,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function rc({app:e,onCreated:t,onClose:s}){var J,ee;const r=ye(),[o,i]=b.useState(null),[a,l]=b.useState(""),[u,c]=b.useState(""),[d,f]=b.useState({}),[p,h]=b.useState(null),[m,w]=b.useState(!1),[x,g]=b.useState(null),[y,A]=b.useState(null),[R,S]=b.useState(""),[v,j]=b.useState(""),[C,$]=b.useState({}),M=b.useRef(null);b.useEffect(()=>{let L=!1;return i(null),r.getAppAuth(e.id).then(H=>!L&&i(H.filter(ie=>ie.available!==!1))).catch(H=>!L&&h(H.message)),()=>{L=!0}},[r,e.id]);const k=o??[],T=k.find(L=>L.key===a)??k.find(L=>L.default===!0)??k[0],I=(T==null?void 0:T.fields)??[],F=(T==null?void 0:T.type)==="oauth2",q=T==null?void 0:T.serviceAccount,z=r.listCredentials,W=r.createCredential,P=!F&&!!q&&typeof z=="function"&&typeof W=="function",O=((J=q==null?void 0:q.accepts)==null?void 0:J[0])??"",Z=(x??[]).filter(L=>L.contract===O&&L.status==="active"),Q=Z.length===0?"new":y??"existing",re=Z.some(L=>L.id===R)?R:((ee=Z[0])==null?void 0:ee.id)??"",_=P&&q?ko(q):[];b.useEffect(()=>{if(!P||!z)return;let L=!1;return g(null),A(null),M.current=null,z.call(r,{contract:O}).then(H=>!L&&g(H)).catch(()=>!L&&g([])),()=>{L=!0}},[r,P,O,z]);const Y=(T==null?void 0:T.key)==="zero-credential",X=L=>L===void 0||L==="",B=!F&&!Y&&(P?x===null||_.some(L=>L.required&&X(C[L.key]))||(Q==="existing"?re==="":v.trim()===""||I.some(L=>L.required&&X(d[L.key]))):I.some(L=>L.required&&X(d[L.key]))),G=!T||!F&&!Y&&B||m;async function te(){if(T){h(null),w(!0);try{if(Y)t({connectionId:`zerocred:${e.id}`});else if(F){const{authorizationUrl:L}=await r.startAppOAuthFlow(e.id,T.key,{displayName:u||void 0}),{connectionId:H}=await Co(L);t({connectionId:H})}else if(P&&W){let L=Q==="existing"?re:M.current;if(L===null){const ue=ss(I,d);if("error"in ue){h(ue.error);return}const me=await W.call(r,{name:v.trim(),contract:O,source:ue.values});M.current=me.id,L=me.id}const H=So(_,C),ie={authKey:T.key,credentialId:L,...H?{binding:H}:{},...u?{displayName:u}:{}},pe=await r.createConnection(e.id,ie);t({connectionId:pe.id})}else{const L=ss(I,d);if("error"in L){h(L.error);return}const H=await r.createConnection(e.id,{authKey:T.key,credential:L.values,displayName:u||void 0});t({connectionId:H.id})}}catch(L){h(L.message)}finally{w(!1)}}}const E=Ao(te,{enabled:!G});return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[o===null&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading auth methods…"}),o!==null&&k.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."}),k.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Auth method"}),n.jsx("select",{value:(T==null?void 0:T.key)??"",onChange:L=>{l(L.target.value),f({}),$({}),M.current=null,h(null)},children:k.map(L=>n.jsxs("option",{value:L.key,children:[L.displayName??L.key," (",L.type,")"]},L.key))})]}),T&&n.jsxs(n.Fragment,{children:[!Y&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Display name"}),n.jsx("input",{type:"text",value:u,onChange:L=>c(L.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",...E})]}),T.description&&n.jsx("p",{className:"w6w-muted w6w-small",children:T.description}),Y?null:F?n.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",n.jsx("strong",{children:T.displayName??T.key})," to authorize this connection."]}):P&&q?n.jsxs(n.Fragment,{children:[n.jsx(No,{credentials:Z,mode:Q,onModeChange:L=>{A(L),M.current=null},selectedId:re,onSelect:S,canUseExisting:Z.length>0,contract:O}),q.scopes.length>0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:["Scopes: ",n.jsx("code",{children:q.scopes.join(" ")})]}),_.length>0&&n.jsx(an,{fields:_,values:C,onChange:$,enterSubmitProps:E}),Q==="new"&&n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Credential name *"}),n.jsx("input",{type:"text",value:v,onChange:L=>j(L.target.value),placeholder:"e.g. Workspace automation",maxLength:80,name:"w6w-credential-name",autoComplete:"off","data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...E})]}),n.jsx(an,{fields:I,values:d,onChange:f,enterSubmitProps:E})]})]}):n.jsx(an,{fields:I,values:d,onChange:f,enterSubmitProps:E})]}),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:G,onClick:te,children:m?Y?"Saving…":F?"Waiting for authorization…":"Saving…":Y?"Use this":F?`Sign in with ${(T==null?void 0:T.displayName)??(T==null?void 0:T.key)??"provider"}`:"Save connection"})]})]})}const St=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Is=[["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)"]],en={"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."},Eo=new Set(Is.map(([e])=>e)),Ro=new Set(["is-true","is-false","has-value","is-empty"]),oc=new Set(["and","or","xor","!","!!","==","!=",...Eo]);function $r(e){if(!St(e))return!0;const t=Object.keys(e);return!(t.length===1&&oc.has(t[0]))}function Pr(e){return Ro.has(e)}const _r={...Object.fromEntries(Is),"==":"equals","!=":"does not equal",in:"is in"};function ic(e){return e.startsWith("not:")?`Not (${_r[e.slice(4)]??e.slice(4)})`:_r[e]??e}const To=[["and","All of (AND)"],["or","Any of (OR)"],["xor","Exactly one of (XOR)"]],Oo=Object.fromEntries(To);function ac(e){return Oo[e]??e}function $s(e,t=!0){if(!St(e))return;const s=Object.entries(e);if(s.length!==1)return;const[r,o]=s[0];if(r==="!!"&&Array.isArray(o)&&o.length===1&&$r(o[0]))return{left:o[0],operator:"has-value",right:!0};if(r==="!"&&Array.isArray(o)&&o.length===1){const i=$s(o[0],!1);return i?t&&!i.negated?{...i,negated:!0}:void 0:$r(o[0])?{left:o[0],operator:"is-empty",right:!0}:void 0}if(!(!Eo.has(r)||!Array.isArray(o)||o.length!==2)){if(r==="==="&&typeof o[1]=="boolean")return{left:o[0],operator:o[1]?"is-true":"is-false",right:o[1]};if(!Ro.has(r))return{left:o[0],operator:r,right:o[1]}}}function lc(e){if(!(!St(e)||Object.keys(e).length!==1))return $s(e.$expr)}function cc(e){const t=lc(e);if(t)return{combinator:"and",rows:[t]};if(!St(e)||Object.keys(e).length!==1||!St(e.$expr))return;const s=Object.entries(e.$expr);if(s.length!==1)return;const[r,o]=s[0];if(!Object.hasOwn(Oo,r)||!Array.isArray(o)||o.length===0)return;const i=o.map(a=>$s(a));if(!i.some(a=>a===void 0))return{combinator:r,rows:i}}function Fr(e){const t=e.rows.filter(s=>s.left!=="").map(s=>{const r=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?{"!":[r]}:r});return t.length===0?!1:{$expr:t.length===1?t[0]:{[e.combinator]:t}}}function rs(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"?Nn(e):qe(e)?e.parts:null;if(t){const s=t.map(r=>r.kind==="expr"?r.expr:r.kind==="var"?{var:r.ref}:r.kind==="secret"?{var:`secrets.${r.ref}`}:r.value??"");return s.length===1?s[0]:{cat:s}}return e}function Lr(e){return typeof e=="string"?rs(e)===e?e:JSON.stringify(e):St(e)?Object.keys(e).length===1&&typeof e.var=="string"?le.serializeTemplate([{kind:"var",ref:e.var}]):le.serializeTemplate([{kind:"expr",expr:e}]):JSON.stringify(e)??""}const Io={left:"",operator:"is-true",right:!0},Mr={combinator:"and",rows:[Io]},uc=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function An({values:e,onChange:t,readOnly:s,purpose:r="if"}){const o=Be(),i=e.condition===void 0?!0:e.condition,a=cc(i),[l,u]=b.useState(!1),[c,d]=b.useState(a??Mr),f=b.useRef(0),[p,h]=b.useState(()=>c.rows.map(()=>f.current++)),m=a!==void 0||typeof i=="boolean",w=uc(Fr(c),i)?c:a??Mr,x=w.rows.map((v,j)=>p[j]??-1-j),g=(v,j=x)=>{d(v),h(j),t({...e,condition:Fr(v)})},y=(v,j)=>g({...w,rows:w.rows.map((C,$)=>$===v?{...C,...j}:C)}),A=()=>g({...w,rows:[...w.rows,Io]},[...x,f.current++]),R=v=>g({...w,rows:w.rows.filter((j,C)=>C!==v)},x.filter((j,C)=>C!==v)),S=w.rows.length>1;return n.jsxs("div",{className:"w6w-condition-editor",children:[l||!m?n.jsx(Ie,{params:[{key:"condition",label:"Condition",type:"json",required:!0}],values:e,onChange:t,readOnly:s}):n.jsxs("div",{className:"w6w-condition-rows",children:[S&&n.jsx("select",{className:"w6w-condition-comparison w6w-condition-combinator","aria-label":"Combine conditions",disabled:s,value:w.combinator,onChange:v=>g({...w,combinator:v.target.value}),children:To.map(([v,j])=>n.jsx("option",{value:v,children:j},v))}),w.rows.map((v,j)=>{const C=Pr(v.operator);return n.jsxs("div",{className:`w6w-condition-row${S?" w6w-condition-row-removable":""}${C?" 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 ${j+1}`,checked:v.negated??!1,disabled:s,onChange:$=>y(j,{negated:$.target.checked})}),"Not"]}),n.jsx(Bt,{value:Lr(v.left),"aria-label":"Condition field",placeholder:"Field or expression",readOnly:s,onChange:$=>y(j,{left:rs($)})}),n.jsx("select",{className:"w6w-condition-comparison","aria-label":"Condition comparison",title:en[v.operator],disabled:s,value:v.operator,onChange:$=>y(j,{operator:$.target.value,right:$.target.value==="is-true"?!0:$.target.value==="is-false"?!1:Pr($.target.value)?!0:C?"":v.right}),children:Is.map(([$,M])=>n.jsx("option",{value:$,title:en[$],children:M},$))}),!C&&n.jsx(Bt,{value:Lr(v.right),"aria-label":"Condition value",placeholder:"Value or expression",readOnly:s,onChange:$=>y(j,{right:rs($)})}),S&&!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-remove",title:"Remove condition","aria-label":`Remove condition ${j+1}`,onClick:()=>R(j),children:n.jsx(ae.Icon,{name:"trash",size:14})})]},x[j])}),!s&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-condition-add",onClick:A,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(v=>v.operator))].map(v=>en[v]?n.jsx("p",{className:"w6w-muted w6w-small",children:en[v]},v):null)]}),m&&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:()=>u(!l),children:n.jsx(ae.Icon,{name:l?"form":"code",size:14})}),r!=="router"&&n.jsx("p",{className:"w6w-muted w6w-small",children:r==="stop"?"End the workflow when this condition is true.":o.loop?"When false, skip the remaining steps for this item.":"Continue when this condition is true."})]})}const dc={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 $o({value:e,onChange:t,readOnly:s,target:r="step"}){const o=!!e,i=(e==null?void 0:e.maxAttempts)??3,a=(e==null?void 0:e.delayMs)??1e3,l=(e==null?void 0:e.backoff)??"fixed",u=c=>t({maxAttempts:i,delayMs:a,backoff:l,...e,...c});return n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:o,disabled:s,onChange:c=>t(c.target.checked?{maxAttempts:i,delayMs:a,backoff:l}:void 0)})," ","Retry on failure"]}),n.jsx("span",{className:"w6w-hint",children:dc[r]})]}),o&&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:i,readOnly:s,onChange:c=>u({maxAttempts:Math.max(1,Number(c.target.value)||1)})})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Delay (ms)"}),n.jsx("input",{type:"number",min:0,value:a,readOnly:s,onChange:c=>u({delayMs:Math.max(0,Number(c.target.value)||0)})})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Backoff"}),n.jsxs("select",{value:l,disabled:s,onChange:c=>u({backoff:c.target.value}),children:[n.jsx("option",{value:"fixed",children:"Fixed"}),n.jsx("option",{value:"exponential",children:"Exponential"})]})]})]})]})}function Ps({config:e,onChange:t,readOnly:s,hasGraph:r=!0,failureHandling:o=!0,retryControls:i=!0,reroute:a}){const l=e.onError??"fail";return n.jsxs("div",{className:"w6w-stack",children:[o&&n.jsxs(n.Fragment,{children:[i&&n.jsx($o,{value:e.retry,onChange:u=>t({...e,retry:u}),readOnly:s}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"On error"}),n.jsxs("select",{value:l,disabled:s,onChange:u=>{const c=u.target.value;t({...e,onError:c==="fail"?void 0:c})},children:[n.jsx("option",{value:"fail",children:"Stop the run (default)"}),n.jsx("option",{value:"continue",children:"Continue to the next step"}),r&&n.jsx("option",{value:"continue-record",children:"Continue to the next step & record the error"})]}),r?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."]})]})]}),a&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Reroute on failure"}),n.jsxs("div",{className:"w6w-field-row",children:[a.picker,a.value&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:s,onClick:()=>a.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 En(e){return e.$merge!==void 0}function Po(e){const t=e.$merge;if(t===void 0)return e;if(!(nt(t)||qe(t)||Ss(t)||typeof t=="string"&&Nn(t)))return t&&typeof t=="object"&&!Array.isArray(t)&&!tt(t)&&!("$merge"in t)?{...e,...t}:null}function _o(e,t,s=[]){if(qe(e)||tt(e)||ks(e)||Ss(e)||e===null||typeof e!="object")return qt(e,t);const r=o=>_o(o,t);return Array.isArray(e)?e.map(r):Object.fromEntries(Object.entries(e).map(([o,i])=>[o,s.includes(o)?i:r(i)]))}function _s({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(Ie,{params:[{key:"$merge",label:"JSON customization",type:"json",required:!0,default:{},whole:!0}],values:e,onChange:t,readOnly:s}),Po(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&&En(e)&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{const{$merge:r,...o}=e;t(o)},children:"Remove JSON customization"})]})}function Fo(e){const{label:t,onClick:s,disabled:r,className:o,...i}=e;return n.jsx(kn,{label:t,onClick:s,disabled:r,className:o,danger:!0,icon:"delete","data-testid":i["data-testid"]})}function Lo({values:e,onChange:t,readOnly:s}){const r=Array.isArray(e.routes)?e.routes:wn(We,"route").routes,o=r.filter(g=>!g.default),[i,a]=b.useState(null),[l,u]=b.useState(null),[c,d]=b.useState(null),[f,p]=b.useState(""),h=g=>t({...e,routes:[...g,...r.filter(y=>y.default)]}),m=(g,y)=>h(o.map(A=>A.id===g?{...A,...y}:A)),w=(g,y)=>{const A=o.findIndex(v=>v.id===g);if(A<0||y<0||y>=o.length||A===y)return;const R=[...o],[S]=R.splice(A,1);R.splice(y,0,S),h(R)},x=g=>{f.trim()&&m(g.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:o.map((g,y)=>n.jsxs("div",{className:`w6w-router-route${i===g.id?" is-dragging":""}${l===g.id?" is-drop-target":""}`,"data-route-id":g.id,onDragOver:A=>{s||!i||i===g.id||(A.preventDefault(),A.dataTransfer.dropEffect="move",u(g.id))},onDrop:A=>{A.preventDefault(),!s&&i&&w(i,y),a(null),u(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 ${g.label||g.id}`,title:"Drag to reorder · arrow keys to move",onDragStart:A=>{A.dataTransfer.effectAllowed="move",A.dataTransfer.setData("text/plain",g.id);const R=A.currentTarget.closest(".w6w-router-route");R&&A.dataTransfer.setDragImage(R,16,16),a(g.id)},onDragEnd:()=>{a(null),u(null)},onKeyDown:A=>{A.key!=="ArrowUp"&&A.key!=="ArrowDown"||(A.preventDefault(),w(g.id,y+(A.key==="ArrowUp"?-1:1)))},children:n.jsx(ae.Icon,{name:"grip",size:14})}),n.jsx("span",{className:"w6w-step-rename",children:c===g.id&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Route name",value:f,onChange:A=>p(A.target.value),onBlur:()=>x(g),onKeyDown:A=>{A.key==="Enter"&&x(g),A.key==="Escape"&&d(null)}}):n.jsxs("button",{type:"button",className:"w6w-router-route-name",disabled:s,"aria-label":`Rename ${g.label||g.id}`,onClick:()=>{p(g.label||g.id),d(g.id)},children:[g.label||g.id,!s&&n.jsx(ae.Icon,{name:"edit",size:12})]})}),n.jsx(Fo,{label:`Remove ${g.label||g.id}`,disabled:s,onClick:()=>h(o.filter(A=>A.id!==g.id))})]}),n.jsx(An,{values:{condition:g.condition??!1},onChange:A=>m(g.id,{condition:A.condition}),readOnly:s,purpose:"router"})]},g.id))}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",disabled:s,onClick:()=>{let g=1;for(;r.some(y=>y.id===`route_${g}`);)g++;h([...o,{id:`route_${g}`,label:`Route ${g}`,condition:!1}])},children:[n.jsx("span",{"aria-hidden":"true",children:"+"})," Add route"]})]})}function Mo({value:e,onCommit:t,readOnly:s}){const[r,o]=b.useState(!1),[i,a]=b.useState(e),[l,u]=b.useState(null),c=()=>{const d=i.trim(),f=d&&d!==e?t(d):null;if(f){u(f);return}u(null),o(!1)};return n.jsxs("span",{className:"w6w-step-rename",children:[r&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Node name",value:i,onChange:d=>{a(d.target.value),u(null)},onBlur:c,onKeyDown:d=>{d.key==="Enter"&&c(),d.key==="Escape"&&(a(e),u(null),o(!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:()=>{a(e),o(!0)},children:n.jsx(ae.Icon,{name:"edit",size:15})})]}),l&&n.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:l})]})}function Do({values:e,onChange:t,readOnly:s}){const r=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:r?"condition":"always",onChange:o=>{const i=o.target.value==="condition";t({...e,condition:!i})},children:[n.jsx("option",{value:"always",children:"Always"}),n.jsx("option",{value:"condition",children:"A condition matches"})]})]}),r?n.jsx(An,{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 pc=["props","code"];function fc(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ho({params:e,values:t,onChange:s,onValidityChange:r,readOnly:o,initialView:i="props"}){const a=e.length>0,[l,u]=b.useState(i),c=!a||l==="code",[d,f]=b.useState(()=>Dr(t)),[p,h]=b.useState(!0),m=b.useRef(!0),w=y=>{y!==m.current&&(m.current=y,h(y),r==null||r(y))},x=y=>{y==="code"&&f(Dr(t)),w(!0),u(y)},g=a?"Values (JSON)":"Payload";return n.jsxs("div",{className:"w6w-stack",children:[a&&n.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:n.jsx(In,{view:l,views:[...pc],onChange:y=>x(y)})}),c?n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:g}),n.jsx(He,{value:d,onChange:f,readOnly:o,minHeight:"140px","aria-label":`${g} JSON`,onValidChange:y=>{const A=fc(y);w(A),A&&s(y)},onValidityChange:y=>{y.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(Ie,{params:e,values:t,onChange:s,readOnly:o})]})}function Dr(e){return JSON.stringify(e??{},null,2)}const hc=new Set(["http:","https:","mailto:"]);function wc(e){try{return hc.has(new URL(e).protocol)?e:""}catch{return""}}const mc=["img"];function bc({node:e,href:t,children:s,...r}){return n.jsx("a",{...r,href:t||void 0,target:"_blank",rel:"noopener noreferrer nofollow",children:s})}function Wo(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 gc({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 Fs({content:e,className:t,copyable:s=!0}){const{frontmatter:r,body:o}=Wo(e),i=n.jsxs("div",{className:t,children:[(r==null?void 0:r.trim())&&n.jsx(gc,{yaml:r}),n.jsx(Ui,{skipHtml:!0,urlTransform:wc,disallowedElements:mc,unwrapDisallowed:!0,components:{a:bc},children:o})]});return s?n.jsx(ae.Copyable,{value:e,label:"Copy Markdown",className:"w6w-copyable--document",children:i}):i}const qo="default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'";function Bo(e){return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${qo}">${e}`}function Uo({html:e}){return n.jsx("iframe",{title:"HTML preview",className:"w6w-html-preview",sandbox:"",referrerPolicy:"no-referrer",srcDoc:Bo(e)})}function Jo(e){return typeof e=="string"?"string":typeof e=="number"?"number":typeof e=="boolean"?"boolean":"null"}function yc(e){return Jo(e)==="string"?JSON.stringify(e):String(e)}function xc(e){return typeof e=="object"&&e!==null}function vc(e,t){return`${t} ${e?"item":"key"}${t===1?"":"s"}`}function jc({value:e,expandDepth:t=2}){return n.jsx(Vo,{label:void 0,value:e,depth:0,expandDepth:t})}function Vo(e){const{label:t,value:s,depth:r,expandDepth:o}=e,i=xc(s),a=Array.isArray(s),l=i?a?s.map((c,d)=>[d,c]):Object.entries(s):[],u=t===void 0?null:n.jsx("span",{className:"w6w-json-key",children:t});return i&&l.length>0?n.jsxs("details",{className:"w6w-json-node",open:r<o,children:[n.jsxs("summary",{children:[u,a?"[…]":"{…}"," ",n.jsx("span",{className:"w6w-json-count",children:vc(a,l.length)})]}),n.jsx("div",{className:"w6w-json-children",children:l.map(([c,d])=>n.jsx(Vo,{label:c,value:d,depth:r+1,expandDepth:o},String(c)))})]}):n.jsxs("div",{className:"w6w-json-leaf",children:[u,u===null?null:": ",n.jsx("span",{className:`w6w-json-${i?"null":Jo(s)}`,children:i?a?"[]":"{}":yc(s)})]})}const zo=262144,Nc=/^#{1,6}\s+\S/,kc=/^```/,Sc=/^\s*(?:[-*+]|\d+\.)\s+\S/,Cc=/\[[^\]\n]+\]\(https?:\/\/[^)\s]+\)/;function Ko(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 r=JSON.parse(t);if(r!==null&&typeof r=="object")return{format:"json",data:r}}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(`
16
- `);return s.some(r=>Nc.test(r)||kc.test(r))||s.filter(r=>Sc.test(r)).length>=2||Cc.test(t)?{format:"markdown",text:e}:{format:"text",text:e}}function Go(e){return e.format==="json"?JSON.stringify(e.data,null,2)??"":e.text}const Ac=65536;function Wn(e,t){return e.length>Ac?n.jsx("pre",{className:"w6w-result-viewer-text",children:e}):n.jsx(ae.CodeBlock,{code:e,language:t,copyable:!1,wrap:!0})}function ke(e){const{value:t,format:s="auto",maxHeight:r=320,className:o}=e,i=b.useMemo(()=>s==="json"?{format:"json",data:t}:Ko(t),[t,s]),[a,l]=b.useState("rendered"),[u,c]=b.useState(2),[d,f]=b.useState(0),p=i.format==="json"?"":i.text,h=i.format==="html"||i.format==="markdown",m=h&&p.length>zo,w=b.useMemo(()=>{try{return Go(i)}catch{return typeof t=="string"?t:String(t)}},[i,t]);let x;if(i.format==="json")x=n.jsx(jc,{value:i.data,expandDepth:u},d);else if(i.format==="xml")x=Wn(i.text,"markup");else if(i.format==="text")x=n.jsx("pre",{className:"w6w-result-viewer-text",children:i.text});else{const y=i.format==="html"?"markup":"markdown";m?x=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to render — showing source."}),Wn(i.text,y)]}):a==="source"?x=Wn(i.text,y):i.format==="html"?x=n.jsx(Uo,{html:i.text}):x=n.jsx(Fs,{content:i.text,copyable:!1})}let g=null;return i.format==="json"?g=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{c(Number.POSITIVE_INFINITY),f(y=>y+1)},children:"Expand all"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{c(1),f(y=>y+1)},children:"Collapse all"})]}):h&&!m&&(g=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${a==="rendered"?" active":""}`,"data-mode":"rendered","aria-pressed":a==="rendered",onClick:()=>l("rendered"),children:"Rendered"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${a==="source"?" active":""}`,"data-mode":"source","aria-pressed":a==="source",onClick:()=>l("source"),children:"Source"})]})),n.jsxs("div",{className:["w6w-result-viewer",o??""].filter(Boolean).join(" "),"data-format":i.format,children:[g,n.jsx(ae.Copyable,{value:w,label:"Copy result",className:"w6w-copyable--overlay",children:n.jsx("div",{className:"w6w-result-viewer-body",style:{maxHeight:r,overflow:"auto"},children:x})})]})}function Yo(e,t){const s=e.filter(r=>r.appId===_e);return s.find(r=>r.nodeId===t)??s.find(r=>!r.nodeId)??s[0]??null}const Ec=/auth|token|secret|passw|cookie|api[-_]?key|signature|session/i,Rc="••••••";function Tc(e){const t={};for(const[s,r]of Object.entries(e))t[s]=Ec.test(s)?Rc:r;return t}const Oc=20;function Ic({workflowId:e,stepId:t,stepWith:s,readOnly:r,onUse:o,using:i}){const a=ye(),[l,u]=b.useState(void 0),[c,d]=b.useState(!1),[f,p]=b.useState({phase:"idle"}),[h,m]=b.useState(()=>Date.now()),w=b.useRef(null);b.useEffect(()=>{const v=a.listSubscriptionsForWorkflow;if(!v)return;let j=!1;return v(e).then(C=>!j&&u(Yo(C,t))).catch(C=>!j&&p({phase:"error",message:C.message})),()=>{j=!0}},[a,e,t]);const x=b.useCallback(v=>{var C;const j=w.current;w.current=null,j&&(j.abort.abort(),v&&((C=a.stopWebhookListen)==null||C.call(a,j.subId,j.sessionId).catch(()=>{})))},[a]);b.useEffect(()=>()=>x(!0),[x]),b.useEffect(()=>{if(f.phase!=="waiting")return;const v=setInterval(()=>m(Date.now()),1e3);return()=>clearInterval(v)},[f.phase]);const g=()=>{const v=a.createSubscription;v&&(d(!0),v(_e,"webhook",{workflowId:e,connectionId:null,params:s??{}}).then(j=>u(j)).catch(j=>p({phase:"error",message:j.message})).finally(()=>d(!1)))},y=async()=>{var k;const v=a.startWebhookListen,j=a.pollWebhookListen;if(!l||!v||!j)return;x(!0),p({phase:"starting"});let C;try{C=(await v(l.id)).session}catch(T){p({phase:"error",message:T.message});return}const $=new AbortController,M={subId:l.id,sessionId:C.id,abort:$};for(w.current=M,m(Date.now()),p({phase:"waiting",session:C});;){let T;try{T=await j(l.id,C.id,{waitSeconds:Oc,signal:$.signal})}catch(I){if(w.current!==M)return;w.current=null,p({phase:"error",message:I.message});return}if(w.current!==M)return;if(T.status==="captured"&&T.request){w.current=null,p({phase:"captured",session:T,request:T.request});return}if(T.status==="expired"){w.current=null,(k=a.stopWebhookListen)==null||k.call(a,l.id,C.id).catch(()=>{}),p({phase:"expired"});return}}},A=()=>{x(!0),p({phase:"idle"})};if(!a.startWebhookListen||!a.pollWebhookListen)return null;const R=l==null?void 0:l.webhookUrl,S=f.phase==="waiting"?Math.max(0,Math.ceil((Date.parse(f.session.expiresAt)-h)/1e3)):0;return n.jsxs("div",{className:"w6w-stack w6w-listen","data-testid":"webhook-listen",children:[l===void 0?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):R?n.jsxs(n.Fragment,{children:[n.jsx(ae.Copyable,{value:R,readOnly:!0,children:n.jsx("input",{type:"text",readOnly:!0,value:R,"aria-label":"Webhook URL"})}),f.phase==="waiting"||f.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:["Waiting for a request to ",n.jsx("code",{children:R}),"…",f.phase==="waiting"&&n.jsxs("span",{className:"w6w-muted",children:[" ",$c(S)," left"]})]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:A,children:"Stop"})]}):n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:r,onClick:()=>void y(),children:f.phase==="captured"?"Listen again":"Listen for test event"}),f.phase==="idle"&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Send a request to this URL — it works before you publish, and starts no run."})]})]}):n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"This webhook has no URL yet. Create one, then listen for a test request."}),!r&&a.createSubscription&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:c,onClick:g,children:c?"Creating…":"Create webhook URL"})]}),f.phase==="expired"&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No request arrived in time. Listen again, then send the request."}),f.phase==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:f.message}),f.phase==="captured"&&n.jsx(Pc,{request:f.request,receivedAt:f.session.receivedAt,readOnly:r,using:i,onUse:()=>o(f.request),stepId:t})]})}function $c(e){const t=Math.floor(e/60);return t>0?`${t}:${String(e%60).padStart(2,"0")}`:`${e}s`}function Pc({request:e,receivedAt:t,readOnly:s,using:r,onUse:o,stepId:i}){const a=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})]}),a&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Query"}),n.jsx(ke,{value:e.query,maxHeight:120})]}),n.jsx("div",{className:"w6w-testout-label",children:"Headers"}),n.jsx(ke,{value:Tc(e.headers??{}),maxHeight:160}),n.jsx("div",{className:"w6w-testout-label",children:"Body"}),n.jsx(ke,{value:e.body,maxHeight:240}),!s&&n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:r,onClick:o,children:r?"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.${i}.output.body… }}`}),"."]})]})]})}function Ls(e){return Array.isArray(e)?e:[]}function Ms(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function Ds(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 Hs(e){return e.filter(t=>typeof t.key=="string"&&t.key.trim()!=="").map(t=>({key:t.key,label:t.key,type:Ms(t.type),required:!!t.required}))}function os(e){const t={};for(const s of e){if(typeof s.key!="string"||s.key.trim()==="")continue;const r=Ds(s.type,s.default);r!==void 0&&(t[s.key]=r)}return t}function Xo(e,t){const s=(e??[]).find(o=>o&&o.nodeId===t);if(!s)return;const r=s.input;return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}function _c(e){return qe(e)||typeof e=="string"&&e.includes("{{")}function Ws(e,t=[]){const s=new Set(t.filter(o=>o.type==="secret").map(o=>o.key)),r={};for(const[o,i]of Object.entries(e))i===void 0||tt(i)||s.has(o)&&!_c(i)||(r[o]=i);return r}const is=new Set;function Zo(e){const t=e.then(()=>{},()=>{});return is.add(t),t.then(()=>is.delete(t)),e}async function Qo(){await Promise.all([...is])}function ei(e,t){const s=ye(),r=typeof s.loadTestInputs=="function"&&!!e&&!!t,[o,i]=b.useState(!r),[a,l]=b.useState(void 0);b.useEffect(()=>{if(!r||!e||!t||!s.loadTestInputs){i(!0);return}let f=!1;return i(!1),Qo().then(()=>{var p;return((p=s.loadTestInputs)==null?void 0:p.call(s,e))??[]}).then(p=>{f||(l(Xo(p,t)),i(!0))}).catch(()=>{f||i(!0)}),()=>{f=!0}},[s,r,e,t]);const u=b.useCallback(f=>{l(f),!(!e||!t||typeof s.saveTestInput!="function")&&Zo(s.saveTestInput(e,t,f)).catch(p=>{console.error("test input save failed",p)})},[s,e,t]),c=b.useCallback((f,p)=>u(Ws(f,p)),[u]),d=b.useCallback(()=>u({}),[u]);return{loaded:o,supported:r,input:a,save:c,clear:d}}function ti({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 Fc=600;function ni({app:e,action:t,fields:s,persist:r,listen:o}){const i=ye(),a=xs(),l=b.useMemo(()=>Ls(s),[s]),u=b.useMemo(()=>Hs(l),[l]),c=u.length>0,[d,f]=b.useState(()=>os(l)),[p,h]=b.useState(null),m=r==null?void 0:r.workflowId,w=r==null?void 0:r.stepId,x=ei(m,w),[g,y]=b.useState(!1),[A,R]=b.useState(!1),[S,v]=b.useState(!m||!w);b.useEffect(()=>{if(!m||!w){v(!0);return}if(!x.loaded)return;if(x.input!==void 0){const Y=x.input;Object.keys(Y).length>0&&(f(X=>({...X,...Y})),y(!0),R(!0)),v(!0);return}let _=!1;return i.listStepTests(m,w).then(Y=>{if(_)return;const X=Y.length?Y[Y.length-1]:null;X!=null&&X.with&&(f(B=>({...B,...X.with})),Object.keys(X.with).length>0&&R(!0)),v(!0)}).catch(()=>{_||v(!0)}),()=>{_=!0}},[i,m,w,x.loaded]);const[j,C]=b.useState(0),$=()=>{clearTimeout(k.current),M.current=null,x.clear(),y(!1),f(os(l)),C(_=>_+1)},M=b.useRef(null),k=b.useRef(void 0),T=b.useRef(()=>{});T.current=()=>{clearTimeout(k.current);const _=M.current;M.current=null,_&&x.save(_,u)},b.useEffect(()=>()=>T.current(),[]);const I=_=>{f(_),!(!m||!w||!S)&&(M.current=_,clearTimeout(k.current),k.current=setTimeout(()=>T.current(),Fc))},[F,q]=b.useState(!0),z=F&&Ct(u,d),W=async _=>{const Y=_??d;clearTimeout(k.current),M.current=null,r&&x.save(Y,u),h({status:"running"});let X;try{const B=await i.invokeAction(e,t,{input:Y},{project:a});X={status:"done",value:B.value,logs:B.logs}}catch(B){const G=B;X={status:"error",error:G.message??String(B),errorCode:G.code,logs:G.logs}}if(h(X),r)try{const B=await i.saveStepTest(r.workflowId,r.stepId,{input:r.input,with:Y});await i.recordStepTestRun(r.workflowId,r.stepId,{stepTestId:B.id,status:X.status==="done"?"succeeded":"failed",input:r.input,output:X.status==="done"?X.value:void 0,error:X.status==="error"?X.error:void 0})}catch(B){console.error("step test persist failed",B)}},P=p&&p.status!=="running"?p.logs:void 0,O=_=>{const Y={..._};f(Y),W(Y)},Z=o&&r&&n.jsx(Ic,{workflowId:r.workflowId,stepId:r.stepId,stepWith:o.stepWith,readOnly:o.readOnly,onUse:O,using:(p==null?void 0:p.status)==="running"});return n.jsxs("div",{className:"w6w-stack",children:[Z,Z?n.jsxs("details",{className:"w6w-listen-manual","data-testid":"trigger-sample-payload",open:A,onToggle:_=>R(_.currentTarget.open),children:[n.jsx("summary",{className:"w6w-small",children:"Or test with a sample payload"}),Q()]}):Q(),re()]});function Q(){return n.jsxs("div",{className:"w6w-stack",children:[S?n.jsxs(n.Fragment,{children:[g&&n.jsx(ti,{onClear:$}),n.jsx(Ho,{params:u,values:d,onChange:I,onValidityChange:q},j),!c&&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:!S||!z||(p==null?void 0:p.status)==="running",onClick:()=>void W(),children:(p==null?void 0:p.status)==="running"?"Running…":"▶ Test run"}),S&&!z&&n.jsx("span",{className:"w6w-muted w6w-small",children:F?"Fill the required fields to test.":"The payload must be a JSON object to test."})]})})]})}function re(){return n.jsxs("div",{className:"w6w-steptest",children:[(p==null?void 0:p.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[p.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:p.errorCode})}),p.error]}),(p==null?void 0:p.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Output state (filled values)"}),n.jsx(ke,{value:p.value,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(ae.Copyable,{value:P.join(`
17
- `),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(`
18
- `)})})]})]})}}const Lc=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],Mc=/^(?=\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 si({values:e,onChange:t,readOnly:s}){const r=e.duration??"1s",o=typeof r=="string"?r.match(/^(\d+(?:\.\d+)?)([smhdw])$/i):null,[i,a]=b.useState("s"),[l,u]=b.useState("text"),[c,d]=b.useState(e.until?"until":"duration"),f=typeof r=="string"&&(!Mc.test(r.trim())||/^P$/i.test(r.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:c,onChange:p=>{const h=p.target.value;d(h),t({...e,duration:h==="duration"?"1s":"",until:""})},children:[n.jsx("option",{value:"duration",children:"A duration"}),n.jsx("option",{value:"until",children:"Until a timestamp"})]})]}),c==="until"?n.jsx(Ie,{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=>{o&&a((o==null?void 0:o[2].toLowerCase())??i),u(p.target.value)},children:[n.jsx("option",{value:"text",children:"Shorthand"}),n.jsx("option",{value:"value",disabled:!o,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:((o==null?void 0:o[2].toLowerCase())??i)==="s"?"any":"1",disabled:s,value:(o==null?void 0:o[1])??"",onChange:p=>t({...e,duration:`${p.target.value}${(o==null?void 0:o[2].toLowerCase())??i}`})})]}),n.jsxs("label",{children:["Unit",n.jsx("select",{"aria-label":"Duration unit",disabled:s,value:(o==null?void 0:o[2].toLowerCase())??i,onChange:p=>{a(p.target.value),t({...e,duration:`${(o==null?void 0:o[1])??""}${p.target.value}`})},children:Lc.map(([p,h])=>n.jsx("option",{value:p,children:h},p))})]})]}):n.jsx(Ie,{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 ri({anchorRef:e,onClose:t,children:s}){const r=b.useRef(null),[o,i]=b.useState(null),[a,l]=b.useState(null);return b.useEffect(()=>{const u=e.current;if(!u)return;const c=u.getBoundingClientRect();i({top:c.bottom+6,left:c.left,width:c.width}),l(u.closest("dialog")??document.body)},[e]),b.useEffect(()=>{function u(d){var p,h;const f=d.target;(p=r.current)!=null&&p.contains(f)||(h=e.current)!=null&&h.contains(f)||t()}function c(d){d.key==="Escape"&&t()}return document.addEventListener("mousedown",u),document.addEventListener("keydown",c),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",c)}},[t,e]),!o||!a?null:pn.createPortal(n.jsx("div",{ref:r,className:"w6w-flyout",style:{top:o.top,left:o.left,width:o.width},children:s}),a)}function oi(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),r=Object.keys(t);return s.length!==r.length?!1:s.every(o=>Object.prototype.hasOwnProperty.call(t,o)&&oi(e[o],t[o]))}function Dc(e,t){return e.map(s=>{const r=t&&Object.hasOwn(t,s.id)?t[s.id]:void 0,o=s.data.stepProblems;if(r===void 0||r.length===0){if(o===void 0&&!("stepProblems"in s.data))return s;const{stepProblems:i,...a}=s.data;return{...s,data:a}}return o&&oi(o,r)?s:{...s,data:{...s.data,stepProblems:structuredClone(r)}}})}const Hc={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 Wc(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=Hc[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 qc(e,t){return(t==null?void 0:t.some(s=>s.code==="unknown_connection"&&e.uses.connection===s.connection))??!1}function Hr(e,t,s){if(!e)return"No connection";if(s)return"Couldn't load connections";if(t===null)return e;const r=t.find(o=>o.id===e);return r?r.builtIn?"Built-in":r.displayName??e:"Missing connection — choose another"}function ln(e,t,s){if(s.type==="update"){const o=ln(e,t,{type:"rename",ref:s.ref,name:s.name}),i=s.name.trim(),a=ln(o.nodes,o.connections,{type:"replace",ref:i,connection:s.connection});return s.nodeIds?ln(a.nodes,a.connections,{type:"assign",ref:i,nodeIds:s.nodeIds}):a}if(s.type==="add"||s.type==="rename"){const o=s.name.trim();if(!o)throw new Error("Give the workflow connection a name.");if(Object.hasOwn(t,o)&&(s.type==="add"||o!==s.ref))throw new Error("A workflow connection already uses that name.");if(s.type==="add")return{nodes:e,connections:{...t,[o]:{app:s.app,connection:s.connection}}}}if(!Object.hasOwn(t,s.ref))throw new Error("This workflow connection no longer exists.");const r=t[s.ref];switch(s.type){case"replace":return{nodes:e,connections:{...t,[s.ref]:{...r,connection:s.connection}}};case"rename":{const o=s.name.trim();return{connections:Object.fromEntries(Object.entries(t).map(([i,a])=>[i===s.ref?o:i,a])),nodes:e.map(i=>i.uses.connectionRef===s.ref?Jt(i,o):i)}}case"remove":{if(e.some(a=>a.uses.connectionRef===s.ref))throw new Error("Choose another connection for its nodes before removing this resource.");const{[s.ref]:o,...i}=t;return{nodes:e,connections:i}}case"assign":{const o=new Set(s.nodeIds);if(e.some(i=>o.has(i.id)&&i.uses.app!==r.app))throw new Error("A connection can only be assigned to nodes for the same app.");return{connections:t,nodes:e.map(i=>o.has(i.id)?Jt(i,s.ref):i)}}}}function Rt(e,t){const{connectionRef:s,connection:r,app:o}=e.uses;if(s===void 0)return r??void 0;const i=t&&Object.hasOwn(t,s)?t[s]:void 0;return(i==null?void 0:i.app)===o?i.connection??void 0:void 0}function qs(e,t){const r=(e.split(/[./]/).filter(Boolean).at(-1)??"connection").toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"connection";let o=1;for(;Object.hasOwn(t,`${r}_${o}`);)o++;return`${r}_${o}`}function ii(e){let t=e.connections??{},s=!1;const r=(e.nodes??[]).map(o=>{if(!o.uses.connection||o.uses.connectionRef!==void 0)return o;const i=Object.hasOwn(t,o.id)?t[o.id]:void 0,a=(i==null?void 0:i.app)===o.uses.app&&i.connection===o.uses.connection?o.id:qs(o.uses.app,t);return t={...t,[a]:{app:o.uses.app,connection:o.uses.connection}},s=!0,Jt(o,a)});return s?{...e,nodes:r,connections:t}:e}function Jt(e,t){const{connection:s,...r}=e.uses;return{...e,uses:{...r,connectionRef:t}}}function Bc(e,t,s,r){if(!t){const{connection:l,connectionRef:u,...c}=e.uses;return{step:{...e,uses:c},connections:r}}const o=e.uses.connectionRef,i=o&&s.some(l=>l.id!==e.id&&l.uses.connectionRef===o),a=o&&!i?o:qs(e.uses.app,r);return{step:Jt(e,a),connections:{...r,[a]:{app:e.uses.app,connection:t}}}}function cn(e,t,s,r){return t?s.filter(o=>o.uses.app===e&&Rt(o,r)===t):[]}function ai(e,t,s,r,o){if(o)return{connection:o};for(const l of[...s].reverse()){if(l.id===e.id||l.uses.app!==e.uses.app)continue;const u=Rt(l,r);if(!(!u||!t.some(c=>c.id===u&&c.appId===e.uses.app)))return l.uses.connectionRef?{connectionRef:l.uses.connectionRef}:{connection:u}}for(const[l,u]of Object.entries(r))if(u.app===e.uses.app&&t.some(c=>c.appId===u.app&&c.id===u.connection))return{connectionRef:l};const i=t.filter(l=>l.appId===e.uses.app),a=i.find(l=>l.builtIn)??i[0];return a?{connection:a.id}:{}}function Wr(e,t,s){return s.some(o=>o.builtIn)||!t.some(o=>o.available!==!1&&(o.key==="zero-credential"||o.autoSatisfied===!0&&(o.type==="tenantAuth"||o.type==="jit")))?s:[...s,{id:`zerocred:${e}`,appId:e,authKey:"zero-credential",displayName:"Built-in",builtIn:!0,state:"connected"}]}function Uc(e,t,s,r,o){const i=new Set(cn(e,t,r,o).map(a=>a.uses.connectionRef));return Object.fromEntries(Object.entries(o).map(([a,l])=>[a,i.has(a)?{...l,connection:s}:l]))}const li=b.createContext(null);function Bs(){return b.useContext(li)}function ci({step:e,conns:t,failed:s=!1,readOnly:r,open:o,onOpenChange:i,anchorRef:a,onChangeConnection:l,onChangeConnectionRef:u,onConnectionCreated:c}){var C,$,M;const d=Bs(),f=r||(d==null?void 0:d.readOnly),p=(d==null?void 0:d.connections)??{},h=(d==null?void 0:d.nodes)??[],m=(t??[]).map(k=>({conn:k,users:cn(e.uses.app,k.id,h,p)})).sort((k,T)=>+(T.users.length>0)-+(k.users.length>0)),w=Rt(e,p)??(e.uses.connectionRef===void 0?(C=t==null?void 0:t.find(k=>k.builtIn&&k.appId===e.uses.app))==null?void 0:C.id:void 0),x=cn(e.uses.app,w,h,p).filter(k=>k.id!==e.id),[g,y]=b.useState(null),[A,R]=b.useState(!1),S=g||A?((M=($=a.current)==null?void 0:$.closest("dialog"))==null?void 0:M.parentElement)??document.body:null,v=(k,T)=>{if(!f){if(T&&d&&w){d.setConnections(Uc(e.uses.app,w,k,h,p));const I=h.find(F=>F.id===e.id)??e;I.uses.connectionRef?u(I.uses.connectionRef):l(k)}else{const I=cn(e.uses.app,k,h,p).filter(q=>q.id!==e.id&&q.uses.connectionRef).at(-1),F=Object.entries(p).find(([,q])=>q.app===e.uses.app&&q.connection===k);I!=null&&I.uses.connectionRef?u(I.uses.connectionRef):F?u(F[0]):l(k)}y(null),i(!1)}},j=k=>{f||(i(!1),k!==w&&(x.length>0&&h.some(T=>T.id===e.id)?y(k):v(k,!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"Connection","aria-expanded":o,disabled:f||t===null&&!s,onClick:()=>i(!o),children:n.jsx("span",{className:"w6w-conn-label-name",children:t===null&&!s&&!w?"Loading connections…":Hr(w,t,s)})}),o&&n.jsx(ri,{anchorRef:a,onClose:()=>i(!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(p).some(([,k])=>k.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(p).filter(([,k])=>k.app===e.uses.app).map(([k,T])=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f||!T.connection||!(t!=null&&t.some(I=>I.id===T.connection)),"aria-pressed":e.uses.connectionRef===k,"data-connection-ref":k,onClick:()=>{u(k),i(!1)},children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:k}),n.jsx("span",{className:"w6w-muted w6w-small",children:Hr(T.connection??void 0,t,s)})]})},k))})]}),n.jsx("div",{className:"w6w-stepbuilder-list",children:m.map(({conn:k,users:T})=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f,"aria-pressed":k.id===w,"data-connection-id":k.id,onClick:()=>j(k.id),children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:k.builtIn?"Built-in":k.displayName||k.id}),n.jsx("span",{className:"w6w-muted w6w-small",children:T.length>0?`In use in this workflow · ${T.map(I=>I.id).join(", ")}`:k.builtIn?"Built-in connection":k.state})]})},k.id))}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>{i(!1),R(!0)},children:"+ New connection"})]})}),A&&S&&pn.createPortal(n.jsx(Os,{initialAppId:e.uses.app,onClose:()=>R(!1),onCreated:({connectionId:k})=>{R(!1),c(),j(k)}}),S),g&&S&&pn.createPortal(n.jsxs(ve,{title:"Change connection",onClose:()=>y(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"}),x.map(k=>n.jsx("li",{children:k.id},k.id))]})]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y(null),children:"Cancel"}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:f,onClick:()=>v(g,!0),children:["All ",x.length+1," nodes"]}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>v(g,!1),children:"Only this node"})]})]}),S)]})}function Jc(e,t){return`${e.method}-${e.url??e.host}-${t}`}function ui({calls:e,defaultOpen:t,keyOf:s,title:r}){if(e.length===0)return null;const o=s??Jc;return n.jsxs("div",{className:"w6w-stack",style:{gap:4},children:[r!==!1&&n.jsx("strong",{className:"w6w-small",children:r??n.jsxs(n.Fragment,{children:["API ",e.length===1?"call":"calls"," (",e.length,")"]})}),e.map((i,a)=>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:[i.method," ",i.url??i.host," →"," ",n.jsx("strong",{children:i.error?"failed":i.status}),i.durationMs!==void 0&&n.jsxs("span",{className:"w6w-muted",children:[" · ",i.durationMs,"ms"]})]})}),n.jsxs("div",{className:"w6w-stack",style:{gap:6,marginTop:8},children:[i.error&&n.jsx("div",{className:"w6w-error w6w-small",children:i.error}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Request headers"}),n.jsx(ke,{value:i.requestHeaders??{},maxHeight:240}),i.requestBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Request body"}),n.jsx(ke,{value:i.requestBody,maxHeight:240})]}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Response headers"}),n.jsx(ke,{value:i.responseHeaders??{},maxHeight:240}),i.responseBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Response body"}),n.jsx(ke,{value:i.responseBody,maxHeight:240})]}),i.truncated&&n.jsx("div",{className:"w6w-muted w6w-small",children:"A captured body exceeded the size cap and was truncated."})]})]},o(i,a)))]})}function di({choices:e,onChange:t,readOnly:s}){const r=new Set(e.selected),o=e.options.every(a=>r.has(a.value)),i=[...e.options,...e.selected.filter(a=>!e.options.some(l=>l.value===a)).map(a=>({value:a,label:a}))];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:o,ref:a=>{a&&(a.indeterminate=!o&&r.size>0)},disabled:s,onChange:a=>t(a.target.checked?e.options.map(l=>l.value):[])}),n.jsx("span",{children:"All events"})]}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[r.size," selected"]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":"Eventbrite events",children:i.map(a=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:r.has(a.value),disabled:s,onChange:l=>t(l.target.checked?[...e.selected,a.value]:e.selected.filter(u=>u!==a.value))}),n.jsx("span",{children:a.label})]},a.value))})]}),n.jsx("span",{className:"w6w-hint",children:"Start this workflow when any selected event occurs."})]})}function Rn({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 pi(e,t,s,r){var u;if(e!=="io.w6w.eventbrite")return null;const o=t==null?void 0:t.find(c=>c.key==="activity"),i=(u=o==null?void 0:o.params)==null?void 0:u.find(c=>c.key==="actions"&&c.type==="multiselect");if(!o||!Array.isArray(i==null?void 0:i.options)||!i.options.length)return null;const a=i.options.map(c=>{var p;const d=String(c.value),f=d.replace(/[._]/g,"-");return{value:d,label:((p=t==null?void 0:t.find(h=>h.key===f))==null?void 0:p.title)??c.label,triggerKey:f}}),l=a.find(c=>c.triggerKey===s);return s&&s!==o.key&&!l||s===o.key&&r.actions!=null&&!Array.isArray(r.actions)?null:{triggerKey:o.key,options:a.sort((c,d)=>c.label.localeCompare(d.label)),selected:l?[l.value]:Array.isArray(r.actions)?r.actions.filter(c=>typeof c=="string"):[]}}function Ae(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===Te&&e.uses.action==="foreach"}function fi(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===Te}function as(e){var t,s;return(e==null?void 0:e.uses.app)===We?!0:!fi(e)||(e==null?void 0:e.uses.action)==="if"&&((t=e.with)==null?void 0:t.then)===void 0&&((s=e.with)==null?void 0:s.else)===void 0}function Us(e){if(!fi(e))return[];const t=e.with??{},s=[],r=o=>{if(typeof o=="string")s.push(o);else if(Array.isArray(o))for(const i of o)r(i)};return r(t.body),r(t.branches),r(t.then),r(t.else),s}function Vc(e){const t=new Set;for(const s of e)for(const r of Us(s))t.add(r);return t}function un(e,t,s,r){return{id:dt(e,t,"each",r),source:e,target:t,sourceHandle:r!==void 0?Et(r):s?gn:void 0,animated:!1,data:{when:"each",...r===void 0?{}:{route:r}},...zt("each",void 0)}}const Js=e=>{var t;return typeof((t=e.data)==null?void 0:t.route)=="string"?e.data.route:void 0};function Tn(e,t,s,r){const o=new Set(t.map(m=>m.id)),i=s.filter(m=>we(m)==="each"),a=new Set([e]),l=[],u=[e];for(let m=0;m<u.length;m++)for(const w of i)w.source===u[m]&&(!o.has(w.target)||a.has(w.target)||r!=null&&r.has(w.target)||(a.add(w.target),l.push(w.target),u.push(w.target)));const c=new Map(l.map((m,w)=>[m,w])),d=i.filter(m=>m.source!==e&&c.has(m.source)&&c.has(m.target)),f=new Map(l.map(m=>[m,0]));for(const m of d)f.set(m.target,(f.get(m.target)??0)+1);const p=[],h=new Set;for(;;){const m=l.find(w=>!h.has(w)&&f.get(w)===0);if(m===void 0)break;h.add(m),p.push(m);for(const w of d)w.source===m&&f.set(w.target,(f.get(w.target)??0)-1)}for(const m of l)h.has(m)||p.push(m);return p}function hi(e,t){const s=new Set(e);return t.filter(r=>we(r)==="each"&&s.has(r.source)&&s.has(r.target))}function zc(e,t){const s=hi(e,t),r=new Set;for(const o of s){if(Js(o)!==void 0||r.has(o.source))return!1;r.add(o.source)}return!0}function Kc(e,t){const s=[];for(const r of On(e,t).values())if(!zc(r,t))for(const o of hi(r,t)){const i=Js(o);s.push({from:o.source,to:o.target,...i===void 0?{}:{route:i}})}return s}function On(e,t){var o;const s=new Map,r=new Set;for(const i of e){if(!Ae((o=i.data)==null?void 0:o.step))continue;const a=Tn(i.id,e,t,r);for(const l of a)r.add(l);s.set(i.id,a)}return s}function Ue(e,t){const s={};for(const[r,o]of On(e,t))for(const i of o)s[i]=r;return s}function Gc(e,t,s){const r=f=>f.source===e||f.target===e,o=s.filter(f=>!r(f));if(Ae((f=>{var p,h;return(h=(p=t.find(m=>m.id===f))==null?void 0:p.data)==null?void 0:h.step})(e))){const f=Tn(e,t,s),p=new Set(f);return o.filter(h=>!(we(h)==="each"&&(h.source===e||p.has(h.source))&&p.has(h.target)))}const a=Ue(t,s)[e];if(a===void 0)return o;const l=s.filter(f=>f.target===e&&we(f)==="each"),u=s.filter(f=>f.source===e&&we(f)==="each");if(l.length!==1||u.length!==1)return o;const c=l[0].source,d=u[0].target;return o.some(f=>f.source===c&&f.target===d&&we(f)==="each")?o:[...o,un(c,d,c===a,Js(l[0]))]}function Vs(e){if(!Ae(e)||!e.with||!("body"in e.with))return e;const{body:t,...s}=e.with;return{...e,with:s}}function wi(e,t,s,r,o){const i=Ue(r,o);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 a=c=>{var d,f;return(f=(d=r.find(p=>p.id===c))==null?void 0:d.data)==null?void 0:f.step},l=Ae(a(e))?e:i[e];if(l===void 0)return null;if(t===l)return"loop_cycle";const u=()=>e!==l||!o.some(c=>c.source===e&&we(c)==="each");return i[t]===l?e===l||Yc(t,e,o)?"loop_cycle":u()?null:"body_branch":i[t]!==void 0?"already_in_loop":as(a(t))?u()?o.some(c=>c.source===t||c.target===t)?"body_exit":null:"body_branch":"control_in_body"}function Yc(e,t,s){const r=new Set([e]),o=[e];for(;o.length>0;){const i=o.pop();if(i===t)return!0;for(const a of s)a.source!==i||we(a)!=="each"||r.has(a.target)||(r.add(a.target),o.push(a.target))}return!1}const Xc={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:"A loop body supports plain steps, If conditions and Routers. Nested control blocks aren't supported here yet.",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 Zc(e){return Xc[e]}function Qc(e,t){const s=Ue(e,t);let r=!1;const o=e.map(i=>{const a=s[i.id];if(i.data.loopOf===a)return i;if(r=!0,a===void 0){const{loopOf:l,...u}=i.data;return{...i,data:u}}return{...i,data:{...i.data,loopOf:a}}});return r?o:e}function eu(e,t,s){var a,l;const r=`Delete node "${e}"? Its connections are removed too.`,o=(l=(a=t.find(u=>u.id===e))==null?void 0:a.data)==null?void 0:l.step;if(!Ae(o))return r;const i=Tn(e,t,s);return i.length===0?r:`${r} Its loop body steps ${i.map(u=>`"${u}"`).join(", ")} stay as standalone steps.`}function zs(e){if(e.edges)return e.edges;const t=Vc(e.nodes),s=e.nodes.filter(o=>!t.has(o.id)),r=[];for(let o=0;o<s.length-1;o++)r.push({from:s[o].id,to:s[o+1].id});return r}const dn=e=>(e.when??"success")==="success",Ks=e=>e.route===Kr&&dn(e);function Gs(e){const t=new Map(e.nodes.map(u=>[u.id,u])),s=new Map;for(const u of e.nodes)for(const c of Us(u)){const d=s.get(c)??new Set;d.add(u.id),s.set(c,d)}const r=zs(e),o=e.edges??[],i={};for(const u of e.nodes){if(!Ae(u))continue;const c=u.with??{};if("body"in c){i[u.id]=a(u.id,c.body);continue}i[u.id]=l(u.id)}return i;function a(u,c){const d=(w,x)=>({invalid:x===void 0?{reason:w}:{reason:w,stepId:x}});if(!Array.isArray(c)||c.some(w=>typeof w!="string"))return d("body_not_literal");const f=c,p=new Set(f),h=new Set;for(const w of f){if(!t.has(w))return d("body_unknown_step",w);if(w===u)return d("body_self",w);if(h.has(w))return d("body_duplicate",w);if(h.add(w),!as(t.get(w)))return d("body_contains_control",w);const x=s.get(w);if(x&&[...x].some(g=>g!==u))return d("body_claimed_twice",w)}const m=[];for(const w of o){if(Ks(w)&&w.from===u&&w.to===f[0]||!(p.has(w.from)||p.has(w.to)))continue;if(!(p.has(w.from)&&p.has(w.to)&&dn(w)&&w.to!==f[0]))return d("body_step_has_edges",p.has(w.from)?w.from:w.to);m.push(w)}return m.length>0?{body:f,source:"body",edges:m}:{body:f,source:"body"}}function l(u){var w;const c=r.filter(x=>x.from===u&&dn(x)&&x.route===void 0);if(c.length===0)return{body:[],source:"body"};const d=x=>({invalid:{reason:"legacy_not_linear",stepId:x}});if(c.length>1)return d(u);const f=[],p=new Set([u]);let h=u,m=c[0].to;for(;m!==void 0;){const x=m,g=t.get(x);if(!g||p.has(x)||!as(g)||s.has(x))return d(x);const y=r.filter(R=>R.to===x);if(y.length!==1||y[0].from!==h)return d(x);const A=r.filter(R=>R.from===x);if(A.length>1||A.length===1&&!dn(A[0]))return d(x);p.add(x),f.push(x),h=x,m=(w=A[0])==null?void 0:w.to}return{body:f,source:"legacy"}}}function we(e){var s;const t=(s=e.data)==null?void 0:s.when;return t==="error"?"error":t==="each"?"each":"success"}function mi(e,t){var s;return((s=e.find(r=>r.id===t))==null?void 0:s.id)??null}function bi(e,t,s,r,o,i){var d,f;if(!e||!t||e===t||r.some(p=>{var h;return p.source===e&&p.target===t&&((h=p.data)==null?void 0:h.route)===i}))return!1;const a=(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(!a||!l)return!1;const u=Wt(a,o),c=Wt(l,o);return u.out>=1&&c.in>=1}function Ys(e,t,s,r,o,i,a){var S,v,j;const l=o==="success"&&Ae((S=s.find(C=>C.id===e))==null?void 0:S.data.step),u=l&&a===void 0?jt:a;if(!bi(e,t,s,r,i,u)||!e||!t)return null;const c=(v=s.find(C=>C.id===e))==null?void 0:v.data.step,d=(j=s.find(C=>C.id===t))==null?void 0:j.data.step;if(!c||!d)return null;const f=gs(c);if(l){if(u!==jt)return null}else if(c.uses.app===We&&o==="success"){if(!bs(c).some(C=>C.id===u))return null}else if(f&&o==="success"){if(u!==void 0&&u!==fn)return null}else if(u!==void 0)return null;const p=Ue(s,r)[e]!==void 0,h=o==="success"&&p?"each":o;if(h==="each"&&!p&&!Ae(c))return null;const m=wi(e,t,h,s,r);if(m)return{next:r,conflict:null,refusal:{refused:"loop",reason:m}};const w=Wt(c,i),x=r,g=x.filter(C=>{var $;return C.source===e&&we(C)===h&&(($=C.data)==null?void 0:$.route)===u}),y=u===void 0||f||l?w.out:1;if(g.length>=y)return{next:r,conflict:null,refusal:{refused:"out_cap",cap:y}};const A=dt(e,t,h,u),R=h==="each"&&p?void 0:fs(h);return{next:Jn.addEdge({source:e,target:t,id:A,sourceHandle:u===void 0?R:Et(u),data:{when:h,...u===void 0?{}:{route:u}},...zt(h,void 0)},x),conflict:mi(x,A),refusal:null}}function tu(e,t,s,r,o="success",i,a){const l=Ys(e,t,s,r,o,i,a);return!l||l.conflict||l.refusal?null:l.next}function nu(e,t,s,r,o="success",i,a){var l;return((l=Ys(e,t,s,r,o,i,a))==null?void 0:l.conflict)??null}function su(e,t,s,r,o="success",i,a){var l;return((l=Ys(e,t,s,r,o,i,a))==null?void 0:l.refusal)??null}function Xs(e,t,s,r,o){var y;const i=e.filter(A=>A.id===t);if(i.length!==1)return null;const a=i[0];if(we(a)==="each")return null;const l=(y=r.find(A=>A.id===a.source))==null?void 0:y.data.step;if(!l||l.uses.app===We||l.uses.app===Kt)return null;const u=Wt(l,o).out,c=e.filter(A=>A.id!==t);if((we(a)===s?[]:c.filter(A=>A.source===a.source&&we(A)===s)).length>=u)return{next:e,conflict:null,refusal:{refused:"out_cap",cap:u}};const f=zt(s,void 0),p=Ae(l),h=p&&s==="success"?jt:void 0,{route:m,...w}=a.data??{},x={...a,id:dt(a.source,a.target,s,h),data:p?{...w,when:s,...h?{route:h}:{}}:{...a.data,when:s},className:f.className,label:f.label,sourceHandle:h?Et(h):fs(s)},g=mi(c,x.id);return{next:e.map(A=>A.id===t?x:A),conflict:g,refusal:null}}function ru(e,t,s,r,o){const i=Xs(e,t,s,r,o);return!i||i.conflict||i.refusal?null:i.next}function ou(e,t,s,r,o){var i;return((i=Xs(e,t,s,r,o))==null?void 0:i.conflict)??null}function iu(e,t,s,r,o){var i;return((i=Xs(e,t,s,r,o))==null?void 0:i.refusal)??null}function au(e,t,s){return e.map(r=>{var a;const o=r.source===t?s:r.source,i=r.target===t?s:r.target;return{...r,source:o,target:i,id:dt(o,i,we(r),typeof((a=r.data)==null?void 0:a.route)=="string"?r.data.route:void 0)}})}function dt(e,t,s,r){const o=s==="error"?`${e}->${t}:error`:`${e}->${t}`;return r===void 0?o:`${o}:route:${encodeURIComponent(r)}`}function lu(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function gi(e,t){const s=lu(e);if(s)return s;for(const r of t)if(r===e)return`A step named "${e}" already exists.`;return null}function cu(e,t,s){const r=(f,p)=>!f||!p?void 0:dt(f,p)===t?"success":dt(f,p,"error")===t?"error":void 0,o=r(s[0],s[1]),i=r(s[2],s[3]),a=o!==void 0&&o===i,l=o!==void 0&&i!==void 0&&o!==i,u=o==="success"?s[1]:s[3],c=a?s.find(f=>!!f&&f.includes("->")):l&&(u!=null&&u.endsWith(":error"))?u:void 0,d=c===void 0?"Rename one of the steps it connects, then try again.":a?`A step id containing “->” collides with the edge-id separator, so two different edges mint one id — rename the step “${c}”, 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 “${c}”, then try again.`;return`${e}: the id “${t}” is already taken by another edge. ${d}`}const uu=240,du=100,pu=40,fu=40;function Zs(e,t){return{x:pu+e*uu,y:fu+t*du}}function hu(e,t){var l;const s=new Map,r=new Map;for(const u of e)s.set(u.id,0),r.set(u.id,[]);for(const u of t)(l=r.get(u.to))==null||l.push(u.from);const o=e.length+1;let i=0,a=!0;for(;a&&i<o;){i++,a=!1;for(const u of e){const c=r.get(u.id)??[];if(c.length===0)continue;const d=c.reduce((f,p)=>Math.max(f,(s.get(p)??0)+1),0);(s.get(u.id)??0)<d&&(s.set(u.id,d),a=!0)}}if(a){const u=Math.max(0,e.length-1);for(const[c,d]of s)d>u&&s.set(c,u)}return s}function yi(e,t){var u;const s=hu(e,t),r=new Map(e.map((c,d)=>[c.id,d])),o=new Map;for(const{from:c,to:d}of t){const f=s.get(c),p=s.get(d);if(f===void 0||p===void 0||f>=p)continue;const h=o.get(d);(h===void 0||f<(s.get(h)??0)||f===s.get(h)&&(r.get(c)??0)<(r.get(h)??0))&&o.set(d,c)}const i=new Map(e.map(c=>[c.id,[]]));for(const[c,d]of o)(u=i.get(d))==null||u.push(c);for(const c of i.values())c.sort((d,f)=>(s.get(f)??0)-(s.get(d)??0)||(r.get(d)??0)-(r.get(f)??0));const a=new Map;let l=0;for(const c of e.filter(d=>!o.has(d.id))){const d=[c.id];for(;d.length;){const f=d.pop();if(f===void 0)continue;a.set(f,Zs(s.get(f)??0,l));const p=i.get(f)??[];if(p.length===0)l++;else for(let h=p.length-1;h>=0;h--)d.push(p[h])}}return a}function wu(e){const t=e.position;if(!(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function Qs(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,...r}=e;return{...r,nodes:t.nodes??t.steps??[]}}function mu(e){const t=Qs(e),s=t.nodes;let r=zs(t);const o=[],i=new Map,a=new Set,l=new Set;for(const[h,m]of Object.entries(Gs(t))){if("invalid"in m)continue;let w=h;if(m.edges&&m.body.length>0){o.push(un(h,m.body[0],!0));for(const x of m.edges)l.add(x),o.push(un(x.from,x.to,!1,x.route));for(const x of m.body)i.set(x,h);continue}for(const x of m.body){if(m.source==="legacy"){const g=r.find(y=>y.from===w&&y.to===x&&(y.when??"success")==="success");g&&l.add(g)}o.push(un(w,x,w===h)),i.set(x,h),w=x}m.source==="legacy"&&a.add(h)}const u=new Set(s.filter(Ae).map(h=>h.id));for(const h of r)u.has(h.from)&&Ks(h)&&l.add(h);l.size>0&&(r=r.filter(h=>!l.has(h)));const c=yi(s,[...r,...o.map(h=>({from:h.source,to:h.target}))]),d=s.map(h=>{const m=Ze(h.uses.app);return{id:h.id,type:m?"control":"step",position:wu(h)??c.get(h.id)??Zs(0,0),data:{step:h,isInternal:m,...i.has(h.id)?{loopOf:i.get(h.id)}:{},...a.has(h.id)?{legacyLoop:!0}:{}}}}),f=new Set(s.filter(gs).map(h=>h.id)),p=r.map(h=>{const m=h.when==="error"&&h.route===void 0&&f.has(h.from)?{from:h.from,to:h.to,route:fn}:u.has(h.from)&&h.route===void 0&&h.when!=="error"?{...h,route:jt}:h,w=m.when??"success";return{id:dt(m.from,m.to,w,m.route),source:m.from,target:m.to,sourceHandle:m.route===void 0?fs(w):`route:${m.route}`,animated:!1,data:{when:w,...m.route===void 0?{}:{route:m.route}},...zt(w,void 0)}});return{nodes:d,edges:[...p,...o]}}function bu(e,t){const s=e.map(o=>({...o.data.step,id:o.id})),r=yi(s,t.map(o=>({from:o.source,to:o.target})));return e.map(o=>({...o,position:r.get(o.id)??Zs(0,0)}))}function gu(e,t,s){var S,v;const r=Qs(e),o=((S=r.settings)==null?void 0:S.savePosition)!==!1,i=new Map(t.map(j=>[j.id,j])),a=j=>{var $;if(!o)return j;const C=($=i.get(j.id))==null?void 0:$.position;return!C||!Number.isFinite(C.x)||!Number.isFinite(C.y)?j:{...j,position:{x:Math.round(C.x),y:Math.round(C.y)}}},l=new Map;for(const j of r.nodes)l.set(j.id,j);for(const j of t)(v=j.data)!=null&&v.step&&l.set(j.id,j.data.step);const u=On(t,s),c=Gs(r),d=new Map(r.nodes.map(j=>[j.id,j])),f=new Set;for(const j of s)we(j)==="success"&&f.add(j.source);const p=j=>{if(!Ae(j))return j;const C=u.get(j.id)??[],$=d.get(j.id),M=c[j.id];let k;C.length>0?k={value:C}:M&&"invalid"in M&&M.invalid.reason!=="legacy_not_linear"?k=$!=null&&$.with&&"body"in $.with?{value:$.with.body}:null:M&&"invalid"in M?k=null:f.has(j.id)||$!=null&&$.with&&"body"in $.with?k={value:[]}:k=null;const T=j.with??{};return k===null?"body"in T?Vs(j):j:{...j,with:{...T,body:k.value}}},h=j=>a(p(j)),m=[],w=new Set;for(const j of r.nodes){const C=l.get(j.id);C&&t.some($=>$.id===j.id)&&(m.push(h(C)),w.add(j.id))}for(const j of t){if(w.has(j.id))continue;const C=l.get(j.id);C&&m.push(h(C))}const x=new Set;for(const j of u.values())for(const C of j)x.add(C);const g=new Set(t.filter(j=>{var C;return Ae((C=j.data)==null?void 0:C.step)}).map(j=>j.id)),y=s.filter(j=>we(j)!=="each"&&!x.has(j.source)&&!x.has(j.target)).map(j=>{var $;const C=typeof(($=j.data)==null?void 0:$.route)=="string"?j.data.route:g.has(j.source)&&we(j)==="success"?jt:void 0;return{from:j.source,to:j.target,...we(j)==="error"?{when:"error"}:{},...C===void 0?{}:{route:C}}}),A=[];for(const[j,C]of u)C.length>0&&A.push({from:j,to:C[0],route:Kr});const R=[...y,...A,...Kc(t,s)];return ii({...r,nodes:m,edges:R})}function xi(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 yu(e,t){var a;if(!(((a=e.settings)==null?void 0:a.savePosition)!==!1)||!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(t.zoom))return e;const r={x:Math.round(t.x),y:Math.round(t.y),zoom:Math.round(t.zoom*1e3)/1e3},o=xi(e);if(o&&o.x===r.x&&o.y===r.y&&o.zoom===r.zoom)return e;const i=typeof e.settings=="object"&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:void 0;return{...e,settings:{...i,viewport:r}}}function xu(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function vu(e,t){const s=new Set(t.map(r=>r.target));return e.find(r=>!s.has(r.id))}function ju(e,t){const s=new Set(t.map(r=>r.source));for(let r=e.length-1;r>=0;r--)if(!s.has(e[r].id))return e[r]}function Nu(e,t="step"){const s=new Set(e);for(let r=1;r<1e3;r++){const o=`${t}_${r}`;if(!s.has(o))return o}return`${t}_${crypto.randomUUID().slice(0,8)}`}function er(e){return JSON.stringify(Vs(e),null,2)}const ku=3,Su=100;function pt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function vi(e){if(!Array.isArray(e))return;const t=[],s=new Set,r=o=>{s.has(o.key)||(s.add(o.key),t.push(o))};for(const o of e){if(!pt(o)||typeof o.key!="string"||o.key==="")continue;const i=typeof o.label=="string"&&o.label!==""?o.label:void 0;if(r({key:o.key,...i?{label:i}:{},path:!0}),o.type==="array"&&Array.isArray(o.items))for(const a of o.items){if(!pt(a)||typeof a.key!="string"||a.key==="")continue;const l=typeof a.label=="string"&&a.label!==""?a.label:void 0;r({key:`${o.key}.0.${a.key}`,...l?{label:l}:{},path:!0})}}return t.length>0?t:void 0}function Cu(e,t){var r;if(!Array.isArray(e))return;const s=e.find(o=>pt(o)&&o.key===t);if(!(!pt(s)||!Array.isArray(s.items)))return(r=vi([{key:t,type:"array",items:s.items}]))==null?void 0:r.filter(o=>o.key!==t).map(o=>({...o,key:o.key.slice(t.length+3)}))}function lt(e){if(!pt(e))return;const t=[],s=(r,o,i)=>{for(const[a,l]of Object.entries(r)){if(t.length>=Su)return;const u=o?`${o}.${a}`:a;t.push({key:u,path:!0}),pt(l)&&i<ku&&s(l,u,i+1)}};return s(e,"",1),t.length>0?t:void 0}function Lt(e,t){let s=e;for(const r of t.split(".")){if(!pt(s)||!(r in s))return;s=s[r]}return s}function xt(e,t,s){const r=vi(e==null?void 0:e.output),o=lt(t),i=o??lt(s);if(i){const l=new Map((r??[]).map(d=>[d.key,d])),u=new Set(i.map(d=>d.key)),c=i.map(d=>{const f=l.get(d.key);return f!=null&&f.label?{...d,label:f.label}:d});for(const d of r??[])u.has(d.key)||c.push({...d,declaredOnly:!0});return{fields:c,from:o?"fresh":"persisted"}}if(r)return{fields:r,from:"declared"};const a=lt(e==null?void 0:e.sample);if(a)return{fields:a,from:"sample"}}function tr(e,t){const s=new Map;for(const i of t){const a=s.get(i.target)??[];a.push(i.source),s.set(i.target,a)}const r=new Set,o=[e];for(;o.length;){const i=o.pop();for(const a of s.get(i)??[])r.has(a)||(r.add(a),o.push(a))}return r}function ji(e,t,s={}){var a,l,u,c,d,f,p;const r=[];let o=!1,i;for(const h of t){if(!e.has(h.id))continue;const m=h.data.step;if(m.uses.app===ms)continue;const w=((a=ct(m.uses.app,m.uses.action))==null?void 0:a.group)==="trigger",x=(l=s.testOutputs)==null?void 0:l[m.id],g=(u=s.persistedOutputs)==null?void 0:u[m.id];if(m.uses.trigger===!0){o=!0;const C=xt((c=s.triggerDef)==null?void 0:c.call(s,m.uses.app,m.uses.action),x,g);if(i??(i=C),C&&(C.from==="fresh"||C.from==="persisted")){r.push({id:m.id,label:m.id,outputs:C.fields,outputsFrom:C.from});continue}}w&&(o=!0);const y=w&&m.uses.app===At,A=y?Hs(Ls((d=m.with)==null?void 0:d.fields)).map(C=>({key:C.key,label:C.label})):((f=ct(m.uses.app,m.uses.action))==null?void 0:f.output)??[],R={id:m.id,label:m.id};if(A.length>0){r.push({...R,outputs:A});continue}if(w){const C=xt(void 0,x,g);C&&!y&&(i??(i=C)),r.push(C?{...R,outputs:C.fields,outputsFrom:C.from}:R);continue}if(Ze(m.uses.app)){const C=xt(void 0,x,g);r.push(C?{...R,outputs:C.fields,outputsFrom:C.from}:R);continue}const S=(p=s.actionDef)==null?void 0:p.call(s,m.uses.app,m.uses.action),v=xt(S,x,g),j=m.uses.app.trim()!==""?{hasMeta:!0}:{};v?r.push({...R,outputs:v.fields,outputsFrom:v.from,...j}):r.push(S?{...R,needsTest:!0,...j}:{...R,...j})}return{steps:r,hasTrigger:o,...i?{eventOutputs:i.fields,eventOutputsFrom:i.from}:{}}}function Au(e,t){const s={};for(const[r,o]of Object.entries(t))s[r]={output:o};return Ni(e,{steps:s})}function Ni(e,t){if(nt(e)!==null){const s=Cs(e,Ns(void 0,t)),r=s.length===1?s[0]:void 0;return(r==null?void 0:r.status)==="resolved"&&Array.isArray(r.value)?r.value:void 0}return Array.isArray(e)?e:void 0}const Eu=10;function Ru(e,t){return{input:t,with:{items:e.slice(0,Eu),itemCount:e.length}}}function Tu(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,r,o={}){const i=Ue(s,r),a=new Set;for(const f of e){if(f===t)continue;const p=i[f];p!==void 0&&p!==t||a.add(f)}const l=ji(a,s,o),u=On(s,r),c=[];return{steps:l.steps.map(f=>{var y,A,R;const p=u.get(f.id);if(!p||p.length===0)return f;const h=p[p.length-1],m=(y=s.find(S=>S.id===h))==null?void 0:y.data.step,w=o.testOutputs??{},x=m?xt((A=o.actionDef)==null?void 0:A.call(o,m.uses.app,m.uses.action),w[h],(R=o.persistedOutputs)==null?void 0:R[h]):void 0;c.includes(h)||c.push(h);const g=((x==null?void 0:x.fields)??[]).map(S=>({key:`items.0.${S.key}`,path:!0,...S.declaredOnly?{declaredOnly:!0}:{}}));return{id:f.id,label:f.label,outputs:[{key:"items",path:!0},...g],...x?{outputsFrom:x.from}:{}}}),hasTrigger:l.hasTrigger,extraSampleIds:c,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{}}}function Ou(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 Iu(e,t,s){var f,p;const r=nt(e),o=r?Ou(r):void 0,i=o?(f=t.find(h=>h.id===o.id))==null?void 0:f.data.step:void 0;if(!o||!i)return;const a=(p=s.actionDef)==null?void 0:p.call(s,i.uses.app,i.uses.action),l=Lt(a==null?void 0:a.sample,o.path),u=Array.isArray(l)&&l.length>0?l[0]:void 0,d=Cu(a==null?void 0:a.output,o.path)??lt(u);if(!(u===void 0&&!d))return{...u!==void 0?{itemSample:u}:{},...d?{itemOutputs:d}:{}}}function Si(e,t,s={}){var c,d,f;const r={foreachId:e},o=(d=(c=t.find(p=>p.id===e))==null?void 0:c.data.step.with)==null?void 0:d.items,i={...s.persistedOutputs??{},...s.testOutputs??{}},a=Au(o,i),l=a&&a.length>0?a:(f=s.loopSamples)==null?void 0:f[e];if(l&&l.length>0){r.itemSample=l[0];const p=lt(l[0]);return p&&(r.itemOutputs=p),r}const u=Iu(o,t,s);return(u==null?void 0:u.itemSample)!==void 0&&(r.itemSample=u.itemSample),u!=null&&u.itemOutputs&&(r.itemOutputs=u.itemOutputs),r}function Ci(e,t,s,r){return!e&&!!t&&!r.some(o=>o.target===t)&&Ue(s,r)[t]===void 0}function $u(e,t,s,r,o){let i=e;if(!i&&o&&!Ci(e,o,t,s)&&(i=o),!i)return ji(new Set(t.map(u=>u.id)),t,r);const a=Ue(t,s)[i],l=ki(tr(i,s),a,t,s,r);return a&&!l.extraSampleIds.includes(a)&&l.extraSampleIds.push(a),{steps:l.steps,hasTrigger:l.hasTrigger,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{},...a?{loop:Si(a,t,r)}:{},...l.extraSampleIds.length>0?{extraSampleIds:l.extraSampleIds}:{}}}function Pu(e,t,s,r){if(!e||e.handleType==="target")return[];const o=tr(e.nodeId,s);o.add(e.nodeId);const i=Ai(e,t,s);return ki(o,i,t,s,r).steps}function Ai(e,t,s){const r=t.find(o=>o.id===e.nodeId);return e.lane==="each"&&Ae(r==null?void 0:r.data.step)?e.nodeId:Ue(t,s)[e.nodeId]}function _u(e,t,s,r){if(!e||e.handleType==="target")return;const o=Ai(e,t,s);return o?Si(o,t,r):void 0}async function Fu(e,t){return(await Promise.all(t.map(async r=>{try{const o=await e(r.id),i=o.length?o[o.length-1]:null;return i?{stepId:r.id,label:r.label??r.id,test:i}:null}catch{return null}}))).filter(r=>r!==null)}function nr(e,t,s){const r=Lu(e,t);return!s||Object.keys(s).length===0?r:{...r??{},state:s}}function Lu(e,t){const s={};for(const o of e){const i=o.test.lastRunOutput,a=i!=null;if(!a&&o.test.lastRunStatus!=="succeeded")continue;const l=o.test.lastRunMeta;s[o.stepId]={output:a?i:null,...l?{meta:l}:{}}}const r=Object.keys(s).length>0;return t?{...r?{steps:s}:{},foreach:{...t.item!==void 0?{item:t.item}:{},index:t.index??0}}:r?{steps:s}:void 0}function Ei(e){if(e)return{..."itemSample"in e?{item:e.itemSample}:{},index:0}}function Mu(e){return!e||!("itemSample"in e)?"":JSON.stringify(e.itemSample,null,2)??""}function Du(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 r=t.trim()===""?0:Number(t.trim());return!Number.isInteger(r)||r<0?{ok:!1,error:"The index must be a whole number, 0 or more."}:{ok:!0,value:{...s!==void 0?{item:s}:{},index:r}}}function Hu(e,t){if(!t)return{};const s={};for(const r of["nodes","steps"]){const o=`${r}.${e}.meta`;s[`${o}.app`]=t.app,s[`${o}.version`]=t.version,s[`${o}.action`]=t.action,s[`${o}.connectionId`]=t.connectionId}return s}function Wu(e,t,s,r,o){return Ri(e,t,s,r,o).values}function qu(e,t,s,r,o){return Ri(e,t,s,r,o).sources}function Bu(e,t){var o,i,a,l;const s={};let r;for(const u of e){const c=u.data.step.uses;if(c.trigger===!0){const f=(i=(o=t.triggerDef)==null?void 0:o.call(t,c.app,c.action))==null?void 0:i.sample;r===void 0&&f!==void 0&&(r=f);continue}if(Ze(c.app))continue;const d=(l=(a=t.actionDef)==null?void 0:a.call(t,c.app,c.action))==null?void 0:l.sample;d!==void 0&&(s[u.id]=d)}return{samples:s,...r!==void 0?{event:r}:{}}}function Ri(e,t,s,r,o={}){var l,u;const i={},a={};for(const c of e){Object.assign(i,Hu(c.id,s[c.id]));const d=[["sample",(l=o.samples)==null?void 0:l[c.id]],["persisted",(u=o.persisted)==null?void 0:u[c.id]],["fresh",t[c.id]]];for(const[f,p]of d){if(p===void 0)continue;const h=(m,w)=>{for(const x of["nodes","steps"])i[`${x}.${m}`]=w,a[`${x}.${m}`]=f};if(h(`${c.id}.output`,p),typeof p=="object"&&p!==null&&!Array.isArray(p))for(const[m,w]of Object.entries(p))h(`${c.id}.output.${m}`,w);for(const m of c.outputs??[]){if(!m.path||!m.key.includes("."))continue;const w=Lt(p,m.key);w!==void 0&&h(`${c.id}.output.${m.key}`,w)}}}if(o.event!==void 0){const c=(d,f)=>{i[d]=f,a[d]="sample"};if(c("trigger.event",o.event),typeof o.event=="object"&&o.event!==null&&!Array.isArray(o.event))for(const[d,f]of Object.entries(o.event))c(`trigger.event.${d}`,f);for(const d of lt(o.event)??[]){const f=Lt(o.event,d.key);f!==void 0&&c(`trigger.event.${d.key}`,f)}}if(r&&"itemSample"in r){i["foreach.item"]=r.itemSample;for(const c of r.itemOutputs??[]){const d=Lt(r.itemSample,c.key);d!==void 0&&(i[`foreach.item.${c.key}`]=d)}i["foreach.index"]=0}return{values:i,sources:a}}function Uu(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 Ju(e){const t=[];for(const s of e){const r=s.data.step,o=Object.entries(r.with??{}).filter(([,a])=>a!==void 0&&!Uu(a)).map(([a])=>a);(r.uses.app===_e||r.uses.trigger===!0)&&!o.includes("url")&&o.unshift("url"),o.length>0&&t.push({id:r.id,keys:o})}return t}function ls(e){if(!(qe(e)||tt(e))){if(Array.isArray(e))return e.map(ls).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 r={};for(const[o,i]of Object.entries(t)){const a=ls(i);a!==void 0&&(r[o]=a)}return r}return e}}function Vu(e,t){const s={};for(const r of e){const o=r.data.step,i={...ls(o.with??{})??{}},a=Ti(o,t);a!=null&&a.webhookUrl&&(i.url=a.webhookUrl),Object.keys(i).length>0&&(s[o.id]=i)}return s}function Ti(e,t){if(!(e.uses.app!==_e&&e.uses.trigger!==!0))return t.find(s=>s.nodeId===e.id)??(e.uses.app===_e?t.find(s=>s.appId===_e):void 0)}function zu(e,t,s,r){var i;const o={};for(const a of e){const l=a.data.step;if(!l.uses.app)continue;const u={app:l.uses.app,action:l.uses.action,connectionId:Rt(l,r)??null},c=(i=s==null?void 0:s.get(l.uses.app))==null?void 0:i.version;c&&(u.version=c);const d=Ti(l,t);d&&(u.subscriptionId=d.id),d!=null&&d.webhookUrl&&(u.url=d.webhookUrl),o[l.id]=u}return o}function Ku(e){const t={};for(const[s,r]of Object.entries(e))for(const[o,i]of Object.entries(r))t[`nodes.${s}.meta.${o}`]=i,t[`steps.${s}.meta.${o}`]=i;return t}function sr(e,t,s){const r=ye(),[o,i]=b.useState([]),a=JSON.stringify(t.map(l=>[l.id,l.label]));return b.useEffect(()=>{const l=JSON.parse(a);if(!s||l.length===0){i([]);return}let u=!1;return Fu(c=>r.listStepTests(e,c),l.map(([c,d])=>({id:c,label:d}))).then(c=>{u||i(c)}),()=>{u=!0}},[r,e,a,s]),o}function Oi(e){return(e.nodes??e.steps??[]).filter(t=>t.uses.app===At&&t.uses.action==="manual")}function Gu(e,t){var i;const s=Oi(e),r=t?s.find(a=>a.id===t):s[0],o=(i=r==null?void 0:r.with)==null?void 0:i.fields;return Array.isArray(o)?o.flatMap(a=>!a||typeof a!="object"||typeof a.key!="string"||!a.key.trim()?[]:[{key:a.key,label:a.key,type:Ms(a.type),default:Ds(a.type,a.default),required:!!a.required}]):[]}const Yu=["function","workflow"],Xu={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"/>'},qn={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},Zu=["props","code","params-code","config"];function In({view:e,onChange:t,disabled:s,views:r=Zu,customized:o=!1}){const i=a=>n.jsx("button",{type:"button",title:qn[a].label,"aria-label":qn[a].label,"aria-pressed":e===a,disabled:s,className:`w6w-icon-btn${e===a&&!s?" active":""}`,onClick:()=>t(a),children:n.jsx(ae.Icon,{name:qn[a].icon,size:15})},a);return n.jsxs("div",{className:"w6w-view-toggle",children:[o&&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"}),r.map(i)]})}function Qu({onClose:e,onDone:t,onAdd:s,onDraftChange:r,theme:o,appsOnly:i,callables:a=Yu,initialTab:l,title:u,workflowId:c,stepId:d,upstreamSteps:f=[],loop:p,initialApp:h,initialAction:m,initialConnection:w,initialWith:x,appsFilter:g,appsIds:y,connectionOnly:A,onConnected:R,excludeCallableIds:S,onOpenStep:v,stepIds:j=[]}){const[C,$]=b.useState(null),[M,k]=b.useState(null),T=b.useRef(null),I=H=>{const ie=s(H);return typeof ie=="string"&&(T.current=H,$(ie),k(null)),ie},F=r?(H,ie)=>{T.current=ie,r(H,ie)}:void 0,q=()=>{C&&M&&M!==C&&F&&T.current&&F(C,{...T.current,id:M}),(t??e)()},z=H=>C&&r?n.jsxs("span",{className:"w6w-stepbuilder-title",children:[H,n.jsx(Mo,{value:M??C,onCommit:ie=>{const pe=gi(ie,j.filter(ue=>ue!==C));return pe||k(ie),pe}})]}):H,[W,P]=b.useState(l??"connected"),[O,Z]=b.useState(""),[Q,re]=b.useState(h??null),[_,Y]=b.useState(null),[X,B]=b.useState(null),[G,te]=b.useState(null),E=!!y&&y.length>0,J=_i(a,g,S,y),ee=J.state!=="empty";if(b.useEffect(()=>{!ee&&W==="connected"&&P("apps")},[ee,W]),G)return n.jsx(ve,{title:z(G.label),ariaLabel:G.label,subtitle:n.jsx("code",{children:G.id}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>te(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(od,{family:G.family,targetId:G.id,targetLabel:G.label,onAdd:I,onClose:e,onDone:q,onDraftChange:F})})});if(_)return n.jsx(ve,{title:z(_.groupActions?_.displayName:_.label),ariaLabel:_.groupActions?_.displayName:_.label,titleIcon:n.jsx(Rn,{icon:_.icon,size:22}),subtitle:n.jsxs("code",{children:[_.app,!_.groupActions&&` · ${_.action}`]}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>Y(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(rd,{node:_,onAdd:I,onClose:e,onDone:q,onDraftChange:F,onOpenStep:v,workflowId:c,upstreamSteps:f,loop:p})})});const L=X??Q;if(L){const H=X?"trigger":"action",ie=()=>{re(null),B(null)};return n.jsx(ve,{title:z(L.displayName),ariaLabel:L.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:L.id}),L.version&&` · v${L.version}`]}),onClose:e,size:"xl",titleIcon:n.jsx(ht,{src:L.iconSvg,srcDark:L.iconSvgDark,brandColor:L.brandColor,name:L.displayName,theme:o,size:22}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:A&&H==="action"?n.jsx(hd,{appId:L.id,app:L,onClose:e,onChangeApp:ie,theme:o,initialConnection:w,onConnected:(pe,ue)=>R==null?void 0:R(pe,ue)}):n.jsx(fd,{kind:H,onOpenStep:v,appId:L.id,app:L,onAdd:I,onClose:e,onDone:q,onDraftChange:F,onChangeApp:ie,theme:o,workflowId:c,stepId:d,upstreamSteps:f,loop:p,...H==="action"?{initialAction:m,initialConnection:w,initialWith:x}:{}})})})}return n.jsx(ve,{title:u??"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 this tab…",value:O,onChange:H=>Z(H.target.value)}),n.jsxs("div",{className:"w6w-stepbuilder",children:[n.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[ee&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="connected"?" active":""}`,onClick:()=>P("connected"),children:"Ready to use"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="apps"?" active":""}`,onClick:()=>P("apps"),children:"Apps"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="ai"?" active":""}`,onClick:()=>P("ai"),children:"AI"}),a.includes("workflow")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="workflows"?" active":""}`,onClick:()=>P("workflows"),children:"Workflows"}),a.includes("function")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="functions"?" active":""}`,onClick:()=>P("functions"),children:"Functions"}),!i&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="triggers"?" active":""}`,onClick:()=>P("triggers"),children:"Triggers"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="controls"?" active":""}`,onClick:()=>P("controls"),children:"Controls"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="utilities"?" active":""}`,onClick:()=>P("utilities"),children:"Utilities"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${W==="data"?" active":""}`,onClick:()=>P("data"),children:"Data"})]})]}),n.jsx("div",{className:"w6w-stepbuilder-content",children:W==="connected"?n.jsx(pd,{data:J,query:O,appsFilter:g,onSelectApp:re,onSelectCallable:te,theme:o}):W==="functions"?n.jsx(qr,{family:"function",query:O,excludeIds:S,onSelect:H=>te({family:"function",...H})}):W==="workflows"?n.jsx(qr,{family:"workflow",query:O,excludeIds:S,onSelect:H=>te({family:"workflow",...H})}):W==="apps"?n.jsx(ut,{search:!1,searchValue:O,onSelectApp:re,theme:o,filter:g,ids:y}):W==="ai"?n.jsx(ut,{search:!1,searchValue:O,onSelectApp:re,theme:o,category:E?void 0:"ai",ids:y,filter:H=>{var ie;return((g==null?void 0:g(H))??!0)&&(E||(((ie=H.categories)==null?void 0:ie.includes("ai"))??!1))},emptyMessage:"No AI apps registered yet."}):W==="triggers"?n.jsx(ed,{query:O,onSelect:Y,onSelectApp:B,theme:o,appsFilter:g,appsIds:y}):W==="controls"?n.jsx(td,{query:O,onSelect:Y}):W==="data"?n.jsx(sd,{query:O,onSelect:Y}):n.jsx(nd,{query:O,onSelect:Y})})]})]})})}function Mt(e,...t){const s=t.filter(Boolean).join(" ").toLowerCase();return e.trim().toLowerCase().split(/\s+/).every(r=>s.includes(r))}function Ii(e,t){return Mt(t,e.label,e.displayName,e.app,e.action)}function rr({nodes:e,onSelect:t,query:s}){const r=new Set,o=e.filter(i=>Ii(i,s)?i.groupActions?r.has(i.app)?!1:(r.add(i.app),!0):!0:!1);return o.length?n.jsx("div",{className:"w6w-stepbuilder-list",children:o.map(i=>n.jsx($i,{node:i,onSelect:t},`${i.app}:${i.action}`))}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No nodes match “",s,"”."]})}function $i({node:e,onSelect:t}){return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>t(e),children:[n.jsx(Rn,{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 ed({query:e,onSelect:t,onSelectApp:s,theme:r,appsFilter:o,appsIds:i}){var m;const a=ye(),l=ft.filter(w=>w.group==="trigger"&&Ii(w,e)),[u,c]=b.useState(!1),d=_i([],o,void 0,i,{resolveInline:!0});if(u)return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>c(!1),children:"← Back"}),n.jsx(ut,{onSelectApp:s,theme:r,filter:o,ids:i?[...i]:void 0,hasTriggers:!0,search:!1,searchValue:e,emptyMessage:"No apps declare triggers yet."})]});const p=d.apps.filter(w=>(w.triggerCount??0)>0&&Mt(e,w.displayName,w.id)).sort(Dt(w=>w.displayName)).map(w=>n.jsx(Fi,{app:w,theme:r,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 h;return d.state==="error"?h=n.jsx("div",{className:"w6w-result w6w-error",children:d.error}):d.state==="loading"?h=n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):e.trim()&&((m=d.appIds)!=null&&m.length)&&typeof a.listAppsPage=="function"?h=n.jsx(ut,{search:!1,searchValue:e,ids:d.appIds,hasTriggers:!0,filter:o,onSelectApp:s,theme:r}):p.length===0?h=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:()=>c(!0),children:"Search all apps"})]}):h=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"}),h]}),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($i,{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:()=>c(!0),children:"Search all apps"})})]})}function td({onSelect:e,query:t}){const s=ft.filter(r=>r.group==="control"&&!r.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(rr,{nodes:s,onSelect:e,query:t})]})}function nd({onSelect:e,query:t}){const s=ft.filter(r=>r.group!=="control"&&r.group!=="trigger"&&r.app!==Ht&&r.app!==ws&&r.app!==De&&!r.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(rr,{nodes:s,onSelect:e,query:t})]})}function sd({onSelect:e,query:t}){const s=ft.filter(r=>(r.app===Ht||r.app===De||r.app===ws)&&!r.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(rr,{nodes:s,onSelect:e,query:t})]})}function rd({node:e,onAdd:t,onClose:s,onDone:r,onDraftChange:o,onOpenStep:i,workflowId:a,upstreamSteps:l=[],loop:u}){var W;const[c,d]=b.useState(e),f=e.groupActions?ft.filter(P=>P.app===e.app&&!P.hidden):[],[p,h]=b.useState(()=>wn(c.app,c.action)),m=!It(c.app),w=sr(a??"",l,m&&!!a),x=(W=Be().stateShape)==null?void 0:W.written,g=nr(w,Ei(u),x),[y,A]=b.useState("configure"),[R,S]=b.useState("props"),[v,j]=b.useState("{}"),[C,$]=b.useState({}),M=Ct(c.params,p),[k,T]=b.useState(null),I=()=>({uses:{app:c.app,action:c.action},with:p,...C});b.useEffect(()=>{if(!o)return;const P=t(I());P&&T(P),P&&c.app===_e&&(i==null||i(P))},[]),b.useEffect(()=>{!o||k===null||o(k,I())},[k,p,C,c]);const F=P=>{P==="code"&&j(er(I())),S(P)},q=()=>t(I()),z=a&&k!==null?{workflowId:a,stepId:k,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${y==="configure"?" active":""}`,onClick:()=>A("configure"),children:"Configure"}),m&&n.jsx("button",{type:"button",disabled:!M,title:M?void 0:"Fill the required fields first",className:`w6w-subtab${y==="test"?" active":""}`,onClick:()=>M&&A("test"),children:"Test"})]}),n.jsx(In,{view:R,customized:En(p),onChange:F,disabled:y!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[y==="configure"&&R==="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:c.action,onChange:P=>{const O=f.find(Q=>Q.action===P.target.value);if(!O)return;const Z=wn(O.app,O.action);h(Object.fromEntries(O.params.flatMap(Q=>Q.key in p?[[Q.key,p[Q.key]]]:Q.key in Z?[[Q.key,Z[Q.key]]]:[]))),d(O)},children:f.map(P=>n.jsx("option",{value:P.action,children:P.label},P.action))})]}),y==="configure"&&(R==="props"?c.app===Kt?n.jsx("p",{className:"w6w-muted w6w-small",children:Yr}):c.action==="wait"&&It(c.app)?n.jsx(si,{values:p,onChange:h}):c.action==="if"&&It(c.app)?n.jsx(An,{values:p,onChange:h}):c.app===ms?n.jsx(Do,{values:p,onChange:h}):c.app===We?n.jsx(Lo,{values:p,onChange:h}):n.jsx(Ie,{params:c.params,values:p,onChange:h}):R==="code"?n.jsx(He,{value:v,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):R==="params-code"?n.jsx(_s,{values:p,onChange:h}):n.jsx(Ps,{config:C,onChange:$,failureHandling:!hn(c.app),retryControls:!It(c.app)&&c.app!==yn})),y==="test"&&m&&(hn(c.app)?n.jsx(ni,{app:c.app,action:c.action,fields:p.fields,persist:z},(z==null?void 0:z.stepId)??""):n.jsx(or,{app:c.app,action:c.action,values:p,canRun:M,state:g,persist:z},(z==null?void 0:z.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"}),y==="configure"&&m?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!M,onClick:()=>A("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:k!==null?r??s:q,children:k!==null?"Done":"Add node"})]})]})}function qr({family:e,query:t,excludeIds:s,onSelect:r}){const o=ye(),[i,a]=b.useState(null),[l,u]=b.useState(null),c=e==="function"?"Functions":"Workflows";b.useEffect(()=>{let w=!1;return(e==="function"?o.listFunctions():o.listWorkflows()).then(g=>!w&&a(g)).catch(g=>!w&&u(g.message)),()=>{w=!0}},[o,e]);const d=w=>n.jsx("div",{className:"w6w-apppicker-host",children:w});if(l)return d(n.jsx("div",{className:"w6w-result w6w-error",children:l}));if(i===null)return d(n.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",c.toLowerCase(),"…"]}));if(i.length===0)return d(n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",c.toLowerCase()," registered yet."]}));const f=vt,p=t.trim().toLowerCase(),h=cs(i,s).sort(Dt(f)),m=p?h.filter(w=>f(w).toLowerCase().includes(p)||w.id.toLowerCase().includes(p)):h;return d(n.jsx("div",{className:"w6w-stepbuilder-apps",children:m.length===0?n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",c.toLowerCase()," match “",t,"”."]}):n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:m.map(w=>n.jsx(us,{family:e,item:w,onSelect:r},w.id))})}))}function od({family:e,targetId:t,targetLabel:s,onAdd:r,onClose:o,onDone:i,onDraftChange:a}){const[l,u]=b.useState({targetKind:e,targetId:t,inputs:{},wait:!0}),[c,d]=b.useState(!1),[f,p]=b.useState("configure"),[h,m]=b.useState(null),w=()=>({uses:{app:yn,action:"call"},with:l});b.useEffect(()=>{if(!a)return;const g=r(w());g&&m(g)},[]),b.useEffect(()=>{!a||h===null||a(h,w())},[h,l]);const x=()=>r(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:!c,title:c?void 0:"Fill the required fields first",className:`w6w-subtab${f==="test"?" active":""}`,onClick:()=>c&&p("test"),children:"Test"})]})}),n.jsx("div",{className:"w6w-stepconfig-body",children:f==="configure"?n.jsx(Di,{fixedTarget:!0,values:l,onChange:u,onValidityChange:d,targetLabel:s}):n.jsx(id,{family:l.targetKind==="function"?"function":"workflow",targetId:String(l.targetId),inputs:l.inputs,entry:typeof l.entry=="string"?l.entry:void 0,canRun:c})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:o,children:"Cancel"}),f==="configure"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!c,onClick:()=>p("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:h!==null?i??o:x,children:h!==null?"Done":"Add node"})]})]})}function id({family:e,targetId:t,inputs:s,entry:r,canRun:o}){const i=ye(),[a,l]=b.useState(null),u=async()=>{if(!(!o||(a==null?void 0:a.status)==="running")){l({status:"running"});try{if(e==="function"){const c=await i.invokeFunction(t,s);l({status:"done",output:c,terminal:!0})}else{const c=await i.runWorkflow(t,{input:s,variables:s,entry:r});l({status:"done",output:c.output,runId:c.runId,terminal:c.terminal,error:c.error})}}catch(c){l({status:"error",error:c.message??String(c)})}}};return 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:!o||(a==null?void 0:a.status)==="running",onClick:u,children:(a==null?void 0:a.status)==="running"?"Running…":"▶ Test run"}),!o&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(a==null?void 0:a.status)==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:a.error}),(a==null?void 0:a.status)==="done"&&!a.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:a.runId})," has not finished yet — check its status from the workflow's run history."]})]}),(a==null?void 0:a.status)==="done"&&a.terminal&&a.error!==void 0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Run failed"}),n.jsx(ae.Copyable,{value:JSON.stringify(a.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(a.error,null,2)})})]}),(a==null?void 0:a.status)==="done"&&a.terminal&&a.error===void 0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result"}),n.jsx(ke,{value:a.output,maxHeight:220})]})]})}function ad(e){const t={};for(const s of e)et(s.default)&&(t[s.key]=s.default);return t}function Ct(e,t){const s=Po(t);if(s===null)return!1;if(s===void 0)return!0;const r=kt(e),o=a=>{var l;return s[a]!==void 0?s[a]:(l=r.find(u=>u.key===a))==null?void 0:l.default},i=(a,l,u)=>a.every(c=>{const d=le.effectiveParam(c,u);if(d.type==="section")return i(d.children??[],l,u);if(d.type==="group"){const p=d.children??[],h=kt(p),m=x=>g=>{const y=h.find(A=>A.key===g);return y?x[g]!==void 0?x[g]:y.default:u(g)};if(d.repeat){const x=Array.isArray(l[d.key])?l[d.key]:[];return x.length===0?!d.required:x.every(g=>{const y=g??{};return i(p,y,m(y))})}const w=l[d.key]??{};return i(p,w,m(w))}if(!d.required||!Yt(c,u))return!0;const f=l[d.key]??d.default;return f==null?!1:typeof f=="string"?f.trim()!=="":!0});return i(e,s,o)}function Pi(e){const t=e==null?void 0:e.testRequired;return typeof t=="boolean"?t:!0}function ld(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 cd(e){const t=e==null?void 0:e.apiCalls;return Array.isArray(t)?t:[]}function ud({log:e,onClose:t}){return n.jsx(ve,{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(ke,{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(ke,{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(ui,{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","."]})]})]})})}const or=b.forwardRef(function({app:t,action:s,connectionId:r,values:o,canRun:i,hideRunButton:a,persist:l,state:u,onBusyChange:c,onResult:d},f){const p=ye(),h=xs(),m=Ra(),[w,x]=b.useState(null),[g,y]=b.useState(null),[A,R]=b.useState(!1),S=b.useRef(!1),[v,j]=b.useState(null),C=l==null?void 0:l.workflowId,$=l==null?void 0:l.stepId,M=Be().nodeMeta,k=$?M==null?void 0:M[$]:void 0;b.useEffect(()=>{if(!C||!$)return;let F=!1;return p.listStepTests(C,$).then(q=>{let z;for(const W of q)!W.lastRunAt||!W.lastRunStatus||(!z||Date.parse(W.lastRunAt)>Date.parse(z.lastRunAt))&&(z=W);!z||!z.lastRunAt||F||S.current||(z.lastRunStatus==="succeeded"?x({status:"done",value:z.lastRunOutput,...z.lastRunMeta?{meta:z.lastRunMeta}:{}}):x({status:"error",error:typeof z.lastRunError=="string"?z.lastRunError:z.lastRunError==null?"Test failed":JSON.stringify(z.lastRunError)}),j(z.lastRunAt))}).catch(()=>{}),()=>{F=!0}},[p,C,$]);const T=async()=>{var P;if(!i||(w==null?void 0:w.status)==="running")return;S.current=!0,j(null),x({status:"running"}),c==null||c(!0);let F;const q=new Date,z={method:"POST",path:`/apps/${encodeURIComponent(t)}/actions/${encodeURIComponent(s)}/invoke`,body:{params:o,...r?{connectionId:r}:{},...h?{project:h}:{},...u?{state:u}:{},...m?{workflowId:m}:{}}},W=O=>y({startedAt:q.toLocaleString(),durationMs:Date.now()-q.getTime(),request:z,response:O,apiCalls:cd(O.body)});try{const O=await p.invokeAction(t,s,o,{...r?{connectionId:r}:{},project:h,...u?{state:u}:{},...m?{workflowId:m}:{}});W({ok:!0,body:O}),F={status:"done",value:O.value,logs:O.logs,...O.meta?{meta:O.meta}:{}}}catch(O){const Z=O;W({ok:!1,...typeof Z.status=="number"?{status:Z.status}:{},body:ld(O)}),F={status:"error",error:Z.message??String(O),errorCode:Z.code,logs:Z.logs}}if(x(F),d==null||d(F.status==="done"),l){(P=p.saveTestInput)==null||P.call(p,l.workflowId,l.stepId,Ws(l.input)).catch(O=>console.error("test input save failed",O));try{const O=await p.saveStepTest(l.workflowId,l.stepId,{input:l.input,with:o});await p.recordStepTestRun(l.workflowId,l.stepId,{stepTestId:O.id,status:F.status==="done"?"succeeded":"failed",input:l.input,output:F.status==="done"?F.value:void 0,error:F.status==="error"?F.error:void 0,...F.status==="done"&&F.meta?{meta:F.meta}:{}})}catch(O){console.error("step test persist failed",O)}}c==null||c(!1)};b.useImperativeHandle(f,()=>({run:T}));const I=w&&w.status!=="running"?w.logs:void 0;return n.jsxs("div",{className:"w6w-steptest",children:[(!a||g)&&n.jsxs("div",{className:"w6w-steptest-bar",children:[!a&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!i||(w==null?void 0:w.status)==="running",onClick:T,children:(w==null?void 0:w.status)==="running"?"Running…":"▶ Test run"}),g&&(w==null?void 0:w.status)!=="running"&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>R(!0),title:"The full request and response of the last test run",children:["Log",g.apiCalls.length>0?` (${g.apiCalls.length})`:""]}),!a&&!i&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),A&&g&&n.jsx(ud,{log:g,onClose:()=>R(!1)}),v&&((w==null?void 0:w.status)==="done"||(w==null?void 0:w.status)==="error")&&n.jsxs("div",{className:"w6w-muted w6w-small w6w-testout-restored",children:["Last run · ",new Date(v).toLocaleString()]}),(w==null?void 0:w.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[w.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:w.errorCode})}),w.error]}),(w==null?void 0:w.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result (return value)"}),n.jsx(ke,{value:w.value,maxHeight:220}),(w.meta||k)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(ke,{value:{...k,...w.meta},maxHeight:220})]})]}),(w==null?void 0:w.status)!=="done"&&(w==null?void 0:w.status)!=="running"&&k&&n.jsxs("div",{className:"w6w-testout","data-testid":"steptest-static-meta",children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(ke,{value:k,maxHeight:220})]}),I&&I.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx(ae.Copyable,{value:I.join(`
19
- `),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:I.join(`
20
- `)})})]})]})}),Br=12,tn=new Set;function _i(e,t,s,r,o){const i=r&&r.length>0?new Set(r):null,a=_=>(i?i.has(_.id):!0)&&((t==null?void 0:t(_))??!0),l=ye(),[u,c]=b.useState(null),[d,f]=b.useState(null),[p,h]=b.useState(null),[m,w]=b.useState(null),[x,g]=b.useState(null),[y,A]=b.useState(()=>new Map),[R,S]=b.useState(()=>new Set),[v,j]=b.useState(tn),C=b.useRef(tn),$=b.useCallback(_=>{C.current=_,j(_)},[]),M=b.useRef(tn),k=e.includes("function"),T=e.includes("workflow"),I=typeof l.listAppsByIds=="function";b.useEffect(()=>{let _=!1;const Y=X=>!_&&g(X.message);return l.listConnections().then(X=>{if(_)return;const B=[],G=new Set,te=new Map;for(const E of X)Ze(E.appId)||(I&&!(o!=null&&o.resolveInline)&&E.app&&!te.has(E.appId)&&te.set(E.appId,{...E.app,id:E.appId}),!G.has(E.appId)&&(G.add(E.appId),B.push(E.appId)));te.size>0&&(M.current=new Set(te.keys()),A(E=>new Map([...E,...te])),S(E=>new Set([...E,...te.keys()]))),c(B)}).catch(Y),k?l.listFunctions().then(X=>!_&&h(X)).catch(Y):h([]),T?l.listWorkflows().then(X=>!_&&w(X)).catch(Y):w([]),()=>{_=!0}},[l,I,k,T,o==null?void 0:o.resolveInline]),b.useEffect(()=>{if(I)return;const _=l.listApps;if(typeof _!="function"){f([]);return}let Y=!1;return _().then(X=>!Y&&f(X)).catch(X=>!Y&&g(X.message)),()=>{Y=!0}},[l,I]);const F=b.useRef(!0);b.useEffect(()=>(F.current=!0,()=>{F.current=!1}),[]);const q=b.useCallback(_=>{const Y=l.listAppsByIds;!Y||_.length===0||C.current.size>0||($(new Set(_)),Y(_).then(X=>{F.current&&($(tn),A(B=>{const G=new Map(B);for(const te of X)G.set(te.id,te);return G}),S(B=>new Set([...B,..._])))}).catch(X=>F.current&&g(X.message)))},[l,$]),z=b.useRef(!1);b.useEffect(()=>{if(!I||u===null||z.current)return;const _=Dn(u,M.current,Br);_.length!==0&&(z.current=!0,q(_))},[I,u,q]);const W=()=>{if(!I||u===null||C.current.size>0)return;const _=new Set([...R,...C.current]);q(Dn(u,_,Br))};if(x)return{state:"error",error:x,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:W};if(p===null||m===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:W};const P=cs(p,s),O=cs(m,s);if(I){if(u===null)return{state:"loading",apps:[],fns:P,wfs:O,moreApps:!1,loadMoreApps:W};if(u.length>0&&R.size===0)return{state:"loading",apps:[],fns:P,wfs:O,moreApps:!1,loadMoreApps:W};const _=Ca(u,y).filter(a),Y=v.size===0&&Dn(u,new Set([...R,...v]),1).length>0;return{state:_.length===0&&P.length===0&&O.length===0&&!Y?"empty":"ready",apps:_,appIds:u.filter(B=>!i||i.has(B)),fns:P,wfs:O,moreApps:Y,loadMoreApps:W}}if(d===null)return{state:"loading",apps:[],fns:P,wfs:O,moreApps:!1,loadMoreApps:W};const Z=new Set(u??[]),Q=d.filter(_=>!Ze(_.id)&&a(_)&&(Z.has(_.id)||_.zeroCredential===!0));return{state:Q.length===0&&P.length===0&&O.length===0?"empty":"ready",apps:Q,fns:P,wfs:O,moreApps:!1,loadMoreApps:W}}function cs(e,t){return t&&t.length>0?e.filter(s=>!t.includes(s.id)):[...e]}function Dt(e){return(t,s)=>e(t).localeCompare(e(s),void 0,{sensitivity:"base"})}function vt(e){const t=e.displayName;return t!=null&&t.trim()?t:"name"in e?e.name:e.id}function us({family:e,item:t,onSelect:s}){const r=vt(t);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-stepbuilder-item--callable","data-kind":e,onClick:()=>s({id:t.id,label:r}),children:[n.jsx(Rn,{icon:Xu[e],size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:r}),n.jsx("code",{className:"w6w-muted w6w-small",children:t.id})]})]})}function dd(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 Fi({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(ht,{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 pd({data:e,query:t,appsFilter:s,onSelectApp:r,onSelectCallable:o,theme:i}){var x;const a=ye(),l=g=>n.jsx("div",{className:"w6w-apppicker-host",children:g});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 u=e.apps.filter(g=>Mt(t,g.displayName,g.id)).sort(Dt(g=>g.displayName)),c=e.fns.filter(g=>Mt(t,vt(g),g.id)).sort(Dt(vt)),d=e.wfs.filter(g=>Mt(t,vt(g),g.id)).sort(Dt(vt)),f=dd,p=u.map(g=>n.jsx(Fi,{app:g,theme:i,onSelect:r},g.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 h=t.trim()&&((x=e.appIds)!=null&&x.length)&&typeof a.listAppsPage=="function"?n.jsxs("section",{className:"w6w-readytouse-col",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Connected apps"}),n.jsx(ut,{search:!1,searchValue:t,ids:e.appIds,filter:s,onSelectApp:r,theme:i})]}):f("Connected apps",p),m=[f("Functions",c.map(g=>n.jsx(us,{family:"function",item:g,onSelect:y=>o({family:"function",...y})},g.id))),f("Workflows",d.map(g=>n.jsx(us,{family:"workflow",item:g,onSelect:y=>o({family:"workflow",...y})},g.id)))].filter(Boolean),w=(h?1:0)+(m.length>0?1:0);return l(w?n.jsxs("div",{className:"w6w-readytouse","data-cols":w,children:[h,m.length>0&&n.jsx("div",{className:"w6w-readytouse-stack",children:m})]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Nothing ready to use matches “",t,"”."]}))}function Li(e,t){var s;return(((s=e.getAppTriggers)==null?void 0:s.call(e,t))??Promise.resolve([])).then(r=>r.map(o=>({key:o.key,title:o.title,description:o.description,params:o.params??[]})))}function Mi({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 fd({kind:e="action",onOpenStep:t,appId:s,app:r,onAdd:o,onClose:i,onDone:a,onDraftChange:l,onChangeApp:u,theme:c,workflowId:d,stepId:f,upstreamSteps:p=[],loop:h,initialAction:m,initialConnection:w,initialWith:x}){var U;const g=ye(),y=e==="trigger",A=y?"a trigger":"an action",[R,S]=b.useState(null),[v,j]=b.useState(null),[C,$]=b.useState(null),[M,k]=b.useState(null),[T,I]=b.useState(w??""),[F,q]=b.useState(),z=Bs(),W=b.useRef(z);W.current=z;const P=F?Rt({uses:{app:s,action:"",connectionRef:F}},z==null?void 0:z.connections)??"":T,O=b.useCallback(V=>{q(void 0),I(V)},[]),[Z,Q]=b.useState(m??""),[re,_]=b.useState(x??{}),Y=b.useRef(null),[X,B]=b.useState(!1),[G,te]=b.useState(m&&x?"configure":"setup"),[E,J]=b.useState("props"),[ee,L]=b.useState("{}"),[H,ie]=b.useState({});b.useEffect(()=>{let V=!1;k(null);const ne=y?Li(g,s):g.getAppActions(s);return Promise.all([g.getAppAuth(s),g.listConnectionsForApp(s),ne]).then(([Ne,ot,it])=>{if(V)return;const Pe=Wr(s,Ne,ot);S(Ne),j(Pe),$(it);const Ee=W.current,he=ai({id:f??"",uses:{app:s,action:""}},Pe,(Ee==null?void 0:Ee.nodes)??[],(Ee==null?void 0:Ee.connections)??{},w);he.connectionRef?q(he.connectionRef):O(he.connection??"")}).catch(Ne=>!V&&k(Ne.message)),()=>{V=!0}},[g,s,y,O,w,f]);const pe=async()=>{const V=await g.listConnectionsForApp(s);j(Wr(s,R??[],V))},ue=(R??[]).filter(V=>V.available!==!1),me=ue.some(V=>V.autoSatisfied===!0&&(V.type==="tenantAuth"||V.type==="jit")),Se=me&&!ue.some(V=>V.autoSatisfied===!0&&V.type==="tenantAuth"),je=ue.length>0&&!me,Je=(v??[]).length>0,ce=(C??[]).find(V=>V.key===Z),Re=y?pi(s,C,Z,re):null,Ve=[...C??[]].sort((V,ne)=>(V.title??V.key).localeCompare(ne.title??ne.key,void 0,{sensitivity:"base"})),st=Pi(r),[mt,rt]=b.useState(!1);b.useEffect(()=>{if(!st||!d||!f)return;let V=!1;return g.listStepTests(d,f).then(ne=>{!V&&ne.some(Ne=>Ne.lastRunStatus==="succeeded")&&rt(!0)}).catch(()=>{}),()=>{V=!0}},[g,st,d,f]);const bt=sr(d??"",p,!!d),Fe=(U=Be().stateShape)==null?void 0:U.written,ze=nr(bt,Ei(h),Fe),be=!!Z&&(!je||Je&&!!P)&&(!Re||Re.selected.length>0),$e=be&&!!ce&&Ct(ce.params??[],re),Ke=be,ge=(v??[]).find(V=>V.id===P);function xe(){return{uses:{app:s,action:(ce==null?void 0:ce.key)??Z,...F?{connectionRef:F}:P?{connection:P}:{},...y?{trigger:!0}:{}},with:re,...H}}function gt(){ce&&o(xe())}const[Ce,Tt]=b.useState(null);b.useEffect(()=>{if(!l||Ce!==null||!be||Re&&G==="setup")return;const V=o(xe());V&&Tt(V),V&&y&&(t==null||t(V))},[l,Ce,be,G]),b.useEffect(()=>{!l||Ce===null||l(Ce,xe())},[Ce,re,H,P,F]);const Ge=V=>{V==="code"&&L(er(xe())),J(V)};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${G==="setup"?" active":""}`,onClick:()=>te("setup"),children:"Setup"}),n.jsx("button",{type:"button",disabled:!be,title:be?void 0:"Complete Setup first",className:`w6w-subtab${G==="configure"?" active":""}`,onClick:()=>be&&te("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!$e,title:$e?void 0:"Fill the required fields first",className:`w6w-subtab${G==="test"?" active":""}`,onClick:()=>$e&&te("test"),children:"Test"})]}),n.jsx(In,{view:E,customized:En(re),onChange:Ge,disabled:G!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[G==="setup"&&n.jsxs("div",{className:"w6w-stack",children:[M&&n.jsx("div",{className:"w6w-result w6w-error",children:M}),R===null&&!M&&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:Y,children:[n.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App",onClick:u,disabled:!u,children:[r&&n.jsx(ht,{src:r.iconSvg,srcDark:r.iconSvgDark,brandColor:r.brandColor,name:r.displayName,theme:c,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(r==null?void 0:r.displayName)??s})]}),n.jsx(ci,{step:{id:Ce??f??"",uses:{app:s,action:Z,...F?{connectionRef:F}:{connection:P||void 0}}},conns:v,failed:!!M,open:X,onOpenChange:B,anchorRef:Y,onChangeConnection:O,onChangeConnectionRef:q,onConnectionCreated:()=>{pe()}})]}),Se&&(ge==null?void 0:ge.builtIn)&&n.jsx("span",{className:"w6w-hint",children:"Scheduled or queued runs need a stored connection. Choose one from the connection menu."}),R!==null&&je&&!Je&&n.jsx("span",{className:"w6w-hint",children:"This app needs a connection before its actions can run."})]}),C!==null&&(C.length===0?n.jsx("p",{className:"w6w-muted w6w-small",children:y?"This app declares no triggers.":"This app exposes no actions."}):Re?n.jsx(di,{choices:Re,onChange:V=>{Q(Re.triggerKey),_(ne=>({...ne,actions:V}))}}):n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[y?"Trigger":"Action",Z?"":" *"]}),n.jsx(wt,{value:Z,placeholder:`— pick ${A} —`,mode:"combobox",listMaxHeight:200,onChange:V=>{var ne;Q(V),_(ad(((ne=(C??[]).find(Ne=>Ne.key===V))==null?void 0:ne.params)??[])),rt(!1)},options:Ve.map(V=>({value:V.key,label:`${V.title??V.key} (${V.key})`}))}),(ce==null?void 0:ce.description)&&n.jsx("span",{className:"w6w-hint",children:ce.description})]}))]}),G==="configure"&&(ce?E==="props"?n.jsx(Ie,{params:ce.params??[],values:re,onChange:_,dynamic:{appId:s,actionKey:ce.key,connectionId:P||void 0,appName:r==null?void 0:r.displayName}}):E==="code"?n.jsx(He,{value:ee,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):E==="params-code"?n.jsx(_s,{values:re,onChange:_}):n.jsx(Ps,{config:H,onChange:ie,failureHandling:!y}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Pick ",A," in Setup first."]})),G==="test"&&(ce&&y?n.jsx(Mi,{title:ce.title??ce.key,app:(r==null?void 0:r.displayName)??s}):ce?n.jsx(or,{app:s,action:ce.key,connectionId:P||void 0,values:re,canRun:be&&Ct(ce.params??[],re),state:ze,onResult:rt}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),G==="test"&&n.jsx("div",{className:"w6w-stepconfig-testnote",children:st&&!mt&&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:i,children:"Cancel"}),G==="test"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:Ce===null&&!Ke,onClick:Ce!==null?a??i:gt,children:Ce!==null?"Done":"Add node"}):n.jsx("button",{type:"button",className:"w6w-btn",disabled:G==="setup"?!be:!$e,onClick:()=>te(G==="setup"?"configure":"test"),children:"Next →"})]})]})}function hd({appId:e,app:t,onClose:s,onChangeApp:r,theme:o,initialConnection:i,onConnected:a}){const l=ye(),[u,c]=b.useState(null),[d,f]=b.useState(null),[p,h]=b.useState(null),[m,w]=b.useState(i??""),[x,g]=b.useState(!1),[y,A]=b.useState(!1);b.useEffect(()=>{let I=!1;return h(null),Promise.all([l.getAppAuth(e),l.listConnectionsForApp(e)]).then(([F,q])=>{if(I)return;c(F),f(q),!(F??[]).some(W=>W.autoSatisfied===!0)&&q.length>0&&w(q[0].id)}).catch(F=>!I&&h(F.message)),()=>{I=!0}},[l,e]);const R=async()=>{const I=await l.listConnectionsForApp(e);f(I),I.length>0&&w(F=>F||I[0].id)},S=(u??[]).filter(I=>I.available!==!1),v=S.some(I=>I.autoSatisfied===!0&&(I.type==="tenantAuth"||I.type==="jit")),j=v&&!S.some(I=>I.autoSatisfied===!0&&I.type==="tenantAuth"),C=S.length>0&&!v,$=(d??[]).length>0,M=!C||$&&!!m,k=(d??[]).find(I=>I.id===m),T=y||!m;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}),u===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(ht,{src:t.iconSvg,srcDark:t.iconSvgDark,brandColor:t.brandColor,name:t.displayName,theme:o,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(t==null?void 0:t.displayName)??e}),r&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:r,children:"Change"})]})]}),u!==null&&v&&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:()=>g(!0),children:"Create connection"})]}),j&&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.'})]}),u!==null&&C&&($?T?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:m,onChange:I=>{w(I.target.value),A(!1)},style:{flex:1},children:(d??[]).map(I=>n.jsxs("option",{value:I.id,children:[I.displayName||I.id," ",I.state?`(${I.state})`:""]},I.id))}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>g(!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:[(k==null?void 0:k.displayName)||(k==null?void 0:k.id)||m,k!=null&&k.state?` (${k.state})`:""]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>A(!0),children:"Change"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>g(!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:()=>g(!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:!M||!t,onClick:()=>t&&a(m,t),children:"Next →"})]}),x&&n.jsx(Os,{theme:o,initialAppId:e,onClose:()=>g(!1),onCreated:async({connectionId:I})=>{g(!1),w(I),A(!1),await R()}})]})}function Di({values:e,onChange:t,readOnly:s,setupOnly:r,onValidityChange:o,targetLabel:i,fixedTarget:a}){var W,P;const l=ye(),u=e.targetKind==="function"?"function":"workflow",c=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=et(e.inputs)||typeof f.$=="string",[h,m]=b.useState([]),[w,x]=b.useState(),[g,y]=b.useState(),[A,R]=b.useState(),S=`${u}:${c}`;b.useEffect(()=>{if(a)return;let O=!1;return m([]),x(void 0),(u==="workflow"?l.listWorkflows():l.listFunctions()).then(Z=>{O||m(Z)}).catch(Z=>{O||x(String(Z.message??Z))}),()=>{O=!0}},[l,u,a]),b.useEffect(()=>{let O=!1;return y(void 0),R(void 0),c?((u==="workflow"?l.getWorkflow(c).then(Q=>({key:S,workflow:Q,fields:[],label:Q.displayName||Q.name||c})):l.getFunction(c).then(Q=>({key:S,fields:Q.inputs,label:Q.displayName||Q.id}))).then(Q=>{O||y(Q)}).catch(Q=>{O||R(String(Q.message??Q))}),()=>{O=!0}):void 0},[l,c,u,S]);const v=(g==null?void 0:g.key)===S?g:void 0,j=v!=null&&v.workflow?Oi(v.workflow):[],C=d??((W=j[0])==null?void 0:W.id),$=v!=null&&v.workflow?Gu(v.workflow,C):(v==null?void 0:v.fields)??[],k={...Object.fromEntries($.filter(O=>O.default!==void 0).map(O=>[O.key,O.default])),...f},T=u==="function"||!d||j.some(O=>O.id===d),I=!!v&&T&&(p||Ct($,k));b.useEffect(()=>{o==null||o(I)},[I,o]),b.useEffect(()=>{if(!v||s||r)return;const O=!p&&$.some(Z=>Z.default!==void 0&&!(Z.key in f));(!d&&C||O)&&t({...e,...C?{entry:C}:{},inputs:p?e.inputs:k})});const F=h.map(O=>({value:O.id,label:O.displayName||("name"in O?O.name:O.id)||O.id})).sort((O,Z)=>O.label.localeCompare(Z.label));c&&!F.some(O=>O.value===c)&&F.unshift({value:c,label:(v==null?void 0:v.label)||i||c});const q=c?(P=l.callableHref)==null?void 0:P.call(l,u,c):void 0,z=(O,Z)=>{const{target:Q,entry:re,..._}=e;t({..._,targetKind:O,targetId:Z,inputs:{}})};return n.jsxs("div",{className:"w6w-stack",children:[!a&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Target kind"}),n.jsxs("select",{className:"w6w-input",value:u,disabled:s,onChange:O=>z(O.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:u==="workflow"?"Workflow":"Function"}),a?n.jsx("span",{children:(v==null?void 0:v.label)||i||c}):n.jsx(wt,{"aria-label":u==="workflow"?"Workflow":"Function",options:F,value:c,disabled:s,placeholder:`Choose a ${u}…`,onChange:O=>z(u,O)}),q&&n.jsxs("a",{className:"w6w-btn w6w-btn-ghost",href:q,target:"_blank",rel:"noopener noreferrer",children:["Open ",u," in new tab ↗"]})]}),w&&n.jsx("div",{className:"w6w-result w6w-error",children:w}),!r&&c&&n.jsxs(n.Fragment,{children:[A?n.jsx("div",{className:"w6w-result w6w-error",children:A}):v?n.jsxs(n.Fragment,{children:[u==="workflow"&&j.length>0&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Trigger"}),n.jsxs("select",{className:"w6w-input","aria-label":"Trigger",value:C,disabled:s,onChange:O=>t({...e,entry:O.target.value,inputs:{}}),children:[d&&!T&&n.jsxs("option",{value:d,children:[d," (unavailable)"]}),j.map(O=>n.jsxs("option",{value:O.id,children:[O.id," (",O.uses.app===At?"Manual":O.uses.action,")"]},O.id))]})]}),!T&&n.jsx("div",{className:"w6w-result w6w-error",children:"The selected trigger is unavailable. Choose another trigger."}),u==="workflow"&&j.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:[v.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(Ie,{params:$,values:k,readOnly:s,onChange:O=>t({...e,inputs:O})}):n.jsx(Ie,{params:[{key:"inputs",label:"Input payload",type:"json"}],values:{inputs:e.inputs??{}},readOnly:s,onChange:O=>t({...e,inputs:O.inputs})})]}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading inputs…"}),n.jsx(Ie,{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 wd=/^(#{1,6})\s+(.*)$/,md=new RegExp("\\*\\*(?=\\S)(.+?)(?<=\\S)\\*\\*","g");function bd(e,t){const s=e.ownerDocument;e.replaceChildren();for(const r of t.split(`
21
- `)){const o=wd.exec(r),i=s.createElement(o?`h${o[1].length}`:"div"),a=o?o[2]:r;let l=0;for(const u of a.matchAll(md)){u.index>l&&i.append(s.createTextNode(a.slice(l,u.index)));const c=s.createElement("strong");c.textContent=u[1],i.append(c),l=u.index+u[0].length}l<a.length&&i.append(s.createTextNode(a.slice(l))),i.firstChild||i.append(s.createElement("br")),e.append(i)}}function gd(e){var r;const t=(r=e.style)==null?void 0:r.fontWeight;if(!t)return;if(t==="bold"||t==="bolder")return!0;const s=Number(t);return Number.isFinite(s)?s>=600:!1}function yd(e){const t=[];for(const s of e){const r=t[t.length-1];r&&r.bold===s.bold?r.text+=s.text:t.push({...s})}return t.map(({text:s,bold:r})=>{const o=s.trim();if(!r||!o)return s;const i=s.slice(0,s.indexOf(o)),a=s.slice(i.length+o.length);return`${i}**${o}**${a}`}).join("")}function xd(e){const t=[];let s=null;const r=a=>(s={level:a,runs:[]},t.push(s),s),o=(a,l,u)=>{if(a.nodeType===3){const w=(a.textContent??"").replace(/ /g," ").replace(/\n/g,"");w&&(s??r(l)).runs.push({text:w,bold:u});return}if(a.nodeType!==1)return;const c=a,d=c.tagName.toLowerCase();if(d==="br"){s||r(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 h=f?Number(f[1]):l,m=d==="b"||d==="strong"?!0:gd(c)??u;for(const w of c.childNodes)o(w,h,m);p&&(s=null)};for(const a of e.childNodes)o(a,0,!1);const i=t.map(a=>{const l=yd(a.runs);return a.level>0?`${"#".repeat(a.level)} ${l.trimStart()}`:l});for(;i.length&&i[i.length-1].trim()==="";)i.pop();return i.join(`
22
- `)}function vd(e){return e.replace(/([^\n])\n(?=[^\n])/g,`$1
23
- `)}const jd=-2,Nd=-1,Ur=1e3,kd=["#facc15","#fb923c","#f87171","#f472b6","#a78bfa","#60a5fa","#2dd4bf","#4ade80","#9ca3af"],Sd=[{level:1,label:"Title"},{level:2,label:"Heading"},{level:3,label:"Subheading"},{level:0,label:"Body"}],Cd=80,Ad=48,Jr=10,Ed=4,Bn=e=>e.stopPropagation();function Rd(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),t.removeAllRanges(),t.addRange(s)}function Td(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 Hi({canvas:e,className:t,viewport:s,readOnly:r,zoom:o=1,onChange:i,onSectionDrop:a,onRequestDelete:l}){const[u,c]=b.useState({}),[d,f]=b.useState(null),[p,h]=b.useState(null),[m,w]=b.useState(null),[x,g]=b.useState(null),y=b.useRef(null),A=b.useRef(null),R=b.useRef(null);if(b.useEffect(()=>{if(!d&&!p)return;const E=d?`[data-note-id="${d}"], [data-note-toolbar="${d}"]`:`[data-section-label="${p}"], [data-section-toolbar="${p}"]`,J=ee=>{var ie,pe;const L=ee.target;if((ie=L==null?void 0:L.closest)!=null&&ie.call(L,E))return;const H=document.activeElement;(pe=H==null?void 0:H.closest)!=null&&pe.call(H,"[data-section-toolbar]")&&H.blur(),f(null),h(null),g(null)};return window.addEventListener("pointerdown",J,!0),()=>window.removeEventListener("pointerdown",J,!0)},[d,p]),!s)return null;const S=!r&&!!i,v=e.sections??[],j=e.notes??[],C=E=>u[E.id]??{x:E.position.x,y:E.position.y,w:E.size.width,h:E.size.height},$=E=>{const J=C(E);return{left:J.x,top:J.y,width:J.w,height:J.h,"--w6w-canvas-color":E.color}},M=(E,J)=>i==null?void 0:i({...e,notes:j.map(ee=>ee.id===E?{...ee,...J}:ee)}),k=(E,J)=>i==null?void 0:i({...e,sections:v.map(ee=>ee.id===E?{...ee,...J}:ee)}),T=E=>{const J=A.current,ee=j.find(H=>H.id===E);if(!(J!=null&&J.isConnected)||!ee)return;const L=xd(J);L!==ee.content&&M(E,{content:L})},I=E=>{h(null),f(E)},F=E=>{f(null),h(E)},q=(E,J)=>{R.current=J??null,I(E),w(E),g(null)},z=E=>J=>{if(!J||J.dataset.ready==="1")return;J.dataset.ready="1",A.current=J,bd(J,E.content),J.focus();const ee=R.current;R.current=null,ee?(Rd(J),ee(),T(E.id)):Td(J)},W=(E,J,ee)=>{var H;g(null);const L=()=>document.execCommand(J,!1,ee);m===E&&((H=A.current)!=null&&H.isConnected)?(L(),T(E)):q(E,L)},P=E=>E.mode==="move"?{...E.base,x:E.base.x+E.dx,y:E.base.y+E.dy}:{...E.base,w:Math.max(Cd,E.base.w+E.dx),h:Math.max(Ad,E.base.h+E.dy)},O=(E,J,ee,L)=>{if(!S||E.button!==0)return;E.stopPropagation(),E.preventDefault();const H={kind:ee,id:J.id,mode:L,sx:E.clientX,sy:E.clientY,base:C(J),dx:0,dy:0};y.current=H;const ie=ue=>{H.dx=(ue.clientX-H.sx)/(o||1),H.dy=(ue.clientY-H.sy)/(o||1),c(me=>({...me,[H.id]:P(H)}))},pe=()=>{if(window.removeEventListener("pointermove",ie),window.removeEventListener("pointerup",pe),y.current=null,c(Se=>{const{[H.id]:je,...Je}=Se;return Je}),H.dx===0&&H.dy===0)return;const ue=P(H),me={position:{x:ue.x,y:ue.y},size:{width:ue.w,height:ue.h}};H.kind==="section"&&H.mode==="move"&&a?a(H.id,{dx:H.dx,dy:H.dy}):H.kind==="note"?M(H.id,me):k(H.id,me)};window.addEventListener("pointermove",ie),window.addEventListener("pointerup",pe)},Z=t?` ${t}`:"",Q="nopan nodrag nowheel",re=S?j.find(E=>E.id===d):void 0,_=S?v.find(E=>E.id===p):void 0,Y=o||1,X=E=>{const J=C(E);return{left:J.x+J.w/2,top:J.y,transform:`translate(-50%, calc(-100% - ${Jr/Y}px)) scale(${1/Y})`,transformOrigin:"50% 100%","--w6w-canvas-color":E.color}},B=(E,J)=>{const ee=C(E);return{left:ee.x,top:ee.y,transform:`translate(0, calc(-100% - ${J/Y}px)) scale(${1/Y})`,transformOrigin:"0 100%","--w6w-canvas-color":E.color}},G=(E,J,ee,L)=>n.jsxs("div",{className:"w6w-note-menu w6w-note-menu-colors",role:"menu",children:[kd.map(H=>n.jsx("button",{type:"button",role:"menuitemradio","aria-checked":H===E,"aria-label":`Colour ${H}`,title:H,className:`w6w-note-swatch-btn${H===E?" active":""}`,style:{"--w6w-canvas-color":H},"data-testid":`${ee}-option`,"data-color":H,onClick:()=>{g(null),H!==E&&L(H)}},H)),n.jsx("label",{className:"w6w-note-swatch-btn w6w-note-swatch-custom",title:"Custom",children:n.jsx("input",{type:"color","aria-label":`Custom ${J} colour`,"data-testid":`${ee}-input`,value:E,onChange:H=>L(H.currentTarget.value)})})]}),te=E=>{E.target.closest("input")||E.preventDefault()};return pn.createPortal(n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`w6w-canvas-layer w6w-canvas-sections${Z}`,style:{zIndex:jd},"data-testid":"w6w-canvas-sections",children:[v.map(E=>n.jsx("div",{className:`w6w-canvas-section${p===E.id?" selected":""}`,style:$(E),"data-section-id":E.id,"data-testid":"section",children:S&&n.jsx("div",{className:`w6w-note-resize ${Q}`,"data-testid":"section-resize",onPointerDown:J=>O(J,E,"section","resize")})},E.id)),v.map(E=>(_==null?void 0:_.id)===E.id?null:n.jsx("div",{className:`w6w-canvas-section-title${S?` editable ${Q}`:""}`,style:B(E,Ed),"data-section-label":E.id,"data-testid":"section-label",title:S?"Click to edit · drag to move":void 0,onPointerDown:S?J=>{F(E.id),O(J,E,"section","move")}:void 0,children:E.title||(S?"Untitled section":"")},E.id))]}),n.jsx("div",{className:`w6w-canvas-layer w6w-canvas-notes${Z}`,style:{zIndex:Nd},"data-testid":"w6w-canvas-notes",children:j.map(E=>{const J=S&&m===E.id;return n.jsxs("div",{className:`w6w-canvas-note${d===E.id?" selected":""}`,style:$(E),"data-note-id":E.id,"data-testid":"note",children:[J?n.jsx("div",{ref:z(E),className:`w6w-canvas-note-body w6w-canvas-note-editor ${Q}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":"true","aria-label":"Note content","data-testid":"note-content",onPointerDown:Bn,onBlur:()=>{T(E.id),A.current=null,w(null)},onKeyDown:ee=>{ee.key==="Escape"&&ee.currentTarget.blur()},onPaste:ee=>{ee.preventDefault(),document.execCommand("insertText",!1,ee.clipboardData.getData("text/plain"))}},"editor"):n.jsx("div",{className:`w6w-canvas-note-body ${Q}`,"data-testid":"note-view",style:S?{cursor:"grab",touchAction:"none"}:void 0,onPointerDown:S?ee=>{I(E.id),O(ee,E,"note","move")}:void 0,onDoubleClick:S?()=>q(E.id):void 0,children:E.content.trim()?n.jsx(Fs,{content:vd(E.content)}):S&&n.jsx("span",{className:"w6w-canvas-note-empty",children:"Double-click to write"})},"view"),S&&n.jsx("div",{className:`w6w-note-resize ${Q}`,"data-testid":"note-resize",onPointerDown:ee=>O(ee,E,"note","resize")})]},E.id)})}),_&&n.jsx("div",{className:`w6w-canvas-layer${Z}`,style:{zIndex:Ur},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar w6w-section-toolbar ${Q}`,role:"toolbar","aria-label":"Section","data-testid":"section-toolbar","data-section-toolbar":_.id,style:B(_,Jr),onPointerDown:Bn,onMouseDown:te,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:E=>O(E,_,"section","move"),children:n.jsx(ae.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:_.title,size:Math.max(8,Math.min(32,_.title.length+1)),onBlur:E=>{const J=E.currentTarget.value;J!==_.title&&k(_.id,{title:J})},onKeyDown:E=>{(E.key==="Enter"||E.key==="Escape")&&E.currentTarget.blur()}},`${_.id}:${_.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${x==="color"?" active":""}`,"aria-label":"Section colour","aria-expanded":x==="color",title:"Colour","data-testid":"section-color",onClick:()=>g(x==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(ae.Icon,{name:"chevron-down",size:12})]}),x==="color"&&G(_.color,"section","section-color",E=>k(_.id,{color:E}))]}),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:()=>{g(null),l==null||l("section",_.id)},children:n.jsx(ae.Icon,{name:"trash"})})]})}),re&&n.jsx("div",{className:`w6w-canvas-layer${Z}`,style:{zIndex:Ur},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar ${Q}`,role:"toolbar","aria-label":"Note","data-testid":"note-toolbar","data-note-toolbar":re.id,style:X(re),onPointerDown:Bn,onMouseDown:te,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:E=>O(E,re,"note","move"),children:n.jsx(ae.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${x==="color"?" active":""}`,"aria-label":"Note colour","aria-expanded":x==="color",title:"Colour","data-testid":"note-color",onClick:()=>g(x==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(ae.Icon,{name:"chevron-down",size:12})]}),x==="color"&&G(re.color,"note","note-color",E=>M(re.id,{color:E}))]}),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${x==="size"?" active":""}`,"aria-label":"Text size","aria-expanded":x==="size",title:"Text size","data-testid":"note-size",onClick:()=>g(x==="size"?null:"size"),children:["Aa",n.jsx(ae.Icon,{name:"chevron-down",size:12})]}),x==="size"&&n.jsx("div",{className:"w6w-note-menu w6w-note-menu-sizes",role:"menu",children:Sd.map(E=>n.jsx("button",{type:"button",role:"menuitem",className:`w6w-note-menu-item w6w-note-size-${E.level}`,"data-testid":`note-size-${E.level}`,onClick:()=>W(re.id,"formatBlock",E.level?`<h${E.level}>`:"<div>"),children:E.label},E.level))})]}),n.jsx("button",{type:"button",className:"w6w-icon-btn","aria-label":"Bold",title:"Bold","data-testid":"note-bold",onClick:()=>W(re.id,"bold"),children:n.jsx(ae.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:()=>{g(null),l==null||l("note",re.id)},children:n.jsx(ae.Icon,{name:"trash"})})]})})]}),s)}function Od(e){const t=Jn.useStore(r=>{var o;return((o=r.domNode)==null?void 0:o.querySelector(".react-flow__viewport"))??null}),s=Jn.useStore(r=>r.transform[2]);return n.jsx(Hi,{...e,zoom:e.zoom??s,viewport:t})}function Id(e){return e.viewport!==void 0?n.jsx(Hi,{...e,viewport:e.viewport}):n.jsx(Od,{...e})}function $d({title:e,message:t,onConfirm:s,onClose:r,confirmLabel:o="Confirm",cancelLabel:i="Cancel",destructive:a=!0,pending:l=!1,autoFocusConfirm:u=!1,children:c}){const d=b.useRef(null);return b.useEffect(()=>{var f;u&&((f=d.current)==null||f.focus())},[u]),n.jsxs(ve,{title:e,onClose:()=>{l||r()},children:[n.jsxs("div",{className:"w6w-modal-body",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:t}),c]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:r,disabled:l,children:i}),n.jsx("button",{ref:d,type:"button",className:a?"w6w-btn w6w-btn-danger":"w6w-btn",onClick:s,disabled:l,children:o})]})]})}function Vt(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,r]of Object.entries(e.fields??{}))t[s]=Vt(r);return t}case"array":return e.items?[Vt(e.items)]:[];default:return null}}function Pd(e){const t={};for(const s of e??[])s&&typeof s.nodeId=="string"&&s.nodeId!==""&&(t[s.nodeId]=s);return t}function $n(e){return e.sampleOmitted!==!0&&"sample"in e&&e.sample!==void 0}function Pn(e,t){if(!t)return!1;const s=Date.parse(e.updatedAt),r=Date.parse(t);return Number.isFinite(s)&&Number.isFinite(r)&&s>r}function Wi(e,t,s,r){const o=t[e],i=s[e];return o!==void 0&&(!i||!Pn(i,r==null?void 0:r[e]))||!i?o:$n(i)?i.sample:Vt(i.shape)}function _d(e,t,s){const r={};for(const o of new Set([...Object.keys(e),...Object.keys(t)])){const i=Wi(o,e,t,s);i!==void 0&&(r[o]=i)}return r}function Fd(e,t,s){const r={...e};for(const[o,i]of Object.entries(t))$n(i)&&(e[o]===void 0||Pn(i,s==null?void 0:s[o]))&&(r[o]=i.sample);return r}function Ld(e,t,s){const r={...e},o={};for(const[i,a]of Object.entries(t))e[i]!==void 0&&!Pn(a,s==null?void 0:s[i])||(delete r[i],o[i]=$n(a)?a.sample:Vt(a.shape));return{fresh:r,persisted:o}}function Md(e,t,s){const r={...e},o={};for(const[i,a]of Object.entries(t))$n(a)&&(e[i]===void 0||Pn(a,s==null?void 0:s[i]))&&(delete r[i],o[i]=a.sample);return{fresh:r,persisted:o}}function Dd(e,t){if(e.app)return e.app;if(e.app!==null)return t.get(e.appId)}function Hd(e){const t=new Set;for(const s of e)s.app===void 0&&t.add(s.appId);return[...t]}exports.AddConnectionModal=Os;exports.AnchoredFlyout=ri;exports.ApiCallsPanel=ui;exports.AppIcon=ht;exports.AppPicker=ut;exports.AppTriggerTestNote=Mi;exports.AuthFieldsForm=an;exports.CALL_APP=yn;exports.CONTROL_APP=Te;exports.CallTargetForm=Di;exports.CanvasLayer=Id;exports.CodeEditor=js;exports.Combobox=wt;exports.ConditionEditor=An;exports.ConfigViewToggle=In;exports.ConfirmModal=$d;exports.CredentialPicker=No;exports.DATA_APP=Ht;exports.DeleteButton=Fo;exports.EACH_SOURCE_HANDLE=gn;exports.EDITOR_THEME_SPEC=vs;exports.ERROR_SOURCE_HANDLE=ps;exports.EventbriteTriggerPicker=di;exports.ExpressionEditorModal=Gt;exports.ExpressionInput=Bt;exports.ExpressionOptionsProvider=vl;exports.FOREACH_DONE_ROUTE=jt;exports.HTML_PREVIEW_CSP=qo;exports.HtmlPreview=Uo;exports.INTERNAL_NODES=ft;exports.IconButton=kn;exports.InternalIcon=Rn;exports.JsonEditor=He;exports.LastUsedNote=ti;exports.Markdown=Fs;exports.Modal=ve;exports.NodeConfigForm=Ps;exports.ParamCustomization=_s;exports.ParamsForm=Ie;exports.PropertyEntryForm=Ho;exports.RACE_APP=Kt;exports.RACE_DESCRIPTION=Yr;exports.RESULT_RENDER_MAX_CHARS=zo;exports.ROUTER_APP=We;exports.ResultViewer=ke;exports.RetryPolicyFields=$o;exports.RouterEditor=Lo;exports.SCHEDULER_APP=hs;exports.SCRIPT_APP=Gr;exports.StepBuilderModal=Qu;exports.StepNameEditor=Mo;exports.StepTestRun=or;exports.StopEditor=Do;exports.TRIGGER_APP=At;exports.TriggerFillForm=ni;exports.W6WUIProvider=Aa;exports.WEBHOOK_APP=_e;exports.WaitEditor=si;exports.WorkflowConnectionPicker=ci;exports.WorkflowConnectionsContext=li;exports.WorkflowProjectProvider=Ea;exports.ancestorIds=tr;exports.applyConnect=tu;exports.applyStepProblems=Dc;exports.asFieldDefs=Ls;exports.bindingFieldsFor=ko;exports.bridgeDeletedBodyStep=Gc;exports.buildBinding=So;exports.buildResolveScope=Ns;exports.canConnect=bi;exports.centralizeConnections=ii;exports.coerceDefault=Ds;exports.conditionCombinatorLabel=ac;exports.conditionOperatorLabel=ic;exports.connectConflict=nu;exports.connectRefusal=su;exports.connectionAppIdsToLookUp=Hd;exports.connectionIdFor=Rt;exports.controlOwnedIds=Us;exports.convertCodeBindingsToReads=Cl;exports.dataVarRows=bn;exports.declaredSamples=Bu;exports.deepEqual=Yn;exports.defaultConnectionFor=ai;exports.definitionLoops=Gs;exports.deleteStepMessage=eu;exports.detectResultFormat=Ko;exports.edgeLane=we;exports.edgeVisuals=zt;exports.edgeWhenConflict=ou;exports.editConnectionResources=ln;exports.effectiveEdges=zs;exports.effectiveNodeOutput=Wi;exports.effectiveNodeOutputs=_d;exports.eventbriteTriggerChoices=pi;exports.excludeSelfStep=xl;exports.fieldWidget=Ms;exports.fieldsToParams=Hs;exports.filterOptions=so;exports.findChainRoot=vu;exports.findChainTail=ju;exports.findCodeBindings=xo;exports.findTestInput=Xo;exports.flattenParams=kt;exports.flowToWorkflow=gu;exports.foreachTestFixture=Ru;exports.foreachTestSample=Tu;exports.getTriggerDefs=Li;exports.hasParamCustomization=En;exports.htmlPreviewSrcDoc=Bo;exports.idClashMessage=cu;exports.ifPortLayout=ra;exports.indexNodeSamples=Pd;exports.inferOutputFields=lt;exports.internalNodeDef=ct;exports.internalNodeDefaults=wn;exports.internalNodeIcon=va;exports.internalNodeLabel=xa;exports.internalNodeParams=Xr;exports.isConnectionBlocked=qc;exports.isControlApp=It;exports.isDollarPath=ks;exports.isEachLink=Ks;exports.isExprValue=qe;exports.isFloatingDraft=Ci;exports.isForeachStep=Ae;exports.isFormResolvedOptions=vn;exports.isIfStep=gs;exports.isInternalApp=Ze;exports.isParamVisible=Yt;exports.isSecretValue=tt;exports.isTestRequired=Pi;exports.isTriggerApp=hn;exports.isTriggerStep=oa;exports.laneForSourceHandle=Gi;exports.loopBody=Tn;exports.loopItemText=Mu;exports.loopMembership=Ue;exports.loopRefusal=wi;exports.loopRefusalMessage=Zc;exports.nextWorkflowConnectionName=qs;exports.nodeConfigSources=Ju;exports.nodeConfigValues=Vu;exports.nodeMetaSampleValues=Ku;exports.nodeMetaValues=zu;exports.nodePortsForStep=Wt;exports.normalizeInput=Qs;exports.parseJsonFields=ss;exports.parseLoopSeed=Du;exports.parseRootAnchoredTemplate=Qe;exports.pickWebhookSubscription=Yo;exports.previewCustomization=_o;exports.previewNodeOutputs=Fd;exports.relaneRefusal=iu;exports.relayoutNodes=bu;exports.rememberableInput=Ws;exports.renameStepInEdges=au;exports.requiredParamsFilled=Ct;exports.resolveConnectionAppMeta=Dd;exports.resolveLoopItemsInState=Ni;exports.resolveOutputShape=xt;exports.resolveParamJson=qt;exports.resolveParamValue=Cs;exports.resolveVarsJson=Ya;exports.resultCopyText=Go;exports.routeFromHandle=ea;exports.routeHandle=Et;exports.routerPortLayout=sa;exports.routesForStep=bs;exports.seedValues=os;exports.selectNodeConnection=Bc;exports.setEdgeWhen=ru;exports.shapeToSkeleton=Vt;exports.shouldUseCombobox=no;exports.slugifyLabel=xu;exports.splitFrontmatter=Wo;exports.splitNodeOutputs=Ld;exports.splitPreviewOutputs=Md;exports.stampLoopOf=Qc;exports.startOAuthPopup=Co;exports.startStateFromSeeds=nr;exports.stepBuilderLoop=_u;exports.stepBuilderUpstreamSteps=Pu;exports.stepNameError=gi;exports.stepProblemTooltip=Wc;exports.stepToJson=er;exports.storedViewport=xi;exports.stripBody=Vs;exports.suggestStepId=Nu;exports.testInputSavesSettled=Qo;exports.trackTestInputSave=Zo;exports.upstreamSampleValueSources=qu;exports.upstreamSampleValues=Wu;exports.upstreamStateSources=$u;exports.useEffectiveTheme=xn;exports.useEnterSubmit=Ao;exports.useExpressionOptions=Be;exports.useRememberedTestInput=ei;exports.useSeedSources=sr;exports.useW6WApi=ye;exports.useWorkflowConnections=Bs;exports.valueAtPath=Lt;exports.varLabel=Xe;exports.withConnectionRef=Jt;exports.withViewport=yu;exports.workflowToFlow=mu;
24
- //# sourceMappingURL=connection-app-meta-CKTmUX08.cjs.map