@w6w/ui 0.2.60 → 0.2.62
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.
- package/CHANGELOG.md +7 -0
- package/dist/AddConnectionModal.d.ts +7 -6
- package/dist/components/CredentialPicker.d.ts +15 -6
- package/dist/components/ExpressionOptions.d.ts +8 -0
- package/dist/{connection-app-meta-CEkQSIlc.js → connection-app-meta-CIfXp2O-.js} +5466 -4945
- package/dist/connection-app-meta-CIfXp2O-.js.map +1 -0
- package/dist/connection-app-meta-Cn39S3ED.cjs +24 -0
- package/dist/connection-app-meta-Cn39S3ED.cjs.map +1 -0
- package/dist/credentialLinkContext.d.ts +8 -0
- package/dist/flow-loop.d.ts +7 -2
- package/dist/flow-types.d.ts +12 -0
- package/dist/flow.cjs +5 -5
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.mjs +1270 -1208
- package/dist/flow.mjs.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +833 -866
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +5 -0
- package/dist/resolve-params.d.ts +4 -0
- package/dist/step-preview-state.d.ts +13 -7
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
- package/src/styles/_tester.scss +8 -0
- package/src/styles.css +10 -0
- package/dist/connection-app-meta-BXCIgekK.cjs +0 -24
- package/dist/connection-app-meta-BXCIgekK.cjs.map +0 -1
- package/dist/connection-app-meta-CEkQSIlc.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),b=require("react"),ae=require("@w6w/expr"),Gn=require("@codemirror/lang-javascript"),ii=require("@codemirror/lang-python"),ws=require("@codemirror/view"),rr=require("@uiw/react-codemirror"),le=require("./CodeBlock-BSX1pi6W.cjs"),ar=require("@codemirror/lang-json"),fo=require("@codemirror/lint"),bn=require("react-dom"),Yn=require("@xyflow/react"),li=require("react-markdown");var Un=typeof document<"u"?document.currentScript:null;const ci={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function ui(e){if(typeof e!="string"||e.trim()==="")return"";const t=ci[e];return t||e.split(/[-_\s]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function di(e){const t=new Map;for(const s of e)for(const o of s.categories??[])t.set(o,(t.get(o)??0)+1);return[...t.entries()].map(([s,o])=>({slug:s,label:ui(s),count:o})).sort((s,o)=>o.count-s.count||s.label.localeCompare(o.label,void 0,{sensitivity:"base"}))}function pi(e,t){if(t.length===0)return!0;const s=e.categories??[];return t.some(o=>s.includes(o))}function Xt(e,t){const s=e==="error"?{className:"w6w-edge-error",label:"on error"}:e==="each"?{className:"w6w-edge-each"}:{};if(!t)return s;const o=t==="taken"?"w6w-edge-taken":"w6w-edge-skipped";return{className:s.className?`${s.className} ${o}`:o,...s.label?{label:s.label}:{}}}const ms="out-error",Cn="out-each",wt="done",ir="each";function bs(e){return e==="error"?ms:e==="each"?Cn:void 0}function fi(e){return e===ms?"error":e===Cn?"each":"success"}const hi="@w6w/",_e="@w6w/control",lr="@w6w/script",Ht="@w6w/data",Rt="@w6w/trigger",wi="@w6w/http",qe="@w6w/webhook",ys="@w6w/scheduler",mi="@w6w/respond",Zt="@w6w/call",gs="@w6w/document",nn="@w6w/model",bi="@w6w/template",sn="@w6w/regex",Je="@w6w/store",vt="@w6w/csv",yi="@w6w/files",xs="@w6w/stop",Ke="@w6w/router",Ot="@w6w/race",cr="Continue once with the first arriving path’s output. Later arrivals are ignored for this run. Other paths keep running.";function vs(e){var t;return e.uses.app!==Ke||!Array.isArray((t=e.with)==null?void 0:t.routes)?[]:e.with.routes.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string")}const It=e=>`route:${e}`,gi=e=>e!=null&&e.startsWith("route:")?e.slice(6):void 0,xi=3,vi=16;function ji(e){const t=e.find(r=>r.default),s=r=>({id:r.id,handleId:It(r.id),label:r.default?"Fallback":r.label||r.id}),o=e.filter(r=>r!==t);return{right:o.map((r,a)=>({...s(r),top:`${(a+.5)/o.length*100}%`})),...t?{bottom:s(t)}:{},...o.length>xi?{minHeight:o.length*vi}:{}}}const yn="false";function js(e){return e.uses.app===_e&&e.uses.action==="if"}function Ni(){return{right:[{id:"true",label:"True",top:"50%"}],bottom:{id:yn,handleId:It(yn),label:"False"}}}function st(e){return e.startsWith(hi)}function kt(e){return e===_e||e===Ot}function gn(e){return e===Rt||e===qe||e===ys}function ki(e){return gn(e.app)||e.trigger===!0}const ho={in:1,out:Number.POSITIVE_INFINITY};function wo(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function Si(...e){let t,s;for(const o of e)t??(t=wo(o==null?void 0:o.in)),s??(s=wo(o==null?void 0:o.out));return{in:t??ho.in,out:s??ho.out}}function Bt(e,t){var a;if(e.uses.app===Ke)return{in:1,out:vs(e).length};const{app:s,action:o}=e.uses,r=e.uses.trigger?{in:0,out:1}:void 0;return Si(e.ports,t==null?void 0:t(s,o),((a=mt(s,o))==null?void 0:a.ports)??r)}const Ci='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',mo='<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" />',Ai='<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" />',Ei='<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" />',Ti='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',Ri='<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" />',Oi='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',bo='<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" />',Ii='<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" />',$i='<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" />',Pi='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',yo='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',_i='<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" />',Fi='<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" />',Vn='<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" />',Li='<rect x="4" y="8" width="16" height="12" rx="2" /><line x1="12" y1="4" x2="12" y2="8" /><circle cx="12" cy="3" r="1" /><circle cx="9" cy="14" r="1.2" /><circle cx="15" cy="14" r="1.2" /><line x1="2" y1="13" x2="2" y2="16" /><line x1="22" y1="13" x2="22" y2="16" />',Mi='<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" />',pt='<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" />',jt='<rect x="3" y="4" width="18" height="16" rx="2" /><line x1="3" y1="10" x2="21" y2="10" /><line x1="3" y1="15" x2="21" y2="15" /><line x1="9" y1="4" x2="9" y2="20" />',Di='<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" /><polyline points="14 3 14 8 19 8" /><line x1="12" y1="11" x2="12" y2="17" /><polyline points="9.5 14.5 12 17 14.5 14.5" />',Wi=[{app:sn,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:sn,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:sn,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:sn,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"}]}],qi=[{app:vt,action:"from-json",label:"From JSON",displayName:"CSV",groupActions:!0,group:"compute",icon:jt,params:[{key:"items",label:"Items",type:"json",required:!0,hint:"A list of objects, one per row."},{key:"csv",label:"Table",type:"json",hint:"Optional table to append to. Its columns stay first.",required:!1},{key:"columns",label:"Columns",type:"json",hint:"Optional column names, in order. Keys not listed are dropped."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:vt,action:"create",label:"Create table",displayName:"CSV",groupActions:!0,group:"compute",icon:jt,params:[{key:"columns",label:"Columns",type:"json",hint:"Column names, in order. Leave empty to use the keys of the rows."},{key:"rows",label:"Rows",type:"json",hint:"Optional list of row objects."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:vt,action:"add-rows",label:"Add rows",displayName:"CSV",groupActions:!0,group:"compute",icon:jt,params:[{key:"csv",label:"Table",type:"json",hint:"A table: { columns: string[], rows: object[] }. Usually the output of another CSV step.",required:!0},{key:"rows",label:"Rows",type:"json",required:!0,hint:"A list of row objects to append."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:vt,action:"remove-rows",label:"Remove rows",displayName:"CSV",groupActions:!0,group:"compute",icon:jt,params:[{key:"csv",label:"Table",type:"json",hint:"A table: { columns: string[], rows: object[] }. Usually the output of another CSV step.",required:!0},{key:"indexes",label:"Row positions",type:"json",hint:"Zero-based positions to remove. Use this or Match, not both."},{key:"where",label:"Match",type:"json",hint:'An object such as { "status": "done" }. A row is removed when every listed column equals its value exactly ("1" is not 1).'}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]},{app:vt,action:"to-text",label:"To CSV text",displayName:"CSV",groupActions:!0,group:"compute",icon:jt,params:[{key:"csv",label:"Table",type:"json",hint:"A table: { columns: string[], rows: object[] }. Usually the output of another CSV step.",required:!0},{key:"delimiter",label:"Delimiter",type:"string",default:",",hint:"One of , ; | or a tab."},{key:"header",label:"Header row",type:"boolean",default:!0,hint:"Write the column names as the first line."},{key:"bom",label:"Byte order mark",type:"boolean",default:!1,hint:"Start the text with U+FEFF, which some spreadsheet apps need for UTF-8."},{key:"escapeFormulas",label:"Escape formulas",type:"boolean",default:!1,hint:"Prefix text starting with = + - @ tab or CR with an apostrophe so spreadsheets do not run it. This breaks an exact round trip."},{key:"file",label:"Also create a file",type:"boolean",default:!1,hint:"Create a downloadable text/csv file as well as the text."},{key:"filename",label:"File name",type:"string",default:"data.csv",hint:"Used when a file is created. 1 to 255 characters, no slashes."}],output:[{key:"text",label:"Text"},{key:"file",label:"File"}]},{app:vt,action:"parse",label:"Parse CSV",displayName:"CSV",groupActions:!0,group:"compute",icon:jt,params:[{key:"text",label:"Text",type:"text",hint:"CSV text. Use this or File."},{key:"file",label:"File",type:"file",hint:"A CSV file from an earlier step. Use this or Text."},{key:"delimiter",label:"Delimiter",type:"string",default:",",hint:"One of , ; | or a tab."},{key:"header",label:"Header row",type:"boolean",default:!0,hint:"Off names the columns column_1, column_2 and so on."},{key:"inferTypes",label:"Detect types",type:"boolean",default:!0,hint:"Off keeps every cell as text."}],output:[{key:"columns",label:"Columns"},{key:"rows",label:"Rows"}]}],it=[...Wi,...qi,{app:Ot,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:Ke,action:"route",label:"Router",displayName:"Router",group:"control",icon:mo,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:xs,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:Rt,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:Ci,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:qe,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:$i,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:ys,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:Ri,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:_e,action:"if",label:"If",displayName:"If",group:"control",icon:mo,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:"A boolean, or an expression like {{ nodes.x.output.ok }}."}]},{app:_e,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:Ai,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:_e,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:Ei,params:[]},{app:_e,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:Ti,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:lr,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:Oi,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:bi,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:Mi,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:bo,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:bo,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:wi,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:Ii,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:mi,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:Pi,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:_e,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:yo,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:_e,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:yo,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:Zt,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:_i,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:gs,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:Fi,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:nn,action:"complete",label:"Complete with model",displayName:"Model",group:"compute",icon:Vn,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:nn,action:"agent",label:"Run agent",displayName:"Agent",group:"compute",icon:Li,ports:{in:1,out:1},params:[{key:"agent",label:"Agent",type:"agent",required:!0,hint:"An agent from the Agents dashboard. Its tools run when it calls them."},{key:"message",label:"Message",type:"text",required:!0,hint:"What to tell the agent — text, or an expression such as an earlier step's output (an object is sent as JSON)."}]},{app:nn,action:"list-models",label:"List models",displayName:"Model",group:"compute",icon:Vn,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:nn,action:"allowance",label:"Model allowance",displayName:"Model",group:"compute",icon:Vn,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:Je,action:"get",label:"Get entry",displayName:"Store",group:"compute",icon:pt,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:Je,action:"set",label:"Set entry",displayName:"Store",group:"compute",icon:pt,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:Je,action:"delete",label:"Delete entry",displayName:"Store",group:"compute",icon:pt,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:Je,action:"increment",label:"Increment counter",displayName:"Store",group:"compute",icon:pt,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:Je,action:"list",label:"List entries",displayName:"Store",group:"compute",icon:pt,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:Je,action:"query",label:"Query rows",displayName:"Store",group:"compute",icon:pt,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:Je,action:"insert",label:"Insert row",displayName:"Store",group:"compute",icon:pt,ports:{in:1,out:1},params:[{key:"store",label:"Store",type:"data-store",required:!0,hint:"Name of a data store in this account and project."},{key:"row",label:"Row",type:"json",required:!0,hint:"The row, keyed by column name."},{key:"ttlSeconds",label:"TTL (seconds)",type:"number",hint:"Expire the entry after this many seconds. Omit to keep it."}],output:[{key:"key"},{key:"value"},{key:"version"}]},{app:yi,action:"save",label:"Save file",displayName:"Files",group:"compute",icon:Di,ports:{in:1,out:1},params:[{key:"path",label:"Path",type:"string",required:!0,hint:"Where to save the file in this account and project, such as reports/summary.csv. Saving to the same path again adds a version."},{key:"text",label:"Text",type:"text",hint:"Text to save. Use exactly one of Text, CSV or File."},{key:"csv",label:"CSV table",type:"json",hint:"A table from a CSV step, saved as CSV text. Use exactly one of Text, CSV or File."},{key:"file",label:"File",type:"file",hint:"A file from an earlier step. Use exactly one of Text, CSV or File."},{key:"contentType",label:"Content type",type:"string",hint:"Optional media type, such as text/plain. Defaults to one that fits the content."}],output:[{key:"fileId"},{key:"versionId"},{key:"path"},{key:"size"},{key:"sha256"},{key:"contentType"}]}];function mt(e,t){return it.find(s=>s.app===e&&s.action===t)}function Ui(e,t){var s;return((s=mt(e,t))==null?void 0:s.label)??t}function Vi(e,t){var s;return((s=mt(e,t))==null?void 0:s.icon)??""}function ur(e,t){var s;return((s=mt(e,t))==null?void 0:s.params)??[]}function xn(e,t){const s={};for(const o of ur(e,t))o.default!==void 0&&(s[o.key]=o.default);return s}function Hi(e,t){return e.q===t.q&&(e.category??"")===(t.category??"")&&(e.ids??[]).join(",")===(t.ids??[]).join(",")}function dr(e,t=0){return{query:e,generation:t,status:"loading",apps:[],hasMore:!1}}function Bi(e,t){const s=new Set(e.map(r=>r.id)),o=[];for(const r of t)s.has(r.id)||(s.add(r.id),o.push(r));return o.length===0?e:[...e,...o]}function Ji(e,t){switch(t.type){case"query-changed":return t.generation===e.generation&&Hi(t.query,e.query)?e:dr(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=Bi(e.apps,t.apps),o=t.nextCursor!==void 0&&t.nextCursor===t.requestedCursor,r=!!t.nextCursor&&!o;return{...e,status:"ready",apps:s,cursor:r?t.nextCursor:void 0,hasMore:r,total:typeof t.total=="number"?t.total:e.total,error:void 0}}case"page-failed":return t.generation!==e.generation?e:{...e,status:"error",error:t.error};default:return e}}function zi(e){return e.filter(t=>!st(t.id))}function Hn(e,t,s){if(s<=0)return[];const o=[];for(const r of e)if(!t.has(r)&&(o.push(r),o.length>=s))break;return o}function Ki(e,t){const s=[];for(const o of e){const r=t.get(o);r&&s.push(r)}return s}const pr=b.createContext(void 0);function go(e,t){var o;if(e)return e;if(t)return t;if(typeof document>"u")return"light";const s=document.documentElement.getAttribute("data-theme");return s==="dark"||s==="light"?s:(o=window.matchMedia)!=null&&o.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"}function An(e){const t=b.useContext(pr),[s,o]=b.useState(()=>go(e,t));return b.useEffect(()=>{if(e){o(e);return}if(t){o(t);return}if(typeof window>"u")return;const r=()=>o(go(void 0,t)),a=window.matchMedia("(prefers-color-scheme: dark)");a.addEventListener("change",r);const i=new MutationObserver(r);return i.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),r(),()=>{a.removeEventListener("change",r),i.disconnect()}},[e,t]),s}function gt({src:e,srcDark:t,brandColor:s,name:o,size:r=32,theme:a}){const l=An(a)==="dark"?t??e:e,[u,c]=b.useState(void 0);if(l&&l!==u)return n.jsx("img",{src:l,width:r,height:r,alt:"",onError:()=>c(l),style:{width:r,height:r,borderRadius:6,flexShrink:0,objectFit:"contain",padding:Math.max(1,Math.round(r*.06)),boxSizing:"border-box",background:"var(--w6w-icon-swatch, var(--w6w-panel-2))"}});const d=(o??"?").split(/\s+/).slice(0,2).map(p=>{var f;return((f=p[0])==null?void 0:f.toUpperCase())??""}).join("");return n.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:r,height:r,borderRadius:6,background:s??"var(--w6w-accent)",color:"#fff",fontWeight:700,fontSize:Math.round(r*.42),flexShrink:0},children:d})}const Ns=b.createContext(null);function Gi({api:e,theme:t,children:s}){const o=n.jsx(Ns.Provider,{value:e,children:n.jsx(pr.Provider,{value:t,children:s})});return t?n.jsx("div",{"data-theme":t,style:{display:"contents"},children:o}):o}function je(){const e=b.useContext(Ns);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}function Ft(){return b.useContext(Ns)??void 0}const fr=b.createContext(void 0),hr=b.createContext(void 0);function Yi({project:e,workflowId:t,children:s}){return n.jsx(fr.Provider,{value:e,children:n.jsx(hr.Provider,{value:t,children:s})})}function ks(){return b.useContext(fr)}function Xi(){return b.useContext(hr)}const Bn=8,Zi=60,Qi=300;function xo(e){const t=e.modelProvider;return!t||typeof t!="object"?null:t}function el(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 ot({onSelectApp:e,theme:t,filter:s,searchPlaceholder:o,emptyMessage:r,search:a=!0,searchValue:i,onSearchChange:l,emptyAction:u,apps:c,categoryFilter:d=!1,providerFilter:p=!1,bridgeSupport:f,category:m,hasTriggers:w,ids:h,pageLimit:g=Zi,loadPage:y}){const x=je(),C=c!==void 0,E=h&&h.length>0?h.join(","):"",S=!C&&(y!==void 0||typeof x.listAppsPage=="function"),j=b.useRef(y);j.current=y;const[N,A]=b.useState(null),[$,P]=b.useState(null);b.useEffect(()=>{if(C||S)return;const V=x.listApps;if(typeof V!="function"){A([]);return}let ue=!1;return V().then(se=>!ue&&A(se)).catch(se=>!ue&&P(se.message)),()=>{ue=!0}},[x,C,S]);const[R,I]=b.useReducer(Ji,dr({q:"",category:m,ids:h},0)),[T,_]=b.useState(""),q=i??T,U=V=>{i===void 0&&_(V),l==null||l(V)},[B,F]=b.useState(q.trim()),O=b.useRef(0),K=b.useRef(null),G=b.useCallback((V,ue,se)=>{var Z;const Qe=j.current,dt=x.listAppsPage;if(!Qe&&!dt)return;(Z=K.current)==null||Z.abort();const et=new AbortController;K.current=et;let We;try{We=Qe?Qe({q:V.q||void 0,cursor:se,limit:g,...V.ids?{ids:V.ids}:{},signal:et.signal}):dt({q:V.q||void 0,category:V.category,...w?{hasTriggers:!0}:{},...V.ids?{ids:V.ids}:{},cursor:se,limit:g,compact:!0,signal:et.signal})}catch(de){We=Promise.reject(de)}We.then(de=>{if(O.current===ue){if(!de||!Array.isArray(de.apps)){I({type:"page-failed",generation:ue,error:"The server returned a malformed apps page."});return}I({type:"page-loaded",generation:ue,apps:de.apps,nextCursor:de.nextCursor,requestedCursor:se,total:typeof de.total=="number"?de.total:void 0})}}).catch(de=>{if(O.current!==ue||de instanceof Error&&de.name==="AbortError")return;const Ee=de==null?void 0:de.code;if(se!==void 0&&(Ee==="snapshot_expired"||Ee==="unknown_snapshot")){const k=++O.current;I({type:"query-changed",query:V,generation:k}),G(V,k,void 0);return}I({type:"page-failed",generation:ue,error:de.message})})},[x,g,w]);b.useEffect(()=>{if(!S)return;const V=setTimeout(()=>F(q.trim()),Qi);return()=>clearTimeout(V)},[q,S]),b.useEffect(()=>{if(!S)return;const V=++O.current,ue={q:B,category:m,...E?{ids:E.split(",")}:{}};return I({type:"query-changed",query:ue,generation:V}),G(ue,V,void 0),()=>{var se;(se=K.current)==null||se.abort()}},[S,B,m,E,G]),b.useEffect(()=>{if(S)return()=>{var V;return(V=K.current)==null?void 0:V.abort()}},[S]);const Q=()=>{if(!S||R.status!=="ready"||!R.hasMore)return;const V=O.current;I({type:"load-more"}),G(R.query,V,R.cursor)},M=()=>{!S||R.status!=="error"||(I({type:"retry"}),G(R.query,O.current,R.cursor))},[X,J]=b.useState([]),[W,ne]=b.useState(!1),[ee,v]=b.useState(!1),D=V=>n.jsx("div",{className:"w6w-apppicker-host",children:V});let Y,re=null,z=!1,ge=!1,me=null,xe=!1;if(C?Y=c??null:S?(Y=R.apps,xe=R.status==="loading",z=R.status==="loading-more",ge=R.hasMore,R.status==="error"&&(R.apps.length===0?re=R.error??"Failed to load apps.":me=R.error??"Failed to load apps.")):(Y=N,re=$),!S&&re)return D(n.jsx("div",{className:"w6w-result w6w-error",children:re}));if(!S&&Y===null)return D(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));Y??(Y=[]);const Ne=zi(Y),be=s?Ne.filter(s):Ne;if(!S&&be.length===0)return D(n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:r??"No apps registered yet. Register one from the Apps page first."}),u]}));const ce=d?di(be):[],ie=ce.slice(0,Bn),pe=ce.slice(Bn).filter(V=>X.includes(V.slug)),Te=[...ie,...pe],Re=ce.length-Te.length,Pt=W?ce:Te,xt=V=>J(ue=>ue.includes(V)?ue.filter(se=>se!==V):[...ue,V]),he=()=>J([]),$e=be.filter(V=>xo(V)!==null).length,Ve=p&&$e>0,Le=Ve&&ee,Me=Le?be.filter(V=>xo(V)!==null):be,Pe=d&&X.length>0?Me.filter(V=>pi(V,X)):Me,ut=S?Pe:[...Pe].sort((V,ue)=>V.displayName.localeCompare(ue.displayName,void 0,{sensitivity:"base"})),Ze=S?"":q.trim().toLowerCase(),Se=q.trim().length>0,Oe=Ze?ut.filter(V=>V.displayName.toLowerCase().includes(Ze)||V.id.toLowerCase().includes(Ze)):ut,Ce=s!==void 0&&be.length!==Ne.length||Le&&Me.length!==be.length||d&&X.length>0&&Pe.length!==Me.length,He=(d&&X.length>0||Le)&&Oe.length===0,_t=Le&&X.length===0,De=()=>{J([]),v(!1),U("")};return D(n.jsxs("div",{className:"w6w-stepbuilder-apps",children:[a&&n.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:o??"Search apps…",value:q,onChange:V=>U(V.target.value),"aria-label":"Search apps"}),(Ve||d&&ce.length>0)&&n.jsxs("div",{className:"w6w-apppicker-cats",children:[Ve&&n.jsxs("button",{type:"button",className:"w6w-apppicker-chip w6w-apppicker-provider-toggle","aria-pressed":ee,"aria-label":"Filter to model providers",onClick:()=>v(V=>!V),children:["Model providers ",n.jsxs("span",{className:"w6w-muted",children:["(",$e,")"]})]}),d&&ce.length>0&&n.jsxs(n.Fragment,{children:[Pt.map(V=>n.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":X.includes(V.slug),"aria-label":`Filter by ${V.label}`,onClick:()=>xt(V.slug),children:[V.label," ",n.jsxs("span",{className:"w6w-muted",children:["(",V.count,")"]})]},V.slug)),!W&&Re>0&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>ne(!0),children:["+",Re," more"]}),W&&ce.length>Bn&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>ne(!1),children:"Show less"}),X.length>0&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:he,children:"Clear"})]})]}),S&&xe?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):S&&re?n.jsxs("div",{className:"w6w-result w6w-error",children:[re," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:M,children:"Retry"})]}):Oe.length===0&&!ge?He?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:_t?Se?`No model providers match “${q}”.`:"No apps declare a model provider.":Se?`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:De,children:"Clear filters"})]}):S?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:Se?`No apps match “${q}”.`:r??"No apps registered yet. Register one from the Apps page first."}),!Se&&u]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No apps match “",q,"”."]}):n.jsxs(n.Fragment,{children:[Oe.length===0&&ge?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:Oe.map(V=>{const ue=f==null?void 0:f.get(V.id),se=el(ue);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(V),children:[n.jsx(gt,{src:V.iconSvg,srcDark:V.iconSvgDark,brandColor:V.brandColor,name:V.displayName,theme:t,size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:V.displayName}),n.jsx("code",{className:"w6w-apppicker-card-id",children:V.id}),V.version&&n.jsxs("span",{className:"w6w-apppicker-card-version",children:["v",V.version]}),se&&n.jsx("span",{className:ue!=null&&ue.supported?"w6w-chip w6w-apppicker-card-bridge":"w6w-chip w6w-apppicker-card-bridge w6w-apppicker-card-bridge-unsupported",title:se.title,children:se.text})]})]},V.id)})}),S&&typeof R.total=="number"&&n.jsx("div",{className:"w6w-small w6w-apppicker-count",children:Ce?`${Oe.length} ${Oe.length===1?"app":"apps"}`:`${R.apps.length} of ${R.total}`}),S&&me&&n.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[me," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:M,children:"Retry"})]}),S&&ge&&!me&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:Q,disabled:z,children:z?"Loading more…":"Load more"})]})]}))}const Ss={"&":{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 tl(){let e,t=0,s=!1;const o=new Map,r=()=>{e==null||e.terminate(),e=void 0;for(const i of o.values())i([]);o.clear()},a=async i=>{const l=i.matchBefore(/[\w$]*/);if(s||!l||!i.explicit&&l.from===l.to&&i.state.sliceDoc(i.pos-1,i.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:Un&&Un.tagName.toUpperCase()==="SCRIPT"&&Un.src||new URL("connection-app-meta-Cn39S3ED.cjs",document.baseURI).href),{type:"module"}),e.onmessage=c=>{var d;(d=o.get(c.data.id))==null||d(c.data.options),o.delete(c.data.id)},e.onerror=r);const u=await new Promise(c=>{const d=++t;o.set(d,c),i.addEventListener("abort",()=>{o.delete(d),c([])},{onDocChange:!0}),e==null||e.postMessage({id:d,code:i.state.doc.toString(),position:i.pos})});return i.aborted||!u.length?null:{from:l.from,options:u}};return[Gn.javascriptLanguage.data.of({autocomplete:a}),ws.ViewPlugin.define(()=>(s=!1,{destroy(){s=!0,r()}}))]}function nl(e){switch(e){case"javascript":return Gn.javascript();case"typescript":return Gn.javascript({typescript:!0});case"python":return ii.python()}}function Cs(e){const t=An(e.theme),{copied:s,copy:o}=le.useCopyToClipboard(e.value),r=b.useMemo(()=>[...e.language?[nl(e.language)]:[],...e.language==="javascript"||e.language==="typescript"?[tl()]:[],ws.EditorView.theme(Ss)],[e.language]);return n.jsxs("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:[n.jsx(rr,{value:e.value,onChange:e.onChange,extensions:r,placeholder:e.placeholder,readOnly:e.readOnly,theme:t,height:e.height,minHeight:e.minHeight??"160px",maxHeight:e.maxHeight,onCreateEditor:e.onCreateEditor,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!e.readOnly,bracketMatching:!0,closeBrackets:!0}}),e.copyable!==!1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-icon-btn w6w-copyable-btn${s?" is-copied":""}`,"aria-label":"Copy",onClick:()=>void o(),children:s?n.jsx(le.CheckGlyph,{}):n.jsx(le.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function sl(){const e=ar.jsonParseLinter();return t=>t.state.doc.toString().trim()===""?[]:e(t)}function ze(e){const t=An(e.theme),{copied:s,copy:o}=le.useCopyToClipboard(e.value),r=b.useMemo(()=>[ar.json(),...e.showDiagnostics===!1?[]:[fo.linter(sl()),fo.lintGutter()],ws.EditorView.theme(Ss)],[e.showDiagnostics]);function a(i){var l,u,c,d;if(e.onChange(i),!(!e.onValidChange&&!e.onValidityChange)){if(i.trim().length===0){(l=e.onValidityChange)==null||l.call(e,{valid:!1,error:"Empty"});return}try{const p=JSON.parse(i);(u=e.onValidChange)==null||u.call(e,p),(c=e.onValidityChange)==null||c.call(e,{valid:!0})}catch(p){(d=e.onValidityChange)==null||d.call(e,{valid:!1,error:p.message})}}}return n.jsxs("div",{className:"w6w-json-editor","aria-label":e["aria-label"]??"JSON editor",children:[n.jsx(rr,{value:e.value,onChange:a,extensions:r,placeholder:e.placeholder,readOnly:e.readOnly,editable:!e.readOnly,theme:t,height:e.height,minHeight:e.minHeight??"240px",maxHeight:e.maxHeight,onCreateEditor:e.onCreateEditor,onBlur:e.onBlur,onFocus:e.onFocus,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:!e.readOnly,autocompletion:!0,bracketMatching:!0,closeBrackets:!0}}),e.overlay,e.copyable!==!1&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-icon-btn w6w-copyable-btn${s?" is-copied":""}`,"aria-label":"Copy",onClick:()=>void o(),children:s?n.jsx(le.CheckGlyph,{}):n.jsx(le.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function wr(e,t,s){return e*t>.6*s}function mr(e,t){const s=t.trim().toLowerCase();return s?e.filter(o=>{var r;return o.label.toLowerCase().includes(s)||o.value.toLowerCase().includes(s)||(((r=o.keywords)==null?void 0:r.toLowerCase().includes(s))??!1)}):e}const vo={display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"none",width:"1.25em",height:"1.25em",overflow:"hidden"},ol=240,jo={display:"block",fontSize:"0.85em",opacity:.65,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},rl={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 Ge({options:e,value:t,onChange:s,placeholder:o,disabled:r,"aria-label":a,mode:i="auto",forceSelection:l=!0,optionHeight:u=32,listMaxHeight:c=ol,className:d,onInputChange:p,emptyText:f="No matches",footer:m}){const w=i==="combobox"||i==="auto"&&wr(e.length,u,typeof window>"u"?0:window.innerHeight),h=b.useId(),g=e.find(F=>F.value===t),y=(g==null?void 0:g.label)??(l?"":t),[x,C]=b.useState(y),[E,S]=b.useState(!1),[j,N]=b.useState(!1),[A,$]=b.useState(0),P=b.useRef(null);b.useEffect(()=>{C(y)},[y]);const R=b.useMemo(()=>j?mr(e,x):e,[e,x,j]),I=b.useMemo(()=>({...rl,maxHeight:c}),[c]);if(!w)return n.jsxs("select",{className:d,value:t,disabled:r,"aria-label":a,onChange:F=>s(F.target.value),children:[o!==void 0&&t===""&&n.jsx("option",{value:"",disabled:!0,children:o}),e.map(F=>n.jsx("option",{value:F.value,children:F.label},F.value))]});const T=F=>`${h}-opt-${F}`,_=()=>{S(!1),N(!1)},q=F=>{C(F.label),s(F.value),_()},U=F=>{F.key==="ArrowDown"?(F.preventDefault(),E?$(O=>Math.min(O+1,R.length-1)):S(!0)):F.key==="ArrowUp"?(F.preventDefault(),E?$(O=>Math.max(O-1,0)):S(!0)):F.key==="Enter"?E&&R[A]?(F.preventDefault(),q(R[A])):l||(x!==y&&s(x),_()):F.key==="Escape"&&(E&&F.stopPropagation(),C(y),_())},B=()=>{l?C(y):x!==y&&s(x),_()};return n.jsxs("div",{ref:P,className:"w6w-combobox",style:{position:"relative"},children:[(g==null?void 0:g.icon)!==void 0&&!j&&n.jsx("span",{"aria-hidden":"true",className:"w6w-combobox-icon",style:{...vo,position:"absolute",left:"0.6em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none"},children:g.icon}),n.jsx("input",{type:"text",role:"combobox",className:d,style:(g==null?void 0:g.icon)!==void 0&&!j?{paddingLeft:"2.2em"}:void 0,value:x,disabled:r,placeholder:o,"aria-label":a,"aria-expanded":E,"aria-controls":`${h}-list`,"aria-autocomplete":"list","aria-activedescendant":E&&R[A]?T(A):void 0,autoComplete:"off",onFocus:()=>S(!0),onChange:F=>{C(F.target.value),p==null||p(F.target.value),N(!0),$(0),S(!0)},onKeyDown:U,onBlur:B}),E&&n.jsxs("div",{id:`${h}-list`,role:"listbox",tabIndex:-1,"aria-label":a,style:I,children:[R.map((F,O)=>n.jsx("div",{id:T(O),role:"option",tabIndex:-1,"aria-selected":F.value===t,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:O===A?"var(--w6w-panel-2)":void 0},onMouseDown:K=>{K.preventDefault(),q(F)},onMouseEnter:()=>$(O),children:F.icon!==void 0?n.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"0.5em"},children:[n.jsx("span",{"aria-hidden":"true",className:"w6w-combobox-icon",style:vo,children:F.icon}),n.jsxs("span",{style:{minWidth:0,flex:1},children:[F.label,F.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:jo,children:F.detail})]})]}):n.jsxs(n.Fragment,{children:[F.label,F.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:jo,children:F.detail})]})},F.value)),R.length===0&&n.jsx("div",{role:"presentation",style:{padding:"6px 8px",opacity:.6},children:f}),m!==void 0&&n.jsx("div",{role:"presentation",className:"w6w-combobox-footer",style:{padding:"6px 8px",opacity:.6,fontSize:"0.85em"},children:m})]})]})}function En(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.source==="resolveFields"}function Ye(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="expr"&&Array.isArray(e.parts)}function lt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function No(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 cn(e){const t=e.filter(o=>o.kind!=="text"||(o.value??"")!=="");if(t.length===0)return"";if(t.some(o=>o.kind==="render"))return{type:"expr",parts:t.map(No)};let s="";for(const o of t){if(o.kind==="text"){s+=o.value??"";continue}al(s)%2===1&&(s+="\\"),s+=ae.serializeTemplate([No(o)])}return s}function al(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t+=1;return t}const br={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(br));const ko=e=>Object.prototype.hasOwnProperty.call(br,e),So=["state","var","vars"];function yr(e){for(const t of So)if(e===t||e.startsWith(`${t}.`)){const s=e.slice(t.length);return[...new Set([e,...So.map(o=>o+s)])]}return[e]}function Co(e){const t=e.indexOf(".");return t===-1?e:e.slice(0,t)}function rt(e){const t=ae.parseTemplate(e,"editor",il);return t.every(Tn)?t:[{kind:"text",value:e}]}function Tn(e){if(e.kind==="var"){const t=e.ref??"";return!ae.hasRefusedChainToken(t)&&ko(Co(t))}if(e.kind==="expr"){const t=ae.coalesceOperandRefs(e.expr);return t===null?!0:t.every(s=>ko(Co(s)))}return!0}const il={isOurs:Tn,backslash:"keep"},gr={isOurs:Tn,backslash:"strip"};function at(e){return Ye(e)?!0:typeof e=="string"&&e.includes("{{")&&rt(e).some(t=>t.kind!=="text")}function Rn(e){if(!e.includes("{{"))return null;const t=ae.parseTemplate(e,"editor",gr);return t.every(Tn)&&(t.some(s=>s.kind!=="text")||t.map(s=>s.value??"").join("")!==e)?t:null}function ll(e){return e.includes("{{")?ae.parseTemplate(e,"editor",gr).map(t=>t.kind==="text"?t.value??"":ae.serializeTemplate([t])).join(""):e}function Xn(e){if(lt(e))return{parts:[],sealed:e};if(Ye(e))return{parts:e.parts.map(s=>({...s})),sealed:null};const t=typeof e=="string"?e:"";return{parts:t?rt(t):[],sealed:null}}function cl(e,t){let s="";for(const o of e)switch(o.kind){case"text":s+=ll(o.value??"");break;case"var":case"render":{const r=yr(o.ref??"").find(a=>a in t);s+=r===void 0?"":t[r];break}case"secret":s+="•••";break;case"expr":s+=ae.serializeTemplate([o]);break}return s}const Ct="var.",Ao="vars.",Zn="documents.",Qn="const.",es="state.";function xr(e){return e==="state"||e==="vars"?"var":e.startsWith(Ao)?Ct+e.slice(Ao.length):e.startsWith(es)?Ct+e.slice(es.length):e}function ul(e){return e.startsWith(es)?3:e.startsWith(Ct)?2:1}function vr(e){return e.rank>0?e.value:Object.fromEntries(Array.from(e.children,([t,s])=>[t,vr(s)]))}function As(e,t,s,o){const r={children:new Map,rank:0},a={},i={};for(const[w,h]of Object.entries(e??{})){const g=xr(w);if(g.startsWith(Ct)){const y=g.slice(Ct.length),x=ul(w);let C=r;for(const E of y.split(".")){let S=C.children.get(E);S||(S={children:new Map,rank:0},C.children.set(E,S)),C=S}x>=C.rank&&(C.value=h,C.rank=x)}else g.startsWith(Zn)?a[g.slice(Zn.length)]=h:g.startsWith(Qn)&&(i[g.slice(Qn.length)]=h)}const l=vr(r),u=(t==null?void 0:t.steps)??{},c=e??{},d=Object.hasOwn(c,"foreach.item"),p=typeof c["foreach.index"]=="number",f=t==null?void 0:t.foreach,m=f?{...f}:d||p?{...d?{item:c["foreach.item"]}:{},...p?{index:c["foreach.index"]}:{}}:void 0;return{...m?{foreach:m}:{},vars:l,state:l,documents:a,constants:i,steps:u,nodes:u,trigger:(t==null?void 0:t.trigger)??{},flat:e??{},...s?{config:s}:{},...o?{meta:o}:{}}}function dl(e,t){const s=t.split(".");let o=e;for(const r of s){if(o===null||typeof o!="object")return{present:!1,value:void 0};if(!(r in o))return{present:!1,value:void 0};o=o[r]}return{present:!0,value:o}}const pl=/^(?:nodes|steps)\.[^.]+\.(?:meta\.)?config(?:\.|$)/,fl=/^(?:nodes|steps)\.([^.]+)\.meta(?:\.|$)/;function hl(e,t,s){var r;if(!t&&!s)return e;const o={...e};for(const a of new Set([...Object.keys(s??{}),...Object.keys(t??{})])){const i=t==null?void 0:t[a];o[a]={...e[a],meta:{...s==null?void 0:s[a],...(r=e[a])==null?void 0:r.meta,...i?{config:i}:{}},...i?{config:i}:{}}}return o}function jr(e,t){var f;const s=xr(e);if(t.flat&&(s.startsWith(Ct)||s.startsWith(Zn)||s.startsWith(Qn))){const m=yr(e).find(w=>Object.hasOwn(t.flat,w));if(m!==void 0)return{status:"resolved",ref:e,value:t.flat[m]}}const{vars:o,constants:r,config:a,meta:i,...l}=t,u=hl(t.nodes??t.steps,a,i),c={...l,var:o,...r?{const:r}:{},nodes:u,steps:u},d=dl(c,s);if(d.present)return{status:"resolved",ref:e,value:d.value};if(pl.test(s))return{status:"at-run",ref:e};const p=(f=fl.exec(s))==null?void 0:f[1];return p!==void 0&&(i!=null&&i[p])?{status:"at-run",ref:e}:{status:"unresolved",ref:e}}function Eo(e,t){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return jr(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 Es(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function Ts(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function Rs(e,t){if(lt(e))return[{status:"masked"}];if(Ye(e))return e.parts.map(s=>Eo(s,t));if(typeof e=="string"){const s=Rn(e);if(s)return s.map(o=>Eo(o,t))}return Es(e)?[jr(String(e.$),t)]:Ts(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function ts(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object")return!1;const s=Array.isArray(e),o=Array.isArray(t);if(s!==o)return!1;if(s){const u=e,c=t;return u.length===c.length&&u.every((d,p)=>ts(d,c[p]))}const r=e,a=t,i=Object.keys(r),l=Object.keys(a);return i.length===l.length&&i.every(u=>u in a&&ts(r[u],a[u]))}function Nr(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 wl(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(Nr(e))}function ml(e){return e.length===1?Nr(e[0]):e.map(wl).join("")}function Jt(e,t){return ml(Rs(e,t))}function bl(e,t){const s={};for(const o of e)s[o.key||"(no key)"]=Jt(o.value,t);return s}const On=b.forwardRef(function(t,s){const{label:o,children:r,icon:a,iconSize:i,title:l,onClick:u,disabled:c,className:d,danger:p,...f}=t,m=r??(a?n.jsx(le.Icon,{name:a,size:i??16}):null);return n.jsx("button",{ref:s,type:"button",className:["w6w-icon-button",p?"w6w-icon-button-danger":"",d??""].filter(Boolean).join(" "),title:l??o,"aria-label":o,"aria-pressed":f["aria-pressed"],"aria-expanded":f["aria-expanded"],"aria-controls":f["aria-controls"],disabled:c,onClick:u,"data-testid":f["data-testid"],children:m})});On.displayName="IconButton";const yl={default:"",wide:" w6w-modal-wide",xl:" w6w-modal-xl",full:" w6w-modal-full",fullscreen:" w6w-modal-fullscreen"};function ke({title:e,ariaLabel:t,onClose:s,children:o,size:r="default",titleIcon:a,subtitle:i,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 p=m=>{m.preventDefault(),s()},f=m=>{if(m.target!==d)return;const w=d.getBoundingClientRect();(m.clientX<w.left||m.clientX>w.right||m.clientY<w.top||m.clientY>w.bottom)&&s()};return d.addEventListener("cancel",p),d.addEventListener("click",f),()=>{d.removeEventListener("cancel",p),d.removeEventListener("click",f)}},[s]),n.jsx("div",{className:"w6w-modal-backdrop",children:n.jsxs("dialog",{ref:u,className:`w6w-modal${yl[r]}`,"aria-label":t??(typeof e=="string"?e:void 0),children:[n.jsxs("div",{className:"w6w-modal-header",children:[n.jsxs("h3",{className:"w6w-modal-title",children:[a,n.jsx("span",{children:e}),i&&n.jsx("span",{className:"w6w-modal-subtitle",children:i})]}),l]}),o]})})}const Os=new Set(["nodes","steps","state","var","vars","const","inputs","output","trigger","foreach","documents"]),gl=/[=<>]|!=|&&|\|\||\?\?/,un=e=>gl.test(e)||/^\s*\(*\s*!/.test(e),To=e=>ae.expressionReferences(e).some(un);function xl(e,t){var a,i,l;const[s,...o]=e.split(".");if(s==="secrets")throw new Error("Secrets can be inserted into text, but cannot be used in comparisons.");if(Os.has(s))return e;const r=[...(a=t.steps)!=null&&a.some(u=>u.id===s)?[`nodes.${s}.output`]:[],...(i=t.vars)!=null&&i.includes(s)?[`var.${s}`]:[],...(l=t.constants)!=null&&l.includes(s)?[`const.${s}`]:[]];if(r.length>1)throw new Error(`“${s}” is ambiguous. Select the field from the sources.`);if(r.length===0)throw new Error(`Unknown field “${s}”. Select a source, or put text values in quotes.`);return[r[0],...o].join(".")}function Lt(e,t){var c,d,p,f,m;const s={parts:e,error:null},o=e.flatMap(w=>w.kind==="text"?rt(w.value??""):[w]);if(o.some(w=>w.kind==="render"))return s;if(o.length===1&&o[0].kind==="expr"&&!To(o[0].expr))return{parts:o,error:null};let r=o.map(w=>{if(w.kind==="text")return w.value??"";if(w.kind==="secret")return`{{ secrets.${w.ref??""} }}`;if(w.kind==="expr"){if(To(w.expr)){const g=ae.serializeTemplate([w]);if(!g.startsWith("{{ ="))return`(${g.slice(2,-2).trim()})`}const h=ae.formatReadableExpression(w.expr);return h===null?ae.serializeTemplate([w]):`(${h})`}return un(w.ref??"")?w.ref??"":`{{ ${w.ref??""} }}`}).join("").trim();if(!un(r))return s;const a=/^\{\{([^{}]+)\}\}$/.exec(r);a&&un(a[1])&&(r=a[1].trim());const i=r.replace(/^[\s(!]+/,""),l=(c=/^(?:\{\{\s*)?([A-Za-z_$][\w$-]*)/.exec(i))==null?void 0:c[1],u=i.startsWith("{{")||l!==void 0&&(Os.has(l)||l==="secrets"||((d=t.steps)==null?void 0:d.some(w=>w.id===l))||((p=t.vars)==null?void 0:p.includes(l))||((f=t.constants)==null?void 0:f.includes(l)));if(!u&&!/^(?:["']|-?\d|true\b|false\b|null\b)/.test(i))return s;if(u&&!/^\s*\(*\s*!/.test(r)){const w=(m=/^(?:\{\{[^{}]+\}\}|[A-Za-z_$][\w$-]*(?:\.[\w$-]+)*)/.exec(i))==null?void 0:m[0];if(w){const h=i.slice(w.length).replace(/^[\s)]+/,"");if(!/^(?:[=<>(]|!=|&&|\|\||\?\?)/.test(h)||/^<\/?[A-Za-z][^>]*>/.test(h))return s}}try{return{parts:[{kind:"expr",expr:ae.parseReadableExpression(r,h=>xl(h,t))}],error:null}}catch(w){return{parts:o,error:w instanceof Error?w.message:"Check the expression."}}}function vl(e){return[...new Set(e.flatMap(t=>t.kind==="expr"?ae.expressionReferences(t.expr):(t.kind==="var"||t.kind==="render")&&t.ref?[t.ref]:[]))]}function jl(e){return e.replace(/^(?:vars|state)(?=\.|$)/,"var").replace(/^steps(?=\.|$)/,"nodes")}function Nl(e){const t=Object.create(null);for(const[s,o]of Object.entries(e).sort(([r],[a])=>r.split(".").length-a.split(".").length)){const r=jl(s).split(".");if(!Os.has(r[0])||r.some(i=>["__proto__","constructor","prototype"].includes(i)))continue;let a=t;for(const i of r.slice(0,-1)){const l=a[i],u=l&&typeof l=="object"?{...l}:{};a[i]=u,a=u}a[r[r.length-1]]=o}return t.steps=t.nodes,t.vars=t.var,t.state=t.var,t}function kl(e,t={},s={}){const o={...t};for(const[i,l]of Object.entries(s))try{o[i]=JSON.parse(l)}catch{o[i]=l}const r=Nl(o),a=Object.fromEntries(Object.entries(o).map(([i,l])=>[i,typeof l=="string"?l:JSON.stringify(l)]));return e.map(i=>{if(i.kind!=="expr"||ae.formatReadableExpression(i.expr)===null)return cl([i],a);if(ae.expressionReferences(i.expr).some(c=>!c||c.split(".")[0]==="secrets"))return"••••";const u=ae.evaluate(i.expr,r);return typeof u=="string"?u:JSON.stringify(u)??""}).join("")}const Sl=/^(?:nodes|steps)\.([^.]+)\.output(?:\.(.+))?$/,Cl=/^(?:nodes|steps)\.([^.]+)\.meta\.(app|version|action|connectionId)$/,nt=e=>{if(e.startsWith("var."))return e.slice(4);if(e.startsWith("vars."))return e.slice(5);if(e.startsWith("const."))return e.slice(6);const t=Sl.exec(e);if(t)return t[2]?`${t[1]}.${t[2]}`:t[1];const s=Cl.exec(e);return s?`${s[1]} meta · ${s[2]}`:e};function Al(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 El(e){const t=e.op==="or"?"||":"??",s=e.operands.map(o=>{const r=Al(o);return r!==void 0?nt(r):JSON.stringify(o)}).join(` ${t} `);return s.length>40?`${s.slice(0,40)}…`:s}const Tl=/[.{}]/;function Nt(e){return e===""||e!==e.trim()?!1:!Tl.test(e)}function on(e){return e.split(".").every(Nt)}function Ro(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 o=s.key.split(".");let r=0,a=0;for(let i=1;i<o.length;i++)t.has(o.slice(0,i).join("."))&&(r++,a=i);return{field:s,depth:r,name:o.slice(a).join(".")}})}function Wt(e,t,{renderToggle:s}={}){const o=e.createElement("span");o.contentEditable="false",o.className=`w6w-expr-chip w6w-expr-chip-${t.kind}`,o.setAttribute("data-kind",t.kind);const r=e.createElement("span");r.className="w6w-expr-chip-sigil";const a=e.createElement("span");if(a.className="w6w-expr-chip-label",t.kind==="var")o.setAttribute("data-ref",t.ref??""),r.textContent="◆",a.textContent=nt(t.ref??""),o.title=`Variable: ${t.ref??""}`;else if(t.kind==="render")o.setAttribute("data-ref",t.ref??""),r.textContent="▤",a.textContent=nt(t.ref??""),o.title=`Render as template: ${t.ref??""}`;else if(t.kind==="secret")o.setAttribute("data-ref",t.ref??""),r.textContent="🔒",a.textContent=t.ref??"",o.title=`Secret: ${t.ref??""}`;else{const l=typeof t.expr=="string"?t.expr:JSON.stringify(t.expr??"");o.setAttribute("data-expr",l),r.textContent="ƒ";const u=ae.parseCoalesceChain(t.expr);if(u)a.textContent=El(u),o.title=`Expression: ${ae.serializeTemplate([t])}`;else{const c=ae.formatReadableExpression(t.expr,nt);a.textContent=c??(l.length>24?`${l.slice(0,24)}…`:l||"expr"),o.title=`Expression: ${c??l}`}}if(o.append(r,a),(t.kind==="var"||t.kind==="render")&&s){const l=e.createElement("span");l.className="w6w-expr-chip-toggle",l.setAttribute("data-render-toggle","1"),l.setAttribute("role","button");const u=t.kind==="render"?"Stop rendering as a template":"Render this as a template";l.setAttribute("aria-label",u),l.title=u,l.textContent="⇄",o.append(l)}const i=e.createElement("span");return i.className="w6w-expr-chip-x",i.setAttribute("data-x","1"),i.setAttribute("role","button"),i.setAttribute("aria-label","Remove"),i.textContent="×",o.append(i),o}const kr=new Set(["div","p"]);function Sr(e){const t=e.getAttribute("data-kind");if(t==="var"||t==="secret"||t==="render")return{kind:t,ref:e.getAttribute("data-ref")??""};if(t==="expr"){const s=e.getAttribute("data-expr")??"";let o=s;try{o=JSON.parse(s)}catch{o=s}return{kind:"expr",expr:o}}return null}function Mt(e){const t=[],s=a=>{if(!a)return;const i=t[t.length-1];i&&i.kind==="text"?i.value=(i.value??"")+a:t.push({kind:"text",value:a})},o=(a,i)=>{if(a.nodeType===Node.TEXT_NODE){s(a.textContent??"");return}if(a.nodeType!==Node.ELEMENT_NODE)return;const l=a,u=Sr(l);if(u){t.push(u);return}const c=(l.tagName??"").toLowerCase();if(c==="br"){i||s(`
|
|
3
|
+
`);return}const d=kr.has(c);d&&t.length>0&&s(`
|
|
4
|
+
`),r(l,d)},r=(a,i)=>{const l=Array.from(a.childNodes);l.forEach((u,c)=>o(u,i&&c===l.length-1))};return r(e,!0),t}const Cr=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function Ar(e){Cr(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function Rl(e){const t=e.ownerDocument.getSelection(),s=t!=null&&t.rangeCount?t.getRangeAt(0):null;if(!s||!e.contains(s.endContainer))return e;let o=s.endContainer;for(;o&&o!==e;){if(o.nodeType===Node.ELEMENT_NODE){const r=o;if(kr.has((r.tagName??"").toLowerCase()))return r}o=o.parentNode}return e}function Er(e){Ar(Rl(e))}const Ol=e=>e.getAttribute("aria-multiline")!=="false";function Tr(e,t,s){var a;const o=e.ownerDocument;e.textContent="";for(const i of t)i.kind==="text"?i.value&&e.appendChild(o.createTextNode(i.value)):e.appendChild(Wt(o,i,s));const r=t[t.length-1];(r==null?void 0:r.kind)==="text"&&((a=r.value)!=null&&a.endsWith(`
|
|
5
|
+
`))&&Ol(e)&&Ar(e)}function Is(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 Dt(e,t){const s=e.ownerDocument,o=s.getSelection(),r=o!=null&&o.rangeCount?o.getRangeAt(0):null;if(r&&e.contains(r.commonAncestorContainer)){r.deleteContents(),r.insertNode(t);const a=s.createRange();a.setStartAfter(t),a.collapse(!0),o==null||o.removeAllRanges(),o==null||o.addRange(a)}else Cr(e.lastChild)?e.insertBefore(t,e.lastChild):e.appendChild(t),Is(e);e.focus()}function Rr(e,t={}){const s=e.ownerDocument,o=s.getSelection();if(!o||o.rangeCount===0||!o.isCollapsed)return!1;const r=o.getRangeAt(0),a=r.startContainer;if(a.nodeType!==Node.TEXT_NODE||!e.contains(a))return!1;const i=r.startOffset,l=a.textContent??"";if(i<2||l.slice(i-2,i)!=="}}")return!1;const u=l.lastIndexOf("{{",i-2);if(u===-1)return!1;const c=l.slice(u,i),d=rt(c);if(d.length!==1||d[0].kind==="text")return!1;let p=0;for(;u-1-p>=0&&l[u-1-p]==="\\";)p+=1;if(p%2===1)return!1;const f=s.createRange();f.setStart(a,u),f.setEnd(a,i),f.deleteContents();const m=Wt(s,d[0],t);f.insertNode(m);const w=s.createRange();return w.setStartAfter(m),w.collapse(!0),o.removeAllRanges(),o.addRange(w),!0}function Or(e){const t=Sr(e);if(!t)return null;const s=t.kind==="expr"&&!ae.parseCoalesceChain(t.expr)?ae.formatReadableExpression(t.expr):null,o=e.ownerDocument.createTextNode(s??ae.serializeTemplate([t]));return e.replaceWith(o),o}function Il(e,t){let s=!1;for(let o=0;o<t&&o<e.length;o++){const r=e[o];if(s&&r==="\\"){o++;continue}r==='"'&&(s=!s)}return s}function $l(e){const t=e.split(".").filter(o=>o!==""),s=t[t.length-1]??"value";return(s==="output"||s==="meta")&&t.length>=3?s==="meta"?`${t[t.length-2]}_meta`:t[t.length-2]:s}function Pl(e,t){const s=[];let o=!1;for(let a=0;a<t&&a<e.length;a++){const i=e[a];if(o){i==="\\"?a++:i==='"'&&(o=!1);continue}i==='"'?o=!0:i==="{"||i==="["?s.push(i):(i==="}"||i==="]")&&s.pop()}const r=s[s.length-1];return r==="{"||r==="["?r:null}function _l(e,t){if(!e||!Object.hasOwn(e,t))return t;let s=2;for(;Object.hasOwn(e,`${t}_${s}`);)s++;return`${t}_${s}`}function Oo(e,t,s,o){var g;const r=o?JSON.stringify(o.value)??"null":"",a=o?JSON.stringify(typeof o.value=="string"?o.value:r).slice(1,-1):`{{ ${s} }}`,i=o?r:JSON.stringify(a),l=(y,x)=>({text:e.slice(0,y)+x+e.slice(y),caret:y+x.length});if(Il(e,t))return l(t,a);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,p=()=>`${JSON.stringify(_l(d,$l(s)))}: ${i}`,f=e.slice(0,t).trimEnd(),m=f[f.length-1],w=e.slice(t).trimStart()[0],h=Pl(e,t);if(m===":"||m==="["||m===","&&h==="[")return l(t,i+(m!==":"&&w!==void 0&&w!=="]"?", ":""));if(m==="{"||m===","&&h==="{"){const y=w!==void 0&&w!=="}"?", ":"";return l(t,(m===","?" ":"")+p()+y)}if(c&&(d||Array.isArray(u))){const y=e.lastIndexOf(d?"}":"]"),x=e.slice(0,y).trimEnd(),C=x.endsWith(d?"{":"["),E=d?p():i,S=e.slice(x.length,y);if(S.includes(`
|
|
6
|
+
`)){const A=C?`${S.slice(S.lastIndexOf(`
|
|
7
|
+
`)+1)} `:((g=/^\s*/.exec(x.slice(x.lastIndexOf(`
|
|
8
|
+
`)+1)))==null?void 0:g[0])??"",$=`${C?"":","}
|
|
9
|
+
${A}${E}`;return{text:x+$+e.slice(x.length),caret:x.length+$.length}}const j=`${C?"":","} ${E} `,N=x.length;return{text:e.slice(0,N)+j+e.slice(y),caret:N+j.length-1}}return l(t,i)}const Fl=/^\{\{\s*((?:var|vars|const|steps|nodes|trigger|foreach|inputs|output|documents)(?:\.[^\s{}]+)?)\s*\}\}$/;function Ll(e){const t=Fl.exec(e.trim());return t?`{{ ${t[1]} }}`:null}function ct(e){if(typeof e=="string"){if(!e.includes("{{"))return null;const t=rt(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 Ml(e){var s;const t={};for(const[o,r]of Object.entries(e??{})){const a=/^(?:steps|nodes)\.([^.]+)\.output$/.exec(o);if(a){t[a[1]]={...t[a[1]],output:r};continue}const i=/^(?:steps|nodes)\.([^.]+)\.meta\.([^.]+)$/.exec(o);if(i){t[s=i[1]]??(t[s]={});const l=t[i[1]];l.meta={...l.meta,[i[2]]:r}}}return{steps:t}}function ns(e,t){if(typeof e=="string"){const s=Rn(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=>ns(s,t));if(e!==null&&typeof e=="object"){const s=Object.keys(e);return s.length===1&&s[0]==="$"&&typeof e.$=="string"?t(e):Object.fromEntries(Object.entries(e).map(([o,r])=>[o,ns(r,t)]))}return e}function Qt({value:e,masked:t,multiline:s,options:o,fieldLabel:r,onSave:a,onClose:i,mode:l,jsonValue:u,onSaveJson:c,whole:d,startingState:p,jsonProblem:f,title:m}){var Ee;const w=l==="json-binding",h=w&&p===!0,[g,y]=b.useState("ref"),[x,C]=b.useState(()=>u===void 0?"":JSON.stringify(u,null,2)),E=b.useRef(null),S=b.useRef(!1),j=b.useMemo(()=>{if(x.trim()==="")return{ok:!1};try{return{ok:!0,value:JSON.parse(x)}}catch{return{ok:!1}}},[x]),N=h?(f==null?void 0:f(x))??null:null,A=h?(x.trim()===""||j.ok)&&N===null:j.ok,$=()=>As(o.sampleValues,Ml(o.sampleValues),o.nodeConfig,o.nodeMeta),P=w?j.ok?JSON.stringify(ns(j.value,k=>Jt(k,$())),null,2):x.trim()===""?"":"Invalid JSON":"",R=k=>{const L=E.current,H=L?L.state.doc.toString():x;if(h){const Be=g==="value"?{value:Jt(`{{ ${k} }}`,$())??null}:void 0,po=H.trim()===""?"{}":H,ai=S.current&&L?L.state.selection.main.head:po.length,qn=Oo(po,ai,k,Be);if(!L){C(qn.text);return}L.dispatch({changes:{from:0,to:H.length,insert:qn.text},selection:{anchor:qn.caret}}),L.focus();return}let te=null;try{te=H.trim()===""?null:ct(JSON.parse(H))}catch{te=null}let fe=!1;if(d)try{const Be=JSON.parse(H);fe=Array.isArray(Be)?Be.length===0:typeof Be=="object"&&Be!==null&&Object.keys(Be).length===0}catch{fe=!1}if(H.trim()===""||te!==null||fe){c==null||c(`{{ ${k} }}`),i();return}if(!L)return;const we=S.current?L.state.selection.main.head:H.length,oe=Oo(H,we,k);L.dispatch({changes:{from:0,to:H.length,insert:oe.text},selection:{anchor:oe.caret}}),L.focus()},[I,T]=b.useState(()=>Lt(Xn(e).parts,o).parts),_=b.useMemo(()=>Lt(I,o),[I,o]),[q,U]=b.useState(0),B=b.useRef(null),F=b.useRef(!1),[O,K]=b.useState({}),[G,Q]=b.useState(null),[M,X]=b.useState(()=>new Set),J=k=>{X(L=>{const H=new Set(L);return H.has(k)?H.delete(k):H.add(k),H})},[W,ne]=b.useState("auto");b.useLayoutEffect(()=>{const k=B.current;k&&(Tr(k,I,{renderToggle:!0}),F.current&&(F.current=!1,Is(k),k.focus()))},[q]);const ee=()=>{const k=B.current;k&&T(Mt(k))},v=k=>{const L=B.current;L&&(Dt(L,Wt(L.ownerDocument,k,{renderToggle:!0})),T(Mt(L)))},D=I.some(k=>k.kind==="render"),Y=(k,{restoreFocus:L})=>{T(Lt(rt(k),o).parts),U(H=>H+1)},re=()=>{const k=B.current,L=Lt(k?Mt(k):I,o);L.error||(a==null||a(cn(L.parts)),i())},z=()=>{Q(null),F.current=!0,U(k=>k+1)},ge=o.vars??[],me=o.constants??[],xe=o.secrets??[],Ne=o.inputs??[],be=o.documents??[],ce=o.steps??[],ie=o.nodeConfigs??[],pe=o.loop,Te=new Map(ie.map(k=>[k.id,k.keys.filter(Nt)]).filter(([,k])=>k.length>0)),Re=o.nodeMeta??{},Pt=k=>Dl.filter(([L])=>Wl.has(L)?he(k):Object.hasOwn(Re[k]??{},L)),xt=ce.filter(k=>k.hasMeta===!0).map(k=>k.id),he=k=>{var H;if(xt.includes(k))return!0;const L=(H=Re[k])==null?void 0:H.app;return typeof L=="string"&&!st(L)},$e=k=>Pt(k).map(([L,H])=>se(H,{kind:"var",ref:`nodes.${k}.meta.${L}`},"w6w-exprmodal-field",null)),Ve=[...new Set([...Object.keys(Re),...xt,...Te.keys()])],Le=ce.length>0||!!o.hasTrigger,Me=!h&&(Le||!!pe),Pe=h?[]:(((Ee=o.stateShape)==null?void 0:Ee.fields)??[]).filter(k=>on(k.key)),ut=[...Me?["state"]:[],...Pe.length>0?["runstate"]:[],...Ve.length>0?["meta"]:[],...o.inputs!==void 0?["inputs"]:[],"vars",...me.length>0?["consts"]:[],...!w||h?["docs"]:[],...w?[]:["secrets"]],Ze=W==="auto"||W!==null&&!ut.includes(W)?ut.find(k=>k!=="meta")??null:W,Se=k=>({open:Ze===k,onToggle:()=>ne(Ze===k?null:k)}),Oe=((pe==null?void 0:pe.itemOutputs)??[]).filter(k=>k.path?on(k.key):Nt(k.key)),Ce=(o.eventOutputs??[]).filter(k=>k.path?on(k.key):Nt(k.key)),He=ae.serializeTemplate(_.parts),_t=b.useMemo(()=>{const k={};for(const[L,H]of Object.entries(o.sampleValues??{}))k[L]=typeof H=="string"?H:JSON.stringify(H);return{...k,...O}},[o.sampleValues,O]),De=b.useMemo(()=>vl(_.parts),[_.parts]),V=b.useMemo(()=>{if(_.error)return"";try{return kl(_.parts,o.sampleValues,O)}catch{return He}},[_,o.sampleValues,O,He]),ue=b.useMemo(()=>{var L;const k=new Set;for(const H of De){if(O[H]!==void 0)continue;const te=(L=o.valueSources)==null?void 0:L[H];te==="sample"?k.add("example from the app"):te==="persisted"&&k.add("from last test")}return[...k]},[De,O,o.valueSources]),se=(k,L,H,te,fe=!1,we,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 ${H}${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)??k}`,"aria-label":we,onClick:()=>w?L.kind==="var"&&R(L.ref??""):v(L),children:[te!==null&&n.jsx("span",{className:"w6w-expr-chip-sigil",children:te}),n.jsx("span",{className:"w6w-exprmodal-source-label",children:k}),(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"})]}),!w&&n.jsx(On,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>v(L)})]},`${L.kind}:${L.ref??k}`),Qe=M.has("loop:item"),dt=se("Current item",{kind:"var",ref:"foreach.item"},"w6w-expr-chip-var","↻"),et=(k,L)=>{if(L.length===0)return null;const H=M.has(`mcfg:${k}`);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-exprmodal-source-row",children:n.jsxs("button",{type:"button",className:"w6w-exprmodal-tree-toggle","data-testid":"expr-config-toggle","aria-expanded":H,title:H?"Hide config":"Show config",onClick:()=>J(`mcfg:${k}`),children:[n.jsx("span",{className:"w6w-exprmodal-tree-caret","aria-hidden":"true",children:H?"▾":"▸"}),"config"]})}),H&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-config-fields",children:L.map(te=>se(te,{kind:"var",ref:`nodes.${k}.meta.config.${te}`},"w6w-exprmodal-field",null))})]})},We=(k,L,H=`nodes.${k}.output`)=>Ro(L).map(({field:te,depth:fe,name:we})=>{const oe=`${H}.${te.key}`;return se(we,{kind:"var",ref:oe},"w6w-exprmodal-field",null,!1,void 0,{name:nt(oe),depth:fe,declaredOnly:te.declaredOnly===!0})}),Z=k=>k==="fresh"||k==="persisted"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:k==="fresh"?"Fields from the last test run":"Fields from last test"}):k==="declared"||k==="sample"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":`expr-fields-from-${k}`,children:k==="declared"?"declared by the app":"example from the app"}):null,de=k=>{const L=`mnode:${k}`,H=M.has(L);return n.jsxs(b.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row","data-testid":"expr-metadata-node",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-metadata-node-toggle","aria-expanded":H,"aria-label":H?`Hide ${k} metadata`:`Show ${k} metadata`,title:H?"Hide metadata":"Show metadata",onClick:()=>J(L),children:H?"▾":"▸"}),se(k,{kind:"var",ref:`nodes.${k}.meta`},"w6w-expr-chip-var w6w-exprmodal-node",null,!0)]}),H&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-metadata-fields",children:[$e(k),et(k,Te.get(k)??[])]})]},L)};return n.jsxs(ke,{title:m??(w?"Edit JSON value":"Edit expression"),subtitle:r?n.jsx("code",{children:r}):void 0,onClose:i,size:"full",headerRight:w?n.jsxs("div",{className:"w6w-exprmodal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:i,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"expr-json-save",disabled:!A,title:A?"Save the composed JSON":N??"Compose valid JSON to save",onClick:()=>{A&&(c==null||c(j.ok?j.value:void 0),i())},children:"Save"})]}):n.jsxs("div",{className:"w6w-exprmodal-actions",children:[!t&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:D,title:D?"Unavailable — a render part has no plain-text form. Flip it back to a variable first.":"Close the expression and keep the text as a literal value",onClick:()=>{a==null||a(ae.serializeTemplate(I)),i()},children:"Use a plain value"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:i,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:re,"data-testid":"expr-save",disabled:_.error!==null,children:"Save"})]}),children:[n.jsxs("div",{className:"w6w-exprmodal",children:[n.jsxs("aside",{className:"w6w-exprmodal-sources",children:[h&&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(([k,L,H])=>n.jsx("button",{type:"button","aria-pressed":g===k,"data-testid":`expr-insert-as-${k}`,title:H,className:`w6w-btn w6w-btn-sm${g===k?"":" w6w-btn-ghost"}`,onClick:()=>y(k),children:L},k))]}),w&&!h&&!Me&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),Me&&n.jsxs(tt,{label:"Previous steps",...Se("state"),children:[pe&&n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":"expr-loop-group",children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:"Loop"}),Oe.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[dt,n.jsx(rn,{count:Oe.length,open:Qe,onToggle:()=>J("loop:item")})]}):dt,Oe.length>0&&Qe&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-loop-fields",children:Oe.map(k=>{const L=`foreach.item.${k.key}`;return se(k.key,{kind:"var",ref:L},"w6w-exprmodal-field",null)})}),se("Index",{kind:"var",ref:"foreach.index"},"w6w-expr-chip-var","#"),(pe.outer??[]).map(k=>{const L=k.name??k.foreachId,H=`foreach.loops.${k.foreachId}`;return n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":`expr-loop-outer-${k.foreachId}`,children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:L}),se(`${L} item`,{kind:"var",ref:`${H}.item`},"w6w-expr-chip-var","↻"),se(`${L} index`,{kind:"var",ref:`${H}.index`},"w6w-expr-chip-var","#")]},k.foreachId)})]}),o.hasTrigger&&(Ce.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":M.has("event"),"aria-label":M.has("event")?"Hide fields":"Show fields",title:M.has("event")?"Hide fields":"Show fields",onClick:()=>J("event"),children:M.has("event")?"▾":"▸"}),se("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡",!0)]}),M.has("event")&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-event-fields",children:[Z(o.eventOutputsFrom),We("",Ce,"trigger.event")]})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),se("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡")]})),ce.map(k=>{const L=(k.outputs??[]).filter(we=>we.path?on(we.key):Nt(we.key)),H=`step:${k.id}`,te=M.has(H),fe=se(k.label??k.id,{kind:"var",ref:`nodes.${k.id}.output`},"w6w-expr-chip-var w6w-exprmodal-node",null,L.length>0);return w?n.jsxs(b.Fragment,{children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:k.label??k.id}),se("Entire output",{kind:"var",ref:`nodes.${k.id}.output`},"w6w-expr-chip-var",null,!1,`Entire output of ${k.label??k.id}`),k.needsTest&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),L.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":te,"aria-label":te?"Hide fields":"Show fields",title:te?"Hide fields":"Show fields",onClick:()=>J(H),children:te?"▾":"▸"}),n.jsx(rn,{count:L.length,open:te,onToggle:()=>J(H)})]}),te&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[Z(k.outputsFrom),We(k.id,L)]})]})]},k.id):n.jsxs(b.Fragment,{children:[L.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":te,"aria-label":te?"Hide fields":"Show fields",title:te?"Hide fields":"Show fields",onClick:()=>J(H),children:te?"▾":"▸"}),fe,n.jsx(rn,{count:L.length,open:te,onToggle:()=>J(H)})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),fe]}),k.needsTest&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),L.length>0&&te&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[Z(k.outputsFrom),We(k.id,L)]})]},k.id)})]}),Pe.length>0&&n.jsxs(tt,{label:"State",testId:"expr-state-group",...Se("runstate"),children:[se("state",{kind:"var",ref:"state"},"w6w-expr-chip-var","◇",!0),n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-state-fields",children:Ro(Pe).map(({field:k,depth:L,name:H})=>{const te=`state.${k.key}`;return se(H,{kind:"var",ref:te},"w6w-exprmodal-field",null,!1,void 0,{name:nt(te),depth:L,somePaths:k.paths==="some"})})})]}),Ve.length>0&&n.jsx(tt,{label:"Metadata",testId:"expr-metadata-group",...Se("meta"),children:Ve.map(k=>de(k))}),n.jsxs(n.Fragment,{children:[o.inputs!==void 0&&n.jsxs(tt,{label:"Inputs",...Se("inputs"),children:[Ne.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),Ne.map(k=>se(k,{kind:"var",ref:`inputs.${k}`},"w6w-expr-chip-var","⇥"))]}),n.jsxs(tt,{label:"Variables",...Se("vars"),action:o.createVar&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-var",onClick:()=>Q("var"),children:"+ Add"}),children:[ge.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),ge.map(k=>se(k,{kind:"var",ref:`var.${k}`},"w6w-expr-chip-var","◆"))]}),me.length>0&&n.jsx(tt,{label:"Constants",testId:"expr-constants-group",...Se("consts"),children:me.map(k=>se(k,{kind:"var",ref:`const.${k}`},"w6w-expr-chip-var","◈"))})]}),(!w||h)&&n.jsxs(tt,{label:"Documents",...Se("docs"),children:[be.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),be.map(k=>{const L=(k.fields??[]).filter(we=>Nt(we.key)),H=`doc:${k.key}`,te=M.has(H),fe=se(k.key,{kind:"var",ref:`documents.${k.key}`},"w6w-expr-chip-var","▦",L.length>0);return n.jsxs(b.Fragment,{children:[L.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[fe,n.jsx(rn,{count:L.length,open:te,onToggle:()=>J(H)})]}):fe,L.length>0&&te&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:L.map(we=>{const oe=`documents.${k.key}.${we.key}`;return n.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[se(we.key,{kind:"var",ref:oe},"w6w-expr-chip-var","·"),!w&&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:()=>v({kind:"render",ref:oe}),children:"▤"})]},oe)})})]},k.key)})]}),!w&&n.jsxs(tt,{label:"Secrets",...Se("secrets"),action:o.createSecret&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm","data-testid":"expr-add-secret",onClick:()=>Q("secret"),children:"+ Add"}),children:[xe.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),xe.map(k=>se(k,{kind:"secret",ref:k},"w6w-expr-chip-secret","🔒"))]})]}),w&&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(ze,{value:x,onChange:C,height:"100%",minHeight:"0px","aria-label":"Compose JSON",placeholder:h?'{ "region": "us", "template": "{{ documents.welcome }}" }':'{ "key": "{{ nodes.step_1.output }}" }',onCreateEditor:k=>{E.current=k}})})]}),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:[" ",h?" — the state each run starts with, against the sample values":" — live preview against the sample values"]})]}),N&&n.jsx("span",{className:"w6w-muted w6w-small",role:"alert","data-testid":"expr-json-problem",children:N}),n.jsx(le.Copyable,{value:P??"",label:"Copy result",children:n.jsx("pre",{className:"w6w-exprmodal-result","data-testid":"expr-json-result",children:P})})]})]}),!w&&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:B,className:`w6w-exprmodal-chips${t?" is-masked":""}${I.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":_.error!==null,"aria-describedby":_.error?"expression-problem":void 0,spellCheck:!1,onInput:()=>{const k=B.current;k&&Rr(k,{renderToggle:!0}),ee()},onDoubleClick:k=>{const L=k.target;if(L.closest("[data-x]")||L.closest("[data-render-toggle]"))return;const H=L.closest(".w6w-expr-chip");if(!H)return;k.preventDefault();const te=Or(H);if(te){const fe=te.ownerDocument,we=fe.createRange();we.setStartAfter(te),we.collapse(!0);const oe=fe.getSelection();oe==null||oe.removeAllRanges(),oe==null||oe.addRange(we)}ee()},onBlur:()=>{const k=B.current;k&&Y(ae.serializeTemplate(Mt(k)),{restoreFocus:!1})},onPaste:k=>{var te;k.preventDefault();const L=B.current;if(!L)return;const H=((te=k.clipboardData)==null?void 0:te.getData("text/plain"))??"";for(const fe of rt(H))fe.kind==="text"?Dt(L,L.ownerDocument.createTextNode(fe.value??"")):Dt(L,Wt(L.ownerDocument,fe,{renderToggle:!0}));ee()},onClick:k=>{var fe;const L=k.target,H=L.closest("[data-x]");if(H){k.preventDefault(),(fe=H.closest(".w6w-expr-chip"))==null||fe.remove(),ee();return}const te=L.closest("[data-render-toggle]");if(te){k.preventDefault();const we=te.closest(".w6w-expr-chip");if(we){const oe=we.getAttribute("data-ref")??"",Be=we.getAttribute("data-kind")==="render"?"var":"render";we.replaceWith(Wt(we.ownerDocument,{kind:Be,ref:oe},{renderToggle:!0}))}ee()}},onKeyDown:k=>{if(k.key!=="Enter"||(k.preventDefault(),!s))return;const L=B.current;L&&(Dt(L,L.ownerDocument.createTextNode(`
|
|
10
|
+
`)),Er(L),ee())}}),n.jsxs("span",{className:"w6w-muted w6w-small",children:["Pick a field, then type ",n.jsx("code",{children:'== "value"'}),". Combine conditions with"," ",n.jsx("code",{children:"&&"})," or ",n.jsx("code",{children:"||"}),". Double-click a chip to edit it."]}),_.error&&n.jsx("span",{id:"expression-problem",role:"alert",className:"w6w-error",children:_.error})]}),De.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"]})]}),De.map(k=>n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:k}),n.jsx("input",{type:"text",value:O[k]??_t[k]??"",placeholder:"sample value",onChange:L=>K(H=>({...H,[k]:L.target.value}))})]},k))]}),n.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— live preview against the sample values"]})]}),n.jsx(le.Copyable,{value:V,readOnly:!0,children:n.jsx("pre",{className:"w6w-exprmodal-result",children:V||" "})}),ue.length>0&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-result-source",children:ue.join(" · ")})]})]})]}),G==="var"&&o.createVar&&n.jsx(Io,{kind:"var",onCreate:o.createVar,onClose:z}),G==="secret"&&o.createSecret&&n.jsx(Io,{kind:"secret",onCreate:o.createSecret,onClose:z})]})}function tt({label:e,open:t,onToggle:s,action:o,testId:r,children:a}){const i=b.useId(),l=b.useRef(null);return b.useLayoutEffect(()=>{l.current&&(l.current.inert=!t)},[t]),n.jsxs("div",{className:`w6w-exprmodal-group${t?" is-open":""}`,"data-testid":r,"data-section-open":t?"true":"false",children:[n.jsxs("div",{className:"w6w-exprmodal-group-head",children:[n.jsxs("button",{type:"button",className:"w6w-exprmodal-group-toggle","data-testid":"expr-section-toggle","aria-expanded":t,"aria-controls":i,onClick:s,children:[n.jsx("span",{className:"w6w-exprmodal-group-label",children:e}),n.jsx("span",{className:"w6w-exprmodal-group-caret","aria-hidden":"true",children:"›"})]}),o]}),n.jsx("div",{id:i,ref:l,className:"w6w-exprmodal-group-body","aria-hidden":!t,children:n.jsx("div",{className:"w6w-exprmodal-group-inner",children:a})})]})}function rn({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 Dl=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"],["subscriptionId","Subscription ID"],["url","Webhook URL"]],Wl=new Set(["app","version","action","connectionId"]);function Io({kind:e,onCreate:t,onClose:s}){const[o,r]=b.useState(""),[a,i]=b.useState(""),[l,u]=b.useState(""),[c,d]=b.useState(null),[p,f]=b.useState(!1),m=e==="var"?"variable":"secret";async function w(){d(null),f(!0);try{await t({name:o,value:a,description:l||void 0}),s()}catch(h){d(h.message)}finally{f(!1)}}return n.jsxs(ke,{title:`Add ${m}`,onClose:s,children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Name"}),n.jsx("input",{type:"text",value:o,onChange:h=>r(h.target.value),placeholder:e==="var"?"e.g. api_base_url":"e.g. openai_api_key",autoComplete:"off","data-testid":"expr-add-value-name",autoFocus:!0}),n.jsx("span",{className:"w6w-muted w6w-small",children:"Letters, digits, and underscores. Must start with a letter or underscore. Case-sensitive."})]}),n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Value"}),n.jsx("input",{type:e==="secret"?"password":"text",value:a,onChange:h=>i(h.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:h=>u(h.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:!o||!a||p,onClick:w,children:p?"Saving…":"Save"})]})]})}function ql(e,t){return t?e.filter(s=>s.id!==t):e}const ss=b.createContext({});function Ul({value:e,children:t}){const s=b.useContext(ss),o=b.useMemo(()=>({...s,...e}),[s,e]);return n.jsx(ss.Provider,{value:o,children:t})}function Xe(){return b.useContext(ss)}function zt({value:e,onChange:t,placeholder:s,masked:o,multiline:r,readOnly:a,options:i,"aria-label":l}){const[u,c]=b.useState(()=>Xn(e)),{parts:d,sealed:p}=u,[f,m]=b.useState(0),[w,h]=b.useState(!1),[g,y]=b.useState(!1),x=b.useRef(!1),C=b.useRef(null),E=b.useRef(null),S=Xe(),j={...S,...i??{}},N=S.sealSecret;b.useLayoutEffect(()=>{const I=C.current;!I||p||(Tr(I,d),(x.current||I.ownerDocument.activeElement===I)&&(I.focus(),Is(I),x.current=!1))},[f,p]);const A=()=>{const I=C.current;if(!I)return;const T=Mt(I);c(q=>({...q,parts:T}));const _=Lt(T,j);t(cn(_.parts))},$=async I=>{if(!N)return!1;h(!0);try{const T=await N(I);return x.current=!1,c({parts:[],sealed:T}),m(_=>_+1),t(T),!0}catch{return!1}finally{h(!1)}},P=I=>{var q;if(g||!o||a||w)return;const T=I.relatedTarget;if(T&&((q=E.current)!=null&&q.contains(T)))return;const _=cn(d);typeof _=="string"&&_!==""&&!at(_)&&$(_)},R=I=>{if(o&&typeof I=="string"&&I.trim()!==""&&!at(I)){$(I);return}x.current=!1,c(Xn(I)),m(T=>T+1),t(I)};return p?n.jsxs("div",{className:`w6w-expr-sealed${a?" is-readonly":""}`,"aria-label":l,children:[n.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-secret",title:"Encrypted secret",children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"🔒"}),n.jsx("span",{className:"w6w-expr-chip-label",children:"••••••"})]}),!a&&n.jsx("button",{type:"button",className:"w6w-expr-replace",onClick:()=>{x.current=!0,c({parts:[],sealed:null}),m(I=>I+1),t("")},children:"Replace"})]}):n.jsxs("div",{className:"w6w-expr",ref:E,onBlur:P,children:[n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{ref:C,className:`w6w-expr-editor${o?" is-masked":""}${d.length===0?" is-empty":""}${a?" is-readonly":""}`,contentEditable:!a,suppressContentEditableWarning:!0,role:"textbox",tabIndex:a?-1:0,"aria-multiline":r?"true":"false","aria-label":l,"data-placeholder":s??"",spellCheck:!1,onInput:()=>{const I=C.current;I&&Rr(I),A()},onClick:I=>{var _;const T=I.target.closest("[data-x]");T&&(I.preventDefault(),(_=T.closest(".w6w-expr-chip"))==null||_.remove(),A())},onDoubleClick:I=>{const T=I.target;if(T.closest("[data-x]"))return;const _=T.closest(".w6w-expr-chip");if(!_)return;I.preventDefault();const q=Or(_);if(q){const U=q.ownerDocument,B=U.createRange();B.setStartAfter(q),B.collapse(!0);const F=U.getSelection();F==null||F.removeAllRanges(),F==null||F.addRange(B)}A()},onKeyDown:I=>{if(I.key!=="Enter"||(I.preventDefault(),!r))return;const T=C.current;T&&(Dt(T,T.ownerDocument.createTextNode(`
|
|
11
|
+
`)),Er(T),A())}}),!a&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse variables, secrets & step outputs","aria-label":"Edit expression",onClick:()=>y(!0),children:"ƒx"})]}),g&&n.jsx(Qt,{value:cn(d),masked:o,multiline:r,options:j,fieldLabel:l,onSave:R,onClose:()=>y(!1)})]})}const Vl=/\{\{\s*([^{}]*?)\s*\}\}/g;function Ir(e,t="javascript"){const s=t==="python",o=[],r=[];let a=0;for(;a<e.length;){const l=e[a],u=e.slice(a,a+2),c=e.slice(a,a+3);if(s&&l==="#"||!s&&u==="//"){const d=e.indexOf(`
|
|
12
|
+
`,a),p=d===-1?e.length:d;r.push({start:a,end:p}),a=p}else if(!s&&u==="/*"){const d=e.indexOf("*/",a+2),p=d===-1?e.length:d+2;r.push({start:a,end:p}),a=p}else if(s&&(c==='"""'||c==="'''")){const d=e.indexOf(c,a+3),p=d===-1?e.length:d+3;o.push({start:a,end:p,quote:c}),a=p}else if(l==="'"||l==='"'||!s&&l==="`"){let d=a+1;for(;d<e.length&&e[d]!==l;){if(e[d]==="\\")d++;else if(l!=="`"&&e[d]===`
|
|
13
|
+
`)break;d++}const p=Math.min(d+1,e.length);o.push({start:a,end:p,quote:l}),a=p}else a++}const i=[];for(const l of e.matchAll(Vl)){const u=l.index??0,c=u+l[0].length;if(r.some(p=>u>=p.start&&u<p.end))continue;const d=o.find(p=>u>p.start&&u<p.end);i.push({start:u,end:c,ref:l[1],context:d?{kind:"string",...d}:{kind:"code"}})}return i}const Hl=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$-]*|\[\d+\]|\["[^"\\]*"\]|\['[^'\\]*'\])*$/,Bl=/\.([A-Za-z_$][\w$-]*)|\[(\d+)\]|\["([^"\\]*)"\]|\['([^'\\]*)'\]/g,Jl={nodes:["run","nodes"],steps:["run","nodes"],trigger:["run","trigger"],foreach:["run","foreach"],state:["state"],var:["state"],vars:["state"],const:["consts"],consts:["consts"]};function dn(e,t="javascript"){var u;const s=e.trim();if(!Hl.test(s))return null;const o=((u=/^[A-Za-z_$][\w$]*/.exec(s))==null?void 0:u[0])??"",r=Jl[o];if(!r)return null;const a=[...r.slice(1)];for(const c of s.slice(o.length).matchAll(Bl))a.push(c[2]!==void 0?Number(c[2]):c[1]??c[3]??c[4]);const i=r[0]==="run"?a.shift():r[0];return`${t==="python"?"ctx":"$"}.get(${[i,...a].map(c=>JSON.stringify(c)).join(", ")})`}function zl(e,t="javascript"){const s=t==="python";let o="",r=0,a=0,i=0;for(const l of Ir(e,t)){const u=dn(l.ref,t);if(u===null){i++;continue}const c=l.context;if(c.kind==="code"){o+=e.slice(r,l.start)+u,r=l.end,a++;continue}const d=c.quote,p=l.start===c.start+d.length,f=l.end===c.end-d.length;if(p&&f)o+=e.slice(r,c.start)+u,r=c.end,a++;else if(!s&&d==="`")o+=`${e.slice(r,l.start)}\${${u}}`,r=l.end,a++;else if(d.length===1&&!(s&&/[A-Za-z]/.test(e[c.start-1]??""))){const m=s?`str(${u})`:u;o+=p?`${e.slice(r,c.start)}${m} + ${d}`:`${e.slice(r,l.start)}${d} + ${m}`,f?r=c.end:(p||(o+=` + ${d}`),r=l.end),a++}else i++}return o+=e.slice(r),{code:o,converted:a,left:i}}function Kl({param:e,value:t,language:s,label:o,req:r,readOnly:a,onChange:i}){var E;const l=b.useRef(null),[u,c]=b.useState(!1),d=Xe(),p=d.steps??[],f=s==="python",m=S=>{const j=l.current;if(!j){i(t+S);return}j.dispatch(j.state.replaceSelection(S)),j.focus()},w=S=>{const j=ct(S);if(j!==null){const N=dn(j,s);N&&m(N);return}S===void 0||S===""||m(JSON.stringify(S,null,2).replace(/"\{\{\s*([^{}"]*?)\s*\}\}"/g,(N,A)=>dn(A,s)??N))},h=((E=p[0])==null?void 0:E.id)??"<step-id>",g=f?"ctx":"$",y=[[`${g}.get("nodes", ${JSON.stringify(h)}, "output")`,"a step's output"],[`${g}.get("state", "region")`,"a workflow state value"],[`${g}.get("consts", "api_base")`,"a constant"]],x=Math.max(...y.map(([S])=>S.length)),C=f?"#":"//";return n.jsxs("div",{className:"w6w-field w6w-script-code",children:[n.jsxs("span",{children:[o,r]}),n.jsx(Cs,{value:t,readOnly:a,minHeight:"180px",language:s,"aria-label":`${e.key} code`,onChange:i,onCreateEditor:S=>{l.current=S}}),!a&&n.jsxs("div",{className:"w6w-seed-chips w6w-script-insert",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Insert"}),p.map(S=>{const j=dn(`nodes[${JSON.stringify(S.id)}].output`,s)??"";return n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Insert ${j}`,onClick:()=>m(j),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 ${o}`,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:y.map(([S,j])=>`${S.padEnd(x)} ${C} ${j}`).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:f?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(Qt,{mode:"json-binding",value:void 0,jsonValue:void 0,options:d,fieldLabel:o,whole:!0,onSaveJson:w,onClose:()=>c(!1)})]})}function In(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...In(s.children));return t}function $r(e){return at(e)||lt(e)?!0:typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"$")}function vn(e){var t;return((t=e.config)==null?void 0:t.allowCustom)===!0}function os(e){return In(e).filter(t=>En(t.options))}function $s(e){return En(e.options)?e.options.refreshOn??[]:[]}function rs(e,t){const s={},o=[];for(const r of In(e)){if(r.type==="section")continue;const a=t[r.key]!==void 0?t[r.key]:r.default;a!==void 0&&($r(a)?o.push(r.key):s[r.key]=a)}return{form:s,unresolved:o}}function Gl(e,t,s,o,r){const{form:a,unresolved:i}=rs(e,t),l=new Set(i),u=os(e).filter(d=>{const p=$s(d);return s==="change"&&!(o??[]).some(f=>p.includes(f))?!1:p.every(f=>!l.has(f))}).map(d=>d.key);if(u.length===0)return null;const c={reason:s,form:a,fields:u,unresolved:i};return s==="change"&&(c.changed=[...o??[]],c.previous=rs(e,r??{}).form),c}function $o(e,t,s){return JSON.stringify([e.appId,e.version??null,e.actionKey,e.connectionId??null,t.key,$s(t).map(o=>s[o]??null)])}function Po(e){return!(En(e.options)&&e.options.cache==="none")}function Yl(e,t){return e.some(s=>t.includes(s))}function Xl(e,t,s,o){var l;if(!o.connectionId)return{reason:"no-connection",hint:"Connect an account to load choices"};const r=new Set(rs(t,s).unresolved),a=$s(e).find(u=>r.has(u));return a===void 0?null:{reason:"unresolved-dependency",hint:`Options unavailable while ${((l=In(t).find(u=>u.key===a))==null?void 0:l.label)??a} is an expression`}}function _o(e,t,s){return e==null||e===""?{action:"keep"}:$r(e)?{action:"keep"}:t.some(o=>o.value===e||String(o.value)===String(e))?{action:"keep"}:s.reason==="change"&&!s.allowCustom?{action:"clear"}:{action:"flag",message:`Not in the list returned by ${s.appLabel}`}}function Zl(e,t,s,o){var C;const r=(C=Ft())==null?void 0:C.resolveActionFields,a=!!(s&&r),[i,l]=b.useState({}),u=b.useRef({params:e,values:t,dynamic:s,onChange:o,resolve:r});u.current={params:e,values:t,dynamic:s,onChange:o,resolve:r};const c=b.useRef(new Map),d=b.useRef([]),p=b.useCallback((E,S,j,N,A)=>{const{params:$,values:P,dynamic:R,resolve:I}=u.current,T=A??P;if(!R||!I||!R.connectionId)return;const _=Gl($,T,E,S,j);if(!_)return;const q=new Map(os($).map(W=>[W.key,W])),U=[],B={},F=[],O=R.appName??R.appId,K=(W,ne)=>{const ee=q.get(W);if(!ee)return;_o(T[W],ne,{allowCustom:vn(ee),reason:E,appLabel:O}).action==="clear"&&U.push(W)};for(const W of _.fields){if(N!==void 0&&W!==N)continue;const ne=q.get(W);if(!ne)continue;const ee=N===void 0&&Po(ne)?c.current.get($o(R,ne,_.form)):void 0;ee?(B[W]={options:ee,loading:!1},K(W,ee)):F.push(W)}const G=(W=!1)=>{if(U.length===0)return;const ne={...W?T:u.current.values};for(const ee of U)delete ne[ee];u.current.onChange(ne)};if(Object.keys(B).length>0&&l(W=>({...W,...B})),F.length===0){G(!0);return}for(const W of d.current)Yl(W.fields,F)&&W.controller.abort();const Q=new AbortController,M={fields:F,controller:Q};d.current=[...d.current.filter(W=>!W.controller.signal.aborted),M],l(W=>{var ee;const ne={...W};for(const v of F)ne[v]={options:(ee=W[v])==null?void 0:ee.options,loading:!0};return ne});const X={..._,fields:F,connectionId:R.connectionId,...R.version!==void 0?{version:R.version}:{}},J=W=>{d.current=d.current.filter(ne=>ne!==M),l(ne=>({...ne,...W}))};Promise.resolve().then(()=>I(R.appId,R.actionKey,X,{signal:Q.signal})).then(W=>{var ee;if(Q.signal.aborted)return;const ne={};for(const v of F){const D=(ee=W==null?void 0:W.fields)==null?void 0:ee[v],Y=q.get(v);if(!D||!Y)ne[v]={loading:!1};else if(D.error)ne[v]={loading:!1,error:D.error};else{const re=Array.isArray(D.options)?D.options:[];ne[v]={loading:!1,options:re},Po(Y)&&c.current.set($o(R,Y,_.form),re),K(v,re)}}J(ne),G()}).catch(W=>{if(Q.signal.aborted)return;const ne=W instanceof Error?W.message:String(W),ee={};for(const v of F)ee[v]={loading:!1,error:ne||"Request failed"};J(ee)})},[]),f=s?JSON.stringify([s.appId,s.actionKey,s.version,s.connectionId]):"";b.useEffect(()=>{if(a)return l({}),p("init"),()=>{for(const E of d.current)E.controller.abort();d.current=[]}},[f,a,p]);const m=b.useRef(new Map),w=b.useCallback((E,S)=>{const j=m.current.get(E)??u.current.values;m.current.delete(E),p("change",[E],j,void 0,{...u.current.values,[E]:S})},[p]),h=b.useCallback(E=>{m.current.has(E)||m.current.set(E,u.current.values)},[]),g=b.useCallback(E=>{const S=m.current.get(E);if(m.current.delete(E),!S)return;const j=u.current.values;JSON.stringify(S[E])!==JSON.stringify(j[E])&&p("change",[E],S)},[p]),y=b.useCallback(E=>p("init",void 0,void 0,E),[p]);return{fields:b.useMemo(()=>{const E={};if(!a||!s)return E;const S=s.appName??s.appId;for(const j of os(e)){const N=Xl(j,e,t,s);if(N){E[j.key]={loading:!1,hint:N.hint};continue}const A=i[j.key]??{loading:!0},$={...A};if(A.options){const P=_o(t[j.key],A.options,{allowCustom:vn(j),reason:"init",appLabel:S});P.action==="flag"&&($.notInList=P.message)}E[j.key]=$}return E},[a,s,e,t,i]),commit:w,focus:h,blur:g,retry:y}}function en(e,t){return e.hidden===!0?!1:e.showIf?ae.matchesParamCondition(e.showIf,t):!0}function At(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...At(s.children));return t}function Kt(e,t){const s=[];for(let o=0;o<e.length;){const r=e[o].row;if(r){const a=[];for(;o<e.length&&e[o].row===r;)a.push(e[o++]);s.push(n.jsx("div",{className:"w6w-field-row",children:a.map(t)},`row:${r}`))}else s.push(t(e[o])),o++}return s}function Pr(e,t,s,o){const r=a=>a.type==="section"?n.jsx(Ql,{param:a,effective:s,renderOne:r},a.key):a.repeat&&a.type!=="array"?n.jsx(sc,{param:a,value:e[a.key],onChange:t,readOnly:o},a.key):a.type==="group"&&a.children&&a.children.length>0?n.jsx(nc,{param:a,value:e[a.key],onChange:t,effective:s,readOnly:o},a.key):n.jsx(rc,{param:a,value:e[a.key],onChange:t,effective:s,readOnly:o},a.key);return r}const $n=b.createContext(null);function Fe({params:e,values:t,onChange:s,readOnly:o,dynamic:r}){const a=Zl(e,t,r,s),i=At(e),l=m=>{var w;return t[m]!==void 0?t[m]:(w=i.find(h=>h.key===m))==null?void 0:w.default},u=e.filter(m=>en(m,l)).map(m=>ae.effectiveParam(m,l)),c=u.filter(m=>m.required||!m.advanced),d=u.filter(m=>!m.required&&m.advanced),p=(m,w)=>{if(m==="language"){const h={...t,[m]:w};for(const g of i){if(g.type!=="code")continue;const y=t[g.key];(y===void 0||y===g.default||y===as||oc.includes(y))&&(h[g.key]=w==="python"?as:g.default)}s(h);return}s({...t,[m]:w})};if(e.length===0)return n.jsx("p",{className:"w6w-muted w6w-small",children:"This action takes no parameters."});const f=Pr(t,p,l,o);return n.jsx($n.Provider,{value:a,children:n.jsxs("div",{className:"w6w-stack",children:[Kt(c,f),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:Kt(d,f)})]})]})})}function Ql({param:e,effective:t,renderOne:s}){const o=(e.children??[]).filter(r=>en(r,t)).map(r=>ae.effectiveParam(r,t));return e.section==="collapsible"?n.jsxs("details",{className:"w6w-section",open:e.collapsed===!1||e.openWhenSet===!0&&o.some(r=>{const a=t(r.key);return a!=null&&a!==""}),children:[n.jsxs("summary",{className:"w6w-section-summary",children:[n.jsx("span",{className:"w6w-section-title",children:e.title??e.label??e.key}),e.subtitle&&n.jsx("span",{className:"w6w-section-subtitle",children:e.subtitle})]}),n.jsx("div",{className:"w6w-stack w6w-section-body",children:Kt(o,s)})]}):e.layout==="row"?n.jsx("div",{className:"w6w-field-row",children:o.map(s)}):n.jsx("div",{className:"w6w-stack",children:Kt(o,s)})}const ec=new Set(["string","text","number","boolean","select"]);function tc(e){return e.length>0&&e.every(t=>ec.has(t.type)&&!t.children)}function nc({param:e,value:t,onChange:s,effective:o,readOnly:r}){const a=e.children??[],i=t??{},l=(f,m)=>s(e.key,{...i,[f]:m}),u=At(a),c=f=>{const m=u.find(w=>w.key===f);return m?i[f]!==void 0?i[f]:m.default:o(f)},d=a.filter(f=>en(f,c)).map(f=>ae.effectiveParam(f,c)),p=Pr(i,l,c,r);return n.jsx($n.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:Kt(d,p)})]})})}function sc({param:e,value:t,onChange:s,readOnly:o}){if(e.type==="group"){const a=e.children??[];if(!tc(a))return n.jsx(Ps,{param:e,value:t,onChange:s,readOnly:o});const i={...e,item:{type:"object",fields:a}};return n.jsx(is,{param:i,value:t,onChange:s,readOnly:o})}const r={...e,item:{type:e.type,options:Array.isArray(e.options)?e.options:void 0}};return n.jsx(is,{param:r,value:t,onChange:s,readOnly:o})}const as=`# Runs as a function body. Return the step's output.
|
|
15
|
+
return input`,oc=["// 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 rc(e){const t=b.useContext($n),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(ac,{...e})})}function ac({param:e,value:t,onChange:s,effective:o,readOnly:r}){var S,j,N,A,$,P;const a=(S=Ft())==null?void 0:S.listModelRoutes,i=(j=Ft())==null?void 0:j.listDataStores,l=(N=Ft())==null?void 0:N.listAgents,u=(A=Ft())==null?void 0:A.listDataStoreEntries,c=ks(),d=b.useContext($n),p=d==null?void 0:d.fields[e.key],f=(R,I)=>{s(R,I),d==null||d.commit(R,I)},m=s,w=e.label??e.key,h=e.required&&e.type!=="boolean"?" *":"",g=b.useId();if(e.type==="boolean"){const R=!!(t??e.default??!1);return n.jsx(Ie,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,variant:"inline",controlId:g,children:n.jsx("input",{id:g,type:"checkbox",checked:R,disabled:r,onChange:I=>f(e.key,I.target.checked)})})}if(e.type==="json"||e.type==="group")return n.jsx(Ps,{param:e,value:t,onChange:m,readOnly:r});if(e.type==="code"){const R=o==null?void 0:o("language"),I=R==="python"||R==="javascript"||R==="typescript"?R:void 0,T=I==="python"?as:e.default,_=t??T??"";return e.scriptReads?n.jsx(Kl,{param:e,value:String(_),language:R==="python"?"python":"javascript",label:w,req:h,readOnly:r,onChange:q=>m(e.key,q)}):n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[w,h]}),n.jsx(Cs,{value:String(_),readOnly:r,minHeight:"180px",language:I,"aria-label":`${e.key} code`,onChange:q=>m(e.key,q)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="model-route"&&a)return n.jsx(ic,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,listModelRoutes:a,project:c});if(e.type==="agent"&&l)return n.jsx(lc,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,listAgents:l});if(e.type==="data-store"&&i)return n.jsx(cc,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,listDataStores:i,project:c});const y=o==null?void 0:o("store");if(e.type==="data-store-key"&&u&&typeof y=="string"&&y.trim()!=="")return n.jsx(fc,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,store:y,listDataStoreEntries:u,project:c});if(e.type==="vars")return n.jsx(jc,{param:e,value:t,onChange:m,readOnly:r});if(e.type==="text"||($=e.config)!=null&&$.multiline){const R=t??e.default??"";return n.jsx(Ie,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,children:n.jsx("textarea",{rows:3,value:String(R),readOnly:r,"aria-label":w,onChange:I=>m(e.key,I.target.value)})})}if(e.type==="multiselect")return n.jsx(hc,{param:e,value:t,onChange:f,readOnly:r});if(e.type==="array")return n.jsx(is,{param:e,value:t,onChange:m,readOnly:r});if(d&&p&&!p.hint)return n.jsx(Fo,{param:e,value:t,onChange:f,readOnly:r,label:w,req:h,state:p,retry:()=>d.retry(e.key)});if(Array.isArray(e.options)&&e.options.length>0&&vn(e))return n.jsx(Fo,{param:e,value:t,onChange:f,readOnly:r,label:w,req:h,state:{loading:!1,options:e.options}});if(Array.isArray(e.options)&&e.options.length>0){const R=!e.required&&e.default===void 0&&typeof e.placeholder=="string"&&e.placeholder?e.placeholder:void 0,I=t??e.default??(R!==void 0?"":(P=e.options[0])==null?void 0:P.value)??"",T=e.type==="number";return n.jsx(Ie,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,children:n.jsxs("select",{value:String(I),disabled:r,"aria-label":w,onChange:_=>{const q=_.target.value;R!==void 0&&q===""?f(e.key,void 0):f(e.key,T?Number(q):q)},children:[R!==void 0&&n.jsx("option",{value:"",children:R}),e.options.map(_=>n.jsx("option",{value:String(_.value),children:_.label},String(_.value)))]})})}if(e.type==="secret"){const R=t??e.default;return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[w,h]}),n.jsx(zt,{value:R,masked:!0,readOnly:r,"aria-label":w,onChange:I=>m(e.key,I)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const x=e.type==="number"?"number":"text",C=t??e.default??"",E=typeof C=="object"&&C!==null?JSON.stringify(C):String(C??"");return n.jsxs(Ie,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,children:[n.jsx("input",{type:x,value:E,readOnly:r,"aria-label":w,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",onChange:R=>m(e.key,e.type==="number"?Number(R.target.value):R.target.value)}),(p==null?void 0:p.hint)&&n.jsx("span",{className:"w6w-hint",children:p.hint})]})}function Fo({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,state:i,retry:l}){const u=t??e.default??"",c=typeof u=="string"||typeof u=="number"?String(u):"";return n.jsxs(Ie,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:[n.jsx("div",{className:"w6w-fx-grow","aria-busy":i.loading?"true":"false",children:n.jsx(Ge,{mode:"combobox",forceSelection:!vn(e),"aria-label":r,disabled:o,value:c,placeholder:i.loading?"Loading…":e.placeholder,options:(i.options??[]).map(d=>({value:String(d.value),label:d.label})),onChange:d=>s(e.key,d)})}),i.notInList&&n.jsx("span",{className:"w6w-hint",children:i.notInList}),i.error&&n.jsxs("span",{role:"alert",className:"w6w-hint",children:[i.error,l&&n.jsx("button",{type:"button",onClick:l,children:"Retry"})]})]})}function ic({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,listModelRoutes:i,project:l}){const[u,c]=b.useState([]);b.useEffect(()=>{let f=!0;return Promise.resolve().then(()=>i(l)).then(m=>f&&c(Array.isArray(m)?m:[])).catch(()=>f&&c([])),()=>{f=!1}},[i,l]);const d=t??e.default??"",p=typeof d=="string"?d:"";return n.jsx(Ie,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(Ge,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:p,placeholder:"Select a route…",options:u.map(f=>({value:f.name,label:f.status==="broken"?`${f.name} (broken)`:f.name})),onChange:f=>s(e.key,f)})})}function lc({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,listAgents:i}){const[l,u]=b.useState(null);b.useEffect(()=>{let h=!0;return Promise.resolve().then(()=>i()).then(g=>h&&u(Array.isArray(g)?g:[])).catch(()=>h&&u([])),()=>{h=!1}},[i]);const c=t??e.default??"",d=typeof c=="string"?c:"",p=l??[],f=p.find(h=>h.id===d),m=p.map(h=>({value:h.id,label:h.name||h.id}));d&&!f&&l!==null&&m.unshift({value:d,label:`${d} (not found)`});const w=l!==null&&p.length===0?n.jsx("span",{className:"w6w-muted w6w-small",children:"Create an agent in the Agents dashboard first."}):f!=null&&f.href?n.jsxs("a",{className:"w6w-small",href:f.href,target:"_blank",rel:"noreferrer",children:["Open ",f.name||f.id," in the Agents dashboard ↗"]}):null;return n.jsxs("div",{className:"w6w-agent-field",children:[n.jsx(Ie,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(Ge,{mode:"combobox","aria-label":r,disabled:o,value:d,placeholder:l===null?"Loading agents…":p.length===0?"No agents yet":"Select an agent…",options:m,onChange:h=>s(e.key,h)})}),w]})}function cc({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,listDataStores:i,project:l}){const[u,c]=b.useState([]);b.useEffect(()=>{let f=!0;return Promise.resolve().then(()=>i(l)).then(m=>f&&c(Array.isArray(m)?m:[])).catch(()=>f&&c([])),()=>{f=!1}},[i,l]);const d=t??e.default??"",p=typeof d=="string"?d:"";return n.jsx(Ie,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(Ge,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:p,placeholder:"Select a store…",options:u.map(f=>({value:f.name,label:`${f.name} (${f.kind})`})),onChange:f=>s(e.key,f)})})}const uc=25,dc=200,Lo=60;function pc(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>Lo&&(t=`${t.slice(0,Lo-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 fc({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,store:i,listDataStoreEntries:l,project:u}){const[c,d]=b.useState(""),[p,f]=b.useState({items:[]}),[m,w]=b.useState(!0);b.useEffect(()=>{const x=new AbortController;w(!0);const C=c.trim(),E=setTimeout(()=>{Promise.resolve().then(()=>l(i,{project:u,prefix:C===""?void 0:C,limit:uc,signal:x.signal})).then(S=>{x.signal.aborted||(f(S&&Array.isArray(S.items)?S:{items:[]}),w(!1))}).catch(()=>{x.signal.aborted||(f({items:[]}),w(!1))})},C===""?0:dc);return()=>{clearTimeout(E),x.abort()}},[l,i,u,c]);const h=t??e.default??"",g=typeof h=="string"?h:"",y=c.trim();return n.jsx(Ie,{param:e,value:t,onChange:s,readOnly:o,label:r,req:a,children:n.jsx(Ge,{mode:"combobox",forceSelection:!1,"aria-label":r,disabled:o,value:g,placeholder:"Search entries or type a key…",options:p.items.map(x=>({value:x.key,label:x.key,detail:pc(x)||void 0})),onInputChange:d,emptyText:m?"Searching…":y!==""?`No key starts with "${y}" — Enter keeps it as typed`:"No entries in this store",footer:p.more?"More entries — type to narrow by key":void 0,onChange:x=>s(e.key,x)})})}function Ie({param:e,value:t,onChange:s,readOnly:o,label:r,req:a,bare:i,variant:l="boxed",controlId:u,children:c}){var y;const d=at(t),p=e.type==="text"||!!((y=e.config)!=null&&y.multiline),[f,m]=b.useState(!1),w=Xe(),h=l==="inline"&&!d,g=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:h?"w6w-fx-inline":`w6w-fx-wrap${d?" is-fx":""}`,children:d?n.jsx(zt,{value:t,multiline:p,readOnly:o,"aria-label":r,onChange:x=>s(e.key,x)}):n.jsxs(n.Fragment,{children:[c,!o&&n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${r}`,onClick:()=>m(!0),children:"ƒx"}),h&&n.jsxs("label",{className:"w6w-fx-inline-label",htmlFor:u,children:[r,a]})]})}),f&&n.jsx(Qt,{value:t,multiline:p,options:w,fieldLabel:r,onSave:x=>s(e.key,x),onClose:()=>m(!1)})]});return i?g:n.jsxs("div",{className:"w6w-field",children:[!h&&n.jsxs("span",{children:[r,a]}),g,e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}function Ps({param:e,value:t,onChange:s,readOnly:o,headerActions:r,onValidityChange:a}){var P;const i=ct(t)??"",l=i!=="",u=t??e.default,[c,d]=b.useState(()=>l||u===void 0?"":JSON.stringify(u,null,2)),[p,f]=b.useState(!1),[m,w]=b.useState(!1),[h,g]=b.useState(!1),y=Xe(),x=y.steps??[],C=(((P=y.stateShape)==null?void 0:P.fields.length)??0)>0;b.useEffect(()=>{if(l)return;let R;try{R=c.trim()===""?void 0:JSON.parse(c)}catch{R=void 0}JSON.stringify(R)!==JSON.stringify(u)&&(d(u===void 0?"":JSON.stringify(u,null,2)),f(!1))},[u,e.key,l]);const E=R=>{d(R)},S=R=>{f(!1),a==null||a(!0),s(e.key,R)},j=({valid:R,error:I})=>{if(a==null||a(R||I==="Empty"),!R&&I==="Empty"){f(!1),s(e.key,void 0);return}f(!R)},N=()=>{const R=Ll(c);R&&(f(!1),s(e.key,R))},A=e.label??e.key,$=()=>{let R;try{R=c.trim()===""?void 0:JSON.parse(c)}catch{R=void 0}s(e.key,R)};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[A,e.required?" *":""]}),r,!l&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${A} in full view`,onClick:()=>w(!0),children:n.jsx(le.Icon,{name:"maximize",size:14})})]}),l?n.jsx("div",{className:"w6w-fx-wrap is-fx w6w-json-binding",children:n.jsx("div",{className:"w6w-expr",children:n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{className:`w6w-expr-editor${o?" is-readonly":""}`,"data-testid":"json-binding-ref",children:n.jsxs("span",{className:"w6w-expr-chip w6w-expr-chip-var","data-kind":"var","data-ref":i,title:`Variable: ${i}`,children:[n.jsx("span",{className:"w6w-expr-chip-sigil",children:"◆"}),n.jsx("span",{className:"w6w-expr-chip-label",children:nt(i)}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-chip-x","aria-label":`Remove the reference from ${A}`,style:{border:0,padding:0,font:"inherit"},onClick:$,children:"×"})]})}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse step outputs, metadata & variables","aria-label":`Edit expression for ${A}`,onClick:()=>g(!0),children:"ƒx"})]})})}):n.jsx(ze,{value:c,onChange:E,onBlur:N,readOnly:o,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:S,onValidityChange:j,overlay:o?void 0:n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${A}`,onClick:()=>g(!0),children:"ƒx"})}),h&&n.jsx(Qt,{mode:"json-binding",value:void 0,jsonValue:t,options:y,fieldLabel:A,whole:e.whole,onSaveJson:R=>s(e.key,R),onClose:()=>g(!1)}),!l&&p&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"}),e.whole&&!l&&!o&&(x.length>0||C)&&n.jsxs("div",{className:"w6w-seed-chips w6w-json-quickbind",children:[C&&n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${A} to {{ state }}, the run state upstream steps wrote`,onClick:()=>s(e.key,"{{ state }}"),children:n.jsx("code",{children:"state"})}),x.length>0&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Use the output of"}),x.map(R=>n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${A} to {{ nodes.${R.id}.output }}`,onClick:()=>s(e.key,`{{ nodes.${R.id}.output }}`),children:n.jsx("code",{children:R.id})},R.id))]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),m&&!l&&n.jsxs(ke,{title:A,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>w(!1),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(ze,{value:c,onChange:E,readOnly:o,height:"100%",minHeight:"360px","aria-label":`${e.key} JSON (full view)`,onValidChange:S,onValidityChange:j})}),p&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function hc({param:e,value:t,onChange:s,readOnly:o}){var y;const r=Array.isArray(e.options)?e.options:[],a=((y=e.config)==null?void 0:y.valueFormat)==="csv",i=t??e.default,l=Array.isArray(i)?i:a&&typeof i=="string"?i.split(",").map(x=>x.trim()).filter(Boolean):[],u=new Set(l.map(String)),c=r.filter(x=>!u.has(String(x.value))),d=x=>{var C;return((C=r.find(E=>String(E.value)===String(x)))==null?void 0:C.label)??String(x)},p=x=>s(e.key,a?x.join(","):x),f=x=>{if(!x||u.has(x))return;const C=r.find(E=>String(E.value)===x);p([...l,C?C.value:x])},m=x=>p(l.filter(C=>String(C)!==String(x))),w=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",h=e.label??e.key,g=e.required?" *":"";return n.jsx(Ie,{param:e,value:t,onChange:s,readOnly:o,label:h,req:g,children:e.ui==="checkboxes"?n.jsxs("div",{className:"w6w-multiselect-checks w6w-fx-grow",children:[n.jsxs("div",{className:"w6w-multiselect-checks-toolbar",children:[n.jsxs("span",{className:"w6w-muted w6w-small",children:[l.length," selected"]}),!o&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:c.length===0,onClick:()=>p([...l,...c.map(x=>x.value)]),children:"Select all"}),n.jsx("button",{type:"button",className:"w6w-linkbtn",disabled:l.length===0,onClick:()=>p([]),children:"Clear"})]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":h,children:[...r,...l.filter(x=>!r.some(C=>String(C.value)===String(x))).map(x=>({value:x,label:String(x)}))].map(x=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:u.has(String(x.value)),disabled:o,onChange:C=>C.target.checked?f(String(x.value)):m(x.value)}),n.jsx("span",{children:x.label})]},String(x.value)))})]}):n.jsx(n.Fragment,{children:n.jsxs("div",{className:`w6w-multiselect${o?" is-readonly":""}`,children:[l.map(x=>n.jsxs("span",{className:"w6w-chip",children:[d(x),!o&&n.jsx("button",{type:"button",className:"w6w-chip-x","aria-label":`Remove ${d(x)}`,title:"Remove",onClick:()=>m(x),children:"×"})]},String(x))),!o&&n.jsxs("select",{className:"w6w-multiselect-add",value:"",disabled:c.length===0,"aria-label":`Add to ${e.label??e.key}`,onChange:x=>f(x.target.value),children:[n.jsx("option",{value:"",children:c.length>0?l.length?"Add more…":w:"All selected"}),c.map(x=>n.jsx("option",{value:String(x.value),children:x.label},String(x.value)))]})]})})})}function wc(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 mc({label:e,value:t,onChange:s,readOnly:o}){const r=typeof t=="string"?t:t==null?"":JSON.stringify(t),[a,i]=b.useState(null),l=()=>{let d=r;try{d=r.trim()?JSON.stringify(JSON.parse(r),null,2):""}catch{}i(d)};let u=!1,c;if(a!==null)if(a.trim()==="")u=!0;else try{c=JSON.parse(a),u=!0}catch{}return n.jsxs("span",{className:"w6w-array-json",children:[n.jsx("input",{className:"w6w-array-input",type:"text",value:r.replace(/\r?\n\s*/g," "),placeholder:"JSON","aria-label":e,readOnly:!0,onClick:l,onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),l())}}),n.jsx("button",{type:"button",className:"w6w-array-x",title:"Open JSON editor","aria-label":`Open ${e} JSON editor`,onClick:l,children:n.jsx(le.Icon,{name:"maximize",size:14})}),a!==null&&n.jsxs(ke,{title:e,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>i(null),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(ze,{value:a,onChange:i,height:"100%",minHeight:"360px",readOnly:o,"aria-label":`${e} JSON editor`})}),!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:()=>i(null),children:o?"Close":"Cancel"}),!o&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:!u,onClick:()=>{u&&(s(a.trim()===""?"":JSON.stringify(c)),i(null))},children:"Apply"})]})]})]})}function bc({field:e,value:t,row:s,onChange:o,readOnly:r}){var c,d;const a=e.placeholder??e.label??e.key,i=(c=e.config)==null?void 0:c.valueTypeFrom,l=e.label??e.key;if(i){const p=String((s==null?void 0:s[i])??"string");if(p==="boolean"){const f=t===!0||t==="true"?"true":t===!1||t==="false"?"false":"";return n.jsxs("select",{className:"w6w-array-input",value:f,disabled:r,"aria-label":l,onChange:m=>o(m.target.value),children:[n.jsx("option",{value:"",children:"(none)"}),n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]})}if(p==="json")return n.jsx(mc,{label:l,value:t,onChange:o,readOnly:r});if(p==="number")return n.jsx("input",{className:"w6w-array-input",type:"number",value:t==null?"":String(t),placeholder:a,"aria-label":l,readOnly:r,onChange:f=>o(f.target.value)})}if(Array.isArray(e.options)&&e.options.length>0)return n.jsx("select",{className:"w6w-array-input",value:String(t??e.default??((d=e.options[0])==null?void 0:d.value)??""),disabled:r,"aria-label":e.label??e.key,onChange:p=>o(p.target.value),children:e.options.map(p=>n.jsx("option",{value:String(p.value),children:p.label},String(p.value)))});if(e.type==="boolean")return n.jsxs("label",{className:"w6w-array-check",title:e.label??e.key,children:[n.jsx("input",{type:"checkbox",checked:!!(t??e.default??!1),disabled:r,"aria-label":e.label??e.key,onChange:p=>o(p.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:a,"aria-label":e.label??e.key,readOnly:r,onChange:p=>o(u?Number(p.target.value):p.target.value)})}function is({param:e,value:t,onChange:s,readOnly:o}){const r=e.item??{type:"string"},a=r.type==="object",i=Array.isArray(t)?t:Array.isArray(e.default)?e.default:[],l=f=>s(e.key,f),u=()=>a?Object.fromEntries((r.fields??[]).map(f=>{var m;return[f.key,f.default??(f.type==="boolean"&&!((m=f.config)!=null&&m.valueTypeFrom)?!1:"")]})):r.type==="number"?0:r.type==="boolean"?!1:"",c=(f,m)=>l(i.map((w,h)=>h===f?m:w)),d=f=>{const w={...f??{}};for(const h of r.fields??[])w[h.key]===void 0&&(w[h.key]=h.default);return w},p=(f,m,w)=>{var g;const h={...f??{},[m]:w};for(const y of r.fields??[])((g=y.config)==null?void 0:g.valueTypeFrom)===m&&!wc(String(w??""),h[y.key])&&(h[y.key]="");return h};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[e.label??e.key,e.required?" *":""]}),n.jsxs("div",{className:"w6w-array",children:[i.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"None yet — add one below."}),a&&i.length>0&&n.jsxs("div",{className:"w6w-array-head","aria-hidden":"true",children:[n.jsx("div",{className:"w6w-array-head-cells",children:(r.fields??[]).map(f=>f.type==="boolean"&&!(Array.isArray(f.options)&&f.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:f.label??f.key})]},f.key):n.jsxs("span",{className:"w6w-array-head-cell",children:[f.label??f.key,f.required?" *":""]},f.key))}),!o&&n.jsx("span",{className:"w6w-array-x w6w-array-head-ghost"})]}),i.map((f,m)=>n.jsxs("div",{className:"w6w-array-row",children:[a?n.jsx("div",{className:"w6w-array-cells",children:(r.fields??[]).map(w=>n.jsx(bc,{field:w,value:f==null?void 0:f[w.key],row:d(f),readOnly:o,onChange:h=>c(m,p(f,w.key,h))},w.key))}):n.jsx("input",{className:"w6w-array-input",type:r.type==="number"?"number":"text",value:String(f??""),placeholder:r.placeholder,readOnly:o,onChange:w=>c(m,r.type==="number"?Number(w.target.value):w.target.value)}),!o&&n.jsx("button",{type:"button",className:"w6w-array-x","aria-label":"Remove item",title:"Remove",onClick:()=>l(i.filter((w,h)=>h!==m)),children:"×"})]},m)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-array-add",onClick:()=>l([...i,u()]),children:"+ Add"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const yc=["string","number","boolean","json"],gc=[];function jn(e,t=[]){return Array.isArray(e)?e.every(s=>s&&typeof s=="object"&&typeof s.key=="string")?e:null:!e||typeof e!="object"||at(e)||ct(e)||"$expr"in e?null:Object.entries(e).map(([s,o])=>{const r=t.find(i=>i.key===s),a=typeof o;return{key:s,type:r&&JSON.stringify(r.value)===JSON.stringify(o)?r.type:a==="string"||a==="number"||a==="boolean"?a:"json",value:o}})}function xc(e){const t=Array.isArray(e)?jn(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 Mo(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 Do(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Wo(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 vc({param:e,value:t,label:s,onChange:o,readOnly:r}){const[a,i]=b.useState(null),l=()=>i(Wo(t,!0));let u=!1,c;if(a!==null)try{c=JSON.parse(a),u=!0}catch{}return n.jsxs(n.Fragment,{children:[n.jsxs(Ie,{bare:!0,param:e,value:t,onChange:(d,p)=>o(p),readOnly:r,label:s,req:"",children:[n.jsx("input",{type:"text",className:"w6w-datavar-json-preview",value:Wo(t).replace(/\r?\n\s*/g," "),placeholder:"JSON value","aria-label":`${s} JSON preview`,readOnly:!0,onClick:l,onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),l())}}),n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Open JSON editor","aria-label":`Open ${s} JSON editor`,onClick:l,children:n.jsx(le.Icon,{name:"maximize",size:14})})]}),a!==null&&n.jsxs(ke,{title:s,subtitle:n.jsx("code",{children:"JSON"}),size:"wide",onClose:()=>i(null),children:[n.jsx("div",{className:"w6w-json-fullview",children:n.jsx(ze,{value:a,onChange:i,height:"100%",minHeight:"360px",readOnly:r,"aria-label":`${s} JSON editor`})}),!u&&a.trim()&&n.jsx("p",{className:"w6w-field-error",role:"alert",children:"Invalid JSON"}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>i(null),children:r?"Close":"Cancel"}),!r&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:!u,onClick:()=>{u&&(o(c),i(null))},children:"Apply"})]})]})]})}function jc({param:e,value:t,onChange:s,readOnly:o}){const r=t??e.default??gc,a=b.useMemo(()=>xc(r),[r]),[i,l]=b.useState(()=>Array.isArray(r)?"fields":"json"),u=b.useRef([]),[c,d]=b.useState(!1),[p,f]=b.useState(null),m=jn(r,u.current),w=m??[],h=i==="json"||m===null,g=e.label??e.key,y=n.jsxs("div",{className:"w6w-view-toggle w6w-datavar-modes",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${h?"":" active"}`,"aria-label":`Edit ${g} as fields`,"aria-pressed":!h,disabled:c||!!p||m===null,title:m===null?"Use a literal JSON object to edit individual fields":"Edit individual fields",onClick:()=>{!o&&!Array.isArray(r)&&s(e.key,w),l("fields")},children:"Fields"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-sm w6w-btn-ghost${h?" active":""}`,"aria-label":`Edit ${g} as JSON`,"aria-pressed":h,onClick:()=>{u.current=w,l("json")},children:"JSON"})]});if(h)return n.jsxs("div",{className:"w6w-datavar-json",children:[n.jsx(Ps,{param:{...e,type:"json",whole:!0,default:{},hint:"Enter a JSON object or use ƒx to bind one. Switch to Fields to edit individual values."},value:a,readOnly:o,headerActions:y,onValidityChange:E=>d(!E),onChange:(E,S)=>{if(S!==void 0&&jn(S)===null&&!ct(S)&&!at(S)&&!(S&&typeof S=="object"&&"$expr"in S)){f("Use a JSON object, a typed key/value array, or an object binding.");return}f(null),d(!1),s(E,S)}}),p&&n.jsx("span",{className:"w6w-hint w6w-datavar-error","aria-live":"polite",children:p})]});const x=E=>s(e.key,E),C=(E,S)=>x(w.map((j,N)=>N===E?{...j,...S}:j));return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[g,e.required?" *":""]}),y]}),n.jsxs("div",{className:"w6w-stack",children:[w.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No variables yet — add one below."}),w.length>0&&n.jsxs("div",{className:"w6w-datavar-head","aria-hidden":"true",children:[n.jsx("span",{children:"Key"}),n.jsx("span",{children:"Type"}),n.jsx("span",{children:"Value"}),!o&&n.jsx("span",{})]}),w.map((E,S)=>n.jsxs("div",{className:"w6w-datavar-row",children:[n.jsx("input",{type:"text",placeholder:"key","aria-label":"Variable key",value:E.key,readOnly:o,onChange:j=>C(S,{key:j.target.value})}),n.jsx("select",{value:E.type,"aria-label":"Variable type",disabled:o,onChange:j=>{const N=j.target.value;C(S,{type:N,value:Mo(N,Do(E.value))})},children:yc.map(j=>n.jsx("option",{value:j,children:j},j))}),E.type==="json"?n.jsx(vc,{param:e,value:E.value,label:E.key||"value",onChange:j=>C(S,{value:j}),readOnly:o}):n.jsx(Ie,{bare:!0,param:e,value:E.value,onChange:(j,N)=>C(S,{value:N}),readOnly:o,label:E.key||"value",req:"",children:E.type==="boolean"?n.jsxs("select",{value:E.value===!0?"true":"false",disabled:o,onChange:j=>C(S,{value:j.target.value==="true"}),children:[n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:E.type==="number"?"number":"text",placeholder:"value",value:Do(E.value),readOnly:o,onChange:j=>C(S,{value:Mo(E.type,j.target.value)})})}),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost","aria-label":`Remove variable ${E.key||S+1}`,title:"Remove",onClick:()=>x(w.filter((j,N)=>N!==S)),children:"×"})]},S)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>x([...w,{key:"",type:"string",value:""}]),children:"+ Add variable"})]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}function _r(e,t){const s={...t};for(const o of e){const r=t[o.key];if(!(o.type!=="json"||typeof r!="string"||r.trim()===""))try{s[o.key]=JSON.parse(r)}catch{return{error:`${o.label} is not valid JSON. Check it and try again.`}}}return{values:s}}function pn({fields:e,values:t,onChange:s,enterSubmitProps:o,mode:r="create"}){const a=(i,l)=>s({...t,[i]:l});return n.jsxs("div",{className:"w6w-stack",children:[e.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"This auth method declares no fields — nothing to fill in. The credential will be an empty object."}),e.map(i=>{const l=r==="edit",u=t[i.key]??(l?void 0:i.default)??"";if(i.type==="boolean")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[n.jsx("input",{type:"checkbox",checked:!!u,onChange:p=>a(i.key,p.target.checked),...o}),i.label,i.required?" *":""]}),i.hint&&n.jsx("span",{className:"w6w-hint",children:i.hint})]},i.key);const c=i.type==="secret"||i.secret===!0;if(i.type==="json"&&c&&!l)return n.jsx(Cc,{field:i,value:String(u??""),onChange:p=>a(i.key,p)},i.key);if(i.type==="json"||i.type==="text")return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[i.label,i.required?" *":""]}),n.jsx("textarea",{className:c?"w6w-secret-input":void 0,rows:i.type==="json"?6:3,value:String(u??""),placeholder:l&&c?"•••••• (unchanged)":void 0,onChange:p=>a(i.key,p.target.value),name:`w6w-cred-${i.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other"}),i.hint&&n.jsx("span",{className:"w6w-hint",children:i.hint})]},i.key);const d=i.type==="number"?"number":"text";return n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[i.label,i.required?" *":""]}),n.jsx("input",{type:d,className:c?"w6w-secret-input":void 0,value:String(u??""),placeholder:l&&c?"•••••• (unchanged)":void 0,onChange:p=>a(i.key,i.type==="number"&&!(l&&p.target.value==="")?Number(p.target.value):p.target.value),name:`w6w-cred-${i.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...o}),i.hint&&n.jsx("span",{className:"w6w-hint",children:i.hint})]},i.key)})]})}const Nc=/(^|_)(private_key|secret|password|token)$/i,qo=["client_email","client_id","project_id","private_key_id","private_key"],kc=["type","universe_domain"];function Sc(e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object"||Array.isArray(t))return null;const s=o=>{const r=qo.indexOf(o);return r===-1?qo.length:r};return Object.entries(t).filter(([o,r])=>typeof r=="string"&&r!==""&&!/^https?:\/\//.test(r)&&!kc.includes(o)).sort(([o],[r])=>s(o)-s(r)).map(([o,r])=>({key:o,label:(o.charAt(0).toUpperCase()+o.slice(1)).replace(/_/g," "),value:r,secret:Nc.test(o)}))}function Cc({field:e,value:t,onChange:s}){const o=b.useRef(null),r=t.trim()===""?null:Sc(t),a=n.jsxs("span",{children:[e.label,e.required?" *":""]}),i=n.jsx("input",{ref:o,type:"file",accept:"application/json,.json",hidden:!0,onChange:async l=>{var c;const u=(c=l.target.files)==null?void 0:c[0];u&&s(await u.text()),l.target.value=""}});return r?n.jsxs("div",{className:"w6w-field",children:[a,n.jsxs("div",{className:"w6w-keyfile","data-testid":`keyfile-${e.key}`,children:[n.jsx("dl",{children:r.map(l=>n.jsxs("div",{children:[n.jsx("dt",{children:l.label}),n.jsx("dd",{children:l.secret?n.jsx("span",{className:"w6w-keyfile-secret",children:"•••••••• encrypted when you save"}):n.jsx("code",{children:l.value})})]},l.key))}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>s(""),children:"Use a different key"})]})]}):n.jsxs("div",{className:"w6w-field",children:[a,n.jsx("textarea",{className:"w6w-keyfile-paste",rows:4,value:t,"aria-label":e.label,placeholder:"Paste the key file's contents here",onChange:l=>s(l.target.value),name:`w6w-cred-${e.key}`,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,"data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other"}),n.jsxs("span",{className:"w6w-hint",children:[t.trim()!==""?"That isn't complete JSON yet. ":"","Paste the whole file, or"," ",n.jsx("button",{type:"button",className:"w6w-linkbtn",onClick:()=>{var l;return(l=o.current)==null?void 0:l.click()},children:"choose the .json file"}),"."]}),i]})}function Fr({credentials:e,mode:t,onModeChange:s,selectedId:o,onSelect:r,canUseExisting:a=!0,contract:i,emptyHint:l,onCreateShared:u}){const c=d=>{const p=Object.values(d.display??{}).filter(Boolean);return p.length>0?`${d.name} (${p.join(", ")})`:d.name};return n.jsxs("div",{className:"w6w-stack",children:[a&&n.jsxs("div",{className:"w6w-field",role:"radiogroup","aria-label":"Credential",children:[n.jsxs("span",{children:["Credential",i?` (${i})`:""]}),n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"w6w-credential-mode",checked:t==="existing",onChange:()=>s("existing")})," ","Use existing"]}),n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"w6w-credential-mode",checked:t==="new",onChange:()=>s("new")})," ","Enter new"]})]}),a&&t==="existing"&&e.length===0&&n.jsxs("div",{className:"w6w-stack","data-w6w":"credential-empty",children:[l&&n.jsx("p",{className:"w6w-muted w6w-small",children:l}),u&&n.jsx("div",{children:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:u,children:"Create a shared credential"})})]}),a&&t==="existing"&&e.length>0&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Stored credential"}),n.jsx("select",{name:"w6w-credential-id",value:o,onChange:d=>r(d.target.value),children:e.map(d=>n.jsx("option",{value:d.id,children:c(d)},d.id))})]})]})}function Lr(e){const t=(e.bindingFields??[]).filter(r=>r.key!=="delegatedUser");return e.impersonation==="none"?t:[{...(e.bindingFields??[]).find(r=>r.key==="delegatedUser")??{type:"string"},key:"delegatedUser",label:"Workspace user to act as",type:"string",required:e.impersonation==="required"},...t]}function Mr(e,t){const s={},o={};for(const r of e){const a=t[r.key];a==null||a===""||(r.key==="delegatedUser"?s.delegatedUser=String(a):o[r.key]=a)}return Object.keys(o).length>0&&(s.settings=o),Object.keys(s).length>0?s:void 0}const Dr=b.createContext(void 0),Ac="width=560,height=720,menubar=no,toolbar=no,location=no";function Wr(e){return new Promise((t,s)=>{const o=window.open(e,"w6w-oauth",Ac);if(!o){s(new Error("Popup blocked — allow popups for this site and try again."));return}let r=!1;const a=()=>{r=!0,window.removeEventListener("message",i),window.clearInterval(l)},i=u=>{const c=u.data;if((c==null?void 0:c.w6w)==="oauth-result"){a();try{o.close()}catch{}c.ok&&typeof c.connectionId=="string"?t({connectionId:c.connectionId}):s(new Error(c.error??"OAuth flow failed."))}};window.addEventListener("message",i);const l=window.setInterval(()=>{r||o.closed&&(a(),s(new Error("OAuth popup was closed before the flow completed.")))},500)})}const Ec=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function Tc(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function qr(e,t){return{onKeyDown:s=>{if((t==null?void 0:t.enabled)===!1||s.key!=="Enter"||s.shiftKey||s.altKey||s.ctrlKey||s.metaKey||s.nativeEvent.isComposing)return;const o=s.target;o.tagName!=="TEXTAREA"&&(Tc(o)||o.tagName==="INPUT"&&Ec.has(o.type)||(s.preventDefault(),e()))}}}function _s(e){const t=je(),s=b.useContext(Dr),o=e.onCreateSharedCredential??s,[r,a]=b.useState(null),[i,l]=b.useState(!!e.initialAppId);return b.useEffect(()=>{const u=e.initialAppId;if(!u)return;let c=!1;const d=m=>{c||(a(m),l(!1))},p=t.listAppsByIds;if(p)return p([u]).then(m=>d(m.find(w=>w.id===u)??null)).catch(()=>d(null)),()=>{c=!0};const f=t.listApps;return typeof f=="function"?f().then(m=>d(m.find(w=>w.id===u)??null)).catch(()=>d(null)):d(null),()=>{c=!0}},[t,e.initialAppId]),r?n.jsx(ke,{title:r.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:r.id}),r.version&&` · v${r.version}`]}),onClose:e.onClose,size:"xl",titleIcon:n.jsx(gt,{src:r.iconSvg,srcDark:r.iconSvgDark,brandColor:r.brandColor,name:r.displayName,theme:e.theme,size:22}),headerRight:e.initialAppId?void 0:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>a(null),children:"← Apps"}),children:n.jsx(Rc,{app:r,onCreated:e.onCreated,onClose:e.onClose,onCreateSharedCredential:o})}):i?n.jsx(ke,{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(ke,{title:"Add connection",onClose:e.onClose,size:"xl",children:n.jsx("div",{className:"w6w-stepbuilder-content",children:n.jsx(ot,{onSelectApp:a,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function Rc({app:e,onCreated:t,onClose:s,onCreateSharedCredential:o}){var ee;const r=je(),[a,i]=b.useState(null),[l,u]=b.useState(""),[c,d]=b.useState(""),[p,f]=b.useState({}),[m,w]=b.useState(null),[h,g]=b.useState(!1),[y,x]=b.useState(null),[C,E]=b.useState(null),[S,j]=b.useState(""),[N,A]=b.useState({});b.useEffect(()=>{let v=!1;return i(null),r.getAppAuth(e.id).then(D=>!v&&i(D.filter(Y=>Y.available!==!1))).catch(D=>!v&&w(D.message)),()=>{v=!0}},[r,e.id]);const $=a??[],P=$.find(v=>v.key===l)??$.find(v=>v.default===!0)??$[0],R=(P==null?void 0:P.fields)??[],I=(P==null?void 0:P.type)==="oauth2",T=P==null?void 0:P.serviceAccount,_=(P==null?void 0:P.accepts)??(T==null?void 0:T.accepts)??[],q=r.listCredentials,U=!I&&_.length>0&&typeof q=="function",B=(y??[]).filter(v=>v.status==="active"&&!v.private&&_.includes(v.contract)),F=C??(B.length>0?"existing":"new"),O=B.some(v=>v.id===S)?S:((ee=B[0])==null?void 0:ee.id)??"",K=U&&T?Lr(T):[],G=(P==null?void 0:P.key)??"";b.useEffect(()=>{if(!U||!q)return;let v=!1;return x(null),E(null),q.call(r,{appId:e.id,authKey:G}).then(D=>!v&&x(D)).catch(()=>!v&&x([])),()=>{v=!0}},[r,e.id,U,G,q]);const Q=(P==null?void 0:P.key)==="zero-credential",M=v=>v===void 0||v==="",X=!I&&!Q&&(U?y===null||K.some(v=>v.required&&M(N[v.key]))||(F==="existing"?O==="":R.some(v=>v.required&&M(p[v.key]))):R.some(v=>v.required&&M(p[v.key]))),J=!P||!I&&!Q&&X||h;async function W(){if(P){w(null),g(!0);try{if(Q)t({connectionId:`zerocred:${e.id}`});else if(I){const{authorizationUrl:v}=await r.startAppOAuthFlow(e.id,P.key,{displayName:c||void 0}),{connectionId:D}=await Wr(v);t({connectionId:D})}else if(U&&F==="existing"){const v=Mr(K,N),D={authKey:P.key,credentialId:O,...v?{binding:v}:{},...c?{displayName:c}:{}},Y=await r.createConnection(e.id,D);t({connectionId:Y.id})}else{const v=_r(R,p);if("error"in v){w(v.error);return}let D=v.values;if(T){D={};for(const re of K){const z=N[re.key];z==null||z===""||(D[re.key]=re.key==="delegatedUser"?String(z):z)}Object.assign(D,p)}const Y=await r.createConnection(e.id,{authKey:P.key,credential:D,displayName:c||void 0});t({connectionId:Y.id})}}catch(v){w(v.message)}finally{g(!1)}}}const ne=qr(W,{enabled:!J});return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-modal-body",children:n.jsxs("div",{className:"w6w-stack",children:[a===null&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading auth methods…"}),a!==null&&$.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."}),$.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Auth method"}),n.jsx("select",{value:(P==null?void 0:P.key)??"",onChange:v=>{u(v.target.value),f({}),A({}),E(null),w(null)},children:$.map(v=>n.jsxs("option",{value:v.key,children:[v.displayName??v.key," (",v.type,")"]},v.key))})]}),P&&n.jsxs(n.Fragment,{children:[!Q&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Display name"}),n.jsx("input",{type:"text",value:c,onChange:v=>d(v.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",...ne})]}),P.description&&n.jsx("p",{className:"w6w-muted w6w-small",children:P.description}),P.setup&&P.setup.length>0?n.jsx(Oc,{steps:P.setup}):null,Q?null:I?n.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",n.jsx("strong",{children:P.displayName??P.key})," to authorize this connection."]}):U?n.jsxs(n.Fragment,{children:[n.jsx(Fr,{credentials:B,mode:F,onModeChange:E,selectedId:O,onSelect:j,emptyHint:"No shared credentials of this type yet.",onCreateShared:o?()=>{s(),o()}:void 0}),T&&T.scopes.length>0&&n.jsx(Ic,{scopes:T.scopes}),K.length>0&&n.jsx(pn,{fields:K,values:N,onChange:A,enterSubmitProps:ne}),F==="new"&&n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Saved for this app only."}),n.jsx(pn,{fields:R,values:p,onChange:f,enterSubmitProps:ne})]})]}):n.jsx(pn,{fields:R,values:p,onChange:f,enterSubmitProps:ne})]}),m&&n.jsx("div",{className:"w6w-result w6w-error",children:m})]})}),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:J,onClick:W,children:h?Q?"Saving…":I?"Waiting for authorization…":"Saving…":Q?"Use this":I?`Sign in with ${(P==null?void 0:P.displayName)??(P==null?void 0:P.key)??"provider"}`:"Save connection"})]})]})}function Oc({steps:e}){return n.jsxs("details",{className:"w6w-auth-setup",children:[n.jsx("summary",{className:"w6w-auth-setup-title",children:"Where do I get this?"}),n.jsx("ol",{children:e.map(t=>n.jsxs("li",{children:[t.text,t.url&&/^https:\/\//.test(t.url)?n.jsxs(n.Fragment,{children:[" ",n.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",children:"Open ↗"})]}):null]},t.text))})]})}function Ic({scopes:e}){const[t,s]=b.useState(!1),o=e.join(",");return n.jsxs("div",{className:"w6w-scopes",children:[n.jsx("span",{className:"w6w-muted w6w-small",children:"Scopes"}),n.jsx("code",{children:o}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(o).then(()=>{s(!0),setTimeout(()=>s(!1),1500)})},children:t?"Copied":"Copy"})]})}const Et=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Fs=[["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)"]],an={"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."},Ur=new Set(Fs.map(([e])=>e)),Vr=new Set(["is-true","is-false","has-value","is-empty"]),$c=new Set(["and","or","xor","!","!!","==","!=",...Ur]);function Uo(e){if(!Et(e))return!0;const t=Object.keys(e);return!(t.length===1&&$c.has(t[0]))}function Vo(e){return Vr.has(e)}const Ho={...Object.fromEntries(Fs),"==":"equals","!=":"does not equal",in:"is in"};function Pc(e){return e.startsWith("not:")?`Not (${Ho[e.slice(4)]??e.slice(4)})`:Ho[e]??e}const Hr=[["and","All of (AND)"],["or","Any of (OR)"],["xor","Exactly one of (XOR)"]],Br=Object.fromEntries(Hr);function _c(e){return Br[e]??e}function Ls(e,t=!0){if(!Et(e))return;const s=Object.entries(e);if(s.length!==1)return;const[o,r]=s[0];if(o==="!!"&&Array.isArray(r)&&r.length===1&&Uo(r[0]))return{left:r[0],operator:"has-value",right:!0};if(o==="!"&&Array.isArray(r)&&r.length===1){const a=Ls(r[0],!1);return a?t&&!a.negated?{...a,negated:!0}:void 0:Uo(r[0])?{left:r[0],operator:"is-empty",right:!0}:void 0}if(!(!Ur.has(o)||!Array.isArray(r)||r.length!==2)){if(o==="==="&&typeof r[1]=="boolean")return{left:r[0],operator:r[1]?"is-true":"is-false",right:r[1]};if(!Vr.has(o))return{left:r[0],operator:o,right:r[1]}}}function Fc(e){if(!(!Et(e)||Object.keys(e).length!==1))return Ls(e.$expr)}function Lc(e){const t=Fc(e);if(t)return{combinator:"and",rows:[t]};if(!Et(e)||Object.keys(e).length!==1||!Et(e.$expr))return;const s=Object.entries(e.$expr);if(s.length!==1)return;const[o,r]=s[0];if(!Object.hasOwn(Br,o)||!Array.isArray(r)||r.length===0)return;const a=r.map(i=>Ls(i));if(!a.some(i=>i===void 0))return{combinator:o,rows:a}}function Bo(e){const t=e.rows.filter(s=>s.left!=="").map(s=>{const o=s.operator==="is-true"||s.operator==="is-false"?{"===":[s.left,s.operator==="is-true"]}:s.operator==="has-value"?{"!!":[s.left]}:s.operator==="is-empty"?{"!":[s.left]}:{[s.operator]:[s.left,s.right]};return s.negated?{"!":[o]}:o});return t.length===0?!1:{$expr:t.length===1?t[0]:{[e.combinator]:t}}}function ls(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"?Rn(e):Ye(e)?e.parts:null;if(t){const s=t.map(o=>o.kind==="expr"?o.expr:o.kind==="var"?{var:o.ref}:o.kind==="secret"?{var:`secrets.${o.ref}`}:o.value??"");return s.length===1?s[0]:{cat:s}}return e}function Jo(e){return typeof e=="string"?ls(e)===e?e:JSON.stringify(e):Et(e)?Object.keys(e).length===1&&typeof e.var=="string"?ae.serializeTemplate([{kind:"var",ref:e.var}]):ae.serializeTemplate([{kind:"expr",expr:e}]):JSON.stringify(e)??""}const Jr={left:"",operator:"is-true",right:!0},zo={combinator:"and",rows:[Jr]},Mc=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function Pn({values:e,onChange:t,readOnly:s,purpose:o="if"}){const r=Xe(),a=e.condition===void 0?!0:e.condition,i=Lc(a),[l,u]=b.useState(!1),[c,d]=b.useState(i??zo),p=b.useRef(0),[f,m]=b.useState(()=>c.rows.map(()=>p.current++)),w=i!==void 0||typeof a=="boolean",h=Mc(Bo(c),a)?c:i??zo,g=h.rows.map((j,N)=>f[N]??-1-N),y=(j,N=g)=>{d(j),m(N),t({...e,condition:Bo(j)})},x=(j,N)=>y({...h,rows:h.rows.map((A,$)=>$===j?{...A,...N}:A)}),C=()=>y({...h,rows:[...h.rows,Jr]},[...g,p.current++]),E=j=>y({...h,rows:h.rows.filter((N,A)=>A!==j)},g.filter((N,A)=>A!==j)),S=h.rows.length>1;return n.jsxs("div",{className:"w6w-condition-editor",children:[l||!w?n.jsx(Fe,{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:h.combinator,onChange:j=>y({...h,combinator:j.target.value}),children:Hr.map(([j,N])=>n.jsx("option",{value:j,children:N},j))}),h.rows.map((j,N)=>{const A=Vo(j.operator);return n.jsxs("div",{className:`w6w-condition-row${S?" w6w-condition-row-removable":""}${A?" w6w-condition-row-boolean":""}`,children:[n.jsxs("label",{className:"w6w-condition-negate",title:"Reverse this condition's result",children:[n.jsx("input",{type:"checkbox","aria-label":`Negate condition ${N+1}`,checked:j.negated??!1,disabled:s,onChange:$=>x(N,{negated:$.target.checked})}),"Not"]}),n.jsx(zt,{value:Jo(j.left),"aria-label":"Condition field",placeholder:"Field or expression",readOnly:s,onChange:$=>x(N,{left:ls($)})}),n.jsx("select",{className:"w6w-condition-comparison","aria-label":"Condition comparison",title:an[j.operator],disabled:s,value:j.operator,onChange:$=>x(N,{operator:$.target.value,right:$.target.value==="is-true"?!0:$.target.value==="is-false"?!1:Vo($.target.value)?!0:A?"":j.right}),children:Fs.map(([$,P])=>n.jsx("option",{value:$,title:an[$],children:P},$))}),!A&&n.jsx(zt,{value:Jo(j.right),"aria-label":"Condition value",placeholder:"Value or expression",readOnly:s,onChange:$=>x(N,{right:ls($)})}),S&&!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-remove",title:"Remove condition","aria-label":`Remove condition ${N+1}`,onClick:()=>E(N),children:n.jsx(le.Icon,{name:"trash",size:14})})]},g[N])}),!s&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-condition-add",onClick:C,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(h.rows.map(j=>j.operator))].map(j=>an[j]?n.jsx("p",{className:"w6w-muted w6w-small",children:an[j]},j):null)]}),w&&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(le.Icon,{name:l?"form":"code",size:14})}),o!=="router"&&n.jsx("p",{className:"w6w-muted w6w-small",children:o==="stop"?"End the workflow when this condition is true.":r.loop?"When false, skip the remaining steps for this item.":"Continue when this condition is true."})]})}const 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 zr({value:e,onChange:t,readOnly:s,target:o="step"}){const r=!!e,a=(e==null?void 0:e.maxAttempts)??3,i=(e==null?void 0:e.delayMs)??1e3,l=(e==null?void 0:e.backoff)??"fixed",u=c=>t({maxAttempts:a,delayMs:i,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:r,disabled:s,onChange:c=>t(c.target.checked?{maxAttempts:a,delayMs:i,backoff:l}:void 0)})," ","Retry on failure"]}),n.jsx("span",{className:"w6w-hint",children:Dc[o]})]}),r&&n.jsxs("div",{className:"w6w-field-row",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Attempts"}),n.jsx("input",{type:"number",min:1,value:a,readOnly:s,onChange: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:i,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 Kr({config:e,onChange:t,readOnly:s,hasGraph:o=!0,failureHandling:r=!0,retryControls:a=!0,reroute:i}){const l=e.onError??"fail";return n.jsxs("div",{className:"w6w-stack",children:[r&&n.jsxs(n.Fragment,{children:[a&&n.jsx(zr,{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"}),o&&n.jsx("option",{value:"continue-record",children:"Continue to the next step & record the error"})]}),o?n.jsxs("span",{className:"w6w-muted w6w-small",children:["Retries run first: this policy is reached only once this step's retry attempts (if any) are exhausted — a run that succeeds on a later attempt continues down the normal path instead. Once reached, ",n.jsx("strong",{children:"Continue"})," and"," ",n.jsx("strong",{children:"Continue & record the error"})," both carry on down this step's ordinary outgoing edges despite the failure. If this step has an outgoing"," ",n.jsx("strong",{children:"error"})," edge on the canvas, that edge decides what happens instead and this policy is not consulted — drawn by dragging from the step's error exit port."]}):n.jsxs("span",{className:"w6w-muted w6w-small",children:["Retries run first: this policy (and reroute, below) is only reached once this step's retry attempts (if any) are exhausted — a run that succeeds on a later attempt continues normally. This step has no canvas of its own, so it can't carry an error edge. Set a ",n.jsx("strong",{children:"reroute"})," target below to send a failure somewhere else instead of stopping."]})]})]}),i&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Reroute on failure"}),n.jsxs("div",{className:"w6w-field-row",children:[i.picker,i.value&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:s,onClick:()=>i.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 _n(e){return e.$merge!==void 0}function Gr(e){const t=e.$merge;if(t===void 0)return e;if(!(ct(t)||Ye(t)||Ts(t)||typeof t=="string"&&Rn(t)))return t&&typeof t=="object"&&!Array.isArray(t)&&!lt(t)&&!("$merge"in t)?{...e,...t}:null}function Yr(e,t,s=[]){if(Ye(e)||lt(e)||Es(e)||Ts(e)||e===null||typeof e!="object")return Jt(e,t);const o=r=>Yr(r,t);return Array.isArray(e)?e.map(o):Object.fromEntries(Object.entries(e).map(([r,a])=>[r,s.includes(r)?a:o(a)]))}function Ms({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(Fe,{params:[{key:"$merge",label:"JSON customization",type:"json",required:!0,default:{},whole:!0}],values:e,onChange:t,readOnly:s}),Gr(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&&_n(e)&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>{const{$merge:o,...r}=e;t(r)},children:"Remove JSON customization"})]})}function Ds(e){const{label:t,onClick:s,disabled:o,className:r,...a}=e;return n.jsx(On,{label:t,onClick:s,disabled:o,className:r,danger:!0,icon:"delete","data-testid":a["data-testid"]})}function Xr({values:e,onChange:t,readOnly:s}){const o=Array.isArray(e.routes)?e.routes:xn(Ke,"route").routes,r=o.filter(y=>!y.default),[a,i]=b.useState(null),[l,u]=b.useState(null),[c,d]=b.useState(null),[p,f]=b.useState(""),m=y=>t({...e,routes:[...y,...o.filter(x=>x.default)]}),w=(y,x)=>m(r.map(C=>C.id===y?{...C,...x}:C)),h=(y,x)=>{const C=r.findIndex(j=>j.id===y);if(C<0||x<0||x>=r.length||C===x)return;const E=[...r],[S]=E.splice(C,1);E.splice(x,0,S),m(E)},g=y=>{p.trim()&&w(y.id,{label:p.trim()}),d(null)};return n.jsxs("div",{className:"w6w-router-editor",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"First match wins. Drag routes to change their order."}),n.jsx("div",{className:"w6w-router-routes",children:r.map((y,x)=>n.jsxs("div",{className:`w6w-router-route${a===y.id?" is-dragging":""}${l===y.id?" is-drop-target":""}`,"data-route-id":y.id,onDragOver:C=>{s||!a||a===y.id||(C.preventDefault(),C.dataTransfer.dropEffect="move",u(y.id))},onDrop:C=>{C.preventDefault(),!s&&a&&h(a,x),i(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 ${y.label||y.id}`,title:"Drag to reorder · arrow keys to move",onDragStart:C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",y.id);const E=C.currentTarget.closest(".w6w-router-route");E&&C.dataTransfer.setDragImage(E,16,16),i(y.id)},onDragEnd:()=>{i(null),u(null)},onKeyDown:C=>{C.key!=="ArrowUp"&&C.key!=="ArrowDown"||(C.preventDefault(),h(y.id,x+(C.key==="ArrowUp"?-1:1)))},children:n.jsx(le.Icon,{name:"grip",size:14})}),n.jsx("span",{className:"w6w-step-rename",children:c===y.id&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Route name",value:p,onChange:C=>f(C.target.value),onBlur:()=>g(y),onKeyDown:C=>{C.key==="Enter"&&g(y),C.key==="Escape"&&d(null)}}):n.jsxs("button",{type:"button",className:"w6w-router-route-name",disabled:s,"aria-label":`Rename ${y.label||y.id}`,onClick:()=>{f(y.label||y.id),d(y.id)},children:[y.label||y.id,!s&&n.jsx(le.Icon,{name:"edit",size:12})]})}),n.jsx(Ds,{label:`Remove ${y.label||y.id}`,disabled:s,onClick:()=>m(r.filter(C=>C.id!==y.id))})]}),n.jsx(Pn,{values:{condition:y.condition??!1},onChange:C=>w(y.id,{condition:C.condition}),readOnly:s,purpose:"router"})]},y.id))}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-router-add",disabled:s,onClick:()=>{let y=1;for(;o.some(x=>x.id===`route_${y}`);)y++;m([...r,{id:`route_${y}`,label:`Route ${y}`,condition:!1}])},children:[n.jsx("span",{"aria-hidden":"true",children:"+"})," Add route"]})]})}function Zr({value:e,onCommit:t,readOnly:s}){const[o,r]=b.useState(!1),[a,i]=b.useState(e),[l,u]=b.useState(null),c=()=>{const d=a.trim(),p=d&&d!==e?t(d):null;if(p){u(p);return}u(null),r(!1)};return n.jsxs("span",{className:"w6w-step-rename",children:[o&&!s?n.jsx("input",{autoFocus:!0,"aria-label":"Node name",value:a,onChange:d=>{i(d.target.value),u(null)},onBlur:c,onKeyDown:d=>{d.key==="Enter"&&c(),d.key==="Escape"&&(i(e),u(null),r(!1))}}):n.jsxs(n.Fragment,{children:[n.jsx("code",{children:e}),!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Rename node","aria-label":"Rename node",onClick:()=>{i(e),r(!0)},children:n.jsx(le.Icon,{name:"edit",size:15})})]}),l&&n.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:l})]})}function Qr({values:e,onChange:t,readOnly:s}){const o=e.condition!==void 0&&e.condition!==!0;return n.jsxs("div",{className:"w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Stop when"}),n.jsxs("select",{"aria-label":"Stop when",disabled:s,value:o?"condition":"always",onChange:r=>{const a=r.target.value==="condition";t({...e,condition:!a})},children:[n.jsx("option",{value:"always",children:"Always"}),n.jsx("option",{value:"condition",children:"A condition matches"})]})]}),o?n.jsx(Pn,{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 Wc=["props","code"];function qc(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ea({params:e,values:t,onChange:s,onValidityChange:o,readOnly:r,initialView:a="props"}){const i=e.length>0,[l,u]=b.useState(a),c=!i||l==="code",[d,p]=b.useState(()=>Ko(t)),[f,m]=b.useState(!0),w=b.useRef(!0),h=x=>{x!==w.current&&(w.current=x,m(x),o==null||o(x))},g=x=>{x==="code"&&p(Ko(t)),h(!0),u(x)},y=i?"Values (JSON)":"Payload";return n.jsxs("div",{className:"w6w-stack",children:[i&&n.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:n.jsx(Mn,{view:l,views:[...Wc],onChange:x=>g(x)})}),c?n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:y}),n.jsx(ze,{value:d,onChange:p,readOnly:r,minHeight:"140px","aria-label":`${y} JSON`,onValidChange:x=>{const C=qc(x);h(C),C&&s(x)},onValidityChange:x=>{x.valid||h(!1)}}),!f&&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(Fe,{params:e,values:t,onChange:s,readOnly:r})]})}function Ko(e){return JSON.stringify(e??{},null,2)}const Uc=new Set(["http:","https:","mailto:"]);function Vc(e){try{return Uc.has(new URL(e).protocol)?e:""}catch{return""}}const Hc=["img"];function Bc({node:e,href:t,children:s,...o}){return n.jsx("a",{...o,href:t||void 0,target:"_blank",rel:"noopener noreferrer nofollow",children:s})}function ta(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 Jc({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 Ws({content:e,className:t,copyable:s=!0}){const{frontmatter:o,body:r}=ta(e),a=n.jsxs("div",{className:t,children:[(o==null?void 0:o.trim())&&n.jsx(Jc,{yaml:o}),n.jsx(li,{skipHtml:!0,urlTransform:Vc,disallowedElements:Hc,unwrapDisallowed:!0,components:{a:Bc},children:r})]});return s?n.jsx(le.Copyable,{value:e,label:"Copy Markdown",className:"w6w-copyable--document",children:a}):a}function zc(e,t){return e.render?e.render(t):String(t[e.key]??"")}function na(e){const{columns:t,rows:s,rowKey:o,onRowClick:r,getRowHref:a,empty:i,loading:l,className:u,testId:c}=e;return s.length===0&&!l&&i!==void 0&&i!==null?n.jsx(n.Fragment,{children:i}):n.jsx("div",{className:"w6w-data-table-frame",children:n.jsxs("table",{className:u?`w6w-data-table ${u}`:"w6w-data-table","data-testid":c,"aria-busy":l?!0:void 0,children:[n.jsx("thead",{children:n.jsx("tr",{children:t.map(d=>n.jsx("th",{style:{width:d.width,textAlign:d.align},scope:"col",children:d.header},d.key))})}),n.jsx("tbody",{children:s.map(d=>{var f;const p=a==null?void 0:a(d);return n.jsx("tr",{"data-testid":(f=e.rowTestId)==null?void 0:f.call(e,d),className:r?"w6w-data-table-row-clickable":void 0,onClick:r?m=>r(d,m):void 0,children:t.map(m=>{const w=zc(m,d);return n.jsx("td",{style:{textAlign:m.align},children:p!==void 0&&m.link!==!1?n.jsx("a",{className:"w6w-data-table-link",href:p,children:w}):w},m.key)})},o(d))})})]})})}const sa="default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'";function oa(e){return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${sa}">${e}`}function ra({html:e}){return n.jsx("iframe",{title:"HTML preview",className:"w6w-html-preview",sandbox:"",referrerPolicy:"no-referrer",srcDoc:oa(e)})}function aa(e){return typeof e=="string"?"string":typeof e=="number"?"number":typeof e=="boolean"?"boolean":"null"}function Kc(e){return aa(e)==="string"?JSON.stringify(e):String(e)}function Gc(e){return typeof e=="object"&&e!==null}function Yc(e,t){return`${t} ${e?"item":"key"}${t===1?"":"s"}`}function Xc({value:e,expandDepth:t=2}){return n.jsx(ia,{label:void 0,value:e,depth:0,expandDepth:t})}function ia(e){const{label:t,value:s,depth:o,expandDepth:r}=e,a=Gc(s),i=Array.isArray(s),l=a?i?s.map((c,d)=>[d,c]):Object.entries(s):[],u=t===void 0?null:n.jsx("span",{className:"w6w-json-key",children:t});return a&&l.length>0?n.jsxs("details",{className:"w6w-json-node",open:o<r,children:[n.jsxs("summary",{children:[u,i?"[…]":"{…}"," ",n.jsx("span",{className:"w6w-json-count",children:Yc(i,l.length)})]}),n.jsx("div",{className:"w6w-json-children",children:l.map(([c,d])=>n.jsx(ia,{label:c,value:d,depth:o+1,expandDepth:r},String(c)))})]}):n.jsxs("div",{className:"w6w-json-leaf",children:[u,u===null?null:": ",n.jsx("span",{className:`w6w-json-${a?"null":aa(s)}`,children:a?i?"[]":"{}":Kc(s)})]})}const cs=262144,Zc=/^#{1,6}\s+\S/,Qc=/^```/,eu=/^\s*(?:[-*+]|\d+\.)\s+\S/,tu=/\[[^\]\n]+\]\(https?:\/\/[^)\s]+\)/;function la(e){if(e===void 0)return{format:"text",text:""};if(typeof e!="string")return{format:"json",data:e};const t=e.trim();if(t.startsWith("{")||t.startsWith("["))try{const o=JSON.parse(t);if(o!==null&&typeof o=="object")return{format:"json",data:o}}catch{}if(/^<!doctype html/i.test(t)||/^<html[\s>]/i.test(t))return{format:"html",text:e};if(t.startsWith("<")&&t.endsWith(">"))return{format:"xml",text:e};const s=t.split(`
|
|
16
|
+
`);return s.some(o=>Zc.test(o)||Qc.test(o))||s.filter(o=>eu.test(o)).length>=2||tu.test(t)?{format:"markdown",text:e}:{format:"text",text:e}}function ca(e){return e.format==="json"?JSON.stringify(e.data,null,2)??"":e.text}function Go(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function nu(e){if(!Go(e))return!1;const t=Object.keys(e);if(t.length!==2||!t.includes("columns")||!t.includes("rows"))return!1;const{columns:s,rows:o}=e;return Array.isArray(s)&&s.every(r=>typeof r=="string")&&Array.isArray(o)&&o.every(Go)}function su(e){try{return JSON.stringify(e).length}catch{return Number.POSITIVE_INFINITY}}function ou(e){return e===null?n.jsx("span",{className:"w6w-muted w6w-result-viewer-null",children:"null"}):typeof e=="object"?JSON.stringify(e):String(e)}const ru=65536;function Jn(e,t){return e.length>ru?n.jsx("pre",{className:"w6w-result-viewer-text",children:e}):n.jsx(le.CodeBlock,{code:e,language:t,copyable:!1,wrap:!0})}function Ae(e){const{value:t,format:s="auto",maxHeight:o=320,className:r}=e,a=b.useMemo(()=>s==="json"?{format:"json",data:t}:la(t),[t,s]),[i,l]=b.useState("rendered"),[u,c]=b.useState("table"),[d,p]=b.useState(2),[f,m]=b.useState(0),w=a.format==="json"?"":a.text,h=a.format==="html"||a.format==="markdown",g=h&&w.length>cs,y=b.useMemo(()=>a.format!=="json"||!nu(a.data)?null:{table:a.data,tooLarge:su(a.data)>cs},[a]),x=y!==null&&!y.tooLarge&&u==="table",C=b.useMemo(()=>((y==null?void 0:y.table.columns)??[]).map((A,$)=>({key:`${$}:${A}`,header:A,render:({row:P})=>ou(P[A])})),[y]),E=b.useMemo(()=>((y==null?void 0:y.table.rows)??[]).map((A,$)=>({i:$,row:A})),[y]),S=b.useMemo(()=>{try{return ca(a)}catch{return typeof t=="string"?t:String(t)}},[a,t]);let j;if(a.format==="json"){const A=n.jsx(Xc,{value:a.data,expandDepth:d},f);x?j=n.jsx(na,{columns:C,rows:E,rowKey:$=>String($.i),className:"w6w-result-viewer-table",testId:"result-viewer-table"}):y!=null&&y.tooLarge?j=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to show as a table — showing JSON."}),A]}):j=A}else if(a.format==="xml")j=Jn(a.text,"markup");else if(a.format==="text")j=n.jsx("pre",{className:"w6w-result-viewer-text",children:a.text});else{const A=a.format==="html"?"markup":"markdown";g?j=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to render — showing source."}),Jn(a.text,A)]}):i==="source"?j=Jn(a.text,A):a.format==="html"?j=n.jsx(ra,{html:a.text}):j=n.jsx(Ws,{content:a.text,copyable:!1})}let N=null;if(a.format==="json"){const A=y!==null&&!y.tooLarge?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${u==="table"?" active":""}`,"data-mode":"table","aria-pressed":u==="table",onClick:()=>c("table"),children:"Table"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${u==="json"?" active":""}`,"data-mode":"json","aria-pressed":u==="json",onClick:()=>c("json"),children:"JSON"})]}):null;N=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[A,x?null:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{p(Number.POSITIVE_INFINITY),m($=>$+1)},children:"Expand all"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{p(1),m($=>$+1)},children:"Collapse all"})]})]})}else h&&!g&&(N=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${i==="rendered"?" active":""}`,"data-mode":"rendered","aria-pressed":i==="rendered",onClick:()=>l("rendered"),children:"Rendered"}),n.jsx("button",{type:"button",className:`w6w-btn w6w-btn-ghost${i==="source"?" active":""}`,"data-mode":"source","aria-pressed":i==="source",onClick:()=>l("source"),children:"Source"})]}));return n.jsxs("div",{className:["w6w-result-viewer",r??""].filter(Boolean).join(" "),"data-format":a.format,children:[N,n.jsx(le.Copyable,{value:S,label:"Copy result",className:"w6w-copyable--overlay",children:n.jsx("div",{className:"w6w-result-viewer-body",style:{maxHeight:o,overflow:"auto"},children:j})})]})}function ua(e,t){const s=e.filter(o=>o.appId===qe);return s.find(o=>o.nodeId===t)??s.find(o=>!o.nodeId)??s[0]??null}const au=/auth|token|secret|passw|cookie|api[-_]?key|signature|session/i,iu="••••••";function lu(e){const t={};for(const[s,o]of Object.entries(e))t[s]=au.test(s)?iu:o;return t}const cu=20;function uu({workflowId:e,stepId:t,stepWith:s,readOnly:o,onUse:r,using:a}){const i=je(),[l,u]=b.useState(void 0),[c,d]=b.useState(!1),[p,f]=b.useState({phase:"idle"}),[m,w]=b.useState(()=>Date.now()),h=b.useRef(null);b.useEffect(()=>{const j=i.listSubscriptionsForWorkflow;if(!j)return;let N=!1;return j(e).then(A=>!N&&u(ua(A,t))).catch(A=>!N&&f({phase:"error",message:A.message})),()=>{N=!0}},[i,e,t]);const g=b.useCallback(j=>{var A;const N=h.current;h.current=null,N&&(N.abort.abort(),j&&((A=i.stopWebhookListen)==null||A.call(i,N.subId,N.sessionId).catch(()=>{})))},[i]);b.useEffect(()=>()=>g(!0),[g]),b.useEffect(()=>{if(p.phase!=="waiting")return;const j=setInterval(()=>w(Date.now()),1e3);return()=>clearInterval(j)},[p.phase]);const y=()=>{const j=i.createSubscription;j&&(d(!0),j(qe,"webhook",{workflowId:e,connectionId:null,params:s??{}}).then(N=>u(N)).catch(N=>f({phase:"error",message:N.message})).finally(()=>d(!1)))},x=async()=>{var R;const j=i.startWebhookListen,N=i.pollWebhookListen;if(!l||!j||!N)return;g(!0),f({phase:"starting"});let A;try{A=(await j(l.id)).session}catch(I){f({phase:"error",message:I.message});return}const $=new AbortController,P={subId:l.id,sessionId:A.id,abort:$};for(h.current=P,w(Date.now()),f({phase:"waiting",session:A});;){let I;try{I=await N(l.id,A.id,{waitSeconds:cu,signal:$.signal})}catch(T){if(h.current!==P)return;h.current=null,f({phase:"error",message:T.message});return}if(h.current!==P)return;if(I.status==="captured"&&I.request){h.current=null,f({phase:"captured",session:I,request:I.request});return}if(I.status==="expired"){h.current=null,(R=i.stopWebhookListen)==null||R.call(i,l.id,A.id).catch(()=>{}),f({phase:"expired"});return}}},C=()=>{g(!0),f({phase:"idle"})};if(!i.startWebhookListen||!i.pollWebhookListen)return null;const E=l==null?void 0:l.webhookUrl,S=p.phase==="waiting"?Math.max(0,Math.ceil((Date.parse(p.session.expiresAt)-m)/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…"}):E?n.jsxs(n.Fragment,{children:[n.jsx(le.Copyable,{value:E,readOnly:!0,children:n.jsx("input",{type:"text",readOnly:!0,value:E,"aria-label":"Webhook URL"})}),p.phase==="waiting"||p.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:E}),"…",p.phase==="waiting"&&n.jsxs("span",{className:"w6w-muted",children:[" ",du(S)," left"]})]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:C,children:"Stop"})]}):n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:o,onClick:()=>void x(),children:p.phase==="captured"?"Listen again":"Listen for test event"}),p.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."}),!o&&i.createSubscription&&n.jsx("button",{type:"button",className:"w6w-btn",disabled:c,onClick:y,children:c?"Creating…":"Create webhook URL"})]}),p.phase==="expired"&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No request arrived in time. Listen again, then send the request."}),p.phase==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:p.message}),p.phase==="captured"&&n.jsx(pu,{request:p.request,receivedAt:p.session.receivedAt,readOnly:o,using:a,onUse:()=>r(p.request),stepId:t})]})}function du(e){const t=Math.floor(e/60);return t>0?`${t}:${String(e%60).padStart(2,"0")}`:`${e}s`}function pu({request:e,receivedAt:t,readOnly:s,using:o,onUse:r,stepId:a}){const i=Object.keys(e.query??{}).length>0;return n.jsxs("div",{className:"w6w-testout w6w-listen-captured","data-testid":"webhook-captured",children:[n.jsxs("div",{className:"w6w-testout-label",children:["Request received",t&&n.jsxs("span",{className:"w6w-muted",children:[" · ",new Date(t).toLocaleTimeString()]})]}),n.jsxs("div",{className:"w6w-small",children:[n.jsx("code",{children:e.method})," ",n.jsx("code",{children:e.path})]}),i&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Query"}),n.jsx(Ae,{value:e.query,maxHeight:120})]}),n.jsx("div",{className:"w6w-testout-label",children:"Headers"}),n.jsx(Ae,{value:lu(e.headers??{}),maxHeight:160}),n.jsx("div",{className:"w6w-testout-label",children:"Body"}),n.jsx(Ae,{value:e.body,maxHeight:240}),!s&&n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn",disabled:o,onClick:r,children:o?"Saving…":"Use as test data"}),n.jsxs("span",{className:"w6w-muted w6w-small",children:["Becomes this trigger's output, so later steps can use"," ",n.jsx("code",{children:`{{ nodes.${a}.output.body… }}`}),"."]})]})]})}function qs(e){return Array.isArray(e)?e:[]}function Us(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function Vs(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:Us(t.type),required:!!t.required}))}function us(e){const t={};for(const s of e){if(typeof s.key!="string"||s.key.trim()==="")continue;const o=Vs(s.type,s.default);o!==void 0&&(t[s.key]=o)}return t}function da(e,t){const s=(e??[]).find(r=>r&&r.nodeId===t);if(!s)return;const o=s.input;return o&&typeof o=="object"&&!Array.isArray(o)?o:{}}function fu(e){return Ye(e)||typeof e=="string"&&e.includes("{{")}function Bs(e,t=[]){const s=new Set(t.filter(r=>r.type==="secret").map(r=>r.key)),o={};for(const[r,a]of Object.entries(e))a===void 0||lt(a)||s.has(r)&&!fu(a)||(o[r]=a);return o}const ds=new Set;function pa(e){const t=e.then(()=>{},()=>{});return ds.add(t),t.then(()=>ds.delete(t)),e}async function fa(){await Promise.all([...ds])}function ha(e,t){const s=je(),o=typeof s.loadTestInputs=="function"&&!!e&&!!t,[r,a]=b.useState(!o),[i,l]=b.useState(void 0);b.useEffect(()=>{if(!o||!e||!t||!s.loadTestInputs){a(!0);return}let p=!1;return a(!1),fa().then(()=>{var f;return((f=s.loadTestInputs)==null?void 0:f.call(s,e))??[]}).then(f=>{p||(l(da(f,t)),a(!0))}).catch(()=>{p||a(!0)}),()=>{p=!0}},[s,o,e,t]);const u=b.useCallback(p=>{l(p),!(!e||!t||typeof s.saveTestInput!="function")&&pa(s.saveTestInput(e,t,p)).catch(f=>{console.error("test input save failed",f)})},[s,e,t]),c=b.useCallback((p,f)=>u(Bs(p,f)),[u]),d=b.useCallback(()=>u({}),[u]);return{loaded:r,supported:o,input:i,save:c,clear:d}}function wa({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 hu=600;function ma({app:e,action:t,fields:s,persist:o,listen:r}){const a=je(),i=ks(),l=b.useMemo(()=>qs(s),[s]),u=b.useMemo(()=>Hs(l),[l]),c=u.length>0,[d,p]=b.useState(()=>us(l)),[f,m]=b.useState(null),w=o==null?void 0:o.workflowId,h=o==null?void 0:o.stepId,g=ha(w,h),[y,x]=b.useState(!1),[C,E]=b.useState(!1),[S,j]=b.useState(!w||!h);b.useEffect(()=>{if(!w||!h){j(!0);return}if(!g.loaded)return;if(g.input!==void 0){const X=g.input;Object.keys(X).length>0&&(p(J=>({...J,...X})),x(!0),E(!0)),j(!0);return}let M=!1;return a.listStepTests(w,h).then(X=>{if(M)return;const J=X.length?X[X.length-1]:null;J!=null&&J.with&&(p(W=>({...W,...J.with})),Object.keys(J.with).length>0&&E(!0)),j(!0)}).catch(()=>{M||j(!0)}),()=>{M=!0}},[a,w,h,g.loaded]);const[N,A]=b.useState(0),$=()=>{clearTimeout(R.current),P.current=null,g.clear(),x(!1),p(us(l)),A(M=>M+1)},P=b.useRef(null),R=b.useRef(void 0),I=b.useRef(()=>{});I.current=()=>{clearTimeout(R.current);const M=P.current;P.current=null,M&&g.save(M,u)},b.useEffect(()=>()=>I.current(),[]);const T=M=>{p(M),!(!w||!h||!S)&&(P.current=M,clearTimeout(R.current),R.current=setTimeout(()=>I.current(),hu))},[_,q]=b.useState(!0),U=_&&Tt(u,d),B=async M=>{const X=M??d;clearTimeout(R.current),P.current=null,o&&g.save(X,u),m({status:"running"});let J;try{const W=await a.invokeAction(e,t,{input:X},{project:i});J={status:"done",value:W.value,logs:W.logs}}catch(W){const ne=W;J={status:"error",error:ne.message??String(W),errorCode:ne.code,logs:ne.logs}}if(m(J),o)try{const W=await a.saveStepTest(o.workflowId,o.stepId,{input:o.input,with:X});await a.recordStepTestRun(o.workflowId,o.stepId,{stepTestId:W.id,status:J.status==="done"?"succeeded":"failed",input:o.input,output:J.status==="done"?J.value:void 0,error:J.status==="error"?J.error:void 0})}catch(W){console.error("step test persist failed",W)}},F=f&&f.status!=="running"?f.logs:void 0,O=M=>{const X={...M};p(X),B(X)},K=r&&o&&n.jsx(uu,{workflowId:o.workflowId,stepId:o.stepId,stepWith:r.stepWith,readOnly:r.readOnly,onUse:O,using:(f==null?void 0:f.status)==="running"});return n.jsxs("div",{className:"w6w-stack",children:[K,K?n.jsxs("details",{className:"w6w-listen-manual","data-testid":"trigger-sample-payload",open:C,onToggle:M=>E(M.currentTarget.open),children:[n.jsx("summary",{className:"w6w-small",children:"Or test with a sample payload"}),G()]}):G(),Q()]});function G(){return n.jsxs("div",{className:"w6w-stack",children:[S?n.jsxs(n.Fragment,{children:[y&&n.jsx(wa,{onClear:$}),n.jsx(ea,{params:u,values:d,onChange:T,onValidityChange:q},N),!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||!U||(f==null?void 0:f.status)==="running",onClick:()=>void B(),children:(f==null?void 0:f.status)==="running"?"Running…":"▶ Test run"}),S&&!U&&n.jsx("span",{className:"w6w-muted w6w-small",children:_?"Fill the required fields to test.":"The payload must be a JSON object to test."})]})})]})}function Q(){return n.jsxs("div",{className:"w6w-steptest",children:[(f==null?void 0:f.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[f.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:f.errorCode})}),f.error]}),(f==null?void 0:f.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Output state (filled values)"}),n.jsx(Ae,{value:f.value,maxHeight:220})]}),F&&F.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx(le.Copyable,{value:F.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:F.join(`
|
|
18
|
+
`)})})]})]})}}const wu=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],mu=/^(?=\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 ba({values:e,onChange:t,readOnly:s}){const o=e.duration??"1s",r=typeof o=="string"?o.match(/^(\d+(?:\.\d+)?)([smhdw])$/i):null,[a,i]=b.useState("s"),[l,u]=b.useState("text"),[c,d]=b.useState(e.until?"until":"duration"),p=typeof o=="string"&&(!mu.test(o.trim())||/^P$/i.test(o.trim()));return n.jsxs("div",{className:"w6w-params-form",children:[n.jsxs("label",{children:["Wait for",n.jsxs("select",{"aria-label":"Wait for",disabled:s,value:c,onChange:f=>{const m=f.target.value;d(m),t({...e,duration:m==="duration"?"1s":"",until:""})},children:[n.jsx("option",{value:"duration",children:"A duration"}),n.jsx("option",{value:"until",children:"Until a timestamp"})]})]}),c==="until"?n.jsx(Fe,{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:f=>{r&&i((r==null?void 0:r[2].toLowerCase())??a),u(f.target.value)},children:[n.jsx("option",{value:"text",children:"Shorthand"}),n.jsx("option",{value:"value",disabled:!r,children:"Value and unit"})]})]}),l==="value"?n.jsxs("div",{className:"w6w-field-row",children:[n.jsxs("label",{children:["Value",n.jsx("input",{"aria-label":"Duration value",type:"number",min:"0",step:((r==null?void 0:r[2].toLowerCase())??a)==="s"?"any":"1",disabled:s,value:(r==null?void 0:r[1])??"",onChange:f=>t({...e,duration:`${f.target.value}${(r==null?void 0:r[2].toLowerCase())??a}`})})]}),n.jsxs("label",{children:["Unit",n.jsx("select",{"aria-label":"Duration unit",disabled:s,value:(r==null?void 0:r[2].toLowerCase())??a,onChange:f=>{i(f.target.value),t({...e,duration:`${(r==null?void 0:r[1])??""}${f.target.value}`})},children:wu.map(([f,m])=>n.jsx("option",{value:f,children:m},f))})]})]}):n.jsx(Fe,{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}),p&&n.jsx("p",{role:"alert",children:"Enter a duration such as 30s or 1h30m30s, using units w, d, h, m, s in order."})]})]})}function ya({anchorRef:e,onClose:t,children:s}){const o=b.useRef(null),[r,a]=b.useState(null),[i,l]=b.useState(null);return b.useEffect(()=>{const u=e.current;if(!u)return;const c=u.getBoundingClientRect();a({top:c.bottom+6,left:c.left,width:c.width}),l(u.closest("dialog")??document.body)},[e]),b.useEffect(()=>{function u(d){var f,m;const p=d.target;(f=o.current)!=null&&f.contains(p)||(m=e.current)!=null&&m.contains(p)||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]),!r||!i?null:bn.createPortal(n.jsx("div",{ref:o,className:"w6w-flyout",style:{top:r.top,left:r.left,width:r.width},children:s}),i)}function ga(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;const s=Object.keys(e),o=Object.keys(t);return s.length!==o.length?!1:s.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&ga(e[r],t[r]))}function bu(e,t){return e.map(s=>{const o=t&&Object.hasOwn(t,s.id)?t[s.id]:void 0,r=s.data.stepProblems;if(o===void 0||o.length===0){if(r===void 0&&!("stepProblems"in s.data))return s;const{stepProblems:a,...i}=s.data;return{...s,data:i}}return r&&ga(r,o)?s:{...s,data:{...s.data,stepProblems:structuredClone(o)}}})}const yu={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 gu(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=yu[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 xu(e,t){return(t==null?void 0:t.some(s=>s.code==="unknown_connection"&&e.uses.connection===s.connection))??!1}function Yo(e,t,s){if(!e)return"No connection";if(s)return"Couldn't load connections";if(t===null)return e;const o=t.find(r=>r.id===e);return o?o.builtIn?"Built-in":o.displayName??e:"Missing connection — choose another"}function fn(e,t,s){if(s.type==="update"){const r=fn(e,t,{type:"rename",ref:s.ref,name:s.name}),a=s.name.trim(),i=fn(r.nodes,r.connections,{type:"replace",ref:a,connection:s.connection});return s.nodeIds?fn(i.nodes,i.connections,{type:"assign",ref:a,nodeIds:s.nodeIds}):i}if(s.type==="add"||s.type==="rename"){const r=s.name.trim();if(!r)throw new Error("Give the workflow connection a name.");if(Object.hasOwn(t,r)&&(s.type==="add"||r!==s.ref))throw new Error("A workflow connection already uses that name.");if(s.type==="add")return{nodes:e,connections:{...t,[r]:{app:s.app,connection:s.connection}}}}if(!Object.hasOwn(t,s.ref))throw new Error("This workflow connection no longer exists.");const o=t[s.ref];switch(s.type){case"replace":return{nodes:e,connections:{...t,[s.ref]:{...o,connection:s.connection}}};case"rename":{const r=s.name.trim();return{connections:Object.fromEntries(Object.entries(t).map(([a,i])=>[a===s.ref?r:a,i])),nodes:e.map(a=>a.uses.connectionRef===s.ref?Gt(a,r):a)}}case"remove":{if(e.some(i=>i.uses.connectionRef===s.ref))throw new Error("Choose another connection for its nodes before removing this resource.");const{[s.ref]:r,...a}=t;return{nodes:e,connections:a}}case"assign":{const r=new Set(s.nodeIds);if(e.some(a=>r.has(a.id)&&a.uses.app!==o.app))throw new Error("A connection can only be assigned to nodes for the same app.");return{connections:t,nodes:e.map(a=>r.has(a.id)?Gt(a,s.ref):a)}}}}function $t(e,t){const{connectionRef:s,connection:o,app:r}=e.uses;if(s===void 0)return o??void 0;const a=t&&Object.hasOwn(t,s)?t[s]:void 0;return(a==null?void 0:a.app)===r?a.connection??void 0:void 0}function Js(e,t){const o=(e.split(/[./]/).filter(Boolean).at(-1)??"connection").toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"connection";let r=1;for(;Object.hasOwn(t,`${o}_${r}`);)r++;return`${o}_${r}`}function xa(e){let t=e.connections??{},s=!1;const o=(e.nodes??[]).map(r=>{if(!r.uses.connection||r.uses.connectionRef!==void 0)return r;const a=Object.hasOwn(t,r.id)?t[r.id]:void 0,i=(a==null?void 0:a.app)===r.uses.app&&a.connection===r.uses.connection?r.id:Js(r.uses.app,t);return t={...t,[i]:{app:r.uses.app,connection:r.uses.connection}},s=!0,Gt(r,i)});return s?{...e,nodes:o,connections:t}:e}function Gt(e,t){const{connection:s,...o}=e.uses;return{...e,uses:{...o,connectionRef:t}}}function vu(e,t,s,o){if(!t){const{connection:l,connectionRef:u,...c}=e.uses;return{step:{...e,uses:c},connections:o}}const r=e.uses.connectionRef,a=r&&s.some(l=>l.id!==e.id&&l.uses.connectionRef===r),i=r&&!a?r:Js(e.uses.app,o);return{step:Gt(e,i),connections:{...o,[i]:{app:e.uses.app,connection:t}}}}function hn(e,t,s,o){return t?s.filter(r=>r.uses.app===e&&$t(r,o)===t):[]}function va(e,t,s,o,r){if(r)return{connection:r};for(const l of[...s].reverse()){if(l.id===e.id||l.uses.app!==e.uses.app)continue;const u=$t(l,o);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(o))if(u.app===e.uses.app&&t.some(c=>c.appId===u.app&&c.id===u.connection))return{connectionRef:l};const a=t.filter(l=>l.appId===e.uses.app),i=a.find(l=>l.builtIn)??a[0];return i?{connection:i.id}:{}}function Xo(e,t,s){return s.some(r=>r.builtIn)||!t.some(r=>r.available!==!1&&(r.key==="zero-credential"||r.autoSatisfied===!0&&(r.type==="tenantAuth"||r.type==="jit")))?s:[...s,{id:`zerocred:${e}`,appId:e,authKey:"zero-credential",displayName:"Built-in",builtIn:!0,state:"connected"}]}function ju(e,t,s,o,r){const a=new Set(hn(e,t,o,r).map(i=>i.uses.connectionRef));return Object.fromEntries(Object.entries(r).map(([i,l])=>[i,a.has(i)?{...l,connection:s}:l]))}const ja=b.createContext(null);function zs(){return b.useContext(ja)}function Na({step:e,conns:t,failed:s=!1,readOnly:o,open:r,onOpenChange:a,anchorRef:i,onChangeConnection:l,onChangeConnectionRef:u,onConnectionCreated:c,createSignal:d}){var P,R,I;const p=zs(),f=o||(p==null?void 0:p.readOnly),m=(p==null?void 0:p.connections)??{},w=(p==null?void 0:p.nodes)??[],h=(t??[]).map(T=>({conn:T,users:hn(e.uses.app,T.id,w,m)})).sort((T,_)=>+(_.users.length>0)-+(T.users.length>0)),g=$t(e,m)??(e.uses.connectionRef===void 0?(P=t==null?void 0:t.find(T=>T.builtIn&&T.appId===e.uses.app))==null?void 0:P.id:void 0),y=hn(e.uses.app,g,w,m).filter(T=>T.id!==e.id),[x,C]=b.useState(null),[E,S]=b.useState(!1),j=b.useRef(d);b.useEffect(()=>{const T=j.current;j.current=d,d!==void 0&&T!==void 0&&d>T&&S(!0)},[d]);const N=x||E?((I=(R=i.current)==null?void 0:R.closest("dialog"))==null?void 0:I.parentElement)??document.body:null,A=(T,_)=>{if(!f){if(_&&p&&g){p.setConnections(ju(e.uses.app,g,T,w,m));const q=w.find(U=>U.id===e.id)??e;q.uses.connectionRef?u(q.uses.connectionRef):l(T)}else{const q=hn(e.uses.app,T,w,m).filter(B=>B.id!==e.id&&B.uses.connectionRef).at(-1),U=Object.entries(m).find(([,B])=>B.app===e.uses.app&&B.connection===T);q!=null&&q.uses.connectionRef?u(q.uses.connectionRef):U?u(U[0]):l(T)}C(null),a(!1)}},$=T=>{f||(a(!1),T!==g&&(y.length>0&&w.some(_=>_.id===e.id)?C(T):A(T,!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"Connection","aria-expanded":r,disabled:f||t===null&&!s,onClick:()=>a(!r),children:n.jsx("span",{className:"w6w-conn-label-name",children:t===null&&!s&&!g?"Loading connections…":Yo(g,t,s)})}),r&&n.jsx(ya,{anchorRef:i,onClose:()=>a(!1),children:n.jsxs("div",{className:"w6w-stack",children:[s&&n.jsx("p",{role:"alert",className:"w6w-field-error",children:"Couldn’t load connections."}),Object.entries(m).some(([,T])=>T.app===e.uses.app)&&n.jsxs("div",{className:"w6w-stack",children:[n.jsx("strong",{className:"w6w-small",children:"Workflow connections"}),n.jsx("div",{className:"w6w-stepbuilder-list",children:Object.entries(m).filter(([,T])=>T.app===e.uses.app).map(([T,_])=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f||!_.connection||!(t!=null&&t.some(q=>q.id===_.connection)),"aria-pressed":e.uses.connectionRef===T,"data-connection-ref":T,onClick:()=>{u(T),a(!1)},children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:T}),n.jsx("span",{className:"w6w-muted w6w-small",children:Yo(_.connection??void 0,t,s)})]})},T))})]}),n.jsx("div",{className:"w6w-stepbuilder-list",children:h.map(({conn:T,users:_})=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f,"aria-pressed":T.id===g,"data-connection-id":T.id,onClick:()=>$(T.id),children:n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:T.builtIn?"Built-in":T.displayName||T.id}),n.jsx("span",{className:"w6w-muted w6w-small",children:_.length>0?`In use in this workflow · ${_.map(q=>q.id).join(", ")}`:T.builtIn?"Built-in connection":T.state})]})},T.id))}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>{a(!1),S(!0)},children:"+ New connection"})]})}),E&&N&&bn.createPortal(n.jsx(_s,{initialAppId:e.uses.app,onClose:()=>S(!1),onCreated:({connectionId:T})=>{S(!1),c(),$(T)}}),N),x&&N&&bn.createPortal(n.jsxs(ke,{title:"Change connection",onClose:()=>C(null),children:[n.jsxs("div",{className:"w6w-modal-body",children:[n.jsx("p",{children:"Change the connection for all these nodes, or only this node?"}),n.jsxs("ul",{children:[n.jsx("li",{children:e.id||"New node"}),y.map(T=>n.jsx("li",{children:T.id},T.id))]})]}),n.jsxs("div",{className:"w6w-modal-actions",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>C(null),children:"Cancel"}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:f,onClick:()=>A(x,!0),children:["All ",y.length+1," nodes"]}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>A(x,!1),children:"Only this node"})]})]}),N)]})}function Nu(e,t){return`${e.method}-${e.url??e.host}-${t}`}function ka({calls:e,defaultOpen:t,keyOf:s,title:o}){if(e.length===0)return null;const r=s??Nu;return n.jsxs("div",{className:"w6w-stack",style:{gap:4},children:[o!==!1&&n.jsx("strong",{className:"w6w-small",children:o??n.jsxs(n.Fragment,{children:["API ",e.length===1?"call":"calls"," (",e.length,")"]})}),e.map((a,i)=>n.jsxs("details",{open:t,className:"w6w-result",style:{padding:8},children:[n.jsx("summary",{style:{cursor:"pointer"},children:n.jsxs("span",{className:"w6w-small",children:[a.method," ",a.url??a.host," →"," ",n.jsx("strong",{children:a.error?"failed":a.status}),a.durationMs!==void 0&&n.jsxs("span",{className:"w6w-muted",children:[" · ",a.durationMs,"ms"]})]})}),n.jsxs("div",{className:"w6w-stack",style:{gap:6,marginTop:8},children:[a.error&&n.jsx("div",{className:"w6w-error w6w-small",children:a.error}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Request headers"}),n.jsx(Ae,{value:a.requestHeaders??{},maxHeight:240}),a.requestBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Request body"}),n.jsx(Ae,{value:a.requestBody,maxHeight:240})]}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Response headers"}),n.jsx(Ae,{value:a.responseHeaders??{},maxHeight:240}),a.responseBody&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small",children:"Response body"}),n.jsx(Ae,{value:a.responseBody,maxHeight:240})]}),a.truncated&&n.jsx("div",{className:"w6w-muted w6w-small",children:"A captured body exceeded the size cap and was truncated."})]})]},r(a,i)))]})}function Sa({title:e,children:t,action:s,className:o,testId:r}){return n.jsx("div",{className:o?`w6w-empty-state ${o}`:"w6w-empty-state","data-testid":r,children:n.jsxs("div",{className:"w6w-empty-state-inner",children:[e!=null&&n.jsx("div",{className:"w6w-empty-state-title",children:e}),t!=null&&n.jsx("div",{className:"w6w-empty-state-body",children:t}),s!=null&&n.jsx("div",{className:"w6w-empty-state-action",children:s})]})})}function Ca({choices:e,onChange:t,readOnly:s}){const o=new Set(e.selected),r=e.options.every(i=>o.has(i.value)),a=[...e.options,...e.selected.filter(i=>!e.options.some(l=>l.value===i)).map(i=>({value:i,label:i}))];return n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Triggers *"}),n.jsxs("div",{className:"w6w-multiselect-checks",children:[n.jsxs("div",{className:"w6w-multiselect-checks-toolbar",children:[n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:r,ref:i=>{i&&(i.indeterminate=!r&&o.size>0)},disabled:s,onChange:i=>t(i.target.checked?e.options.map(l=>l.value):[])}),n.jsx("span",{children:"All events"})]}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[o.size," selected"]})]}),n.jsx("fieldset",{className:"w6w-multiselect-checks-options","aria-label":"Eventbrite events",children:a.map(i=>n.jsxs("label",{className:"w6w-multiselect-check",children:[n.jsx("input",{type:"checkbox",checked:o.has(i.value),disabled:s,onChange:l=>t(l.target.checked?[...e.selected,i.value]:e.selected.filter(u=>u!==i.value))}),n.jsx("span",{children:i.label})]},i.value))})]}),n.jsx("span",{className:"w6w-hint",children:"Start this workflow when any selected event occurs."})]})}function Fn({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 Aa(e,t,s,o){var u;if(e!=="io.w6w.eventbrite")return null;const r=t==null?void 0:t.find(c=>c.key==="activity"),a=(u=r==null?void 0:r.params)==null?void 0:u.find(c=>c.key==="actions"&&c.type==="multiselect");if(!r||!Array.isArray(a==null?void 0:a.options)||!a.options.length)return null;const i=a.options.map(c=>{var f;const d=String(c.value),p=d.replace(/[._]/g,"-");return{value:d,label:((f=t==null?void 0:t.find(m=>m.key===p))==null?void 0:f.title)??c.label,triggerKey:p}}),l=i.find(c=>c.triggerKey===s);return s&&s!==r.key&&!l||s===r.key&&o.actions!=null&&!Array.isArray(o.actions)?null:{triggerKey:r.key,options:i.sort((c,d)=>c.label.localeCompare(d.label)),selected:l?[l.value]:Array.isArray(o.actions)?o.actions.filter(c=>typeof c=="string"):[]}}const ku=["off","root","key","pick","append"],Su={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function Cu(e){return ae.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function Au(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Eu(e,t){const{state:s,...o}=e,r=ae.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return Au(t,r)?o:{...o,state:t}}function Tu(e,t){switch(t){case"key":return{mode:"key",key:e.id};case"pick":return{mode:"pick",map:[{from:"",to:e.id}]};case"append":return{mode:"append",path:e.id};case"root":return{mode:"root"};default:return{mode:"off"}}}function Ea(e){return!kt(e.uses.app)}function ve(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===_e&&e.uses.action==="foreach"}function Ta(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===_e}function ps(e){var s,o;if((e==null?void 0:e.uses.app)===Ke)return!0;if((e==null?void 0:e.uses.app)===Ot)return!1;if(!Ta(e))return!0;const t=e==null?void 0:e.uses.action;return t==="foreach"||t==="wait"?!0:t==="if"&&((s=e==null?void 0:e.with)==null?void 0:s.then)===void 0&&((o=e==null?void 0:e.with)==null?void 0:o.else)===void 0}function Ks(e){if(!Ta(e))return[];const t=e.with??{},s=[],o=r=>{if(typeof r=="string")s.push(r);else if(Array.isArray(r))for(const a of r)o(a)};return o(t.body),o(t.branches),o(t.then),o(t.else),s}function Ru(e){const t=new Set;for(const s of e)for(const o of Ks(s))t.add(o);return t}function wn(e,t,s,o){return{id:bt(e,t,"each",o),source:e,target:t,sourceHandle:o!==void 0?It(o):s?Cn:void 0,animated:!1,data:{when:"each",...o===void 0?{}:{route:o}},...Xt("each",void 0)}}const tn=e=>{var t;return typeof((t=e.data)==null?void 0:t.route)=="string"?e.data.route:void 0};function Gs(e,t,s,o){const r=new Set(t.map(h=>h.id)),a=new Set(t.filter(h=>{var g;return ve((g=h.data)==null?void 0:g.step)}).map(h=>h.id)),i=s.filter(h=>ye(h)==="each"&&!(h.source!==e&&a.has(h.source)&&tn(h)===void 0)),l=new Set([e]),u=[],c=[e];for(let h=0;h<c.length;h++)for(const g of i)g.source===c[h]&&(!r.has(g.target)||l.has(g.target)||o!=null&&o.has(g.target)||(l.add(g.target),u.push(g.target),c.push(g.target)));const d=new Map(u.map((h,g)=>[h,g])),p=i.filter(h=>h.source!==e&&d.has(h.source)&&d.has(h.target)),f=new Map(u.map(h=>[h,0]));for(const h of p)f.set(h.target,(f.get(h.target)??0)+1);const m=[],w=new Set;for(;;){const h=u.find(g=>!w.has(g)&&f.get(g)===0);if(h===void 0)break;w.add(h),m.push(h);for(const g of p)g.source===h&&f.set(g.target,(f.get(g.target)??0)-1)}for(const h of u)w.has(h)||m.push(h);return m}function Ra(e,t){const s=new Set(e);return t.filter(o=>ye(o)==="each"&&s.has(o.source)&&s.has(o.target))}function Ou(e,t){const s=Ra(e,t),o=new Set;for(const r of s){if(tn(r)!==void 0||o.has(r.source))return!1;o.add(r.source)}return!0}function Iu(e,t){const s=[];for(const o of Ln(e,t).values())if(!Ou(o,t))for(const r of Ra(o,t)){const a=tn(r);s.push({from:r.source,to:r.target,...a===void 0?{}:{route:a}})}return s}function Ln(e,t){var r;const s=new Map,o=new Set;for(const a of e){if(!ve((r=a.data)==null?void 0:r.step))continue;const i=Gs(a.id,e,t,o);for(const l of i)o.add(l);s.set(a.id,i)}return s}function Ue(e,t){const s={};for(const[o,r]of Ln(e,t))for(const a of r)s[a]=o;return s}function Oa(e,t,s){const o=Ue(t,s),r=[];let a=o[e];for(;a!==void 0&&!r.includes(a);)r.unshift(a),a=o[a];return r}function $u(e,t,s){const o=h=>h.source===e||h.target===e,r=s.filter(h=>!o(h)),i=ve((h=>{var g,y;return(y=(g=t.find(x=>x.id===h))==null?void 0:g.data)==null?void 0:y.step})(e)),l=Ue(t,s),u=new Set(i?Object.keys(l).filter(h=>l[h]===e):[]),c=i?r.filter(h=>!(ye(h)==="each"&&(h.source===e||u.has(h.source))&&u.has(h.target))):r,d=l[e];if(d===void 0)return c;const p=s.filter(h=>h.target===e&&ye(h)==="each"),f=s.filter(h=>h.source===e&&ye(h)==="each"&&!u.has(h.target));if(p.length!==1||f.length!==1)return c;const m=p[0].source,w=f[0].target;return c.some(h=>h.source===m&&h.target===w&&ye(h)==="each")?c:[...c,wn(m,w,m===d,tn(p[0]))]}function Ys(e){if(!ve(e)||!e.with||!("body"in e.with))return e;const{body:t,...s}=e.with;return{...e,with:s}}function Ia(e,t,s,o,r,a){const i=Ue(o,r);if(s==="error")return i[e]!==void 0||i[t]!==void 0?"error_lane_in_body":null;if(s==="success")return i[t]!==void 0?"outside_inbound":null;const l=p=>{var f,m;return(m=(f=o.find(w=>w.id===p))==null?void 0:f.data)==null?void 0:m.step},c=ve(l(e))&&(a===void 0||i[e]===void 0)?e:i[e];if(c===void 0)return null;if(t===c||Oa(c,o,r).includes(t))return"loop_cycle";const d=()=>e!==c||!r.some(p=>p.source===e&&ye(p)==="each"&&tn(p)===void 0);return i[t]===c?e===c||Pu(t,e,r)?"loop_cycle":d()?null:"body_branch":i[t]!==void 0?"already_in_loop":ps(l(t))?d()?r.some(p=>p.source===t||p.target===t)?"body_exit":null:"body_branch":"control_in_body"}function Pu(e,t,s){const o=new Set([e]),r=[e];for(;r.length>0;){const a=r.pop();if(a===t)return!0;for(const i of s)i.source!==a||ye(i)!=="each"||o.has(i.target)||(o.add(i.target),r.push(i.target))}return!1}const _u={error_lane_in_body:"A step inside a loop can't have an error connection. Handle the failure outside the loop.",outside_inbound:"This step is inside a loop, so nothing outside it can connect into it. Connect from the loop's Each item side instead.",loop_cycle:"A loop body can't connect back to its own For each.",already_in_loop:"That step is already inside another loop.",control_in_body:"Parallel, Merge, Aggregate and Race join paths of the main workflow, so they can't run inside a loop body. Use an If, Router, Wait, Stop, Respond or another For each.",body_branch:"A For each's Each item port connects to one first step. Branch inside the loop from that step onward.",body_exit:"That step is already connected elsewhere in the workflow. Use a step with no connections, or disconnect it first."};function Fu(e){return _u[e]}function Lu(e,t){const s=Ue(e,t);let o=!1;const r=e.map(a=>{const i=s[a.id];if(a.data.loopOf===i)return a;if(o=!0,i===void 0){const{loopOf:l,...u}=a.data;return{...a,data:u}}return{...a,data:{...a.data,loopOf:i}}});return o?r:e}function Mu(e,t,s){var i,l;const o=`Delete node "${e}"? Its connections are removed too.`,r=(l=(i=t.find(u=>u.id===e))==null?void 0:i.data)==null?void 0:l.step;if(!ve(r))return o;const a=Gs(e,t,s);return a.length===0?o:`${o} Its loop body steps ${a.map(u=>`"${u}"`).join(", ")} stay as standalone steps.`}function Xs(e){if(e.edges)return e.edges;const t=Ru(e.nodes),s=e.nodes.filter(r=>!t.has(r.id)),o=[];for(let r=0;r<s.length-1;r++)o.push({from:s[r].id,to:s[r+1].id});return o}const mn=e=>(e.when??"success")==="success",Nn=e=>e.route===ir&&mn(e);function Zs(e){const t=new Map(e.nodes.map(c=>[c.id,c])),s=new Map;for(const c of e.nodes)for(const d of Ks(c)){const p=s.get(d)??new Set;p.add(c.id),s.set(d,p)}const o=Xs(e),r=e.edges??[],a={};for(const c of e.nodes){if(!ve(c))continue;const d=c.with??{};if("body"in d){a[c.id]=i(c.id,d.body);continue}a[c.id]=u(c.id)}return a;function i(c,d){const p=(g,y)=>({invalid:y===void 0?{reason:g}:{reason:g,stepId:y}});if(!Array.isArray(d)||d.some(g=>typeof g!="string"))return p("body_not_literal");const f=d,m=new Set(f),w=new Set;for(const g of f){if(!t.has(g))return p("body_unknown_step",g);if(g===c)return p("body_self",g);if(w.has(g))return p("body_duplicate",g);if(w.add(g),!ps(t.get(g)))return p("body_contains_control",g);const y=s.get(g);if(y&&[...y].some(x=>x!==c))return p("body_claimed_twice",g)}const h=[];for(const g of r){if(Nn(g)&&g.from===c&&g.to===f[0]||Nn(g)&&m.has(g.from)&&!m.has(g.to)&&l(g.from,g.to)||!(m.has(g.from)||m.has(g.to)))continue;if(!(m.has(g.from)&&m.has(g.to)&&mn(g)&&g.to!==f[0]))return p("body_step_has_edges",m.has(g.from)?g.from:g.to);h.push(g)}return h.length>0?{body:f,source:"body",edges:h}:{body:f,source:"body"}}function l(c,d){var f,m;const p=(m=(f=t.get(c))==null?void 0:f.with)==null?void 0:m.body;return ve(t.get(c))&&Array.isArray(p)&&p[0]===d}function u(c){var g;const d=o.filter(y=>y.from===c&&mn(y)&&y.route===void 0);if(d.length===0)return{body:[],source:"body"};const p=y=>({invalid:{reason:"legacy_not_linear",stepId:y}});if(d.length>1)return p(c);const f=[],m=new Set([c]);let w=c,h=d[0].to;for(;h!==void 0;){const y=h,x=t.get(y);if(!x||m.has(y)||!ps(x)||s.has(y))return p(y);const C=o.filter(S=>S.to===y);if(C.length!==1||C[0].from!==w)return p(y);const E=o.filter(S=>S.from===y);if(E.length>1||E.length===1&&!mn(E[0]))return p(y);m.add(y),f.push(y),w=y,h=(g=E[0])==null?void 0:g.to}return{body:f,source:"legacy"}}}function ye(e){var s;const t=(s=e.data)==null?void 0:s.when;return t==="error"?"error":t==="each"?"each":"success"}function $a(e,t){var s;return((s=e.find(o=>o.id===t))==null?void 0:s.id)??null}function Pa(e,t,s,o,r,a){var d,p;if(!e||!t||e===t||o.some(f=>{var m;return f.source===e&&f.target===t&&((m=f.data)==null?void 0:m.route)===a}))return!1;const i=(d=s.find(f=>f.id===e))==null?void 0:d.data.step,l=(p=s.find(f=>f.id===t))==null?void 0:p.data.step;if(!i||!l)return!1;const u=Bt(i,r),c=Bt(l,r);return u.out>=1&&c.in>=1}function Qs(e,t,s,o,r,a,i){var S,j,N;const l=r==="success"&&ve((S=s.find(A=>A.id===e))==null?void 0:S.data.step),u=l&&i===void 0?wt:i;if(!Pa(e,t,s,o,a,u)||!e||!t)return null;const c=(j=s.find(A=>A.id===e))==null?void 0:j.data.step,d=(N=s.find(A=>A.id===t))==null?void 0:N.data.step;if(!c||!d)return null;const p=js(c);if(l){if(u!==wt)return null}else if(c.uses.app===Ke&&r==="success"){if(!vs(c).some(A=>A.id===u))return null}else if(p&&r==="success"){if(u!==void 0&&u!==yn)return null}else if(u!==void 0)return null;const f=Ue(s,o)[e]!==void 0,m=r==="success"&&f?"each":r;if(m==="each"&&!f&&!ve(c))return null;const w=Ia(e,t,m,s,o,u);if(w)return{next:o,conflict:null,refusal:{refused:"loop",reason:w}};const h=Bt(c,a),g=o,y=g.filter(A=>{var $;return A.source===e&&ye(A)===m&&(($=A.data)==null?void 0:$.route)===u}),x=u===void 0||p||l?h.out:1;if(y.length>=x)return{next:o,conflict:null,refusal:{refused:"out_cap",cap:x}};const C=bt(e,t,m,u),E=m==="each"&&f&&!ve(c)?void 0:bs(m);return{next:Yn.addEdge({source:e,target:t,id:C,sourceHandle:u===void 0?E:It(u),data:{when:m,...u===void 0?{}:{route:u}},...Xt(m,void 0)},g),conflict:$a(g,C),refusal:null}}function Du(e,t,s,o,r="success",a,i){const l=Qs(e,t,s,o,r,a,i);return!l||l.conflict||l.refusal?null:l.next}function Wu(e,t,s,o,r="success",a,i){var l;return((l=Qs(e,t,s,o,r,a,i))==null?void 0:l.conflict)??null}function qu(e,t,s,o,r="success",a,i){var l;return((l=Qs(e,t,s,o,r,a,i))==null?void 0:l.refusal)??null}function eo(e,t,s,o,r){var x;const a=e.filter(C=>C.id===t);if(a.length!==1)return null;const i=a[0];if(ye(i)==="each")return null;const l=(x=o.find(C=>C.id===i.source))==null?void 0:x.data.step;if(!l||l.uses.app===Ke||l.uses.app===Ot)return null;const u=Bt(l,r).out,c=e.filter(C=>C.id!==t);if((ye(i)===s?[]:c.filter(C=>C.source===i.source&&ye(C)===s)).length>=u)return{next:e,conflict:null,refusal:{refused:"out_cap",cap:u}};const p=Xt(s,void 0),f=ve(l),m=f&&s==="success"?wt:void 0,{route:w,...h}=i.data??{},g={...i,id:bt(i.source,i.target,s,m),data:f?{...h,when:s,...m?{route:m}:{}}:{...i.data,when:s},className:p.className,label:p.label,sourceHandle:m?It(m):bs(s)},y=$a(c,g.id);return{next:e.map(C=>C.id===t?g:C),conflict:y,refusal:null}}function Uu(e,t,s,o,r){const a=eo(e,t,s,o,r);return!a||a.conflict||a.refusal?null:a.next}function Vu(e,t,s,o,r){var a;return((a=eo(e,t,s,o,r))==null?void 0:a.conflict)??null}function Hu(e,t,s,o,r){var a;return((a=eo(e,t,s,o,r))==null?void 0:a.refusal)??null}function Bu(e,t,s){return e.map(o=>{var i;const r=o.source===t?s:o.source,a=o.target===t?s:o.target;return{...o,source:r,target:a,id:bt(r,a,ye(o),typeof((i=o.data)==null?void 0:i.route)=="string"?o.data.route:void 0)}})}function bt(e,t,s,o){const r=s==="error"?`${e}->${t}:error`:`${e}->${t}`;return o===void 0?r:`${r}:route:${encodeURIComponent(o)}`}function Ju(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function _a(e,t){const s=Ju(e);if(s)return s;for(const o of t)if(o===e)return`A step named "${e}" already exists.`;return null}function zu(e,t,s){const o=(p,f)=>!p||!f?void 0:bt(p,f)===t?"success":bt(p,f,"error")===t?"error":void 0,r=o(s[0],s[1]),a=o(s[2],s[3]),i=r!==void 0&&r===a,l=r!==void 0&&a!==void 0&&r!==a,u=r==="success"?s[1]:s[3],c=i?s.find(p=>!!p&&p.includes("->")):l&&(u!=null&&u.endsWith(":error"))?u:void 0,d=c===void 0?"Rename one of the steps it connects, then try again.":i?`A step id containing “->” collides with the edge-id separator, so two different edges mint one id — rename the step “${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 Ku=240,Gu=100,Yu=40,Xu=40;function to(e,t){return{x:Yu+e*Ku,y:Xu+t*Gu}}function Zu(e,t){var l;const s=new Map,o=new Map;for(const u of e)s.set(u.id,0),o.set(u.id,[]);for(const u of t)(l=o.get(u.to))==null||l.push(u.from);const r=e.length+1;let a=0,i=!0;for(;i&&a<r;){a++,i=!1;for(const u of e){const c=o.get(u.id)??[];if(c.length===0)continue;const d=c.reduce((p,f)=>Math.max(p,(s.get(f)??0)+1),0);(s.get(u.id)??0)<d&&(s.set(u.id,d),i=!0)}}if(i){const u=Math.max(0,e.length-1);for(const[c,d]of s)d>u&&s.set(c,u)}return s}function Fa(e,t){var u;const s=Zu(e,t),o=new Map(e.map((c,d)=>[c.id,d])),r=new Map;for(const{from:c,to:d}of t){const p=s.get(c),f=s.get(d);if(p===void 0||f===void 0||p>=f)continue;const m=r.get(d);(m===void 0||p<(s.get(m)??0)||p===s.get(m)&&(o.get(c)??0)<(o.get(m)??0))&&r.set(d,c)}const a=new Map(e.map(c=>[c.id,[]]));for(const[c,d]of r)(u=a.get(d))==null||u.push(c);for(const c of a.values())c.sort((d,p)=>(s.get(p)??0)-(s.get(d)??0)||(o.get(d)??0)-(o.get(p)??0));const i=new Map;let l=0;for(const c of e.filter(d=>!r.has(d.id))){const d=[c.id];for(;d.length;){const p=d.pop();if(p===void 0)continue;i.set(p,to(s.get(p)??0,l));const f=a.get(p)??[];if(f.length===0)l++;else for(let m=f.length-1;m>=0;m--)d.push(f[m])}}return i}function Qu(e){const t=e.position;if(!(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function no(e){const t=e;if(t.nodes!==void 0&&t.steps!==void 0)throw new Error("workflow carries both nodes and steps");const{steps:s,...o}=e;return{...o,nodes:t.nodes??t.steps??[]}}function ed(e){const t=no(e),s=t.nodes;let o=Xs(t);const r=[],a=new Set(s.filter(ve).map(w=>w.id)),i=new Map,l=new Set,u=new Set;for(const[w,h]of Object.entries(Zs(t))){if("invalid"in h)continue;let g=w;if(h.edges&&h.body.length>0){r.push(wn(w,h.body[0],!0));for(const y of h.edges)u.add(y),r.push(wn(y.from,y.to,!1,y.route));for(const y of h.body)i.set(y,w);continue}for(const y of h.body){if(h.source==="legacy"){const x=o.find(C=>C.from===g&&C.to===y&&(C.when??"success")==="success");x&&u.add(x)}r.push(wn(g,y,g===w,g!==w&&a.has(g)?wt:void 0)),i.set(y,w),g=y}h.source==="legacy"&&l.add(w)}const c=new Set(s.filter(ve).map(w=>w.id));for(const w of o)c.has(w.from)&&Nn(w)&&u.add(w);u.size>0&&(o=o.filter(w=>!u.has(w)));const d=Fa(s,[...o,...r.map(w=>({from:w.source,to:w.target}))]),p=s.map(w=>{const h=st(w.uses.app);return{id:w.id,type:h?"control":"step",position:Qu(w)??d.get(w.id)??to(0,0),data:{step:w,isInternal:h,...i.has(w.id)?{loopOf:i.get(w.id)}:{},...l.has(w.id)?{legacyLoop:!0}:{}}}}),f=new Set(s.filter(js).map(w=>w.id)),m=o.map(w=>{const h=w.when==="error"&&w.route===void 0&&f.has(w.from)?{from:w.from,to:w.to,route:yn}:c.has(w.from)&&w.route===void 0&&w.when!=="error"?{...w,route:wt}:w,g=h.when??"success";return{id:bt(h.from,h.to,g,h.route),source:h.from,target:h.to,sourceHandle:h.route===void 0?bs(g):`route:${h.route}`,animated:!1,data:{when:g,...h.route===void 0?{}:{route:h.route}},...Xt(g,void 0)}});return{nodes:p,edges:[...m,...r]}}function td(e,t){const s=e.map(r=>({...r.data.step,id:r.id})),o=Fa(s,t.map(r=>({from:r.source,to:r.target})));return e.map(r=>({...r,position:o.get(r.id)??to(0,0)}))}function nd(e,t,s){var S,j;const o=no(e),r=((S=o.settings)==null?void 0:S.savePosition)!==!1,a=new Map(t.map(N=>[N.id,N])),i=N=>{var $;if(!r)return N;const A=($=a.get(N.id))==null?void 0:$.position;return!A||!Number.isFinite(A.x)||!Number.isFinite(A.y)?N:{...N,position:{x:Math.round(A.x),y:Math.round(A.y)}}},l=new Map;for(const N of o.nodes)l.set(N.id,N);for(const N of t)(j=N.data)!=null&&j.step&&l.set(N.id,N.data.step);const u=Ln(t,s),c=Zs(o),d=new Map(o.nodes.map(N=>[N.id,N])),p=new Set;for(const N of s)ye(N)==="success"&&p.add(N.source);const f=N=>{if(!ve(N))return N;const A=u.get(N.id)??[],$=d.get(N.id),P=c[N.id];let R;A.length>0?R={value:A}:P&&"invalid"in P&&P.invalid.reason!=="legacy_not_linear"?R=$!=null&&$.with&&"body"in $.with?{value:$.with.body}:null:P&&"invalid"in P?R=null:p.has(N.id)||$!=null&&$.with&&"body"in $.with?R={value:[]}:R=null;const I=N.with??{};return R===null?"body"in I?Ys(N):N:{...N,with:{...I,body:R.value}}},m=N=>i(f(N)),w=[],h=new Set;for(const N of o.nodes){const A=l.get(N.id);A&&t.some($=>$.id===N.id)&&(w.push(m(A)),h.add(N.id))}for(const N of t){if(h.has(N.id))continue;const A=l.get(N.id);A&&w.push(m(A))}const g=new Set;for(const N of u.values())for(const A of N)g.add(A);const y=new Set(t.filter(N=>{var A;return ve((A=N.data)==null?void 0:A.step)}).map(N=>N.id)),x=s.filter(N=>ye(N)!=="each"&&!g.has(N.source)&&!g.has(N.target)).map(N=>{var $;const A=typeof(($=N.data)==null?void 0:$.route)=="string"?N.data.route:y.has(N.source)&&ye(N)==="success"?wt:void 0;return{from:N.source,to:N.target,...ye(N)==="error"?{when:"error"}:{},...A===void 0?{}:{route:A}}}),C=[];for(const[N,A]of u)A.length>0&&C.push({from:N,to:A[0],route:ir});const E=[...x,...C,...Iu(t,s)];return xa({...o,nodes:w,edges:E})}function La(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 sd(e,t){var i;if(!(((i=e.settings)==null?void 0:i.savePosition)!==!1)||!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(t.zoom))return e;const o={x:Math.round(t.x),y:Math.round(t.y),zoom:Math.round(t.zoom*1e3)/1e3},r=La(e);if(r&&r.x===o.x&&r.y===o.y&&r.zoom===o.zoom)return e;const a=typeof e.settings=="object"&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:void 0;return{...e,settings:{...a,viewport:o}}}function od(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function rd(e,t){const s=new Set(t.map(o=>o.target));return e.find(o=>!s.has(o.id))}function ad(e,t){const s=new Set(t.map(o=>o.source));for(let o=e.length-1;o>=0;o--)if(!s.has(e[o].id))return e[o]}function id(e,t="step"){const s=new Set(e);for(let o=1;o<1e3;o++){const r=`${t}_${o}`;if(!s.has(r))return r}return`${t}_${crypto.randomUUID().slice(0,8)}`}function so(e){return JSON.stringify(Ys(e),null,2)}const ld=3,cd=100;function yt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ma(e){if(!Array.isArray(e))return;const t=[],s=new Set,o=r=>{s.has(r.key)||(s.add(r.key),t.push(r))};for(const r of e){if(!yt(r)||typeof r.key!="string"||r.key==="")continue;const a=typeof r.label=="string"&&r.label!==""?r.label:void 0;if(o({key:r.key,...a?{label:a}:{},path:!0}),r.type==="array"&&Array.isArray(r.items))for(const i of r.items){if(!yt(i)||typeof i.key!="string"||i.key==="")continue;const l=typeof i.label=="string"&&i.label!==""?i.label:void 0;o({key:`${r.key}.0.${i.key}`,...l?{label:l}:{},path:!0})}}return t.length>0?t:void 0}function ud(e,t){var o;if(!Array.isArray(e))return;const s=e.find(r=>yt(r)&&r.key===t);if(!(!yt(s)||!Array.isArray(s.items)))return(o=Ma([{key:t,type:"array",items:s.items}]))==null?void 0:o.filter(r=>r.key!==t).map(r=>({...r,key:r.key.slice(t.length+3)}))}function ht(e){if(!yt(e))return;const t=[],s=(o,r,a)=>{for(const[i,l]of Object.entries(o)){if(t.length>=cd)return;const u=r?`${r}.${i}`:i;t.push({key:u,path:!0}),yt(l)&&a<ld&&s(l,u,a+1)}};return s(e,"",1),t.length>0?t:void 0}function qt(e,t){let s=e;for(const o of t.split(".")){if(!yt(s)||!(o in s))return;s=s[o]}return s}function ft(e,t,s){const o=Ma(e==null?void 0:e.output),r=ht(t),a=r??ht(s);if(a){const l=new Map((o??[]).map(d=>[d.key,d])),u=new Set(a.map(d=>d.key)),c=a.map(d=>{const p=l.get(d.key);return p!=null&&p.label?{...d,label:p.label}:d});for(const d of o??[])u.has(d.key)||c.push({...d,declaredOnly:!0});return{fields:c,from:r?"fresh":"persisted"}}if(o)return{fields:o,from:"declared"};const i=ht(e==null?void 0:e.sample);if(i)return{fields:i,from:"sample"}}function oo(e,t){const s=new Map;for(const a of t){const i=s.get(a.target)??[];i.push(a.source),s.set(a.target,i)}const o=new Set,r=[e];for(;r.length;){const a=r.pop();for(const i of s.get(a)??[])o.has(i)||(o.add(i),r.push(i))}return o}function Da(e,t,s={}){var i,l,u,c,d,p,f;const o=[];let r=!1,a;for(const m of t){if(!e.has(m.id))continue;const w=m.data.step;if(w.uses.app===xs)continue;const h=((i=mt(w.uses.app,w.uses.action))==null?void 0:i.group)==="trigger",g=(l=s.testOutputs)==null?void 0:l[w.id],y=(u=s.persistedOutputs)==null?void 0:u[w.id];if(w.uses.trigger===!0){r=!0;const A=ft((c=s.triggerDef)==null?void 0:c.call(s,w.uses.app,w.uses.action),g,y);if(a??(a=A),A&&(A.from==="fresh"||A.from==="persisted")){o.push({id:w.id,label:w.id,outputs:A.fields,outputsFrom:A.from});continue}}h&&(r=!0);const x=h&&w.uses.app===Rt,C=x?Hs(qs((d=w.with)==null?void 0:d.fields)).map(A=>({key:A.key,label:A.label})):((p=mt(w.uses.app,w.uses.action))==null?void 0:p.output)??[],E={id:w.id,label:w.id};if(C.length>0){o.push({...E,outputs:C});continue}if(h){const A=ft(void 0,g,y);A&&!x&&(a??(a=A)),o.push(A?{...E,outputs:A.fields,outputsFrom:A.from}:E);continue}if(st(w.uses.app)){const A=ft(void 0,g,y);o.push(A?{...E,outputs:A.fields,outputsFrom:A.from}:E);continue}const S=(f=s.actionDef)==null?void 0:f.call(s,w.uses.app,w.uses.action),j=ft(S,g,y),N=w.uses.app.trim()!==""?{hasMeta:!0}:{};j?o.push({...E,outputs:j.fields,outputsFrom:j.from,...N}):o.push(S?{...E,needsTest:!0,...N}:{...E,...N})}return{steps:o,hasTrigger:r,...a?{eventOutputs:a.fields,eventOutputsFrom:a.from}:{}}}function dd(e,t){const s={};for(const[o,r]of Object.entries(t))s[o]={output:r};return Wa(e,{steps:s})}function Wa(e,t){if(ct(e)!==null){const s=Rs(e,As(void 0,t)),o=s.length===1?s[0]:void 0;return(o==null?void 0:o.status)==="resolved"&&Array.isArray(o.value)?o.value:void 0}return Array.isArray(e)?e:void 0}const pd=10;function fd(e,t){return{input:t,with:{items:e.slice(0,pd),itemCount:e.length}}}function hd(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 qa(e,t,s,o,r={}){const a=Ue(s,o),i=new Set;for(const p of e){if(p===t)continue;const f=a[p];f!==void 0&&f!==t||i.add(p)}const l=Da(i,s,r),u=Ln(s,o),c=[];return{steps:l.steps.map(p=>{var x,C,E;const f=u.get(p.id);if(!f||f.length===0)return p;const m=f[f.length-1],w=(x=s.find(S=>S.id===m))==null?void 0:x.data.step,h=r.testOutputs??{},g=w?ft((C=r.actionDef)==null?void 0:C.call(r,w.uses.app,w.uses.action),h[m],(E=r.persistedOutputs)==null?void 0:E[m]):void 0;c.includes(m)||c.push(m);const y=((g==null?void 0:g.fields)??[]).map(S=>({key:`items.0.${S.key}`,path:!0,...S.declaredOnly?{declaredOnly:!0}:{}}));return{id:p.id,label:p.label,outputs:[{key:"items",path:!0},...y],...g?{outputsFrom:g.from}:{}}}),hasTrigger:l.hasTrigger,extraSampleIds:c,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{}}}function wd(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 md(e,t,s){var p,f;const o=ct(e),r=o?wd(o):void 0,a=r?(p=t.find(m=>m.id===r.id))==null?void 0:p.data.step:void 0;if(!r||!a)return;const i=(f=s.actionDef)==null?void 0:f.call(s,a.uses.app,a.uses.action),l=qt(i==null?void 0:i.sample,r.path),u=Array.isArray(l)&&l.length>0?l[0]:void 0,d=ud(i==null?void 0:i.output,r.path)??ht(u);if(!(u===void 0&&!d))return{...u!==void 0?{itemSample:u}:{},...d?{itemOutputs:d}:{}}}function Ua(e,t,s={},o=[]){const r=Zo(e,t,s),a=Oa(e,t,o);return a.length===0?r:{...r,outer:a.map(i=>({...Zo(i,t,s),name:i}))}}function Zo(e,t,s={}){var c,d,p;const o={foreachId:e},r=(d=(c=t.find(f=>f.id===e))==null?void 0:c.data.step.with)==null?void 0:d.items,a={...s.persistedOutputs??{},...s.testOutputs??{}},i=dd(r,a),l=i&&i.length>0?i:(p=s.loopSamples)==null?void 0:p[e];if(l&&l.length>0){o.itemSample=l[0];const f=ht(l[0]);return f&&(o.itemOutputs=f),o}const u=md(r,t,s);return(u==null?void 0:u.itemSample)!==void 0&&(o.itemSample=u.itemSample),u!=null&&u.itemOutputs&&(o.itemOutputs=u.itemOutputs),o}function Va(e,t,s,o){return!e&&!!t&&!o.some(r=>r.target===t)&&Ue(s,o)[t]===void 0}function bd(e,t,s,o,r){let a=e;if(!a&&r&&!Va(e,r,t,s)&&(a=r),!a)return Da(new Set(t.map(u=>u.id)),t,o);const i=Ue(t,s)[a],l=qa(oo(a,s),i,t,s,o);return i&&!l.extraSampleIds.includes(i)&&l.extraSampleIds.push(i),{steps:l.steps,hasTrigger:l.hasTrigger,...l.eventOutputs?{eventOutputs:l.eventOutputs,eventOutputsFrom:l.eventOutputsFrom}:{},...i?{loop:Ua(i,t,o,s)}:{},...l.extraSampleIds.length>0?{extraSampleIds:l.extraSampleIds}:{}}}function yd(e,t,s,o){if(!e||e.handleType==="target")return[];const r=oo(e.nodeId,s);r.add(e.nodeId);const a=Ha(e,t,s);return qa(r,a,t,s,o).steps}function Ha(e,t,s){const o=t.find(r=>r.id===e.nodeId);return e.lane==="each"&&ve(o==null?void 0:o.data.step)?e.nodeId:Ue(t,s)[e.nodeId]}function gd(e,t,s,o){if(!e||e.handleType==="target")return;const r=Ha(e,t,s);return r?Ua(r,t,o,s):void 0}async function xd(e,t){return(await Promise.all(t.map(async o=>{try{const r=await e(o.id),a=r.length?r[r.length-1]:null;return a?{stepId:o.id,label:o.label??o.id,test:a}:null}catch{return null}}))).filter(o=>o!==null)}function ro(e,t,s){const o=vd(e,t);return!s||Object.keys(s).length===0?o:{...o??{},state:s}}function vd(e,t){const s={};for(const r of e){const a=r.test.lastRunOutput,i=a!=null;if(!i&&r.test.lastRunStatus!=="succeeded")continue;const l=r.test.lastRunMeta;s[r.stepId]={output:i?a:null,...l?{meta:l}:{}}}const o=Object.keys(s).length>0;return t?{...o?{steps:s}:{},foreach:{...t.item!==void 0?{item:t.item}:{},index:t.index??0,...t.loops?{loops:t.loops}:{}}}:o?{steps:s}:void 0}function Ba(e){if(!e)return;const t=o=>({..."itemSample"in o?{item:o.itemSample}:{},index:0}),s=[...e.outer??[],e];return{...t(e),loops:Object.fromEntries(s.map(o=>[o.foreachId,t(o)]))}}function jd(e){return!e||!("itemSample"in e)?"":JSON.stringify(e.itemSample,null,2)??""}function Nd(e,t){let s;if(e.trim()!=="")try{s=JSON.parse(e)}catch{return{ok:!1,error:"The current item must be valid JSON."}}const o=t.trim()===""?0:Number(t.trim());return!Number.isInteger(o)||o<0?{ok:!1,error:"The index must be a whole number, 0 or more."}:{ok:!0,value:{...s!==void 0?{item:s}:{},index:o}}}function kd(e,t){if(!t)return{};const s={};for(const o of["nodes","steps"]){const r=`${o}.${e}.meta`;s[`${r}.app`]=t.app,s[`${r}.version`]=t.version,s[`${r}.action`]=t.action,s[`${r}.connectionId`]=t.connectionId}return s}function Sd(e,t,s,o,r){return Ja(e,t,s,o,r).values}function Cd(e,t,s,o,r){return Ja(e,t,s,o,r).sources}function Ad(e,t){var r,a,i,l;const s={};let o;for(const u of e){const c=u.data.step.uses;if(c.trigger===!0){const p=(a=(r=t.triggerDef)==null?void 0:r.call(t,c.app,c.action))==null?void 0:a.sample;o===void 0&&p!==void 0&&(o=p);continue}if(st(c.app))continue;const d=(l=(i=t.actionDef)==null?void 0:i.call(t,c.app,c.action))==null?void 0:l.sample;d!==void 0&&(s[u.id]=d)}return{samples:s,...o!==void 0?{event:o}:{}}}function Ja(e,t,s,o,r={}){var l,u;const a={},i={};for(const c of e){Object.assign(a,kd(c.id,s[c.id]));const d=[["sample",(l=r.samples)==null?void 0:l[c.id]],["persisted",(u=r.persisted)==null?void 0:u[c.id]],["fresh",t[c.id]]];for(const[p,f]of d){if(f===void 0)continue;const m=(w,h)=>{for(const g of["nodes","steps"])a[`${g}.${w}`]=h,i[`${g}.${w}`]=p};if(m(`${c.id}.output`,f),typeof f=="object"&&f!==null&&!Array.isArray(f))for(const[w,h]of Object.entries(f))m(`${c.id}.output.${w}`,h);for(const w of c.outputs??[]){if(!w.path||!w.key.includes("."))continue;const h=qt(f,w.key);h!==void 0&&m(`${c.id}.output.${w.key}`,h)}}}if(r.event!==void 0){const c=(d,p)=>{a[d]=p,i[d]="sample"};if(c("trigger.event",r.event),typeof r.event=="object"&&r.event!==null&&!Array.isArray(r.event))for(const[d,p]of Object.entries(r.event))c(`trigger.event.${d}`,p);for(const d of ht(r.event)??[]){const p=qt(r.event,d.key);p!==void 0&&c(`trigger.event.${d.key}`,p)}}if(o&&"itemSample"in o){a["foreach.item"]=o.itemSample;for(const c of o.itemOutputs??[]){const d=qt(o.itemSample,c.key);d!==void 0&&(a[`foreach.item.${c.key}`]=d)}a["foreach.index"]=0}return{values:a,sources:i}}function Ed(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 Td(e){const t=[];for(const s of e){const o=s.data.step,r=Object.entries(o.with??{}).filter(([,i])=>i!==void 0&&!Ed(i)).map(([i])=>i);(o.uses.app===qe||o.uses.trigger===!0)&&!r.includes("url")&&r.unshift("url"),r.length>0&&t.push({id:o.id,keys:r})}return t}function fs(e){if(!(Ye(e)||lt(e))){if(Array.isArray(e))return e.map(fs).filter(t=>t!==void 0);if(typeof e=="object"&&e!==null){const t=e,s=Object.keys(t);if(s.length===1&&s[0]==="$"&&typeof t.$=="string")return;const o={};for(const[r,a]of Object.entries(t)){const i=fs(a);i!==void 0&&(o[r]=i)}return o}return e}}function Rd(e,t){const s={};for(const o of e){const r=o.data.step,a={...fs(r.with??{})??{}},i=za(r,t);i!=null&&i.webhookUrl&&(a.url=i.webhookUrl),Object.keys(a).length>0&&(s[r.id]=a)}return s}function za(e,t){if(!(e.uses.app!==qe&&e.uses.trigger!==!0))return t.find(s=>s.nodeId===e.id)??(e.uses.app===qe?t.find(s=>s.appId===qe):void 0)}function Od(e,t,s,o){var a;const r={};for(const i of e){const l=i.data.step;if(!l.uses.app)continue;const u={app:l.uses.app,action:l.uses.action,connectionId:$t(l,o)??null},c=(a=s==null?void 0:s.get(l.uses.app))==null?void 0:a.version;c&&(u.version=c);const d=za(l,t);d&&(u.subscriptionId=d.id),d!=null&&d.webhookUrl&&(u.url=d.webhookUrl),r[l.id]=u}return r}function Id(e){const t={};for(const[s,o]of Object.entries(e))for(const[r,a]of Object.entries(o))t[`nodes.${s}.meta.${r}`]=a,t[`steps.${s}.meta.${r}`]=a;return t}function $d(e,t){const s={success:0,error:0};for(const r of t){if(r.source!==e)continue;const a=ye(r);a!=="each"&&s[a]++}const o=Math.max(s.success,s.error);return{enabled:o>=2,count:o}}function Pd(e,t){const{fanOut:s,...o}=e;return t==="parallel"?{...o,fanOut:"parallel"}:o}function _d(e,t){return`Runs these ${e} nodes in ${t==="parallel"?"parallel":"sequence"}`}function Ka({step:e,count:t,readOnly:s,onChange:o}){const r=t>=2,a=e.fanOut==="parallel"?"parallel":"sequential";return n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Run next nodes"}),n.jsxs("select",{"aria-label":"Run next nodes",value:a,disabled:s||!r,onChange:i=>o(Pd(e,i.target.value)),children:[n.jsx("option",{value:"sequential",children:"In sequence"}),n.jsx("option",{value:"parallel",children:"In parallel"})]}),!r&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Connect two or more steps after this one to choose how they run."})]})}function Qo({to:e}){return n.jsxs("div",{className:"w6w-state-map-row w6w-state-map-head","aria-hidden":"true",children:[n.jsx("span",{children:"From this step output"}),n.jsx("span",{}),n.jsx("span",{children:e})]})}function er(){return n.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function tr({label:e,fields:t,value:s,readOnly:o,onChange:r}){const a=b.useMemo(()=>(t??[]).map(i=>({value:i,label:i})),[t]);return n.jsx(Ge,{mode:"combobox",forceSelection:!1,"aria-label":e,placeholder:"Whole output, or e.g. order",options:a,value:s,disabled:o,emptyText:a.length>0?"No matching field — keep typing a path":"Test this step to list its output fields, or type a path",onChange:r})}function Ga({step:e,inLoop:t,outputFields:s,readOnly:o,onChange:r}){const a=Cu(e),i=ae.validateStateConfig(a),l=p=>r(Eu(e,p)),u=a.mode==="pick"&&Array.isArray(a.map)?a.map:[],c=(p,f)=>l({mode:"pick",map:u.map((m,w)=>w===p?{...m,...f}:m)}),d=p=>{if(a.mode!=="append")return;const f=p.path??a.path,m="from"in p?p.from:a.from;l({mode:"append",path:f,...m?{from:m}:{}})};return n.jsxs("div",{className:"w6w-field w6w-stack",children:[n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Write to state"}),n.jsx("select",{"aria-label":"Write to state",value:a.mode,disabled:o,onChange:p=>l(Tu(e,p.target.value)),children:ku.map(p=>n.jsx("option",{value:p,children:Su[p]},p))})]}),a.mode==="key"&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"To state key"}),n.jsx("input",{type:"text","aria-label":"State key",placeholder:"e.g. order",value:a.key,disabled:o,onChange:p=>l({mode:"key",key:p.target.value})}),n.jsxs("span",{className:"w6w-hint",children:["Copies the whole step output into ",n.jsx("code",{children:"state.<key>"}),". A dotted key such as"," ",n.jsx("code",{children:"order.id"})," nests."]})]}),a.mode==="pick"&&n.jsxs("div",{className:"w6w-stack",children:[n.jsx(Qo,{to:"To state key"}),u.length===0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"No fields yet — add one below."}),u.map((p,f)=>n.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[n.jsx(tr,{label:"From output field",fields:s,value:p.from,readOnly:o,onChange:m=>c(f,{from:m})}),n.jsx(er,{}),n.jsx("input",{type:"text","aria-label":"To state path",placeholder:"e.g. order",value:p.to,disabled:o,onChange:m=>c(f,{to:m.target.value})}),!o&&n.jsx(Ds,{label:"Remove field",onClick:()=>l({mode:"pick",map:u.filter((m,w)=>w!==f)})})]},f)),!o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-state-map-add","aria-label":"Add field",onClick:()=>l({mode:"pick",map:[...u,{from:"",to:""}]}),children:"+ Add field"}),n.jsxs("span",{className:"w6w-hint",children:["Copies ",n.jsx("code",{children:"output.<path>"})," into ",n.jsx("code",{children:"state.<key>"}),". Leave the left side blank to copy the whole output."]})]}),a.mode==="append"&&n.jsxs("div",{className:"w6w-stack",children:[n.jsx(Qo,{to:"Append to state list"}),n.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[n.jsx(tr,{label:"Output field to append",fields:s,value:a.from??"",readOnly:o,onChange:p=>d({from:p})}),n.jsx(er,{}),n.jsx("input",{type:"text","aria-label":"Append to state path",placeholder:"e.g. orders",value:a.path,disabled:o,onChange:p=>d({path:p.target.value})})]}),n.jsxs("span",{className:"w6w-hint",children:["Appends ",n.jsx("code",{children:"output.<path>"})," to the list at ",n.jsx("code",{children:"state.<key>"}),". Leave the left side blank to append the whole output."]})]}),i.length>0&&n.jsx("div",{role:"alert",className:"w6w-state-write-issues w6w-small",children:i.map(p=>n.jsx("div",{children:p.message},`${p.code}:${p.message}`))}),a.mode!=="off"&&n.jsxs("span",{className:"w6w-muted w6w-small",children:["Writing ",n.jsx("code",{children:"null"})," deletes the key, and secrets are stored masked."]}),t&&n.jsx("span",{className:"w6w-muted w6w-small",children:"This step is inside a For each, so it writes once per item — Append collects one entry per item."})]})}function ao(e,t,s){const o=je(),[r,a]=b.useState([]),i=JSON.stringify(t.map(l=>[l.id,l.label]));return b.useEffect(()=>{const l=JSON.parse(i);if(!s||l.length===0){a([]);return}let u=!1;return xd(c=>o.listStepTests(e,c),l.map(([c,d])=>({id:c,label:d}))).then(c=>{u||a(c)}),()=>{u=!0}},[o,e,i,s]),r}function Ya(e){return(e.nodes??e.steps??[]).filter(t=>t.uses.app===Rt&&t.uses.action==="manual")}function Fd(e,t){var a;const s=Ya(e),o=t?s.find(i=>i.id===t):s[0],r=(a=o==null?void 0:o.with)==null?void 0:a.fields;return Array.isArray(r)?r.flatMap(i=>!i||typeof i!="object"||typeof i.key!="string"||!i.key.trim()?[]:[{key:i.key,label:i.key,type:Us(i.type),default:Vs(i.type,i.default),required:!!i.required}]):[]}const Ld=["function","workflow"],Md={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"/>'},zn={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},Dd=["props","code","params-code","config"];function Mn({view:e,onChange:t,disabled:s,views:o=Dd,customized:r=!1}){const a=i=>n.jsx("button",{type:"button",title:zn[i].label,"aria-label":zn[i].label,"aria-pressed":e===i,disabled:s,className:`w6w-icon-btn${e===i&&!s?" active":""}`,onClick:()=>t(i),children:n.jsx(le.Icon,{name:zn[i].icon,size:15})},i);return n.jsxs("div",{className:"w6w-view-toggle",children:[r&&n.jsx("button",{type:"button",className:"w6w-json-customized",disabled:s,onClick:()=>t("params-code"),title:"JSON customization adds or overrides form values",children:"JSON customized"}),o.map(a)]})}function Wd({onClose:e,onDone:t,onAdd:s,onDraftChange:o,theme:r,appsOnly:a,callables:i=Ld,initialTab:l,title:u,workflowId:c,stepId:d,upstreamSteps:p=[],loop:f,initialApp:m,initialAction:w,initialConnection:h,initialWith:g,appsFilter:y,appsIds:x,connectionOnly:C,setupOnly:E,addLabel:S,onConnected:j,excludeCallableIds:N,onOpenStep:A,stepIds:$=[]}){const[P,R]=b.useState(null),[I,T]=b.useState(null),_=b.useRef(null),q=ie=>{const pe=s(ie);return typeof pe=="string"&&(_.current=ie,R(pe),T(null)),pe},U=o?(ie,pe)=>{_.current=pe,o(ie,pe)}:void 0,B=()=>{P&&I&&I!==P&&U&&_.current&&U(P,{..._.current,id:I}),(t??e)()},F=ie=>P&&o?n.jsxs("span",{className:"w6w-stepbuilder-title",children:[ie,n.jsx(Zr,{value:I??P,onCommit:pe=>{const Te=_a(pe,$.filter(Re=>Re!==P));return Te||T(pe),Te}})]}):ie,[O,K]=b.useState(l??"connected"),[G,Q]=b.useState(""),[M,X]=b.useState(!1),J=G.trim()!==""&&!M,W=ie=>{K(ie),X(!0)},[ne,ee]=b.useState(m??null),[v,D]=b.useState(null),[Y,re]=b.useState(null),[z,ge]=b.useState(null),me=ie=>{if(!E)return ge(ie);s({uses:{app:Zt,action:"call"},with:{targetKind:ie.family,targetId:ie.id}})},xe=!!x&&x.length>0,Ne=Qa(i,y,N,x),be=Ne.state!=="empty";if(b.useEffect(()=>{!be&&O==="connected"&&K("apps")},[be,O]),z)return n.jsx(ke,{title:F(z.label),ariaLabel:z.label,subtitle:n.jsx("code",{children:z.id}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>ge(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(zd,{family:z.family,targetId:z.id,targetLabel:z.label,onAdd:q,onClose:e,onDone:B,onDraftChange:U})})});if(v)return n.jsx(ke,{title:F(v.groupActions?v.displayName:v.label),ariaLabel:v.groupActions?v.displayName:v.label,titleIcon:n.jsx(Fn,{icon:v.icon,size:22}),subtitle:n.jsxs("code",{children:[v.app,!v.groupActions&&` · ${v.action}`]}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>D(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(Jd,{node:v,onAdd:q,onClose:e,onDone:B,onDraftChange:U,onOpenStep:A,workflowId:c,upstreamSteps:p,loop:f})})});const ce=Y??ne;if(ce){const ie=Y?"trigger":"action",pe=()=>{ee(null),re(null)};return n.jsx(ke,{title:F(ce.displayName),ariaLabel:ce.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:ce.id}),ce.version&&` · v${ce.version}`]}),onClose:e,size:"xl",titleIcon:n.jsx(gt,{src:ce.iconSvg,srcDark:ce.iconSvgDark,brandColor:ce.brandColor,name:ce.displayName,theme:r,size:22}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:C&&ie==="action"?n.jsx(np,{appId:ce.id,app:ce,onClose:e,onChangeApp:pe,theme:r,initialConnection:h,onConnected:(Te,Re)=>j==null?void 0:j(Te,Re)}):n.jsx(tp,{kind:ie,onOpenStep:A,appId:ce.id,app:ce,onAdd:q,onClose:e,onDone:B,onDraftChange:U,onChangeApp:pe,theme:r,workflowId:c,stepId:d,upstreamSteps:p,loop:f,...ie==="action"?{initialAction:w,initialConnection:h,initialWith:g}:{},setupOnly:E&&ie==="action",addLabel:S})})})}return n.jsx(ke,{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 apps, workflows and nodes…",value:G,onChange:ie=>{Q(ie.target.value),X(!1)}}),n.jsxs("div",{className:"w6w-stepbuilder",children:[n.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[be&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="connected"?" active":""}`,onClick:()=>W("connected"),children:"Ready to use"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="apps"?" active":""}`,onClick:()=>W("apps"),children:"Apps"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="ai"?" active":""}`,onClick:()=>W("ai"),children:"AI"}),i.includes("workflow")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="workflows"?" active":""}`,onClick:()=>W("workflows"),children:"Workflows"}),i.includes("function")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="functions"?" active":""}`,onClick:()=>W("functions"),children:"Functions"}),!a&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="triggers"?" active":""}`,onClick:()=>W("triggers"),children:"Triggers"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="controls"?" active":""}`,onClick:()=>W("controls"),children:"Controls"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="utilities"?" active":""}`,onClick:()=>W("utilities"),children:"Utilities"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!J&&O==="data"?" active":""}`,onClick:()=>W("data"),children:"Data"})]})]}),n.jsx("div",{className:"w6w-stepbuilder-content",children:J?n.jsx(qd,{query:G,builtIns:!a,callables:i,excludeCallableIds:N,appsFilter:y,appsIds:x,theme:r,onSelectNode:D,onSelectApp:ee,onSelectCallable:me}):O==="connected"?n.jsx(ep,{data:Ne,query:G,appsFilter:y,onSelectApp:ee,onSelectCallable:me,theme:r}):O==="functions"?n.jsx(kn,{family:"function",query:G,excludeIds:N,onSelect:ie=>me({family:"function",...ie})}):O==="workflows"?n.jsx(kn,{family:"workflow",query:G,excludeIds:N,onSelect:ie=>me({family:"workflow",...ie})}):O==="apps"?n.jsx(ot,{search:!1,searchValue:G,onSelectApp:ee,theme:r,filter:y,ids:x}):O==="ai"?n.jsx(ot,{search:!1,searchValue:G,onSelectApp:ee,theme:r,category:xe?void 0:"ai",ids:x,filter:ie=>{var pe;return((y==null?void 0:y(ie))??!0)&&(xe||(((pe=ie.categories)==null?void 0:pe.includes("ai"))??!1))},emptyMessage:"No AI apps registered yet."}):O==="triggers"?n.jsx(Ud,{query:G,onSelect:D,onSelectApp:re,theme:r,appsFilter:y,appsIds:x}):O==="controls"?n.jsx(Vd,{query:G,onSelect:D}):O==="data"?n.jsx(Bd,{query:G,onSelect:D}):n.jsx(Hd,{query:G,onSelect:D})})]})]})})}function Ut(e,...t){const s=t.filter(Boolean).join(" ").toLowerCase();return e.trim().toLowerCase().split(/\s+/).every(o=>s.includes(o))}function io(e,t){return Ut(t,e.label,e.displayName,e.app,e.action)}function qd({query:e,builtIns:t,callables:s,excludeCallableIds:o,appsFilter:r,appsIds:a,theme:i,onSelectNode:l,onSelectApp:u,onSelectCallable:c}){const d=new Set,p=t?it.filter(f=>f.hidden||!io(f,e)?!1:f.groupActions?d.has(f.app)?!1:(d.add(f.app),!0):!0):[];return n.jsxs("div",{className:"w6w-stepbuilder-results","data-testid":"stepbuilder-search-all",children:[p.length>0?n.jsxs("section",{className:"w6w-stepbuilder-results-section",children:[n.jsx("h4",{children:"Built-in"}),n.jsx("div",{className:"w6w-stepbuilder-list",children:p.map(f=>n.jsx(co,{node:f,onSelect:l},`${f.app}:${f.action}`))})]}):null,n.jsxs("section",{className:"w6w-stepbuilder-results-section",children:[n.jsx("h4",{children:"Apps"}),n.jsx(ot,{search:!1,searchValue:e,onSelectApp:u,theme:i,filter:r,ids:a})]}),s.includes("workflow")?n.jsx(kn,{section:!0,family:"workflow",query:e,excludeIds:o,onSelect:f=>c({family:"workflow",...f})}):null,s.includes("function")?n.jsx(kn,{section:!0,family:"function",query:e,excludeIds:o,onSelect:f=>c({family:"function",...f})}):null]})}function lo({nodes:e,onSelect:t,query:s}){const o=new Set,r=e.filter(a=>io(a,s)?a.groupActions?o.has(a.app)?!1:(o.add(a.app),!0):!0:!1);return r.length?n.jsx("div",{className:"w6w-stepbuilder-list",children:r.map(a=>n.jsx(co,{node:a,onSelect:t},`${a.app}:${a.action}`))}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No nodes match “",s,"”."]})}function co({node:e,onSelect:t}){return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>t(e),children:[n.jsx(Fn,{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 Ud({query:e,onSelect:t,onSelectApp:s,theme:o,appsFilter:r,appsIds:a}){var w;const i=je(),l=it.filter(h=>h.group==="trigger"&&io(h,e)),[u,c]=b.useState(!1),d=Qa([],r,void 0,a,{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(ot,{onSelectApp:s,theme:o,filter:r,ids:a?[...a]:void 0,hasTriggers:!0,search:!1,searchValue:e,emptyMessage:"No apps declare triggers yet."})]});const f=d.apps.filter(h=>(h.triggerCount??0)>0&&Ut(e,h.displayName,h.id)).sort(Vt(h=>h.displayName)).map(h=>n.jsx(ei,{app:h,theme:o,onSelect:s},h.id));d.moreApps&&f.push(n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:d.loadMoreApps,children:"Load more"},"__load_more_apps"));let m;return d.state==="error"?m=n.jsx("div",{className:"w6w-result w6w-error",children:d.error}):d.state==="loading"?m=n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}):e.trim()&&((w=d.appIds)!=null&&w.length)&&typeof i.listAppsPage=="function"?m=n.jsx(ot,{search:!1,searchValue:e,ids:d.appIds,hasTriggers:!0,filter:r,onSelectApp:s,theme:o}):f.length===0?m=n.jsxs("p",{className:"w6w-muted w6w-small w6w-readytouse-empty",children:[e.trim()?`No connected apps match “${e}”.`:"No connected apps with triggers yet"," ","·"," ",n.jsx("button",{type:"button",className:"w6w-linkbtn",onClick:()=>c(!0),children:"Search all apps"})]}):m=n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:f}),n.jsxs("div",{className:"w6w-apppicker-host",children:[n.jsxs("div",{className:"w6w-readytouse","data-cols":2,children:[n.jsxs("section",{className:"w6w-readytouse-col","data-col":"your-apps",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Your apps"}),m]}),n.jsx("div",{className:"w6w-readytouse-stack",children:n.jsxs("section",{className:"w6w-readytouse-col","data-col":"built-in",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Built-in"}),n.jsxs("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:[l.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:["No built-in triggers match “",e,"”."]}),l.map(h=>n.jsx(co,{node:h,onSelect:t},`${h.app}:${h.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 Vd({onSelect:e,query:t}){const s=it.filter(o=>o.group==="control"&&!o.hidden);return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Flow-control nodes branch, route, join paths, loop, parallelize, pause, or stop the run."}),n.jsx(lo,{nodes:s,onSelect:e,query:t})]})}function Hd({onSelect:e,query:t}){const s=it.filter(o=>o.group!=="control"&&o.group!=="trigger"&&o.app!==Ht&&o.app!==gs&&o.app!==Je&&!o.hidden);return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Run scripts, work with regular expressions, render templates, call models, or make HTTP requests."}),n.jsx(lo,{nodes:s,onSelect:e,query:t})]})}function Bd({onSelect:e,query:t}){const s=it.filter(o=>(o.app===Ht||o.app===Je||o.app===gs)&&!o.hidden);return n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:"Set data, read documents, read and write store entries, or query stored rows."}),n.jsx(lo,{nodes:s,onSelect:e,query:t})]})}function Jd({node:e,onAdd:t,onClose:s,onDone:o,onDraftChange:r,onOpenStep:a,workflowId:i,upstreamSteps:l=[],loop:u}){var B,F;const[c,d]=b.useState(e),p=e.groupActions?it.filter(O=>O.app===e.app&&!O.hidden):[],[f,m]=b.useState(()=>xn(c.app,c.action)),w=!kt(c.app),h=ao(i??"",l,w&&!!i),g=(B=Xe().stateShape)==null?void 0:B.written,y=ro(h,Ba(u),g),[x,C]=b.useState("configure"),[E,S]=b.useState("props"),[j,N]=b.useState("{}"),[A,$]=b.useState({}),P=Tt(c.params,f),[R,I]=b.useState(null),T=()=>({uses:{app:c.app,action:c.action},with:f,...A});b.useEffect(()=>{if(!r)return;const O=t(T());O&&I(O),O&&c.app===qe&&(a==null||a(O))},[]),b.useEffect(()=>{!r||R===null||r(R,T())},[R,f,A,c]);const _=O=>{O==="code"&&N(so(T())),S(O)},q=()=>t(T()),U=i&&R!==null?{workflowId:i,stepId:R,input:{}}:void 0;return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsxs("div",{className:"w6w-tabsbar",children:[n.jsxs("div",{className:"w6w-subtabs",children:[n.jsx("button",{type:"button",className:`w6w-subtab${x==="configure"?" active":""}`,onClick:()=>C("configure"),children:"Configure"}),w&&n.jsx("button",{type:"button",disabled:!P,title:P?void 0:"Fill the required fields first",className:`w6w-subtab${x==="test"?" active":""}`,onClick:()=>P&&C("test"),children:"Test"})]}),n.jsx(Mn,{view:E,customized:_n(f),onChange:_,disabled:x!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[x==="configure"&&E==="props"&&p.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:O=>{const K=p.find(Q=>Q.action===O.target.value);if(!K)return;const G=xn(K.app,K.action);m(Object.fromEntries(K.params.flatMap(Q=>Q.key in f?[[Q.key,f[Q.key]]]:Q.key in G?[[Q.key,G[Q.key]]]:[]))),d(K)},children:p.map(O=>n.jsx("option",{value:O.action,children:O.label},O.action))})]}),x==="configure"&&(E==="props"?c.app===Ot?n.jsx("p",{className:"w6w-muted w6w-small",children:cr}):c.action==="wait"&&kt(c.app)?n.jsx(ba,{values:f,onChange:m}):c.action==="if"&&kt(c.app)?n.jsx(Pn,{values:f,onChange:m}):c.app===xs?n.jsx(Qr,{values:f,onChange:m}):c.app===Ke?n.jsx(Xr,{values:f,onChange:m}):n.jsx(Fe,{params:c.params,values:f,onChange:m}):E==="code"?n.jsx(ze,{value:j,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):E==="params-code"?n.jsx(Ms,{values:f,onChange:m}):n.jsx(Za,{step:{id:R??"",...T()},config:A,onChange:$,inLoop:u!==void 0,outputFields:(F=c.output)==null?void 0:F.map(O=>O.key),failureHandling:!gn(c.app),retryControls:!kt(c.app)&&c.app!==Zt})),x==="test"&&w&&(gn(c.app)?n.jsx(ma,{app:c.app,action:c.action,fields:f.fields,persist:U},(U==null?void 0:U.stepId)??""):n.jsx(uo,{app:c.app,action:c.action,values:f,canRun:P,state:y,persist:U},(U==null?void 0:U.stepId)??""))]}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),x==="configure"&&w?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!P,onClick:()=>C("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:R!==null?o??s:q,children:R!==null?"Done":"Add node"})]})]})}function kn({family:e,query:t,excludeIds:s,onSelect:o,section:r=!1}){const a=je(),[i,l]=b.useState(null),[u,c]=b.useState(null),d=e==="function"?"Functions":"Workflows";b.useEffect(()=>{let g=!1;return(e==="function"?a.listFunctions():a.listWorkflows()).then(x=>!g&&l(x)).catch(x=>!g&&c(x.message)),()=>{g=!0}},[a,e]);const p=g=>n.jsx("div",{className:"w6w-apppicker-host",children:g});if(r&&(u||i===null||i.length===0))return null;if(u)return p(n.jsx("div",{className:"w6w-result w6w-error",children:u}));if(i===null)return p(n.jsxs("p",{className:"w6w-muted w6w-small",children:["Loading ",d.toLowerCase(),"…"]}));if(i.length===0)return p(n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",d.toLowerCase()," registered yet."]}));const f=St,m=t.trim().toLowerCase(),w=hs(i,s).sort(Vt(f)),h=m?w.filter(g=>f(g).toLowerCase().includes(m)||g.id.toLowerCase().includes(m)):w;return r?h.length===0?null:n.jsxs("section",{className:"w6w-stepbuilder-results-section",children:[n.jsx("h4",{children:d}),n.jsx("div",{className:"w6w-stepbuilder-list",children:h.map(g=>n.jsx(Sn,{family:e,item:g,onSelect:o},g.id))})]}):p(n.jsx("div",{className:"w6w-stepbuilder-apps",children:h.length===0?n.jsxs("p",{className:"w6w-muted w6w-small",children:["No ",d.toLowerCase()," match “",t,"”."]}):n.jsx("div",{className:"w6w-stepbuilder-list w6w-stepbuilder-scroll",children:h.map(g=>n.jsx(Sn,{family:e,item:g,onSelect:o},g.id))})}))}function zd({family:e,targetId:t,targetLabel:s,onAdd:o,onClose:r,onDone:a,onDraftChange:i}){const[l,u]=b.useState({targetKind:e,targetId:t,inputs:{},wait:!0}),[c,d]=b.useState(!1),[p,f]=b.useState("configure"),[m,w]=b.useState(null),h=()=>({uses:{app:Zt,action:"call"},with:l});b.useEffect(()=>{if(!i)return;const y=o(h());y&&w(y)},[]),b.useEffect(()=>{!i||m===null||i(m,h())},[m,l]);const g=()=>o(h());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${p==="configure"?" active":""}`,onClick:()=>f("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!c,title:c?void 0:"Fill the required fields first",className:`w6w-subtab${p==="test"?" active":""}`,onClick:()=>c&&f("test"),children:"Test"})]})}),n.jsx("div",{className:"w6w-stepconfig-body",children:p==="configure"?n.jsx(si,{fixedTarget:!0,values:l,onChange:u,onValidityChange:d,targetLabel:s}):n.jsx(Kd,{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:r,children:"Cancel"}),p==="configure"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:!c,onClick:()=>f("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:m!==null?a??r:g,children:m!==null?"Done":"Add node"})]})]})}function Kd({family:e,targetId:t,inputs:s,entry:o,canRun:r}){const a=je(),[i,l]=b.useState(null),u=async()=>{if(!(!r||(i==null?void 0:i.status)==="running")){l({status:"running"});try{if(e==="function"){const c=await a.invokeFunction(t,s);l({status:"done",output:c,terminal:!0})}else{const c=await a.runWorkflow(t,{input:s,variables:s,entry:o});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:!r||(i==null?void 0:i.status)==="running",onClick:u,children:(i==null?void 0:i.status)==="running"?"Running…":"▶ Test run"}),!r&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),(i==null?void 0:i.status)==="error"&&n.jsx("div",{className:"w6w-result w6w-error",children:i.error}),(i==null?void 0:i.status)==="done"&&!i.terminal&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Still running"}),n.jsxs("div",{className:"w6w-result",children:["Run ",n.jsx("code",{children:i.runId})," has not finished yet — check its status from the workflow's run history."]})]}),(i==null?void 0:i.status)==="done"&&i.terminal&&i.error!==void 0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Run failed"}),n.jsx(le.Copyable,{value:JSON.stringify(i.error,null,2),label:"Copy error",children:n.jsx("pre",{className:"w6w-result w6w-error",style:{whiteSpace:"pre-wrap",maxHeight:220,overflow:"auto",margin:0},children:JSON.stringify(i.error,null,2)})})]}),(i==null?void 0:i.status)==="done"&&i.terminal&&i.error===void 0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result"}),n.jsx(Ae,{value:i.output,maxHeight:220})]})]})}function Gd(e){const t={};for(const s of e)at(s.default)&&(t[s.key]=s.default);return t}function Tt(e,t){const s=Gr(t);if(s===null)return!1;if(s===void 0)return!0;const o=At(e),r=i=>{var l;return s[i]!==void 0?s[i]:(l=o.find(u=>u.key===i))==null?void 0:l.default},a=(i,l,u)=>i.every(c=>{const d=ae.effectiveParam(c,u);if(d.type==="section")return a(d.children??[],l,u);if(d.type==="group"){const f=d.children??[],m=At(f),w=g=>y=>{const x=m.find(C=>C.key===y);return x?g[y]!==void 0?g[y]:x.default:u(y)};if(d.repeat){const g=Array.isArray(l[d.key])?l[d.key]:[];return g.length===0?!d.required:g.every(y=>{const x=y??{};return a(f,x,w(x))})}const h=l[d.key]??{};return a(f,h,w(h))}if(!d.required||!en(c,u))return!0;const p=l[d.key]??d.default;return p==null?!1:typeof p=="string"?p.trim()!=="":!0});return a(e,s,r)}function Xa(e){const t=e==null?void 0:e.testRequired;return typeof t=="boolean"?t:!0}function Yd(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 Xd(e){const t=e==null?void 0:e.apiCalls;return Array.isArray(t)?t:[]}function Zd({log:e,onClose:t}){return n.jsx(ke,{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(Ae,{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(Ae,{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(ka,{calls:e.apiCalls,title:!1,defaultOpen:!0}):n.jsxs("div",{className:"w6w-muted w6w-small",children:["No HTTP request reached the vendor API — the action",e.response.ok?" made no outbound call":" failed before sending one","."]})]})]})})}function Za({step:e,config:t,onChange:s,inLoop:o,outputFields:r,failureHandling:a,retryControls:i}){const l=u=>{const{state:c,fanOut:d,...p}=t;s({...p,...u.state!==void 0?{state:u.state}:{},...u.fanOut!==void 0?{fanOut:u.fanOut}:{}})};return n.jsxs("div",{className:"w6w-stack",children:[n.jsx(Kr,{config:t,onChange:u=>s({...t,...u}),failureHandling:a,retryControls:i}),n.jsx(Ka,{step:e,count:0,onChange:l}),Ea(e)&&n.jsx(Ga,{step:e,inLoop:o,outputFields:r,onChange:l})]})}const uo=b.forwardRef(function({app:t,action:s,connectionId:o,values:r,canRun:a,hideRunButton:i,persist:l,state:u,onBusyChange:c,onResult:d},p){const f=je(),m=ks(),w=Xi(),[h,g]=b.useState(null),[y,x]=b.useState(null),[C,E]=b.useState(!1),S=b.useRef(!1),[j,N]=b.useState(null),A=l==null?void 0:l.workflowId,$=l==null?void 0:l.stepId,P=Xe().nodeMeta,R=$?P==null?void 0:P[$]:void 0;b.useEffect(()=>{if(!A||!$)return;let _=!1;return f.listStepTests(A,$).then(q=>{let U;for(const B of q)!B.lastRunAt||!B.lastRunStatus||(!U||Date.parse(B.lastRunAt)>Date.parse(U.lastRunAt))&&(U=B);!U||!U.lastRunAt||_||S.current||(U.lastRunStatus==="succeeded"?g({status:"done",value:U.lastRunOutput,...U.lastRunMeta?{meta:U.lastRunMeta}:{}}):g({status:"error",error:typeof U.lastRunError=="string"?U.lastRunError:U.lastRunError==null?"Test failed":JSON.stringify(U.lastRunError)}),N(U.lastRunAt))}).catch(()=>{}),()=>{_=!0}},[f,A,$]);const I=async()=>{var F;if(!a||(h==null?void 0:h.status)==="running")return;S.current=!0,N(null),g({status:"running"}),c==null||c(!0);let _;const q=new Date,U={method:"POST",path:`/apps/${encodeURIComponent(t)}/actions/${encodeURIComponent(s)}/invoke`,body:{params:r,...o?{connectionId:o}:{},...m?{project:m}:{},...u?{state:u}:{},...w?{workflowId:w}:{}}},B=O=>x({startedAt:q.toLocaleString(),durationMs:Date.now()-q.getTime(),request:U,response:O,apiCalls:Xd(O.body)});try{const O=await f.invokeAction(t,s,r,{...o?{connectionId:o}:{},project:m,...u?{state:u}:{},...w?{workflowId:w}:{}});B({ok:!0,body:O}),_={status:"done",value:O.value,logs:O.logs,...O.meta?{meta:O.meta}:{}}}catch(O){const K=O;B({ok:!1,...typeof K.status=="number"?{status:K.status}:{},body:Yd(O)}),_={status:"error",error:K.message??String(O),errorCode:K.code,logs:K.logs}}if(g(_),d==null||d(_.status==="done"),l){(F=f.saveTestInput)==null||F.call(f,l.workflowId,l.stepId,Bs(l.input)).catch(O=>console.error("test input save failed",O));try{const O=await f.saveStepTest(l.workflowId,l.stepId,{input:l.input,with:r});await f.recordStepTestRun(l.workflowId,l.stepId,{stepTestId:O.id,status:_.status==="done"?"succeeded":"failed",input:l.input,output:_.status==="done"?_.value:void 0,error:_.status==="error"?_.error:void 0,..._.status==="done"&&_.meta?{meta:_.meta}:{}})}catch(O){console.error("step test persist failed",O)}}c==null||c(!1)};b.useImperativeHandle(p,()=>({run:I}));const T=h&&h.status!=="running"?h.logs:void 0;return n.jsxs("div",{className:"w6w-steptest",children:[(!i||y)&&n.jsxs("div",{className:"w6w-steptest-bar",children:[!i&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!a||(h==null?void 0:h.status)==="running",onClick:I,children:(h==null?void 0:h.status)==="running"?"Running…":"▶ Test run"}),y&&(h==null?void 0:h.status)!=="running"&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>E(!0),title:"The full request and response of the last test run",children:["Log",y.apiCalls.length>0?` (${y.apiCalls.length})`:""]}),!i&&!a&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Fill the required fields to test."})]}),C&&y&&n.jsx(Zd,{log:y,onClose:()=>E(!1)}),j&&((h==null?void 0:h.status)==="done"||(h==null?void 0:h.status)==="error")&&n.jsxs("div",{className:"w6w-muted w6w-small w6w-testout-restored",children:["Last run · ",new Date(j).toLocaleString()]}),(h==null?void 0:h.status)==="error"&&n.jsxs("div",{className:"w6w-result w6w-error",children:[h.errorCode&&n.jsx("div",{className:"w6w-small",style:{opacity:.75,marginBottom:4},children:n.jsx("code",{children:h.errorCode})}),h.error]}),(h==null?void 0:h.status)==="done"&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Result (return value)"}),n.jsx(Ae,{value:h.value,maxHeight:220}),(h.meta||R)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Ae,{value:{...R,...h.meta},maxHeight:220})]})]}),(h==null?void 0:h.status)!=="done"&&(h==null?void 0:h.status)!=="running"&&R&&n.jsxs("div",{className:"w6w-testout","data-testid":"steptest-static-meta",children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Ae,{value:R,maxHeight:220})]}),T&&T.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx(le.Copyable,{value:T.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:T.join(`
|
|
20
|
+
`)})})]})]})}),nr=12,ln=new Set;function Qa(e,t,s,o,r){const a=o&&o.length>0?new Set(o):null,i=M=>(a?a.has(M.id):!0)&&((t==null?void 0:t(M))??!0),l=je(),[u,c]=b.useState(null),[d,p]=b.useState(null),[f,m]=b.useState(null),[w,h]=b.useState(null),[g,y]=b.useState(null),[x,C]=b.useState(()=>new Map),[E,S]=b.useState(()=>new Set),[j,N]=b.useState(ln),A=b.useRef(ln),$=b.useCallback(M=>{A.current=M,N(M)},[]),P=b.useRef(ln),R=e.includes("function"),I=e.includes("workflow"),T=typeof l.listAppsByIds=="function";b.useEffect(()=>{let M=!1;const X=J=>!M&&y(J.message);return l.listConnections().then(J=>{if(M)return;const W=[],ne=new Set,ee=new Map;for(const v of J)st(v.appId)||(T&&!(r!=null&&r.resolveInline)&&v.app&&!ee.has(v.appId)&&ee.set(v.appId,{...v.app,id:v.appId}),!ne.has(v.appId)&&(ne.add(v.appId),W.push(v.appId)));ee.size>0&&(P.current=new Set(ee.keys()),C(v=>new Map([...v,...ee])),S(v=>new Set([...v,...ee.keys()]))),c(W)}).catch(X),R?l.listFunctions().then(J=>!M&&m(J)).catch(X):m([]),I?l.listWorkflows().then(J=>!M&&h(J)).catch(X):h([]),()=>{M=!0}},[l,T,R,I,r==null?void 0:r.resolveInline]),b.useEffect(()=>{if(T)return;const M=l.listApps;if(typeof M!="function"){p([]);return}let X=!1;return M().then(J=>!X&&p(J)).catch(J=>!X&&y(J.message)),()=>{X=!0}},[l,T]);const _=b.useRef(!0);b.useEffect(()=>(_.current=!0,()=>{_.current=!1}),[]);const q=b.useCallback(M=>{const X=l.listAppsByIds;!X||M.length===0||A.current.size>0||($(new Set(M)),X(M).then(J=>{_.current&&($(ln),C(W=>{const ne=new Map(W);for(const ee of J)ne.set(ee.id,ee);return ne}),S(W=>new Set([...W,...M])))}).catch(J=>_.current&&y(J.message)))},[l,$]),U=b.useRef(!1);b.useEffect(()=>{if(!T||u===null||U.current)return;const M=Hn(u,P.current,nr);M.length!==0&&(U.current=!0,q(M))},[T,u,q]);const B=()=>{if(!T||u===null||A.current.size>0)return;const M=new Set([...E,...A.current]);q(Hn(u,M,nr))};if(g)return{state:"error",error:g,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:B};if(f===null||w===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:B};const F=hs(f,s),O=hs(w,s);if(T){if(u===null)return{state:"loading",apps:[],fns:F,wfs:O,moreApps:!1,loadMoreApps:B};if(u.length>0&&E.size===0)return{state:"loading",apps:[],fns:F,wfs:O,moreApps:!1,loadMoreApps:B};const M=Ki(u,x).filter(i),X=j.size===0&&Hn(u,new Set([...E,...j]),1).length>0;return{state:M.length===0&&F.length===0&&O.length===0&&!X?"empty":"ready",apps:M,appIds:u.filter(W=>!a||a.has(W)),fns:F,wfs:O,moreApps:X,loadMoreApps:B}}if(d===null)return{state:"loading",apps:[],fns:F,wfs:O,moreApps:!1,loadMoreApps:B};const K=new Set(u??[]),G=d.filter(M=>!st(M.id)&&i(M)&&(K.has(M.id)||M.zeroCredential===!0));return{state:G.length===0&&F.length===0&&O.length===0?"empty":"ready",apps:G,fns:F,wfs:O,moreApps:!1,loadMoreApps:B}}function hs(e,t){return t&&t.length>0?e.filter(s=>!t.includes(s.id)):[...e]}function Vt(e){return(t,s)=>e(t).localeCompare(e(s),void 0,{sensitivity:"base"})}function St(e){const t=e.displayName;return t!=null&&t.trim()?t:"name"in e?e.name:e.id}function Sn({family:e,item:t,onSelect:s}){const o=St(t);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-stepbuilder-item--callable","data-kind":e,onClick:()=>s({id:t.id,label:o}),children:[n.jsx(Fn,{icon:Md[e],size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:o}),n.jsx("code",{className:"w6w-muted w6w-small",children:t.id})]})]})}function Qd(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 ei({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(gt,{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 ep({data:e,query:t,appsFilter:s,onSelectApp:o,onSelectCallable:r,theme:a}){var g;const i=je(),l=y=>n.jsx("div",{className:"w6w-apppicker-host",children:y});if(e.state==="error")return l(n.jsx("div",{className:"w6w-result w6w-error",children:e.error}));if(e.state==="loading")return l(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}));const u=e.apps.filter(y=>Ut(t,y.displayName,y.id)).sort(Vt(y=>y.displayName)),c=e.fns.filter(y=>Ut(t,St(y),y.id)).sort(Vt(St)),d=e.wfs.filter(y=>Ut(t,St(y),y.id)).sort(Vt(St)),p=Qd,f=u.map(y=>n.jsx(ei,{app:y,theme:a,onSelect:o},y.id));e.moreApps&&f.push(n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:e.loadMoreApps,children:"Load more"},"__load_more_apps"));const m=t.trim()&&((g=e.appIds)!=null&&g.length)&&typeof i.listAppsPage=="function"?n.jsxs("section",{className:"w6w-readytouse-col",children:[n.jsx("h4",{className:"w6w-readytouse-heading",children:"Connected apps"}),n.jsx(ot,{search:!1,searchValue:t,ids:e.appIds,filter:s,onSelectApp:o,theme:a})]}):p("Connected apps",f),w=[p("Functions",c.map(y=>n.jsx(Sn,{family:"function",item:y,onSelect:x=>r({family:"function",...x})},y.id))),p("Workflows",d.map(y=>n.jsx(Sn,{family:"workflow",item:y,onSelect:x=>r({family:"workflow",...x})},y.id)))].filter(Boolean),h=(m?1:0)+(w.length>0?1:0);return l(h?n.jsxs("div",{className:"w6w-readytouse","data-cols":h,children:[m,w.length>0&&n.jsx("div",{className:"w6w-readytouse-stack",children:w})]}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Nothing ready to use matches “",t,"”."]}))}function ti(e,t){var s;return(((s=e.getAppTriggers)==null?void 0:s.call(e,t))??Promise.resolve([])).then(o=>o.map(r=>({key:r.key,title:r.title,description:r.description,params:r.params??[]})))}function ni({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 tp({kind:e="action",onOpenStep:t,appId:s,app:o,onAdd:r,onClose:a,onDone:i,onDraftChange:l,onChangeApp:u,theme:c,workflowId:d,stepId:p,upstreamSteps:f=[],loop:m,initialAction:w,initialConnection:h,initialWith:g,setupOnly:y=!1,addLabel:x="Add"}){var et,We;const C=je(),E=e==="trigger",S=E?"a trigger":"an action",[j,N]=b.useState(null),[A,$]=b.useState(null),[P,R]=b.useState(null),[I,T]=b.useState(null),[_,q]=b.useState(h??""),[U,B]=b.useState(),F=zs(),O=b.useRef(F);O.current=F;const K=U?$t({uses:{app:s,action:"",connectionRef:U}},F==null?void 0:F.connections)??"":_,G=b.useCallback(Z=>{B(void 0),q(Z)},[]),[Q,M]=b.useState(w??""),[X,J]=b.useState(g??{}),W=b.useRef(null),[ne,ee]=b.useState(!1),[v,D]=b.useState(!y&&w&&g?"configure":"setup"),[Y,re]=b.useState("props"),[z,ge]=b.useState("{}"),[me,xe]=b.useState({});b.useEffect(()=>{let Z=!1;T(null);const de=E?ti(C,s):C.getAppActions(s);return Promise.all([C.getAppAuth(s),C.listConnectionsForApp(s),de]).then(([Ee,k,L])=>{if(Z)return;const H=Xo(s,Ee,k);N(Ee),$(H),R(L);const te=O.current,fe=va({id:p??"",uses:{app:s,action:""}},H,(te==null?void 0:te.nodes)??[],(te==null?void 0:te.connections)??{},h);fe.connectionRef?B(fe.connectionRef):G(fe.connection??"")}).catch(Ee=>!Z&&T(Ee.message)),()=>{Z=!0}},[C,s,E,G,h,p]);const Ne=async()=>{const Z=await C.listConnectionsForApp(s);$(Xo(s,j??[],Z))},be=(j??[]).filter(Z=>Z.available!==!1),ce=be.some(Z=>Z.autoSatisfied===!0&&(Z.type==="tenantAuth"||Z.type==="jit")),ie=ce&&!be.some(Z=>Z.autoSatisfied===!0&&Z.type==="tenantAuth"),pe=be.length>0&&!ce,Te=(A??[]).length>0,Re=j!==null&&A!==null&&pe&&!Te,[Pt,xt]=b.useState(0),he=(P??[]).find(Z=>Z.key===Q),$e=E?Aa(s,P,Q,X):null,Ve=[...P??[]].sort((Z,de)=>(Z.title??Z.key).localeCompare(de.title??de.key,void 0,{sensitivity:"base"})),Le=Xa(o),[Me,Pe]=b.useState(!1);b.useEffect(()=>{if(!Le||!d||!p)return;let Z=!1;return C.listStepTests(d,p).then(de=>{!Z&&de.some(Ee=>Ee.lastRunStatus==="succeeded")&&Pe(!0)}).catch(()=>{}),()=>{Z=!0}},[C,Le,d,p]);const ut=ao(d??"",f,!!d),Ze=(et=Xe().stateShape)==null?void 0:et.written,Se=ro(ut,Ba(m),Ze),Ce=!!Q&&(!pe||Te&&!!K)&&(!$e||$e.selected.length>0),He=Ce&&!!he&&Tt(he.params??[],X),_t=Ce,De=(A??[]).find(Z=>Z.id===K);function V(){return{uses:{app:s,action:(he==null?void 0:he.key)??Q,...U?{connectionRef:U}:K?{connection:K}:{},...E?{trigger:!0}:{}},with:X,...me}}function ue(){he&&r(V())}const[se,Qe]=b.useState(null);b.useEffect(()=>{if(!l||se!==null||!Ce||$e&&v==="setup")return;const Z=r(V());Z&&Qe(Z),Z&&E&&(t==null||t(Z))},[l,se,Ce,v]),b.useEffect(()=>{!l||se===null||l(se,V())},[se,X,me,K,U]);const dt=Z=>{Z==="code"&&ge(so(V())),re(Z)};return n.jsxs("div",{className:"w6w-stepconfig",children:[!y&&n.jsxs("div",{className:"w6w-tabsbar",children:[n.jsxs("div",{className:"w6w-subtabs",children:[n.jsx("button",{type:"button",className:`w6w-subtab${v==="setup"?" active":""}`,onClick:()=>D("setup"),children:"Setup"}),n.jsx("button",{type:"button",disabled:!Ce,title:Ce?void 0:"Complete Setup first",className:`w6w-subtab${v==="configure"?" active":""}`,onClick:()=>Ce&&D("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!He,title:He?void 0:"Fill the required fields first",className:`w6w-subtab${v==="test"?" active":""}`,onClick:()=>He&&D("test"),children:"Test"})]}),n.jsx(Mn,{view:Y,customized:_n(X),onChange:dt,disabled:v!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[v==="setup"&&n.jsxs("div",{className:"w6w-stack",children:[I&&n.jsx("div",{className:"w6w-result w6w-error",children:I}),j===null&&!I&&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:W,children:[n.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App",onClick:u,disabled:!u,children:[o&&n.jsx(gt,{src:o.iconSvg,srcDark:o.iconSvgDark,brandColor:o.brandColor,name:o.displayName,theme:c,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(o==null?void 0:o.displayName)??s})]}),n.jsx(Na,{step:{id:se??p??"",uses:{app:s,action:Q,...U?{connectionRef:U}:{connection:K||void 0}}},conns:A,failed:!!I,open:ne,onOpenChange:ee,anchorRef:W,onChangeConnection:G,onChangeConnectionRef:B,onConnectionCreated:()=>{Ne()},createSignal:Pt})]}),ie&&(De==null?void 0:De.builtIn)&&n.jsx("span",{className:"w6w-hint",children:"Scheduled or queued runs need a stored connection. Choose one from the connection menu."})]}),Re?n.jsxs(Sa,{testId:"step-needs-connection",className:"w6w-sb-connect-gate",action:n.jsxs("button",{type:"button",className:"w6w-btn",onClick:()=>xt(Z=>Z+1),children:["Connect ",(o==null?void 0:o.displayName)??s]}),children:["Connect ",(o==null?void 0:o.displayName)??s," to choose ",S,"."]}):P!==null&&(P.length===0?n.jsx("p",{className:"w6w-muted w6w-small",children:E?"This app declares no triggers.":"This app exposes no actions."}):$e?n.jsx(Ca,{choices:$e,onChange:Z=>{M($e.triggerKey),J(de=>({...de,actions:Z}))}}):n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[E?"Trigger":"Action",Q?"":" *"]}),n.jsx(Ge,{value:Q,placeholder:`— pick ${S} —`,mode:"combobox",listMaxHeight:200,onChange:Z=>{var de;M(Z),J(Gd(((de=(P??[]).find(Ee=>Ee.key===Z))==null?void 0:de.params)??[])),Pe(!1)},options:Ve.map(Z=>({value:Z.key,label:`${Z.title??Z.key} (${Z.key})`}))}),(he==null?void 0:he.description)&&n.jsx("span",{className:"w6w-hint",children:he.description})]}))]}),v==="configure"&&(he?Y==="props"?n.jsx(Fe,{params:he.params??[],values:X,onChange:J,dynamic:{appId:s,actionKey:he.key,connectionId:K||void 0,appName:o==null?void 0:o.displayName}}):Y==="code"?n.jsx(ze,{value:z,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):Y==="params-code"?n.jsx(Ms,{values:X,onChange:J}):n.jsx(Za,{step:{id:p??"",...V()},config:me,onChange:xe,inLoop:m!==void 0,outputFields:(We=ft(he,void 0))==null?void 0:We.fields.map(Z=>Z.key),failureHandling:!E}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Pick ",S," in Setup first."]})),v==="test"&&(he&&E?n.jsx(ni,{title:he.title??he.key,app:(o==null?void 0:o.displayName)??s}):he?n.jsx(uo,{app:s,action:he.key,connectionId:K||void 0,values:X,canRun:Ce&&Tt(he.params??[],X),state:Se,onResult:Pe}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),v==="test"&&n.jsx("div",{className:"w6w-stepconfig-testnote",children:Le&&!Me&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Not yet tested. You can publish without running a test."})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:a,children:"Cancel"}),y?n.jsx("button",{type:"button",className:"w6w-btn","data-testid":"stepbuilder-setup-add",disabled:!Ce,onClick:ue,children:x}):v==="test"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:se===null&&!_t,onClick:se!==null?i??a:ue,children:se!==null?"Done":"Add node"}):n.jsx("button",{type:"button",className:"w6w-btn",disabled:v==="setup"?!Ce:!He,onClick:()=>D(v==="setup"?"configure":"test"),children:"Next →"})]})]})}function np({appId:e,app:t,onClose:s,onChangeApp:o,theme:r,initialConnection:a,onConnected:i}){const l=je(),[u,c]=b.useState(null),[d,p]=b.useState(null),[f,m]=b.useState(null),[w,h]=b.useState(a??""),[g,y]=b.useState(!1),[x,C]=b.useState(!1);b.useEffect(()=>{let T=!1;return m(null),Promise.all([l.getAppAuth(e),l.listConnectionsForApp(e)]).then(([_,q])=>{if(T)return;c(_),p(q),!(_??[]).some(B=>B.autoSatisfied===!0)&&q.length>0&&h(q[0].id)}).catch(_=>!T&&m(_.message)),()=>{T=!0}},[l,e]);const E=async()=>{const T=await l.listConnectionsForApp(e);p(T),T.length>0&&h(_=>_||T[0].id)},S=(u??[]).filter(T=>T.available!==!1),j=S.some(T=>T.autoSatisfied===!0&&(T.type==="tenantAuth"||T.type==="jit")),N=j&&!S.some(T=>T.autoSatisfied===!0&&T.type==="tenantAuth"),A=S.length>0&&!j,$=(d??[]).length>0,P=!A||$&&!!w,R=(d??[]).find(T=>T.id===w),I=x||!w;return n.jsxs("div",{className:"w6w-stepconfig",children:[n.jsx("div",{className:"w6w-stepconfig-body",children:n.jsxs("div",{className:"w6w-stack",children:[f&&n.jsx("div",{className:"w6w-result w6w-error",children:f}),u===null&&!f&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"App"}),n.jsxs("div",{className:"w6w-conn-label",children:[t&&n.jsx(gt,{src:t.iconSvg,srcDark:t.iconSvgDark,brandColor:t.brandColor,name:t.displayName,theme:r,size:20}),n.jsx("span",{className:"w6w-conn-label-name",children:(t==null?void 0:t.displayName)??e}),o&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:o,children:"Change"})]})]}),u!==null&&j&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"Create connection"})]}),N&&n.jsx("span",{className:"w6w-hint",children:'A scheduled or queued run of this workflow still needs a connection configured on this step — use "Create connection" if this step will run on a schedule.'})]}),u!==null&&A&&($?I?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:w,onChange:T=>{h(T.target.value),C(!1)},style:{flex:1},children:(d??[]).map(T=>n.jsxs("option",{value:T.id,children:[T.displayName||T.id," ",T.state?`(${T.state})`:""]},T.id))}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>y(!0),children:"+ New"})]})]}):n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsxs("span",{className:"w6w-conn-label-name",children:[(R==null?void 0:R.displayName)||(R==null?void 0:R.id)||w,R!=null&&R.state?` (${R.state})`:""]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>C(!0),children:"Change"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"+ New"})]})]}):n.jsxs("div",{className:"w6w-result w6w-stepconfig-conn-empty",children:[n.jsx("div",{style:{marginBottom:8},children:"This app needs a connection before its actions can run."}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:()=>y(!0),children:"Create connection"})]}))]})}),n.jsxs("div",{className:"w6w-modal-actions w6w-stepconfig-footer",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:s,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:!P||!t,onClick:()=>t&&i(w,t),children:"Next →"})]}),g&&n.jsx(_s,{theme:r,initialAppId:e,onClose:()=>y(!1),onCreated:async({connectionId:T})=>{y(!1),h(T),C(!1),await E()}})]})}function si({values:e,onChange:t,readOnly:s,setupOnly:o,onValidityChange:r,targetLabel:a,fixedTarget:i}){var B,F;const l=je(),u=e.targetKind==="function"?"function":"workflow",c=typeof e.targetId=="string"?e.targetId:"",d=typeof e.entry=="string"?e.entry:void 0,p=e.inputs&&typeof e.inputs=="object"&&!Array.isArray(e.inputs)?e.inputs:{},f=at(e.inputs)||typeof p.$=="string",[m,w]=b.useState([]),[h,g]=b.useState(),[y,x]=b.useState(),[C,E]=b.useState(),S=`${u}:${c}`;b.useEffect(()=>{if(i)return;let O=!1;return w([]),g(void 0),(u==="workflow"?l.listWorkflows():l.listFunctions()).then(K=>{O||w(K)}).catch(K=>{O||g(String(K.message??K))}),()=>{O=!0}},[l,u,i]),b.useEffect(()=>{let O=!1;return x(void 0),E(void 0),c?((u==="workflow"?l.getWorkflow(c).then(G=>({key:S,workflow:G,fields:[],label:G.displayName||G.name||c})):l.getFunction(c).then(G=>({key:S,fields:G.inputs,label:G.displayName||G.id}))).then(G=>{O||x(G)}).catch(G=>{O||E(String(G.message??G))}),()=>{O=!0}):void 0},[l,c,u,S]);const j=(y==null?void 0:y.key)===S?y:void 0,N=j!=null&&j.workflow?Ya(j.workflow):[],A=d??((B=N[0])==null?void 0:B.id),$=j!=null&&j.workflow?Fd(j.workflow,A):(j==null?void 0:j.fields)??[],R={...Object.fromEntries($.filter(O=>O.default!==void 0).map(O=>[O.key,O.default])),...p},I=u==="function"||!d||N.some(O=>O.id===d),T=!!j&&I&&(f||Tt($,R));b.useEffect(()=>{r==null||r(T)},[T,r]),b.useEffect(()=>{if(!j||s||o)return;const O=!f&&$.some(K=>K.default!==void 0&&!(K.key in p));(!d&&A||O)&&t({...e,...A?{entry:A}:{},inputs:f?e.inputs:R})});const _=m.map(O=>({value:O.id,label:O.displayName||("name"in O?O.name:O.id)||O.id})).sort((O,K)=>O.label.localeCompare(K.label));c&&!_.some(O=>O.value===c)&&_.unshift({value:c,label:(j==null?void 0:j.label)||a||c});const q=c?(F=l.callableHref)==null?void 0:F.call(l,u,c):void 0,U=(O,K)=>{const{target:G,entry:Q,...M}=e;t({...M,targetKind:O,targetId:K,inputs:{}})};return n.jsxs("div",{className:"w6w-stack",children:[!i&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Target kind"}),n.jsxs("select",{className:"w6w-input",value:u,disabled:s,onChange:O=>U(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"}),i?n.jsx("span",{children:(j==null?void 0:j.label)||a||c}):n.jsx(Ge,{"aria-label":u==="workflow"?"Workflow":"Function",options:_,value:c,disabled:s,placeholder:`Choose a ${u}…`,onChange:O=>U(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 ↗"]})]}),h&&n.jsx("div",{className:"w6w-result w6w-error",children:h}),!o&&c&&n.jsxs(n.Fragment,{children:[C?n.jsx("div",{className:"w6w-result w6w-error",children:C}):j?n.jsxs(n.Fragment,{children:[u==="workflow"&&N.length>0&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Trigger"}),n.jsxs("select",{className:"w6w-input","aria-label":"Trigger",value:A,disabled:s,onChange:O=>t({...e,entry:O.target.value,inputs:{}}),children:[d&&!I&&n.jsxs("option",{value:d,children:[d," (unavailable)"]}),N.map(O=>n.jsxs("option",{value:O.id,children:[O.id," (",O.uses.app===Rt?"Manual":O.uses.action,")"]},O.id))]})]}),!I&&n.jsx("div",{className:"w6w-result w6w-error",children:"The selected trigger is unavailable. Choose another trigger."}),u==="workflow"&&N.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:[j.label," has no manual trigger. Add a manual trigger to that workflow to define its input fields."]}),n.jsx("span",{className:"w6w-small",children:"Inputs"}),$.length>0&&!f?n.jsx(Fe,{params:$,values:R,readOnly:s,onChange:O=>t({...e,inputs:O})}):n.jsx(Fe,{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(Fe,{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 sp=/^(#{1,6})\s+(.*)$/,op=new RegExp("\\*\\*(?=\\S)(.+?)(?<=\\S)\\*\\*","g");function rp(e,t){const s=e.ownerDocument;e.replaceChildren();for(const o of t.split(`
|
|
21
|
+
`)){const r=sp.exec(o),a=s.createElement(r?`h${r[1].length}`:"div"),i=r?r[2]:o;let l=0;for(const u of i.matchAll(op)){u.index>l&&a.append(s.createTextNode(i.slice(l,u.index)));const c=s.createElement("strong");c.textContent=u[1],a.append(c),l=u.index+u[0].length}l<i.length&&a.append(s.createTextNode(i.slice(l))),a.firstChild||a.append(s.createElement("br")),e.append(a)}}function ap(e){var o;const t=(o=e.style)==null?void 0:o.fontWeight;if(!t)return;if(t==="bold"||t==="bolder")return!0;const s=Number(t);return Number.isFinite(s)?s>=600:!1}function ip(e){const t=[];for(const s of e){const o=t[t.length-1];o&&o.bold===s.bold?o.text+=s.text:t.push({...s})}return t.map(({text:s,bold:o})=>{const r=s.trim();if(!o||!r)return s;const a=s.slice(0,s.indexOf(r)),i=s.slice(a.length+r.length);return`${a}**${r}**${i}`}).join("")}function lp(e){const t=[];let s=null;const o=i=>(s={level:i,runs:[]},t.push(s),s),r=(i,l,u)=>{if(i.nodeType===3){const h=(i.textContent??"").replace(/ /g," ").replace(/\n/g,"");h&&(s??o(l)).runs.push({text:h,bold:u});return}if(i.nodeType!==1)return;const c=i,d=c.tagName.toLowerCase();if(d==="br"){s||o(l),s=null;return}const p=/^h([1-6])$/.exec(d),f=p||["div","p","li","ul","ol","blockquote","pre"].includes(d);f&&(s=null);const m=p?Number(p[1]):l,w=d==="b"||d==="strong"?!0:ap(c)??u;for(const h of c.childNodes)r(h,m,w);f&&(s=null)};for(const i of e.childNodes)r(i,0,!1);const a=t.map(i=>{const l=ip(i.runs);return i.level>0?`${"#".repeat(i.level)} ${l.trimStart()}`:l});for(;a.length&&a[a.length-1].trim()==="";)a.pop();return a.join(`
|
|
22
|
+
`)}function cp(e){return e.replace(/([^\n])\n(?=[^\n])/g,`$1
|
|
23
|
+
`)}const up=-2,dp=-1,sr=1e3,pp=["#facc15","#fb923c","#f87171","#f472b6","#a78bfa","#60a5fa","#2dd4bf","#4ade80","#9ca3af"],fp=[{level:1,label:"Title"},{level:2,label:"Heading"},{level:3,label:"Subheading"},{level:0,label:"Body"}],hp=80,wp=48,or=10,mp=4,Kn=e=>e.stopPropagation();function bp(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),t.removeAllRanges(),t.addRange(s)}function yp(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 oi({canvas:e,className:t,viewport:s,readOnly:o,zoom:r=1,onChange:a,onSectionDrop:i,onRequestDelete:l}){const[u,c]=b.useState({}),[d,p]=b.useState(null),[f,m]=b.useState(null),[w,h]=b.useState(null),[g,y]=b.useState(null),x=b.useRef(null),C=b.useRef(null),E=b.useRef(null);if(b.useEffect(()=>{if(!d&&!f)return;const v=d?`[data-note-id="${d}"], [data-note-toolbar="${d}"]`:`[data-section-label="${f}"], [data-section-toolbar="${f}"]`,D=Y=>{var ge,me;const re=Y.target;if((ge=re==null?void 0:re.closest)!=null&&ge.call(re,v))return;const z=document.activeElement;(me=z==null?void 0:z.closest)!=null&&me.call(z,"[data-section-toolbar]")&&z.blur(),p(null),m(null),y(null)};return window.addEventListener("pointerdown",D,!0),()=>window.removeEventListener("pointerdown",D,!0)},[d,f]),!s)return null;const S=!o&&!!a,j=e.sections??[],N=e.notes??[],A=v=>u[v.id]??{x:v.position.x,y:v.position.y,w:v.size.width,h:v.size.height},$=v=>{const D=A(v);return{left:D.x,top:D.y,width:D.w,height:D.h,"--w6w-canvas-color":v.color}},P=(v,D)=>a==null?void 0:a({...e,notes:N.map(Y=>Y.id===v?{...Y,...D}:Y)}),R=(v,D)=>a==null?void 0:a({...e,sections:j.map(Y=>Y.id===v?{...Y,...D}:Y)}),I=v=>{const D=C.current,Y=N.find(z=>z.id===v);if(!(D!=null&&D.isConnected)||!Y)return;const re=lp(D);re!==Y.content&&P(v,{content:re})},T=v=>{m(null),p(v)},_=v=>{p(null),m(v)},q=(v,D)=>{E.current=D??null,T(v),h(v),y(null)},U=v=>D=>{if(!D||D.dataset.ready==="1")return;D.dataset.ready="1",C.current=D,rp(D,v.content),D.focus();const Y=E.current;E.current=null,Y?(bp(D),Y(),I(v.id)):yp(D)},B=(v,D,Y)=>{var z;y(null);const re=()=>document.execCommand(D,!1,Y);w===v&&((z=C.current)!=null&&z.isConnected)?(re(),I(v)):q(v,re)},F=v=>v.mode==="move"?{...v.base,x:v.base.x+v.dx,y:v.base.y+v.dy}:{...v.base,w:Math.max(hp,v.base.w+v.dx),h:Math.max(wp,v.base.h+v.dy)},O=(v,D,Y,re)=>{if(!S||v.button!==0)return;v.stopPropagation(),v.preventDefault();const z={kind:Y,id:D.id,mode:re,sx:v.clientX,sy:v.clientY,base:A(D),dx:0,dy:0};x.current=z;const ge=xe=>{z.dx=(xe.clientX-z.sx)/(r||1),z.dy=(xe.clientY-z.sy)/(r||1),c(Ne=>({...Ne,[z.id]:F(z)}))},me=()=>{if(window.removeEventListener("pointermove",ge),window.removeEventListener("pointerup",me),x.current=null,c(be=>{const{[z.id]:ce,...ie}=be;return ie}),z.dx===0&&z.dy===0)return;const xe=F(z),Ne={position:{x:xe.x,y:xe.y},size:{width:xe.w,height:xe.h}};z.kind==="section"&&z.mode==="move"&&i?i(z.id,{dx:z.dx,dy:z.dy}):z.kind==="note"?P(z.id,Ne):R(z.id,Ne)};window.addEventListener("pointermove",ge),window.addEventListener("pointerup",me)},K=t?` ${t}`:"",G="nopan nodrag nowheel",Q=S?N.find(v=>v.id===d):void 0,M=S?j.find(v=>v.id===f):void 0,X=r||1,J=v=>{const D=A(v);return{left:D.x+D.w/2,top:D.y,transform:`translate(-50%, calc(-100% - ${or/X}px)) scale(${1/X})`,transformOrigin:"50% 100%","--w6w-canvas-color":v.color}},W=(v,D)=>{const Y=A(v);return{left:Y.x,top:Y.y,transform:`translate(0, calc(-100% - ${D/X}px)) scale(${1/X})`,transformOrigin:"0 100%","--w6w-canvas-color":v.color}},ne=(v,D,Y,re)=>n.jsxs("div",{className:"w6w-note-menu w6w-note-menu-colors",role:"menu",children:[pp.map(z=>n.jsx("button",{type:"button",role:"menuitemradio","aria-checked":z===v,"aria-label":`Colour ${z}`,title:z,className:`w6w-note-swatch-btn${z===v?" active":""}`,style:{"--w6w-canvas-color":z},"data-testid":`${Y}-option`,"data-color":z,onClick:()=>{y(null),z!==v&&re(z)}},z)),n.jsx("label",{className:"w6w-note-swatch-btn w6w-note-swatch-custom",title:"Custom",children:n.jsx("input",{type:"color","aria-label":`Custom ${D} colour`,"data-testid":`${Y}-input`,value:v,onChange:z=>re(z.currentTarget.value)})})]}),ee=v=>{v.target.closest("input")||v.preventDefault()};return bn.createPortal(n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`w6w-canvas-layer w6w-canvas-sections${K}`,style:{zIndex:up},"data-testid":"w6w-canvas-sections",children:[j.map(v=>n.jsx("div",{className:`w6w-canvas-section${f===v.id?" selected":""}`,style:$(v),"data-section-id":v.id,"data-testid":"section",children:S&&n.jsx("div",{className:`w6w-note-resize ${G}`,"data-testid":"section-resize",onPointerDown:D=>O(D,v,"section","resize")})},v.id)),j.map(v=>(M==null?void 0:M.id)===v.id?null:n.jsx("div",{className:`w6w-canvas-section-title${S?` editable ${G}`:""}`,style:W(v,mp),"data-section-label":v.id,"data-testid":"section-label",title:S?"Click to edit · drag to move":void 0,onPointerDown:S?D=>{_(v.id),O(D,v,"section","move")}:void 0,children:v.title||(S?"Untitled section":"")},v.id))]}),n.jsx("div",{className:`w6w-canvas-layer w6w-canvas-notes${K}`,style:{zIndex:dp},"data-testid":"w6w-canvas-notes",children:N.map(v=>{const D=S&&w===v.id;return n.jsxs("div",{className:`w6w-canvas-note${d===v.id?" selected":""}`,style:$(v),"data-note-id":v.id,"data-testid":"note",children:[D?n.jsx("div",{ref:U(v),className:`w6w-canvas-note-body w6w-canvas-note-editor ${G}`,contentEditable:!0,suppressContentEditableWarning:!0,role:"textbox",tabIndex:0,"aria-multiline":"true","aria-label":"Note content","data-testid":"note-content",onPointerDown:Kn,onBlur:()=>{I(v.id),C.current=null,h(null)},onKeyDown:Y=>{Y.key==="Escape"&&Y.currentTarget.blur()},onPaste:Y=>{Y.preventDefault(),document.execCommand("insertText",!1,Y.clipboardData.getData("text/plain"))}},"editor"):n.jsx("div",{className:`w6w-canvas-note-body ${G}`,"data-testid":"note-view",style:S?{cursor:"grab",touchAction:"none"}:void 0,onPointerDown:S?Y=>{T(v.id),O(Y,v,"note","move")}:void 0,onDoubleClick:S?()=>q(v.id):void 0,children:v.content.trim()?n.jsx(Ws,{content:cp(v.content)}):S&&n.jsx("span",{className:"w6w-canvas-note-empty",children:"Double-click to write"})},"view"),S&&n.jsx("div",{className:`w6w-note-resize ${G}`,"data-testid":"note-resize",onPointerDown:Y=>O(Y,v,"note","resize")})]},v.id)})}),M&&n.jsx("div",{className:`w6w-canvas-layer${K}`,style:{zIndex:sr},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar w6w-section-toolbar ${G}`,role:"toolbar","aria-label":"Section","data-testid":"section-toolbar","data-section-toolbar":M.id,style:W(M,or),onPointerDown:Kn,onMouseDown:ee,children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-grip","aria-label":"Move section",title:"Drag to move","data-testid":"section-drag",onPointerDown:v=>O(v,M,"section","move"),children:n.jsx(le.Icon,{name:"grip"})}),n.jsx("input",{type:"text",className:"w6w-section-title-input","aria-label":"Section title",placeholder:"Untitled section","data-testid":"section-title",defaultValue:M.title,size:Math.max(8,Math.min(32,M.title.length+1)),onBlur:v=>{const D=v.currentTarget.value;D!==M.title&&R(M.id,{title:D})},onKeyDown:v=>{(v.key==="Enter"||v.key==="Escape")&&v.currentTarget.blur()}},`${M.id}:${M.title}`),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn${g==="color"?" active":""}`,"aria-label":"Section colour","aria-expanded":g==="color",title:"Colour","data-testid":"section-color",onClick:()=>y(g==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(le.Icon,{name:"chevron-down",size:12})]}),g==="color"&&ne(M.color,"section","section-color",v=>R(M.id,{color:v}))]}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-delete","aria-label":"Delete section",title:"Delete section","data-testid":"section-delete",onClick:()=>{y(null),l==null||l("section",M.id)},children:n.jsx(le.Icon,{name:"trash"})})]})}),Q&&n.jsx("div",{className:`w6w-canvas-layer${K}`,style:{zIndex:sr},"data-testid":"w6w-canvas-overlay",children:n.jsxs("div",{className:`w6w-note-toolbar ${G}`,role:"toolbar","aria-label":"Note","data-testid":"note-toolbar","data-note-toolbar":Q.id,style:J(Q),onPointerDown:Kn,onMouseDown:ee,children:[n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-grip","aria-label":"Move note",title:"Drag to move","data-testid":"note-drag",onPointerDown:v=>O(v,Q,"note","move"),children:n.jsx(le.Icon,{name:"grip"})}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn${g==="color"?" active":""}`,"aria-label":"Note colour","aria-expanded":g==="color",title:"Colour","data-testid":"note-color",onClick:()=>y(g==="color"?null:"color"),children:[n.jsx("span",{className:"w6w-note-swatch"}),n.jsx(le.Icon,{name:"chevron-down",size:12})]}),g==="color"&&ne(Q.color,"note","note-color",v=>P(Q.id,{color:v}))]}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsxs("div",{className:"w6w-note-toolbar-group",children:[n.jsxs("button",{type:"button",className:`w6w-icon-btn w6w-note-size-btn${g==="size"?" active":""}`,"aria-label":"Text size","aria-expanded":g==="size",title:"Text size","data-testid":"note-size",onClick:()=>y(g==="size"?null:"size"),children:["Aa",n.jsx(le.Icon,{name:"chevron-down",size:12})]}),g==="size"&&n.jsx("div",{className:"w6w-note-menu w6w-note-menu-sizes",role:"menu",children:fp.map(v=>n.jsx("button",{type:"button",role:"menuitem",className:`w6w-note-menu-item w6w-note-size-${v.level}`,"data-testid":`note-size-${v.level}`,onClick:()=>B(Q.id,"formatBlock",v.level?`<h${v.level}>`:"<div>"),children:v.label},v.level))})]}),n.jsx("button",{type:"button",className:"w6w-icon-btn","aria-label":"Bold",title:"Bold","data-testid":"note-bold",onClick:()=>B(Q.id,"bold"),children:n.jsx(le.Icon,{name:"bold"})}),n.jsx("span",{className:"w6w-note-toolbar-sep"}),n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-note-delete","aria-label":"Delete note",title:"Delete note","data-testid":"note-delete",onClick:()=>{y(null),l==null||l("note",Q.id)},children:n.jsx(le.Icon,{name:"trash"})})]})})]}),s)}function gp(e){const t=Yn.useStore(o=>{var r;return((r=o.domNode)==null?void 0:r.querySelector(".react-flow__viewport"))??null}),s=Yn.useStore(o=>o.transform[2]);return n.jsx(oi,{...e,zoom:e.zoom??s,viewport:t})}function xp(e){return e.viewport!==void 0?n.jsx(oi,{...e,viewport:e.viewport}):n.jsx(gp,{...e})}function vp({title:e,message:t,onConfirm:s,onClose:o,confirmLabel:r="Confirm",cancelLabel:a="Cancel",destructive:i=!0,pending:l=!1,autoFocusConfirm:u=!1,children:c}){const d=b.useRef(null);return b.useEffect(()=>{var p;u&&((p=d.current)==null||p.focus())},[u]),n.jsxs(ke,{title:e,onClose:()=>{l||o()},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:o,disabled:l,children:a}),n.jsx("button",{ref:d,type:"button",className:i?"w6w-btn w6w-btn-danger":"w6w-btn",onClick:s,disabled:l,children:r})]})]})}function Yt(e){if(!e||typeof e!="object")return null;switch(e.type){case"string":return"";case"number":return 0;case"boolean":return!1;case"object":{const t={};for(const[s,o]of Object.entries(e.fields??{}))t[s]=Yt(o);return t}case"array":return e.items?[Yt(e.items)]:[];default:return null}}function jp(e){const t={};for(const s of e??[])s&&typeof s.nodeId=="string"&&s.nodeId!==""&&(t[s.nodeId]=s);return t}function Dn(e){return e.sampleOmitted!==!0&&"sample"in e&&e.sample!==void 0}function Wn(e,t){if(!t)return!1;const s=Date.parse(e.updatedAt),o=Date.parse(t);return Number.isFinite(s)&&Number.isFinite(o)&&s>o}function ri(e,t,s,o){const r=t[e],a=s[e];return r!==void 0&&(!a||!Wn(a,o==null?void 0:o[e]))||!a?r:Dn(a)?a.sample:Yt(a.shape)}function Np(e,t,s){const o={};for(const r of new Set([...Object.keys(e),...Object.keys(t)])){const a=ri(r,e,t,s);a!==void 0&&(o[r]=a)}return o}function kp(e,t,s){const o={...e};for(const[r,a]of Object.entries(t))Dn(a)&&(e[r]===void 0||Wn(a,s==null?void 0:s[r]))&&(o[r]=a.sample);return o}function Sp(e,t,s){const o={...e},r={};for(const[a,i]of Object.entries(t))e[a]!==void 0&&!Wn(i,s==null?void 0:s[a])||(delete o[a],r[a]=Dn(i)?i.sample:Yt(i.shape));return{fresh:o,persisted:r}}function Cp(e,t,s){const o={...e},r={};for(const[a,i]of Object.entries(t))Dn(i)&&(e[a]===void 0||Wn(i,s==null?void 0:s[a]))&&(delete o[a],r[a]=i.sample);return{fresh:o,persisted:r}}function Ap(e,t){if(e.app)return e.app;if(e.app!==null)return t.get(e.appId)}function Ep(e){const t=new Set;for(const s of e)s.app===void 0&&t.add(s.appId);return[...t]}exports.AddConnectionModal=_s;exports.AnchoredFlyout=ya;exports.ApiCallsPanel=ka;exports.AppIcon=gt;exports.AppPicker=ot;exports.AppTriggerTestNote=ni;exports.AuthFieldsForm=pn;exports.CALL_APP=Zt;exports.CONTROL_APP=_e;exports.CallTargetForm=si;exports.CanvasLayer=xp;exports.CodeEditor=Cs;exports.Combobox=Ge;exports.ConditionEditor=Pn;exports.ConfigViewToggle=Mn;exports.ConfirmModal=vp;exports.CreateSharedCredentialContext=Dr;exports.CredentialPicker=Fr;exports.DATA_APP=Ht;exports.DataTable=na;exports.DeleteButton=Ds;exports.EACH_SOURCE_HANDLE=Cn;exports.EDITOR_THEME_SPEC=Ss;exports.ERROR_SOURCE_HANDLE=ms;exports.EmptyState=Sa;exports.EventbriteTriggerPicker=Ca;exports.ExpressionEditorModal=Qt;exports.ExpressionInput=zt;exports.ExpressionOptionsProvider=Ul;exports.FOREACH_DONE_ROUTE=wt;exports.HTML_PREVIEW_CSP=sa;exports.HtmlPreview=ra;exports.INTERNAL_NODES=it;exports.IconButton=On;exports.InternalIcon=Fn;exports.JsonEditor=ze;exports.LastUsedNote=wa;exports.Markdown=Ws;exports.Modal=ke;exports.NodeConfigForm=Kr;exports.ParamCustomization=Ms;exports.ParamsForm=Fe;exports.PropertyEntryForm=ea;exports.RACE_APP=Ot;exports.RACE_DESCRIPTION=cr;exports.RESULT_RENDER_MAX_CHARS=cs;exports.ROUTER_APP=Ke;exports.ResultViewer=Ae;exports.RetryPolicyFields=zr;exports.RouterEditor=Xr;exports.SCHEDULER_APP=ys;exports.SCRIPT_APP=lr;exports.StepBuilderModal=Wd;exports.StepFanOutControl=Ka;exports.StepNameEditor=Zr;exports.StepStateControl=Ga;exports.StepTestRun=uo;exports.StopEditor=Qr;exports.TRIGGER_APP=Rt;exports.TriggerFillForm=ma;exports.W6WUIProvider=Gi;exports.WEBHOOK_APP=qe;exports.WaitEditor=ba;exports.WorkflowConnectionPicker=Na;exports.WorkflowConnectionsContext=ja;exports.WorkflowProjectProvider=Yi;exports.ancestorIds=oo;exports.applyConnect=Du;exports.applyStepProblems=bu;exports.asFieldDefs=qs;exports.bindingFieldsFor=Lr;exports.bridgeDeletedBodyStep=$u;exports.buildBinding=Mr;exports.buildResolveScope=As;exports.canConnect=Pa;exports.centralizeConnections=xa;exports.coerceDefault=Vs;exports.conditionCombinatorLabel=_c;exports.conditionOperatorLabel=Pc;exports.connectConflict=Wu;exports.connectRefusal=qu;exports.connectionAppIdsToLookUp=Ep;exports.connectionIdFor=$t;exports.controlOwnedIds=Ks;exports.convertCodeBindingsToReads=zl;exports.dataVarRows=jn;exports.declaredSamples=Ad;exports.deepEqual=ts;exports.defaultConnectionFor=va;exports.definitionLoops=Zs;exports.deleteStepMessage=Mu;exports.detectResultFormat=la;exports.edgeLane=ye;exports.edgeVisuals=Xt;exports.edgeWhenConflict=Vu;exports.editConnectionResources=fn;exports.effectiveEdges=Xs;exports.effectiveNodeOutput=ri;exports.effectiveNodeOutputs=Np;exports.eventbriteTriggerChoices=Aa;exports.excludeSelfStep=ql;exports.fanOutLabel=_d;exports.fanOutState=$d;exports.fieldWidget=Us;exports.fieldsToParams=Hs;exports.filterOptions=mr;exports.findChainRoot=rd;exports.findChainTail=ad;exports.findCodeBindings=Ir;exports.findTestInput=da;exports.flattenParams=At;exports.flowToWorkflow=nd;exports.foreachTestFixture=fd;exports.foreachTestSample=hd;exports.getTriggerDefs=ti;exports.hasParamCustomization=_n;exports.htmlPreviewSrcDoc=oa;exports.idClashMessage=zu;exports.ifPortLayout=Ni;exports.indexNodeSamples=jp;exports.inferOutputFields=ht;exports.internalNodeDef=mt;exports.internalNodeDefaults=xn;exports.internalNodeIcon=Vi;exports.internalNodeLabel=Ui;exports.internalNodeParams=ur;exports.isConnectionBlocked=xu;exports.isControlApp=kt;exports.isDollarPath=Es;exports.isEachLink=Nn;exports.isExprValue=Ye;exports.isFloatingDraft=Va;exports.isForeachStep=ve;exports.isFormResolvedOptions=En;exports.isIfStep=js;exports.isInternalApp=st;exports.isParamVisible=en;exports.isSecretValue=lt;exports.isTestRequired=Xa;exports.isTriggerApp=gn;exports.isTriggerStep=ki;exports.laneForSourceHandle=fi;exports.loopBody=Gs;exports.loopItemText=jd;exports.loopMembership=Ue;exports.loopRefusal=Ia;exports.loopRefusalMessage=Fu;exports.nextWorkflowConnectionName=Js;exports.nodeConfigSources=Td;exports.nodeConfigValues=Rd;exports.nodeMetaSampleValues=Id;exports.nodeMetaValues=Od;exports.nodePortsForStep=Bt;exports.normalizeInput=no;exports.parseJsonFields=_r;exports.parseLoopSeed=Nd;exports.parseRootAnchoredTemplate=rt;exports.pickWebhookSubscription=ua;exports.previewCustomization=Yr;exports.previewNodeOutputs=kp;exports.relaneRefusal=Hu;exports.relayoutNodes=td;exports.rememberableInput=Bs;exports.renameStepInEdges=Bu;exports.requiredParamsFilled=Tt;exports.resolveConnectionAppMeta=Ap;exports.resolveLoopItemsInState=Wa;exports.resolveOutputShape=ft;exports.resolveParamJson=Jt;exports.resolveParamValue=Rs;exports.resolveVarsJson=bl;exports.resultCopyText=ca;exports.routeFromHandle=gi;exports.routeHandle=It;exports.routerPortLayout=ji;exports.routesForStep=vs;exports.seedValues=us;exports.selectNodeConnection=vu;exports.setEdgeWhen=Uu;exports.shapeToSkeleton=Yt;exports.shouldUseCombobox=wr;exports.slugifyLabel=od;exports.splitFrontmatter=ta;exports.splitNodeOutputs=Sp;exports.splitPreviewOutputs=Cp;exports.stampLoopOf=Lu;exports.startOAuthPopup=Wr;exports.startStateFromSeeds=ro;exports.stateWriteVisible=Ea;exports.stepBuilderLoop=gd;exports.stepBuilderUpstreamSteps=yd;exports.stepNameError=_a;exports.stepProblemTooltip=gu;exports.stepToJson=so;exports.storedViewport=La;exports.stripBody=Ys;exports.suggestStepId=id;exports.testInputSavesSettled=fa;exports.trackTestInputSave=pa;exports.upstreamSampleValueSources=Cd;exports.upstreamSampleValues=Sd;exports.upstreamStateSources=bd;exports.useEffectiveTheme=An;exports.useEnterSubmit=qr;exports.useExpressionOptions=Xe;exports.useRememberedTestInput=ha;exports.useSeedSources=ao;exports.useW6WApi=je;exports.useWorkflowConnections=zs;exports.valueAtPath=qt;exports.varLabel=nt;exports.withConnectionRef=Gt;exports.withViewport=sd;exports.workflowToFlow=ed;
|
|
24
|
+
//# sourceMappingURL=connection-app-meta-Cn39S3ED.cjs.map
|