@w6w/ui 0.2.62 → 0.2.64
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/dist/{CodeBlock-CPKXSNEs.js → CodeBlock-Bp0SGY1m.js} +82 -57
- package/dist/{CodeBlock-CPKXSNEs.js.map → CodeBlock-Bp0SGY1m.js.map} +1 -1
- package/dist/{CodeBlock-BSX1pi6W.cjs → CodeBlock-a2aIm-0b.cjs} +5 -5
- package/dist/{CodeBlock-BSX1pi6W.cjs.map → CodeBlock-a2aIm-0b.cjs.map} +1 -1
- package/dist/EditConnectionModal.d.ts +1 -1
- package/dist/code.cjs +1 -1
- package/dist/code.mjs +1 -1
- package/dist/components/CallableBindingSetup.d.ts +15 -0
- package/dist/components/ConnectionList.d.ts +1 -1
- package/dist/components/DataStoreList.d.ts +1 -1
- package/dist/components/DataTable.d.ts +6 -0
- package/dist/components/IconButton.d.ts +4 -0
- package/dist/components/RunCallable.d.ts +52 -0
- package/dist/components/expression-authoring.d.ts +3 -2
- package/dist/components/expression-dom.d.ts +30 -0
- package/dist/components/icons.d.ts +1 -1
- package/dist/connection-app-meta-BRf92BmY.cjs +26 -0
- package/dist/connection-app-meta-BRf92BmY.cjs.map +1 -0
- package/dist/{connection-app-meta-CIfXp2O-.js → connection-app-meta-BWPwf8UR.js} +3372 -3235
- package/dist/connection-app-meta-BWPwf8UR.js.map +1 -0
- package/dist/flow.cjs +1 -1
- package/dist/flow.mjs +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +1696 -1284
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +29 -0
- package/dist/run-callable.d.ts +50 -0
- package/dist/types.d.ts +13 -0
- package/package.json +2 -2
- package/src/styles/_connections.scss +43 -0
- package/src/styles/_data-stores.scss +26 -3
- package/src/styles/_data-table.scss +38 -1
- package/src/styles.css +122 -4
- package/dist/connection-app-meta-CIfXp2O-.js.map +0 -1
- package/dist/connection-app-meta-Cn39S3ED.cjs +0 -24
- package/dist/connection-app-meta-Cn39S3ED.cjs.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";const n=require("react/jsx-runtime"),b=require("react"),le=require("@w6w/expr"),Zn=require("@codemirror/lang-javascript"),fi=require("@codemirror/lang-python"),gs=require("@codemirror/view"),ur=require("@uiw/react-codemirror"),de=require("./CodeBlock-a2aIm-0b.cjs"),dr=require("@codemirror/lang-json"),yo=require("@codemirror/lint"),gn=require("react-dom"),Qn=require("@xyflow/react"),hi=require("react-markdown");var Bn=typeof document<"u"?document.currentScript:null;const wi={ai:"AI",cms:"CMS",crm:"CRM",hr:"HR",devops:"DevOps"};function mi(e){if(typeof e!="string"||e.trim()==="")return"";const t=wi[e];return t||e.split(/[-_\s]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}function bi(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:mi(s),count:o})).sort((s,o)=>o.count-s.count||s.label.localeCompare(o.label,void 0,{sensitivity:"base"}))}function yi(e,t){if(t.length===0)return!0;const s=e.categories??[];return t.some(o=>s.includes(o))}function Zt(e,t){const s=e==="error"?{className:"w6w-edge-error",label:"on error"}:e==="each"?{className:"w6w-edge-each"}:{};if(!t)return s;const o=t==="taken"?"w6w-edge-taken":"w6w-edge-skipped";return{className:s.className?`${s.className} ${o}`:o,...s.label?{label:s.label}:{}}}const xs="out-error",Tn="out-each",wt="done",pr="each";function vs(e){return e==="error"?xs:e==="each"?Tn:void 0}function gi(e){return e===xs?"error":e===Tn?"each":"success"}const xi="@w6w/",Fe="@w6w/control",fr="@w6w/script",Ht="@w6w/data",Ot="@w6w/trigger",vi="@w6w/http",Ue="@w6w/webhook",js="@w6w/scheduler",ji="@w6w/respond",Qt="@w6w/call",Ns="@w6w/document",rn="@w6w/model",Ni="@w6w/template",an="@w6w/regex",Je="@w6w/store",jt="@w6w/csv",ki="@w6w/files",ks="@w6w/stop",Ke="@w6w/router",It="@w6w/race",hr="Continue once with the first arriving path’s output. Later arrivals are ignored for this run. Other paths keep running.";function Ss(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 $t=e=>`route:${e}`,Si=e=>e!=null&&e.startsWith("route:")?e.slice(6):void 0,Ci=3,Ai=16;function Ei(e){const t=e.find(r=>r.default),s=r=>({id:r.id,handleId:$t(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>Ci?{minHeight:o.length*Ai}:{}}}const xn="false";function Cs(e){return e.uses.app===Fe&&e.uses.action==="if"}function Ti(){return{right:[{id:"true",label:"True",top:"50%"}],bottom:{id:xn,handleId:$t(xn),label:"False"}}}function nt(e){return e.startsWith(xi)}function St(e){return e===Fe||e===It}function vn(e){return e===Ot||e===Ue||e===js}function Ri(e){return vn(e.app)||e.trigger===!0}const go={in:1,out:Number.POSITIVE_INFINITY};function xo(e){return e==="many"?Number.POSITIVE_INFINITY:typeof e=="number"?e:void 0}function Oi(...e){let t,s;for(const o of e)t??(t=xo(o==null?void 0:o.in)),s??(s=xo(o==null?void 0:o.out));return{in:t??go.in,out:s??go.out}}function Bt(e,t){var a;if(e.uses.app===Ke)return{in:1,out:Ss(e).length};const{app:s,action:o}=e.uses,r=e.uses.trigger?{in:0,out:1}:void 0;return Oi(e.ports,t==null?void 0:t(s,o),((a=mt(s,o))==null?void 0:a.ports)??r)}const Ii='<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />',vo='<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" />',$i='<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" />',Pi='<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" />',_i='<circle cx="12" cy="12" r="9" /><polyline points="12 7 12 12 15 14" />',Fi='<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" />',Li='<polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" />',jo='<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" />',Mi='<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" />',Di='<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" />',Wi='<polyline points="9 17 4 12 9 7" /><path d="M20 18v-2a4 4 0 0 0-4-4H4" />',No='<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />',qi='<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" />',Ui='<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" />',Jn='<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" />',Vi='<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" />',Hi='<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" />',dt='<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" />',Nt='<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" />',Bi='<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" />',Ji=[{app:an,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:an,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:an,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:an,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"}]}],zi=[{app:jt,action:"from-json",label:"From JSON",displayName:"CSV",groupActions:!0,group:"compute",icon:Nt,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:jt,action:"create",label:"Create table",displayName:"CSV",groupActions:!0,group:"compute",icon:Nt,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:jt,action:"add-rows",label:"Add rows",displayName:"CSV",groupActions:!0,group:"compute",icon:Nt,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:jt,action:"remove-rows",label:"Remove rows",displayName:"CSV",groupActions:!0,group:"compute",icon:Nt,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:jt,action:"to-text",label:"To CSV text",displayName:"CSV",groupActions:!0,group:"compute",icon:Nt,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:jt,action:"parse",label:"Parse CSV",displayName:"CSV",groupActions:!0,group:"compute",icon:Nt,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"}]}],rt=[...Ji,...zi,{app:It,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:vo,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:ks,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:Ot,action:"manual",label:"Manual trigger",displayName:"Manual trigger",group:"trigger",icon:Ii,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:Ue,action:"webhook",label:"Webhook",displayName:"Webhook",group:"trigger",icon:Di,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:js,action:"schedule",label:"Schedule",displayName:"Scheduler",group:"trigger",icon:Fi,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:Fe,action:"if",label:"If",displayName:"If",group:"control",icon:vo,params:[{key:"condition",type:"json",label:"Condition",required:!0,default:!0,hint:"A boolean, or an expression like {{ nodes.x.output.ok }}."}]},{app:Fe,action:"foreach",label:"For each",displayName:"For each",group:"control",icon:$i,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:Fe,action:"parallel",label:"Parallel",displayName:"Parallel",group:"control",icon:Pi,params:[]},{app:Fe,action:"wait",label:"Wait",displayName:"Wait",group:"control",icon:_i,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:fr,action:"run",label:"Run script",displayName:"Run script",group:"compute",icon:Li,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:Ni,action:"render",label:"Render template",displayName:"Template",group:"compute",icon:Hi,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:jo,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:jo,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:vi,action:"request",label:"HTTP request",displayName:"HTTP",group:"request",icon:Mi,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:ji,action:"respond",label:"Respond to Webhook",displayName:"Respond to Webhook",group:"request",icon:Wi,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:Fe,action:"aggregate",label:"Aggregate",displayName:"Aggregate",group:"control",icon:No,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:Fe,action:"merge",label:"Merge",displayName:"Merge",group:"control",icon:No,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:Qt,action:"call",label:"Call workflow",displayName:"Call",group:"compute",icon:qi,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:Ns,action:"get",label:"Get document",displayName:"Document",group:"compute",icon:Ui,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:rn,action:"complete",label:"Complete with model",displayName:"Model",group:"compute",icon:Jn,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:rn,action:"agent",label:"Run agent",displayName:"Agent",group:"compute",icon:Vi,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:rn,action:"list-models",label:"List models",displayName:"Model",group:"compute",icon:Jn,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:rn,action:"allowance",label:"Model allowance",displayName:"Model",group:"compute",icon:Jn,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:dt,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:dt,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:dt,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:dt,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:dt,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:dt,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:dt,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:ki,action:"save",label:"Save file",displayName:"Files",group:"compute",icon:Bi,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 rt.find(s=>s.app===e&&s.action===t)}function Ki(e,t){var s;return((s=mt(e,t))==null?void 0:s.label)??t}function Gi(e,t){var s;return((s=mt(e,t))==null?void 0:s.icon)??""}function wr(e,t){var s;return((s=mt(e,t))==null?void 0:s.params)??[]}function jn(e,t){const s={};for(const o of wr(e,t))o.default!==void 0&&(s[o.key]=o.default);return s}function Yi(e,t){return e.q===t.q&&(e.category??"")===(t.category??"")&&(e.ids??[]).join(",")===(t.ids??[]).join(",")}function mr(e,t=0){return{query:e,generation:t,status:"loading",apps:[],hasMore:!1}}function Xi(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 Zi(e,t){switch(t.type){case"query-changed":return t.generation===e.generation&&Yi(t.query,e.query)?e:mr(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=Xi(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 Qi(e){return e.filter(t=>!nt(t.id))}function zn(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 el(e,t){const s=[];for(const o of e){const r=t.get(o);r&&s.push(r)}return s}const br=b.createContext(void 0);function ko(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 Rn(e){const t=b.useContext(br),[s,o]=b.useState(()=>ko(e,t));return b.useEffect(()=>{if(e){o(e);return}if(t){o(t);return}if(typeof window>"u")return;const r=()=>o(ko(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=Rn(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 As=b.createContext(null);function tl({api:e,theme:t,children:s}){const o=n.jsx(As.Provider,{value:e,children:n.jsx(br.Provider,{value:t,children:s})});return t?n.jsx("div",{"data-theme":t,style:{display:"contents"},children:o}):o}function Ne(){const e=b.useContext(As);if(!e)throw new Error("useW6WApi must be used inside <W6WUIProvider>. Wrap your app root with <W6WUIProvider api={api}>...</W6WUIProvider>.");return e}function Mt(){return b.useContext(As)??void 0}const yr=b.createContext(void 0),gr=b.createContext(void 0);function nl({project:e,workflowId:t,children:s}){return n.jsx(yr.Provider,{value:e,children:n.jsx(gr.Provider,{value:t,children:s})})}function Es(){return b.useContext(yr)}function sl(){return b.useContext(gr)}const Kn=8,ol=60,rl=300;function So(e){const t=e.modelProvider;return!t||typeof t!="object"?null:t}function al(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 st({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=ol,loadPage:y}){const x=Ne(),k=c!==void 0,E=h&&h.length>0?h.join(","):"",S=!k&&(y!==void 0||typeof x.listAppsPage=="function"),v=b.useRef(y);v.current=y;const[j,C]=b.useState(null),[P,q]=b.useState(null);b.useEffect(()=>{if(k||S)return;const B=x.listApps;if(typeof B!="function"){C([]);return}let fe=!1;return B().then(ne=>!fe&&C(ne)).catch(ne=>!fe&&q(ne.message)),()=>{fe=!0}},[x,k,S]);const[I,$]=b.useReducer(Zi,mr({q:"",category:m,ids:h},0)),[T,R]=b.useState(""),D=i??T,W=B=>{i===void 0&&R(B),l==null||l(B)},[H,L]=b.useState(D.trim()),O=b.useRef(0),K=b.useRef(null),G=b.useCallback((B,fe,ne)=>{var ee;const Qe=v.current,ut=x.listAppsPage;if(!Qe&&!ut)return;(ee=K.current)==null||ee.abort();const et=new AbortController;K.current=et;let qe;try{qe=Qe?Qe({q:B.q||void 0,cursor:ne,limit:g,...B.ids?{ids:B.ids}:{},signal:et.signal}):ut({q:B.q||void 0,category:B.category,...w?{hasTriggers:!0}:{},...B.ids?{ids:B.ids}:{},cursor:ne,limit:g,compact:!0,signal:et.signal})}catch(pe){qe=Promise.reject(pe)}qe.then(pe=>{if(O.current===fe){if(!pe||!Array.isArray(pe.apps)){$({type:"page-failed",generation:fe,error:"The server returned a malformed apps page."});return}$({type:"page-loaded",generation:fe,apps:pe.apps,nextCursor:pe.nextCursor,requestedCursor:ne,total:typeof pe.total=="number"?pe.total:void 0})}}).catch(pe=>{if(O.current!==fe||pe instanceof Error&&pe.name==="AbortError")return;const Ae=pe==null?void 0:pe.code;if(ne!==void 0&&(Ae==="snapshot_expired"||Ae==="unknown_snapshot")){const vt=++O.current;$({type:"query-changed",query:B,generation:vt}),G(B,vt,void 0);return}$({type:"page-failed",generation:fe,error:pe.message})})},[x,g,w]);b.useEffect(()=>{if(!S)return;const B=setTimeout(()=>L(D.trim()),rl);return()=>clearTimeout(B)},[D,S]),b.useEffect(()=>{if(!S)return;const B=++O.current,fe={q:H,category:m,...E?{ids:E.split(",")}:{}};return $({type:"query-changed",query:fe,generation:B}),G(fe,B,void 0),()=>{var ne;(ne=K.current)==null||ne.abort()}},[S,H,m,E,G]),b.useEffect(()=>{if(S)return()=>{var B;return(B=K.current)==null?void 0:B.abort()}},[S]);const se=()=>{if(!S||I.status!=="ready"||!I.hasMore)return;const B=O.current;$({type:"load-more"}),G(I.query,B,I.cursor)},F=()=>{!S||I.status!=="error"||($({type:"retry"}),G(I.query,O.current,I.cursor))},[X,z]=b.useState([]),[M,te]=b.useState(!1),[Q,A]=b.useState(!1),U=B=>n.jsx("div",{className:"w6w-apppicker-host",children:B});let Z,ae=null,Y=!1,ge=!1,V=null,ue=!1;if(k?Z=c??null:S?(Z=I.apps,ue=I.status==="loading",Y=I.status==="loading-more",ge=I.hasMore,I.status==="error"&&(I.apps.length===0?ae=I.error??"Failed to load apps.":V=I.error??"Failed to load apps.")):(Z=j,ae=P),!S&&ae)return U(n.jsx("div",{className:"w6w-result w6w-error",children:ae}));if(!S&&Z===null)return U(n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}));Z??(Z=[]);const ye=Qi(Z),we=s?ye.filter(s):ye;if(!S&&we.length===0)return U(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 ie=d?bi(we):[],ce=ie.slice(0,Kn),he=ie.slice(Kn).filter(B=>X.includes(B.slug)),Re=[...ce,...he],Oe=ie.length-Re.length,_t=M?ie:Re,xt=B=>z(fe=>fe.includes(B)?fe.filter(ne=>ne!==B):[...fe,B]),me=()=>z([]),Pe=we.filter(B=>So(B)!==null).length,He=p&&Pe>0,Me=He&&Q,De=Me?we.filter(B=>So(B)!==null):we,_e=d&&X.length>0?De.filter(B=>yi(B,X)):De,ct=S?_e:[..._e].sort((B,fe)=>B.displayName.localeCompare(fe.displayName,void 0,{sensitivity:"base"})),Ze=S?"":D.trim().toLowerCase(),Se=D.trim().length>0,Ie=Ze?ct.filter(B=>B.displayName.toLowerCase().includes(Ze)||B.id.toLowerCase().includes(Ze)):ct,Ce=s!==void 0&&we.length!==ye.length||Me&&De.length!==we.length||d&&X.length>0&&_e.length!==De.length,Be=(d&&X.length>0||Me)&&Ie.length===0,Ft=Me&&X.length===0,We=()=>{z([]),A(!1),W("")};return U(n.jsxs("div",{className:"w6w-stepbuilder-apps",children:[a&&n.jsx("input",{type:"text",className:"w6w-stepbuilder-search",placeholder:o??"Search apps…",value:D,onChange:B=>W(B.target.value),"aria-label":"Search apps"}),(He||d&&ie.length>0)&&n.jsxs("div",{className:"w6w-apppicker-cats",children:[He&&n.jsxs("button",{type:"button",className:"w6w-apppicker-chip w6w-apppicker-provider-toggle","aria-pressed":Q,"aria-label":"Filter to model providers",onClick:()=>A(B=>!B),children:["Model providers ",n.jsxs("span",{className:"w6w-muted",children:["(",Pe,")"]})]}),d&&ie.length>0&&n.jsxs(n.Fragment,{children:[_t.map(B=>n.jsxs("button",{type:"button",className:"w6w-apppicker-chip","aria-pressed":X.includes(B.slug),"aria-label":`Filter by ${B.label}`,onClick:()=>xt(B.slug),children:[B.label," ",n.jsxs("span",{className:"w6w-muted",children:["(",B.count,")"]})]},B.slug)),!M&&Oe>0&&n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>te(!0),children:["+",Oe," more"]}),M&&ie.length>Kn&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>te(!1),children:"Show less"}),X.length>0&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:me,children:"Clear"})]})]}),S&&ue?n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading apps…"}):S&&ae?n.jsxs("div",{className:"w6w-result w6w-error",children:[ae," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:F,children:"Retry"})]}):Ie.length===0&&!ge?Be?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:Ft?Se?`No model providers match “${D}”.`:"No apps declare a model provider.":Se?`No apps match “${D}” 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:We,children:"Clear filters"})]}):S?n.jsxs("div",{className:"w6w-stack",children:[n.jsx("p",{className:"w6w-muted w6w-small",children:Se?`No apps match “${D}”.`: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 “",D,"”."]}):n.jsxs(n.Fragment,{children:[Ie.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:Ie.map(B=>{const fe=f==null?void 0:f.get(B.id),ne=al(fe);return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item w6w-apppicker-card",onClick:()=>e(B),children:[n.jsx(gt,{src:B.iconSvg,srcDark:B.iconSvgDark,brandColor:B.brandColor,name:B.displayName,theme:t,size:24}),n.jsxs("span",{className:"w6w-stepbuilder-item-main",children:[n.jsx("strong",{children:B.displayName}),n.jsx("code",{className:"w6w-apppicker-card-id",children:B.id}),B.version&&n.jsxs("span",{className:"w6w-apppicker-card-version",children:["v",B.version]}),ne&&n.jsx("span",{className:fe!=null&&fe.supported?"w6w-chip w6w-apppicker-card-bridge":"w6w-chip w6w-apppicker-card-bridge w6w-apppicker-card-bridge-unsupported",title:ne.title,children:ne.text})]})]},B.id)})}),S&&typeof I.total=="number"&&n.jsx("div",{className:"w6w-small w6w-apppicker-count",children:Ce?`${Ie.length} ${Ie.length===1?"app":"apps"}`:`${I.apps.length} of ${I.total}`}),S&&V&&n.jsxs("div",{className:"w6w-result w6w-error w6w-small",children:[V," ",n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:F,children:"Retry"})]}),S&&ge&&!V&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-apppicker-load-more",onClick:se,disabled:Y,children:Y?"Loading more…":"Load more"})]})]}))}const Ts={"&":{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 il(){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:Bn&&Bn.tagName.toUpperCase()==="SCRIPT"&&Bn.src||new URL("connection-app-meta-BRf92BmY.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[Zn.javascriptLanguage.data.of({autocomplete:a}),gs.ViewPlugin.define(()=>(s=!1,{destroy(){s=!0,r()}}))]}function ll(e){switch(e){case"javascript":return Zn.javascript();case"typescript":return Zn.javascript({typescript:!0});case"python":return fi.python()}}function Rs(e){const t=Rn(e.theme),{copied:s,copy:o}=de.useCopyToClipboard(e.value),r=b.useMemo(()=>[...e.language?[ll(e.language)]:[],...e.language==="javascript"||e.language==="typescript"?[il()]:[],gs.EditorView.theme(Ts)],[e.language]);return n.jsxs("div",{className:"w6w-code-editor","aria-label":e["aria-label"]??"Code editor",children:[n.jsx(ur,{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(de.CheckGlyph,{}):n.jsx(de.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function cl(){const e=dr.jsonParseLinter();return t=>t.state.doc.toString().trim()===""?[]:e(t)}function ze(e){const t=Rn(e.theme),{copied:s,copy:o}=de.useCopyToClipboard(e.value),r=b.useMemo(()=>[dr.json(),...e.showDiagnostics===!1?[]:[yo.linter(cl()),yo.lintGutter()],gs.EditorView.theme(Ts)],[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(ur,{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(de.CheckGlyph,{}):n.jsx(de.CopyGlyph,{})}),n.jsx("span",{className:"w6w-copyable-status","aria-live":"polite",children:s?"Copied":""})]})]})}function xr(e,t,s){return e*t>.6*s}function vr(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 Co={display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"none",width:"1.25em",height:"1.25em",overflow:"hidden"},ul=240,Ao={display:"block",fontSize:"0.85em",opacity:.65,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},dl={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=ul,className:d,onInputChange:p,emptyText:f="No matches",footer:m}){const w=i==="combobox"||i==="auto"&&xr(e.length,u,typeof window>"u"?0:window.innerHeight),h=b.useId(),g=e.find(L=>L.value===t),y=(g==null?void 0:g.label)??(l?"":t),[x,k]=b.useState(y),[E,S]=b.useState(!1),[v,j]=b.useState(!1),[C,P]=b.useState(0),q=b.useRef(null);b.useEffect(()=>{k(y)},[y]);const I=b.useMemo(()=>v?vr(e,x):e,[e,x,v]),$=b.useMemo(()=>({...dl,maxHeight:c}),[c]);if(!w)return n.jsxs("select",{className:d,value:t,disabled:r,"aria-label":a,onChange:L=>s(L.target.value),children:[o!==void 0&&t===""&&n.jsx("option",{value:"",disabled:!0,children:o}),e.map(L=>n.jsx("option",{value:L.value,children:L.label},L.value))]});const T=L=>`${h}-opt-${L}`,R=()=>{S(!1),j(!1)},D=L=>{k(L.label),s(L.value),R()},W=L=>{L.key==="ArrowDown"?(L.preventDefault(),E?P(O=>Math.min(O+1,I.length-1)):S(!0)):L.key==="ArrowUp"?(L.preventDefault(),E?P(O=>Math.max(O-1,0)):S(!0)):L.key==="Enter"?E&&I[C]?(L.preventDefault(),D(I[C])):l||(x!==y&&s(x),R()):L.key==="Escape"&&(E&&L.stopPropagation(),k(y),R())},H=()=>{l?k(y):x!==y&&s(x),R()};return n.jsxs("div",{ref:q,className:"w6w-combobox",style:{position:"relative"},children:[(g==null?void 0:g.icon)!==void 0&&!v&&n.jsx("span",{"aria-hidden":"true",className:"w6w-combobox-icon",style:{...Co,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&&!v?{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&&I[C]?T(C):void 0,autoComplete:"off",onFocus:()=>S(!0),onChange:L=>{k(L.target.value),p==null||p(L.target.value),j(!0),P(0),S(!0)},onKeyDown:W,onBlur:H}),E&&n.jsxs("div",{id:`${h}-list`,role:"listbox",tabIndex:-1,"aria-label":a,style:$,children:[I.map((L,O)=>n.jsx("div",{id:T(O),role:"option",tabIndex:-1,"aria-selected":L.value===t,style:{padding:"6px 8px",cursor:"pointer",borderRadius:4,background:O===C?"var(--w6w-panel-2)":void 0},onMouseDown:K=>{K.preventDefault(),D(L)},onMouseEnter:()=>P(O),children:L.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:Co,children:L.icon}),n.jsxs("span",{style:{minWidth:0,flex:1},children:[L.label,L.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:Ao,children:L.detail})]})]}):n.jsxs(n.Fragment,{children:[L.label,L.detail!==void 0&&n.jsx("span",{className:"w6w-combobox-detail",style:Ao,children:L.detail})]})},L.value)),I.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 On(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 at(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&e.type==="secret"&&typeof e.ciphertext=="string"&&typeof e.iv=="string"}function Eo(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 dn(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(Eo)};let s="";for(const o of t){if(o.kind==="text"){s+=o.value??"";continue}pl(s)%2===1&&(s+="\\"),s+=le.serializeTemplate([Eo(o)])}return s}function pl(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t+=1;return t}const jr={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(jr));const To=e=>Object.prototype.hasOwnProperty.call(jr,e),Ro=["state","var","vars"];function Nr(e){for(const t of Ro)if(e===t||e.startsWith(`${t}.`)){const s=e.slice(t.length);return[...new Set([e,...Ro.map(o=>o+s)])]}return[e]}function Oo(e){const t=e.indexOf(".");return t===-1?e:e.slice(0,t)}function it(e){const t=le.parseTemplate(e,"editor",fl);return t.every(In)?t:[{kind:"text",value:e}]}function In(e){if(e.kind==="var"){const t=e.ref??"";return!le.hasRefusedChainToken(t)&&To(Oo(t))}if(e.kind==="expr"){const t=le.coalesceOperandRefs(e.expr);return t===null?!0:t.every(s=>To(Oo(s)))}return!0}const fl={isOurs:In,backslash:"keep"},kr={isOurs:In,backslash:"strip"};function ot(e){return Ye(e)?!0:typeof e=="string"&&e.includes("{{")&&it(e).some(t=>t.kind!=="text")}function $n(e){if(!e.includes("{{"))return null;const t=le.parseTemplate(e,"editor",kr);return t.every(In)&&(t.some(s=>s.kind!=="text")||t.map(s=>s.value??"").join("")!==e)?t:null}function hl(e){return e.includes("{{")?le.parseTemplate(e,"editor",kr).map(t=>t.kind==="text"?t.value??"":le.serializeTemplate([t])).join(""):e}function es(e){if(at(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?it(t):[],sealed:null}}function wl(e,t){let s="";for(const o of e)switch(o.kind){case"text":s+=hl(o.value??"");break;case"var":case"render":{const r=Nr(o.ref??"").find(a=>a in t);s+=r===void 0?"":t[r];break}case"secret":s+="•••";break;case"expr":s+=le.serializeTemplate([o]);break}return s}const At="var.",Io="vars.",ts="documents.",ns="const.",ss="state.";function Sr(e){return e==="state"||e==="vars"?"var":e.startsWith(Io)?At+e.slice(Io.length):e.startsWith(ss)?At+e.slice(ss.length):e}function ml(e){return e.startsWith(ss)?3:e.startsWith(At)?2:1}function Cr(e){return e.rank>0?e.value:Object.fromEntries(Array.from(e.children,([t,s])=>[t,Cr(s)]))}function Os(e,t,s,o){const r={children:new Map,rank:0},a={},i={};for(const[w,h]of Object.entries(e??{})){const g=Sr(w);if(g.startsWith(At)){const y=g.slice(At.length),x=ml(w);let k=r;for(const E of y.split(".")){let S=k.children.get(E);S||(S={children:new Map,rank:0},k.children.set(E,S)),k=S}x>=k.rank&&(k.value=h,k.rank=x)}else g.startsWith(ts)?a[g.slice(ts.length)]=h:g.startsWith(ns)&&(i[g.slice(ns.length)]=h)}const l=Cr(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 bl(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 yl=/^(?:nodes|steps)\.[^.]+\.(?:meta\.)?config(?:\.|$)/,gl=/^(?:nodes|steps)\.([^.]+)\.meta(?:\.|$)/;function xl(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 Ar(e,t){var f;const s=Sr(e);if(t.flat&&(s.startsWith(At)||s.startsWith(ts)||s.startsWith(ns))){const m=Nr(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=xl(t.nodes??t.steps,a,i),c={...l,var:o,...r?{const:r}:{},nodes:u,steps:u},d=bl(c,s);if(d.present)return{status:"resolved",ref:e,value:d.value};if(yl.test(s))return{status:"at-run",ref:e};const p=(f=gl.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 $o(e,t){switch(e.kind){case"text":return{status:"resolved",value:e.value??""};case"var":return Ar(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 Is(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$"in e}function $s(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1&&"$expr"in e}function Ps(e,t){if(at(e))return[{status:"masked"}];if(Ye(e))return e.parts.map(s=>$o(s,t));if(typeof e=="string"){const s=$n(e);if(s)return s.map(o=>$o(o,t))}return Is(e)?[Ar(String(e.$),t)]:$s(e)?[{status:"not-evaluated"}]:[{status:"resolved",value:e}]}function os(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)=>os(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&&os(r[u],a[u]))}function Er(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 vl(e){return e.status==="resolved"&&e.value!==void 0?typeof e.value=="string"?e.value:JSON.stringify(e.value):String(Er(e))}function jl(e){return e.length===1?Er(e[0]):e.map(vl).join("")}function Jt(e,t){return jl(Ps(e,t))}function Nl(e,t){const s={};for(const o of e)s[o.key||"(no key)"]=Jt(o.value,t);return s}const Pn=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(de.Icon,{name:a,size:i??16}):null),w=Object.fromEntries(Object.entries(f).filter(([h])=>h.startsWith("data-")));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"],"aria-haspopup":f["aria-haspopup"],disabled:c,onClick:u,...w,children:m})});Pn.displayName="IconButton";const kl={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${kl[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 _s=new Set(["nodes","steps","state","var","vars","const","inputs","output","trigger","foreach","documents"]),Sl=/[=<>]|!=|&&|\|\||\?\?/,pn=e=>Sl.test(e)||/^\s*\(*\s*!/.test(e),rs=e=>le.expressionReferences(e).some(pn);function Cl(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(_s.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 Dt(e,t){var c,d,p,f,m;const s={parts:e,error:null},o=e.flatMap(w=>w.kind==="text"?it(w.value??""):[w]);if(o.some(w=>w.kind==="render"))return s;if(o.some(Tr))return{parts:o,error:Al};if(o.some(El))return s;if(o.length===1&&o[0].kind==="expr"&&!rs(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(rs(w.expr)){const g=le.serializeTemplate([w]);if(!g.startsWith("{{ ="))return`(${g.slice(2,-2).trim()})`}const h=le.formatReadableExpression(w.expr);return h===null?le.serializeTemplate([w]):`(${h})`}return pn(w.ref??"")?w.ref??"":`{{ ${w.ref??""} }}`}).join("").trim();if(!pn(r))return s;const a=/^\{\{([^{}]+)\}\}$/.exec(r);a&&pn(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&&(_s.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:le.parseReadableExpression(r,h=>Cl(h,t))}],error:null}}catch(w){return{parts:o,error:w instanceof Error?w.message:"Check the expression."}}}const Al="The JSONLogic after “=” is not valid JSON. Check its quotes, brackets and commas.";function Tr(e){return e.kind==="expr"&&typeof e.expr=="string"}function El(e){return e.kind==="expr"&&e.expr!==null&&typeof e.expr=="object"&&!rs(e.expr)&&le.formatReadableExpression(e.expr)===null}function Tl(e){return[...new Set(e.flatMap(t=>t.kind==="expr"?le.expressionReferences(t.expr):(t.kind==="var"||t.kind==="render")&&t.ref?[t.ref]:[]))]}function Rl(e){return e.replace(/^(?:vars|state)(?=\.|$)/,"var").replace(/^steps(?=\.|$)/,"nodes")}function Ol(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=Rl(s).split(".");if(!_s.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 Il(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=Ol(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"||Tr(i))return wl([i],a);if(le.expressionReferences(i.expr).some(c=>!c||c.split(".")[0]==="secrets"))return"••••";const u=le.evaluate(i.expr,r);return typeof u=="string"?u:JSON.stringify(u)??""}).join("")}const $l=/^(?:nodes|steps)\.([^.]+)\.output(?:\.(.+))?$/,Pl=/^(?:nodes|steps)\.([^.]+)\.meta\.(app|version|action|connectionId)$/,ft=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=$l.exec(e);if(t)return t[2]?`${t[1]}.${t[2]}`:t[1];const s=Pl.exec(e);return s?`${s[1]} meta · ${s[2]}`:e};function _l(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 Fl(e){const t=e.op==="or"?"||":"??",s=e.operands.map(o=>{const r=_l(o);return r!==void 0?ft(r):JSON.stringify(o)}).join(` ${t} `);return s.length>40?`${s.slice(0,40)}…`:s}const Ll=/[.{}]/;function kt(e){return e===""||e!==e.trim()?!1:!Ll.test(e)}function ln(e){return e.split(".").every(kt)}function Ml(e){const t=new Set(e.filter(s=>s.path).map(s=>s.key));return e.map(s=>{if(!s.path)return{field:s,depth:0,name:s.key,parent:null};const o=s.key.split(".");let r=0,a=0;for(let l=1;l<o.length;l++)t.has(o.slice(0,l).join("."))&&(r++,a=l);const i=a>0?o.slice(0,a).join("."):null;return{field:s,depth:r,name:o.slice(a).join("."),parent:i}})}function Po(e,t){const s=Ml(e),o=new Map(s.map(i=>[i.field.key,i.parent])),r=new Map;for(const i of s)i.parent!==null&&r.set(i.parent,(r.get(i.parent)??0)+1);const a=i=>{const l=o.get(i)??null;return l===null||t(l)&&a(l)};return s.filter(i=>a(i.field.key)).map(({field:i,depth:l,name:u})=>({field:i,depth:l,name:u,children:r.get(i.key)??0}))}function zt(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=ft(t.ref??""),o.title=`Variable: ${t.ref??""}`;else if(t.kind==="render")o.setAttribute("data-ref",t.ref??""),r.textContent="▤",a.textContent=ft(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=le.parseCoalesceChain(t.expr);if(u)a.textContent=Fl(u),o.title=`Expression: ${le.serializeTemplate([t])}`;else{const c=le.formatReadableExpression(t.expr,ft);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 Rr=new Set(["div","p"]);function Or(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 Wt(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=Or(l);if(u){t.push(u);return}const c=(l.tagName??"").toLowerCase();if(c==="br"){i||s(`
|
|
3
|
+
`);return}const d=Rr.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 Ir=e=>!!e&&(e.tagName??"").toLowerCase()==="br";function $r(e){Ir(e.lastChild)||e.appendChild(e.ownerDocument.createElement("br"))}function Dl(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(Rr.has((r.tagName??"").toLowerCase()))return r}o=o.parentNode}return e}function Fs(e){$r(Dl(e))}const Pr=e=>e.getAttribute("aria-multiline")!=="false";function _r(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(zt(o,i,s));const r=t[t.length-1];(r==null?void 0:r.kind)==="text"&&((a=r.value)!=null&&a.endsWith(`
|
|
5
|
+
`))&&Pr(e)&&$r(e)}function Ls(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 Nn(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 Ir(e.lastChild)?e.insertBefore(t,e.lastChild):e.appendChild(t),Ls(e);e.focus()}function Fr(e,t,s={}){const o=Pr(e),r=o?t.replace(/\r\n?/g,`
|
|
6
|
+
`):t.replace(/\r\n?|\n/g,"");if(!r)return;const a=e.ownerDocument;for(const i of it(r))Nn(e,i.kind==="text"?a.createTextNode(i.value??""):zt(a,i,s));o&&r.endsWith(`
|
|
7
|
+
`)&&Fs(e)}function Lr(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=it(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=zt(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 Mr(e){const t=Or(e);if(!t)return null;const s=t.kind==="expr"&&!le.parseCoalesceChain(t.expr)?le.formatReadableExpression(t.expr):null,o=e.ownerDocument.createTextNode(s??le.serializeTemplate([t]));return e.replaceWith(o),o}function Wl(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 ql(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 Ul(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 Vl(e,t){if(!e||!Object.hasOwn(e,t))return t;let s=2;for(;Object.hasOwn(e,`${t}_${s}`);)s++;return`${t}_${s}`}function _o(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(Wl(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(Vl(d,ql(s)))}: ${i}`,f=e.slice(0,t).trimEnd(),m=f[f.length-1],w=e.slice(t).trimStart()[0],h=Ul(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(),k=x.endsWith(d?"{":"["),E=d?p():i,S=e.slice(x.length,y);if(S.includes(`
|
|
8
|
+
`)){const C=k?`${S.slice(S.lastIndexOf(`
|
|
9
|
+
`)+1)} `:((g=/^\s*/.exec(x.slice(x.lastIndexOf(`
|
|
10
|
+
`)+1)))==null?void 0:g[0])??"",P=`${k?"":","}
|
|
11
|
+
${C}${E}`;return{text:x+P+e.slice(x.length),caret:x.length+P.length}}const v=`${k?"":","} ${E} `,j=x.length;return{text:e.slice(0,j)+v+e.slice(y),caret:j+v.length-1}}return l(t,i)}const Hl=/^\{\{\s*((?:var|vars|const|steps|nodes|trigger|foreach|inputs|output|documents)(?:\.[^\s{}]+)?)\s*\}\}$/;function Bl(e){const t=Hl.exec(e.trim());return t?`{{ ${t[1]} }}`:null}function lt(e){if(typeof e=="string"){if(!e.includes("{{"))return null;const t=it(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 Jl(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 as(e,t){if(typeof e=="string"){const s=$n(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=>as(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,as(r,t)]))}return e}function en({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 sn;const w=l==="json-binding",h=w&&p===!0,[g,y]=b.useState("ref"),[x,k]=b.useState(()=>u===void 0?"":JSON.stringify(u,null,2)),E=b.useRef(null),S=b.useRef(!1),v=b.useMemo(()=>{if(x.trim()==="")return{ok:!1};try{return{ok:!0,value:JSON.parse(x)}}catch{return{ok:!1}}},[x]),j=h?(f==null?void 0:f(x))??null:null,C=h?(x.trim()===""||v.ok)&&j===null:v.ok,P=()=>Os(o.sampleValues,Jl(o.sampleValues),o.nodeConfig,o.nodeMeta),q=w?v.ok?JSON.stringify(as(v.value,N=>Jt(N,P())),null,2):x.trim()===""?"":"Invalid JSON":"",I=N=>{const _=E.current,J=_?_.state.doc.toString():x;if(h){const Te=g==="value"?{value:Jt(`{{ ${N} }}`,P())??null}:void 0,on=J.trim()===""?"{}":J,pi=S.current&&_?_.state.selection.main.head:on.length,Hn=_o(on,pi,N,Te);if(!_){k(Hn.text);return}_.dispatch({changes:{from:0,to:J.length,insert:Hn.text},selection:{anchor:Hn.caret}}),_.focus();return}let oe=null;try{oe=J.trim()===""?null:lt(JSON.parse(J))}catch{oe=null}let ve=!1;if(d)try{const Te=JSON.parse(J);ve=Array.isArray(Te)?Te.length===0:typeof Te=="object"&&Te!==null&&Object.keys(Te).length===0}catch{ve=!1}if(J.trim()===""||oe!==null||ve){c==null||c(`{{ ${N} }}`),i();return}if(!_)return;const be=S.current?_.state.selection.main.head:J.length,re=_o(J,be,N);_.dispatch({changes:{from:0,to:J.length,insert:re.text},selection:{anchor:re.caret}}),_.focus()},[$,T]=b.useState(()=>Dt(es(e).parts,o).parts),R=b.useMemo(()=>Dt($,o),[$,o]),[D,W]=b.useState(0),H=b.useRef(null),L=b.useRef(!1),[O,K]=b.useState({}),[G,se]=b.useState(null),[F,X]=b.useState(()=>new Set),z=N=>{X(_=>{const J=new Set(_);return J.has(N)?J.delete(N):J.add(N),J})},[M,te]=b.useState("auto");b.useLayoutEffect(()=>{const N=H.current;N&&(_r(N,$,{renderToggle:!0}),L.current&&(L.current=!1,Ls(N),N.focus()))},[D]);const Q=()=>{const N=H.current;N&&T(Wt(N))},A=N=>{const _=H.current;_&&(Nn(_,zt(_.ownerDocument,N,{renderToggle:!0})),T(Wt(_)))},U=$.some(N=>N.kind==="render"),Z=(N,{restoreFocus:_})=>{T(Dt(it(N),o).parts),W(J=>J+1)},ae=()=>{const N=H.current,_=Dt(N?Wt(N):$,o);_.error||(a==null||a(dn(_.parts)),i())},Y=()=>{se(null),L.current=!0,W(N=>N+1)},ge=o.vars??[],V=o.constants??[],ue=o.secrets??[],ye=o.inputs??[],we=o.documents??[],ie=o.steps??[],ce=o.nodeConfigs??[],he=o.loop,Re=new Map(ce.map(N=>[N.id,N.keys.filter(kt)]).filter(([,N])=>N.length>0)),Oe=o.nodeMeta??{},_t=N=>zl.filter(([_])=>Kl.has(_)?me(N):Object.hasOwn(Oe[N]??{},_)),xt=ie.filter(N=>N.hasMeta===!0).map(N=>N.id),me=N=>{var J;if(xt.includes(N))return!0;const _=(J=Oe[N])==null?void 0:J.app;return typeof _=="string"&&!nt(_)},Pe=N=>_t(N).map(([_,J])=>ne(J,{kind:"var",ref:`nodes.${N}.meta.${_}`},"w6w-exprmodal-field",null)),He=[...new Set([...Object.keys(Oe),...xt,...Re.keys()])],Me=ie.length>0||!!o.hasTrigger,De=!h&&(Me||!!he),_e=h?[]:(((sn=o.stateShape)==null?void 0:sn.fields)??[]).filter(N=>ln(N.key)),ct=[...De?["state"]:[],..._e.length>0?["runstate"]:[],...He.length>0?["meta"]:[],...o.inputs!==void 0?["inputs"]:[],"vars",...V.length>0?["consts"]:[],...!w||h?["docs"]:[],...w?[]:["secrets"]],Ze=M==="auto"||M!==null&&!ct.includes(M)?ct.find(N=>N!=="meta")??null:M,Se=N=>({open:Ze===N,onToggle:()=>te(Ze===N?null:N)}),Ie=((he==null?void 0:he.itemOutputs)??[]).filter(N=>N.path?ln(N.key):kt(N.key)),Ce=(o.eventOutputs??[]).filter(N=>N.path?ln(N.key):kt(N.key)),Be=le.serializeTemplate(R.parts),Ft=b.useMemo(()=>{const N={};for(const[_,J]of Object.entries(o.sampleValues??{}))N[_]=typeof J=="string"?J:JSON.stringify(J);return{...N,...O}},[o.sampleValues,O]),We=b.useMemo(()=>Tl(R.parts),[R.parts]),B=b.useMemo(()=>{if(R.error)return"";try{return Il(R.parts,o.sampleValues,O)}catch{return Be}},[R,o.sampleValues,O,Be]),fe=b.useMemo(()=>{var _;const N=new Set;for(const J of We){if(O[J]!==void 0)continue;const oe=(_=o.valueSources)==null?void 0:_[J];oe==="sample"?N.add("example from the app"):oe==="persisted"&&N.add("from last test")}return[...N]},[We,O,o.valueSources]),ne=(N,_,J,oe,ve=!1,be,re)=>n.jsxs("div",{className:"w6w-exprmodal-item",style:{display:"flex",alignItems:"center",gap:4,minWidth:0,...re&&re.depth>0?{paddingLeft:re.depth*14}:{}},children:[n.jsxs("button",{type:"button",className:`w6w-exprmodal-source ${J}${re!=null&&re.declaredOnly?" is-declared-only":""}`,style:{flex:1,minWidth:0,...re!=null&&re.declaredOnly?{opacity:.6}:{}},title:`Insert ${(re==null?void 0:re.name)??N}`,"aria-label":be,onClick:()=>w?_.kind==="var"&&I(_.ref??""):A(_),children:[oe!==null&&n.jsx("span",{className:"w6w-expr-chip-sigil",children:oe}),n.jsx("span",{className:"w6w-exprmodal-source-label",children:N}),(re==null?void 0:re.declaredOnly)&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-declared-only",style:{marginLeft:6},children:"declared by the app"}),(re==null?void 0:re.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"})]}),re==null?void 0:re.toggle,!w&&n.jsx(Pn,{icon:"copy",iconSize:14,label:"Copy to expression editor","data-testid":"expr-copy-to-editor",onClick:()=>A(_)})]},`${_.kind}:${_.ref??N}`),Qe=F.has("loop:item"),ut=ne("Current item",{kind:"var",ref:"foreach.item"},"w6w-expr-chip-var","↻"),et=(N,_)=>{if(_.length===0)return null;const J=F.has(`mcfg:${N}`);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-exprmodal-source-row",children:n.jsxs("button",{type:"button",className:"w6w-exprmodal-tree-toggle","data-testid":"expr-config-toggle","aria-expanded":J,title:J?"Hide config":"Show config",onClick:()=>z(`mcfg:${N}`),children:[n.jsx("span",{className:"w6w-exprmodal-tree-caret","aria-hidden":"true",children:J?"▾":"▸"}),"config"]})}),J&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-config-fields",children:_.map(oe=>ne(oe,{kind:"var",ref:`nodes.${N}.meta.config.${oe}`},"w6w-exprmodal-field",null))})]})},qe=(N,_,J=`nodes.${N}.output`)=>pe(_,J,oe=>({declaredOnly:oe.declaredOnly===!0})),ee=N=>Po(N,()=>!1).length,pe=(N,_,J=()=>({}))=>Po(N,oe=>F.has(`tree:${_}.${oe}`)).map(({field:oe,depth:ve,name:be,children:re})=>{const Te=`${_}.${oe.key}`,on=F.has(`tree:${Te}`);return ne(be,{kind:"var",ref:Te},"w6w-exprmodal-field",null,!1,void 0,{name:ft(Te),depth:ve,...J(oe),toggle:re>0?n.jsx(Lt,{count:re,open:on,onToggle:()=>z(`tree:${Te}`)}):void 0})}),Ae=N=>N==="fresh"||N==="persisted"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-fields-from-test",children:N==="fresh"?"Fields from the last test run":"Fields from last test"}):N==="declared"||N==="sample"?n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":`expr-fields-from-${N}`,children:N==="declared"?"declared by the app":"example from the app"}):null,vt=N=>{const _=`mnode:${N}`,J=F.has(_);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":J,"aria-label":J?`Hide ${N} metadata`:`Show ${N} metadata`,title:J?"Hide metadata":"Show metadata",onClick:()=>z(_),children:J?"▾":"▸"}),ne(N,{kind:"var",ref:`nodes.${N}.meta`},"w6w-expr-chip-var w6w-exprmodal-node",null,!0)]}),J&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-metadata-fields",children:[Pe(N),et(N,Re.get(N)??[])]})]},_)};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:!C,title:C?"Save the composed JSON":j??"Compose valid JSON to save",onClick:()=>{C&&(c==null||c(v.ok?v.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:U,title:U?"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(le.serializeTemplate($)),i()},children:"Use a plain value"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:i,children:"Cancel"}),n.jsx("button",{type:"button",className:"w6w-btn",onClick:ae,"data-testid":"expr-save",disabled:R.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(([N,_,J])=>n.jsx("button",{type:"button","aria-pressed":g===N,"data-testid":`expr-insert-as-${N}`,title:J,className:`w6w-btn w6w-btn-sm${g===N?"":" w6w-btn-ghost"}`,onClick:()=>y(N),children:_},N))]}),w&&!h&&!De&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No upstream steps"}),De&&n.jsxs(tt,{label:"Previous steps",...Se("state"),children:[he&&n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":"expr-loop-group",children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:"Loop"}),Ie.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[ut,n.jsx(Lt,{count:ee(Ie),open:Qe,onToggle:()=>z("loop:item")})]}):ut,Ie.length>0&&Qe&&n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-loop-fields",children:pe(Ie,"foreach.item")}),ne("Index",{kind:"var",ref:"foreach.index"},"w6w-expr-chip-var","#"),(he.outer??[]).map(N=>{const _=N.name??N.foreachId,J=`foreach.loops.${N.foreachId}`;return n.jsxs("div",{className:"w6w-exprmodal-subgroup","data-testid":`expr-loop-outer-${N.foreachId}`,children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:_}),ne(`${_} item`,{kind:"var",ref:`${J}.item`},"w6w-expr-chip-var","↻"),ne(`${_} index`,{kind:"var",ref:`${J}.index`},"w6w-expr-chip-var","#")]},N.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":F.has("event"),"aria-label":F.has("event")?"Hide fields":"Show fields",title:F.has("event")?"Hide fields":"Show fields",onClick:()=>z("event"),children:F.has("event")?"▾":"▸"}),ne("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡",!0)]}),F.has("event")&&n.jsxs("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-event-fields",children:[Ae(o.eventOutputsFrom),qe("",Ce,"trigger.event")]})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),ne("trigger.event",{kind:"var",ref:"trigger.event"},"w6w-expr-chip-var w6w-exprmodal-node","⚡")]})),ie.map(N=>{const _=(N.outputs??[]).filter(be=>be.path?ln(be.key):kt(be.key)),J=`step:${N.id}`,oe=F.has(J),ve=ne(N.label??N.id,{kind:"var",ref:`nodes.${N.id}.output`},"w6w-expr-chip-var w6w-exprmodal-node",null,_.length>0);return w?n.jsxs(b.Fragment,{children:[n.jsx("span",{className:"w6w-exprmodal-shape-note",children:N.label??N.id}),ne("Entire output",{kind:"var",ref:`nodes.${N.id}.output`},"w6w-expr-chip-var",null,!1,`Entire output of ${N.label??N.id}`),N.needsTest&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),_.length>0&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":oe,"aria-label":oe?"Hide fields":"Show fields",title:oe?"Hide fields":"Show fields",onClick:()=>z(J),children:oe?"▾":"▸"}),n.jsx(Lt,{count:ee(_),open:oe,onToggle:()=>z(J)})]}),oe&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[Ae(N.outputsFrom),qe(N.id,_)]})]})]},N.id):n.jsxs(b.Fragment,{children:[_.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("button",{type:"button",className:"w6w-exprmodal-caret-btn","data-testid":"expr-caret-fields","aria-expanded":oe,"aria-label":oe?"Hide fields":"Show fields",title:oe?"Hide fields":"Show fields",onClick:()=>z(J),children:oe?"▾":"▸"}),ve,n.jsx(Lt,{count:ee(_),open:oe,onToggle:()=>z(J)})]}):n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[n.jsx("span",{className:"w6w-exprmodal-caret-spacer","aria-hidden":"true"}),ve]}),N.needsTest&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:n.jsx("span",{className:"w6w-exprmodal-shape-note","data-testid":"expr-needs-test",children:"Run a test of this step to see its fields"})}),_.length>0&&oe&&n.jsxs("div",{className:"w6w-exprmodal-subsources",children:[Ae(N.outputsFrom),qe(N.id,_)]})]},N.id)})]}),_e.length>0&&n.jsxs(tt,{label:"State",testId:"expr-state-group",...Se("runstate"),children:[ne("state",{kind:"var",ref:"state"},"w6w-expr-chip-var","◇",!0),n.jsx("div",{className:"w6w-exprmodal-subsources","data-testid":"expr-state-fields",children:pe(_e,"state",N=>({somePaths:N.paths==="some"}))})]}),He.length>0&&n.jsx(tt,{label:"Metadata",testId:"expr-metadata-group",...Se("meta"),children:He.map(N=>vt(N))}),n.jsxs(n.Fragment,{children:[o.inputs!==void 0&&n.jsxs(tt,{label:"Inputs",...Se("inputs"),children:[ye.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No inputs"}),ye.map(N=>ne(N,{kind:"var",ref:`inputs.${N}`},"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:()=>se("var"),children:"+ Add"}),children:[ge.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No variables"}),ge.map(N=>ne(N,{kind:"var",ref:`var.${N}`},"w6w-expr-chip-var","◆"))]}),V.length>0&&n.jsx(tt,{label:"Constants",testId:"expr-constants-group",...Se("consts"),children:V.map(N=>ne(N,{kind:"var",ref:`const.${N}`},"w6w-expr-chip-var","◈"))})]}),(!w||h)&&n.jsxs(tt,{label:"Documents",...Se("docs"),children:[we.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No documents"}),we.map(N=>{const _=(N.fields??[]).filter(be=>kt(be.key)),J=`doc:${N.key}`,oe=F.has(J),ve=ne(N.key,{kind:"var",ref:`documents.${N.key}`},"w6w-expr-chip-var","▦",_.length>0);return n.jsxs(b.Fragment,{children:[_.length>0?n.jsxs("div",{className:"w6w-exprmodal-source-row",children:[ve,n.jsx(Lt,{count:_.length,open:oe,onToggle:()=>z(J)})]}):ve,_.length>0&&oe&&n.jsx("div",{className:"w6w-exprmodal-subsources",children:_.map(be=>{const re=`documents.${N.key}.${be.key}`;return n.jsxs("div",{className:"w6w-exprmodal-subsource-row",children:[ne(be.key,{kind:"var",ref:re},"w6w-expr-chip-var","·"),!w&&n.jsx("button",{type:"button",className:"w6w-exprmodal-render-btn","data-testid":"expr-insert-render",title:`Insert ${re} and render its {{ }} placeholders`,"aria-label":`Insert ${re} and render its {{ }} placeholders`,onClick:()=>A({kind:"render",ref:re}),children:"▤"})]},re)})})]},N.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:()=>se("secret"),children:"+ Add"}),children:[ue.length===0&&n.jsx("span",{className:"w6w-expr-menu-empty",children:"No secrets"}),ue.map(N=>ne(N,{kind:"secret",ref:N},"w6w-expr-chip-secret","🔒"))]})]}),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:k,height:"100%",minHeight:"0px","aria-label":"Compose JSON",placeholder:h?'{ "region": "us", "template": "{{ documents.welcome }}" }':'{ "key": "{{ nodes.step_1.output }}" }',onCreateEditor:N=>{E.current=N}})})]}),n.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ",h?" — the state each run starts with, against the sample values":" — live preview against the sample values"]})]}),j&&n.jsx("span",{className:"w6w-muted w6w-small",role:"alert","data-testid":"expr-json-problem",children:j}),n.jsx(de.Copyable,{value:q??"",label:"Copy result",children:n.jsx("pre",{className:"w6w-exprmodal-result","data-testid":"expr-json-result",children:q})})]})]}),!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:H,className:`w6w-exprmodal-chips${t?" is-masked":""}${$.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":R.error!==null,"aria-describedby":R.error?"expression-problem":void 0,spellCheck:!1,onInput:()=>{const N=H.current;N&&Lr(N,{renderToggle:!0}),Q()},onDoubleClick:N=>{const _=N.target;if(_.closest("[data-x]")||_.closest("[data-render-toggle]"))return;const J=_.closest(".w6w-expr-chip");if(!J)return;N.preventDefault();const oe=Mr(J);if(oe){const ve=oe.ownerDocument,be=ve.createRange();be.setStartAfter(oe),be.collapse(!0);const re=ve.getSelection();re==null||re.removeAllRanges(),re==null||re.addRange(be)}Q()},onBlur:()=>{const N=H.current;N&&Z(le.serializeTemplate(Wt(N)),{restoreFocus:!1})},onPaste:N=>{var J;N.preventDefault();const _=H.current;_&&(Fr(_,((J=N.clipboardData)==null?void 0:J.getData("text/plain"))??"",{renderToggle:!0}),Q())},onClick:N=>{var ve;const _=N.target,J=_.closest("[data-x]");if(J){N.preventDefault(),(ve=J.closest(".w6w-expr-chip"))==null||ve.remove(),Q();return}const oe=_.closest("[data-render-toggle]");if(oe){N.preventDefault();const be=oe.closest(".w6w-expr-chip");if(be){const re=be.getAttribute("data-ref")??"",Te=be.getAttribute("data-kind")==="render"?"var":"render";be.replaceWith(zt(be.ownerDocument,{kind:Te,ref:re},{renderToggle:!0}))}Q()}},onKeyDown:N=>{if(N.key!=="Enter"||(N.preventDefault(),!s))return;const _=H.current;_&&(Nn(_,_.ownerDocument.createTextNode(`
|
|
12
|
+
`)),Fs(_),Q())}}),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."]}),R.error&&n.jsx("span",{id:"expression-problem",role:"alert",className:"w6w-error",children:R.error})]}),We.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"]})]}),We.map(N=>n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:N}),n.jsx("input",{type:"text",value:O[N]??Ft[N]??"",placeholder:"sample value",onChange:_=>K(J=>({...J,[N]:_.target.value}))})]},N))]}),n.jsxs("div",{className:"w6w-exprmodal-preview w6w-exprmodal-result-pane",children:[n.jsxs("span",{className:"w6w-exprmodal-pane-label",children:["Result",n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ","— live preview against the sample values"]})]}),n.jsx(de.Copyable,{value:B,readOnly:!0,children:n.jsx("pre",{className:"w6w-exprmodal-result",children:B||" "})}),fe.length>0&&n.jsx("span",{className:"w6w-muted w6w-small","data-testid":"expr-result-source",children:fe.join(" · ")})]})]})]}),G==="var"&&o.createVar&&n.jsx(Fo,{kind:"var",onCreate:o.createVar,onClose:Y}),G==="secret"&&o.createSecret&&n.jsx(Fo,{kind:"secret",onCreate:o.createSecret,onClose:Y})]})}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 Lt({count:e,open:t,onToggle:s}){return n.jsxs("button",{type:"button",className:"w6w-exprmodal-toggle-btn","data-testid":"expr-toggle-fields","aria-expanded":t,title:t?"Hide fields":"Show fields",onClick:s,children:[e," ",e===1?"field":"fields"," ",t?"⌄":"›"]})}const zl=[["app","App"],["version","App version"],["action","Action"],["connectionId","Connection ID"],["subscriptionId","Subscription ID"],["url","Webhook URL"]],Kl=new Set(["app","version","action","connectionId"]);function Fo({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 Gl(e,t){return t?e.filter(s=>s.id!==t):e}const is=b.createContext({});function Yl({value:e,children:t}){const s=b.useContext(is),o=b.useMemo(()=>({...s,...e}),[s,e]);return n.jsx(is.Provider,{value:o,children:t})}function Xe(){return b.useContext(is)}function Kt({value:e,onChange:t,placeholder:s,masked:o,multiline:r,readOnly:a,options:i,"aria-label":l}){const[u,c]=b.useState(()=>es(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),k=b.useRef(null),E=b.useRef(null),S=Xe(),v={...S,...i??{}},j=S.sealSecret;b.useLayoutEffect(()=>{const $=k.current;!$||p||(_r($,d),(x.current||$.ownerDocument.activeElement===$)&&($.focus(),Ls($),x.current=!1))},[f,p]);const C=()=>{const $=k.current;if(!$)return;const T=Wt($);c(D=>({...D,parts:T}));const R=Dt(T,v);t(dn(R.parts))},P=async $=>{if(!j)return!1;h(!0);try{const T=await j($);return x.current=!1,c({parts:[],sealed:T}),m(R=>R+1),t(T),!0}catch{return!1}finally{h(!1)}},q=$=>{var D;if(g||!o||a||w)return;const T=$.relatedTarget;if(T&&((D=E.current)!=null&&D.contains(T)))return;const R=dn(d);typeof R=="string"&&R!==""&&!ot(R)&&P(R)},I=$=>{if(o&&typeof $=="string"&&$.trim()!==""&&!ot($)){P($);return}x.current=!1,c(es($)),m(T=>T+1),t($)};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($=>$+1),t("")},children:"Replace"})]}):n.jsxs("div",{className:"w6w-expr",ref:E,onBlur:q,children:[n.jsxs("div",{className:"w6w-expr-field",children:[n.jsx("div",{ref:k,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 $=k.current;$&&Lr($),C()},onPaste:$=>{var R;$.preventDefault();const T=k.current;T&&(Fr(T,((R=$.clipboardData)==null?void 0:R.getData("text/plain"))??""),C())},onClick:$=>{var R;const T=$.target.closest("[data-x]");T&&($.preventDefault(),(R=T.closest(".w6w-expr-chip"))==null||R.remove(),C())},onDoubleClick:$=>{const T=$.target;if(T.closest("[data-x]"))return;const R=T.closest(".w6w-expr-chip");if(!R)return;$.preventDefault();const D=Mr(R);if(D){const W=D.ownerDocument,H=W.createRange();H.setStartAfter(D),H.collapse(!0);const L=W.getSelection();L==null||L.removeAllRanges(),L==null||L.addRange(H)}C()},onKeyDown:$=>{if($.key!=="Enter"||($.preventDefault(),!r))return;const T=k.current;T&&(Nn(T,T.ownerDocument.createTextNode(`
|
|
13
|
+
`)),Fs(T),C())}}),!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(en,{value:dn(d),masked:o,multiline:r,options:v,fieldLabel:l,onSave:I,onClose:()=>y(!1)})]})}const Xl=/\{\{\s*([^{}]*?)\s*\}\}/g;function Dr(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(`
|
|
14
|
+
`,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]===`
|
|
15
|
+
`)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(Xl)){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 Zl=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$-]*|\[\d+\]|\["[^"\\]*"\]|\['[^'\\]*'\])*$/,Ql=/\.([A-Za-z_$][\w$-]*)|\[(\d+)\]|\["([^"\\]*)"\]|\['([^'\\]*)'\]/g,ec={nodes:["run","nodes"],steps:["run","nodes"],trigger:["run","trigger"],foreach:["run","foreach"],state:["state"],var:["state"],vars:["state"],const:["consts"],consts:["consts"]};function fn(e,t="javascript"){var u;const s=e.trim();if(!Zl.test(s))return null;const o=((u=/^[A-Za-z_$][\w$]*/.exec(s))==null?void 0:u[0])??"",r=ec[o];if(!r)return null;const a=[...r.slice(1)];for(const c of s.slice(o.length).matchAll(Ql))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 tc(e,t="javascript"){const s=t==="python";let o="",r=0,a=0,i=0;for(const l of Dr(e,t)){const u=fn(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 nc({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 v=l.current;if(!v){i(t+S);return}v.dispatch(v.state.replaceSelection(S)),v.focus()},w=S=>{const v=lt(S);if(v!==null){const j=fn(v,s);j&&m(j);return}S===void 0||S===""||m(JSON.stringify(S,null,2).replace(/"\{\{\s*([^{}"]*?)\s*\}\}"/g,(j,C)=>fn(C,s)??j))},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)),k=f?"#":"//";return n.jsxs("div",{className:"w6w-field w6w-script-code",children:[n.jsxs("span",{children:[o,r]}),n.jsx(Rs,{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 v=fn(`nodes[${JSON.stringify(S.id)}].output`,s)??"";return n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Insert ${v}`,onClick:()=>m(v),children:n.jsx("code",{children:S.id})},S.id)}),n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:"Pick a step field, variable or constant to insert as code","aria-label":`Insert a value into ${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,v])=>`${S.padEnd(x)} ${k} ${v}`).join(`
|
|
16
|
+
`)}),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(en,{mode:"json-binding",value:void 0,jsonValue:void 0,options:d,fieldLabel:o,whole:!0,onSaveJson:w,onClose:()=>c(!1)})]})}function _n(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(..._n(s.children));return t}function Wr(e){return ot(e)||at(e)?!0:typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,"$")}function kn(e){var t;return((t=e.config)==null?void 0:t.allowCustom)===!0}function ls(e){return _n(e).filter(t=>On(t.options))}function Ms(e){return On(e.options)?e.options.refreshOn??[]:[]}function cs(e,t){const s={},o=[];for(const r of _n(e)){if(r.type==="section")continue;const a=t[r.key]!==void 0?t[r.key]:r.default;a!==void 0&&(Wr(a)?o.push(r.key):s[r.key]=a)}return{form:s,unresolved:o}}function sc(e,t,s,o,r){const{form:a,unresolved:i}=cs(e,t),l=new Set(i),u=ls(e).filter(d=>{const p=Ms(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=cs(e,r??{}).form),c}function Lo(e,t,s){return JSON.stringify([e.appId,e.version??null,e.actionKey,e.connectionId??null,t.key,Ms(t).map(o=>s[o]??null)])}function Mo(e){return!(On(e.options)&&e.options.cache==="none")}function oc(e,t){return e.some(s=>t.includes(s))}function rc(e,t,s,o){var l;if(!o.connectionId)return{reason:"no-connection",hint:"Connect an account to load choices"};const r=new Set(cs(t,s).unresolved),a=Ms(e).find(u=>r.has(u));return a===void 0?null:{reason:"unresolved-dependency",hint:`Options unavailable while ${((l=_n(t).find(u=>u.key===a))==null?void 0:l.label)??a} is an expression`}}function Do(e,t,s){return e==null||e===""?{action:"keep"}:Wr(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 ac(e,t,s,o){var k;const r=(k=Mt())==null?void 0:k.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,v,j,C)=>{const{params:P,values:q,dynamic:I,resolve:$}=u.current,T=C??q;if(!I||!$||!I.connectionId)return;const R=sc(P,T,E,S,v);if(!R)return;const D=new Map(ls(P).map(M=>[M.key,M])),W=[],H={},L=[],O=I.appName??I.appId,K=(M,te)=>{const Q=D.get(M);if(!Q)return;Do(T[M],te,{allowCustom:kn(Q),reason:E,appLabel:O}).action==="clear"&&W.push(M)};for(const M of R.fields){if(j!==void 0&&M!==j)continue;const te=D.get(M);if(!te)continue;const Q=j===void 0&&Mo(te)?c.current.get(Lo(I,te,R.form)):void 0;Q?(H[M]={options:Q,loading:!1},K(M,Q)):L.push(M)}const G=(M=!1)=>{if(W.length===0)return;const te={...M?T:u.current.values};for(const Q of W)delete te[Q];u.current.onChange(te)};if(Object.keys(H).length>0&&l(M=>({...M,...H})),L.length===0){G(!0);return}for(const M of d.current)oc(M.fields,L)&&M.controller.abort();const se=new AbortController,F={fields:L,controller:se};d.current=[...d.current.filter(M=>!M.controller.signal.aborted),F],l(M=>{var Q;const te={...M};for(const A of L)te[A]={options:(Q=M[A])==null?void 0:Q.options,loading:!0};return te});const X={...R,fields:L,connectionId:I.connectionId,...I.version!==void 0?{version:I.version}:{}},z=M=>{d.current=d.current.filter(te=>te!==F),l(te=>({...te,...M}))};Promise.resolve().then(()=>$(I.appId,I.actionKey,X,{signal:se.signal})).then(M=>{var Q;if(se.signal.aborted)return;const te={};for(const A of L){const U=(Q=M==null?void 0:M.fields)==null?void 0:Q[A],Z=D.get(A);if(!U||!Z)te[A]={loading:!1};else if(U.error)te[A]={loading:!1,error:U.error};else{const ae=Array.isArray(U.options)?U.options:[];te[A]={loading:!1,options:ae},Mo(Z)&&c.current.set(Lo(I,Z,R.form),ae),K(A,ae)}}z(te),G()}).catch(M=>{if(se.signal.aborted)return;const te=M instanceof Error?M.message:String(M),Q={};for(const A of L)Q[A]={loading:!1,error:te||"Request failed"};z(Q)})},[]),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 v=m.current.get(E)??u.current.values;m.current.delete(E),p("change",[E],v,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 v=u.current.values;JSON.stringify(S[E])!==JSON.stringify(v[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 v of ls(e)){const j=rc(v,e,t,s);if(j){E[v.key]={loading:!1,hint:j.hint};continue}const C=i[v.key]??{loading:!0},P={...C};if(C.options){const q=Do(t[v.key],C.options,{allowCustom:kn(v),reason:"init",appLabel:S});q.action==="flag"&&(P.notInList=q.message)}E[v.key]=P}return E},[a,s,e,t,i]),commit:w,focus:h,blur:g,retry:y}}function tn(e,t){return e.hidden===!0?!1:e.showIf?le.matchesParamCondition(e.showIf,t):!0}function Et(e){const t=[];for(const s of e)t.push(s),s.type==="section"&&s.children&&t.push(...Et(s.children));return t}function Gt(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 qr(e,t,s,o){const r=a=>a.type==="section"?n.jsx(ic,{param:a,effective:s,renderOne:r},a.key):a.repeat&&a.type!=="array"?n.jsx(dc,{param:a,value:e[a.key],onChange:t,readOnly:o},a.key):a.type==="group"&&a.children&&a.children.length>0?n.jsx(uc,{param:a,value:e[a.key],onChange:t,effective:s,readOnly:o},a.key):n.jsx(fc,{param:a,value:e[a.key],onChange:t,effective:s,readOnly:o},a.key);return r}const Fn=b.createContext(null);function Le({params:e,values:t,onChange:s,readOnly:o,dynamic:r}){const a=ac(e,t,r,s),i=Et(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=>tn(m,l)).map(m=>le.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===us||pc.includes(y))&&(h[g.key]=w==="python"?us: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=qr(t,p,l,o);return n.jsx(Fn.Provider,{value:a,children:n.jsxs("div",{className:"w6w-stack",children:[Gt(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:Gt(d,f)})]})]})})}function ic({param:e,effective:t,renderOne:s}){const o=(e.children??[]).filter(r=>tn(r,t)).map(r=>le.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:Gt(o,s)})]}):e.layout==="row"?n.jsx("div",{className:"w6w-field-row",children:o.map(s)}):n.jsx("div",{className:"w6w-stack",children:Gt(o,s)})}const lc=new Set(["string","text","number","boolean","select"]);function cc(e){return e.length>0&&e.every(t=>lc.has(t.type)&&!t.children)}function uc({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=Et(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=>tn(f,c)).map(f=>le.effectiveParam(f,c)),p=qr(i,l,c,r);return n.jsx(Fn.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:Gt(d,p)})]})})}function dc({param:e,value:t,onChange:s,readOnly:o}){if(e.type==="group"){const a=e.children??[];if(!cc(a))return n.jsx(Ds,{param:e,value:t,onChange:s,readOnly:o});const i={...e,item:{type:"object",fields:a}};return n.jsx(ds,{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(ds,{param:r,value:t,onChange:s,readOnly:o})}const us=`# Runs as a function body. Return the step's output.
|
|
17
|
+
return input`,pc=["// 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 fc(e){const t=b.useContext(Fn),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(hc,{...e})})}function hc({param:e,value:t,onChange:s,effective:o,readOnly:r}){var S,v,j,C,P,q;const a=(S=Mt())==null?void 0:S.listModelRoutes,i=(v=Mt())==null?void 0:v.listDataStores,l=(j=Mt())==null?void 0:j.listAgents,u=(C=Mt())==null?void 0:C.listDataStoreEntries,c=Es(),d=b.useContext(Fn),p=d==null?void 0:d.fields[e.key],f=(I,$)=>{s(I,$),d==null||d.commit(I,$)},m=s,w=e.label??e.key,h=e.required&&e.type!=="boolean"?" *":"",g=b.useId();if(e.type==="boolean"){const I=!!(t??e.default??!1);return n.jsx($e,{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:I,disabled:r,onChange:$=>f(e.key,$.target.checked)})})}if(e.type==="json"||e.type==="group")return n.jsx(Ds,{param:e,value:t,onChange:m,readOnly:r});if(e.type==="code"){const I=o==null?void 0:o("language"),$=I==="python"||I==="javascript"||I==="typescript"?I:void 0,T=$==="python"?us:e.default,R=t??T??"";return e.scriptReads?n.jsx(nc,{param:e,value:String(R),language:I==="python"?"python":"javascript",label:w,req:h,readOnly:r,onChange:D=>m(e.key,D)}):n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[w,h]}),n.jsx(Rs,{value:String(R),readOnly:r,minHeight:"180px",language:$,"aria-label":`${e.key} code`,onChange:D=>m(e.key,D)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}if(e.type==="model-route"&&a)return n.jsx(wc,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,listModelRoutes:a,project:c});if(e.type==="agent"&&l)return n.jsx(mc,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,listAgents:l});if(e.type==="data-store"&&i)return n.jsx(bc,{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(vc,{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(Rc,{param:e,value:t,onChange:m,readOnly:r});if(e.type==="text"||(P=e.config)!=null&&P.multiline){const I=t??e.default??"";return n.jsx($e,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,children:n.jsx("textarea",{rows:3,value:String(I),readOnly:r,"aria-label":w,onChange:$=>m(e.key,$.target.value)})})}if(e.type==="multiselect")return n.jsx(jc,{param:e,value:t,onChange:f,readOnly:r});if(e.type==="array")return n.jsx(ds,{param:e,value:t,onChange:m,readOnly:r});if(d&&p&&!p.hint)return n.jsx(Wo,{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&&kn(e))return n.jsx(Wo,{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 I=!e.required&&e.default===void 0&&typeof e.placeholder=="string"&&e.placeholder?e.placeholder:void 0,$=t??e.default??(I!==void 0?"":(q=e.options[0])==null?void 0:q.value)??"",T=e.type==="number";return n.jsx($e,{param:e,value:t,onChange:m,readOnly:r,label:w,req:h,children:n.jsxs("select",{value:String($),disabled:r,"aria-label":w,onChange:R=>{const D=R.target.value;I!==void 0&&D===""?f(e.key,void 0):f(e.key,T?Number(D):D)},children:[I!==void 0&&n.jsx("option",{value:"",children:I}),e.options.map(R=>n.jsx("option",{value:String(R.value),children:R.label},String(R.value)))]})})}if(e.type==="secret"){const I=t??e.default;return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{children:[w,h]}),n.jsx(Kt,{value:I,masked:!0,readOnly:r,"aria-label":w,onChange:$=>m(e.key,$)}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint})]})}const x=e.type==="number"?"number":"text",k=t??e.default??"",E=typeof k=="object"&&k!==null?JSON.stringify(k):String(k??"");return n.jsxs($e,{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:I=>m(e.key,e.type==="number"?Number(I.target.value):I.target.value)}),(p==null?void 0:p.hint)&&n.jsx("span",{className:"w6w-hint",children:p.hint})]})}function Wo({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($e,{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:!kn(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 wc({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($e,{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 mc({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($e,{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 bc({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($e,{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 yc=25,gc=200,qo=60;function xc(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>qo&&(t=`${t.slice(0,qo-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 vc({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 k=c.trim(),E=setTimeout(()=>{Promise.resolve().then(()=>l(i,{project:u,prefix:k===""?void 0:k,limit:yc,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))})},k===""?0:gc);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($e,{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:xc(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 $e({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=ot(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(Kt,{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(en,{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 Ds({param:e,value:t,onChange:s,readOnly:o,headerActions:r,onValidityChange:a}){var q;const i=lt(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??[],k=(((q=y.stateShape)==null?void 0:q.fields.length)??0)>0;b.useEffect(()=>{if(l)return;let I;try{I=c.trim()===""?void 0:JSON.parse(c)}catch{I=void 0}JSON.stringify(I)!==JSON.stringify(u)&&(d(u===void 0?"":JSON.stringify(u,null,2)),f(!1))},[u,e.key,l]);const E=I=>{d(I)},S=I=>{f(!1),a==null||a(!0),s(e.key,I)},v=({valid:I,error:$})=>{if(a==null||a(I||$==="Empty"),!I&&$==="Empty"){f(!1),s(e.key,void 0);return}f(!I)},j=()=>{const I=Bl(c);I&&(f(!1),s(e.key,I))},C=e.label??e.key,P=()=>{let I;try{I=c.trim()===""?void 0:JSON.parse(c)}catch{I=void 0}s(e.key,I)};return n.jsxs("div",{className:"w6w-field",children:[n.jsxs("span",{className:"w6w-field-labelrow",children:[n.jsxs("span",{children:[C,e.required?" *":""]}),r,!l&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-btn-sm",title:"Open in full view","aria-label":`Open ${C} in full view`,onClick:()=>w(!0),children:n.jsx(de.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:ft(i)}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-chip-x","aria-label":`Remove the reference from ${C}`,style:{border:0,padding:0,font:"inherit"},onClick:P,children:"×"})]})}),!o&&n.jsx("button",{type:"button",className:"w6w-expr-edit",title:"Edit expression — browse step outputs, metadata & variables","aria-label":`Edit expression for ${C}`,onClick:()=>g(!0),children:"ƒx"})]})})}):n.jsx(ze,{value:c,onChange:E,onBlur:j,readOnly:o,minHeight:"34px",maxHeight:"260px","aria-label":`${e.key} JSON`,onValidChange:S,onValidityChange:v,overlay:o?void 0:n.jsx("button",{type:"button",className:"w6w-expr-fx",title:"Use an expression","aria-label":`Use an expression for ${C}`,onClick:()=>g(!0),children:"ƒx"})}),h&&n.jsx(en,{mode:"json-binding",value:void 0,jsonValue:t,options:y,fieldLabel:C,whole:e.whole,onSaveJson:I=>s(e.key,I),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||k)&&n.jsxs("div",{className:"w6w-seed-chips w6w-json-quickbind",children:[k&&n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${C} to {{ state }}, the run state upstream steps wrote`,onClick:()=>s(e.key,"{{ state }}"),children:n.jsx("code",{children:"state"})}),x.length>0&&n.jsx("span",{className:"w6w-muted w6w-small",children:"Use the output of"}),x.map(I=>n.jsx("button",{type:"button",className:"w6w-chip w6w-seed-chip",title:`Bind ${C} to {{ nodes.${I.id}.output }}`,onClick:()=>s(e.key,`{{ nodes.${I.id}.output }}`),children:n.jsx("code",{children:I.id})},I.id))]}),e.hint&&n.jsx("span",{className:"w6w-hint",children:e.hint}),m&&!l&&n.jsxs(ke,{title:C,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:v})}),p&&n.jsx("span",{className:"w6w-hint",style:{color:"var(--w6w-danger)"},children:"Invalid JSON"})]})]})}function jc({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 k;return((k=r.find(E=>String(E.value)===String(x)))==null?void 0:k.label)??String(x)},p=x=>s(e.key,a?x.join(","):x),f=x=>{if(!x||u.has(x))return;const k=r.find(E=>String(E.value)===x);p([...l,k?k.value:x])},m=x=>p(l.filter(k=>String(k)!==String(x))),w=typeof e.placeholder=="string"&&e.placeholder?e.placeholder:"Select…",h=e.label??e.key,g=e.required?" *":"";return n.jsx($e,{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(k=>String(k.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:k=>k.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 Nc(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 kc({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(de.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 Sc({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(kc,{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 ds({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&&!Nc(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(Sc,{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 Cc=["string","number","boolean","json"],Ac=[];function Sn(e,t=[]){return Array.isArray(e)?e.every(s=>s&&typeof s=="object"&&typeof s.key=="string")?e:null:!e||typeof e!="object"||ot(e)||lt(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 Ec(e){const t=Array.isArray(e)?Sn(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 Uo(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 Vo(e){return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}function Ho(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 Tc({param:e,value:t,label:s,onChange:o,readOnly:r}){const[a,i]=b.useState(null),l=()=>i(Ho(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($e,{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:Ho(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(de.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 Rc({param:e,value:t,onChange:s,readOnly:o}){const r=t??e.default??Ac,a=b.useMemo(()=>Ec(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=Sn(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(Ds,{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&&Sn(S)===null&&!lt(S)&&!ot(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),k=(E,S)=>x(w.map((v,j)=>j===E?{...v,...S}:v));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:v=>k(S,{key:v.target.value})}),n.jsx("select",{value:E.type,"aria-label":"Variable type",disabled:o,onChange:v=>{const j=v.target.value;k(S,{type:j,value:Uo(j,Vo(E.value))})},children:Cc.map(v=>n.jsx("option",{value:v,children:v},v))}),E.type==="json"?n.jsx(Tc,{param:e,value:E.value,label:E.key||"value",onChange:v=>k(S,{value:v}),readOnly:o}):n.jsx($e,{bare:!0,param:e,value:E.value,onChange:(v,j)=>k(S,{value:j}),readOnly:o,label:E.key||"value",req:"",children:E.type==="boolean"?n.jsxs("select",{value:E.value===!0?"true":"false",disabled:o,onChange:v=>k(S,{value:v.target.value==="true"}),children:[n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}):n.jsx("input",{type:E.type==="number"?"number":"text",placeholder:"value",value:Vo(E.value),readOnly:o,onChange:v=>k(S,{value:Uo(E.type,v.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((v,j)=>j!==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 Ur(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 hn({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(Pc,{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 Oc=/(^|_)(private_key|secret|password|token)$/i,Bo=["client_email","client_id","project_id","private_key_id","private_key"],Ic=["type","universe_domain"];function $c(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=Bo.indexOf(o);return r===-1?Bo.length:r};return Object.entries(t).filter(([o,r])=>typeof r=="string"&&r!==""&&!/^https?:\/\//.test(r)&&!Ic.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:Oc.test(o)}))}function Pc({field:e,value:t,onChange:s}){const o=b.useRef(null),r=t.trim()===""?null:$c(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 Vr({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} · ${d.accessScope==="user"?"Only me":"This account"}`};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 Hr(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 Br(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 Jr=b.createContext(void 0),_c="width=560,height=720,menubar=no,toolbar=no,location=no";function zr(e){return new Promise((t,s)=>{const o=window.open(e,"w6w-oauth",_c);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 Fc=new Set(["checkbox","radio","button","submit","reset","file","range","color","image","hidden","date","datetime-local","month","week","time"]);function Lc(e){return e.closest('[contenteditable]:not([contenteditable="false"])')!==null}function Kr(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"&&(Lc(o)||o.tagName==="INPUT"&&Fc.has(o.type)||(s.preventDefault(),e()))}}}function Ws(e){const t=Ne(),s=b.useContext(Jr),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(Mc,{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(st,{onSelectApp:a,theme:e.theme,searchPlaceholder:"Search apps to connect…",categoryFilter:!0})})})}function Mc({app:e,onCreated:t,onClose:s,onCreateSharedCredential:o}){var ge;const r=Ne(),[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),[k,E]=b.useState(null),[S,v]=b.useState(""),[j,C]=b.useState({}),[P,q]=b.useState("account"),[I,$]=b.useState(!1);b.useEffect(()=>{let V=!1;return i(null),r.getAppAuth(e.id).then(ue=>!V&&i(ue.filter(ye=>ye.available!==!1))).catch(ue=>!V&&w(ue.message)),()=>{V=!0}},[r,e.id]);const T=a??[],R=T.find(V=>V.key===l)??T.find(V=>V.default===!0)??T[0],D=(R==null?void 0:R.fields)??[],W=(R==null?void 0:R.type)==="oauth2",H=R==null?void 0:R.serviceAccount,L=(R==null?void 0:R.accepts)??(H==null?void 0:H.accepts)??[],O=r.listCredentials,K=!W&&L.length>0&&typeof O=="function",G=(y??[]).filter(V=>V.status==="active"&&!V.private&&V.accessScope!=="user"&&L.includes(V.contract)),se=(R==null?void 0:R.userScope)===!0&&!W&&(R==null?void 0:R.key)!=="zero-credential",F=se&&P==="user",X=F?"new":k??(G.length>0?"existing":"new"),z=G.some(V=>V.id===S)?S:((ge=G[0])==null?void 0:ge.id)??"",M=K&&H?Hr(H):[],te=(R==null?void 0:R.key)??"";b.useEffect(()=>{if(!K||!O)return;let V=!1;return x(null),E(null),O.call(r,{appId:e.id,authKey:te}).then(ue=>!V&&x(ue)).catch(()=>!V&&x([])),()=>{V=!0}},[r,e.id,K,te,O]);const Q=(R==null?void 0:R.key)==="zero-credential",A=V=>V===void 0||V==="",U=!W&&!Q&&(K?y===null||M.some(V=>V.required&&A(j[V.key]))||(X==="existing"?z==="":D.some(V=>V.required&&A(p[V.key]))):D.some(V=>V.required&&A(p[V.key]))),Z=!R||!W&&!Q&&U||h;async function ae(){if(R){w(null),g(!0);try{if(Q)t({connectionId:`zerocred:${e.id}`});else if(W){const{authorizationUrl:V}=await r.startAppOAuthFlow(e.id,R.key,{displayName:c||void 0}),{connectionId:ue}=await zr(V);t({connectionId:ue})}else if(K&&X==="existing"){const V=Br(M,j),ue={authKey:R.key,credentialId:z,...V?{binding:V}:{},...c?{displayName:c}:{}},ye=await r.createConnection(e.id,ue);t({connectionId:ye.id})}else{const V=Ur(D,p);if("error"in V){w(V.error);return}let ue=V.values;if(H){ue={};for(const we of M){const ie=j[we.key];ie==null||ie===""||(ue[we.key]=we.key==="delegatedUser"?String(ie):ie)}Object.assign(ue,p)}const ye=await r.createConnection(e.id,{authKey:R.key,credential:ue,displayName:c||void 0,...F?{accessScope:"user"}:{}});t({connectionId:ye.id})}}catch(V){w(V.message)}finally{g(!1)}}}const Y=Kr(ae,{enabled:!Z});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&&T.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."}),T.length>1&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Auth method"}),n.jsx("select",{value:(R==null?void 0:R.key)??"",onChange:V=>{u(V.target.value),f({}),C({}),E(null),q("account"),w(null)},children:T.map(V=>n.jsxs("option",{value:V.key,children:[V.displayName??V.key," (",V.type,")"]},V.key))})]}),R&&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",...Y})]}),R.description&&n.jsx("p",{className:"w6w-muted w6w-small",children:R.description}),R.setup&&R.setup.length>0?n.jsx(qc,{steps:R.setup}):null,Q?null:W?n.jsxs("p",{className:"w6w-muted w6w-small",children:["You'll be redirected to ",n.jsx("strong",{children:R.displayName??R.key})," to authorize this connection."]}):K?n.jsxs(n.Fragment,{children:[!F&&n.jsx(Vr,{credentials:G,mode:X,onModeChange:E,selectedId:z,onSelect:v,emptyHint:"No shared credentials of this type yet.",onCreateShared:o?()=>{s(),o()}:void 0}),X==="existing"&&G.length>0&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Reusable credential · This account"}),H&&H.scopes.length>0&&n.jsx(Uc,{scopes:H.scopes}),M.length>0&&n.jsx(hn,{fields:M,values:j,onChange:C,enterSubmitProps:Y}),X==="new"&&n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"w6w-muted w6w-small",children:["Saved for this app only. One connection ·"," ",F?"Only me":"This account"]}),n.jsx(hn,{fields:D,values:p,onChange:f,enterSubmitProps:Y})]})]}):n.jsx(hn,{fields:D,values:p,onChange:f,enterSubmitProps:Y})]}),se&&n.jsx(Wc,{open:I,onToggle:()=>$(V=>!V),owner:P,onOwnerChange:q}),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:Z,onClick:ae,children:h?Q?"Saving…":W?"Waiting for authorization…":"Saving…":Q?"Use this":W?`Sign in with ${(R==null?void 0:R.displayName)??(R==null?void 0:R.key)??"provider"}`:"Save connection"})]})]})}const Dc=[{value:"account",label:"This account",hint:"Everyone authorized in the account can use it."},{value:"user",label:"Only me",hint:"Only you can use it. Others in the account cannot."}];function Wc({open:e,onToggle:t,owner:s,onOwnerChange:o}){return n.jsxs("div",{className:"w6w-advanced","data-testid":"connection-advanced",children:[n.jsxs("button",{type:"button",className:"w6w-advanced-toggle","aria-expanded":e,"aria-controls":"w6w-connection-advanced-panel",onClick:t,children:["Advanced",!e&&s==="user"&&n.jsx("span",{className:"w6w-muted",children:" · Only me"})]}),e&&n.jsxs("div",{id:"w6w-connection-advanced-panel",className:"w6w-advanced-panel",role:"radiogroup","aria-label":"Who can use it",children:[n.jsx("span",{className:"w6w-advanced-label",children:"Who can use it"}),Dc.map(r=>n.jsxs("label",{className:"w6w-radio",children:[n.jsx("input",{type:"radio",name:"w6w-connection-owner",value:r.value,checked:s===r.value,onChange:()=>o(r.value)}),n.jsxs("span",{children:[n.jsx("strong",{children:r.label}),n.jsxs("span",{className:"w6w-muted w6w-small",children:[" ",r.hint]})]})]},r.value))]})]})}function qc({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 Uc({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 Tt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),qs=[["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)"]],cn={"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."},Gr=new Set(qs.map(([e])=>e)),Yr=new Set(["is-true","is-false","has-value","is-empty"]),Vc=new Set(["and","or","xor","!","!!","==","!=",...Gr]);function Jo(e){if(!Tt(e))return!0;const t=Object.keys(e);return!(t.length===1&&Vc.has(t[0]))}function zo(e){return Yr.has(e)}const Ko={...Object.fromEntries(qs),"==":"equals","!=":"does not equal",in:"is in"};function Hc(e){return e.startsWith("not:")?`Not (${Ko[e.slice(4)]??e.slice(4)})`:Ko[e]??e}const Xr=[["and","All of (AND)"],["or","Any of (OR)"],["xor","Exactly one of (XOR)"]],Zr=Object.fromEntries(Xr);function Bc(e){return Zr[e]??e}function Us(e,t=!0){if(!Tt(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&&Jo(r[0]))return{left:r[0],operator:"has-value",right:!0};if(o==="!"&&Array.isArray(r)&&r.length===1){const a=Us(r[0],!1);return a?t&&!a.negated?{...a,negated:!0}:void 0:Jo(r[0])?{left:r[0],operator:"is-empty",right:!0}:void 0}if(!(!Gr.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(!Yr.has(o))return{left:r[0],operator:o,right:r[1]}}}function Jc(e){if(!(!Tt(e)||Object.keys(e).length!==1))return Us(e.$expr)}function zc(e){const t=Jc(e);if(t)return{combinator:"and",rows:[t]};if(!Tt(e)||Object.keys(e).length!==1||!Tt(e.$expr))return;const s=Object.entries(e.$expr);if(s.length!==1)return;const[o,r]=s[0];if(!Object.hasOwn(Zr,o)||!Array.isArray(r)||r.length===0)return;const a=r.map(i=>Us(i));if(!a.some(i=>i===void 0))return{combinator:o,rows:a}}function Go(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 ps(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"?$n(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 Yo(e){return typeof e=="string"?ps(e)===e?e:JSON.stringify(e):Tt(e)?Object.keys(e).length===1&&typeof e.var=="string"?le.serializeTemplate([{kind:"var",ref:e.var}]):le.serializeTemplate([{kind:"expr",expr:e}]):JSON.stringify(e)??""}const Qr={left:"",operator:"is-true",right:!0},Xo={combinator:"and",rows:[Qr]},Kc=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function Ln({values:e,onChange:t,readOnly:s,purpose:o="if"}){const r=Xe(),a=e.condition===void 0?!0:e.condition,i=zc(a),[l,u]=b.useState(!1),[c,d]=b.useState(i??Xo),p=b.useRef(0),[f,m]=b.useState(()=>c.rows.map(()=>p.current++)),w=i!==void 0||typeof a=="boolean",h=Kc(Go(c),a)?c:i??Xo,g=h.rows.map((v,j)=>f[j]??-1-j),y=(v,j=g)=>{d(v),m(j),t({...e,condition:Go(v)})},x=(v,j)=>y({...h,rows:h.rows.map((C,P)=>P===v?{...C,...j}:C)}),k=()=>y({...h,rows:[...h.rows,Qr]},[...g,p.current++]),E=v=>y({...h,rows:h.rows.filter((j,C)=>C!==v)},g.filter((j,C)=>C!==v)),S=h.rows.length>1;return n.jsxs("div",{className:"w6w-condition-editor",children:[l||!w?n.jsx(Le,{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:v=>y({...h,combinator:v.target.value}),children:Xr.map(([v,j])=>n.jsx("option",{value:v,children:j},v))}),h.rows.map((v,j)=>{const C=zo(v.operator);return n.jsxs("div",{className:`w6w-condition-row${S?" w6w-condition-row-removable":""}${C?" w6w-condition-row-boolean":""}`,children:[n.jsxs("label",{className:"w6w-condition-negate",title:"Reverse this condition's result",children:[n.jsx("input",{type:"checkbox","aria-label":`Negate condition ${j+1}`,checked:v.negated??!1,disabled:s,onChange:P=>x(j,{negated:P.target.checked})}),"Not"]}),n.jsx(Kt,{value:Yo(v.left),"aria-label":"Condition field",placeholder:"Field or expression",readOnly:s,onChange:P=>x(j,{left:ps(P)})}),n.jsx("select",{className:"w6w-condition-comparison","aria-label":"Condition comparison",title:cn[v.operator],disabled:s,value:v.operator,onChange:P=>x(j,{operator:P.target.value,right:P.target.value==="is-true"?!0:P.target.value==="is-false"?!1:zo(P.target.value)?!0:C?"":v.right}),children:qs.map(([P,q])=>n.jsx("option",{value:P,title:cn[P],children:q},P))}),!C&&n.jsx(Kt,{value:Yo(v.right),"aria-label":"Condition value",placeholder:"Value or expression",readOnly:s,onChange:P=>x(j,{right:ps(P)})}),S&&!s&&n.jsx("button",{type:"button",className:"w6w-icon-btn w6w-condition-remove",title:"Remove condition","aria-label":`Remove condition ${j+1}`,onClick:()=>E(j),children:n.jsx(de.Icon,{name:"trash",size:14})})]},g[j])}),!s&&n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm w6w-condition-add",onClick:k,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(v=>v.operator))].map(v=>cn[v]?n.jsx("p",{className:"w6w-muted w6w-small",children:cn[v]},v):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(de.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 Gc={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 ea({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:Gc[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 ta({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(ea,{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 Mn(e){return e.$merge!==void 0}function na(e){const t=e.$merge;if(t===void 0)return e;if(!(lt(t)||Ye(t)||$s(t)||typeof t=="string"&&$n(t)))return t&&typeof t=="object"&&!Array.isArray(t)&&!at(t)&&!("$merge"in t)?{...e,...t}:null}function sa(e,t,s=[]){if(Ye(e)||at(e)||Is(e)||$s(e)||e===null||typeof e!="object")return Jt(e,t);const o=r=>sa(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 Vs({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(Le,{params:[{key:"$merge",label:"JSON customization",type:"json",required:!0,default:{},whole:!0}],values:e,onChange:t,readOnly:s}),na(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&&Mn(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 Hs(e){const{label:t,onClick:s,disabled:o,className:r,...a}=e;return n.jsx(Pn,{label:t,onClick:s,disabled:o,className:r,danger:!0,icon:"delete","data-testid":a["data-testid"]})}function oa({values:e,onChange:t,readOnly:s}){const o=Array.isArray(e.routes)?e.routes:jn(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(k=>k.id===y?{...k,...x}:k)),h=(y,x)=>{const k=r.findIndex(v=>v.id===y);if(k<0||x<0||x>=r.length||k===x)return;const E=[...r],[S]=E.splice(k,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:k=>{s||!a||a===y.id||(k.preventDefault(),k.dataTransfer.dropEffect="move",u(y.id))},onDrop:k=>{k.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:k=>{k.dataTransfer.effectAllowed="move",k.dataTransfer.setData("text/plain",y.id);const E=k.currentTarget.closest(".w6w-router-route");E&&k.dataTransfer.setDragImage(E,16,16),i(y.id)},onDragEnd:()=>{i(null),u(null)},onKeyDown:k=>{k.key!=="ArrowUp"&&k.key!=="ArrowDown"||(k.preventDefault(),h(y.id,x+(k.key==="ArrowUp"?-1:1)))},children:n.jsx(de.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:k=>f(k.target.value),onBlur:()=>g(y),onKeyDown:k=>{k.key==="Enter"&&g(y),k.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(de.Icon,{name:"edit",size:12})]})}),n.jsx(Hs,{label:`Remove ${y.label||y.id}`,disabled:s,onClick:()=>m(r.filter(k=>k.id!==y.id))})]}),n.jsx(Ln,{values:{condition:y.condition??!1},onChange:k=>w(y.id,{condition:k.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 ra({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(de.Icon,{name:"edit",size:15})})]}),l&&n.jsx("span",{className:"w6w-hint",role:"alert",style:{color:"var(--w6w-danger)"},children:l})]})}function aa({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(Ln,{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 Yc=["props","code"];function Xc(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ia({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(()=>Zo(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(Zo(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(qn,{view:l,views:[...Yc],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 k=Xc(x);h(k),k&&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(Le,{params:e,values:t,onChange:s,readOnly:r})]})}function Zo(e){return JSON.stringify(e??{},null,2)}const Zc=new Set(["http:","https:","mailto:"]);function Qc(e){try{return Zc.has(new URL(e).protocol)?e:""}catch{return""}}const eu=["img"];function tu({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 la(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 nu({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 Bs({content:e,className:t,copyable:s=!0}){const{frontmatter:o,body:r}=la(e),a=n.jsxs("div",{className:t,children:[(o==null?void 0:o.trim())&&n.jsx(nu,{yaml:o}),n.jsx(hi,{skipHtml:!0,urlTransform:Qc,disallowedElements:eu,unwrapDisallowed:!0,components:{a:tu},children:r})]});return s?n.jsx(de.Copyable,{value:e,label:"Copy Markdown",className:"w6w-copyable--document",children:a}):a}const Qo="w6w-data-table-actions";function su(e,t){return e.render?e.render(t):String(t[e.key]??"")}function ca(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",{className:d.actions?Qo:void 0,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=su(m,d);return n.jsx("td",{className:m.actions?Qo:void 0,style:{textAlign:m.align},children:p!==void 0&&m.link!==!1?n.jsx("a",{className:"w6w-data-table-link",href:p,children:w}):m.actions&&w!==null&&w!==void 0?n.jsx("div",{className:"w6w-data-table-actions-row",children:w}):w},m.key)})},o(d))})})]})})}const ua="default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'";function da(e){return`<!doctype html><meta http-equiv="Content-Security-Policy" content="${ua}">${e}`}function pa({html:e}){return n.jsx("iframe",{title:"HTML preview",className:"w6w-html-preview",sandbox:"",referrerPolicy:"no-referrer",srcDoc:da(e)})}function fa(e){return typeof e=="string"?"string":typeof e=="number"?"number":typeof e=="boolean"?"boolean":"null"}function ou(e){return fa(e)==="string"?JSON.stringify(e):String(e)}function ru(e){return typeof e=="object"&&e!==null}function au(e,t){return`${t} ${e?"item":"key"}${t===1?"":"s"}`}function iu({value:e,expandDepth:t=2}){return n.jsx(ha,{label:void 0,value:e,depth:0,expandDepth:t})}function ha(e){const{label:t,value:s,depth:o,expandDepth:r}=e,a=ru(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:au(i,l.length)})]}),n.jsx("div",{className:"w6w-json-children",children:l.map(([c,d])=>n.jsx(ha,{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":fa(s)}`,children:a?i?"[]":"{}":ou(s)})]})}const fs=262144,lu=/^#{1,6}\s+\S/,cu=/^```/,uu=/^\s*(?:[-*+]|\d+\.)\s+\S/,du=/\[[^\]\n]+\]\(https?:\/\/[^)\s]+\)/;function wa(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(`
|
|
18
|
+
`);return s.some(o=>lu.test(o)||cu.test(o))||s.filter(o=>uu.test(o)).length>=2||du.test(t)?{format:"markdown",text:e}:{format:"text",text:e}}function ma(e){return e.format==="json"?JSON.stringify(e.data,null,2)??"":e.text}function er(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function pu(e){if(!er(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(er)}function fu(e){try{return JSON.stringify(e).length}catch{return Number.POSITIVE_INFINITY}}function hu(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 wu=65536;function Gn(e,t){return e.length>wu?n.jsx("pre",{className:"w6w-result-viewer-text",children:e}):n.jsx(de.CodeBlock,{code:e,language:t,copyable:!1,wrap:!0})}function Ee(e){const{value:t,format:s="auto",maxHeight:o=320,className:r}=e,a=b.useMemo(()=>s==="json"?{format:"json",data:t}:wa(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>fs,y=b.useMemo(()=>a.format!=="json"||!pu(a.data)?null:{table:a.data,tooLarge:fu(a.data)>fs},[a]),x=y!==null&&!y.tooLarge&&u==="table",k=b.useMemo(()=>((y==null?void 0:y.table.columns)??[]).map((C,P)=>({key:`${P}:${C}`,header:C,render:({row:q})=>hu(q[C])})),[y]),E=b.useMemo(()=>((y==null?void 0:y.table.rows)??[]).map((C,P)=>({i:P,row:C})),[y]),S=b.useMemo(()=>{try{return ma(a)}catch{return typeof t=="string"?t:String(t)}},[a,t]);let v;if(a.format==="json"){const C=n.jsx(iu,{value:a.data,expandDepth:d},f);x?v=n.jsx(ca,{columns:k,rows:E,rowKey:P=>String(P.i),className:"w6w-result-viewer-table",testId:"result-viewer-table"}):y!=null&&y.tooLarge?v=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."}),C]}):v=C}else if(a.format==="xml")v=Gn(a.text,"markup");else if(a.format==="text")v=n.jsx("pre",{className:"w6w-result-viewer-text",children:a.text});else{const C=a.format==="html"?"markup":"markdown";g?v=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-muted w6w-small w6w-result-viewer-note",children:"Too large to render — showing source."}),Gn(a.text,C)]}):i==="source"?v=Gn(a.text,C):a.format==="html"?v=n.jsx(pa,{html:a.text}):v=n.jsx(Bs,{content:a.text,copyable:!1})}let j=null;if(a.format==="json"){const C=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;j=n.jsxs("div",{className:"w6w-result-viewer-bar",children:[C,x?null:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{p(Number.POSITIVE_INFINITY),m(P=>P+1)},children:"Expand all"}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>{p(1),m(P=>P+1)},children:"Collapse all"})]})]})}else h&&!g&&(j=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:[j,n.jsx(de.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:v})})]})}function ba(e,t){const s=e.filter(o=>o.appId===Ue);return s.find(o=>o.nodeId===t)??s.find(o=>!o.nodeId)??s[0]??null}const mu=/auth|token|secret|passw|cookie|api[-_]?key|signature|session/i,bu="••••••";function yu(e){const t={};for(const[s,o]of Object.entries(e))t[s]=mu.test(s)?bu:o;return t}const gu=20;function xu({workflowId:e,stepId:t,stepWith:s,readOnly:o,onUse:r,using:a}){const i=Ne(),[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 v=i.listSubscriptionsForWorkflow;if(!v)return;let j=!1;return v(e).then(C=>!j&&u(ba(C,t))).catch(C=>!j&&f({phase:"error",message:C.message})),()=>{j=!0}},[i,e,t]);const g=b.useCallback(v=>{var C;const j=h.current;h.current=null,j&&(j.abort.abort(),v&&((C=i.stopWebhookListen)==null||C.call(i,j.subId,j.sessionId).catch(()=>{})))},[i]);b.useEffect(()=>()=>g(!0),[g]),b.useEffect(()=>{if(p.phase!=="waiting")return;const v=setInterval(()=>w(Date.now()),1e3);return()=>clearInterval(v)},[p.phase]);const y=()=>{const v=i.createSubscription;v&&(d(!0),v(Ue,"webhook",{workflowId:e,connectionId:null,params:s??{}}).then(j=>u(j)).catch(j=>f({phase:"error",message:j.message})).finally(()=>d(!1)))},x=async()=>{var I;const v=i.startWebhookListen,j=i.pollWebhookListen;if(!l||!v||!j)return;g(!0),f({phase:"starting"});let C;try{C=(await v(l.id)).session}catch($){f({phase:"error",message:$.message});return}const P=new AbortController,q={subId:l.id,sessionId:C.id,abort:P};for(h.current=q,w(Date.now()),f({phase:"waiting",session:C});;){let $;try{$=await j(l.id,C.id,{waitSeconds:gu,signal:P.signal})}catch(T){if(h.current!==q)return;h.current=null,f({phase:"error",message:T.message});return}if(h.current!==q)return;if($.status==="captured"&&$.request){h.current=null,f({phase:"captured",session:$,request:$.request});return}if($.status==="expired"){h.current=null,(I=i.stopWebhookListen)==null||I.call(i,l.id,C.id).catch(()=>{}),f({phase:"expired"});return}}},k=()=>{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(de.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:[" ",vu(S)," left"]})]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:k,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(ju,{request:p.request,receivedAt:p.session.receivedAt,readOnly:o,using:a,onUse:()=>r(p.request),stepId:t})]})}function vu(e){const t=Math.floor(e/60);return t>0?`${t}:${String(e%60).padStart(2,"0")}`:`${e}s`}function ju({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(Ee,{value:e.query,maxHeight:120})]}),n.jsx("div",{className:"w6w-testout-label",children:"Headers"}),n.jsx(Ee,{value:yu(e.headers??{}),maxHeight:160}),n.jsx("div",{className:"w6w-testout-label",children:"Body"}),n.jsx(Ee,{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 Js(e){return Array.isArray(e)?e:[]}function zs(e){return e==="object"||e==="array"?"json":e==="number"||e==="boolean"||e==="json"?e:"string"}function Ks(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 Gs(e){return e.filter(t=>typeof t.key=="string"&&t.key.trim()!=="").map(t=>({key:t.key,label:t.key,type:zs(t.type),required:!!t.required}))}function hs(e){const t={};for(const s of e){if(typeof s.key!="string"||s.key.trim()==="")continue;const o=Ks(s.type,s.default);o!==void 0&&(t[s.key]=o)}return t}function ya(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 Nu(e){return Ye(e)||typeof e=="string"&&e.includes("{{")}function Ys(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||at(a)||s.has(r)&&!Nu(a)||(o[r]=a);return o}const ws=new Set;function ga(e){const t=e.then(()=>{},()=>{});return ws.add(t),t.then(()=>ws.delete(t)),e}async function xa(){await Promise.all([...ws])}function va(e,t){const s=Ne(),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),xa().then(()=>{var f;return((f=s.loadTestInputs)==null?void 0:f.call(s,e))??[]}).then(f=>{p||(l(ya(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")&&ga(s.saveTestInput(e,t,p)).catch(f=>{console.error("test input save failed",f)})},[s,e,t]),c=b.useCallback((p,f)=>u(Ys(p,f)),[u]),d=b.useCallback(()=>u({}),[u]);return{loaded:r,supported:o,input:i,save:c,clear:d}}function ja({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 ku=600;function Na({app:e,action:t,fields:s,persist:o,listen:r}){const a=Ne(),i=Es(),l=b.useMemo(()=>Js(s),[s]),u=b.useMemo(()=>Gs(l),[l]),c=u.length>0,[d,p]=b.useState(()=>hs(l)),[f,m]=b.useState(null),w=o==null?void 0:o.workflowId,h=o==null?void 0:o.stepId,g=va(w,h),[y,x]=b.useState(!1),[k,E]=b.useState(!1),[S,v]=b.useState(!w||!h);b.useEffect(()=>{if(!w||!h){v(!0);return}if(!g.loaded)return;if(g.input!==void 0){const X=g.input;Object.keys(X).length>0&&(p(z=>({...z,...X})),x(!0),E(!0)),v(!0);return}let F=!1;return a.listStepTests(w,h).then(X=>{if(F)return;const z=X.length?X[X.length-1]:null;z!=null&&z.with&&(p(M=>({...M,...z.with})),Object.keys(z.with).length>0&&E(!0)),v(!0)}).catch(()=>{F||v(!0)}),()=>{F=!0}},[a,w,h,g.loaded]);const[j,C]=b.useState(0),P=()=>{clearTimeout(I.current),q.current=null,g.clear(),x(!1),p(hs(l)),C(F=>F+1)},q=b.useRef(null),I=b.useRef(void 0),$=b.useRef(()=>{});$.current=()=>{clearTimeout(I.current);const F=q.current;q.current=null,F&&g.save(F,u)},b.useEffect(()=>()=>$.current(),[]);const T=F=>{p(F),!(!w||!h||!S)&&(q.current=F,clearTimeout(I.current),I.current=setTimeout(()=>$.current(),ku))},[R,D]=b.useState(!0),W=R&&Rt(u,d),H=async F=>{const X=F??d;clearTimeout(I.current),q.current=null,o&&g.save(X,u),m({status:"running"});let z;try{const M=await a.invokeAction(e,t,{input:X},{project:i});z={status:"done",value:M.value,logs:M.logs}}catch(M){const te=M;z={status:"error",error:te.message??String(M),errorCode:te.code,logs:te.logs}}if(m(z),o)try{const M=await a.saveStepTest(o.workflowId,o.stepId,{input:o.input,with:X});await a.recordStepTestRun(o.workflowId,o.stepId,{stepTestId:M.id,status:z.status==="done"?"succeeded":"failed",input:o.input,output:z.status==="done"?z.value:void 0,error:z.status==="error"?z.error:void 0})}catch(M){console.error("step test persist failed",M)}},L=f&&f.status!=="running"?f.logs:void 0,O=F=>{const X={...F};p(X),H(X)},K=r&&o&&n.jsx(xu,{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:k,onToggle:F=>E(F.currentTarget.open),children:[n.jsx("summary",{className:"w6w-small",children:"Or test with a sample payload"}),G()]}):G(),se()]});function G(){return n.jsxs("div",{className:"w6w-stack",children:[S?n.jsxs(n.Fragment,{children:[y&&n.jsx(ja,{onClear:P}),n.jsx(ia,{params:u,values:d,onChange:T,onValidityChange:D},j),!c&&n.jsxs("span",{className:"w6w-hint",children:["This trigger declares no fields — provide a sample payload to test with. It becomes the trigger's output state (",n.jsx("code",{children:"input"}),")."]})]}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading saved values…"}),n.jsx("div",{className:"w6w-steptest",children:n.jsxs("div",{className:"w6w-steptest-bar",children:[n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:!S||!W||(f==null?void 0:f.status)==="running",onClick:()=>void H(),children:(f==null?void 0:f.status)==="running"?"Running…":"▶ Test run"}),S&&!W&&n.jsx("span",{className:"w6w-muted w6w-small",children:R?"Fill the required fields to test.":"The payload must be a JSON object to test."})]})})]})}function se(){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(Ee,{value:f.value,maxHeight:220})]}),L&&L.length>0&&n.jsxs("div",{className:"w6w-testout",children:[n.jsx("div",{className:"w6w-testout-label",children:"Console output"}),n.jsx(de.Copyable,{value:L.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:L.join(`
|
|
20
|
+
`)})})]})]})}}const Su=[["s","Seconds"],["m","Minutes"],["h","Hours"],["d","Days"],["w","Weeks"]],Cu=/^(?=\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 ka({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"&&(!Cu.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(Le,{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:Su.map(([f,m])=>n.jsx("option",{value:f,children:m},f))})]})]}):n.jsx(Le,{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 Sa({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:gn.createPortal(n.jsx("div",{ref:o,className:"w6w-flyout",style:{top:r.top,left:r.left,width:r.width},children:s}),i)}function Ca(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)&&Ca(e[r],t[r]))}function Au(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&&Ca(r,o)?s:{...s,data:{...s.data,stepProblems:structuredClone(o)}}})}const Eu={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 Tu(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=Eu[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 Ru(e,t){return(t==null?void 0:t.some(s=>s.code==="unknown_connection"&&e.uses.connection===s.connection))??!1}function tr(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 wn(e,t,s){if(s.type==="update"){const r=wn(e,t,{type:"rename",ref:s.ref,name:s.name}),a=s.name.trim(),i=wn(r.nodes,r.connections,{type:"replace",ref:a,connection:s.connection});return s.nodeIds?wn(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?Yt(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)?Yt(a,s.ref):a)}}}}function Pt(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 Xs(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 Aa(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:Xs(r.uses.app,t);return t={...t,[i]:{app:r.uses.app,connection:r.uses.connection}},s=!0,Yt(r,i)});return s?{...e,nodes:o,connections:t}:e}function Yt(e,t){const{connection:s,...o}=e.uses;return{...e,uses:{...o,connectionRef:t}}}function Ou(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:Xs(e.uses.app,o);return{step:Yt(e,i),connections:{...o,[i]:{app:e.uses.app,connection:t}}}}function mn(e,t,s,o){return t?s.filter(r=>r.uses.app===e&&Pt(r,o)===t):[]}function Ea(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=Pt(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 nr(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 Iu(e,t,s,o,r){const a=new Set(mn(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 Ta=b.createContext(null);function Zs(){return b.useContext(Ta)}function Ra({step:e,conns:t,failed:s=!1,readOnly:o,open:r,onOpenChange:a,anchorRef:i,onChangeConnection:l,onChangeConnectionRef:u,onConnectionCreated:c,createSignal:d}){var q,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:mn(e.uses.app,T.id,w,m)})).sort((T,R)=>+(R.users.length>0)-+(T.users.length>0)),g=Pt(e,m)??(e.uses.connectionRef===void 0?(q=t==null?void 0:t.find(T=>T.builtIn&&T.appId===e.uses.app))==null?void 0:q.id:void 0),y=mn(e.uses.app,g,w,m).filter(T=>T.id!==e.id),[x,k]=b.useState(null),[E,S]=b.useState(!1),v=b.useRef(d);b.useEffect(()=>{const T=v.current;v.current=d,d!==void 0&&T!==void 0&&d>T&&S(!0)},[d]);const j=x||E?(($=(I=i.current)==null?void 0:I.closest("dialog"))==null?void 0:$.parentElement)??document.body:null,C=(T,R)=>{if(!f){if(R&&p&&g){p.setConnections(Iu(e.uses.app,g,T,w,m));const D=w.find(W=>W.id===e.id)??e;D.uses.connectionRef?u(D.uses.connectionRef):l(T)}else{const D=mn(e.uses.app,T,w,m).filter(H=>H.id!==e.id&&H.uses.connectionRef).at(-1),W=Object.entries(m).find(([,H])=>H.app===e.uses.app&&H.connection===T);D!=null&&D.uses.connectionRef?u(D.uses.connectionRef):W?u(W[0]):l(T)}k(null),a(!1)}},P=T=>{f||(a(!1),T!==g&&(y.length>0&&w.some(R=>R.id===e.id)?k(T):C(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…":tr(g,t,s)})}),r&&n.jsx(Sa,{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,R])=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f||!R.connection||!(t!=null&&t.some(D=>D.id===R.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:tr(R.connection??void 0,t,s)})]})},T))})]}),n.jsx("div",{className:"w6w-stepbuilder-list",children:h.map(({conn:T,users:R})=>n.jsx("button",{type:"button",className:"w6w-stepbuilder-item",disabled:f,"aria-pressed":T.id===g,"data-connection-id":T.id,onClick:()=>P(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:R.length>0?`In use in this workflow · ${R.map(D=>D.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&&j&&gn.createPortal(n.jsx(Ws,{initialAppId:e.uses.app,onClose:()=>S(!1),onCreated:({connectionId:T})=>{S(!1),c(),P(T)}}),j),x&&j&&gn.createPortal(n.jsxs(ke,{title:"Change connection",onClose:()=>k(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:()=>k(null),children:"Cancel"}),n.jsxs("button",{type:"button",className:"w6w-btn w6w-btn-ghost",disabled:f,onClick:()=>C(x,!0),children:["All ",y.length+1," nodes"]}),n.jsx("button",{type:"button",className:"w6w-btn",disabled:f,onClick:()=>C(x,!1),children:"Only this node"})]})]}),j)]})}function $u(e,t){return`${e.method}-${e.url??e.host}-${t}`}function Oa({calls:e,defaultOpen:t,keyOf:s,title:o}){if(e.length===0)return null;const r=s??$u;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(Ee,{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(Ee,{value:a.requestBody,maxHeight:240})]}),n.jsx("div",{className:"w6w-muted w6w-small",children:"Response headers"}),n.jsx(Ee,{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(Ee,{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 Ia({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 $a({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 Dn({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 Pa(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 Pu=["off","root","key","pick","append"],_u={off:"Off",root:"Merge at root",key:"Under a key",pick:"Pick fields",append:"Append"};function Fu(e){return le.effectiveStateConfig(e.uses.app,e.uses.action,e.state)}function Lu(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Mu(e,t){const{state:s,...o}=e,r=le.effectiveStateConfig(e.uses.app,e.uses.action,void 0);return Lu(t,r)?o:{...o,state:t}}function Du(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 _a(e){return!St(e.uses.app)}function je(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===Fe&&e.uses.action==="foreach"}function Fa(e){var t;return((t=e==null?void 0:e.uses)==null?void 0:t.app)===Fe}function ms(e){var s,o;if((e==null?void 0:e.uses.app)===Ke)return!0;if((e==null?void 0:e.uses.app)===It)return!1;if(!Fa(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 Qs(e){if(!Fa(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 Wu(e){const t=new Set;for(const s of e)for(const o of Qs(s))t.add(o);return t}function bn(e,t,s,o){return{id:bt(e,t,"each",o),source:e,target:t,sourceHandle:o!==void 0?$t(o):s?Tn:void 0,animated:!1,data:{when:"each",...o===void 0?{}:{route:o}},...Zt("each",void 0)}}const nn=e=>{var t;return typeof((t=e.data)==null?void 0:t.route)=="string"?e.data.route:void 0};function eo(e,t,s,o){const r=new Set(t.map(h=>h.id)),a=new Set(t.filter(h=>{var g;return je((g=h.data)==null?void 0:g.step)}).map(h=>h.id)),i=s.filter(h=>xe(h)==="each"&&!(h.source!==e&&a.has(h.source)&&nn(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 La(e,t){const s=new Set(e);return t.filter(o=>xe(o)==="each"&&s.has(o.source)&&s.has(o.target))}function qu(e,t){const s=La(e,t),o=new Set;for(const r of s){if(nn(r)!==void 0||o.has(r.source))return!1;o.add(r.source)}return!0}function Uu(e,t){const s=[];for(const o of Wn(e,t).values())if(!qu(o,t))for(const r of La(o,t)){const a=nn(r);s.push({from:r.source,to:r.target,...a===void 0?{}:{route:a}})}return s}function Wn(e,t){var r;const s=new Map,o=new Set;for(const a of e){if(!je((r=a.data)==null?void 0:r.step))continue;const i=eo(a.id,e,t,o);for(const l of i)o.add(l);s.set(a.id,i)}return s}function Ve(e,t){const s={};for(const[o,r]of Wn(e,t))for(const a of r)s[a]=o;return s}function Ma(e,t,s){const o=Ve(t,s),r=[];let a=o[e];for(;a!==void 0&&!r.includes(a);)r.unshift(a),a=o[a];return r}function Vu(e,t,s){const o=h=>h.source===e||h.target===e,r=s.filter(h=>!o(h)),i=je((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=Ve(t,s),u=new Set(i?Object.keys(l).filter(h=>l[h]===e):[]),c=i?r.filter(h=>!(xe(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&&xe(h)==="each"),f=s.filter(h=>h.source===e&&xe(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&&xe(h)==="each")?c:[...c,bn(m,w,m===d,nn(p[0]))]}function to(e){if(!je(e)||!e.with||!("body"in e.with))return e;const{body:t,...s}=e.with;return{...e,with:s}}function Da(e,t,s,o,r,a){const i=Ve(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=je(l(e))&&(a===void 0||i[e]===void 0)?e:i[e];if(c===void 0)return null;if(t===c||Ma(c,o,r).includes(t))return"loop_cycle";const d=()=>e!==c||!r.some(p=>p.source===e&&xe(p)==="each"&&nn(p)===void 0);return i[t]===c?e===c||Hu(t,e,r)?"loop_cycle":d()?null:"body_branch":i[t]!==void 0?"already_in_loop":ms(l(t))?d()?r.some(p=>p.source===t||p.target===t)?"body_exit":null:"body_branch":"control_in_body"}function Hu(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||xe(i)!=="each"||o.has(i.target)||(o.add(i.target),r.push(i.target))}return!1}const Bu={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 Ju(e){return Bu[e]}function zu(e,t){const s=Ve(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 Ku(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(!je(r))return o;const a=eo(e,t,s);return a.length===0?o:`${o} Its loop body steps ${a.map(u=>`"${u}"`).join(", ")} stay as standalone steps.`}function no(e){if(e.edges)return e.edges;const t=Wu(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 yn=e=>(e.when??"success")==="success",Cn=e=>e.route===pr&&yn(e);function so(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 Qs(c)){const p=s.get(d)??new Set;p.add(c.id),s.set(d,p)}const o=no(e),r=e.edges??[],a={};for(const c of e.nodes){if(!je(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),!ms(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(Cn(g)&&g.from===c&&g.to===f[0]||Cn(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)&&yn(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 je(t.get(c))&&Array.isArray(p)&&p[0]===d}function u(c){var g;const d=o.filter(y=>y.from===c&&yn(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)||!ms(x)||s.has(y))return p(y);const k=o.filter(S=>S.to===y);if(k.length!==1||k[0].from!==w)return p(y);const E=o.filter(S=>S.from===y);if(E.length>1||E.length===1&&!yn(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 xe(e){var s;const t=(s=e.data)==null?void 0:s.when;return t==="error"?"error":t==="each"?"each":"success"}function Wa(e,t){var s;return((s=e.find(o=>o.id===t))==null?void 0:s.id)??null}function qa(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 oo(e,t,s,o,r,a,i){var S,v,j;const l=r==="success"&&je((S=s.find(C=>C.id===e))==null?void 0:S.data.step),u=l&&i===void 0?wt:i;if(!qa(e,t,s,o,a,u)||!e||!t)return null;const c=(v=s.find(C=>C.id===e))==null?void 0:v.data.step,d=(j=s.find(C=>C.id===t))==null?void 0:j.data.step;if(!c||!d)return null;const p=Cs(c);if(l){if(u!==wt)return null}else if(c.uses.app===Ke&&r==="success"){if(!Ss(c).some(C=>C.id===u))return null}else if(p&&r==="success"){if(u!==void 0&&u!==xn)return null}else if(u!==void 0)return null;const f=Ve(s,o)[e]!==void 0,m=r==="success"&&f?"each":r;if(m==="each"&&!f&&!je(c))return null;const w=Da(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(C=>{var P;return C.source===e&&xe(C)===m&&((P=C.data)==null?void 0:P.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 k=bt(e,t,m,u),E=m==="each"&&f&&!je(c)?void 0:vs(m);return{next:Qn.addEdge({source:e,target:t,id:k,sourceHandle:u===void 0?E:$t(u),data:{when:m,...u===void 0?{}:{route:u}},...Zt(m,void 0)},g),conflict:Wa(g,k),refusal:null}}function Gu(e,t,s,o,r="success",a,i){const l=oo(e,t,s,o,r,a,i);return!l||l.conflict||l.refusal?null:l.next}function Yu(e,t,s,o,r="success",a,i){var l;return((l=oo(e,t,s,o,r,a,i))==null?void 0:l.conflict)??null}function Xu(e,t,s,o,r="success",a,i){var l;return((l=oo(e,t,s,o,r,a,i))==null?void 0:l.refusal)??null}function ro(e,t,s,o,r){var x;const a=e.filter(k=>k.id===t);if(a.length!==1)return null;const i=a[0];if(xe(i)==="each")return null;const l=(x=o.find(k=>k.id===i.source))==null?void 0:x.data.step;if(!l||l.uses.app===Ke||l.uses.app===It)return null;const u=Bt(l,r).out,c=e.filter(k=>k.id!==t);if((xe(i)===s?[]:c.filter(k=>k.source===i.source&&xe(k)===s)).length>=u)return{next:e,conflict:null,refusal:{refused:"out_cap",cap:u}};const p=Zt(s,void 0),f=je(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?$t(m):vs(s)},y=Wa(c,g.id);return{next:e.map(k=>k.id===t?g:k),conflict:y,refusal:null}}function Zu(e,t,s,o,r){const a=ro(e,t,s,o,r);return!a||a.conflict||a.refusal?null:a.next}function Qu(e,t,s,o,r){var a;return((a=ro(e,t,s,o,r))==null?void 0:a.conflict)??null}function ed(e,t,s,o,r){var a;return((a=ro(e,t,s,o,r))==null?void 0:a.refusal)??null}function td(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,xe(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 nd(e){return e.includes(".")?"A step id can't contain a dot (.).":null}function Ua(e,t){const s=nd(e);if(s)return s;for(const o of t)if(o===e)return`A step named "${e}" already exists.`;return null}function sd(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 od=240,rd=100,ad=40,id=40;function ao(e,t){return{x:ad+e*od,y:id+t*rd}}function ld(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 Va(e,t){var u;const s=ld(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,ao(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 cd(e){const t=e.position;if(!(!t||!Number.isFinite(t.x)||!Number.isFinite(t.y)))return{x:t.x,y:t.y}}function io(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 ud(e){const t=io(e),s=t.nodes;let o=no(t);const r=[],a=new Set(s.filter(je).map(w=>w.id)),i=new Map,l=new Set,u=new Set;for(const[w,h]of Object.entries(so(t))){if("invalid"in h)continue;let g=w;if(h.edges&&h.body.length>0){r.push(bn(w,h.body[0],!0));for(const y of h.edges)u.add(y),r.push(bn(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(k=>k.from===g&&k.to===y&&(k.when??"success")==="success");x&&u.add(x)}r.push(bn(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(je).map(w=>w.id));for(const w of o)c.has(w.from)&&Cn(w)&&u.add(w);u.size>0&&(o=o.filter(w=>!u.has(w)));const d=Va(s,[...o,...r.map(w=>({from:w.source,to:w.target}))]),p=s.map(w=>{const h=nt(w.uses.app);return{id:w.id,type:h?"control":"step",position:cd(w)??d.get(w.id)??ao(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(Cs).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:xn}: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?vs(g):`route:${h.route}`,animated:!1,data:{when:g,...h.route===void 0?{}:{route:h.route}},...Zt(g,void 0)}});return{nodes:p,edges:[...m,...r]}}function dd(e,t){const s=e.map(r=>({...r.data.step,id:r.id})),o=Va(s,t.map(r=>({from:r.source,to:r.target})));return e.map(r=>({...r,position:o.get(r.id)??ao(0,0)}))}function pd(e,t,s){var S,v;const o=io(e),r=((S=o.settings)==null?void 0:S.savePosition)!==!1,a=new Map(t.map(j=>[j.id,j])),i=j=>{var P;if(!r)return j;const C=(P=a.get(j.id))==null?void 0:P.position;return!C||!Number.isFinite(C.x)||!Number.isFinite(C.y)?j:{...j,position:{x:Math.round(C.x),y:Math.round(C.y)}}},l=new Map;for(const j of o.nodes)l.set(j.id,j);for(const j of t)(v=j.data)!=null&&v.step&&l.set(j.id,j.data.step);const u=Wn(t,s),c=so(o),d=new Map(o.nodes.map(j=>[j.id,j])),p=new Set;for(const j of s)xe(j)==="success"&&p.add(j.source);const f=j=>{if(!je(j))return j;const C=u.get(j.id)??[],P=d.get(j.id),q=c[j.id];let I;C.length>0?I={value:C}:q&&"invalid"in q&&q.invalid.reason!=="legacy_not_linear"?I=P!=null&&P.with&&"body"in P.with?{value:P.with.body}:null:q&&"invalid"in q?I=null:p.has(j.id)||P!=null&&P.with&&"body"in P.with?I={value:[]}:I=null;const $=j.with??{};return I===null?"body"in $?to(j):j:{...j,with:{...$,body:I.value}}},m=j=>i(f(j)),w=[],h=new Set;for(const j of o.nodes){const C=l.get(j.id);C&&t.some(P=>P.id===j.id)&&(w.push(m(C)),h.add(j.id))}for(const j of t){if(h.has(j.id))continue;const C=l.get(j.id);C&&w.push(m(C))}const g=new Set;for(const j of u.values())for(const C of j)g.add(C);const y=new Set(t.filter(j=>{var C;return je((C=j.data)==null?void 0:C.step)}).map(j=>j.id)),x=s.filter(j=>xe(j)!=="each"&&!g.has(j.source)&&!g.has(j.target)).map(j=>{var P;const C=typeof((P=j.data)==null?void 0:P.route)=="string"?j.data.route:y.has(j.source)&&xe(j)==="success"?wt:void 0;return{from:j.source,to:j.target,...xe(j)==="error"?{when:"error"}:{},...C===void 0?{}:{route:C}}}),k=[];for(const[j,C]of u)C.length>0&&k.push({from:j,to:C[0],route:pr});const E=[...x,...k,...Uu(t,s)];return Aa({...o,nodes:w,edges:E})}function Ha(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 fd(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=Ha(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 hd(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"step"}function wd(e,t){const s=new Set(t.map(o=>o.target));return e.find(o=>!s.has(o.id))}function md(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 bd(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 lo(e){return JSON.stringify(to(e),null,2)}const yd=3,gd=100;function yt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ba(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 xd(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=Ba([{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>=gd)return;const u=r?`${r}.${i}`:i;t.push({key:u,path:!0}),yt(l)&&a<yd&&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 pt(e,t,s){const o=Ba(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 co(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 Ja(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===ks)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 C=pt((c=s.triggerDef)==null?void 0:c.call(s,w.uses.app,w.uses.action),g,y);if(a??(a=C),C&&(C.from==="fresh"||C.from==="persisted")){o.push({id:w.id,label:w.id,outputs:C.fields,outputsFrom:C.from});continue}}h&&(r=!0);const x=h&&w.uses.app===Ot,k=x?Gs(Js((d=w.with)==null?void 0:d.fields)).map(C=>({key:C.key,label:C.label})):((p=mt(w.uses.app,w.uses.action))==null?void 0:p.output)??[],E={id:w.id,label:w.id};if(k.length>0){o.push({...E,outputs:k});continue}if(h){const C=pt(void 0,g,y);C&&!x&&(a??(a=C)),o.push(C?{...E,outputs:C.fields,outputsFrom:C.from}:E);continue}if(nt(w.uses.app)){const C=pt(void 0,g,y);o.push(C?{...E,outputs:C.fields,outputsFrom:C.from}:E);continue}const S=(f=s.actionDef)==null?void 0:f.call(s,w.uses.app,w.uses.action),v=pt(S,g,y),j=w.uses.app.trim()!==""?{hasMeta:!0}:{};v?o.push({...E,outputs:v.fields,outputsFrom:v.from,...j}):o.push(S?{...E,needsTest:!0,...j}:{...E,...j})}return{steps:o,hasTrigger:r,...a?{eventOutputs:a.fields,eventOutputsFrom:a.from}:{}}}function vd(e,t){const s={};for(const[o,r]of Object.entries(t))s[o]={output:r};return za(e,{steps:s})}function za(e,t){if(lt(e)!==null){const s=Ps(e,Os(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 jd=10;function Nd(e,t){return{input:t,with:{items:e.slice(0,jd),itemCount:e.length}}}function kd(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 Ka(e,t,s,o,r={}){const a=Ve(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=Ja(i,s,r),u=Wn(s,o),c=[];return{steps:l.steps.map(p=>{var x,k,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?pt((k=r.actionDef)==null?void 0:k.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 Sd(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 Cd(e,t,s){var p,f;const o=lt(e),r=o?Sd(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=xd(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 Ga(e,t,s={},o=[]){const r=sr(e,t,s),a=Ma(e,t,o);return a.length===0?r:{...r,outer:a.map(i=>({...sr(i,t,s),name:i}))}}function sr(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=vd(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=Cd(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 Ya(e,t,s,o){return!e&&!!t&&!o.some(r=>r.target===t)&&Ve(s,o)[t]===void 0}function Ad(e,t,s,o,r){let a=e;if(!a&&r&&!Ya(e,r,t,s)&&(a=r),!a)return Ja(new Set(t.map(u=>u.id)),t,o);const i=Ve(t,s)[a],l=Ka(co(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:Ga(i,t,o,s)}:{},...l.extraSampleIds.length>0?{extraSampleIds:l.extraSampleIds}:{}}}function Ed(e,t,s,o){if(!e||e.handleType==="target")return[];const r=co(e.nodeId,s);r.add(e.nodeId);const a=Xa(e,t,s);return Ka(r,a,t,s,o).steps}function Xa(e,t,s){const o=t.find(r=>r.id===e.nodeId);return e.lane==="each"&&je(o==null?void 0:o.data.step)?e.nodeId:Ve(t,s)[e.nodeId]}function Td(e,t,s,o){if(!e||e.handleType==="target")return;const r=Xa(e,t,s);return r?Ga(r,t,o,s):void 0}async function Rd(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 uo(e,t,s){const o=Od(e,t);return!s||Object.keys(s).length===0?o:{...o??{},state:s}}function Od(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 Za(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 Id(e){return!e||!("itemSample"in e)?"":JSON.stringify(e.itemSample,null,2)??""}function $d(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 Pd(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 _d(e,t,s,o,r){return Qa(e,t,s,o,r).values}function Fd(e,t,s,o,r){return Qa(e,t,s,o,r).sources}function Ld(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(nt(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 Qa(e,t,s,o,r={}){var l,u;const a={},i={};for(const c of e){Object.assign(a,Pd(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 Md(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 Dd(e){const t=[];for(const s of e){const o=s.data.step,r=Object.entries(o.with??{}).filter(([,i])=>i!==void 0&&!Md(i)).map(([i])=>i);(o.uses.app===Ue||o.uses.trigger===!0)&&!r.includes("url")&&r.unshift("url"),r.length>0&&t.push({id:o.id,keys:r})}return t}function bs(e){if(!(Ye(e)||at(e))){if(Array.isArray(e))return e.map(bs).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=bs(a);i!==void 0&&(o[r]=i)}return o}return e}}function Wd(e,t){const s={};for(const o of e){const r=o.data.step,a={...bs(r.with??{})??{}},i=ei(r,t);i!=null&&i.webhookUrl&&(a.url=i.webhookUrl),Object.keys(a).length>0&&(s[r.id]=a)}return s}function ei(e,t){if(!(e.uses.app!==Ue&&e.uses.trigger!==!0))return t.find(s=>s.nodeId===e.id)??(e.uses.app===Ue?t.find(s=>s.appId===Ue):void 0)}function qd(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:Pt(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=ei(l,t);d&&(u.subscriptionId=d.id),d!=null&&d.webhookUrl&&(u.url=d.webhookUrl),r[l.id]=u}return r}function Ud(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 Vd(e,t){const s={success:0,error:0};for(const r of t){if(r.source!==e)continue;const a=xe(r);a!=="each"&&s[a]++}const o=Math.max(s.success,s.error);return{enabled:o>=2,count:o}}function Hd(e,t){const{fanOut:s,...o}=e;return t==="parallel"?{...o,fanOut:"parallel"}:o}function Bd(e,t){return`Runs these ${e} nodes in ${t==="parallel"?"parallel":"sequence"}`}function ti({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(Hd(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 or({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 rr(){return n.jsx("span",{className:"w6w-state-map-arrow","aria-hidden":"true",children:"→"})}function ar({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 ni({step:e,inLoop:t,outputFields:s,readOnly:o,onChange:r}){const a=Fu(e),i=le.validateStateConfig(a),l=p=>r(Mu(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(Du(e,p.target.value)),children:Pu.map(p=>n.jsx("option",{value:p,children:_u[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(or,{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(ar,{label:"From output field",fields:s,value:p.from,readOnly:o,onChange:m=>c(f,{from:m})}),n.jsx(rr,{}),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(Hs,{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(or,{to:"Append to state list"}),n.jsxs("div",{className:"w6w-datavar-row w6w-state-map-row",children:[n.jsx(ar,{label:"Output field to append",fields:s,value:a.from??"",readOnly:o,onChange:p=>d({from:p})}),n.jsx(rr,{}),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 po(e,t,s){const o=Ne(),[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 Rd(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 fo(e){return(e.nodes??e.steps??[]).filter(t=>t.uses.app===Ot&&t.uses.action==="manual")}function Jd(e,t){var a;const s=fo(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:zs(i.type),default:Ks(i.type,i.default),required:!!i.required}]):[]}const zd=["function","workflow"],Kd={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"/>'},Yn={props:{label:"Form",icon:"form"},code:{label:"JSON",icon:"code"},"params-code":{label:"Params JSON",icon:"braces"},config:{label:"Node settings",icon:"settings-2"}},Gd=["props","code","params-code","config"];function qn({view:e,onChange:t,disabled:s,views:o=Gd,customized:r=!1}){const a=i=>n.jsx("button",{type:"button",title:Yn[i].label,"aria-label":Yn[i].label,"aria-pressed":e===i,disabled:s,className:`w6w-icon-btn${e===i&&!s?" active":""}`,onClick:()=>t(i),children:n.jsx(de.Icon,{name:Yn[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 Yd({onClose:e,onDone:t,onAdd:s,onDraftChange:o,theme:r,appsOnly:a,callables:i=zd,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:k,setupOnly:E,addLabel:S,onConnected:v,excludeCallableIds:j,onOpenStep:C,stepIds:P=[]}){const[q,I]=b.useState(null),[$,T]=b.useState(null),R=b.useRef(null),D=ce=>{const he=s(ce);return typeof he=="string"&&(R.current=ce,I(he),T(null)),he},W=o?(ce,he)=>{R.current=he,o(ce,he)}:void 0,H=()=>{q&&$&&$!==q&&W&&R.current&&W(q,{...R.current,id:$}),(t??e)()},L=ce=>q&&o?n.jsxs("span",{className:"w6w-stepbuilder-title",children:[ce,n.jsx(ra,{value:$??q,onCommit:he=>{const Re=Ua(he,P.filter(Oe=>Oe!==q));return Re||T(he),Re}})]}):ce,[O,K]=b.useState(l??"connected"),[G,se]=b.useState(""),[F,X]=b.useState(!1),z=G.trim()!==""&&!F,M=ce=>{K(ce),X(!0)},[te,Q]=b.useState(m??null),[A,U]=b.useState(null),[Z,ae]=b.useState(null),[Y,ge]=b.useState(null),V=ce=>{if(!E)return ge(ce);s({uses:{app:Qt,action:"call"},with:{targetKind:ce.family,targetId:ce.id}})},ue=!!x&&x.length>0,ye=ri(i,y,j,x),we=ye.state!=="empty";if(b.useEffect(()=>{!we&&O==="connected"&&K("apps")},[we,O]),Y)return n.jsx(ke,{title:L(Y.label),ariaLabel:Y.label,subtitle:n.jsx("code",{children:Y.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(sp,{family:Y.family,targetId:Y.id,targetLabel:Y.label,onAdd:D,onClose:e,onDone:H,onDraftChange:W})})});if(A)return n.jsx(ke,{title:L(A.groupActions?A.displayName:A.label),ariaLabel:A.groupActions?A.displayName:A.label,titleIcon:n.jsx(Dn,{icon:A.icon,size:22}),subtitle:n.jsxs("code",{children:[A.app,!A.groupActions&&` · ${A.action}`]}),onClose:e,size:"xl",headerRight:n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost",onClick:()=>U(null),children:"← Back"}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:n.jsx(np,{node:A,onAdd:D,onClose:e,onDone:H,onDraftChange:W,onOpenStep:C,workflowId:c,upstreamSteps:p,loop:f})})});const ie=Z??te;if(ie){const ce=Z?"trigger":"action",he=()=>{Q(null),ae(null)};return n.jsx(ke,{title:L(ie.displayName),ariaLabel:ie.displayName,subtitle:n.jsxs(n.Fragment,{children:[n.jsx("code",{children:ie.id}),ie.version&&` · v${ie.version}`]}),onClose:e,size:"xl",titleIcon:n.jsx(gt,{src:ie.iconSvg,srcDark:ie.iconSvgDark,brandColor:ie.brandColor,name:ie.displayName,theme:r,size:22}),children:n.jsx("div",{className:"w6w-stepbuilder-config",children:k&&ce==="action"?n.jsx(pp,{appId:ie.id,app:ie,onClose:e,onChangeApp:he,theme:r,initialConnection:h,onConnected:(Re,Oe)=>v==null?void 0:v(Re,Oe)}):n.jsx(dp,{kind:ce,onOpenStep:C,appId:ie.id,app:ie,onAdd:D,onClose:e,onDone:H,onDraftChange:W,onChangeApp:he,theme:r,workflowId:c,stepId:d,upstreamSteps:p,loop:f,...ce==="action"?{initialAction:w,initialConnection:h,initialWith:g}:{},setupOnly:E&&ce==="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:ce=>{se(ce.target.value),X(!1)}}),n.jsxs("div",{className:"w6w-stepbuilder",children:[n.jsxs("nav",{className:"w6w-stepbuilder-sidebar",children:[we&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="connected"?" active":""}`,onClick:()=>M("connected"),children:"Ready to use"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="apps"?" active":""}`,onClick:()=>M("apps"),children:"Apps"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="ai"?" active":""}`,onClick:()=>M("ai"),children:"AI"}),i.includes("workflow")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="workflows"?" active":""}`,onClick:()=>M("workflows"),children:"Workflows"}),i.includes("function")&&n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="functions"?" active":""}`,onClick:()=>M("functions"),children:"Functions"}),!a&&n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="triggers"?" active":""}`,onClick:()=>M("triggers"),children:"Triggers"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="controls"?" active":""}`,onClick:()=>M("controls"),children:"Controls"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="utilities"?" active":""}`,onClick:()=>M("utilities"),children:"Utilities"}),n.jsx("button",{type:"button",className:`w6w-stepbuilder-tab${!z&&O==="data"?" active":""}`,onClick:()=>M("data"),children:"Data"})]})]}),n.jsx("div",{className:"w6w-stepbuilder-content",children:z?n.jsx(Xd,{query:G,builtIns:!a,callables:i,excludeCallableIds:j,appsFilter:y,appsIds:x,theme:r,onSelectNode:U,onSelectApp:Q,onSelectCallable:V}):O==="connected"?n.jsx(up,{data:ye,query:G,appsFilter:y,onSelectApp:Q,onSelectCallable:V,theme:r}):O==="functions"?n.jsx(An,{family:"function",query:G,excludeIds:j,onSelect:ce=>V({family:"function",...ce})}):O==="workflows"?n.jsx(An,{family:"workflow",query:G,excludeIds:j,onSelect:ce=>V({family:"workflow",...ce})}):O==="apps"?n.jsx(st,{search:!1,searchValue:G,onSelectApp:Q,theme:r,filter:y,ids:x}):O==="ai"?n.jsx(st,{search:!1,searchValue:G,onSelectApp:Q,theme:r,category:ue?void 0:"ai",ids:x,filter:ce=>{var he;return((y==null?void 0:y(ce))??!0)&&(ue||(((he=ce.categories)==null?void 0:he.includes("ai"))??!1))},emptyMessage:"No AI apps registered yet."}):O==="triggers"?n.jsx(Zd,{query:G,onSelect:U,onSelectApp:ae,theme:r,appsFilter:y,appsIds:x}):O==="controls"?n.jsx(Qd,{query:G,onSelect:U}):O==="data"?n.jsx(tp,{query:G,onSelect:U}):n.jsx(ep,{query:G,onSelect:U})})]})]})})}function Ut(e,...t){const s=t.filter(Boolean).join(" ").toLowerCase();return e.trim().toLowerCase().split(/\s+/).every(o=>s.includes(o))}function ho(e,t){return Ut(t,e.label,e.displayName,e.app,e.action)}function Xd({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?rt.filter(f=>f.hidden||!ho(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(mo,{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(st,{search:!1,searchValue:e,onSelectApp:u,theme:i,filter:r,ids:a})]}),s.includes("workflow")?n.jsx(An,{section:!0,family:"workflow",query:e,excludeIds:o,onSelect:f=>c({family:"workflow",...f})}):null,s.includes("function")?n.jsx(An,{section:!0,family:"function",query:e,excludeIds:o,onSelect:f=>c({family:"function",...f})}):null]})}function wo({nodes:e,onSelect:t,query:s}){const o=new Set,r=e.filter(a=>ho(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(mo,{node:a,onSelect:t},`${a.app}:${a.action}`))}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["No nodes match “",s,"”."]})}function mo({node:e,onSelect:t}){return n.jsxs("button",{type:"button",className:"w6w-stepbuilder-item",onClick:()=>t(e),children:[n.jsx(Dn,{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 Zd({query:e,onSelect:t,onSelectApp:s,theme:o,appsFilter:r,appsIds:a}){var w;const i=Ne(),l=rt.filter(h=>h.group==="trigger"&&ho(h,e)),[u,c]=b.useState(!1),d=ri([],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(st,{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(ai,{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(st,{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(mo,{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 Qd({onSelect:e,query:t}){const s=rt.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(wo,{nodes:s,onSelect:e,query:t})]})}function ep({onSelect:e,query:t}){const s=rt.filter(o=>o.group!=="control"&&o.group!=="trigger"&&o.app!==Ht&&o.app!==Ns&&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(wo,{nodes:s,onSelect:e,query:t})]})}function tp({onSelect:e,query:t}){const s=rt.filter(o=>(o.app===Ht||o.app===Je||o.app===Ns)&&!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(wo,{nodes:s,onSelect:e,query:t})]})}function np({node:e,onAdd:t,onClose:s,onDone:o,onDraftChange:r,onOpenStep:a,workflowId:i,upstreamSteps:l=[],loop:u}){var H,L;const[c,d]=b.useState(e),p=e.groupActions?rt.filter(O=>O.app===e.app&&!O.hidden):[],[f,m]=b.useState(()=>jn(c.app,c.action)),w=!St(c.app),h=po(i??"",l,w&&!!i),g=(H=Xe().stateShape)==null?void 0:H.written,y=uo(h,Za(u),g),[x,k]=b.useState("configure"),[E,S]=b.useState("props"),[v,j]=b.useState("{}"),[C,P]=b.useState({}),q=Rt(c.params,f),[I,$]=b.useState(null),T=()=>({uses:{app:c.app,action:c.action},with:f,...C});b.useEffect(()=>{if(!r)return;const O=t(T());O&&$(O),O&&c.app===Ue&&(a==null||a(O))},[]),b.useEffect(()=>{!r||I===null||r(I,T())},[I,f,C,c]);const R=O=>{O==="code"&&j(lo(T())),S(O)},D=()=>t(T()),W=i&&I!==null?{workflowId:i,stepId:I,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:()=>k("configure"),children:"Configure"}),w&&n.jsx("button",{type:"button",disabled:!q,title:q?void 0:"Fill the required fields first",className:`w6w-subtab${x==="test"?" active":""}`,onClick:()=>q&&k("test"),children:"Test"})]}),n.jsx(qn,{view:E,customized:Mn(f),onChange:R,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(se=>se.action===O.target.value);if(!K)return;const G=jn(K.app,K.action);m(Object.fromEntries(K.params.flatMap(se=>se.key in f?[[se.key,f[se.key]]]:se.key in G?[[se.key,G[se.key]]]:[]))),d(K)},children:p.map(O=>n.jsx("option",{value:O.action,children:O.label},O.action))})]}),x==="configure"&&(E==="props"?c.app===It?n.jsx("p",{className:"w6w-muted w6w-small",children:hr}):c.action==="wait"&&St(c.app)?n.jsx(ka,{values:f,onChange:m}):c.action==="if"&&St(c.app)?n.jsx(Ln,{values:f,onChange:m}):c.app===ks?n.jsx(aa,{values:f,onChange:m}):c.app===Ke?n.jsx(oa,{values:f,onChange:m}):n.jsx(Le,{params:c.params,values:f,onChange:m}):E==="code"?n.jsx(ze,{value:v,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):E==="params-code"?n.jsx(Vs,{values:f,onChange:m}):n.jsx(oi,{step:{id:I??"",...T()},config:C,onChange:P,inLoop:u!==void 0,outputFields:(L=c.output)==null?void 0:L.map(O=>O.key),failureHandling:!vn(c.app),retryControls:!St(c.app)&&c.app!==Qt})),x==="test"&&w&&(vn(c.app)?n.jsx(Na,{app:c.app,action:c.action,fields:f.fields,persist:W},(W==null?void 0:W.stepId)??""):n.jsx(bo,{app:c.app,action:c.action,values:f,canRun:q,state:y,persist:W},(W==null?void 0:W.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:!q,onClick:()=>k("test"),children:"Next →"}):n.jsx("button",{type:"button",className:"w6w-btn",onClick:I!==null?o??s:D,children:I!==null?"Done":"Add node"})]})]})}function An({family:e,query:t,excludeIds:s,onSelect:o,section:r=!1}){const a=Ne(),[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=Ct,m=t.trim().toLowerCase(),w=ys(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(En,{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(En,{family:e,item:g,onSelect:o},g.id))})}))}function sp({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:Qt,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(ci,{fixedTarget:!0,values:l,onChange:u,onValidityChange:d,targetLabel:s}):n.jsx(op,{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 op({family:e,targetId:t,inputs:s,entry:o,canRun:r}){const a=Ne(),[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(de.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(Ee,{value:i.output,maxHeight:220})]})]})}function rp(e){const t={};for(const s of e)ot(s.default)&&(t[s.key]=s.default);return t}function Rt(e,t){const s=na(t);if(s===null)return!1;if(s===void 0)return!0;const o=Et(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=le.effectiveParam(c,u);if(d.type==="section")return a(d.children??[],l,u);if(d.type==="group"){const f=d.children??[],m=Et(f),w=g=>y=>{const x=m.find(k=>k.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||!tn(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 si(e){const t=e==null?void 0:e.testRequired;return typeof t=="boolean"?t:!0}function ap(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 ip(e){const t=e==null?void 0:e.apiCalls;return Array.isArray(t)?t:[]}function lp({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(Ee,{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(Ee,{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(Oa,{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 oi({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(ta,{config:t,onChange:u=>s({...t,...u}),failureHandling:a,retryControls:i}),n.jsx(ti,{step:e,count:0,onChange:l}),_a(e)&&n.jsx(ni,{step:e,inLoop:o,outputFields:r,onChange:l})]})}const bo=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=Ne(),m=Es(),w=sl(),[h,g]=b.useState(null),[y,x]=b.useState(null),[k,E]=b.useState(!1),S=b.useRef(!1),[v,j]=b.useState(null),C=l==null?void 0:l.workflowId,P=l==null?void 0:l.stepId,q=Xe().nodeMeta,I=P?q==null?void 0:q[P]:void 0;b.useEffect(()=>{if(!C||!P)return;let R=!1;return f.listStepTests(C,P).then(D=>{let W;for(const H of D)!H.lastRunAt||!H.lastRunStatus||(!W||Date.parse(H.lastRunAt)>Date.parse(W.lastRunAt))&&(W=H);!W||!W.lastRunAt||R||S.current||(W.lastRunStatus==="succeeded"?g({status:"done",value:W.lastRunOutput,...W.lastRunMeta?{meta:W.lastRunMeta}:{}}):g({status:"error",error:typeof W.lastRunError=="string"?W.lastRunError:W.lastRunError==null?"Test failed":JSON.stringify(W.lastRunError)}),j(W.lastRunAt))}).catch(()=>{}),()=>{R=!0}},[f,C,P]);const $=async()=>{var L;if(!a||(h==null?void 0:h.status)==="running")return;S.current=!0,j(null),g({status:"running"}),c==null||c(!0);let R;const D=new Date,W={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}:{}}},H=O=>x({startedAt:D.toLocaleString(),durationMs:Date.now()-D.getTime(),request:W,response:O,apiCalls:ip(O.body)});try{const O=await f.invokeAction(t,s,r,{...o?{connectionId:o}:{},project:m,...u?{state:u}:{},...w?{workflowId:w}:{}});H({ok:!0,body:O}),R={status:"done",value:O.value,logs:O.logs,...O.meta?{meta:O.meta}:{}}}catch(O){const K=O;H({ok:!1,...typeof K.status=="number"?{status:K.status}:{},body:ap(O)}),R={status:"error",error:K.message??String(O),errorCode:K.code,logs:K.logs}}if(g(R),d==null||d(R.status==="done"),l){(L=f.saveTestInput)==null||L.call(f,l.workflowId,l.stepId,Ys(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:R.status==="done"?"succeeded":"failed",input:l.input,output:R.status==="done"?R.value:void 0,error:R.status==="error"?R.error:void 0,...R.status==="done"&&R.meta?{meta:R.meta}:{}})}catch(O){console.error("step test persist failed",O)}}c==null||c(!1)};b.useImperativeHandle(p,()=>({run:$}));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:$,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."})]}),k&&y&&n.jsx(lp,{log:y,onClose:()=>E(!1)}),v&&((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(v).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(Ee,{value:h.value,maxHeight:220}),(h.meta||I)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Ee,{value:{...I,...h.meta},maxHeight:220})]})]}),(h==null?void 0:h.status)!=="done"&&(h==null?void 0:h.status)!=="running"&&I&&n.jsxs("div",{className:"w6w-testout","data-testid":"steptest-static-meta",children:[n.jsx("div",{className:"w6w-testout-label",children:"Metadata"}),n.jsx(Ee,{value:I,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(de.Copyable,{value:T.join(`
|
|
21
|
+
`),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(`
|
|
22
|
+
`)})})]})]})}),ir=12,un=new Set;function ri(e,t,s,o,r){const a=o&&o.length>0?new Set(o):null,i=F=>(a?a.has(F.id):!0)&&((t==null?void 0:t(F))??!0),l=Ne(),[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,k]=b.useState(()=>new Map),[E,S]=b.useState(()=>new Set),[v,j]=b.useState(un),C=b.useRef(un),P=b.useCallback(F=>{C.current=F,j(F)},[]),q=b.useRef(un),I=e.includes("function"),$=e.includes("workflow"),T=typeof l.listAppsByIds=="function";b.useEffect(()=>{let F=!1;const X=z=>!F&&y(z.message);return l.listConnections().then(z=>{if(F)return;const M=[],te=new Set,Q=new Map;for(const A of z)nt(A.appId)||(T&&!(r!=null&&r.resolveInline)&&A.app&&!Q.has(A.appId)&&Q.set(A.appId,{...A.app,id:A.appId}),!te.has(A.appId)&&(te.add(A.appId),M.push(A.appId)));Q.size>0&&(q.current=new Set(Q.keys()),k(A=>new Map([...A,...Q])),S(A=>new Set([...A,...Q.keys()]))),c(M)}).catch(X),I?l.listFunctions().then(z=>!F&&m(z)).catch(X):m([]),$?l.listWorkflows().then(z=>!F&&h(z)).catch(X):h([]),()=>{F=!0}},[l,T,I,$,r==null?void 0:r.resolveInline]),b.useEffect(()=>{if(T)return;const F=l.listApps;if(typeof F!="function"){p([]);return}let X=!1;return F().then(z=>!X&&p(z)).catch(z=>!X&&y(z.message)),()=>{X=!0}},[l,T]);const R=b.useRef(!0);b.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]);const D=b.useCallback(F=>{const X=l.listAppsByIds;!X||F.length===0||C.current.size>0||(P(new Set(F)),X(F).then(z=>{R.current&&(P(un),k(M=>{const te=new Map(M);for(const Q of z)te.set(Q.id,Q);return te}),S(M=>new Set([...M,...F])))}).catch(z=>R.current&&y(z.message)))},[l,P]),W=b.useRef(!1);b.useEffect(()=>{if(!T||u===null||W.current)return;const F=zn(u,q.current,ir);F.length!==0&&(W.current=!0,D(F))},[T,u,D]);const H=()=>{if(!T||u===null||C.current.size>0)return;const F=new Set([...E,...C.current]);D(zn(u,F,ir))};if(g)return{state:"error",error:g,apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:H};if(f===null||w===null)return{state:"loading",apps:[],fns:[],wfs:[],moreApps:!1,loadMoreApps:H};const L=ys(f,s),O=ys(w,s);if(T){if(u===null)return{state:"loading",apps:[],fns:L,wfs:O,moreApps:!1,loadMoreApps:H};if(u.length>0&&E.size===0)return{state:"loading",apps:[],fns:L,wfs:O,moreApps:!1,loadMoreApps:H};const F=el(u,x).filter(i),X=v.size===0&&zn(u,new Set([...E,...v]),1).length>0;return{state:F.length===0&&L.length===0&&O.length===0&&!X?"empty":"ready",apps:F,appIds:u.filter(M=>!a||a.has(M)),fns:L,wfs:O,moreApps:X,loadMoreApps:H}}if(d===null)return{state:"loading",apps:[],fns:L,wfs:O,moreApps:!1,loadMoreApps:H};const K=new Set(u??[]),G=d.filter(F=>!nt(F.id)&&i(F)&&(K.has(F.id)||F.zeroCredential===!0));return{state:G.length===0&&L.length===0&&O.length===0?"empty":"ready",apps:G,fns:L,wfs:O,moreApps:!1,loadMoreApps:H}}function ys(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 Ct(e){const t=e.displayName;return t!=null&&t.trim()?t:"name"in e?e.name:e.id}function En({family:e,item:t,onSelect:s}){const o=Ct(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(Dn,{icon:Kd[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 cp(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 ai({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 up({data:e,query:t,appsFilter:s,onSelectApp:o,onSelectCallable:r,theme:a}){var g;const i=Ne(),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,Ct(y),y.id)).sort(Vt(Ct)),d=e.wfs.filter(y=>Ut(t,Ct(y),y.id)).sort(Vt(Ct)),p=cp,f=u.map(y=>n.jsx(ai,{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(st,{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(En,{family:"function",item:y,onSelect:x=>r({family:"function",...x})},y.id))),p("Workflows",d.map(y=>n.jsx(En,{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 ii(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 li({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 dp({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,qe;const k=Ne(),E=e==="trigger",S=E?"a trigger":"an action",[v,j]=b.useState(null),[C,P]=b.useState(null),[q,I]=b.useState(null),[$,T]=b.useState(null),[R,D]=b.useState(h??""),[W,H]=b.useState(),L=Zs(),O=b.useRef(L);O.current=L;const K=W?Pt({uses:{app:s,action:"",connectionRef:W}},L==null?void 0:L.connections)??"":R,G=b.useCallback(ee=>{H(void 0),D(ee)},[]),[se,F]=b.useState(w??""),[X,z]=b.useState(g??{}),M=b.useRef(null),[te,Q]=b.useState(!1),[A,U]=b.useState(!y&&w&&g?"configure":"setup"),[Z,ae]=b.useState("props"),[Y,ge]=b.useState("{}"),[V,ue]=b.useState({});b.useEffect(()=>{let ee=!1;T(null);const pe=E?ii(k,s):k.getAppActions(s);return Promise.all([k.getAppAuth(s),k.listConnectionsForApp(s),pe]).then(([Ae,vt,sn])=>{if(ee)return;const N=nr(s,Ae,vt);j(Ae),P(N),I(sn);const _=O.current,J=Ea({id:p??"",uses:{app:s,action:""}},N,(_==null?void 0:_.nodes)??[],(_==null?void 0:_.connections)??{},h);J.connectionRef?H(J.connectionRef):G(J.connection??"")}).catch(Ae=>!ee&&T(Ae.message)),()=>{ee=!0}},[k,s,E,G,h,p]);const ye=async()=>{const ee=await k.listConnectionsForApp(s);P(nr(s,v??[],ee))},we=(v??[]).filter(ee=>ee.available!==!1),ie=we.some(ee=>ee.autoSatisfied===!0&&(ee.type==="tenantAuth"||ee.type==="jit")),ce=ie&&!we.some(ee=>ee.autoSatisfied===!0&&ee.type==="tenantAuth"),he=we.length>0&&!ie,Re=(C??[]).length>0,Oe=v!==null&&C!==null&&he&&!Re,[_t,xt]=b.useState(0),me=(q??[]).find(ee=>ee.key===se),Pe=E?Pa(s,q,se,X):null,He=[...q??[]].sort((ee,pe)=>(ee.title??ee.key).localeCompare(pe.title??pe.key,void 0,{sensitivity:"base"})),Me=si(o),[De,_e]=b.useState(!1);b.useEffect(()=>{if(!Me||!d||!p)return;let ee=!1;return k.listStepTests(d,p).then(pe=>{!ee&&pe.some(Ae=>Ae.lastRunStatus==="succeeded")&&_e(!0)}).catch(()=>{}),()=>{ee=!0}},[k,Me,d,p]);const ct=po(d??"",f,!!d),Ze=(et=Xe().stateShape)==null?void 0:et.written,Se=uo(ct,Za(m),Ze),Ce=!!se&&(!he||Re&&!!K)&&(!Pe||Pe.selected.length>0),Be=Ce&&!!me&&Rt(me.params??[],X),Ft=Ce,We=(C??[]).find(ee=>ee.id===K);function B(){return{uses:{app:s,action:(me==null?void 0:me.key)??se,...W?{connectionRef:W}:K?{connection:K}:{},...E?{trigger:!0}:{}},with:X,...V}}function fe(){me&&r(B())}const[ne,Qe]=b.useState(null);b.useEffect(()=>{if(!l||ne!==null||!Ce||Pe&&A==="setup")return;const ee=r(B());ee&&Qe(ee),ee&&E&&(t==null||t(ee))},[l,ne,Ce,A]),b.useEffect(()=>{!l||ne===null||l(ne,B())},[ne,X,V,K,W]);const ut=ee=>{ee==="code"&&ge(lo(B())),ae(ee)};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${A==="setup"?" active":""}`,onClick:()=>U("setup"),children:"Setup"}),n.jsx("button",{type:"button",disabled:!Ce,title:Ce?void 0:"Complete Setup first",className:`w6w-subtab${A==="configure"?" active":""}`,onClick:()=>Ce&&U("configure"),children:"Configure"}),n.jsx("button",{type:"button",disabled:!Be,title:Be?void 0:"Fill the required fields first",className:`w6w-subtab${A==="test"?" active":""}`,onClick:()=>Be&&U("test"),children:"Test"})]}),n.jsx(qn,{view:Z,customized:Mn(X),onChange:ut,disabled:A!=="configure"})]}),n.jsxs("div",{className:"w6w-stepconfig-body",children:[A==="setup"&&n.jsxs("div",{className:"w6w-stack",children:[$&&n.jsx("div",{className:"w6w-result w6w-error",children:$}),v===null&&!$&&n.jsx("p",{className:"w6w-muted w6w-small",children:"Loading…"}),n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"App"}),n.jsxs("div",{className:"w6w-app-conn-row",ref:M,children:[n.jsxs("button",{type:"button",className:"w6w-app-conn-btn","aria-label":"App",onClick: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(Ra,{step:{id:ne??p??"",uses:{app:s,action:se,...W?{connectionRef:W}:{connection:K||void 0}}},conns:C,failed:!!$,open:te,onOpenChange:Q,anchorRef:M,onChangeConnection:G,onChangeConnectionRef:H,onConnectionCreated:()=>{ye()},createSignal:_t})]}),ce&&(We==null?void 0:We.builtIn)&&n.jsx("span",{className:"w6w-hint",children:"Scheduled or queued runs need a stored connection. Choose one from the connection menu."})]}),Oe?n.jsxs(Ia,{testId:"step-needs-connection",className:"w6w-sb-connect-gate",action:n.jsxs("button",{type:"button",className:"w6w-btn",onClick:()=>xt(ee=>ee+1),children:["Connect ",(o==null?void 0:o.displayName)??s]}),children:["Connect ",(o==null?void 0:o.displayName)??s," to choose ",S,"."]}):q!==null&&(q.length===0?n.jsx("p",{className:"w6w-muted w6w-small",children:E?"This app declares no triggers.":"This app exposes no actions."}):Pe?n.jsx($a,{choices:Pe,onChange:ee=>{F(Pe.triggerKey),z(pe=>({...pe,actions:ee}))}}):n.jsxs("label",{className:"w6w-field",children:[n.jsxs("span",{children:[E?"Trigger":"Action",se?"":" *"]}),n.jsx(Ge,{value:se,placeholder:`— pick ${S} —`,mode:"combobox",listMaxHeight:200,onChange:ee=>{var pe;F(ee),z(rp(((pe=(q??[]).find(Ae=>Ae.key===ee))==null?void 0:pe.params)??[])),_e(!1)},options:He.map(ee=>({value:ee.key,label:`${ee.title??ee.key} (${ee.key})`}))}),(me==null?void 0:me.description)&&n.jsx("span",{className:"w6w-hint",children:me.description})]}))]}),A==="configure"&&(me?Z==="props"?n.jsx(Le,{params:me.params??[],values:X,onChange:z,dynamic:{appId:s,actionKey:me.key,connectionId:K||void 0,appName:o==null?void 0:o.displayName}}):Z==="code"?n.jsx(ze,{value:Y,onChange:()=>{},readOnly:!0,minHeight:"240px",height:"100%","aria-label":"Node JSON",copyable:!0}):Z==="params-code"?n.jsx(Vs,{values:X,onChange:z}):n.jsx(oi,{step:{id:p??"",...B()},config:V,onChange:ue,inLoop:m!==void 0,outputFields:(qe=pt(me,void 0))==null?void 0:qe.fields.map(ee=>ee.key),failureHandling:!E}):n.jsxs("p",{className:"w6w-muted w6w-small",children:["Pick ",S," in Setup first."]})),A==="test"&&(me&&E?n.jsx(li,{title:me.title??me.key,app:(o==null?void 0:o.displayName)??s}):me?n.jsx(bo,{app:s,action:me.key,connectionId:K||void 0,values:X,canRun:Ce&&Rt(me.params??[],X),state:Se,onResult:_e}):n.jsx("p",{className:"w6w-muted w6w-small",children:"Pick an action in Setup first."}))]}),A==="test"&&n.jsx("div",{className:"w6w-stepconfig-testnote",children:Me&&!De&&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:fe,children:x}):A==="test"?n.jsx("button",{type:"button",className:"w6w-btn",disabled:ne===null&&!Ft,onClick:ne!==null?i??a:fe,children:ne!==null?"Done":"Add node"}):n.jsx("button",{type:"button",className:"w6w-btn",disabled:A==="setup"?!Ce:!Be,onClick:()=>U(A==="setup"?"configure":"test"),children:"Next →"})]})]})}function pp({appId:e,app:t,onClose:s,onChangeApp:o,theme:r,initialConnection:a,onConnected:i}){const l=Ne(),[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,k]=b.useState(!1);b.useEffect(()=>{let T=!1;return m(null),Promise.all([l.getAppAuth(e),l.listConnectionsForApp(e)]).then(([R,D])=>{if(T)return;c(R),p(D),!(R??[]).some(H=>H.autoSatisfied===!0)&&D.length>0&&h(D[0].id)}).catch(R=>!T&&m(R.message)),()=>{T=!0}},[l,e]);const E=async()=>{const T=await l.listConnectionsForApp(e);p(T),T.length>0&&h(R=>R||T[0].id)},S=(u??[]).filter(T=>T.available!==!1),v=S.some(T=>T.autoSatisfied===!0&&(T.type==="tenantAuth"||T.type==="jit")),j=v&&!S.some(T=>T.autoSatisfied===!0&&T.type==="tenantAuth"),C=S.length>0&&!v,P=(d??[]).length>0,q=!C||P&&!!w,I=(d??[]).find(T=>T.id===w),$=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&&v&&n.jsxs("div",{className:"w6w-field",children:[n.jsx("span",{children:"Connection"}),n.jsxs("div",{className:"w6w-conn-label",children:[n.jsx("span",{className:"w6w-conn-label-name",children:"Connected automatically — this app needs no connection for your organization."}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>y(!0),children:"Create connection"})]}),j&&n.jsx("span",{className:"w6w-hint",children:'A scheduled or queued run of this workflow still needs a connection configured on this step — use "Create connection" if this step will run on a schedule.'})]}),u!==null&&C&&(P?$?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),k(!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:[(I==null?void 0:I.displayName)||(I==null?void 0:I.id)||w,I!=null&&I.state?` (${I.state})`:""]}),n.jsx("button",{type:"button",className:"w6w-btn w6w-btn-ghost w6w-btn-sm",onClick:()=>k(!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:!q||!t,onClick:()=>t&&i(w,t),children:"Next →"})]}),g&&n.jsx(Ws,{theme:r,initialAppId:e,onClose:()=>y(!1),onCreated:async({connectionId:T})=>{y(!1),h(T),k(!1),await E()}})]})}function ci({values:e,onChange:t,readOnly:s,setupOnly:o,onValidityChange:r,targetLabel:a,fixedTarget:i}){var H,L;const l=Ne(),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=ot(e.inputs)||typeof p.$=="string",[m,w]=b.useState([]),[h,g]=b.useState(),[y,x]=b.useState(),[k,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 v=(y==null?void 0:y.key)===S?y:void 0,j=v!=null&&v.workflow?fo(v.workflow):[],C=d??((H=j[0])==null?void 0:H.id),P=v!=null&&v.workflow?Jd(v.workflow,C):(v==null?void 0:v.fields)??[],I={...Object.fromEntries(P.filter(O=>O.default!==void 0).map(O=>[O.key,O.default])),...p},$=u==="function"||!d||j.some(O=>O.id===d),T=!!v&&$&&(f||Rt(P,I));b.useEffect(()=>{r==null||r(T)},[T,r]),b.useEffect(()=>{if(!v||s||o)return;const O=!f&&P.some(K=>K.default!==void 0&&!(K.key in p));(!d&&C||O)&&t({...e,...C?{entry:C}:{},inputs:f?e.inputs:I})});const R=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&&!R.some(O=>O.value===c)&&R.unshift({value:c,label:(v==null?void 0:v.label)||a||c});const D=c?(L=l.callableHref)==null?void 0:L.call(l,u,c):void 0,W=(O,K)=>{const{target:G,entry:se,...F}=e;t({...F,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=>W(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:(v==null?void 0:v.label)||a||c}):n.jsx(Ge,{"aria-label":u==="workflow"?"Workflow":"Function",options:R,value:c,disabled:s,placeholder:`Choose a ${u}…`,onChange:O=>W(u,O)}),D&&n.jsxs("a",{className:"w6w-btn w6w-btn-ghost",href:D,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:[k?n.jsx("div",{className:"w6w-result w6w-error",children:k}):v?n.jsxs(n.Fragment,{children:[u==="workflow"&&j.length>0&&n.jsxs("label",{className:"w6w-field",children:[n.jsx("span",{children:"Trigger"}),n.jsxs("select",{className:"w6w-input","aria-label":"Trigger",value:C,disabled:s,onChange:O=>t({...e,entry:O.target.value,inputs:{}}),children:[d&&!$&&n.jsxs("option",{value:d,children:[d," (unavailable)"]}),j.map(O=>n.jsxs("option",{value:O.id,children:[O.id," (",O.uses.app===Ot?"Manual":O.uses.action,")"]},O.id))]})]}),!$&&n.jsx("div",{className:"w6w-result w6w-error",children:"The selected trigger is unavailable. Choose another trigger."}),u==="workflow"&&j.length===0&&n.jsxs("p",{className:"w6w-muted w6w-small",children:[v.label," has no manual trigger. Add a manual trigger to that workflow to define its input fields."]}),n.jsx("span",{className:"w6w-small",children:"Inputs"}),P.length>0&&!f?n.jsx(Le,{params:P,values:I,readOnly:s,onChange:O=>t({...e,inputs:O})}):n.jsx(Le,{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(Le,{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 fp=/^(#{1,6})\s+(.*)$/,hp=new RegExp("\\*\\*(?=\\S)(.+?)(?<=\\S)\\*\\*","g");function wp(e,t){const s=e.ownerDocument;e.replaceChildren();for(const o of t.split(`
|
|
23
|
+
`)){const r=fp.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(hp)){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 mp(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 bp(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 yp(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:mp(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=bp(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(`
|
|
24
|
+
`)}function gp(e){return e.replace(/([^\n])\n(?=[^\n])/g,`$1
|
|
25
|
+
`)}const xp=-2,vp=-1,lr=1e3,jp=["#facc15","#fb923c","#f87171","#f472b6","#a78bfa","#60a5fa","#2dd4bf","#4ade80","#9ca3af"],Np=[{level:1,label:"Title"},{level:2,label:"Heading"},{level:3,label:"Subheading"},{level:0,label:"Body"}],kp=80,Sp=48,cr=10,Cp=4,Xn=e=>e.stopPropagation();function Ap(e){const t=e.ownerDocument.getSelection();if(!t)return;const s=e.ownerDocument.createRange();s.selectNodeContents(e),t.removeAllRanges(),t.addRange(s)}function Ep(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 ui({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),k=b.useRef(null),E=b.useRef(null);if(b.useEffect(()=>{if(!d&&!f)return;const A=d?`[data-note-id="${d}"], [data-note-toolbar="${d}"]`:`[data-section-label="${f}"], [data-section-toolbar="${f}"]`,U=Z=>{var ge,V;const ae=Z.target;if((ge=ae==null?void 0:ae.closest)!=null&&ge.call(ae,A))return;const Y=document.activeElement;(V=Y==null?void 0:Y.closest)!=null&&V.call(Y,"[data-section-toolbar]")&&Y.blur(),p(null),m(null),y(null)};return window.addEventListener("pointerdown",U,!0),()=>window.removeEventListener("pointerdown",U,!0)},[d,f]),!s)return null;const S=!o&&!!a,v=e.sections??[],j=e.notes??[],C=A=>u[A.id]??{x:A.position.x,y:A.position.y,w:A.size.width,h:A.size.height},P=A=>{const U=C(A);return{left:U.x,top:U.y,width:U.w,height:U.h,"--w6w-canvas-color":A.color}},q=(A,U)=>a==null?void 0:a({...e,notes:j.map(Z=>Z.id===A?{...Z,...U}:Z)}),I=(A,U)=>a==null?void 0:a({...e,sections:v.map(Z=>Z.id===A?{...Z,...U}:Z)}),$=A=>{const U=k.current,Z=j.find(Y=>Y.id===A);if(!(U!=null&&U.isConnected)||!Z)return;const ae=yp(U);ae!==Z.content&&q(A,{content:ae})},T=A=>{m(null),p(A)},R=A=>{p(null),m(A)},D=(A,U)=>{E.current=U??null,T(A),h(A),y(null)},W=A=>U=>{if(!U||U.dataset.ready==="1")return;U.dataset.ready="1",k.current=U,wp(U,A.content),U.focus();const Z=E.current;E.current=null,Z?(Ap(U),Z(),$(A.id)):Ep(U)},H=(A,U,Z)=>{var Y;y(null);const ae=()=>document.execCommand(U,!1,Z);w===A&&((Y=k.current)!=null&&Y.isConnected)?(ae(),$(A)):D(A,ae)},L=A=>A.mode==="move"?{...A.base,x:A.base.x+A.dx,y:A.base.y+A.dy}:{...A.base,w:Math.max(kp,A.base.w+A.dx),h:Math.max(Sp,A.base.h+A.dy)},O=(A,U,Z,ae)=>{if(!S||A.button!==0)return;A.stopPropagation(),A.preventDefault();const Y={kind:Z,id:U.id,mode:ae,sx:A.clientX,sy:A.clientY,base:C(U),dx:0,dy:0};x.current=Y;const ge=ue=>{Y.dx=(ue.clientX-Y.sx)/(r||1),Y.dy=(ue.clientY-Y.sy)/(r||1),c(ye=>({...ye,[Y.id]:L(Y)}))},V=()=>{if(window.removeEventListener("pointermove",ge),window.removeEventListener("pointerup",V),x.current=null,c(we=>{const{[Y.id]:ie,...ce}=we;return ce}),Y.dx===0&&Y.dy===0)return;const ue=L(Y),ye={position:{x:ue.x,y:ue.y},size:{width:ue.w,height:ue.h}};Y.kind==="section"&&Y.mode==="move"&&i?i(Y.id,{dx:Y.dx,dy:Y.dy}):Y.kind==="note"?q(Y.id,ye):I(Y.id,ye)};window.addEventListener("pointermove",ge),window.addEventListener("pointerup",V)},K=t?` ${t}`:"",G="nopan nodrag nowheel",se=S?j.find(A=>A.id===d):void 0,F=S?v.find(A=>A.id===f):void 0,X=r||1,z=A=>{const U=C(A);return{left:U.x+U.w/2,top:U.y,transform:`translate(-50%, calc(-100% - ${cr/X}px)) scale(${1/X})`,transformOrigin:"50% 100%","--w6w-canvas-color":A.color}},M=(A,U)=>{const Z=C(A);return{left:Z.x,top:Z.y,transform:`translate(0, calc(-100% - ${U/X}px)) scale(${1/X})`,transformOrigin:"0 100%","--w6w-canvas-color":A.color}},te=(A,U,Z,ae)=>n.jsxs("div",{className:"w6w-note-menu w6w-note-menu-colors",role:"menu",children:[jp.map(Y=>n.jsx("button",{type:"button",role:"menuitemradio","aria-checked":Y===A,"aria-label":`Colour ${Y}`,title:Y,className:`w6w-note-swatch-btn${Y===A?" active":""}`,style:{"--w6w-canvas-color":Y},"data-testid":`${Z}-option`,"data-color":Y,onClick:()=>{y(null),Y!==A&&ae(Y)}},Y)),n.jsx("label",{className:"w6w-note-swatch-btn w6w-note-swatch-custom",title:"Custom",children:n.jsx("input",{type:"color","aria-label":`Custom ${U} colour`,"data-testid":`${Z}-input`,value:A,onChange:Y=>ae(Y.currentTarget.value)})})]}),Q=A=>{A.target.closest("input")||A.preventDefault()};return gn.createPortal(n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`w6w-canvas-layer w6w-canvas-sections${K}`,style:{zIndex:xp},"data-testid":"w6w-canvas-sections",children:[v.map(A=>n.jsx("div",{className:`w6w-canvas-section${f===A.id?" selected":""}`,style:P(A),"data-section-id":A.id,"data-testid":"section",children:S&&n.jsx("div",{className:`w6w-note-resize ${G}`,"data-testid":"section-resize",onPointerDown:U=>O(U,A,"section","resize")})},A.id)),v.map(A=>(F==null?void 0:F.id)===A.id?null:n.jsx("div",{className:`w6w-canvas-section-title${S?` editable ${G}`:""}`,style:M(A,Cp),"data-section-label":A.id,"data-testid":"section-label",title:S?"Click to edit · drag to move":void 0,onPointerDown:S?U=>{R(A.id),O(U,A,"section","move")}:void 0,children:A.title||(S?"Untitled section":"")},A.id))]}),n.jsx("div",{className:`w6w-canvas-layer w6w-canvas-notes${K}`,style:{zIndex:vp},"data-testid":"w6w-canvas-notes",children:j.map(A=>{const U=S&&w===A.id;return n.jsxs("div",{className:`w6w-canvas-note${d===A.id?" selected":""}`,style:P(A),"data-note-id":A.id,"data-testid":"note",children:[U?n.jsx("div",{ref:W(A),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:Xn,onBlur:()=>{$(A.id),k.current=null,h(null)},onKeyDown:Z=>{Z.key==="Escape"&&Z.currentTarget.blur()},onPaste:Z=>{Z.preventDefault(),document.execCommand("insertText",!1,Z.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?Z=>{T(A.id),O(Z,A,"note","move")}:void 0,onDoubleClick:S?()=>D(A.id):void 0,children:A.content.trim()?n.jsx(Bs,{content:gp(A.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:Z=>O(Z,A,"note","resize")})]},A.id)})}),F&&n.jsx("div",{className:`w6w-canvas-layer${K}`,style:{zIndex:lr},"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":F.id,style:M(F,cr),onPointerDown:Xn,onMouseDown:Q,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:A=>O(A,F,"section","move"),children:n.jsx(de.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:F.title,size:Math.max(8,Math.min(32,F.title.length+1)),onBlur:A=>{const U=A.currentTarget.value;U!==F.title&&I(F.id,{title:U})},onKeyDown:A=>{(A.key==="Enter"||A.key==="Escape")&&A.currentTarget.blur()}},`${F.id}:${F.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(de.Icon,{name:"chevron-down",size:12})]}),g==="color"&&te(F.color,"section","section-color",A=>I(F.id,{color:A}))]}),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",F.id)},children:n.jsx(de.Icon,{name:"trash"})})]})}),se&&n.jsx("div",{className:`w6w-canvas-layer${K}`,style:{zIndex:lr},"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":se.id,style:z(se),onPointerDown:Xn,onMouseDown:Q,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:A=>O(A,se,"note","move"),children:n.jsx(de.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(de.Icon,{name:"chevron-down",size:12})]}),g==="color"&&te(se.color,"note","note-color",A=>q(se.id,{color:A}))]}),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(de.Icon,{name:"chevron-down",size:12})]}),g==="size"&&n.jsx("div",{className:"w6w-note-menu w6w-note-menu-sizes",role:"menu",children:Np.map(A=>n.jsx("button",{type:"button",role:"menuitem",className:`w6w-note-menu-item w6w-note-size-${A.level}`,"data-testid":`note-size-${A.level}`,onClick:()=>H(se.id,"formatBlock",A.level?`<h${A.level}>`:"<div>"),children:A.label},A.level))})]}),n.jsx("button",{type:"button",className:"w6w-icon-btn","aria-label":"Bold",title:"Bold","data-testid":"note-bold",onClick:()=>H(se.id,"bold"),children:n.jsx(de.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",se.id)},children:n.jsx(de.Icon,{name:"trash"})})]})})]}),s)}function Tp(e){const t=Qn.useStore(o=>{var r;return((r=o.domNode)==null?void 0:r.querySelector(".react-flow__viewport"))??null}),s=Qn.useStore(o=>o.transform[2]);return n.jsx(ui,{...e,zoom:e.zoom??s,viewport:t})}function Rp(e){return e.viewport!==void 0?n.jsx(ui,{...e,viewport:e.viewport}):n.jsx(Tp,{...e})}function Op({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 Xt(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]=Xt(o);return t}case"array":return e.items?[Xt(e.items)]:[];default:return null}}function Ip(e){const t={};for(const s of e??[])s&&typeof s.nodeId=="string"&&s.nodeId!==""&&(t[s.nodeId]=s);return t}function Un(e){return e.sampleOmitted!==!0&&"sample"in e&&e.sample!==void 0}function Vn(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 di(e,t,s,o){const r=t[e],a=s[e];return r!==void 0&&(!a||!Vn(a,o==null?void 0:o[e]))||!a?r:Un(a)?a.sample:Xt(a.shape)}function $p(e,t,s){const o={};for(const r of new Set([...Object.keys(e),...Object.keys(t)])){const a=di(r,e,t,s);a!==void 0&&(o[r]=a)}return o}function Pp(e,t,s){const o={...e};for(const[r,a]of Object.entries(t))Un(a)&&(e[r]===void 0||Vn(a,s==null?void 0:s[r]))&&(o[r]=a.sample);return o}function _p(e,t,s){const o={...e},r={};for(const[a,i]of Object.entries(t))e[a]!==void 0&&!Vn(i,s==null?void 0:s[a])||(delete o[a],r[a]=Un(i)?i.sample:Xt(i.shape));return{fresh:o,persisted:r}}function Fp(e,t,s){const o={...e},r={};for(const[a,i]of Object.entries(t))Un(i)&&(e[a]===void 0||Vn(i,s==null?void 0:s[a]))&&(delete o[a],r[a]=i.sample);return{fresh:o,persisted:r}}function Lp(e,t){if(e.app)return e.app;if(e.app!==null)return t.get(e.appId)}function Mp(e){const t=new Set;for(const s of e)s.app===void 0&&t.add(s.appId);return[...t]}exports.AddConnectionModal=Ws;exports.AnchoredFlyout=Sa;exports.ApiCallsPanel=Oa;exports.AppIcon=gt;exports.AppPicker=st;exports.AppTriggerTestNote=li;exports.AuthFieldsForm=hn;exports.CALL_APP=Qt;exports.CONTROL_APP=Fe;exports.CallTargetForm=ci;exports.CanvasLayer=Rp;exports.CodeEditor=Rs;exports.Combobox=Ge;exports.ConditionEditor=Ln;exports.ConfigViewToggle=qn;exports.ConfirmModal=Op;exports.CreateSharedCredentialContext=Jr;exports.CredentialPicker=Vr;exports.DATA_APP=Ht;exports.DataTable=ca;exports.DeleteButton=Hs;exports.EACH_SOURCE_HANDLE=Tn;exports.EDITOR_THEME_SPEC=Ts;exports.ERROR_SOURCE_HANDLE=xs;exports.EmptyState=Ia;exports.EventbriteTriggerPicker=$a;exports.ExpressionEditorModal=en;exports.ExpressionInput=Kt;exports.ExpressionOptionsProvider=Yl;exports.FOREACH_DONE_ROUTE=wt;exports.HTML_PREVIEW_CSP=ua;exports.HtmlPreview=pa;exports.INTERNAL_NODES=rt;exports.IconButton=Pn;exports.InternalIcon=Dn;exports.JsonEditor=ze;exports.LastUsedNote=ja;exports.Markdown=Bs;exports.Modal=ke;exports.NodeConfigForm=ta;exports.ParamCustomization=Vs;exports.ParamsForm=Le;exports.PropertyEntryForm=ia;exports.RACE_APP=It;exports.RACE_DESCRIPTION=hr;exports.RESULT_RENDER_MAX_CHARS=fs;exports.ROUTER_APP=Ke;exports.ResultViewer=Ee;exports.RetryPolicyFields=ea;exports.RouterEditor=oa;exports.SCHEDULER_APP=js;exports.SCRIPT_APP=fr;exports.StepBuilderModal=Yd;exports.StepFanOutControl=ti;exports.StepNameEditor=ra;exports.StepStateControl=ni;exports.StepTestRun=bo;exports.StopEditor=aa;exports.TRIGGER_APP=Ot;exports.TriggerFillForm=Na;exports.W6WUIProvider=tl;exports.WEBHOOK_APP=Ue;exports.WaitEditor=ka;exports.WorkflowConnectionPicker=Ra;exports.WorkflowConnectionsContext=Ta;exports.WorkflowProjectProvider=nl;exports.ancestorIds=co;exports.applyConnect=Gu;exports.applyStepProblems=Au;exports.asFieldDefs=Js;exports.bindingFieldsFor=Hr;exports.bridgeDeletedBodyStep=Vu;exports.buildBinding=Br;exports.buildResolveScope=Os;exports.callableTriggers=fo;exports.canConnect=qa;exports.centralizeConnections=Aa;exports.coerceDefault=Ks;exports.conditionCombinatorLabel=Bc;exports.conditionOperatorLabel=Hc;exports.connectConflict=Yu;exports.connectRefusal=Xu;exports.connectionAppIdsToLookUp=Mp;exports.connectionIdFor=Pt;exports.controlOwnedIds=Qs;exports.convertCodeBindingsToReads=tc;exports.dataVarRows=Sn;exports.declaredSamples=Ld;exports.deepEqual=os;exports.defaultConnectionFor=Ea;exports.definitionLoops=so;exports.deleteStepMessage=Ku;exports.detectResultFormat=wa;exports.edgeLane=xe;exports.edgeVisuals=Zt;exports.edgeWhenConflict=Qu;exports.editConnectionResources=wn;exports.effectiveEdges=no;exports.effectiveNodeOutput=di;exports.effectiveNodeOutputs=$p;exports.eventbriteTriggerChoices=Pa;exports.excludeSelfStep=Gl;exports.fanOutLabel=Bd;exports.fanOutState=Vd;exports.fieldWidget=zs;exports.fieldsToParams=Gs;exports.filterOptions=vr;exports.findChainRoot=wd;exports.findChainTail=md;exports.findCodeBindings=Dr;exports.findTestInput=ya;exports.flattenParams=Et;exports.flowToWorkflow=pd;exports.foreachTestFixture=Nd;exports.foreachTestSample=kd;exports.getTriggerDefs=ii;exports.hasParamCustomization=Mn;exports.htmlPreviewSrcDoc=da;exports.idClashMessage=sd;exports.ifPortLayout=Ti;exports.indexNodeSamples=Ip;exports.inferOutputFields=ht;exports.internalNodeDef=mt;exports.internalNodeDefaults=jn;exports.internalNodeIcon=Gi;exports.internalNodeLabel=Ki;exports.internalNodeParams=wr;exports.isConnectionBlocked=Ru;exports.isControlApp=St;exports.isDollarPath=Is;exports.isEachLink=Cn;exports.isExprValue=Ye;exports.isFloatingDraft=Ya;exports.isForeachStep=je;exports.isFormResolvedOptions=On;exports.isIfStep=Cs;exports.isInternalApp=nt;exports.isParamVisible=tn;exports.isSecretValue=at;exports.isTestRequired=si;exports.isTriggerApp=vn;exports.isTriggerStep=Ri;exports.laneForSourceHandle=gi;exports.loopBody=eo;exports.loopItemText=Id;exports.loopMembership=Ve;exports.loopRefusal=Da;exports.loopRefusalMessage=Ju;exports.nextWorkflowConnectionName=Xs;exports.nodeConfigSources=Dd;exports.nodeConfigValues=Wd;exports.nodeMetaSampleValues=Ud;exports.nodeMetaValues=qd;exports.nodePortsForStep=Bt;exports.normalizeInput=io;exports.parseJsonFields=Ur;exports.parseLoopSeed=$d;exports.parseRootAnchoredTemplate=it;exports.pickWebhookSubscription=ba;exports.previewCustomization=sa;exports.previewNodeOutputs=Pp;exports.relaneRefusal=ed;exports.relayoutNodes=dd;exports.rememberableInput=Ys;exports.renameStepInEdges=td;exports.requiredParamsFilled=Rt;exports.resolveConnectionAppMeta=Lp;exports.resolveLoopItemsInState=za;exports.resolveOutputShape=pt;exports.resolveParamJson=Jt;exports.resolveParamValue=Ps;exports.resolveVarsJson=Nl;exports.resultCopyText=ma;exports.routeFromHandle=Si;exports.routeHandle=$t;exports.routerPortLayout=Ei;exports.routesForStep=Ss;exports.seedValues=hs;exports.selectNodeConnection=Ou;exports.setEdgeWhen=Zu;exports.shapeToSkeleton=Xt;exports.shouldUseCombobox=xr;exports.slugifyLabel=hd;exports.splitFrontmatter=la;exports.splitNodeOutputs=_p;exports.splitPreviewOutputs=Fp;exports.stampLoopOf=zu;exports.startOAuthPopup=zr;exports.startStateFromSeeds=uo;exports.stateWriteVisible=_a;exports.stepBuilderLoop=Td;exports.stepBuilderUpstreamSteps=Ed;exports.stepNameError=Ua;exports.stepProblemTooltip=Tu;exports.stepToJson=lo;exports.storedViewport=Ha;exports.stripBody=to;exports.suggestStepId=bd;exports.testInputSavesSettled=xa;exports.trackTestInputSave=ga;exports.upstreamSampleValueSources=Fd;exports.upstreamSampleValues=_d;exports.upstreamStateSources=Ad;exports.useEffectiveTheme=Rn;exports.useEnterSubmit=Kr;exports.useExpressionOptions=Xe;exports.useRememberedTestInput=va;exports.useSeedSources=po;exports.useW6WApi=Ne;exports.useWorkflowConnections=Zs;exports.valueAtPath=qt;exports.varLabel=ft;exports.withConnectionRef=Yt;exports.withViewport=fd;exports.workflowToFlow=ud;
|
|
26
|
+
//# sourceMappingURL=connection-app-meta-BRf92BmY.cjs.map
|